diff --git a/app/build.gradle b/app/build.gradle index a5656d80..72d855a0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -95,6 +95,7 @@ dependencies { implementation 'me.zhanghai.android.fastscroll:library:1.1.2' implementation "com.thefuntasty.hauler:core:3.1.0" implementation 'com.github.Piasy:BigImageViewer:1.6.5' + implementation 'androidx.biometric:biometric:1.1.0-alpha02' def toroVersion = '3.7.0.2010003' implementation "im.ene.toro3:toro:$toroVersion" diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java index dea3aaf2..3efc949f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java @@ -75,6 +75,7 @@ import ml.docilealligator.infinityforreddit.Event.ChangeConfirmToExitEvent; import ml.docilealligator.infinityforreddit.Event.ChangeDisableSwipingBetweenTabsEvent; import ml.docilealligator.infinityforreddit.Event.ChangeLockBottomAppBarEvent; import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent; +import ml.docilealligator.infinityforreddit.Event.ChangeRequireAuthToAccountSectionEvent; import ml.docilealligator.infinityforreddit.Event.RecreateActivityEvent; import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.FetchMyInfo; @@ -468,9 +469,9 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb fab.setVisibility(View.VISIBLE); } - boolean nsfwEnabled = mSharedPreferences.getBoolean(SharedPreferencesUtils.NSFW_KEY, false); - adapter = new NavigationDrawerRecyclerViewAdapter(this, mCustomThemeWrapper, mAccountName, - mProfileImageUrl, mBannerImageUrl, mKarma, nsfwEnabled, + adapter = new NavigationDrawerRecyclerViewAdapter(this, mSharedPreferences, + mCustomThemeWrapper, mAccountName, + mProfileImageUrl, mBannerImageUrl, mKarma, new NavigationDrawerRecyclerViewAdapter.ItemClickListener() { @Override public void onMenuClick(int stringId) { @@ -972,6 +973,11 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb viewPager2.setUserInputEnabled(!mDisableSwipingBetweenTabs); } + @Subscribe + public void onChangeRequireAuthToAccountSectionEvent(ChangeRequireAuthToAccountSectionEvent changeRequireAuthToAccountSectionEvent) { + adapter.setRequireAuthToAccountSection(changeRequireAuthToAccountSectionEvent.requireAuthToAccountSection); + } + @Override public void onLongPress() { if (sectionsPagerAdapter != null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/NavigationDrawerRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/NavigationDrawerRecyclerViewAdapter.java index 4e2f5b7f..7f6938a4 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/NavigationDrawerRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/NavigationDrawerRecyclerViewAdapter.java @@ -1,6 +1,6 @@ package ml.docilealligator.infinityforreddit.Adapter; -import android.content.Context; +import android.content.SharedPreferences; import android.content.res.Configuration; import android.content.res.Resources; import android.view.LayoutInflater; @@ -10,6 +10,10 @@ import android.widget.ImageView; import android.widget.TextView; import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.biometric.BiometricManager; +import androidx.biometric.BiometricPrompt; +import androidx.core.content.ContextCompat; import androidx.recyclerview.widget.RecyclerView; import com.bumptech.glide.Glide; @@ -18,6 +22,7 @@ import com.bumptech.glide.request.RequestOptions; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.Executor; import butterknife.BindView; import butterknife.ButterKnife; @@ -26,8 +31,12 @@ import ml.docilealligator.infinityforreddit.Account.Account; import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.SubscribedSubreddit.SubscribedSubredditData; +import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; import pl.droidsonroids.gif.GifImageView; +import static androidx.biometric.BiometricManager.Authenticators.BIOMETRIC_STRONG; +import static androidx.biometric.BiometricManager.Authenticators.DEVICE_CREDENTIAL; + public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter { public interface ItemClickListener { @@ -44,7 +53,7 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter { if (isInMainPage) { - ((NavHeaderViewHolder) holder).dropIconImageView.setImageDrawable(resources.getDrawable(R.drawable.ic_baseline_arrow_drop_up_24px)); - notifyItemRangeRemoved(1, getItemCount() - 1); - if (accounts != null) { - notifyItemRangeInserted(1, accounts.size() + 3); - } else { - if (isLoggedIn) { - notifyItemRangeInserted(1, 3); + if (requireAuthToAccountSection) { + BiometricManager biometricManager = BiometricManager.from(appCompatActivity); + if (biometricManager.canAuthenticate(BIOMETRIC_STRONG | DEVICE_CREDENTIAL) == BiometricManager.BIOMETRIC_SUCCESS) { + Executor executor = ContextCompat.getMainExecutor(appCompatActivity); + BiometricPrompt biometricPrompt = new BiometricPrompt(appCompatActivity, + executor, new BiometricPrompt.AuthenticationCallback() { + @Override + public void onAuthenticationError(int errorCode, + @NonNull CharSequence errString) { + super.onAuthenticationError(errorCode, errString); + } + + @Override + public void onAuthenticationSucceeded( + @NonNull BiometricPrompt.AuthenticationResult result) { + super.onAuthenticationSucceeded(result); + openAccountSection(((NavHeaderViewHolder) holder).dropIconImageView); + } + + @Override + public void onAuthenticationFailed() { + super.onAuthenticationFailed(); + } + }); + + BiometricPrompt.PromptInfo promptInfo = new BiometricPrompt.PromptInfo.Builder() + .setTitle(appCompatActivity.getString(R.string.unlock_account_section)) + .setAllowedAuthenticators(BIOMETRIC_STRONG | DEVICE_CREDENTIAL) + .build(); + + biometricPrompt.authenticate(promptInfo); } else { - notifyItemInserted(1); + openAccountSection(((NavHeaderViewHolder) holder).dropIconImageView); } + } else { + openAccountSection(((NavHeaderViewHolder) holder).dropIconImageView); } - isInMainPage = false; } else { ((NavHeaderViewHolder) holder).dropIconImageView.setImageDrawable(resources.getDrawable(R.drawable.ic_baseline_arrow_drop_down_24px)); notifyItemRangeRemoved(1, getItemCount() - 1); @@ -284,12 +321,12 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter itemClickListener.onMenuClick(finalStringId)); @@ -396,6 +433,21 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter { + EventBus.getDefault().post(new ChangeRequireAuthToAccountSectionEvent((Boolean) newValue)); + return true; + }); + } + } +} \ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java index acf7566d..8381319b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java @@ -123,6 +123,7 @@ public class SharedPreferencesUtils { public static final String DISABLE_SWIPING_BETWEEN_TABS = "disable_swiping_between_tabs"; public static final String ENABLE_SWIPE_ACTION = "enable_swipe_action"; public static final String PULL_TO_REFRESH = "pull_to_refresh"; + public static final String REQUIRE_AUTHENTICATION_TO_GO_TO_ACCOUNT_SECTION_IN_NAVIGATION_DRAWER = "require_auth_to_account_section"; public static final String MAIN_PAGE_TABS_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.main_page_tabs"; public static final String MAIN_PAGE_TAB_1_TITLE = "_main_page_tab_1_title"; diff --git a/app/src/main/res/drawable-night/ic_security_24dp.xml b/app/src/main/res/drawable-night/ic_security_24dp.xml new file mode 100644 index 00000000..3e21f473 --- /dev/null +++ b/app/src/main/res/drawable-night/ic_security_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_security_24dp.xml b/app/src/main/res/drawable/ic_security_24dp.xml new file mode 100644 index 00000000..be9737bd --- /dev/null +++ b/app/src/main/res/drawable/ic_security_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 94df20c9..695ddfeb 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -233,14 +233,4 @@ 1 2 - - - Reply - Reply to all - - - - reply - reply_all - \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3e70c54d..39a228ff 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -483,6 +483,8 @@ Disable Swiping Between Tabs Enable Swipe Action Pull to Refresh + Security + Require Authentication to Go to Account Section in Navigation Drawer Cannot get the link @@ -882,7 +884,21 @@ Failed to block user View Full Markdown - - Hello blank fragment + + Unlock Account Section + + Messages + Sync + + + Your signature + Default reply action + + + Sync email periodically + Download incoming attachments + Automatically download attachments for incoming emails + + Only download attachments when manually requested diff --git a/app/src/main/res/xml/main_preferences.xml b/app/src/main/res/xml/main_preferences.xml index ce6ff184..48bf5697 100644 --- a/app/src/main/res/xml/main_preferences.xml +++ b/app/src/main/res/xml/main_preferences.xml @@ -41,6 +41,11 @@ android:icon="@drawable/ic_download_24dp" app:fragment="ml.docilealligator.infinityforreddit.Settings.DownloadLocationPreferenceFragment" /> + + + + + + \ No newline at end of file