diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
index ab75be24..f7a03145 100644
--- a/.idea/codeStyles/Project.xml
+++ b/.idea/codeStyles/Project.xml
@@ -4,6 +4,13 @@
+
+
+
+
+
+
+
diff --git a/.idea/dictionaries/Kuba.xml b/.idea/dictionaries/Kuba.xml
index aba38775..7959d9aa 100644
--- a/.idea/dictionaries/Kuba.xml
+++ b/.idea/dictionaries/Kuba.xml
@@ -5,6 +5,7 @@
ciasteczko
csrf
edziennik
+ eggfall
elearning
gson
hebe
diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/App.kt b/app/src/main/java/pl/szczodrzynski/edziennik/App.kt
index 1dcea55b..4a68cac6 100644
--- a/app/src/main/java/pl/szczodrzynski/edziennik/App.kt
+++ b/app/src/main/java/pl/szczodrzynski/edziennik/App.kt
@@ -12,6 +12,7 @@ import android.graphics.drawable.Icon
import android.os.Build
import android.provider.Settings
import android.util.Log
+import android.widget.Toast
import androidx.appcompat.app.AppCompatDelegate
import androidx.multidex.MultiDexApplication
import androidx.work.Configuration
@@ -31,6 +32,7 @@ import kotlinx.coroutines.*
import me.leolin.shortcutbadger.ShortcutBadger
import okhttp3.OkHttpClient
import org.greenrobot.eventbus.EventBus
+import pl.szczodrzynski.edziennik.config.AppData
import pl.szczodrzynski.edziennik.config.Config
import pl.szczodrzynski.edziennik.data.api.events.ProfileListEmptyEvent
import pl.szczodrzynski.edziennik.data.api.szkolny.SzkolnyApi
@@ -48,18 +50,27 @@ import pl.szczodrzynski.edziennik.sync.SyncWorker
import pl.szczodrzynski.edziennik.sync.UpdateWorker
import pl.szczodrzynski.edziennik.ui.base.CrashActivity
import pl.szczodrzynski.edziennik.ui.base.enums.NavTarget
-import pl.szczodrzynski.edziennik.utils.*
+import pl.szczodrzynski.edziennik.utils.DebugLogFormat
+import pl.szczodrzynski.edziennik.utils.PermissionChecker
+import pl.szczodrzynski.edziennik.utils.Themes
+import pl.szczodrzynski.edziennik.utils.Utils
import pl.szczodrzynski.edziennik.utils.Utils.d
import pl.szczodrzynski.edziennik.utils.managers.*
import java.util.concurrent.TimeUnit
import kotlin.coroutines.CoroutineContext
+import kotlin.system.exitProcess
class App : MultiDexApplication(), Configuration.Provider, CoroutineScope {
companion object {
@Volatile
lateinit var db: AppDb
+ private set
lateinit var config: Config
+ // private set // for LabFragment
lateinit var profile: Profile
+ private set
+ lateinit var data: AppData
+ private set
val profileId
get() = profile.id
@@ -90,6 +101,8 @@ class App : MultiDexApplication(), Configuration.Provider, CoroutineScope {
get() = App.profile
val profileId
get() = App.profileId
+ val data
+ get() = App.data
private val job = Job()
override val coroutineContext: CoroutineContext
@@ -124,9 +137,6 @@ class App : MultiDexApplication(), Configuration.Provider, CoroutineScope {
SSLProviderInstaller.enableSupportedTls(builder, enableCleartext = true)
if (devMode) {
- HyperLog.initialize(this)
- HyperLog.setLogLevel(Log.VERBOSE)
- HyperLog.setLogFormat(DebugLogFormat(this))
if (enableChucker) {
val chuckerCollector = ChuckerCollector(this, true, RetentionManager.Period.ONE_HOUR)
val chuckerInterceptor = ChuckerInterceptor(this, chuckerCollector)
@@ -180,16 +190,24 @@ class App : MultiDexApplication(), Configuration.Provider, CoroutineScope {
Iconics.init(applicationContext)
Iconics.respectFontBoundsDefault = true
+ if (devMode) {
+ HyperLog.initialize(this)
+ HyperLog.setLogLevel(Log.VERBOSE)
+ HyperLog.setLogFormat(DebugLogFormat(this))
+ }
+
// initialize companion object values
+ AppData.read(this)
App.db = AppDb(this)
App.config = Config(App.db)
- App.profile = Profile(0, 0, LoginType.TEMPLATE, "")
debugMode = BuildConfig.DEBUG
devMode = config.devMode ?: debugMode
enableChucker = config.enableChucker ?: devMode
if (!profileLoadById(config.lastProfileId)) {
- db.profileDao().firstId?.let { profileLoadById(it) }
+ val success = db.profileDao().firstId?.let { profileLoadById(it) }
+ if (success != true)
+ profileLoad(Profile(0, 0, LoginType.TEMPLATE, ""))
}
buildHttp()
@@ -381,10 +399,22 @@ class App : MultiDexApplication(), Configuration.Provider, CoroutineScope {
}
}
+ fun profileLoad(profile: Profile) {
+ App.profile = profile
+ App.config.lastProfileId = profile.id
+ try {
+ App.data = AppData.get(profile.loginStoreType)
+ d("App", "Loaded AppData: ${App.data}")
+ } catch (e: Exception) {
+ Log.e("App", "Cannot load AppData", e)
+ Toast.makeText(this, R.string.app_cannot_load_data, Toast.LENGTH_LONG).show()
+ exitProcess(0)
+ }
+ }
+
private fun profileLoadById(profileId: Int): Boolean {
db.profileDao().getByIdNow(profileId)?.also {
- App.profile = it
- App.config.lastProfileId = it.id
+ profileLoad(it)
return true
}
return false
diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/MainActivity.kt b/app/src/main/java/pl/szczodrzynski/edziennik/MainActivity.kt
index e0e6cd3e..2a819c7b 100644
--- a/app/src/main/java/pl/szczodrzynski/edziennik/MainActivity.kt
+++ b/app/src/main/java/pl/szczodrzynski/edziennik/MainActivity.kt
@@ -42,7 +42,6 @@ import pl.szczodrzynski.edziennik.data.db.entity.Message
import pl.szczodrzynski.edziennik.data.db.entity.Metadata.*
import pl.szczodrzynski.edziennik.data.db.entity.Profile
import pl.szczodrzynski.edziennik.data.db.enums.FeatureType
-import pl.szczodrzynski.edziennik.data.db.enums.LoginType
import pl.szczodrzynski.edziennik.databinding.ActivitySzkolnyBinding
import pl.szczodrzynski.edziennik.ext.*
import pl.szczodrzynski.edziennik.sync.AppManagerDetectedEvent
@@ -427,7 +426,7 @@ class MainActivity : AppCompatActivity(), CoroutineScope {
launch {
withContext(Dispatchers.Default) {
app.db.profileDao().allNow.forEach { profile ->
- if (profile.loginStoreType != LoginType.LIBRUS)
+ if (!profile.getAppData().uiConfig.enableMarkAsReadAnnouncements)
app.db.metadataDao()
.setAllSeenExceptMessagesAndAnnouncements(profile.id, true)
else
@@ -695,7 +694,7 @@ class MainActivity : AppCompatActivity(), CoroutineScope {
}
d(TAG, "}")
- val intentProfileId = extras.getIntOrNull("profileId")
+ val intentProfileId = extras.getIntOrNull("profileId").takePositive()
var intentNavTarget = extras.getIntOrNull("fragmentId").asNavTargetOrNull()
if (extras?.containsKey("action") == true) {
@@ -743,8 +742,8 @@ class MainActivity : AppCompatActivity(), CoroutineScope {
}
if (extras?.containsKey("reloadProfileId") == true) {
- val reloadProfileId = extras.getIntOrNull("reloadProfileId")
- if (reloadProfileId == -1 || app.profile.id == reloadProfileId) {
+ val reloadProfileId = extras.getIntOrNull("reloadProfileId").takePositive()
+ if (reloadProfileId == null || app.profile.id == reloadProfileId) {
reloadTarget()
return
}
@@ -767,7 +766,7 @@ class MainActivity : AppCompatActivity(), CoroutineScope {
navTarget = intentNavTarget,
args = extras,
)
- intentProfileId != -1 -> navigate(
+ intentProfileId != null -> navigate(
profileId = intentProfileId,
navTarget = intentNavTarget,
args = extras,
@@ -776,6 +775,7 @@ class MainActivity : AppCompatActivity(), CoroutineScope {
navTarget = intentNavTarget,
args = extras,
)
+ navLoading -> navigate()
else -> drawer.currentProfile = app.profile.id
}
navLoading = false
@@ -923,7 +923,8 @@ class MainActivity : AppCompatActivity(), CoroutineScope {
}
if (profileChanged) {
- App.profile = profile
+ if (App.profileId != profile.id)
+ app.profileLoad(profile)
MessagesFragment.pageSelection = -1
// set new drawer items for this profile
setDrawerItems()
diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/config/AbstractConfig.kt b/app/src/main/java/pl/szczodrzynski/edziennik/config/AbstractConfig.kt
deleted file mode 100644
index d597a119..00000000
--- a/app/src/main/java/pl/szczodrzynski/edziennik/config/AbstractConfig.kt
+++ /dev/null
@@ -1,9 +0,0 @@
-/*
- * Copyright (c) Kuba Szczodrzyński 2019-11-27.
- */
-
-package pl.szczodrzynski.edziennik.config
-
-interface AbstractConfig {
- fun set(key: String, value: String?)
-}
\ No newline at end of file
diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/config/AppData.kt b/app/src/main/java/pl/szczodrzynski/edziennik/config/AppData.kt
new file mode 100644
index 00000000..6f72b82e
--- /dev/null
+++ b/app/src/main/java/pl/szczodrzynski/edziennik/config/AppData.kt
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) Kuba Szczodrzyński 2022-10-21.
+ */
+
+package pl.szczodrzynski.edziennik.config
+
+import com.google.gson.Gson
+import com.google.gson.JsonObject
+import com.google.gson.JsonParser
+import com.google.gson.stream.JsonReader
+import pl.szczodrzynski.edziennik.App
+import pl.szczodrzynski.edziennik.R
+import pl.szczodrzynski.edziennik.data.db.enums.LoginType
+import pl.szczodrzynski.edziennik.ext.getJsonObject
+import pl.szczodrzynski.edziennik.ext.mergeWith
+import pl.szczodrzynski.edziennik.utils.managers.TextStylingManager.HtmlMode
+
+data class AppData(
+ val configOverrides: Map,
+ val messagesConfig: MessagesConfig,
+ val uiConfig: UIConfig,
+ val eventTypes: List,
+) {
+ companion object {
+ private var data: JsonObject? = null
+ private val appData = mutableMapOf()
+
+ fun read(app: App) {
+ val res = app.resources.openRawResource(R.raw.app_data)
+ data = JsonParser.parseReader(JsonReader(res.reader())).asJsonObject
+ }
+
+ fun get(loginType: LoginType): AppData {
+ if (loginType in appData)
+ return appData.getValue(loginType)
+ val json = data?.getJsonObject("base")?.deepCopy()
+ ?: throw NoSuchElementException("Base data not found")
+ val overrides = setOf(loginType, loginType.schoolType)
+ for (overrideType in overrides) {
+ val override = data?.getJsonObject(overrideType.name.lowercase()) ?: continue
+ json.mergeWith(override)
+ }
+ val value = Gson().fromJson(json, AppData::class.java)
+ appData[loginType] = value
+ return value
+ }
+ }
+
+ data class MessagesConfig(
+ val subjectLength: Int?,
+ val bodyLength: Int?,
+ val textStyling: Boolean,
+ val syncRecipientList: Boolean,
+ val htmlMode: HtmlMode,
+ val needsReadStatus: Boolean,
+ )
+
+ data class UIConfig(
+ val lessonHeight: Int,
+ val enableMarkAsReadAnnouncements: Boolean,
+ val enableNoticePoints: Boolean,
+ )
+
+ data class EventType(
+ val id: Int,
+ val color: String,
+ val name: String,
+ )
+}
diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/config/BaseConfig.kt b/app/src/main/java/pl/szczodrzynski/edziennik/config/BaseConfig.kt
new file mode 100644
index 00000000..ac3a8af9
--- /dev/null
+++ b/app/src/main/java/pl/szczodrzynski/edziennik/config/BaseConfig.kt
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) Kuba Szczodrzyński 2019-11-27.
+ */
+
+package pl.szczodrzynski.edziennik.config
+
+import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.Job
+import kotlinx.coroutines.launch
+import pl.szczodrzynski.edziennik.config.db.ConfigEntry
+import pl.szczodrzynski.edziennik.data.db.AppDb
+import pl.szczodrzynski.edziennik.ext.takePositive
+import kotlin.coroutines.CoroutineContext
+
+abstract class BaseConfig(
+ val db: AppDb,
+ val profileId: Int? = null,
+ protected var entries: List? = null,
+) : CoroutineScope {
+
+ private val job = Job()
+ override val coroutineContext: CoroutineContext
+ get() = job + Dispatchers.Default
+
+ val values = hashMapOf()
+
+ init {
+ if (entries == null)
+ entries = db.configDao().getAllNow()
+ values.clear()
+ for ((profileId, key, value) in entries!!) {
+ if (profileId.takePositive() != this.profileId)
+ continue
+ values[key] = value
+ }
+ }
+
+ fun set(key: String, value: String?) {
+ values[key] = value
+ launch(Dispatchers.IO) {
+ db.configDao().add(ConfigEntry(profileId ?: -1, key, value))
+ }
+ }
+}
diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/config/Config.kt b/app/src/main/java/pl/szczodrzynski/edziennik/config/Config.kt
index e29d93ad..f065a97e 100644
--- a/app/src/main/java/pl/szczodrzynski/edziennik/config/Config.kt
+++ b/app/src/main/java/pl/szczodrzynski/edziennik/config/Config.kt
@@ -5,151 +5,59 @@
package pl.szczodrzynski.edziennik.config
import com.google.gson.JsonObject
-import kotlinx.coroutines.CoroutineScope
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.Job
-import kotlinx.coroutines.launch
import pl.szczodrzynski.edziennik.App
import pl.szczodrzynski.edziennik.BuildConfig
-import pl.szczodrzynski.edziennik.config.db.ConfigEntry
import pl.szczodrzynski.edziennik.config.utils.*
import pl.szczodrzynski.edziennik.data.api.szkolny.response.Update
import pl.szczodrzynski.edziennik.data.db.AppDb
-import kotlin.coroutines.CoroutineContext
-class Config(val db: AppDb) : CoroutineScope, AbstractConfig {
+@Suppress("RemoveExplicitTypeArguments")
+class Config(db: AppDb) : BaseConfig(db) {
companion object {
const val DATA_VERSION = 12
}
- private val job = Job()
- override val coroutineContext: CoroutineContext
- get() = job + Dispatchers.Default
-
- val values: HashMap = hashMapOf()
+ private val profileConfigs: HashMap = hashMapOf()
val ui by lazy { ConfigUI(this) }
val sync by lazy { ConfigSync(this) }
val timetable by lazy { ConfigTimetable(this) }
val grades by lazy { ConfigGrades(this) }
- private var mDataVersion: Int? = null
- var dataVersion: Int
- get() { mDataVersion = mDataVersion ?: values.get("dataVersion", 0); return mDataVersion ?: 0 }
- set(value) { set("dataVersion", value); mDataVersion = value }
+ var dataVersion by config(0)
+ var hash by config("")
- private var mHash: String? = null
- var hash: String
- get() { mHash = mHash ?: values.get("hash", ""); return mHash ?: "" }
- set(value) { set("hash", value); mHash = value }
+ var lastProfileId by config(0)
+ var loginFinished by config(false)
+ var privacyPolicyAccepted by config(false)
+ var update by config(null)
+ var updatesChannel by config("release")
- private var mLastProfileId: Int? = null
- var lastProfileId: Int
- get() { mLastProfileId = mLastProfileId ?: values.get("lastProfileId", 0); return mLastProfileId ?: 0 }
- set(value) { set("lastProfileId", value); mLastProfileId = value }
+ var devMode by config(null)
+ var devModePassword by config(null)
+ var enableChucker by config(null)
- private var mUpdatesChannel: String? = null
- var updatesChannel: String
- get() { mUpdatesChannel = mUpdatesChannel ?: values.get("updatesChannel", "release"); return mUpdatesChannel ?: "release" }
- set(value) { set("updatesChannel", value); mUpdatesChannel = value }
- private var mUpdate: Update? = null
- var update: Update?
- get() { mUpdate = mUpdate ?: values.get("update", null as Update?); return mUpdate ?: null as Update? }
- set(value) { set("update", value); mUpdate = value }
+ var apiAvailabilityCheck by config(true)
+ var apiInvalidCert by config(null)
+ var appInstalledTime by config(0L)
+ var appRateSnackbarTime by config(0L)
+ var appVersion by config(BuildConfig.VERSION_CODE)
+ var validation by config(null, "buildValidation")
- private var mAppVersion: Int? = null
- var appVersion: Int
- get() { mAppVersion = mAppVersion ?: values.get("appVersion", BuildConfig.VERSION_CODE); return mAppVersion ?: BuildConfig.VERSION_CODE }
- set(value) { set("appVersion", value); mAppVersion = value }
+ var archiverEnabled by config(true)
+ var runSync by config(false)
+ var widgetConfigs by config { JsonObject() }
- private var mLoginFinished: Boolean? = null
- var loginFinished: Boolean
- get() { mLoginFinished = mLoginFinished ?: values.get("loginFinished", false); return mLoginFinished ?: false }
- set(value) { set("loginFinished", value); mLoginFinished = value }
-
- private var mPrivacyPolicyAccepted: Boolean? = null
- var privacyPolicyAccepted: Boolean
- get() { mPrivacyPolicyAccepted = mPrivacyPolicyAccepted ?: values.get("privacyPolicyAccepted", false); return mPrivacyPolicyAccepted ?: false }
- set(value) { set("privacyPolicyAccepted", value); mPrivacyPolicyAccepted = value }
-
- private var mDevMode: Boolean? = null
- var devMode: Boolean?
- get() { mDevMode = mDevMode ?: values.getBooleanOrNull("debugMode"); return mDevMode }
- set(value) { set("debugMode", value?.toString()); mDevMode = value }
-
- private var mEnableChucker: Boolean? = null
- var enableChucker: Boolean?
- get() { mEnableChucker = mEnableChucker ?: values.getBooleanOrNull("enableChucker"); return mEnableChucker }
- set(value) { set("enableChucker", value?.toString()); mEnableChucker = value }
-
- private var mDevModePassword: String? = null
- var devModePassword: String?
- get() { mDevModePassword = mDevModePassword ?: values.get("devModePassword", null as String?); return mDevModePassword }
- set(value) { set("devModePassword", value); mDevModePassword = value }
-
- private var mAppInstalledTime: Long? = null
- var appInstalledTime: Long
- get() { mAppInstalledTime = mAppInstalledTime ?: values.get("appInstalledTime", 0L); return mAppInstalledTime ?: 0L }
- set(value) { set("appInstalledTime", value); mAppInstalledTime = value }
-
- private var mAppRateSnackbarTime: Long? = null
- var appRateSnackbarTime: Long
- get() { mAppRateSnackbarTime = mAppRateSnackbarTime ?: values.get("appRateSnackbarTime", 0L); return mAppRateSnackbarTime ?: 0L }
- set(value) { set("appRateSnackbarTime", value); mAppRateSnackbarTime = value }
-
- private var mRunSync: Boolean? = null
- var runSync: Boolean
- get() { mRunSync = mRunSync ?: values.get("runSync", false); return mRunSync ?: false }
- set(value) { set("runSync", value); mRunSync = value }
-
- private var mWidgetConfigs: JsonObject? = null
- var widgetConfigs: JsonObject
- get() { mWidgetConfigs = mWidgetConfigs ?: values.get("widgetConfigs", JsonObject()); return mWidgetConfigs ?: JsonObject() }
- set(value) { set("widgetConfigs", value); mWidgetConfigs = value }
-
- private var mArchiverEnabled: Boolean? = null
- var archiverEnabled: Boolean
- get() { mArchiverEnabled = mArchiverEnabled ?: values.get("archiverEnabled", true); return mArchiverEnabled ?: true }
- set(value) { set("archiverEnabled", value); mArchiverEnabled = value }
-
- private var mValidation: String? = null
- var validation: String?
- get() { mValidation = mValidation ?: values["buildValidation"]; return mValidation }
- set(value) { set("buildValidation", value); mValidation = value }
-
- private var mApiInvalidCert: String? = null
- var apiInvalidCert: String?
- get() { mApiInvalidCert = mApiInvalidCert ?: values["apiInvalidCert"]; return mApiInvalidCert }
- set(value) { set("apiInvalidCert", value); mApiInvalidCert = value }
-
- private var mApiAvailabilityCheck: Boolean? = null
- var apiAvailabilityCheck: Boolean
- get() { mApiAvailabilityCheck = mApiAvailabilityCheck ?: values.get("apiAvailabilityCheck", true); return mApiAvailabilityCheck ?: true }
- set(value) { set("apiAvailabilityCheck", value); mApiAvailabilityCheck = value }
-
- private var rawEntries: List = db.configDao().getAllNow()
- private val profileConfigs: HashMap = hashMapOf()
- init {
- rawEntries.toHashMap(-1, values)
- }
fun migrate(app: App) {
if (dataVersion < DATA_VERSION)
ConfigMigration(app, this)
}
+
fun getFor(profileId: Int): ProfileConfig {
- return profileConfigs[profileId] ?: ProfileConfig(db, profileId, db.configDao().getAllNow(profileId)).also {
+ return profileConfigs[profileId] ?: ProfileConfig(db, profileId, entries).also {
profileConfigs[profileId] = it
}
}
+
fun forProfile() = getFor(App.profileId)
-
- fun setProfile(profileId: Int) {
- }
-
- override fun set(key: String, value: String?) {
- values[key] = value
- launch {
- db.configDao().add(ConfigEntry(-1, key, value))
- }
- }
}
diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/config/ConfigGrades.kt b/app/src/main/java/pl/szczodrzynski/edziennik/config/ConfigGrades.kt
index 267ec322..a28dcc3d 100644
--- a/app/src/main/java/pl/szczodrzynski/edziennik/config/ConfigGrades.kt
+++ b/app/src/main/java/pl/szczodrzynski/edziennik/config/ConfigGrades.kt
@@ -4,13 +4,10 @@
package pl.szczodrzynski.edziennik.config
-import pl.szczodrzynski.edziennik.config.utils.get
-import pl.szczodrzynski.edziennik.config.utils.set
-import pl.szczodrzynski.edziennik.utils.managers.GradesManager
+import pl.szczodrzynski.edziennik.utils.managers.GradesManager.Companion.ORDER_BY_DATE_DESC
-class ConfigGrades(private val config: Config) {
- private var mOrderBy: Int? = null
- var orderBy: Int
- get() { mOrderBy = mOrderBy ?: config.values.get("gradesOrderBy", 0); return mOrderBy ?: GradesManager.ORDER_BY_DATE_DESC }
- set(value) { config.set("gradesOrderBy", value); mOrderBy = value }
+@Suppress("RemoveExplicitTypeArguments")
+class ConfigGrades(base: Config) {
+
+ var orderBy by base.config("gradesOrderBy", ORDER_BY_DATE_DESC)
}
diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/config/ConfigSync.kt b/app/src/main/java/pl/szczodrzynski/edziennik/config/ConfigSync.kt
index 387e5cf7..6688838b 100644
--- a/app/src/main/java/pl/szczodrzynski/edziennik/config/ConfigSync.kt
+++ b/app/src/main/java/pl/szczodrzynski/edziennik/config/ConfigSync.kt
@@ -4,139 +4,53 @@
package pl.szczodrzynski.edziennik.config
-import com.google.gson.Gson
-import com.google.gson.reflect.TypeToken
import pl.szczodrzynski.edziennik.BuildConfig
-import pl.szczodrzynski.edziennik.config.utils.get
-import pl.szczodrzynski.edziennik.config.utils.getIntList
-import pl.szczodrzynski.edziennik.config.utils.set
-import pl.szczodrzynski.edziennik.config.utils.setMap
import pl.szczodrzynski.edziennik.data.api.szkolny.response.RegisterAvailabilityStatus
+import pl.szczodrzynski.edziennik.ext.HOUR
import pl.szczodrzynski.edziennik.utils.models.Time
-class ConfigSync(private val config: Config) {
- private val gson = Gson()
+@Suppress("RemoveExplicitTypeArguments")
+class ConfigSync(base: Config) {
- private var mDontShowAppManagerDialog: Boolean? = null
- var dontShowAppManagerDialog: Boolean
- get() { mDontShowAppManagerDialog = mDontShowAppManagerDialog ?: config.values.get("dontShowAppManagerDialog", false); return mDontShowAppManagerDialog ?: false }
- set(value) { config.set("dontShowAppManagerDialog", value); mDontShowAppManagerDialog = value }
+ var enabled by base.config("syncEnabled", true)
+ var interval by base.config("syncInterval", 1 * HOUR.toInt())
+ var onlyWifi by base.config("syncOnlyWifi", false)
- private var mSyncEnabled: Boolean? = null
- var enabled: Boolean
- get() { mSyncEnabled = mSyncEnabled ?: config.values.get("syncEnabled", true); return mSyncEnabled ?: true }
- set(value) { config.set("syncEnabled", value); mSyncEnabled = value }
+ var dontShowAppManagerDialog by base.config(false)
+ var lastAppSync by base.config(0L)
+ var notifyAboutUpdates by base.config(true)
+ var webPushEnabled by base.config(true)
- private var mWebPushEnabled: Boolean? = null
- var webPushEnabled: Boolean
- get() { mWebPushEnabled = mWebPushEnabled ?: config.values.get("webPushEnabled", true); return mWebPushEnabled ?: true }
- set(value) { config.set("webPushEnabled", value); mWebPushEnabled = value }
+ // Quiet Hours
+ var quietHoursEnabled by base.config(false)
+ var quietHoursStart by base.config