Skip to content

Instantly share code, notes, and snippets.

View burnoo's full-sized avatar

Bruno Wieczorek burnoo

  • Kotlin Multiplatform / Android Developer
  • Wrocław, Poland
  • 15:46 (UTC +01:00)
View GitHub Profile
@burnoo
burnoo / RetryRequest.MD
Last active August 14, 2021 10:31
Kotlin Flow - custom result retry

Kotlin Flow - custom result retry

Maybe I will write article about this

API:

internal fun <T, R> Flow<T>.retryMap(
    map: suspend (T) -> R,
    predicate: suspend FlowCollector<R>.(value: T, result: R, attempt: Int) -> Boolean
): Flow<R> {
    var retryCount = 1
@burnoo
burnoo / build.gradle
Last active December 5, 2021 16:57
Medium Cokoin 1
dependencies {
implementation "dev.burnoo:cokoin:0.3.2"
// REMOVE "org.koin:koin-androidx-compose:X.Y.Z" if you were using it
}
@burnoo
burnoo / Wrapping Configuration.kt
Last active October 13, 2021 12:17
Cokoin Medium 2
val appModule = module {
single { AppData() }
}
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
Koin(appDeclaration = { modules(appModule) }) {
val appData = get<AppData>()
@burnoo
burnoo / Preview Koin.kt
Created September 21, 2021 09:46
Medium Cokoin 3
@Composable
fun Hello() {
val hello = get<Hello>()
Text(hello.text)
}
val previewModule = module {
factory { Hello(text = "preview hello text") }
}
@burnoo
burnoo / Koin Scopes.kt
Last active October 4, 2021 19:54
Cokoin Medium 4
data class A(val value: String)
val scopedModule = module {
scope<ScopeTypeA> {
scoped { A("scopeA") }
}
scope<ScopeTypeB> {
scoped { A("scopeB") }
}
}
@burnoo
burnoo / HarmonyOSAndroidCheatSheet.MD
Last active October 7, 2021 12:39
Java HarmonyOS API for Android developers - cheatsheet

Basic Applications Elements

Android HarmonyOS Notes / Usage
Application AbilityPackage
@burnoo
burnoo / KoinContext.kt
Created October 13, 2021 12:25
Cokoin medium 5
@Composable
fun App() {
val globalData = get<AppData>() // uses Global KoinContext
Koin(koinApplication) {
val localData = get<AppData>() // uses Local KoinContext (koinApplication)
}
}
@burnoo
burnoo / Cokoin ViewModel.kt
Created October 21, 2021 13:48
Cokoin medium 6
val module = module {
viewModel { AppViewModel() }
}
Koin(appDeclaration = { modules(module) }) {
val viewModel = getViewModel<AppViewModel>()
Text(viewModel.text)
}
@burnoo
burnoo / viewModelStoreOwner usage.kt
Last active October 21, 2021 13:58
Cokoin Medium 7
@Composable
fun Screen1(navController: NavController) {
val rootViewModel = getViewModel<RootViewModel>(
viewModelStoreOwner = navController.getBackStackEntry("root")
)
}
@burnoo
burnoo / Jetpack Compose two-way data binding.kt
Last active October 13, 2022 07:08
Jetpack Compose two-way data binding
private class MutableStateAdapter<T>(
private val state: State<T>,
private val mutate: (T) -> Unit
) : MutableState<T> {
override var value: T
get() = state.value
set(value) {
mutate(value)
}