From 698ff66b5161ab4f9dee7e72cab1562014b15e6f Mon Sep 17 00:00:00 2001 From: Hasib Prince Date: Thu, 5 May 2022 13:07:43 +0600 Subject: [PATCH] App Lounge: force accept tos on update --- .../foundation/e/apps/AppLoungeApplication.kt | 15 +++++++++++++++ .../foundation/e/apps/setup/tos/TOSViewModel.kt | 4 +++- .../e/apps/utils/modules/DataStoreModule.kt | 11 ++++++++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/AppLoungeApplication.kt b/app/src/main/java/foundation/e/apps/AppLoungeApplication.kt index 4ecf0bda4..57948f010 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 742ea9211..c9a26fd42 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 bccf26392..5fa284aba 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() } } -- GitLab