diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/App.kt b/app/src/main/java/pl/szczodrzynski/edziennik/App.kt index 4db63386..b3ec1cc3 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/App.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/App.kt @@ -175,8 +175,8 @@ class App : MultiDexApplication(), Configuration.Provider, CoroutineScope { App.config = Config(App.db) App.profile = Profile(0, 0, 0, "") debugMode = BuildConfig.DEBUG - devMode = config.debugMode || debugMode - enableChucker = config.enableChucker || devMode + devMode = config.devMode ?: debugMode + enableChucker = config.enableChucker ?: devMode if (!profileLoadById(config.lastProfileId)) { db.profileDao().firstId?.let { profileLoadById(it) } 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 8c9270f2..e29d93ad 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/config/Config.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/config/Config.kt @@ -12,10 +12,7 @@ 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.ConfigMigration -import pl.szczodrzynski.edziennik.config.utils.get -import pl.szczodrzynski.edziennik.config.utils.set -import pl.szczodrzynski.edziennik.config.utils.toHashMap +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 @@ -75,15 +72,15 @@ class Config(val db: AppDb) : CoroutineScope, AbstractConfig { get() { mPrivacyPolicyAccepted = mPrivacyPolicyAccepted ?: values.get("privacyPolicyAccepted", false); return mPrivacyPolicyAccepted ?: false } set(value) { set("privacyPolicyAccepted", value); mPrivacyPolicyAccepted = value } - private var mDebugMode: Boolean? = null - var debugMode: Boolean - get() { mDebugMode = mDebugMode ?: values.get("debugMode", false); return mDebugMode ?: false } - set(value) { set("debugMode", value); mDebugMode = 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.get("enableChucker", false); return mEnableChucker ?: false } - set(value) { set("enableChucker", value); mEnableChucker = value } + 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? diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/config/utils/ConfigExtensions.kt b/app/src/main/java/pl/szczodrzynski/edziennik/config/utils/ConfigExtensions.kt index c98cf832..94bb87e6 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/config/utils/ConfigExtensions.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/config/utils/ConfigExtensions.kt @@ -59,6 +59,9 @@ fun HashMap.get(key: String, default: String?): String? { fun HashMap.get(key: String, default: Boolean): Boolean { return this[key]?.toBoolean() ?: default } +fun HashMap.getBooleanOrNull(key: String): Boolean? { + return this[key]?.toBooleanStrictOrNull() +} fun HashMap.get(key: String, default: Int): Int { return this[key]?.toIntOrNull() ?: default } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/config/utils/ConfigMigration.kt b/app/src/main/java/pl/szczodrzynski/edziennik/config/utils/ConfigMigration.kt index 1095f511..58dc35f7 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/config/utils/ConfigMigration.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/config/utils/ConfigMigration.kt @@ -67,7 +67,7 @@ class ConfigMigration(app: App, config: Config) { if (dataVersion < 3) { update = null privacyPolicyAccepted = false - debugMode = false + devMode = null devModePassword = null appInstalledTime = 0L appRateSnackbarTime = 0L diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/debug/LabFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/debug/LabFragment.kt index 60c30cf9..f7c8952d 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/debug/LabFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/debug/LabFragment.kt @@ -41,6 +41,7 @@ class LabFragment : Fragment(), CoroutineScope { app = activity.application as App b = TemplateFragmentBinding.inflate(inflater) b.refreshLayout.setParent(activity.swipeRefreshLayout) + b.refreshLayout.isEnabled = false return b.root } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/debug/LabPageFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/debug/LabPageFragment.kt index 4d8205bf..19ae4697 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/debug/LabPageFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/debug/LabPageFragment.kt @@ -16,6 +16,7 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job import kotlinx.coroutines.launch import pl.szczodrzynski.edziennik.* +import pl.szczodrzynski.edziennik.config.Config import pl.szczodrzynski.edziennik.data.db.entity.Event import pl.szczodrzynski.edziennik.databinding.LabFragmentBinding import pl.szczodrzynski.edziennik.ui.dialogs.profile.ProfileRemoveDialog @@ -78,10 +79,10 @@ class LabPageFragment : LazyFragment(), CoroutineScope { app.db.eventDao().getRawNow("UPDATE events SET homeworkBody = NULL WHERE profileId = ${App.profileId}") } - b.chucker.isChecked = app.config.enableChucker - + b.chucker.isChecked = App.enableChucker b.chucker.onChange { _, isChecked -> app.config.enableChucker = isChecked + App.enableChucker = isChecked MaterialAlertDialogBuilder(activity) .setTitle("Restart") .setMessage("Wymagany restart aplikacji") @@ -94,9 +95,9 @@ class LabPageFragment : LazyFragment(), CoroutineScope { .show() } - b.disableDebug.onClick { - app.config.debugMode = false + app.config.devMode = false + App.devMode = false MaterialAlertDialogBuilder(activity) .setTitle("Restart") .setMessage("Wymagany restart aplikacji") @@ -115,6 +116,14 @@ class LabPageFragment : LazyFragment(), CoroutineScope { app.profileSave() } + b.resetCert.onClick { + app.config.apiInvalidCert = null + } + + b.rebuildConfig.onClick { + App.config = Config(App.db) + } + val profiles = app.db.profileDao().allNow b.profile.clear() b.profile += profiles.map { TextInputDropDown.Item(it.id.toLong(), "${it.id} ${it.name} archived ${it.archived}", tag = it) } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginPrizeFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginPrizeFragment.kt index 1c9634fc..f14c6d19 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginPrizeFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginPrizeFragment.kt @@ -53,7 +53,7 @@ class LoginPrizeFragment : Fragment(), CoroutineScope { .setTitle(R.string.are_you_sure) .setMessage(R.string.dev_mode_enable_warning) .setPositiveButton(R.string.yes) { _, _ -> - app.config.debugMode = true + app.config.devMode = true App.devMode = true MaterialAlertDialogBuilder(activity) .setTitle("Restart") @@ -67,8 +67,8 @@ class LoginPrizeFragment : Fragment(), CoroutineScope { .show() } .setNegativeButton(R.string.no) { _, _ -> - app.config.debugMode = false - App.devMode = false + app.config.devMode = App.debugMode + App.devMode = App.debugMode activity.finish() } .show() diff --git a/app/src/main/res/layout/lab_fragment.xml b/app/src/main/res/layout/lab_fragment.xml index 6c4bca77..d0756d7f 100644 --- a/app/src/main/res/layout/lab_fragment.xml +++ b/app/src/main/res/layout/lab_fragment.xml @@ -1,15 +1,17 @@ - - - - + + --> - + tools:text="Cookies:\n\nsynergia.librus.pl\n DZIENNIKSID=L01~1234567890abcdef" />