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

Commit 8463f689 authored by Nishant D's avatar Nishant D
Browse files

Merge branch '1347-improve-local-cache' into 1401-refactor-network-layer

parents 8c7bd53f 6d2b03df
Loading
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -32,11 +32,11 @@ android {
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
        sourceCompatibility JavaVersion.VERSION_11
        targetCompatibility JavaVersion.VERSION_11
    }
    kotlinOptions {
        jvmTarget = '17'
        jvmTarget = '11'
    }
}

+3 −3
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@ package app.lounge

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import app.lounge.storage.cache.PersistedConfiguration
import app.lounge.storage.cache.PersistentConfiguration
import app.lounge.storage.cache.PersistenceKey
import app.lounge.storage.cache.configurations
import com.google.gson.Gson
@@ -15,7 +15,7 @@ import kotlin.reflect.KClassifier
@RunWith(AndroidJUnit4::class)
class PersistentStorageTest {

    private lateinit var testConfiguration: PersistedConfiguration
    private lateinit var testConfiguration: PersistentConfiguration

    @Before
    fun setupPersistentConfiguration(){
@@ -92,7 +92,7 @@ private inline fun <reified T : Any> T.getPropertyReturnType(name: String): KCla
        .firstOrNull { it.name == name }
        ?.returnType
        ?.classifier
private fun PersistedConfiguration.evaluateValue(classifier: KClassifier?, key: PersistenceKey) {
private fun PersistentConfiguration.evaluateValue(classifier: KClassifier?, key: PersistenceKey) {
    when(classifier){
        Int::class -> Assert.assertEquals(
            "Expected to be `$testIntValue`", testIntValue, this.callMethod(key.name) as Int)
+18 −31
Original line number Diff line number Diff line
@@ -4,13 +4,7 @@ import android.content.Context
import kotlin.reflect.KProperty


//region Setter Accessors (primarily used for setting)

val Context.configurations: PersistedConfiguration get() = PersistedConfiguration(context = this)

//endregion

// region - Persistence Configuration
val Context.configurations: PersistentConfiguration get() = PersistentConfiguration(context = this)

internal enum class PersistenceKey {
    updateInstallAuto,
@@ -28,26 +22,22 @@ internal enum class PersistenceKey {
    tosversion
}

class PersistedConfiguration(context: Context) {
    var updateInstallAuto by context.persisted(PersistenceKey.updateInstallAuto, false)
    var updateCheckIntervals by context.persisted(PersistenceKey.updateCheckIntervals, 24)
    var updateAppsFromOtherStores by context.persisted(PersistenceKey.updateAppsFromOtherStores, false)
    var showAllApplications by context.persisted(PersistenceKey.showAllApplications, true)
    var showPWAApplications by context.persisted(PersistenceKey.showPWAApplications, true)
    var showFOSSApplications by context.persisted(PersistenceKey.showFOSSApplications, true)
    var authData by context.persisted(PersistenceKey.authData, "")
    var email by context.persisted(PersistenceKey.email, "")
    var oauthtoken by context.persisted(PersistenceKey.oauthtoken, "")
    var userType by context.persisted(PersistenceKey.userType, "")
    var tocStatus by context.persisted(PersistenceKey.tocStatus, false)
    var tosversion by context.persisted(PersistenceKey.tosversion, "")
class PersistentConfiguration(context: Context) {
    var updateInstallAuto by context.persistent(PersistenceKey.updateInstallAuto, false)
    var updateCheckIntervals by context.persistent(PersistenceKey.updateCheckIntervals, 24)
    var updateAppsFromOtherStores by context.persistent(PersistenceKey.updateAppsFromOtherStores, false)
    var showAllApplications by context.persistent(PersistenceKey.showAllApplications, true)
    var showPWAApplications by context.persistent(PersistenceKey.showPWAApplications, true)
    var showFOSSApplications by context.persistent(PersistenceKey.showFOSSApplications, true)
    var authData by context.persistent(PersistenceKey.authData, "")
    var email by context.persistent(PersistenceKey.email, "")
    var oauthtoken by context.persistent(PersistenceKey.oauthtoken, "")
    var userType by context.persistent(PersistenceKey.userType, "")
    var tocStatus by context.persistent(PersistenceKey.tocStatus, false)
    var tosversion by context.persistent(PersistenceKey.tosversion, "")
}

// endregion

//region - Persistence (in shared preferences)

private class PersistedItem<T>(
internal  class PersistentItem<T>(
    context: Context,
    val key: PersistenceKey,
    var defaultValue: T
@@ -90,9 +80,6 @@ private class PersistedItem<T>(
    }
}


private fun <T> Context.persisted(key: PersistenceKey, defaultValue: T) : PersistedItem<T> {
    return PersistedItem(context = this, key = key, defaultValue = defaultValue)
internal fun <T> Context.persistent(key: PersistenceKey, defaultValue: T) : PersistentItem<T> {
    return PersistentItem(context = this, key = key, defaultValue = defaultValue)
}
 No newline at end of file

//endregion
 No newline at end of file