Skip to content

Instantly share code, notes, and snippets.

@MrOzOn
MrOzOn / gist:de40c9b86f98b39278dfc760a46c5434
Created October 16, 2024 13:35
template for dependencies block
dependencies {
// coreLibraryDesugaring(libs.desugar.jdk.libs)
// timber as logging
implementation(libs.logging.timber)
// common android+compose dependencies
implementation(libs.bundles.common)
implementation(platform(libs.androidx.compose.bom))
// using material3
implementation(libs.androidx.material3)
implementation(libs.material.icons.extended)
@MrOzOn
MrOzOn / gist:7084d0d7d6934b483a94aabb205f1d07
Last active October 16, 2024 13:36
my toml file for android developer
[versions]
agp = "8.7.1"
authsdk = "3.1.0"
composecalendar = "1.1.0"
desugar_jdk_libs = "2.1.2"
firebaseBom = "33.1.2"
glance = "1.1.0"
hiltCompiler = "1.2.0"
kotlin = "2.0.0"
coreKtx = "1.13.1"
@MrOzOn
MrOzOn / gist:f0ff6fa7557eab399e10f0acbd7ca686
Created October 13, 2022 11:38
shimmer effect in Compose
fun Modifier.shimmerBackground(shape: Shape = RectangleShape): Modifier = composed {
val transition = rememberInfiniteTransition()
val translateAnimation by transition.animateFloat(
initialValue = 0f,
targetValue = 400f,
animationSpec = infiniteRepeatable(
tween(durationMillis = 1500, easing = LinearOutSlowInEasing),
RepeatMode.Restart
),
)
@MrOzOn
MrOzOn / gist:c3ce8db3687666563e3ff7445582ea80
Created September 8, 2021 08:46
using StateFlow in ViewModel with suspend function
val result: Flow<Result> = flow {
val data = someSuspendingFunction()
emit(data)
}.stateIn(
scope = viewModelScope,
started = SharingStarted.WhileSubscribed(5000L),
initialValue = Result.Loading
)
@MrOzOn
MrOzOn / gist:a30169004cbec31b255b42f0403f46f3
Created September 8, 2021 08:43
a safer way to collect Flows of any kind
import lifecycle:lifecycle-runtime-ktx:2.4.0
viewLifecycleOwner.lifecycleScope.launch {
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.result.collect { data ->
displayResult(data)
}
}
}
@MrOzOn
MrOzOn / gist:364311d60f7038a290a21b051c95f3f3
Created September 1, 2021 07:15
delay in android views
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.3.1"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.3"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.3"
import androidx.lifecycle.coroutineScope
import androidx.lifecycle.findViewTreeLifecycleOwner
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
@SuppressLint("ApplySharedPref")
fun String.save(applicationContext: Context, value: Map<String, Any>, clear: Boolean = false, now: Boolean = false) {
val sp = applicationContext.getSharedPreferences(this, Context.MODE_PRIVATE).edit()
if (clear)
sp.clear()
value.keys.forEach { key ->
val v = value[key]
if (v != null) {
when (v) {
is String -> sp.putString(key, v)
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
implementation 'com.jakewharton.timber:timber:4.7.1'
private fun initTimber() {
if (BuildConfig.DEBUG) {
Timber.plant(DebugTree())
} else {
Fabric.with(this, Crashlytics())
}
}