block application launch setup until beta upgrades have completed
This commit is contained in:
parent
223b5d27ef
commit
5b7fe5aa4e
|
@ -60,13 +60,12 @@ class SmallTalkApplication : Application(), ModuleProvider {
|
||||||
|
|
||||||
private fun onApplicationLaunch(notificationsModule: NotificationsModule, storeModule: StoreModule) {
|
private fun onApplicationLaunch(notificationsModule: NotificationsModule, storeModule: StoreModule) {
|
||||||
applicationScope.launch {
|
applicationScope.launch {
|
||||||
|
featureModules.homeModule.betaVersionUpgradeUseCase.waitUnitReady()
|
||||||
|
|
||||||
storeModule.credentialsStore().credentials()?.let {
|
storeModule.credentialsStore().credentials()?.let {
|
||||||
featureModules.pushModule.pushTokenRegistrar().registerCurrentToken()
|
featureModules.pushModule.pushTokenRegistrar().registerCurrentToken()
|
||||||
}
|
}
|
||||||
runCatching { storeModule.localEchoStore.preload() }
|
runCatching { storeModule.localEchoStore.preload() }
|
||||||
}
|
|
||||||
|
|
||||||
applicationScope.launch {
|
|
||||||
val notificationsUseCase = notificationsModule.notificationsUseCase()
|
val notificationsUseCase = notificationsModule.notificationsUseCase()
|
||||||
notificationsUseCase.listenForNotificationChanges(this)
|
notificationsUseCase.listenForNotificationChanges(this)
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ import app.dapk.st.directory.DirectoryModule
|
||||||
import app.dapk.st.domain.StoreModule
|
import app.dapk.st.domain.StoreModule
|
||||||
import app.dapk.st.engine.MatrixEngine
|
import app.dapk.st.engine.MatrixEngine
|
||||||
import app.dapk.st.firebase.messaging.MessagingModule
|
import app.dapk.st.firebase.messaging.MessagingModule
|
||||||
|
import app.dapk.st.home.BetaVersionUpgradeUseCase
|
||||||
import app.dapk.st.home.HomeModule
|
import app.dapk.st.home.HomeModule
|
||||||
import app.dapk.st.home.MainActivity
|
import app.dapk.st.home.MainActivity
|
||||||
import app.dapk.st.imageloader.ImageLoaderModule
|
import app.dapk.st.imageloader.ImageLoaderModule
|
||||||
|
@ -164,7 +165,16 @@ internal class FeatureModules internal constructor(
|
||||||
deviceMeta,
|
deviceMeta,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
val homeModule by unsafeLazy { HomeModule(chatEngineModule.engine, storeModule.value, buildMeta) }
|
val homeModule by unsafeLazy {
|
||||||
|
HomeModule(
|
||||||
|
chatEngineModule.engine,
|
||||||
|
storeModule.value,
|
||||||
|
BetaVersionUpgradeUseCase(
|
||||||
|
storeModule.value.applicationStore(),
|
||||||
|
buildMeta,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
val settingsModule by unsafeLazy {
|
val settingsModule by unsafeLazy {
|
||||||
SettingsModule(
|
SettingsModule(
|
||||||
chatEngineModule.engine,
|
chatEngineModule.engine,
|
||||||
|
|
|
@ -3,24 +3,44 @@ package app.dapk.st.home
|
||||||
import app.dapk.st.core.BuildMeta
|
import app.dapk.st.core.BuildMeta
|
||||||
import app.dapk.st.domain.ApplicationPreferences
|
import app.dapk.st.domain.ApplicationPreferences
|
||||||
import app.dapk.st.domain.ApplicationVersion
|
import app.dapk.st.domain.ApplicationVersion
|
||||||
|
import kotlinx.coroutines.CancellableContinuation
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
|
import kotlinx.coroutines.suspendCancellableCoroutine
|
||||||
|
import kotlin.coroutines.resume
|
||||||
|
|
||||||
class BetaVersionUpgradeUseCase(
|
class BetaVersionUpgradeUseCase(
|
||||||
private val applicationPreferences: ApplicationPreferences,
|
private val applicationPreferences: ApplicationPreferences,
|
||||||
private val buildMeta: BuildMeta,
|
private val buildMeta: BuildMeta,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
private var _continuation: CancellableContinuation<Unit>? = null
|
||||||
|
|
||||||
fun hasVersionChanged(): Boolean {
|
fun hasVersionChanged(): Boolean {
|
||||||
return runBlocking {
|
return runBlocking { hasChangedVersion() }
|
||||||
val previousVersion = applicationPreferences.readVersion()?.value
|
}
|
||||||
val currentVersion = buildMeta.versionCode
|
|
||||||
when (previousVersion) {
|
private suspend fun hasChangedVersion(): Boolean {
|
||||||
null -> false
|
val previousVersion = applicationPreferences.readVersion()?.value
|
||||||
else -> currentVersion > previousVersion
|
val currentVersion = buildMeta.versionCode
|
||||||
}.also {
|
return when (previousVersion) {
|
||||||
applicationPreferences.setVersion(ApplicationVersion(currentVersion))
|
null -> false
|
||||||
|
else -> currentVersion > previousVersion
|
||||||
|
}.also {
|
||||||
|
applicationPreferences.setVersion(ApplicationVersion(currentVersion))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun waitUnitReady() {
|
||||||
|
if (hasChangedVersion()) {
|
||||||
|
suspendCancellableCoroutine { continuation ->
|
||||||
|
_continuation = continuation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun notifyUpgraded() {
|
||||||
|
_continuation?.resume(Unit)
|
||||||
|
_continuation = null
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,6 +1,5 @@
|
||||||
package app.dapk.st.home
|
package app.dapk.st.home
|
||||||
|
|
||||||
import app.dapk.st.core.BuildMeta
|
|
||||||
import app.dapk.st.core.ProvidableModule
|
import app.dapk.st.core.ProvidableModule
|
||||||
import app.dapk.st.directory.DirectoryViewModel
|
import app.dapk.st.directory.DirectoryViewModel
|
||||||
import app.dapk.st.domain.StoreModule
|
import app.dapk.st.domain.StoreModule
|
||||||
|
@ -11,7 +10,7 @@ import app.dapk.st.profile.ProfileViewModel
|
||||||
class HomeModule(
|
class HomeModule(
|
||||||
private val chatEngine: ChatEngine,
|
private val chatEngine: ChatEngine,
|
||||||
private val storeModule: StoreModule,
|
private val storeModule: StoreModule,
|
||||||
private val buildMeta: BuildMeta,
|
val betaVersionUpgradeUseCase: BetaVersionUpgradeUseCase,
|
||||||
) : ProvidableModule {
|
) : ProvidableModule {
|
||||||
|
|
||||||
fun homeViewModel(directory: DirectoryViewModel, login: LoginViewModel, profileViewModel: ProfileViewModel): HomeViewModel {
|
fun homeViewModel(directory: DirectoryViewModel, login: LoginViewModel, profileViewModel: ProfileViewModel): HomeViewModel {
|
||||||
|
@ -22,10 +21,7 @@ class HomeModule(
|
||||||
login,
|
login,
|
||||||
profileViewModel,
|
profileViewModel,
|
||||||
storeModule.cacheCleaner(),
|
storeModule.cacheCleaner(),
|
||||||
BetaVersionUpgradeUseCase(
|
betaVersionUpgradeUseCase,
|
||||||
storeModule.applicationStore(),
|
|
||||||
buildMeta,
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@ import app.dapk.st.profile.ProfileViewModel
|
||||||
import app.dapk.st.viewmodel.DapkViewModel
|
import app.dapk.st.viewmodel.DapkViewModel
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.cancel
|
|
||||||
import kotlinx.coroutines.flow.first
|
import kotlinx.coroutines.flow.first
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
|
@ -87,6 +86,7 @@ class HomeViewModel(
|
||||||
fun clearCache() {
|
fun clearCache() {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
cacheCleaner.cleanCache(removeCredentials = false)
|
cacheCleaner.cleanCache(removeCredentials = false)
|
||||||
|
betaVersionUpgradeUseCase.notifyUpgraded()
|
||||||
_events.emit(HomeEvent.Relaunch)
|
_events.emit(HomeEvent.Relaunch)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue