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 co.touchlab.kermit.BaseLogger | |
import co.touchlab.kermit.LoggerConfig | |
import co.touchlab.kermit.Severity | |
import co.touchlab.kermit.mutableLoggerConfigInit | |
import co.touchlab.kermit.platformLogWriter | |
@Suppress("ClassName") // lower case class name. | |
open class log( | |
config: LoggerConfig, | |
) : BaseLogger(config) { |
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 ie.conorgarry.patreontemplate | |
import androidx.annotation.VisibleForTesting | |
import androidx.lifecycle.LiveData | |
import androidx.lifecycle.Observer | |
import java.util.concurrent.CountDownLatch | |
import java.util.concurrent.TimeUnit | |
import java.util.concurrent.TimeoutException | |
// kotlin-coroutines-end/app/src/test/java/com/example/android/kotlincoroutines/LiveDataTestUtil.kt |
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
plugins { | |
id 'com.android.application' | |
id 'kotlin-android' | |
id 'kotlin-kapt' | |
} | |
android { | |
compileSdk 31 | |
defaultConfig { |
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
sealed class UiState<out T> { | |
fun interface SuccessHandler<T> { | |
fun invoke(data: T) | |
} | |
fun interface FailureHandler { | |
fun invoke(error: Throwable) | |
} |
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
/** | |
* Similar to [groupBy] or [partition], except an arbitrary amount of predicates can be returned. | |
* Think [partition] for > 2 predicates. | |
* | |
* | |
* @return [List] with size n for predicates where all items will satisfy one of the predicates, | |
* or size n + 1 for n predicates, where there will be remaining items after condition check. | |
* | |
* @throws [IndexOutOfBoundsException] If using declaration deconstruction where val count is > possible return size. | |
* |
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.LiveData | |
import androidx.lifecycle.MutableLiveData | |
import androidx.lifecycle.ViewModel | |
import androidx.lifecycle.viewModelScope | |
import kotlinx.coroutines.* | |
import kotlin.coroutines.AbstractCoroutineContextElement | |
import kotlin.coroutines.CoroutineContext | |
class CoroutineApiViewModel : ViewModel() { |
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
// Scope to LifeCycle ON_START | |
@ExperimentalCoroutinesApi | |
fun <T> LifecycleOwner.stateFlow(stateFlow: StateFlow<T>, funCollect: (T) -> Unit) { | |
lifecycleScope.launchWhenStarted { | |
stateFlow.collect { | |
funCollect(it) | |
} | |
} | |
} |