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.view.View | |
/** | |
* Lightweight alternative for [android.view.ViewStub] | |
*/ | |
class LazyView<T : View>( | |
private val init: () -> T, | |
) { |
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 androidx.lifecycle.Lifecycle | |
import androidx.lifecycle.LifecycleOwner | |
import androidx.lifecycle.lifecycleScope | |
import androidx.lifecycle.repeatOnLifecycle | |
import kotlinx.coroutines.flow.StateFlow | |
import kotlinx.coroutines.launch | |
/* | |
* Contraction for: |
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.graphics.BlurMaskFilter | |
import androidx.compose.foundation.background | |
import androidx.compose.foundation.layout.Box | |
import androidx.compose.foundation.layout.fillMaxSize | |
import androidx.compose.foundation.layout.padding | |
import androidx.compose.foundation.layout.requiredSize | |
import androidx.compose.runtime.Composable | |
import androidx.compose.runtime.remember | |
import androidx.compose.ui.Modifier | |
import androidx.compose.ui.composed |
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.delay | |
import kotlin.coroutines.cancellation.CancellationException | |
@Throws | |
suspend fun <T> retrying( | |
fallbackValue: T? = null, | |
tryCnt: Int = 3, | |
intervalMillis: (attempt: Int) -> Long = { 2000L * it }, | |
onError: suspend (Throwable) -> Unit = {}, | |
retryCheck: (Throwable) -> Boolean = networkRetryCheck, |
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 <T> Flow<T>.throttleLatest(delayMillis: Long) = this | |
.conflate() | |
.transform { | |
emit(it) | |
delay(delayMillis) | |
} | |
import kotlinx.coroutines.ExperimentalCoroutinesApi |
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.annotation.SuppressLint | |
import android.app.Activity | |
import android.app.Application | |
import android.os.Bundle | |
import timber.log.Timber | |
import java.lang.ref.WeakReference | |
class ActivitiesTracker { | |
private val createdActivities = mutableListOf<WeakReference<Activity>>() |
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 <T : Any> Single<T>.withProgress(progress: MutableState<Boolean>): Single<T> = this | |
.doOnSubscribe { progress.value = true } | |
.doFinally { progress.value = false } | |
fun Completable.withProgress(progress: MutableState<Boolean>): Completable = this | |
.doOnSubscribe { progress.value = true } | |
.doFinally { progress.value = false } | |
fun <T : Any> Observable<T>.withProgress(progress: RxValueMutable<Boolean>): Observable<T> = this |
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 launch() { | |
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT) | |
intent.addCategory(Intent.CATEGORY_OPENABLE) | |
intent.type = "image/*" | |
startActivityForResult(intent, 2) | |
} | |
//TODO use registerForActivityResult() as modern approach | |
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { |
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.NonCancellable | |
import kotlinx.coroutines.sync.Mutex | |
import kotlinx.coroutines.sync.withLock | |
import kotlinx.coroutines.withContext | |
class LockedObj<T>( | |
/** | |
* Use it directly only in [withLock] | |
*/ |
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
@Suppress("Unused") | |
object DebugAssert { | |
fun ensure(predicate: () -> Boolean) { | |
ensure(predicate, null) | |
} | |
fun ensure(predicate: () -> Boolean, description: String? = null) { | |
if (BuildConfig.DEBUG && !predicate()) { |