This file contains hidden or 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 androidx.compose.animation.core.* | |
| import androidx.compose.foundation.Canvas | |
| import androidx.compose.foundation.background | |
| import androidx.compose.foundation.layout.* | |
| import androidx.compose.material.Text | |
| import androidx.compose.runtime.* | |
| import androidx.compose.ui.Alignment | |
| import androidx.compose.ui.Modifier | |
| import androidx.compose.ui.geometry.Offset | |
| import androidx.compose.ui.geometry.Size |
This file contains hidden or 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 Screen() { | |
| var date by remember { | |
| mutableStateOf( | |
| TextFieldValue( | |
| text = "dd-MM-yyyy" | |
| ) | |
| ) | |
| } |
This file contains hidden or 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 KeepScreenOn() { | |
| val currentView = LocalView.current | |
| DisposableEffect(Unit) { | |
| currentView.keepScreenOn = true | |
| onDispose { | |
| currentView.keepScreenOn = false | |
| } | |
| } |
This file contains hidden or 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
| // | |
| // Copyright (c) Christian Gruber, All Rights Reserved | |
| // | |
| // Licensed for use under any of simplified BSD 2-clause, BSD, MIT, or Apache licenses, | |
| // at the licensee's discretion. | |
| // | |
| // I'd release it to the public domain, except that prevents its use in some commercial | |
| // environments due to the US having a broken copyright system. So there it is. Liberally | |
| // licensed as I can make it. |
This file contains hidden or 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 androidx.lifecycle.* | |
| import kotlinx.coroutines.CoroutineDispatcher | |
| import kotlinx.coroutines.Dispatchers | |
| import kotlinx.coroutines.flow.Flow | |
| import kotlinx.coroutines.flow.MutableStateFlow | |
| import kotlinx.coroutines.launch | |
| import kotlinx.coroutines.withContext | |
| abstract class ComposeViewModel<C, E> : ViewModel(), LifecycleObserver { |
This file contains hidden or 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 android.os.Bundle | |
| import androidx.lifecycle.Lifecycle | |
| import androidx.lifecycle.LifecycleRegistry | |
| import androidx.savedstate.SavedStateRegistry | |
| import androidx.savedstate.SavedStateRegistryController | |
| import androidx.savedstate.SavedStateRegistryOwner | |
| internal class MyLifecycleOwner : SavedStateRegistryOwner { | |
| private var mLifecycleRegistry: LifecycleRegistry = LifecycleRegistry(this) | |
| private var mSavedStateRegistryController: SavedStateRegistryController = SavedStateRegistryController.create(this) |
This file contains hidden or 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
| val db = Room | |
| .databaseBuilder(getApplication(), CitiesDb::class.java, "cities.db") | |
| .createFromAsset("databases/cities.db") | |
| .fallbackToDestructiveMigration() // On version update - just copy over | |
| .build() |
This file contains hidden or 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
| suspend fun <T, R> T.letOn( | |
| context: CoroutineContext, | |
| block: suspend CoroutineScope.(T) -> R | |
| ): R = withContext(context) { block(this@letOn) } | |
| suspend fun <T> T.alsoOn( | |
| context: CoroutineContext, | |
| block: suspend CoroutineScope.(T) -> Unit | |
| ): T = also { withContext(context) { block(this@alsoOn) } } |
This file contains hidden or 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
| package ${PACKAGE_NAME} | |
| #parse("File Header.java") | |
| import androidx.room.Dao | |
| import androidx.room.Insert | |
| import androidx.room.Update | |
| import androidx.room.Query | |
| @Dao |
NewerOlder