Skip to content

Instantly share code, notes, and snippets.

View hadiyarajesh's full-sized avatar
🏠
Working from home

Rajesh Hadiya hadiyarajesh

🏠
Working from home
View GitHub Profile
class MyStateFlow<T>(private var value: T) {
private val observers = mutableListOf<(T) -> Unit>()
fun addObserver(observer: (T) -> Unit) {
observers.add(observer)
observer(value)
}
fun updateValue(newValue: T) {
value = newValue
import kotlin.random.Random
data class Post(
val postId: Long,
val caption: String?,
val likesCount: Int,
val isLiked: Boolean,
)
fun main() {
/**
*** Live template ***
Learn how to apply at here: https://lnkd.in/dnHYYVEX
*/
// Create a composable function with default Modifier
@androidx.compose.runtime.Composable
fun $NAME$(modifier: androidx.compose.ui.Modifier = androidx.compose.ui.Modifier) {
$END$
}
@Composable
fun SignInButton(
...
) {
Surface(
...
) {
Row(
modifier = Modifier
.animateContentSize(
@ExperimentalAnimationApi
@ExperimentalFoundationApi
@ExperimentalCoroutinesApi
@ExperimentalMaterialApi
@Composable
fun AuthScreen(
authViewModel: AuthViewModel
) {
val coroutineScope = rememberCoroutineScope()
var text by remember { mutableStateOf<String?>(null) }
@ExperimentalMaterialApi
@Composable
fun AuthView(
errorText: String?,
onClick: () -> Unit
) {
var isLoading by remember { mutableStateOf(false) }
Scaffold {
Column(
@ExperimentalMaterialApi
@Composable
fun SignInButton(
text: String,
loadingText: String = "Signing in...",
icon: Painter,
isLoading: Boolean = false,
shape: Shape = Shapes.medium,
borderColor: Color = Color.LightGray,
backgroundColor: Color = MaterialTheme.colors.surface,
class AuthResultContract : ActivityResultContract<Int, Task<GoogleSignInAccount>?>() {
override fun createIntent(context: Context, input: Int?): Intent =
getGoogleSignInClient(context).signInIntent.putExtra("input", input)
override fun parseResult(resultCode: Int, intent: Intent?): Task<GoogleSignInAccount>? {
return when (resultCode) {
Activity.RESULT_OK -> GoogleSignIn.getSignedInAccountFromIntent(intent)
else -> null
}
}
fun getGoogleSignInClient(context: Context): GoogleSignInClient {
val signInOptions = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
// Request id token if you intend to verify google user from your backend server
// .requestIdToken(context.getString(R.string.backend_client_id))
.requestEmail()
.build()
return GoogleSignIn.getClient(context, signInOptions)
}
@Composable
fun TimelineView(
posts: LazyPagingItems<Post>,
onLikeToggle: (Post) -> Unit,
onCommentClick: (Post) -> Unit
) {
val context = LocalContext.current
val listState = rememberLazyListState()