Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Reaktive to 2.2.0 in samples #802

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion deps.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
decompose = "3.2.0"
kotlin = "2.0.20"
essenty = "2.2.0"
reaktive = "1.2.3"
reaktive = "2.2.0"
junit = "4.13.2"
jetbrainsCompose = "1.7.0"
jetbrainsKotlinWrappers = "1.0.0-pre.608"
Expand All @@ -25,6 +25,7 @@ kotlin-kotlinGradlePlug = { group = "org.jetbrains.kotlin", name = "kotlin-gradl
kotlin-test = { group = "org.jetbrains.kotlin", name = "kotlin-test", version.ref = "kotlin" }

essenty-lifecycle = { group = "com.arkivanov.essenty", name = "lifecycle", version.ref = "essenty" }
essenty-lifecycleReaktive = { group = "com.arkivanov.essenty", name = "lifecycle-reaktive", version.ref = "essenty" }
essenty-stateKeeper = { group = "com.arkivanov.essenty", name = "state-keeper", version.ref = "essenty" }
essenty-instanceKeeper = { group = "com.arkivanov.essenty", name = "instance-keeper", version.ref = "essenty" }
essenty-backHandler = { group = "com.arkivanov.essenty", name = "back-handler", version.ref = "essenty" }
Expand Down
1 change: 1 addition & 0 deletions sample/shared/shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ kotlin {
api(deps.essenty.lifecycle)
api(deps.essenty.stateKeeper)
api(deps.essenty.backHandler)
implementation(deps.essenty.lifecycleReaktive)
implementation(deps.reaktive.reaktive)
implementation(deps.jetbrains.kotlinx.kotlinxSerializationJson)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import com.google.android.play.core.splitinstall.SplitInstallRequest
import com.google.android.play.core.splitinstall.SplitInstallSessionState
import com.google.android.play.core.splitinstall.SplitInstallStateUpdatedListener
import com.google.android.play.core.splitinstall.model.SplitInstallSessionStatus
import kotlin.time.Duration.Companion.seconds

class DefaultFeatureInstaller(
context: Context
Expand All @@ -34,7 +35,7 @@ class DefaultFeatureInstaller(
// For testing purposes all dynamic features are configured as `install-time`, so simulating installation process
private fun Single<Result>.simulateInstallationProcessIfNeeded(name: String): Single<Result> =
takeUnless { name in installedFeatures }
?.delaySubscription(delayMillis = 3000L, scheduler = mainScheduler)
?.delaySubscription(delay = 3.seconds, scheduler = mainScheduler)
?.doOnBeforeSuccess {
if (it is Result.Installed) {
installedFeatures += name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import com.arkivanov.decompose.ComponentContext
import com.arkivanov.decompose.value.MutableValue
import com.arkivanov.decompose.value.Value
import com.arkivanov.decompose.value.update
import com.arkivanov.essenty.instancekeeper.ExperimentalInstanceKeeperApi
import com.arkivanov.essenty.instancekeeper.InstanceKeeper
import com.arkivanov.essenty.instancekeeper.retainedInstance
import com.arkivanov.essenty.lifecycle.reaktive.disposableScope
import com.arkivanov.essenty.lifecycle.subscribe
import com.arkivanov.essenty.statekeeper.ExperimentalStateKeeperApi
import com.arkivanov.essenty.statekeeper.saveable
Expand All @@ -20,18 +20,19 @@ import com.badoo.reaktive.scheduler.mainScheduler
import com.badoo.reaktive.subject.behavior.BehaviorObservable
import com.badoo.reaktive.subject.behavior.BehaviorSubject
import kotlinx.serialization.builtins.serializer
import kotlin.time.Duration.Companion.milliseconds

class DefaultCardComponent(
componentContext: ComponentContext,
color: Long,
number: Int,
tickScheduler: Scheduler = mainScheduler,
) : CardComponent, ComponentContext by componentContext, DisposableScope by DisposableScope() {
) : CardComponent, ComponentContext by componentContext, DisposableScope by componentContext.disposableScope() {

@OptIn(ExperimentalStateKeeperApi::class, ExperimentalInstanceKeeperApi::class)
@OptIn(ExperimentalStateKeeperApi::class)
private val handler: Handler by saveable(serializer = Int.serializer(), state = { it.count.value }) { savedState ->
retainedInstance {
Handler(initialCount = savedState ?: 0, tickScheduler = tickScheduler)
Handler(savedState = savedState, tickScheduler = tickScheduler)
}
}

Expand All @@ -43,15 +44,6 @@ class DefaultCardComponent(
_model.update { it.copy(text = "Count: $count") }
}

lifecycle.subscribe(
onCreate = { setStatus("Created") },
onStart = { setStatus("Started") },
onResume = { setStatus("Resumed") },
onPause = { setStatus("Paused") },
onStop = { setStatus("Stopped") },
onDestroy = { setStatus("Destroyed") },
)

lifecycle.subscribe(
onStart = handler::start,
onStop = handler::stop,
Expand All @@ -63,16 +55,16 @@ class DefaultCardComponent(
}

private class Handler(
initialCount: Int,
savedState: Int?,
private val tickScheduler: Scheduler,
) : InstanceKeeper.Instance {
private val _count = BehaviorSubject(initialCount)
private val _count = BehaviorSubject(savedState ?: 0)
val count: BehaviorObservable<Int> = _count
private var disposable: Disposable? = null

fun start() {
disposable =
observableInterval(periodMillis = 250L, scheduler = tickScheduler)
observableInterval(period = 250.milliseconds, scheduler = tickScheduler)
.subscribe { _count.onNext(_count.value + 1) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.badoo.reaktive.observable.observableInterval
import com.badoo.reaktive.scheduler.Scheduler
import com.badoo.reaktive.scheduler.mainScheduler
import kotlinx.serialization.Serializable
import kotlin.time.Duration.Companion.milliseconds

internal class DefaultCounterComponent(
componentContext: ComponentContext,
Expand Down Expand Up @@ -105,7 +106,7 @@ internal class DefaultCounterComponent(
val state: MutableValue<State> = MutableValue(initialState)

init {
observableInterval(periodMillis = 250L, scheduler = tickScheduler).subscribeScoped {
observableInterval(period = 250.milliseconds, scheduler = tickScheduler).subscribeScoped {
state.update { it.copy(count = it.count + 1) }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.badoo.reaktive.observable.observableInterval
import com.badoo.reaktive.observable.subscribe
import com.badoo.reaktive.scheduler.mainScheduler
import kotlinx.serialization.Serializable
import kotlin.time.Duration.Companion.milliseconds

class DefaultKittenComponent(
componentContext: ComponentContext,
Expand Down Expand Up @@ -61,7 +62,7 @@ class DefaultKittenComponent(
disposable?.dispose()

disposable =
observableInterval(periodMillis = 250L, scheduler = mainScheduler).subscribe(isThreadLocal = true) {
observableInterval(period = 250.milliseconds, scheduler = mainScheduler).subscribe {
state.update { it.copy(count = it.count + 1) }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import com.arkivanov.decompose.router.panels.isSingle
import com.arkivanov.decompose.router.panels.navigate
import com.arkivanov.decompose.router.panels.pop
import com.arkivanov.decompose.value.Value
import com.arkivanov.essenty.lifecycle.reaktive.disposableScope
arkivanov marked this conversation as resolved.
Show resolved Hide resolved
import com.arkivanov.sample.shared.multipane.author.ArticleAuthorComponent
import com.arkivanov.sample.shared.multipane.author.DefaultArticleAuthorComponent
import com.arkivanov.sample.shared.multipane.database.DefaultArticleDatabase
import com.arkivanov.sample.shared.multipane.details.ArticleDetailsComponent
import com.arkivanov.sample.shared.multipane.details.DefaultArticleDetailsComponent
import com.arkivanov.sample.shared.multipane.list.ArticleListComponent
import com.arkivanov.sample.shared.multipane.list.DefaultArticleListComponent
import com.arkivanov.sample.shared.multipane.utils.disposableScope
import com.badoo.reaktive.disposable.scope.DisposableScope
import com.badoo.reaktive.observable.map
import com.badoo.reaktive.observable.notNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import com.arkivanov.decompose.ComponentContext
import com.arkivanov.decompose.value.MutableValue
import com.arkivanov.decompose.value.Value
import com.arkivanov.decompose.value.update
import com.arkivanov.essenty.lifecycle.reaktive.disposableScope
import com.arkivanov.sample.shared.multipane.author.ArticleAuthorComponent.Author
import com.arkivanov.sample.shared.multipane.author.ArticleAuthorComponent.Model
import com.arkivanov.sample.shared.multipane.database.ArticleDatabase
import com.arkivanov.sample.shared.multipane.database.AuthorEntity
import com.arkivanov.sample.shared.multipane.utils.disposableScope
import com.badoo.reaktive.disposable.scope.DisposableScope
import com.badoo.reaktive.observable.Observable

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import com.arkivanov.decompose.ComponentContext
import com.arkivanov.decompose.value.MutableValue
import com.arkivanov.decompose.value.Value
import com.arkivanov.decompose.value.update
import com.arkivanov.essenty.lifecycle.reaktive.disposableScope
import com.arkivanov.sample.shared.multipane.database.ArticleDatabase
import com.arkivanov.sample.shared.multipane.database.ArticleEntity
import com.arkivanov.sample.shared.multipane.details.ArticleDetailsComponent.Article
import com.arkivanov.sample.shared.multipane.details.ArticleDetailsComponent.Model
import com.arkivanov.sample.shared.multipane.utils.disposableScope
import com.badoo.reaktive.disposable.scope.DisposableScope
import com.badoo.reaktive.observable.Observable

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import com.arkivanov.decompose.ComponentContext
import com.arkivanov.decompose.value.MutableValue
import com.arkivanov.decompose.value.Value
import com.arkivanov.decompose.value.update
import com.arkivanov.essenty.lifecycle.reaktive.disposableScope
import com.arkivanov.sample.shared.multipane.database.ArticleDatabase
import com.arkivanov.sample.shared.multipane.database.ArticleEntity
import com.arkivanov.sample.shared.multipane.list.ArticleListComponent.Article
import com.arkivanov.sample.shared.multipane.list.ArticleListComponent.Model
import com.arkivanov.sample.shared.multipane.utils.disposableScope
import com.badoo.reaktive.disposable.scope.DisposableScope
import com.badoo.reaktive.observable.Observable

Expand Down

This file was deleted.

Loading