diff --git a/app/src/main/java/foundation/e/apps/AppLoungeApplication.kt b/app/src/main/java/foundation/e/apps/AppLoungeApplication.kt index 4ecf0bda4e915c29b550f70cc795cf4b39f778db..57948f010b28ceee7e3d33f79a6dc87c135aa80f 100644 --- a/app/src/main/java/foundation/e/apps/AppLoungeApplication.kt +++ b/app/src/main/java/foundation/e/apps/AppLoungeApplication.kt @@ -24,7 +24,11 @@ import androidx.work.Configuration import dagger.hilt.android.HiltAndroidApp import foundation.e.apps.manager.pkg.PkgManagerBR import foundation.e.apps.manager.pkg.PkgManagerModule +import foundation.e.apps.setup.tos.TOS_VERSION +import foundation.e.apps.utils.modules.DataStoreModule import kotlinx.coroutines.DelicateCoroutinesApi +import kotlinx.coroutines.MainScope +import kotlinx.coroutines.launch import java.util.concurrent.Executors import javax.inject.Inject @@ -34,15 +38,26 @@ class AppLoungeApplication : Application(), Configuration.Provider { @Inject lateinit var pkgManagerModule: PkgManagerModule + @Inject lateinit var workerFactory: HiltWorkerFactory + @Inject + lateinit var dataStoreModule: DataStoreModule + override fun onCreate() { super.onCreate() // Register broadcast receiver for package manager val pkgManagerBR = object : PkgManagerBR() {} registerReceiver(pkgManagerBR, pkgManagerModule.getFilter()) + + val currentVersion = dataStoreModule.getTOSVersion() + if (!currentVersion.contentEquals(TOS_VERSION)) { + MainScope().launch { + dataStoreModule.saveTOCStatus(false, "") + } + } } override fun getWorkManagerConfiguration() = diff --git a/app/src/main/java/foundation/e/apps/setup/tos/TOSViewModel.kt b/app/src/main/java/foundation/e/apps/setup/tos/TOSViewModel.kt index 742ea921128c87aa48d7192d48beb221a75911e4..c9a26fd4245c571ba92cc0ef416b963388ae6ac0 100644 --- a/app/src/main/java/foundation/e/apps/setup/tos/TOSViewModel.kt +++ b/app/src/main/java/foundation/e/apps/setup/tos/TOSViewModel.kt @@ -18,7 +18,9 @@ class TOSViewModel @Inject constructor( fun saveTOCStatus(status: Boolean) { viewModelScope.launch { - dataStoreModule.saveTOCStatus(status) + dataStoreModule.saveTOCStatus(status, TOS_VERSION) } } } + +const val TOS_VERSION = "1.0.3" diff --git a/app/src/main/java/foundation/e/apps/utils/modules/DataStoreModule.kt b/app/src/main/java/foundation/e/apps/utils/modules/DataStoreModule.kt index bccf26392ff9cb13e0380d0f067f695f8a20e762..5fa284abace01730e4b898f082a72a9690d6ddbc 100644 --- a/app/src/main/java/foundation/e/apps/utils/modules/DataStoreModule.kt +++ b/app/src/main/java/foundation/e/apps/utils/modules/DataStoreModule.kt @@ -48,12 +48,14 @@ class DataStoreModule @Inject constructor( private val OAUTHTOKEN = stringPreferencesKey("oauthtoken") private val USERTYPE = stringPreferencesKey("userType") private val TOCSTATUS = booleanPreferencesKey("tocStatus") + private val TOSVERSION = stringPreferencesKey("tosversion") val authData = context.dataStore.data.map { it[AUTHDATA] ?: "" } val emailData = context.dataStore.data.map { it[EMAIL] ?: "" } val aasToken = context.dataStore.data.map { it[OAUTHTOKEN] ?: "" } val userType = context.dataStore.data.map { it[USERTYPE] ?: "" } val tocStatus = context.dataStore.data.map { it[TOCSTATUS] ?: false } + val tosVersion = context.dataStore.data.map { it[TOSVERSION] ?: "" } /** * Allows to save gplay API token data into datastore @@ -88,9 +90,16 @@ class DataStoreModule @Inject constructor( /** * TOC status */ - suspend fun saveTOCStatus(status: Boolean) { + suspend fun saveTOCStatus(status: Boolean, tosVersion: String) { context.dataStore.edit { it[TOCSTATUS] = status + it[TOSVERSION] = tosVersion + } + } + + fun getTOSVersion(): String { + return runBlocking { + tosVersion.first() } }