Skip to content

Instantly share code, notes, and snippets.

View itsandreramon's full-sized avatar

André Thiele itsandreramon

View GitHub Profile
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.State
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
plugins {
// ...
}
android {
// ...
}
dependencies {
// ...
[versions]
kotlin = "1.9.22"
agp = "8.2.0"
dagger = "2.50"
anvil = "2.4.8"
[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
kotlin-kapt = { id = "org.jetbrains.kotlin.kapt", version.ref = "kotlin" }
@SingleIn(AppScope::class)
class UserSessionManager @Inject constructor(private val app: App) {
private var _userCoroutineScope: UserCoroutineScope? = null
private val userCoroutineScope: CoroutineScope
get() = createUserCoroutineScope()
fun resetSession() {
_userCoroutineScope?.cancel()
class UserCoroutineScope(
private val parentScope: CoroutineScope
) : CoroutineScope by parentScope
@SingleIn(UserScope::class)
@MergeSubcomponent(UserScope::class)
interface UserComponent {
@Subcomponent.Factory
interface Factory {
fun create(
@BindsInstance userSession: UserSession,
@BindsInstance userCoroutineScope: UserCoroutineScope,
): UserComponent
@SingleIn(AppScope::class)
class UserSessionManager @Inject constructor(private val app: App) {
private var _userCoroutineScope: UserCoroutineScope? = null
private val userCoroutineScope: CoroutineScope
get() = createUserCoroutineScope()
fun resetSession() {
_userCoroutineScope?.cancel()
class App : Application() {
@Inject lateinit var userSessionManager: UserSessionManager
val appComponent: AppComponent by lazy {
DaggerAppComponent
.factory()
.create(this)
}
abstract class AppScope private constructor()
@SingleIn(AppScope::class)
@MergeComponent(AppScope::class)
interface AppComponent {
@Component.Factory
interface Factory {
fun create(
@BindsInstance app: App,
): AppComponent
}