From f6f1370edf96bf538cd3af710c50cb46e51fc776 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Wed, 26 Feb 2020 20:37:55 +0100 Subject: [PATCH] [Debug] Add new debug mode. Include hidden Chucker in release. --- app/build.gradle | 4 +- .../java/pl/szczodrzynski/edziennik/App.kt | 5 +- .../szczodrzynski/edziennik/config/Config.kt | 5 ++ .../ui/modules/login/LoginActivity.kt | 3 + .../ui/modules/login/LoginChooserFragment.kt | 65 ++++++++++++++++++- .../modules/login/LoginEdudziennikFragment.kt | 28 ++++++++ .../szczodrzynski/edziennik/utils/Utils.java | 2 +- app/src/main/res/anim/shake.xml | 8 +++ .../res/layout/fragment_login_chooser.xml | 15 ++++- .../res/layout/fragment_login_edudziennik.xml | 1 + app/src/main/res/values/strings.xml | 2 + 11 files changed, 132 insertions(+), 6 deletions(-) create mode 100644 app/src/main/res/anim/shake.xml diff --git a/app/build.gradle b/app/build.gradle index 0121d93a..beadd513 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -166,8 +166,8 @@ dependencies { //implementation project(":Navigation") implementation project(":szkolny-font") - debugImplementation "com.github.ChuckerTeam.Chucker:library:3.0.1" - releaseImplementation "com.github.ChuckerTeam.Chucker:library-no-op:3.0.1" + implementation "com.github.ChuckerTeam.Chucker:library:3.0.1" + //releaseImplementation "com.github.ChuckerTeam.Chucker:library-no-op:3.0.1" //implementation 'com.github.wulkanowy:uonet-request-signer:master-SNAPSHOT' //implementation 'com.github.kuba2k2.uonet-request-signer:android:master-63f094b14a-1' diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/App.kt b/app/src/main/java/pl/szczodrzynski/edziennik/App.kt index 6469fc0d..b2dc9e0e 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/App.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/App.kt @@ -60,6 +60,7 @@ class App : MultiDexApplication(), Configuration.Provider, CoroutineScope { get() = profile.id var devMode = false + var debugMode = false } val notificationChannelsManager by lazy { NotificationChannelsManager(this) } @@ -103,7 +104,7 @@ class App : MultiDexApplication(), Configuration.Provider, CoroutineScope { .readTimeout(10, TimeUnit.SECONDS) builder.installHttpsSupport(this) - if (devMode || BuildConfig.DEBUG) { + if (debugMode || BuildConfig.DEBUG) { HyperLog.initialize(this) HyperLog.setLogLevel(Log.VERBOSE) HyperLog.setLogFormat(DebugLogFormat(this)) @@ -158,6 +159,7 @@ class App : MultiDexApplication(), Configuration.Provider, CoroutineScope { Iconics.registerFont(SzkolnyFont) App.db = AppDb(this) Themes.themeInt = config.ui.theme + debugMode = config.debugMode MHttp.instance().customOkHttpClient(http) if (!profileLoadById(config.lastProfileId)) { @@ -174,6 +176,7 @@ class App : MultiDexApplication(), Configuration.Provider, CoroutineScope { if (config.devModePassword != null) checkDevModePassword() + debugMode = devMode || config.debugMode if (config.sync.enabled) SyncWorker.scheduleNext(this@App, false) 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 46fdc63b..4e7a4c23 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/config/Config.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/config/Config.kt @@ -75,6 +75,11 @@ 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 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/login/LoginActivity.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginActivity.kt index 42dc3606..7f65279f 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginActivity.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginActivity.kt @@ -23,6 +23,7 @@ class LoginActivity : AppCompatActivity(), CoroutineScope { private const val TAG = "LoginActivity" @JvmField var navOptions: NavOptions? = null + var thisOneIsTricky = 0 } private val app: App by lazy { applicationContext as App } @@ -73,6 +74,8 @@ class LoginActivity : AppCompatActivity(), CoroutineScope { super.onCreate(savedInstanceState) setTheme(R.style.AppTheme_Light) + thisOneIsTricky = -1 + navOptions = NavOptions.Builder() .setEnterAnim(R.anim.slide_in_right) .setExitAnim(R.anim.slide_out_left) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginChooserFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginChooserFragment.kt index ef5f0099..ee48a453 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginChooserFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginChooserFragment.kt @@ -3,16 +3,25 @@ package pl.szczodrzynski.edziennik.ui.modules.login import android.app.Activity import android.content.Intent import android.os.Bundle +import android.os.Process import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.view.animation.AnimationUtils import android.widget.CompoundButton import androidx.fragment.app.Fragment +import com.afollestad.materialdialogs.DialogAction +import com.afollestad.materialdialogs.MaterialDialog +import com.google.android.material.dialog.MaterialAlertDialogBuilder import pl.szczodrzynski.edziennik.App import pl.szczodrzynski.edziennik.R import pl.szczodrzynski.edziennik.databinding.FragmentLoginChooserBinding +import pl.szczodrzynski.edziennik.onChange import pl.szczodrzynski.edziennik.onClick import pl.szczodrzynski.edziennik.ui.modules.feedback.FeedbackActivity +import pl.szczodrzynski.edziennik.utils.Anim +import kotlin.system.exitProcess + class LoginChooserFragment : Fragment() { companion object { @@ -34,6 +43,20 @@ class LoginChooserFragment : Fragment() { } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + b.topLogo.onClick { + if (LoginActivity.thisOneIsTricky <= -1) { + LoginActivity.thisOneIsTricky = 999 + } + if (LoginActivity.thisOneIsTricky in 0..7) { + LoginActivity.thisOneIsTricky++ + if (LoginActivity.thisOneIsTricky == 7) { + b.topLogo.startAnimation(AnimationUtils.loadAnimation(activity, R.anim.shake)); + if (b.devMode.visibility != View.VISIBLE) + Anim.expand(b.devMode, 500, null); + LoginActivity.thisOneIsTricky = 3 + } + } + } b.loginMobidziennikLogo.onClick { nav.navigate(R.id.loginMobidziennikFragment, null, LoginActivity.navOptions) } b.loginLibrusLogo.onClick { nav.navigate(R.id.loginLibrusFragment, null, LoginActivity.navOptions) } b.loginVulcanLogo.onClick { nav.navigate(R.id.loginVulcanFragment, null, LoginActivity.navOptions) } @@ -61,6 +84,46 @@ class LoginChooserFragment : Fragment() { } } + b.devMode.visibility = if (App.debugMode) View.VISIBLE else View.GONE + b.devMode.onChange { v, isChecked -> + if (isChecked) { + MaterialDialog.Builder(activity) + .title(R.string.are_you_sure) + .content(R.string.dev_mode_enable_warning) + .positiveText(R.string.yes) + .negativeText(R.string.no) + .onPositive { _: MaterialDialog?, _: DialogAction? -> + app.config.debugMode = true + MaterialAlertDialogBuilder(activity) + .setTitle("Restart") + .setMessage("Wymagany restart aplikacji") + .setPositiveButton("OK") { _, _ -> + Process.killProcess(Process.myPid()) + Runtime.getRuntime().exit(0) + exitProcess(0) + } + .setCancelable(false) + .show() + /*if (b.devModeLayout.getVisibility() !== View.VISIBLE) { + Anim.expand(b.devModeTitle, 500, null) + Anim.expand(b.devModeLayout, 500, null) + }*/ + } + .onNegative { _: MaterialDialog?, _: DialogAction? -> + b.devMode.isChecked = app.config.debugMode + b.devMode.jumpDrawablesToCurrentState() + Anim.collapse(b.devMode, 1000, null) + } + .show() + } else { + app.config.debugMode = false + /*if (b.devModeLayout.getVisibility() === View.VISIBLE) { + Anim.collapse(b.devModeTitle, 500, null) + Anim.collapse(b.devModeLayout, 500, null) + }*/ + } + } + b.fakeLogin.visibility = if (App.devMode) View.VISIBLE else View.GONE b.fakeLogin.isChecked = fakeLogin b.fakeLogin.setOnCheckedChangeListener { _: CompoundButton?, isChecked: Boolean -> @@ -69,4 +132,4 @@ class LoginChooserFragment : Fragment() { b.helpButton.onClick { startActivity(Intent(activity, FeedbackActivity::class.java)) } } -} \ No newline at end of file +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginEdudziennikFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginEdudziennikFragment.kt index d150add9..be1a83a7 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginEdudziennikFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginEdudziennikFragment.kt @@ -4,6 +4,9 @@ package pl.szczodrzynski.edziennik.ui.modules.login +import android.animation.ArgbEvaluator +import android.animation.ObjectAnimator +import android.graphics.Color import android.os.Bundle import android.view.LayoutInflater import android.view.View @@ -19,6 +22,7 @@ import pl.szczodrzynski.edziennik.databinding.FragmentLoginEdudziennikBinding import java.util.* import kotlin.coroutines.CoroutineContext + class LoginEdudziennikFragment : Fragment(), CoroutineScope { companion object { private const val TAG = "LoginEdudziennikFragment" @@ -28,6 +32,7 @@ class LoginEdudziennikFragment : Fragment(), CoroutineScope { private lateinit var activity: LoginActivity private lateinit var b: FragmentLoginEdudziennikBinding private val nav by lazy { activity.nav } + private var hehe = 0 private val job: Job = Job() override val coroutineContext: CoroutineContext @@ -52,6 +57,29 @@ class LoginEdudziennikFragment : Fragment(), CoroutineScope { } } + b.topText.onClick { + if (LoginActivity.thisOneIsTricky != -1) + return@onClick + hehe++ + if (hehe >= 5) { + LoginActivity.thisOneIsTricky = 3 + val colorAnim = ObjectAnimator.ofInt( + b.topText, + "textColor", + Color.BLACK, + Color.RED, + Color.BLACK, + Color.RED, + Color.BLACK, + Color.RED, + Color.BLACK + ) + colorAnim.setEvaluator(ArgbEvaluator()) + colorAnim.duration = 1500L + colorAnim.start() + } + } + b.backButton.onClick { nav.navigateUp() } b.loginButton.onClick { diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/utils/Utils.java b/app/src/main/java/pl/szczodrzynski/edziennik/utils/Utils.java index 910fc6f0..082d800d 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/utils/Utils.java +++ b/app/src/main/java/pl/szczodrzynski/edziennik/utils/Utils.java @@ -108,7 +108,7 @@ public class Utils { public static List debugLog = new ArrayList<>(); public static void d(String TAG, String message) { - if (App.Companion.getDevMode()) { + if (App.Companion.getDebugMode()) { HyperLog.d("Szkolny/"+TAG, message); //debugLog.add(TAG+": "+message); } diff --git a/app/src/main/res/anim/shake.xml b/app/src/main/res/anim/shake.xml new file mode 100644 index 00000000..40cccc66 --- /dev/null +++ b/app/src/main/res/anim/shake.xml @@ -0,0 +1,8 @@ + + + + diff --git a/app/src/main/res/layout/fragment_login_chooser.xml b/app/src/main/res/layout/fragment_login_chooser.xml index a9a85047..8a7c0f77 100644 --- a/app/src/main/res/layout/fragment_login_chooser.xml +++ b/app/src/main/res/layout/fragment_login_chooser.xml @@ -24,6 +24,7 @@ android:orientation="vertical"> + + + android:text="Fake login" + android:visibility="gone" + tools:visibility="visible"/> diff --git a/app/src/main/res/layout/fragment_login_edudziennik.xml b/app/src/main/res/layout/fragment_login_edudziennik.xml index 588eb6b0..551962b5 100644 --- a/app/src/main/res/layout/fragment_login_edudziennik.xml +++ b/app/src/main/res/layout/fragment_login_edudziennik.xml @@ -44,6 +44,7 @@ tools:srcCompat="@tools:sample/avatars" /> Czy na pewno chcesz zastosować te ustawienia?\n\nNie będziesz widział informacji o niektórych danych, przez co możesz przeoczyć ważne komunikaty, wiadomości lub oceny.\n\nUstawienia zostaną zastosowane dla aktualnie otwartego profilu. %s - %s (%s lekcji - %s godzin %s minut) + Developer mode + Te ustawienia nie są przeznaczone dla zwykłych użytkowników, wyłącznie dla twórcy tej aplikacji.\n\nNie są nawet w żaden sposób opisane, nie wiadomo co robią, więc możesz nawet nie wiedzieć kiedy coś zepsujesz.\n\nWłączenie tych opcji może spowodować utratę danych w aplikacji, uszkodzenie twojego systemu lub nawet uruchomienie wirusa na baterii.\n\nLepiej uważaj.