This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlin.random.Random | |
data class Post( | |
val postId: Long, | |
val caption: String?, | |
val likesCount: Int, | |
val isLiked: Boolean, | |
) | |
fun main() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
*** 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$ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun SignInButton( | |
... | |
) { | |
Surface( | |
... | |
) { | |
Row( | |
modifier = Modifier | |
.animateContentSize( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ExperimentalAnimationApi | |
@ExperimentalFoundationApi | |
@ExperimentalCoroutinesApi | |
@ExperimentalMaterialApi | |
@Composable | |
fun AuthScreen( | |
authViewModel: AuthViewModel | |
) { | |
val coroutineScope = rememberCoroutineScope() | |
var text by remember { mutableStateOf<String?>(null) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ExperimentalMaterialApi | |
@Composable | |
fun AuthView( | |
errorText: String?, | |
onClick: () -> Unit | |
) { | |
var isLoading by remember { mutableStateOf(false) } | |
Scaffold { | |
Column( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun TimelineView( | |
posts: LazyPagingItems<Post>, | |
onLikeToggle: (Post) -> Unit, | |
onCommentClick: (Post) -> Unit | |
) { | |
val context = LocalContext.current | |
val listState = rememberLazyListState() |
NewerOlder