diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java index 561acf46..02bff5d4 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java @@ -213,6 +213,9 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb @Named("navigation_drawer") SharedPreferences mNavigationDrawerSharedPreferences; @Inject + @Named("security") + SharedPreferences mSecuritySharedPreferences; + @Inject CustomThemeWrapper mCustomThemeWrapper; @Inject Executor mExecutor; @@ -724,8 +727,8 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb fab.setVisibility(View.VISIBLE); adapter = new NavigationDrawerRecyclerViewMergedAdapter(this, mSharedPreferences, - mNsfwAndSpoilerSharedPreferences, mNavigationDrawerSharedPreferences, mCustomThemeWrapper, mAccountName, - new NavigationDrawerRecyclerViewMergedAdapter.ItemClickListener() { + mNsfwAndSpoilerSharedPreferences, mNavigationDrawerSharedPreferences, mSecuritySharedPreferences, + mCustomThemeWrapper, mAccountName, new NavigationDrawerRecyclerViewMergedAdapter.ItemClickListener() { @Override public void onMenuClick(int stringId) { Intent intent = null; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/HeaderSectionRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/HeaderSectionRecyclerViewAdapter.java index 6533f610..efc4ecc0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/HeaderSectionRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/HeaderSectionRecyclerViewAdapter.java @@ -49,6 +49,7 @@ public class HeaderSectionRecyclerViewAdapter extends RecyclerView.Adapter { - adapter.changeAccountsDataset(accounts); - }); + if (sharedPreferences.getBoolean(SharedPreferencesUtils.REQUIRE_AUTHENTICATION_TO_GO_TO_ACCOUNT_SECTION_IN_NAVIGATION_DRAWER, false)) { + BiometricManager biometricManager = BiometricManager.from(activity); + if (biometricManager.canAuthenticate(BIOMETRIC_STRONG | DEVICE_CREDENTIAL) == BiometricManager.BIOMETRIC_SUCCESS) { + Executor executor = ContextCompat.getMainExecutor(activity); + BiometricPrompt biometricPrompt = new BiometricPrompt(this, + executor, new BiometricPrompt.AuthenticationCallback() { + @Override + public void onAuthenticationSucceeded( + @NonNull BiometricPrompt.AuthenticationResult result) { + super.onAuthenticationSucceeded(result); + accountViewModel = new ViewModelProvider(AccountChooserBottomSheetFragment.this, + new AccountViewModel.Factory(redditDataRoomDatabase)).get(AccountViewModel.class); + accountViewModel.getAllAccountsLiveData().observe(getViewLifecycleOwner(), accounts -> { + adapter.changeAccountsDataset(accounts); + }); + } + + @Override + public void onAuthenticationError(int errorCode, @NonNull CharSequence errString) { + super.onAuthenticationError(errorCode, errString); + dismiss(); + } + }); + + BiometricPrompt.PromptInfo promptInfo = new BiometricPrompt.PromptInfo.Builder() + .setTitle(getString(R.string.unlock)) + .setAllowedAuthenticators(BIOMETRIC_STRONG | DEVICE_CREDENTIAL) + .build(); + + biometricPrompt.authenticate(promptInfo); + } else { + dismiss(); + } + } else { + accountViewModel = new ViewModelProvider(this, + new AccountViewModel.Factory(redditDataRoomDatabase)).get(AccountViewModel.class); + accountViewModel.getAllAccountsLiveData().observe(getViewLifecycleOwner(), accounts -> { + adapter.changeAccountsDataset(accounts); + }); + } return rootView; } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9bbe06c9..e70184cd 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -532,7 +532,7 @@ Threshold Pull to Refresh Security - Require Authentication to Go to Account Section in Navigation Drawer + Require Authentication to Show Accounts Long Press to Hide Toolbar Hide Toolbar by Default Customize Bottom Navigation Bar diff --git a/app/src/main/res/xml/security_preferences.xml b/app/src/main/res/xml/security_preferences.xml index ea150dcf..e388f4c4 100644 --- a/app/src/main/res/xml/security_preferences.xml +++ b/app/src/main/res/xml/security_preferences.xml @@ -3,7 +3,7 @@ + app:title="@string/settings_require_authentication_to_show_accounts" />