Skip to content

Instantly share code, notes, and snippets.

View yveskalume's full-sized avatar
🌍
Working from Anywhere

Yves Kalume yveskalume

🌍
Working from Anywhere
View GitHub Profile
@yveskalume
yveskalume / TextFieldScreen.kt
Created March 17, 2024 22:02
Shake animation for text field on wrong value submission
@Composable
fun TextFieldScreen() {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(8.dp, Alignment.CenterVertically)
) {
val context = LocalContext.current
val (email, onEmailChange) = remember {
@yveskalume
yveskalume / gist:469c3721ee43620d6e9eb76601b0caf4
Last active March 17, 2024 17:48
ButtonWithLongClick.kt
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun Button(
onClick: () -> Unit,
onLongClick: () -> Unit,
modifier: Modifier = Modifier,
shape: Shape = ButtonDefaults.shape,
containerColor: Color,
contentColor: Color,
border: BorderStroke? = null,
val instanceName = if (BuildConfig.DEBUG) "beserved-development" else "beserved-production"
FirebaseApp.getInstance(instanceName)
class App : Application() {
override fun onCreate() { 
super.onCreate()
val devOptions = FirebaseOptions.Builder()
.setProjectId("beserved-development-project")
.setApplicationId("1:212877806437:android:fee5f52927e2f7a907ed8c")
.setApiKey("AIzaSyADUe90ULnQDuGShD9W23RDP0xmeDc6Mvw")
.build()
val prodOptions = FirebaseOptions.Builder()
.setProjectId("beserved-production-project")
val options = FirebaseOptions.Builder()
.setProjectId("my-firebase-project")
.setApplicationId("1:27992087142:android:ce3b6448250083d1")
.setApiKey("AIzaSyADUe90ULnQDuGShD9W23RDP0xmeDc6Mvw") 
.build()
private val postViewModel: PostViewModel by fragmentViewModel()
override fun invalidate(): Unit = withState(postViewModel) {
binding.progess.isVisible = it.post is Loading
when (it.post) {
is Success -> {
binding.progess.visibility = View.GONE
adapter.submitList(it.post.invoke())
}
is Fail -> {
Toast.makeText( requireContext(), "An error occured", Toast.LENGTH_SHORT).show()
Log.e("message", it.post.error.localizedMessage)
private val postViewModel: PostViewModel by fragmentViewModel()
override fun invalidate(): Unit = withState(postViewModel) {
binding.progess.isVisible = it.post is Loading
when (it.post) {
is Success -> {
binding.progess.visibility = View.GONE
adapter.submitList(it.post.invoke())
}
is Fail -> {
Toast.makeText( requireContext(), "An error occured", Toast.LENGTH_SHORT).show()
Log.e("message", it.post.error.localizedMessage)
data class PostState(
val post: Async<List<Post>> = Uninitialized
) : MavericksState