mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-27 19:38:22 +01:00
Fix biometric authentication prompt not shown when opening the account section in the navigation drawer. Require biometric authentication in AccountChooserBottomSheetFragment.
This commit is contained in:
parent
345392a833
commit
22cf0a9c20
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
sharedPreferences, navigationDrawerSharedPreferences, securitySharedPreferences,
|
||||
new HeaderSectionRecyclerViewAdapter.PageToggle() {
|
||||
@Override
|
||||
public void openAccountSection() {
|
||||
NavigationDrawerRecyclerViewMergedAdapter.this.openAccountSection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeAccountSectionWithoutChangeIconResource() {
|
||||
NavigationDrawerRecyclerViewMergedAdapter.this.closeAccountSectionWithoutChangeIconResource();
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public void closeAccountSectionWithoutChangeIconResource() {
|
||||
NavigationDrawerRecyclerViewMergedAdapter.this.closeAccountSectionWithoutChangeIconResource();
|
||||
}
|
||||
});
|
||||
accountSectionRecyclerViewAdapter = new AccountSectionRecyclerViewAdapter(baseActivity, customThemeWrapper,
|
||||
navigationDrawerSharedPreferences, accountName != null, itemClickListener);
|
||||
redditSectionRecyclerViewAdapter = new RedditSectionRecyclerViewAdapter(baseActivity, customThemeWrapper,
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -532,7 +532,7 @@
|
||||
<string name="settings_swipe_action_threshold">Threshold</string>
|
||||
<string name="settings_pull_to_refresh_title">Pull to Refresh</string>
|
||||
<string name="settings_security_title">Security</string>
|
||||
<string name="settings_require_authentication_to_go_to_account_section_in_navigation_drawer_title">Require Authentication to Go to Account Section in Navigation Drawer</string>
|
||||
<string name="settings_require_authentication_to_show_accounts">Require Authentication to Show Accounts</string>
|
||||
<string name="settings_long_press_to_hide_toolbar_in_compact_layout_title">Long Press to Hide Toolbar</string>
|
||||
<string name="settings_post_compact_layout_toolbar_hidden_by_default_title">Hide Toolbar by Default</string>
|
||||
<string name="settings_customize_bottom_app_bar_title">Customize Bottom Navigation Bar</string>
|
||||
|
@ -3,7 +3,7 @@
|
||||
<ml.docilealligator.infinityforreddit.customviews.CustomFontSwitchPreference
|
||||
app:defaultValue="false"
|
||||
app:key="require_auth_to_account_section"
|
||||
app:title="@string/settings_require_authentication_to_go_to_account_section_in_navigation_drawer_title" />
|
||||
app:title="@string/settings_require_authentication_to_show_accounts" />
|
||||
|
||||
<ml.docilealligator.infinityforreddit.customviews.CustomFontSwitchPreference
|
||||
app:defaultValue="false"
|
||||
|
Loading…
Reference in New Issue
Block a user