mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2024-11-28 04:43:33 -06:00
[Lab] Fix disabling Chucker and Dev Mode. Add new Lab options.
This commit is contained in:
parent
80dcd9aa69
commit
60f0628f5e
@ -175,8 +175,8 @@ class App : MultiDexApplication(), Configuration.Provider, CoroutineScope {
|
|||||||
App.config = Config(App.db)
|
App.config = Config(App.db)
|
||||||
App.profile = Profile(0, 0, 0, "")
|
App.profile = Profile(0, 0, 0, "")
|
||||||
debugMode = BuildConfig.DEBUG
|
debugMode = BuildConfig.DEBUG
|
||||||
devMode = config.debugMode || debugMode
|
devMode = config.devMode ?: debugMode
|
||||||
enableChucker = config.enableChucker || devMode
|
enableChucker = config.enableChucker ?: devMode
|
||||||
|
|
||||||
if (!profileLoadById(config.lastProfileId)) {
|
if (!profileLoadById(config.lastProfileId)) {
|
||||||
db.profileDao().firstId?.let { profileLoadById(it) }
|
db.profileDao().firstId?.let { profileLoadById(it) }
|
||||||
|
@ -12,10 +12,7 @@ import kotlinx.coroutines.launch
|
|||||||
import pl.szczodrzynski.edziennik.App
|
import pl.szczodrzynski.edziennik.App
|
||||||
import pl.szczodrzynski.edziennik.BuildConfig
|
import pl.szczodrzynski.edziennik.BuildConfig
|
||||||
import pl.szczodrzynski.edziennik.config.db.ConfigEntry
|
import pl.szczodrzynski.edziennik.config.db.ConfigEntry
|
||||||
import pl.szczodrzynski.edziennik.config.utils.ConfigMigration
|
import pl.szczodrzynski.edziennik.config.utils.*
|
||||||
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.data.api.szkolny.response.Update
|
import pl.szczodrzynski.edziennik.data.api.szkolny.response.Update
|
||||||
import pl.szczodrzynski.edziennik.data.db.AppDb
|
import pl.szczodrzynski.edziennik.data.db.AppDb
|
||||||
import kotlin.coroutines.CoroutineContext
|
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 }
|
get() { mPrivacyPolicyAccepted = mPrivacyPolicyAccepted ?: values.get("privacyPolicyAccepted", false); return mPrivacyPolicyAccepted ?: false }
|
||||||
set(value) { set("privacyPolicyAccepted", value); mPrivacyPolicyAccepted = value }
|
set(value) { set("privacyPolicyAccepted", value); mPrivacyPolicyAccepted = value }
|
||||||
|
|
||||||
private var mDebugMode: Boolean? = null
|
private var mDevMode: Boolean? = null
|
||||||
var debugMode: Boolean
|
var devMode: Boolean?
|
||||||
get() { mDebugMode = mDebugMode ?: values.get("debugMode", false); return mDebugMode ?: false }
|
get() { mDevMode = mDevMode ?: values.getBooleanOrNull("debugMode"); return mDevMode }
|
||||||
set(value) { set("debugMode", value); mDebugMode = value }
|
set(value) { set("debugMode", value?.toString()); mDevMode = value }
|
||||||
|
|
||||||
private var mEnableChucker: Boolean? = null
|
private var mEnableChucker: Boolean? = null
|
||||||
var enableChucker: Boolean
|
var enableChucker: Boolean?
|
||||||
get() { mEnableChucker = mEnableChucker ?: values.get("enableChucker", false); return mEnableChucker ?: false }
|
get() { mEnableChucker = mEnableChucker ?: values.getBooleanOrNull("enableChucker"); return mEnableChucker }
|
||||||
set(value) { set("enableChucker", value); mEnableChucker = value }
|
set(value) { set("enableChucker", value?.toString()); mEnableChucker = value }
|
||||||
|
|
||||||
private var mDevModePassword: String? = null
|
private var mDevModePassword: String? = null
|
||||||
var devModePassword: String?
|
var devModePassword: String?
|
||||||
|
@ -59,6 +59,9 @@ fun HashMap<String, String?>.get(key: String, default: String?): String? {
|
|||||||
fun HashMap<String, String?>.get(key: String, default: Boolean): Boolean {
|
fun HashMap<String, String?>.get(key: String, default: Boolean): Boolean {
|
||||||
return this[key]?.toBoolean() ?: default
|
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 {
|
fun HashMap<String, String?>.get(key: String, default: Int): Int {
|
||||||
return this[key]?.toIntOrNull() ?: default
|
return this[key]?.toIntOrNull() ?: default
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ class ConfigMigration(app: App, config: Config) {
|
|||||||
if (dataVersion < 3) {
|
if (dataVersion < 3) {
|
||||||
update = null
|
update = null
|
||||||
privacyPolicyAccepted = false
|
privacyPolicyAccepted = false
|
||||||
debugMode = false
|
devMode = null
|
||||||
devModePassword = null
|
devModePassword = null
|
||||||
appInstalledTime = 0L
|
appInstalledTime = 0L
|
||||||
appRateSnackbarTime = 0L
|
appRateSnackbarTime = 0L
|
||||||
|
@ -41,6 +41,7 @@ class LabFragment : Fragment(), CoroutineScope {
|
|||||||
app = activity.application as App
|
app = activity.application as App
|
||||||
b = TemplateFragmentBinding.inflate(inflater)
|
b = TemplateFragmentBinding.inflate(inflater)
|
||||||
b.refreshLayout.setParent(activity.swipeRefreshLayout)
|
b.refreshLayout.setParent(activity.swipeRefreshLayout)
|
||||||
|
b.refreshLayout.isEnabled = false
|
||||||
return b.root
|
return b.root
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ import kotlinx.coroutines.Dispatchers
|
|||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import pl.szczodrzynski.edziennik.*
|
import pl.szczodrzynski.edziennik.*
|
||||||
|
import pl.szczodrzynski.edziennik.config.Config
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Event
|
import pl.szczodrzynski.edziennik.data.db.entity.Event
|
||||||
import pl.szczodrzynski.edziennik.databinding.LabFragmentBinding
|
import pl.szczodrzynski.edziennik.databinding.LabFragmentBinding
|
||||||
import pl.szczodrzynski.edziennik.ui.dialogs.profile.ProfileRemoveDialog
|
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}")
|
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 ->
|
b.chucker.onChange { _, isChecked ->
|
||||||
app.config.enableChucker = isChecked
|
app.config.enableChucker = isChecked
|
||||||
|
App.enableChucker = isChecked
|
||||||
MaterialAlertDialogBuilder(activity)
|
MaterialAlertDialogBuilder(activity)
|
||||||
.setTitle("Restart")
|
.setTitle("Restart")
|
||||||
.setMessage("Wymagany restart aplikacji")
|
.setMessage("Wymagany restart aplikacji")
|
||||||
@ -94,9 +95,9 @@ class LabPageFragment : LazyFragment(), CoroutineScope {
|
|||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
b.disableDebug.onClick {
|
b.disableDebug.onClick {
|
||||||
app.config.debugMode = false
|
app.config.devMode = false
|
||||||
|
App.devMode = false
|
||||||
MaterialAlertDialogBuilder(activity)
|
MaterialAlertDialogBuilder(activity)
|
||||||
.setTitle("Restart")
|
.setTitle("Restart")
|
||||||
.setMessage("Wymagany restart aplikacji")
|
.setMessage("Wymagany restart aplikacji")
|
||||||
@ -115,6 +116,14 @@ class LabPageFragment : LazyFragment(), CoroutineScope {
|
|||||||
app.profileSave()
|
app.profileSave()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
b.resetCert.onClick {
|
||||||
|
app.config.apiInvalidCert = null
|
||||||
|
}
|
||||||
|
|
||||||
|
b.rebuildConfig.onClick {
|
||||||
|
App.config = Config(App.db)
|
||||||
|
}
|
||||||
|
|
||||||
val profiles = app.db.profileDao().allNow
|
val profiles = app.db.profileDao().allNow
|
||||||
b.profile.clear()
|
b.profile.clear()
|
||||||
b.profile += profiles.map { TextInputDropDown.Item(it.id.toLong(), "${it.id} ${it.name} archived ${it.archived}", tag = it) }
|
b.profile += profiles.map { TextInputDropDown.Item(it.id.toLong(), "${it.id} ${it.name} archived ${it.archived}", tag = it) }
|
||||||
|
@ -53,7 +53,7 @@ class LoginPrizeFragment : Fragment(), CoroutineScope {
|
|||||||
.setTitle(R.string.are_you_sure)
|
.setTitle(R.string.are_you_sure)
|
||||||
.setMessage(R.string.dev_mode_enable_warning)
|
.setMessage(R.string.dev_mode_enable_warning)
|
||||||
.setPositiveButton(R.string.yes) { _, _ ->
|
.setPositiveButton(R.string.yes) { _, _ ->
|
||||||
app.config.debugMode = true
|
app.config.devMode = true
|
||||||
App.devMode = true
|
App.devMode = true
|
||||||
MaterialAlertDialogBuilder(activity)
|
MaterialAlertDialogBuilder(activity)
|
||||||
.setTitle("Restart")
|
.setTitle("Restart")
|
||||||
@ -67,8 +67,8 @@ class LoginPrizeFragment : Fragment(), CoroutineScope {
|
|||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
.setNegativeButton(R.string.no) { _, _ ->
|
.setNegativeButton(R.string.no) { _, _ ->
|
||||||
app.config.debugMode = false
|
app.config.devMode = App.debugMode
|
||||||
App.devMode = false
|
App.devMode = App.debugMode
|
||||||
activity.finish()
|
activity.finish()
|
||||||
}
|
}
|
||||||
.show()
|
.show()
|
||||||
|
@ -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.
|
~ 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:tools="http://schemas.android.com/tools"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
tools:ignore="HardcodedText">
|
tools:ignore="HardcodedText">
|
||||||
|
|
||||||
<data>
|
<data>
|
||||||
<variable name="app" type="pl.szczodrzynski.edziennik.App"/>
|
|
||||||
|
<variable
|
||||||
|
name="app"
|
||||||
|
type="pl.szczodrzynski.edziennik.App" />
|
||||||
</data>
|
</data>
|
||||||
|
|
||||||
<ScrollView
|
<ScrollView
|
||||||
@ -39,7 +41,7 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
app:layout_behavior="@string/appbar_scrolling_view_behavior" />-->
|
app:layout_behavior="@string/appbar_scrolling_view_behavior" />-->
|
||||||
|
|
||||||
<Switch
|
<com.google.android.material.checkbox.MaterialCheckBox
|
||||||
android:id="@+id/chucker"
|
android:id="@+id/chucker"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@ -87,7 +89,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:fontFamily="monospace"
|
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
|
<Button
|
||||||
android:id="@+id/unarchive"
|
android:id="@+id/unarchive"
|
||||||
@ -99,9 +101,9 @@
|
|||||||
|
|
||||||
<pl.szczodrzynski.edziennik.utils.TextInputDropDown
|
<pl.szczodrzynski.edziennik.utils.TextInputDropDown
|
||||||
android:id="@+id/profile"
|
android:id="@+id/profile"
|
||||||
|
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content" />
|
||||||
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox" />
|
|
||||||
|
|
||||||
<com.google.android.material.checkbox.MaterialCheckBox
|
<com.google.android.material.checkbox.MaterialCheckBox
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@ -109,13 +111,36 @@
|
|||||||
android:checked="@={app.config.archiverEnabled}"
|
android:checked="@={app.config.archiverEnabled}"
|
||||||
android:text="Archiver enabled" />
|
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
|
<Button
|
||||||
android:id="@+id/disableDebug"
|
android:id="@+id/disableDebug"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="24dp"
|
||||||
android:text="Disable Dev Mode"
|
android:text="Disable Dev Mode"
|
||||||
android:textAllCaps="false"
|
android:textAllCaps="false"
|
||||||
app:backgroundTint="@color/windowBackgroundRed" />
|
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>
|
</LinearLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
</layout>
|
</layout>
|
||||||
|
Loading…
Reference in New Issue
Block a user