From f86edc2ffce1cf050a6e5d9f5a16926e9803ff18 Mon Sep 17 00:00:00 2001 From: androidacy-user Date: Thu, 7 Sep 2023 21:41:33 -0400 Subject: [PATCH] use md3 switches for prefs w/o java Signed-off-by: androidacy-user --- .../fox2code/mmm/settings/AppearanceFragment.kt | 1 - .../fox2code/mmm/settings/CreditsFragment.kt | 1 - .../com/fox2code/mmm/settings/DebugFragment.kt | 1 - .../com/fox2code/mmm/settings/InfoFragment.kt | 1 - .../fox2code/mmm/settings/PrivacyFragment.kt | 1 - .../com/fox2code/mmm/settings/RepoFragment.kt | 17 ++++++++++------- .../fox2code/mmm/settings/SecurityFragment.kt | 1 - .../fox2code/mmm/settings/SettingsActivity.kt | 13 ------------- .../com/fox2code/mmm/settings/UpdateFragment.kt | 1 - app/src/main/res/xml/debugging_preferences.xml | 6 +++++- app/src/main/res/xml/privacy_preferences.xml | 6 +++++- app/src/main/res/xml/repo_preferences.xml | 8 ++++++++ app/src/main/res/xml/security_preferences.xml | 7 ++++++- app/src/main/res/xml/theme_preferences.xml | 4 ++++ app/src/main/res/xml/update_preferences.xml | 3 +++ 15 files changed, 41 insertions(+), 30 deletions(-) diff --git a/app/src/main/kotlin/com/fox2code/mmm/settings/AppearanceFragment.kt b/app/src/main/kotlin/com/fox2code/mmm/settings/AppearanceFragment.kt index 5580dd4..f0db2b9 100644 --- a/app/src/main/kotlin/com/fox2code/mmm/settings/AppearanceFragment.kt +++ b/app/src/main/kotlin/com/fox2code/mmm/settings/AppearanceFragment.kt @@ -54,7 +54,6 @@ class AppearanceFragment : PreferenceFragmentCompat() { throw RuntimeException(getString(R.string.error_encrypted_shared_preferences)) } setPreferencesFromResource(R.xml.theme_preferences, rootKey) - SettingsActivity.applyMaterial3(preferenceScreen) val themePreference = findPreference("pref_theme") // If transparent theme(s) are set, disable monet if (themePreference!!.value == "transparent_light") { diff --git a/app/src/main/kotlin/com/fox2code/mmm/settings/CreditsFragment.kt b/app/src/main/kotlin/com/fox2code/mmm/settings/CreditsFragment.kt index 3860428..f639577 100644 --- a/app/src/main/kotlin/com/fox2code/mmm/settings/CreditsFragment.kt +++ b/app/src/main/kotlin/com/fox2code/mmm/settings/CreditsFragment.kt @@ -45,7 +45,6 @@ class CreditsFragment : PreferenceFragmentCompat() { } setPreferencesFromResource(R.xml.credits_preferences, rootKey) - SettingsActivity.applyMaterial3(preferenceScreen) diff --git a/app/src/main/kotlin/com/fox2code/mmm/settings/DebugFragment.kt b/app/src/main/kotlin/com/fox2code/mmm/settings/DebugFragment.kt index 3120c03..bf2d597 100644 --- a/app/src/main/kotlin/com/fox2code/mmm/settings/DebugFragment.kt +++ b/app/src/main/kotlin/com/fox2code/mmm/settings/DebugFragment.kt @@ -54,7 +54,6 @@ class DebugFragment : PreferenceFragmentCompat() { } setPreferencesFromResource(R.xml.debugging_preferences, rootKey) - SettingsActivity.applyMaterial3(preferenceScreen) if (!MainApplication.isDeveloper) { findPreference("pref_disable_low_quality_module_filter")!!.isVisible = false diff --git a/app/src/main/kotlin/com/fox2code/mmm/settings/InfoFragment.kt b/app/src/main/kotlin/com/fox2code/mmm/settings/InfoFragment.kt index f52a84f..9c73921 100644 --- a/app/src/main/kotlin/com/fox2code/mmm/settings/InfoFragment.kt +++ b/app/src/main/kotlin/com/fox2code/mmm/settings/InfoFragment.kt @@ -45,7 +45,6 @@ class InfoFragment : PreferenceFragmentCompat() { } setPreferencesFromResource(R.xml.app_info_preferences, rootKey) - SettingsActivity.applyMaterial3(preferenceScreen) val clipboard = requireContext().getSystemService(FoxActivity.CLIPBOARD_SERVICE) as ClipboardManager diff --git a/app/src/main/kotlin/com/fox2code/mmm/settings/PrivacyFragment.kt b/app/src/main/kotlin/com/fox2code/mmm/settings/PrivacyFragment.kt index b8057de..e7bf202 100644 --- a/app/src/main/kotlin/com/fox2code/mmm/settings/PrivacyFragment.kt +++ b/app/src/main/kotlin/com/fox2code/mmm/settings/PrivacyFragment.kt @@ -50,7 +50,6 @@ class PrivacyFragment : PreferenceFragmentCompat() { throw RuntimeException(getString(R.string.error_encrypted_shared_preferences)) } setPreferencesFromResource(R.xml.privacy_preferences, rootKey) - SettingsActivity.applyMaterial3(preferenceScreen) // Crash reporting val crashReportingPreference = findPreference("pref_crash_reporting") 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 92c1a34..84ea14a 100644 --- a/app/src/main/kotlin/com/fox2code/mmm/settings/RepoFragment.kt +++ b/app/src/main/kotlin/com/fox2code/mmm/settings/RepoFragment.kt @@ -21,7 +21,6 @@ import android.widget.Toast import androidx.preference.EditTextPreference import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat -import androidx.preference.PreferenceGroup import androidx.preference.SwitchPreferenceCompat import androidx.preference.TwoStatePreference import androidx.room.Room @@ -70,7 +69,7 @@ class RepoFragment : PreferenceFragmentCompat() { 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.getSharedPreferences("mmm")!! @@ -115,7 +114,7 @@ class RepoFragment : PreferenceFragmentCompat() { 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 = @@ -174,7 +173,7 @@ class RepoFragment : PreferenceFragmentCompat() { MaterialAlertDialogBuilder(requireContext()).setTitle(R.string.androidacy_repo_disabled) .setCancelable(false).setMessage( R.string.androidacy_repo_disabled_message - ) + ) .setPositiveButton(R.string.download_full_app) { _: DialogInterface?, _: Int -> // User clicked OK button. Open GitHub releases page val browserIntent = Intent( @@ -367,7 +366,9 @@ class RepoFragment : PreferenceFragmentCompat() { // If the key is valid, save it if (valid) { originalApiKeyRef[0] = apiKey - RepoManager.getINSTANCE()!!.androidacyRepoData!!.setToken(apiKey) + RepoManager.getINSTANCE()!!.androidacyRepoData!!.setToken( + apiKey + ) MainApplication.getSharedPreferences("androidacy")!! .edit() .putString("pref_androidacy_api_token", apiKey) @@ -422,7 +423,10 @@ class RepoFragment : PreferenceFragmentCompat() { BaseTransientBottomBar.LENGTH_SHORT ).show() // Save the original key - MainApplication.INSTANCE!!.getSharedPreferences("androidacy", 0) + MainApplication.INSTANCE!!.getSharedPreferences( + "androidacy", + 0 + ) .edit().putString( "pref_androidacy_api_token", originalApiKeyRef[0] @@ -848,7 +852,6 @@ class RepoFragment : PreferenceFragmentCompat() { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { preferenceManager.sharedPreferencesName = "mmm" setPreferencesFromResource(R.xml.repo_preferences, rootKey) - SettingsActivity.applyMaterial3(preferenceScreen) setRepoData(RepoManager.MAGISK_ALT_REPO) setRepoData(RepoManager.ANDROIDACY_MAGISK_REPO_ENDPOINT) updateCustomRepoList(true) diff --git a/app/src/main/kotlin/com/fox2code/mmm/settings/SecurityFragment.kt b/app/src/main/kotlin/com/fox2code/mmm/settings/SecurityFragment.kt index 7bc4d99..5108f4a 100644 --- a/app/src/main/kotlin/com/fox2code/mmm/settings/SecurityFragment.kt +++ b/app/src/main/kotlin/com/fox2code/mmm/settings/SecurityFragment.kt @@ -52,7 +52,6 @@ class SecurityFragment : PreferenceFragmentCompat() { } setPreferencesFromResource(R.xml.security_preferences, rootKey) - SettingsActivity.applyMaterial3(preferenceScreen) findPreference("pref_dns_over_https")!!.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _: Preference?, v: Any? -> diff --git a/app/src/main/kotlin/com/fox2code/mmm/settings/SettingsActivity.kt b/app/src/main/kotlin/com/fox2code/mmm/settings/SettingsActivity.kt index a213e9d..37952c8 100644 --- a/app/src/main/kotlin/com/fox2code/mmm/settings/SettingsActivity.kt +++ b/app/src/main/kotlin/com/fox2code/mmm/settings/SettingsActivity.kt @@ -17,8 +17,6 @@ import android.widget.Toast import androidx.fragment.app.FragmentTransaction import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat -import androidx.preference.PreferenceGroup -import androidx.preference.SwitchPreferenceCompat import androidx.security.crypto.EncryptedSharedPreferences import androidx.security.crypto.MasterKey import com.fox2code.foxcompat.app.FoxActivity @@ -165,7 +163,6 @@ class SettingsActivity : FoxActivity(), LanguageActivity, throw RuntimeException(getString(R.string.error_encrypted_shared_preferences)) } setPreferencesFromResource(R.xml.root_preferences, rootKey) - applyMaterial3(preferenceScreen) // track all non empty values dataStore.sharedPreferences // disabled until EncryptedSharedPreferences fixes getAll() @@ -282,16 +279,6 @@ class SettingsActivity : FoxActivity(), LanguageActivity, } } - - fun applyMaterial3(p: Preference) { - if (p is PreferenceGroup) { - for (i in 0 until p.preferenceCount) { - applyMaterial3(p.getPreference(i)) - } - } - (p as? SwitchPreferenceCompat)?.widgetLayoutResource = - R.layout.preference_material_switch - } } override fun onPreferenceStartFragment( diff --git a/app/src/main/kotlin/com/fox2code/mmm/settings/UpdateFragment.kt b/app/src/main/kotlin/com/fox2code/mmm/settings/UpdateFragment.kt index e9f9e91..2d75280 100644 --- a/app/src/main/kotlin/com/fox2code/mmm/settings/UpdateFragment.kt +++ b/app/src/main/kotlin/com/fox2code/mmm/settings/UpdateFragment.kt @@ -60,7 +60,6 @@ class UpdateFragment : PreferenceFragmentCompat() { throw RuntimeException(getString(R.string.error_encrypted_shared_preferences)) } setPreferencesFromResource(R.xml.update_preferences, rootKey) - SettingsActivity.applyMaterial3(preferenceScreen) // track all non empty values val sharedPreferences = dataStore.sharedPreferences val debugNotification = findPreference("pref_background_update_check_debug") diff --git a/app/src/main/res/xml/debugging_preferences.xml b/app/src/main/res/xml/debugging_preferences.xml index 7faaf23..019664b 100644 --- a/app/src/main/res/xml/debugging_preferences.xml +++ b/app/src/main/res/xml/debugging_preferences.xml @@ -1,9 +1,11 @@ - + - + - +