From e0fafde550613cfaf9d97ba204fd9f8b7fee3566 Mon Sep 17 00:00:00 2001 From: androidacy-user Date: Sat, 9 Dec 2023 21:48:11 -0500 Subject: [PATCH] update libs + bug fixes - Fixes #88 - Fixes #75 - Possibly fixes #92 Signed-off-by: androidacy-user --- app/build.gradle.kts | 24 +-- .../com/fox2code/mmm/MainApplication.kt | 7 +- .../mmm/androidacy/AndroidacyWebAPI.kt | 4 +- .../com/fox2code/mmm/settings/RepoFragment.kt | 154 +++++------------- app/src/main/res/layout/custom_repo_input.xml | 33 ++++ app/src/main/res/values-v27/themes.xml | 4 + app/src/main/res/values-v29/themes.xml | 4 + app/src/main/res/values-v31/themes.xml | 10 ++ app/src/main/res/values/themes.xml | 14 +- 9 files changed, 126 insertions(+), 128 deletions(-) create mode 100644 app/src/main/res/layout/custom_repo_input.xml diff --git a/app/build.gradle.kts b/app/build.gradle.kts index d16a512..3b9471b 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -353,20 +353,20 @@ configurations { dependencies { // UI implementation("androidx.appcompat:appcompat:1.6.1") - implementation("androidx.activity:activity-ktx:1.8.0") + implementation("androidx.activity:activity-ktx:1.8.1") implementation("androidx.emoji2:emoji2:1.4.0") implementation("androidx.emoji2:emoji2-views-helper:1.4.0") implementation("androidx.preference:preference-ktx:1.2.1") implementation("androidx.constraintlayout:constraintlayout:2.1.4") implementation("androidx.recyclerview:recyclerview:1.3.2") implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.1.0") - implementation("androidx.webkit:webkit:1.8.0") + implementation("androidx.webkit:webkit:1.9.0") implementation("com.google.android.material:material:1.10.0") - implementation("com.mikepenz:aboutlibraries:10.9.1") + implementation("com.mikepenz:aboutlibraries:10.9.2") // Utils - implementation("androidx.work:work-runtime:2.8.1") + implementation("androidx.work:work-runtime:2.9.0") implementation("com.squareup.okhttp3:okhttp:5.0.0-alpha.11") implementation("com.squareup.okhttp3:okhttp-dnsoverhttps:5.0.0-alpha.11") // logging interceptor @@ -405,14 +405,14 @@ dependencies { implementation("androidx.security:security-crypto:1.1.0-alpha06") // some utils - implementation("commons-io:commons-io:2.15.0") - implementation("org.apache.commons:commons-compress:1.24.0") + implementation("commons-io:commons-io:2.15.1") + implementation("org.apache.commons:commons-compress:1.25.0") // analytics implementation("ly.count.android:sdk:23.8.4") // annotations - implementation("org.jetbrains:annotations-java5:24.0.1") + implementation("org.jetbrains:annotations-java5:24.1.0") // debugging debugImplementation("com.squareup.leakcanary:leakcanary-android:2.12") @@ -421,16 +421,16 @@ dependencies { coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.0.4") // yes - implementation("com.github.fingerprintjs:fingerprint-android:2.0.2") + implementation("com.github.fingerprintjs:fingerprint-android:2.1.0") // room - implementation("androidx.room:room-runtime:2.6.0") + implementation("androidx.room:room-runtime:2.6.1") // To use Kotlin Symbol Processing (KSP) - ksp("androidx.room:room-compiler:2.6.0") + ksp("androidx.room:room-compiler:2.6.1") // optional - Kotlin Extensions and Coroutines support for Room - implementation("androidx.room:room-ktx:2.6.0") + implementation("androidx.room:room-ktx:2.6.1") implementation("pl.droidsonroids.gif:android-gif-drawable:1.2.28") @@ -445,7 +445,7 @@ android { } } - ndkVersion = "25.2.9519653" + ndkVersion = "26.1.10909125" dependenciesInfo { includeInApk = false includeInBundle = false diff --git a/app/src/main/kotlin/com/fox2code/mmm/MainApplication.kt b/app/src/main/kotlin/com/fox2code/mmm/MainApplication.kt index b8a9b92..9f3e622 100644 --- a/app/src/main/kotlin/com/fox2code/mmm/MainApplication.kt +++ b/app/src/main/kotlin/com/fox2code/mmm/MainApplication.kt @@ -135,10 +135,6 @@ class MainApplication : Application(), Configuration.Provider, ActivityLifecycle return existingKey!! } - override fun getWorkManagerConfiguration(): Configuration { - return Configuration.Builder().build() - } - fun updateTheme() { @StyleRes val themeResId: Int var theme: String? @@ -772,4 +768,7 @@ class MainApplication : Application(), Configuration.Provider, ActivityLifecycle override fun onActivityDestroyed(activity: Activity) { } + + override val workManagerConfiguration: Configuration + get() = Configuration.Builder().build() } diff --git a/app/src/main/kotlin/com/fox2code/mmm/androidacy/AndroidacyWebAPI.kt b/app/src/main/kotlin/com/fox2code/mmm/androidacy/AndroidacyWebAPI.kt index 6d065da..f11c882 100644 --- a/app/src/main/kotlin/com/fox2code/mmm/androidacy/AndroidacyWebAPI.kt +++ b/app/src/main/kotlin/com/fox2code/mmm/androidacy/AndroidacyWebAPI.kt @@ -59,8 +59,8 @@ class AndroidacyWebAPI( * return current effective compat mode */ @get:JavascriptInterface - var effectiveCompatMode = 0 - var notifiedCompatMode = 0 + var effectiveCompatMode = 1 + var notifiedCompatMode = 1 fun forceQuitRaw(error: String?) { Toast.makeText(activity, error, Toast.LENGTH_LONG).show() activity.runOnUiThread { activity.finish() } diff --git a/app/src/main/kotlin/com/fox2code/mmm/settings/RepoFragment.kt b/app/src/main/kotlin/com/fox2code/mmm/settings/RepoFragment.kt index 7d1f485..c9c0a0b 100644 --- a/app/src/main/kotlin/com/fox2code/mmm/settings/RepoFragment.kt +++ b/app/src/main/kotlin/com/fox2code/mmm/settings/RepoFragment.kt @@ -15,6 +15,7 @@ import android.os.Handler import android.os.Looper import android.text.Editable import android.text.TextWatcher +import android.view.LayoutInflater import android.view.inputmethod.EditorInfo import android.widget.EditText import android.widget.Toast @@ -38,6 +39,7 @@ import com.fox2code.mmm.utils.room.ReposListDatabase import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.snackbar.BaseTransientBottomBar import com.google.android.material.snackbar.Snackbar +import com.google.android.material.textfield.TextInputEditText import com.topjohnwu.superuser.internal.UiThreadHandler import timber.log.Timber import java.io.IOException @@ -55,91 +57,7 @@ class RepoFragment : PreferenceFragmentCompat() { // CaptchaWebview.setVisible(false); val androidacyTestMode = findPreference("pref_androidacy_test_mode")!! - if (!MainApplication.isDeveloper) { - androidacyTestMode.isVisible = false - } else { - // Show a warning if user tries to enable test mode - androidacyTestMode.onPreferenceChangeListener = - Preference.OnPreferenceChangeListener { _: Preference?, newValue: Any -> - if (java.lang.Boolean.parseBoolean(newValue.toString())) { - // Use MaterialAlertDialogBuilder - MaterialAlertDialogBuilder(requireContext()).setTitle(R.string.warning) - .setCancelable(false).setMessage( - R.string.androidacy_test_mode_warning - ) - .setPositiveButton(android.R.string.ok) { _: DialogInterface?, _: Int -> - // User clicked OK button - MainApplication.getPreferences("mmm")!! - .edit().putBoolean("androidacy_test_mode", true).apply() - // Check the switch - val mStartActivity = - Intent(requireContext(), MainActivity::class.java) - mStartActivity.flags = - Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK - val mPendingIntentId = 123456 - // If < 23, FLAG_IMMUTABLE is not available - val mPendingIntent: PendingIntent = PendingIntent.getActivity( - requireContext(), - mPendingIntentId, - mStartActivity, - PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE - ) - val mgr = - requireContext().getSystemService(ALARM_SERVICE) as AlarmManager - mgr[AlarmManager.RTC, System.currentTimeMillis() + 100] = - mPendingIntent - if (MainApplication.forceDebugLogging) Timber.d( - "Restarting app to save staging endpoint preference: %s", - newValue - ) - exitProcess(0) // Exit app process - } - .setNegativeButton(android.R.string.cancel) { _: DialogInterface?, _: Int -> - // User cancelled the dialog - // Uncheck the switch - val switchPreferenceCompat = - androidacyTestMode as SwitchPreferenceCompat - switchPreferenceCompat.isChecked = false - // There's probably a better way to do this than duplicate code but I'm too lazy to figure it out - MainApplication.getPreferences("mmm")!! - .edit().putBoolean("androidacy_test_mode", false).apply() - }.show() - } else { - MainApplication.getPreferences("mmm")!! - .edit().putBoolean("androidacy_test_mode", false).apply() - // Show dialog to restart app with ok button - MaterialAlertDialogBuilder(requireContext()).setTitle(R.string.warning) - .setCancelable(false).setMessage( - R.string.androidacy_test_mode_disable_warning - ) - .setNeutralButton(android.R.string.ok) { _: DialogInterface?, _: Int -> - // User clicked OK button - val mStartActivity = - Intent(requireContext(), MainActivity::class.java) - mStartActivity.flags = - Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK - val mPendingIntentId = 123456 - // If < 23, FLAG_IMMUTABLE is not available - val mPendingIntent: PendingIntent = PendingIntent.getActivity( - requireContext(), - mPendingIntentId, - mStartActivity, - PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE - ) - val mgr = - requireContext().getSystemService(ALARM_SERVICE) as AlarmManager - mgr[AlarmManager.RTC, System.currentTimeMillis() + 100] = - mPendingIntent - if (MainApplication.forceDebugLogging) Timber.d( - "Restarting app to save staging endpoint preference: %s", - newValue - ) - exitProcess(0) // Exit app process - }.show() - } - true - } - } + androidacyTestMode.isVisible = false // Get magisk_alt_repo enabled state from room reposlist db val db = Room.databaseBuilder( requireContext(), @@ -218,6 +136,38 @@ class RepoFragment : PreferenceFragmentCompat() { findPreference("pref_androidacy_repo_donate")!! prefAndroidacyRepoApiD.isEnabled = false prefAndroidacyRepoApiD.isVisible = false + } else { + val clipboard = + requireContext().getSystemService(CLIPBOARD_SERVICE) as ClipboardManager + val prefDonateAndroidacy = + findPreference("pref_androidacy_repo_donate")!! + prefDonateAndroidacy.onPreferenceClickListener = + Preference.OnPreferenceClickListener { _: Preference? -> + // copy FOX2CODE promo code to clipboard and toast user that they can use it for half off any subscription + val toastText = requireContext().getString(R.string.promo_code_copied) + clipboard.setPrimaryClip(ClipData.newPlainText(toastText, "FOX2CODE")) + Toast.makeText(requireContext(), toastText, Toast.LENGTH_SHORT).show() + // open androidacy + IntentHelper.openUrl( + MainApplication.INSTANCE!!.lastActivity!!, + "https://www.androidacy.com/membership-join/?utm_source=AMMM&utm_medium=app&utm_campaign=donate" + ) + true + } + // handle long click on pref_donate_androidacy + prefDonateAndroidacy.onPreferenceLongClickListener = + LongClickablePreference.OnPreferenceLongClickListener { _: Preference? -> + // copy to clipboard + val toastText = requireContext().getString(R.string.link_copied) + clipboard.setPrimaryClip( + ClipData.newPlainText( + toastText, + "https://www.androidacy.com/membership-join/?utm_source=AMMM&utm_medium=app&utm_campaign=donate" + ) + ) + Toast.makeText(requireContext(), toastText, Toast.LENGTH_SHORT).show() + true + } } } val originalApiKeyRef = arrayOf( @@ -510,15 +460,13 @@ class RepoFragment : PreferenceFragmentCompat() { Preference.OnPreferenceClickListener { val context = requireContext() val builder = MaterialAlertDialogBuilder(context) - val input = EditText(context) - input.setHint(R.string.custom_url) - input.setHorizontallyScrolling(true) - input.maxLines = 1 + val view = LayoutInflater.from(context).inflate(R.layout.custom_repo_input, null) builder.setIcon(R.drawable.ic_baseline_add_box_24) builder.setTitle(R.string.add_repo) // make link in message clickable builder.setMessage(R.string.add_repo_message) - builder.setView(input) + builder.setView(view) + val input = view.findViewById(R.id.custom_repo_input_edit) builder.setPositiveButton("OK") { _: DialogInterface?, _: Int -> var text = input.text.toString() text = text.trim { it <= ' ' } @@ -571,8 +519,7 @@ class RepoFragment : PreferenceFragmentCompat() { ) startActivity(intent) } - val alertDialog = builder.show() - val positiveButton = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE) + val alertDialog = builder.create() // validate as they type input.addTextChangedListener(object : TextWatcher { override fun beforeTextChanged( @@ -594,42 +541,31 @@ class RepoFragment : PreferenceFragmentCompat() { if (charSequence.toString().isEmpty()) { input.error = getString(R.string.empty_field) if (MainApplication.forceDebugLogging) Timber.d("No input for repo") - positiveButton.isEnabled = false + return } else if (!charSequence.toString() .matches("^https://.*".toRegex()) ) { input.error = getString(R.string.invalid_repo_url) if (MainApplication.forceDebugLogging) Timber.d("Non https link for repo") - positiveButton.isEnabled = false + return } else if (charSequence.toString().contains(" ")) { input.error = getString(R.string.invalid_repo_url) if (MainApplication.forceDebugLogging) Timber.d("Repo url has space") - positiveButton.isEnabled = false + return } else if (!customRepoManager.canAddRepo(charSequence.toString())) { input.error = getString(R.string.repo_already_added) if (MainApplication.forceDebugLogging) Timber.d("Could not add repo for misc reason") - positiveButton.isEnabled = false + return } else { // enable ok button if (MainApplication.forceDebugLogging) Timber.d("Repo URL is ok") - positiveButton.isEnabled = true + return } } override fun afterTextChanged(s: Editable) {} }) - positiveButton.isEnabled = false - val dp10 = MainApplication.INSTANCE!!.lastActivity?.resources?.getDimensionPixelSize( - R.dimen.dp10 - ) ?: 0 - val dp20 = MainApplication.INSTANCE!!.lastActivity?.resources?.getDimensionPixelSize( - R.dimen.dp20 - ) ?: 0 - alertDialog.window!!.setSoftInputMode(20) - alertDialog.window!!.setLayout( - dp20, - dp10 - ) + alertDialog.show() true } } diff --git a/app/src/main/res/layout/custom_repo_input.xml b/app/src/main/res/layout/custom_repo_input.xml new file mode 100644 index 0000000..3685d90 --- /dev/null +++ b/app/src/main/res/layout/custom_repo_input.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-v27/themes.xml b/app/src/main/res/values-v27/themes.xml index 8c9802e..347fa46 100644 --- a/app/src/main/res/values-v27/themes.xml +++ b/app/src/main/res/values-v27/themes.xml @@ -33,5 +33,9 @@ false true @dimen/card_corner_radius + @style/Theme.MagiskModuleManager.AlertDialog + + @style/Widget.Material3.TextInputEditText.OutlinedBox + @style/Widget.Material3.TextInputLayout.OutlinedBox \ No newline at end of file diff --git a/app/src/main/res/values-v29/themes.xml b/app/src/main/res/values-v29/themes.xml index fdb1759..2f89f6c 100644 --- a/app/src/main/res/values-v29/themes.xml +++ b/app/src/main/res/values-v29/themes.xml @@ -34,5 +34,9 @@ false true @dimen/card_corner_radius + @style/Theme.MagiskModuleManager.AlertDialog + + @style/Widget.Material3.TextInputEditText.OutlinedBox + @style/Widget.Material3.TextInputLayout.OutlinedBox \ No newline at end of file diff --git a/app/src/main/res/values-v31/themes.xml b/app/src/main/res/values-v31/themes.xml index a18e803..c96c882 100644 --- a/app/src/main/res/values-v31/themes.xml +++ b/app/src/main/res/values-v31/themes.xml @@ -18,6 +18,10 @@ @style/Theme.Design.NoActionBar @dimen/card_corner_radius @style/Theme.MagiskModuleManager.AlertDialog + + @style/Widget.Material3.TextInputEditText.OutlinedBox + @style/Widget.Material3.TextInputLayout.OutlinedBox + @@ -58,6 +65,9 @@ @style/Theme.Design.NoActionBar @dimen/card_corner_radius @style/Theme.MagiskModuleManager.AlertDialog + + @style/Widget.Material3.TextInputEditText.OutlinedBox + @style/Widget.Material3.TextInputLayout.OutlinedBox diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index 5b285f3..3ef0c07 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -36,6 +36,9 @@ false true @dimen/card_corner_radius + + @style/Widget.Material3.TextInputEditText.OutlinedBox + @style/Widget.Material3.TextInputLayout.OutlinedBox @@ -123,6 +132,9 @@ true @dimen/card_corner_radius @style/Theme.MagiskModuleManager.AlertDialog + + @style/Widget.Material3.TextInputEditText.OutlinedBox + @style/Widget.Material3.TextInputLayout.OutlinedBox @@ -137,7 +149,7 @@ -