From 2e3e3dcf3cb147c6811d3ecbc6098685b9b00b87 Mon Sep 17 00:00:00 2001 From: Antoni Czaplicki <56671347+Antoni-Czaplicki@users.noreply.github.com> Date: Fri, 10 Sep 2021 23:47:46 +0200 Subject: [PATCH] [Lab] Add button to disable devmode and Chucker toggle. (#70) * Add option to disable/enable chucker and option to disable dev mode from lab page * Change "chucker" to "enableChucker" * Update App.kt --- .../java/pl/szczodrzynski/edziennik/App.kt | 10 ++++-- .../szczodrzynski/edziennik/config/Config.kt | 5 +++ .../ui/modules/debug/LabPageFragment.kt | 34 +++++++++++++++++++ .../ui/modules/debug/LabProfileFragment.kt | 2 +- app/src/main/res/layout/lab_fragment.xml | 17 +++++++++- 5 files changed, 63 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/App.kt b/app/src/main/java/pl/szczodrzynski/edziennik/App.kt index a9186d94..71e6c7e6 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/App.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/App.kt @@ -58,6 +58,7 @@ class App : MultiDexApplication(), Configuration.Provider, CoroutineScope { val profileId get() = profile.id + var enableChucker = false var debugMode = false var devMode = false } @@ -115,9 +116,11 @@ class App : MultiDexApplication(), Configuration.Provider, CoroutineScope { HyperLog.initialize(this) HyperLog.setLogLevel(Log.VERBOSE) HyperLog.setLogFormat(DebugLogFormat(this)) - val chuckerCollector = ChuckerCollector(this, true, RetentionManager.Period.ONE_HOUR) - val chuckerInterceptor = ChuckerInterceptor(this, chuckerCollector) - builder.addInterceptor(chuckerInterceptor) + if (enableChucker) { + val chuckerCollector = ChuckerCollector(this, true, RetentionManager.Period.ONE_HOUR) + val chuckerInterceptor = ChuckerInterceptor(this, chuckerCollector) + builder.addInterceptor(chuckerInterceptor) + } } http = builder.build() @@ -172,6 +175,7 @@ class App : MultiDexApplication(), Configuration.Provider, CoroutineScope { App.profile = Profile(0, 0, 0, "") debugMode = BuildConfig.DEBUG devMode = config.debugMode || 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 160deb23..0274912f 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/config/Config.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/config/Config.kt @@ -80,6 +80,11 @@ class Config(val db: AppDb) : CoroutineScope, AbstractConfig { get() { mDebugMode = mDebugMode ?: values.get("debugMode", false); return mDebugMode ?: false } set(value) { set("debugMode", value); mDebugMode = 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 } + private var mDevModePassword: String? = null var devModePassword: String? get() { mDevModePassword = mDevModePassword ?: values.get("devModePassword", null as String?); return mDevModePassword } 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 b1b84f9d..4d8205bf 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 @@ -5,10 +5,12 @@ package pl.szczodrzynski.edziennik.ui.modules.debug import android.os.Bundle +import android.os.Process import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.sqlite.db.SimpleSQLiteQuery +import com.google.android.material.dialog.MaterialAlertDialogBuilder import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job @@ -21,6 +23,7 @@ import pl.szczodrzynski.edziennik.ui.modules.base.lazypager.LazyFragment import pl.szczodrzynski.edziennik.utils.TextInputDropDown import pl.szczodrzynski.fslogin.decode import kotlin.coroutines.CoroutineContext +import kotlin.system.exitProcess class LabPageFragment : LazyFragment(), CoroutineScope { companion object { @@ -75,6 +78,37 @@ 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.onChange { _, isChecked -> + app.config.enableChucker = isChecked + MaterialAlertDialogBuilder(activity) + .setTitle("Restart") + .setMessage("Wymagany restart aplikacji") + .setPositiveButton(R.string.ok) { _, _ -> + Process.killProcess(Process.myPid()) + Runtime.getRuntime().exit(0) + exitProcess(0) + } + .setCancelable(false) + .show() + } + + + b.disableDebug.onClick { + app.config.debugMode = false + MaterialAlertDialogBuilder(activity) + .setTitle("Restart") + .setMessage("Wymagany restart aplikacji") + .setPositiveButton(R.string.ok) { _, _ -> + Process.killProcess(Process.myPid()) + Runtime.getRuntime().exit(0) + exitProcess(0) + } + .setCancelable(false) + .show() + } + b.unarchive.onClick { app.profile.archived = false app.profile.archiveId = null diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/debug/LabProfileFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/debug/LabProfileFragment.kt index ee3ea2c6..f4b03f55 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/debug/LabProfileFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/debug/LabProfileFragment.kt @@ -166,7 +166,7 @@ class LabProfileFragment : LazyFragment(), CoroutineScope { json.add("App.profile", app.gson.toJsonTree(app.profile)) json.add("App.profile.studentData", app.profile.studentData) json.add("App.profile.loginStore", loginStore?.data ?: JsonObject()) - json.add("App.config", JsonParser().parse(app.gson.toJson(app.config.values))) + json.add("App.config", JsonParser().parse(app.gson.toJson(app.config.values.toSortedMap()))) } adapter.items = LabJsonAdapter.expand(json, 0) adapter.notifyDataSetChanged() diff --git a/app/src/main/res/layout/lab_fragment.xml b/app/src/main/res/layout/lab_fragment.xml index 8152f917..6c4bca77 100644 --- a/app/src/main/res/layout/lab_fragment.xml +++ b/app/src/main/res/layout/lab_fragment.xml @@ -3,7 +3,8 @@ ~ Copyright (c) Kuba SzczodrzyƄski 2020-4-3. --> - @@ -38,6 +39,12 @@ android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" />--> + +