diff options
Diffstat (limited to '')
4 files changed, 74 insertions, 19 deletions
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<Recyc public HeaderSectionRecyclerViewAdapter(BaseActivity baseActivity, RequestManager glide, String accountName, SharedPreferences sharedPreferences, SharedPreferences navigationDrawerSharedPreferences, + SharedPreferences securitySharedPreferences, PageToggle pageToggle) { this.baseActivity = baseActivity; resources = baseActivity.getResources(); @@ -56,7 +57,7 @@ public class HeaderSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recyc this.accountName = accountName; isLoggedIn = accountName != null; this.pageToggle = pageToggle; - requireAuthToAccountSection = sharedPreferences.getBoolean(SharedPreferencesUtils.REQUIRE_AUTHENTICATION_TO_GO_TO_ACCOUNT_SECTION_IN_NAVIGATION_DRAWER, false); + requireAuthToAccountSection = securitySharedPreferences.getBoolean(SharedPreferencesUtils.REQUIRE_AUTHENTICATION_TO_GO_TO_ACCOUNT_SECTION_IN_NAVIGATION_DRAWER, false); showAvatarOnTheRightInTheNavigationDrawer = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_AVATAR_ON_THE_RIGHT, false); showAvatarOnTheRightInTheNavigationDrawer = navigationDrawerSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_AVATAR_ON_THE_RIGHT, false); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/NavigationDrawerRecyclerViewMergedAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/NavigationDrawerRecyclerViewMergedAdapter.java index 553aaee4..2eb97d96 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/NavigationDrawerRecyclerViewMergedAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/NavigationDrawerRecyclerViewMergedAdapter.java @@ -35,23 +35,25 @@ public class NavigationDrawerRecyclerViewMergedAdapter { public NavigationDrawerRecyclerViewMergedAdapter(BaseActivity baseActivity, SharedPreferences sharedPreferences, SharedPreferences nsfwAndSpoilerSharedPreferences, SharedPreferences navigationDrawerSharedPreferences, + SharedPreferences securitySharedPreferences, CustomThemeWrapper customThemeWrapper, String accountName, ItemClickListener itemClickListener) { RequestManager glide = Glide.with(baseActivity); headerSectionRecyclerViewAdapter = new HeaderSectionRecyclerViewAdapter(baseActivity, glide, accountName, - sharedPreferences, navigationDrawerSharedPreferences, new HeaderSectionRecyclerViewAdapter.PageToggle() { - @Override - public void openAccountSection() { - NavigationDrawerRecyclerViewMergedAdapter.this.openAccountSection(); - } - - @Override - public void closeAccountSectionWithoutChangeIconResource() { - NavigationDrawerRecyclerViewMergedAdapter.this.closeAccountSectionWithoutChangeIconResource(); - } - }); + sharedPreferences, navigationDrawerSharedPreferences, securitySharedPreferences, + new HeaderSectionRecyclerViewAdapter.PageToggle() { + @Override + public void openAccountSection() { + NavigationDrawerRecyclerViewMergedAdapter.this.openAccountSection(); + } + + @Override + public void closeAccountSectionWithoutChangeIconResource() { + NavigationDrawerRecyclerViewMergedAdapter.this.closeAccountSectionWithoutChangeIconResource(); + } + }); accountSectionRecyclerViewAdapter = new AccountSectionRecyclerViewAdapter(baseActivity, customThemeWrapper, navigationDrawerSharedPreferences, accountName != null, itemClickListener); redditSectionRecyclerViewAdapter = new RedditSectionRecyclerViewAdapter(baseActivity, customThemeWrapper, diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/AccountChooserBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/AccountChooserBottomSheetFragment.java index a76ecd47..a358caa2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/AccountChooserBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/AccountChooserBottomSheetFragment.java @@ -1,18 +1,28 @@ package ml.docilealligator.infinityforreddit.bottomsheetfragments; +import static androidx.biometric.BiometricManager.Authenticators.BIOMETRIC_STRONG; +import static androidx.biometric.BiometricManager.Authenticators.DEVICE_CREDENTIAL; + import android.content.Context; +import android.content.SharedPreferences; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import androidx.annotation.NonNull; +import androidx.biometric.BiometricManager; +import androidx.biometric.BiometricPrompt; +import androidx.core.content.ContextCompat; import androidx.lifecycle.ViewModelProvider; import androidx.recyclerview.widget.RecyclerView; import com.bumptech.glide.Glide; +import java.util.concurrent.Executor; + import javax.inject.Inject; +import javax.inject.Named; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; @@ -23,6 +33,7 @@ import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.adapters.AccountChooserRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.LandscapeExpandedBottomSheetDialogFragment; +import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; public class AccountChooserBottomSheetFragment extends LandscapeExpandedBottomSheetDialogFragment { @@ -30,6 +41,9 @@ public class AccountChooserBottomSheetFragment extends LandscapeExpandedBottomSh RedditDataRoomDatabase redditDataRoomDatabase; @Inject CustomThemeWrapper customThemeWrapper; + @Inject + @Named("security") + SharedPreferences sharedPreferences; BaseActivity activity; RecyclerView recyclerView; AccountChooserRecyclerViewAdapter adapter; @@ -57,11 +71,46 @@ public class AccountChooserBottomSheetFragment extends LandscapeExpandedBottomSh }); recyclerView.setAdapter(adapter); - accountViewModel = new ViewModelProvider(this, - new AccountViewModel.Factory(redditDataRoomDatabase)).get(AccountViewModel.class); - accountViewModel.getAllAccountsLiveData().observe(getViewLifecycleOwner(), accounts -> { - 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; } |