From 9703a46f5fcdf6973ee19c43ca20d053aef80176 Mon Sep 17 00:00:00 2001 From: Patrick Demers Date: Wed, 2 Nov 2022 07:11:46 -0500 Subject: wait to load security settings until successful authentication (#1196) --- .../customviews/CustomFontPreferenceFragmentCompat.java | 9 +++++++-- .../settings/SecurityPreferenceFragment.java | 12 ++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) (limited to 'app') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontPreferenceFragmentCompat.java b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontPreferenceFragmentCompat.java index 695131cf..3357918a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontPreferenceFragmentCompat.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontPreferenceFragmentCompat.java @@ -8,6 +8,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.preference.Preference; import androidx.preference.PreferenceFragmentCompat; +import androidx.preference.PreferenceScreen; import ml.docilealligator.infinityforreddit.CustomFontReceiver; import ml.docilealligator.infinityforreddit.CustomThemeWrapperReceiver; @@ -20,9 +21,13 @@ public abstract class CustomFontPreferenceFragmentCompat extends PreferenceFragm public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); - int preferenceCount = getPreferenceScreen().getPreferenceCount(); + PreferenceScreen preferenceScreen = getPreferenceScreen(); + if (preferenceScreen == null) + return; + + int preferenceCount = preferenceScreen.getPreferenceCount(); for (int i = 0; i < preferenceCount; i++) { - Preference preference = getPreferenceScreen().getPreference(i); + Preference preference = preferenceScreen.getPreference(i); if (preference instanceof CustomThemeWrapperReceiver) { ((CustomThemeWrapperReceiver) preference).setCustomThemeWrapper(activity.customThemeWrapper); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/SecurityPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/SecurityPreferenceFragment.java index a1d49a82..b62a6b98 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/SecurityPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/SecurityPreferenceFragment.java @@ -34,8 +34,14 @@ public class SecurityPreferenceFragment extends CustomFontPreferenceFragmentComp @Named("default") SharedPreferences sharedPreferences; + String rootKey; + @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { + this.rootKey = rootKey; + } + + private void createPreferences() { PreferenceManager preferenceManager = getPreferenceManager(); preferenceManager.setSharedPreferencesName(SharedPreferencesUtils.SECURITY_SHARED_PREFERENCES_FILE); setPreferencesFromResource(R.xml.security_preferences, rootKey); @@ -80,6 +86,12 @@ public class SecurityPreferenceFragment extends CustomFontPreferenceFragmentComp Executor executor = ContextCompat.getMainExecutor(activity); BiometricPrompt biometricPrompt = new BiometricPrompt(SecurityPreferenceFragment.this, executor, new BiometricPrompt.AuthenticationCallback() { + @Override + public void onAuthenticationSucceeded(@NonNull BiometricPrompt.AuthenticationResult result) { + super.onAuthenticationSucceeded(result); + createPreferences(); + } + @Override public void onAuthenticationError(int errorCode, @NonNull CharSequence errString) { activity.onBackPressed(); -- cgit v1.2.3