Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2fedf8e3 authored by Hasib Prince's avatar Hasib Prince
Browse files

Merge branch '200-tos_update' into main

parents 73054f19 698ff66b
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -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() =
+3 −1
Original line number Diff line number Diff line
@@ -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"
+10 −1
Original line number Diff line number Diff line
@@ -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()
        }
    }