[Lab] Fix disabling Chucker and Dev Mode. Add new Lab options.

This commit is contained in:
Kuba Szczodrzyński 2021-09-18 16:37:24 +02:00
parent 80dcd9aa69
commit 60f0628f5e
No known key found for this signature in database
GPG Key ID: 70CB8A85BA1633CB
8 changed files with 65 additions and 30 deletions

View File

@ -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) }

View File

@ -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?

View File

@ -59,6 +59,9 @@ fun HashMap<String, String?>.get(key: String, default: String?): String? {
fun HashMap<String, String?>.get(key: String, default: Boolean): Boolean {
return this[key]?.toBoolean() ?: default
}
fun HashMap<String, String?>.getBooleanOrNull(key: String): Boolean? {
return this[key]?.toBooleanStrictOrNull()
}
fun HashMap<String, String?>.get(key: String, default: Int): Int {
return this[key]?.toIntOrNull() ?: default
}

View File

@ -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

View File

@ -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
}

View File

@ -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) }

View File

@ -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()

View File

@ -1,15 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (c) Kuba Szczodrzyński 2020-4-3.
-->
<layout xmlns:app="http://schemas.android.com/apk/res-auto"
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
tools:ignore="HardcodedText">
<data>
<variable name="app" type="pl.szczodrzynski.edziennik.App"/>
<variable
name="app"
type="pl.szczodrzynski.edziennik.App" />
</data>
<ScrollView
@ -39,7 +41,7 @@
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />-->
<Switch
<com.google.android.material.checkbox.MaterialCheckBox
android:id="@+id/chucker"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -87,7 +89,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="monospace"
tools:text="Cookies:\n\nsynergia.librus.pl\n DZIENNIKSID=L01~1234567890abcdef"/>
tools:text="Cookies:\n\nsynergia.librus.pl\n DZIENNIKSID=L01~1234567890abcdef" />
<Button
android:id="@+id/unarchive"
@ -99,9 +101,9 @@
<pl.szczodrzynski.edziennik.utils.TextInputDropDown
android:id="@+id/profile"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox" />
android:layout_height="wrap_content" />
<com.google.android.material.checkbox.MaterialCheckBox
android:layout_width="match_parent"
@ -109,13 +111,36 @@
android:checked="@={app.config.archiverEnabled}"
android:text="Archiver enabled" />
<com.google.android.material.checkbox.MaterialCheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="@={app.config.apiAvailabilityCheck}"
android:text="Availability check enabled" />
<Button
android:id="@+id/resetCert"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Reset API signature"
android:textAllCaps="false" />
<Button
android:id="@+id/disableDebug"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="Disable Dev Mode"
android:textAllCaps="false"
app:backgroundTint="@color/windowBackgroundRed" />
<Button
android:id="@+id/rebuildConfig"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="Rebuild App.config"
android:textAllCaps="false" />
</LinearLayout>
</ScrollView>
</layout>