[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
This commit is contained in:
Antoni Czaplicki 2021-09-10 23:47:46 +02:00 committed by GitHub
parent 118f5e1794
commit 2e3e3dcf3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 63 additions and 5 deletions

View File

@ -58,6 +58,7 @@ class App : MultiDexApplication(), Configuration.Provider, CoroutineScope {
val profileId val profileId
get() = profile.id get() = profile.id
var enableChucker = false
var debugMode = false var debugMode = false
var devMode = false var devMode = false
} }
@ -115,9 +116,11 @@ class App : MultiDexApplication(), Configuration.Provider, CoroutineScope {
HyperLog.initialize(this) HyperLog.initialize(this)
HyperLog.setLogLevel(Log.VERBOSE) HyperLog.setLogLevel(Log.VERBOSE)
HyperLog.setLogFormat(DebugLogFormat(this)) HyperLog.setLogFormat(DebugLogFormat(this))
val chuckerCollector = ChuckerCollector(this, true, RetentionManager.Period.ONE_HOUR) if (enableChucker) {
val chuckerInterceptor = ChuckerInterceptor(this, chuckerCollector) val chuckerCollector = ChuckerCollector(this, true, RetentionManager.Period.ONE_HOUR)
builder.addInterceptor(chuckerInterceptor) val chuckerInterceptor = ChuckerInterceptor(this, chuckerCollector)
builder.addInterceptor(chuckerInterceptor)
}
} }
http = builder.build() http = builder.build()
@ -172,6 +175,7 @@ class App : MultiDexApplication(), Configuration.Provider, CoroutineScope {
App.profile = Profile(0, 0, 0, "") App.profile = Profile(0, 0, 0, "")
debugMode = BuildConfig.DEBUG debugMode = BuildConfig.DEBUG
devMode = config.debugMode || debugMode devMode = config.debugMode || debugMode
enableChucker = config.enableChucker || devMode
if (!profileLoadById(config.lastProfileId)) { if (!profileLoadById(config.lastProfileId)) {
db.profileDao().firstId?.let { profileLoadById(it) } db.profileDao().firstId?.let { profileLoadById(it) }

View File

@ -80,6 +80,11 @@ class Config(val db: AppDb) : CoroutineScope, AbstractConfig {
get() { mDebugMode = mDebugMode ?: values.get("debugMode", false); return mDebugMode ?: false } get() { mDebugMode = mDebugMode ?: values.get("debugMode", false); return mDebugMode ?: false }
set(value) { set("debugMode", value); mDebugMode = value } 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 private var mDevModePassword: String? = null
var devModePassword: String? var devModePassword: String?
get() { mDevModePassword = mDevModePassword ?: values.get("devModePassword", null as String?); return mDevModePassword } get() { mDevModePassword = mDevModePassword ?: values.get("devModePassword", null as String?); return mDevModePassword }

View File

@ -5,10 +5,12 @@
package pl.szczodrzynski.edziennik.ui.modules.debug package pl.szczodrzynski.edziennik.ui.modules.debug
import android.os.Bundle import android.os.Bundle
import android.os.Process
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.sqlite.db.SimpleSQLiteQuery import androidx.sqlite.db.SimpleSQLiteQuery
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job 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.edziennik.utils.TextInputDropDown
import pl.szczodrzynski.fslogin.decode import pl.szczodrzynski.fslogin.decode
import kotlin.coroutines.CoroutineContext import kotlin.coroutines.CoroutineContext
import kotlin.system.exitProcess
class LabPageFragment : LazyFragment(), CoroutineScope { class LabPageFragment : LazyFragment(), CoroutineScope {
companion object { companion object {
@ -75,6 +78,37 @@ 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.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 { b.unarchive.onClick {
app.profile.archived = false app.profile.archived = false
app.profile.archiveId = null app.profile.archiveId = null

View File

@ -166,7 +166,7 @@ class LabProfileFragment : LazyFragment(), CoroutineScope {
json.add("App.profile", app.gson.toJsonTree(app.profile)) json.add("App.profile", app.gson.toJsonTree(app.profile))
json.add("App.profile.studentData", app.profile.studentData) json.add("App.profile.studentData", app.profile.studentData)
json.add("App.profile.loginStore", loginStore?.data ?: JsonObject()) 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.items = LabJsonAdapter.expand(json, 0)
adapter.notifyDataSetChanged() adapter.notifyDataSetChanged()

View File

@ -3,7 +3,8 @@
~ Copyright (c) Kuba Szczodrzyński 2020-4-3. ~ Copyright (c) Kuba Szczodrzyński 2020-4-3.
--> -->
<layout xmlns:tools="http://schemas.android.com/tools" <layout 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" xmlns:android="http://schemas.android.com/apk/res/android"
tools:ignore="HardcodedText"> tools:ignore="HardcodedText">
@ -38,6 +39,12 @@
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
android:id="@+id/chucker"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Chucker" />
<Button <Button
android:id="@+id/last10unseen" android:id="@+id/last10unseen"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -101,6 +108,14 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:checked="@={app.config.archiverEnabled}" android:checked="@={app.config.archiverEnabled}"
android:text="Archiver enabled" /> android:text="Archiver enabled" />
<Button
android:id="@+id/disableDebug"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Disable Dev Mode"
android:textAllCaps="false"
app:backgroundTint="@color/windowBackgroundRed" />
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>
</layout> </layout>