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
@file:Suppress( | |
"IMPLICIT_CAST_TO_ANY", | |
"UNCHECKED_CAST", | |
"IMPLICIT_CAST_TO_ANY", | |
"NOTHING_TO_INLINE", | |
"UNUSED_PARAMETER", | |
"KotlinOperator", | |
"KotlinConstantConditions", | |
"unused", | |
) |
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 | |
internal fun <T> rememberRetained( | |
owner: ViewModelStoreOwner = LocalViewModelStoreOwner.current!! | |
key: String? = null, | |
block: @DisallowComposableCalls CreationExtras.() -> T, | |
): T { | |
val wrapperViewModel = viewModel(owner, key) { WrapperViewModel(block()) } | |
return remember(owner, key) { wrapperViewModel.instance } | |
} |
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
package provider | |
internal class MutableProviderImpl<T>( | |
scope: ProviderScope? = null, | |
private val factory: InstanceFactory<T>? = null, | |
) : ReadWriteProvider<T> { | |
init { | |
require(scope is ProviderScopeImpl) | |
scope.listeners.add { value = 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
package logcat | |
public object LogClient { | |
private var isInitialized: Boolean = false | |
@PublishedApi | |
internal var isEnabled: Boolean = false | |
@PublishedApi |
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
package coroutines | |
/** | |
* Calls the specified function [block] and returns its encapsulated result if invocation was | |
* successful, catching any [Throwable] exception that was thrown from the block function execution | |
* and encapsulating it as a failure. | |
* | |
* Unlike [runCatching], [suspendRunCatching] does not break structured concurrency by rethrowing | |
* any [CancellationException]. | |
* |
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 ComponentActivity.lazySavedStateHandle( | |
key: String = this::class.java.canonicalName, | |
defaultState: Bundle? = intent?.extras, | |
): Lazy<SavedStateHandle> = lazy(LazyThreadSafetyMode.NONE) { | |
SavedStateHandle(savedStateRegistry, key, defaultState) | |
} | |
fun Fragment.lazySavedStateHandle( | |
key: String = this::class.java.canonicalName, | |
defaultState: Bundle? = arguments, |
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 kotlinx.coroutines.CancellationException | |
import kotlin.contracts.ExperimentalContracts | |
import kotlin.contracts.InvocationKind | |
import kotlin.contracts.contract | |
/** | |
* A discriminated union that encapsulates a successful outcome with a value of type [T] | |
* or a failure with an arbitrary [Throwable] exception. | |
* | |
* While using Kotlin's [Result] with [runCatching] method is very simple, there are some flaws: |
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 android.app.Activity | |
import android.content.pm.PackageManager | |
import androidx.activity.compose.rememberLauncherForActivityResult | |
import androidx.activity.result.ActivityResultLauncher | |
import androidx.activity.result.contract.ActivityResultContracts | |
import androidx.compose.runtime.Composable | |
import androidx.compose.runtime.getValue | |
import androidx.compose.runtime.mutableStateOf | |
import androidx.compose.runtime.remember | |
import androidx.compose.runtime.setValue |
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
/** | |
* Invokes [otherwise] if the [value] is false. | |
*/ | |
@OptIn(ExperimentalContracts::class) | |
inline fun guard(value: Boolean, otherwise: () -> Unit) { | |
contract { | |
returns() implies value | |
} | |
if (!value) otherwise() |
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
# Android | |
android.enableJetifier=false | |
android.nonTransitiveRClass=true | |
android.useAndroidX=true | |
# Android Experimental | |
android.enableR8.fullMode=true | |
android.experimental.cacheCompileLibResources=true | |
android.experimental.enableSourceSetPathsMap=true | |
# Build Features: https://developer.android.com/reference/tools/gradle-api/7.0/com/android/build/api/dsl/BuildFeatures | |
android.defaults.buildfeatures.aidl=true |
NewerOlder