From ddefda08f167bed33240e3c382f104c3eeec0deb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Sun, 7 Jul 2024 22:55:20 +0200 Subject: [PATCH] [App] Simplify enabling Dev Mode on nightly builds --- .../edziennik/core/manager/BuildManager.kt | 4 +- .../edziennik/ui/dialogs/DevModeDialog.kt | 39 +++++++++++++++++++ .../ui/login/LoginChooserFragment.kt | 8 +++- .../edziennik/ui/login/LoginPrizeFragment.kt | 20 +++------- .../ui/settings/cards/SettingsAboutCard.kt | 8 +++- .../contributors/ContributorsFragment.kt | 18 ++------- 6 files changed, 65 insertions(+), 32 deletions(-) create mode 100644 app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/DevModeDialog.kt diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/core/manager/BuildManager.kt b/app/src/main/java/pl/szczodrzynski/edziennik/core/manager/BuildManager.kt index e33cd0eb..80e1801c 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/core/manager/BuildManager.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/core/manager/BuildManager.kt @@ -78,7 +78,7 @@ class BuildManager(val app: App) : CoroutineScope { val isOfficial = isSigned && (isPlayRelease || isApkRelease) val versionName = when { - isOfficial -> BuildConfig.VERSION_NAME + ", " + BuildConfig.BUILD_TYPE + isOfficial -> BuildConfig.VERSION_NAME isRelease -> "$gitVersion\n$gitBranch" else -> BuildConfig.VERSION_NAME } @@ -103,6 +103,8 @@ class BuildManager(val app: App) : CoroutineScope { else -> Update.Type.RELEASE } + val devModeEasy = (isDaily || isNightly || isDebug) && !App.devMode + fun fetchInstalledTime() { if (app.config.appInstalledTime != 0L) return diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/DevModeDialog.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/DevModeDialog.kt new file mode 100644 index 00000000..8b7ccf45 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/DevModeDialog.kt @@ -0,0 +1,39 @@ +/* + * Copyright (c) Kuba SzczodrzyƄski 2024-7-5. + */ + +package pl.szczodrzynski.edziennik.ui.dialogs + +import androidx.appcompat.app.AppCompatActivity +import pl.szczodrzynski.edziennik.App +import pl.szczodrzynski.edziennik.R +import pl.szczodrzynski.edziennik.ui.base.dialog.BaseDialog + +class DevModeDialog( + activity: AppCompatActivity, +) : BaseDialog(activity) { + + override fun getTitleRes() = R.string.are_you_sure + override fun getMessageRes() = R.string.dev_mode_enable_warning + override fun isCancelable() = false + override fun getPositiveButtonText() = R.string.yes + override fun getNegativeButtonText() = R.string.no + + override suspend fun onPositiveClick(): Boolean { + app.config.devMode = true + if (!App.devMode) { + RestartDialog(activity).showModal() + return NO_DISMISS + } + return DISMISS + } + + override suspend fun onNegativeClick(): Boolean { + app.config.devMode = null + if (App.devMode) { + RestartDialog(activity).showModal() + return NO_DISMISS + } + return DISMISS + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/login/LoginChooserFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/login/LoginChooserFragment.kt index 1a6a1d2d..f013b218 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/login/LoginChooserFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/login/LoginChooserFragment.kt @@ -17,6 +17,7 @@ import android.view.animation.AccelerateDecelerateInterpolator import android.view.animation.Animation import android.view.animation.RotateAnimation import android.widget.Toast +import androidx.core.view.isInvisible import androidx.core.view.isVisible import androidx.fragment.app.Fragment import androidx.recyclerview.widget.LinearLayoutManager @@ -37,6 +38,7 @@ import pl.szczodrzynski.edziennik.ext.resolveColor import pl.szczodrzynski.edziennik.ext.setText import pl.szczodrzynski.edziennik.ext.setTintColor import pl.szczodrzynski.edziennik.ui.base.dialog.SimpleDialog +import pl.szczodrzynski.edziennik.ui.dialogs.DevModeDialog import pl.szczodrzynski.edziennik.ui.dialogs.sync.RegisterUnavailableDialog import pl.szczodrzynski.edziennik.ui.feedback.FeedbackActivity import pl.szczodrzynski.edziennik.utils.SimpleDividerItemDecoration @@ -86,6 +88,10 @@ class LoginChooserFragment : Fragment(), CoroutineScope { Date.fromMillis(app.buildManager.buildTimestamp).stringY_m_d ) b.versionText.onClick { + if (app.buildManager.devModeEasy) { + DevModeDialog(activity).show() + return@onClick + } app.buildManager.showVersionDialog(activity) if (!App.devMode) return@onClick @@ -238,7 +244,7 @@ class LoginChooserFragment : Fragment(), CoroutineScope { } else -> { // there are no profiles - b.cancelButton.isVisible = false + b.cancelButton.isInvisible = true } } } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/login/LoginPrizeFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/login/LoginPrizeFragment.kt index 41d5d40b..2d2f6400 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/login/LoginPrizeFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/login/LoginPrizeFragment.kt @@ -13,12 +13,14 @@ import coil.load import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job +import kotlinx.coroutines.launch import pl.szczodrzynski.edziennik.App import pl.szczodrzynski.edziennik.BuildConfig import pl.szczodrzynski.edziennik.R import pl.szczodrzynski.edziennik.databinding.LoginPrizeFragmentBinding import pl.szczodrzynski.edziennik.ext.onClick import pl.szczodrzynski.edziennik.ui.base.dialog.SimpleDialog +import pl.szczodrzynski.edziennik.ui.dialogs.DevModeDialog import pl.szczodrzynski.edziennik.ui.dialogs.RestartDialog import kotlin.coroutines.CoroutineContext @@ -49,20 +51,10 @@ class LoginPrizeFragment : Fragment(), CoroutineScope { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { b.button.load("https://szkolny.eu/game/button.png") b.button.onClick { - SimpleDialog(activity) { - title(R.string.are_you_sure) - message(R.string.dev_mode_enable_warning) - positive(R.string.yes) { - app.config.devMode = true - App.devMode = true - RestartDialog(activity).show() - } - negative(R.string.no) { - app.config.devMode = BuildConfig.DEBUG - App.devMode = BuildConfig.DEBUG - activity.finish() - } - }.show() + launch { + DevModeDialog(activity).showModal() + activity.finish() + } } } } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/settings/cards/SettingsAboutCard.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/settings/cards/SettingsAboutCard.kt index 1d5cb04b..00cb48bd 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/settings/cards/SettingsAboutCard.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/settings/cards/SettingsAboutCard.kt @@ -22,6 +22,7 @@ import pl.szczodrzynski.edziennik.data.enums.NavTarget import pl.szczodrzynski.edziennik.ext.after import pl.szczodrzynski.edziennik.ext.resolveAttr import pl.szczodrzynski.edziennik.ui.dialogs.ChangelogDialog +import pl.szczodrzynski.edziennik.ui.dialogs.DevModeDialog import pl.szczodrzynski.edziennik.ui.settings.SettingsCard import pl.szczodrzynski.edziennik.ui.settings.SettingsLicenseActivity import pl.szczodrzynski.edziennik.ui.settings.SettingsUtil @@ -69,7 +70,7 @@ class SettingsAboutCard(util: SettingsUtil) : SettingsCard(util), CoroutineScope card.items.after(item, versionDetailsItem) util.refresh() } - + // eggs clickCounter++ if (clickCounter < 7) Toast.makeText(activity, "\uD83D\uDE02", Toast.LENGTH_SHORT).show() @@ -79,10 +80,13 @@ class SettingsAboutCard(util: SettingsUtil) : SettingsCard(util), CoroutineScope if (clickCounter >= 7) { mediaPlayer.start() clickCounter = 0 + if (app.buildManager.devModeEasy) { + DevModeDialog(activity).show() + } } } ).also { - it.subText = BuildConfig.VERSION_NAME + ", " + BuildConfig.BUILD_TYPE + it.subText = BuildConfig.VERSION_NAME }, util.createActionItem( diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/settings/contributors/ContributorsFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/settings/contributors/ContributorsFragment.kt index 8d4b7f20..faaa3c1e 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/settings/contributors/ContributorsFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/settings/contributors/ContributorsFragment.kt @@ -14,6 +14,7 @@ import pl.szczodrzynski.edziennik.ext.onClick import pl.szczodrzynski.edziennik.ext.onLongClick import pl.szczodrzynski.edziennik.ui.base.dialog.SimpleDialog import pl.szczodrzynski.edziennik.ui.base.fragment.PagerFragment +import pl.szczodrzynski.edziennik.ui.dialogs.DevModeDialog import pl.szczodrzynski.edziennik.ui.dialogs.RestartDialog class ContributorsFragment : PagerFragment( @@ -40,6 +41,7 @@ class ContributorsFragment : PagerFragment(activity) { - title(R.string.are_you_sure) - message(R.string.dev_mode_enable_warning) - positive(R.string.yes) { - app.config.devMode = true - App.devMode = true - RestartDialog(activity).show() - } - negative(R.string.no) { - app.config.devMode = false - App.devMode = false - } - }.show() + DevModeDialog(activity).show() } contributors = contributors ?: SzkolnyApi(app).runCatching(activity.errorSnackbar) {