aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2020-09-18 16:07:41 +0000
committerAlex Ning <chineseperson5@gmail.com>2020-09-18 16:07:41 +0000
commitbf906b8a6cc81423edf681efe2218e1689816855 (patch)
treeea989a4b35ce71e325be8fbb34deea1e1fdf7f58 /app/src/main/java
parent8a999a04c372311bed0f3d890a42e387969e2954 (diff)
downloadinfinity-for-reddit-bf906b8a6cc81423edf681efe2218e1689816855.tar
infinity-for-reddit-bf906b8a6cc81423edf681efe2218e1689816855.tar.gz
infinity-for-reddit-bf906b8a6cc81423edf681efe2218e1689816855.tar.bz2
infinity-for-reddit-bf906b8a6cc81423edf681efe2218e1689816855.tar.lz
infinity-for-reddit-bf906b8a6cc81423edf681efe2218e1689816855.tar.xz
infinity-for-reddit-bf906b8a6cc81423edf681efe2218e1689816855.tar.zst
infinity-for-reddit-bf906b8a6cc81423edf681efe2218e1689816855.zip
Hide Security option if no biometric authentication available. Require biometric authentication when going into security settings.
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/MarkdownBottomBarRecyclerViewAdapter.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java19
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Settings/SecurityPreferenceFragment.java62
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java1
5 files changed, 85 insertions, 6 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/MarkdownBottomBarRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/MarkdownBottomBarRecyclerViewAdapter.java
index be458bab..3d4b1788 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/MarkdownBottomBarRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/MarkdownBottomBarRecyclerViewAdapter.java
@@ -6,12 +6,12 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
-import android.widget.SeekBar;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
+import com.google.android.material.slider.Slider;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.R;
@@ -158,7 +158,7 @@ public class MarkdownBottomBarRecyclerViewAdapter extends RecyclerView.Adapter<R
}
case MarkdownBottomBarRecyclerViewAdapter.HEADER: {
View dialogView = activity.getLayoutInflater().inflate(R.layout.dialog_select_header, null);
- SeekBar seekBar = dialogView.findViewById(R.id.seek_bar_dialog_select_header);
+ Slider seekBar = dialogView.findViewById(R.id.seek_bar_dialog_select_header);
new MaterialAlertDialogBuilder(activity, R.style.MaterialAlertDialogTheme)
.setTitle(R.string.select_header_size)
.setView(dialogView)
@@ -167,7 +167,7 @@ public class MarkdownBottomBarRecyclerViewAdapter extends RecyclerView.Adapter<R
int start = Math.max(commentEditText.getSelectionStart(), 0);
int end = Math.max(commentEditText.getSelectionEnd(), 0);
String hashTags;
- switch (seekBar.getProgress()) {
+ switch ((int) seekBar.getValue()) {
case 0:
hashTags = "###### ";
break;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
index 328b3714..8a8905a8 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
@@ -66,6 +66,7 @@ import ml.docilealligator.infinityforreddit.Settings.DownloadLocationPreferenceF
import ml.docilealligator.infinityforreddit.Settings.GesturesAndButtonsPreferenceFragment;
import ml.docilealligator.infinityforreddit.Settings.MainPreferenceFragment;
import ml.docilealligator.infinityforreddit.Settings.NotificationPreferenceFragment;
+import ml.docilealligator.infinityforreddit.Settings.SecurityPreferenceFragment;
import ml.docilealligator.infinityforreddit.Settings.ThemePreferenceFragment;
import ml.docilealligator.infinityforreddit.Settings.VideoPreferenceFragment;
@@ -203,4 +204,6 @@ public interface AppComponent {
void inject(CommentFullMarkdownActivity commentFullMarkdownActivity);
void inject(SelectUserFlairActivity selectUserFlairActivity);
+
+ void inject(SecurityPreferenceFragment securityPreferenceFragment);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java
index 3a11855a..ce601cf7 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java
@@ -1,12 +1,14 @@
package ml.docilealligator.infinityforreddit.Settings;
-import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.annotation.NonNull;
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.biometric.BiometricManager;
+import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.SwitchPreference;
@@ -24,6 +26,9 @@ import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
+import static androidx.biometric.BiometricManager.Authenticators.BIOMETRIC_STRONG;
+import static androidx.biometric.BiometricManager.Authenticators.DEVICE_CREDENTIAL;
+
public class MainPreferenceFragment extends PreferenceFragmentCompat {
@Inject
@@ -32,13 +37,14 @@ public class MainPreferenceFragment extends PreferenceFragmentCompat {
@Inject
@Named("post_feed_scrolled_position_cache")
SharedPreferences cache;
- private Activity activity;
+ private AppCompatActivity activity;
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.main_preferences, rootKey);
((Infinity) activity.getApplication()).getAppComponent().inject(this);
+ Preference securityPreference = findPreference(SharedPreferencesUtils.SECURITY);
SwitchPreference savePostFeedScrolledPositionSwitch = findPreference(SharedPreferencesUtils.SAVE_FRONT_PAGE_SCROLLED_POSITION);
SwitchPreference confirmToExitSwitch = findPreference(SharedPreferencesUtils.CONFIRM_TO_EXIT);
SwitchPreference nsfwSwitch = findPreference(SharedPreferencesUtils.NSFW_KEY);
@@ -93,11 +99,18 @@ public class MainPreferenceFragment extends PreferenceFragmentCompat {
return true;
});
}
+
+ BiometricManager biometricManager = BiometricManager.from(activity);
+ if (biometricManager.canAuthenticate(BIOMETRIC_STRONG | DEVICE_CREDENTIAL) != BiometricManager.BIOMETRIC_SUCCESS) {
+ if (securityPreference != null) {
+ securityPreference.setVisible(false);
+ }
+ }
}
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
- activity = (Activity) context;
+ activity = (AppCompatActivity) context;
}
}
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 882fe17d..4a5df68b 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/SecurityPreferenceFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/SecurityPreferenceFragment.java
@@ -1,22 +1,44 @@
package ml.docilealligator.infinityforreddit.Settings;
+import android.content.Context;
+import android.content.SharedPreferences;
import android.os.Bundle;
+import androidx.annotation.NonNull;
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.biometric.BiometricPrompt;
+import androidx.core.content.ContextCompat;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.SwitchPreference;
import org.greenrobot.eventbus.EventBus;
+import java.util.concurrent.Executor;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
import ml.docilealligator.infinityforreddit.Event.ChangeRequireAuthToAccountSectionEvent;
+import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
+import static androidx.biometric.BiometricManager.Authenticators.BIOMETRIC_STRONG;
+import static androidx.biometric.BiometricManager.Authenticators.DEVICE_CREDENTIAL;
+
public class SecurityPreferenceFragment extends PreferenceFragmentCompat {
+ private AppCompatActivity activity;
+ @Inject
+ @Named("default")
+ SharedPreferences sharedPreferences;
+
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.security_preferences, rootKey);
+ ((Infinity) activity.getApplication()).getAppComponent().inject(this);
+
SwitchPreference requireAuthToAccountSectionSwitch = findPreference(SharedPreferencesUtils.REQUIRE_AUTHENTICATION_TO_GO_TO_ACCOUNT_SECTION_IN_NAVIGATION_DRAWER);
if (requireAuthToAccountSectionSwitch != null) {
@@ -26,4 +48,44 @@ public class SecurityPreferenceFragment extends PreferenceFragmentCompat {
});
}
}
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ Executor executor = ContextCompat.getMainExecutor(activity);
+ BiometricPrompt biometricPrompt = new BiometricPrompt(SecurityPreferenceFragment.this,
+ executor, new BiometricPrompt.AuthenticationCallback() {
+ @Override
+ public void onAuthenticationError(int errorCode,
+ @NonNull CharSequence errString) {
+ super.onAuthenticationError(errorCode, errString);
+ activity.onBackPressed();
+ }
+
+ @Override
+ public void onAuthenticationSucceeded(
+ @NonNull BiometricPrompt.AuthenticationResult result) {
+ super.onAuthenticationSucceeded(result);
+ }
+
+ @Override
+ public void onAuthenticationFailed() {
+ super.onAuthenticationFailed();
+ activity.onBackPressed();
+ }
+ });
+
+ BiometricPrompt.PromptInfo promptInfo = new BiometricPrompt.PromptInfo.Builder()
+ .setTitle(activity.getString(R.string.unlock))
+ .setAllowedAuthenticators(BIOMETRIC_STRONG | DEVICE_CREDENTIAL)
+ .build();
+
+ biometricPrompt.authenticate(promptInfo);
+ }
+
+ @Override
+ public void onAttach(@NonNull Context context) {
+ super.onAttach(context);
+ this.activity = (AppCompatActivity) context;
+ }
} \ 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 87b70f3e..351088c3 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java
@@ -126,6 +126,7 @@ public class SharedPreferencesUtils {
public static final String REQUIRE_AUTHENTICATION_TO_GO_TO_ACCOUNT_SECTION_IN_NAVIGATION_DRAWER = "require_auth_to_account_section";
public static final String LONG_PRESS_TO_HIDE_TOOLBAR_IN_COMPACT_LAYOUT = "long_press_to_hide_toolbar_in_compact_layout";
public static final String POST_COMPACT_LAYOUT_TOOLBAR_HIDDEN_BY_DEFAULT = "post_compact_layout_toolbar_hidden_by_default";
+ public static final String SECURITY = "security";
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";