aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/ml/docilealligator
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2021-05-05 07:51:34 +0000
committerAlex Ning <chineseperson5@gmail.com>2021-05-05 07:51:34 +0000
commitc08d06df2e2339906cd175de55c95fe6bc59e12c (patch)
treeb275cdf84cbebdbc692f443339245527aeb5c70f /app/src/main/java/ml/docilealligator
parentee4c25a465e2568ab3ed784e60cba8d2e3caa40b (diff)
downloadinfinity-for-reddit-c08d06df2e2339906cd175de55c95fe6bc59e12c.tar
infinity-for-reddit-c08d06df2e2339906cd175de55c95fe6bc59e12c.tar.gz
infinity-for-reddit-c08d06df2e2339906cd175de55c95fe6bc59e12c.tar.bz2
infinity-for-reddit-c08d06df2e2339906cd175de55c95fe6bc59e12c.tar.lz
infinity-for-reddit-c08d06df2e2339906cd175de55c95fe6bc59e12c.tar.xz
infinity-for-reddit-c08d06df2e2339906cd175de55c95fe6bc59e12c.tar.zst
infinity-for-reddit-c08d06df2e2339906cd175de55c95fe6bc59e12c.zip
Fix app crashes in CopyTextBottomSheetFragment. Add LockScreenActivity.
Diffstat (limited to 'app/src/main/java/ml/docilealligator')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java5
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java54
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/LockScreenActivity.java85
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CopyTextBottomSheetFragment.java6
4 files changed, 145 insertions, 5 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
index b0506a82..922642f2 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
@@ -21,11 +21,12 @@ import ml.docilealligator.infinityforreddit.activities.FullMarkdownActivity;
import ml.docilealligator.infinityforreddit.activities.GiveAwardActivity;
import ml.docilealligator.infinityforreddit.activities.InboxActivity;
import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity;
+import ml.docilealligator.infinityforreddit.activities.LockScreenActivity;
import ml.docilealligator.infinityforreddit.activities.LoginActivity;
import ml.docilealligator.infinityforreddit.activities.MainActivity;
import ml.docilealligator.infinityforreddit.activities.MultiredditSelectionActivity;
-import ml.docilealligator.infinityforreddit.activities.PostFilterUsageListingActivity;
import ml.docilealligator.infinityforreddit.activities.PostFilterPreferenceActivity;
+import ml.docilealligator.infinityforreddit.activities.PostFilterUsageListingActivity;
import ml.docilealligator.infinityforreddit.activities.PostImageActivity;
import ml.docilealligator.infinityforreddit.activities.PostLinkActivity;
import ml.docilealligator.infinityforreddit.activities.PostTextActivity;
@@ -263,4 +264,6 @@ public interface AppComponent {
void inject(CrashReportsFragment crashReportsFragment);
void inject(AnonymousSubscriptionsActivity anonymousSubscriptionsActivity);
+
+ void inject(LockScreenActivity lockScreenActivity);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java
index 274d1ad7..1514b745 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java
@@ -7,6 +7,7 @@ import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
+import androidx.lifecycle.LifecycleObserver;
import com.evernote.android.state.StateSaver;
import com.livefront.bridge.Bridge;
@@ -18,7 +19,7 @@ import ml.docilealligator.infinityforreddit.broadcastreceivers.NetworkWifiStatus
import ml.docilealligator.infinityforreddit.events.ChangeNetworkStatusEvent;
import ml.docilealligator.infinityforreddit.utils.Utils;
-public class Infinity extends Application {
+public class Infinity extends Application implements LifecycleObserver {
private AppComponent mAppComponent;
private NetworkWifiStatusReceiver mNetworkWifiStatusReceiver;
@@ -26,12 +27,49 @@ public class Infinity extends Application {
public void onCreate() {
super.onCreate();
- //RedScreenOfDeath.init(this);
-
mAppComponent = DaggerAppComponent.builder()
.appModule(new AppModule(this))
.build();
+ //ProcessLifecycleOwner.get().getLifecycle().addObserver(this);
+
+ /*registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
+ @Override
+ public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle bundle) {
+ activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
+ }
+
+ @Override
+ public void onActivityStarted(@NonNull Activity activity) {
+
+ }
+
+ @Override
+ public void onActivityResumed(@NonNull Activity activity) {
+
+ }
+
+ @Override
+ public void onActivityPaused(@NonNull Activity activity) {
+
+ }
+
+ @Override
+ public void onActivityStopped(@NonNull Activity activity) {
+
+ }
+
+ @Override
+ public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle bundle) {
+
+ }
+
+ @Override
+ public void onActivityDestroyed(@NonNull Activity activity) {
+
+ }
+ });*/
+
Bridge.initialize(getApplicationContext(), new SavedStateHandler() {
@Override
public void saveInstanceState(@NonNull Object target, @NonNull Bundle state) {
@@ -51,6 +89,16 @@ public class Infinity extends Application {
registerReceiver(mNetworkWifiStatusReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
}
+// @OnLifecycleEvent(Lifecycle.Event.ON_START)
+// public void appInForeground(){
+// Toast.makeText(this, "Foreground", Toast.LENGTH_SHORT).show();
+// }
+//
+// @OnLifecycleEvent(Lifecycle.Event.ON_STOP)
+// public void appInBackground(){
+// Toast.makeText(this, "Background", Toast.LENGTH_SHORT).show();
+// }
+
public AppComponent getAppComponent() {
return mAppComponent;
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LockScreenActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LockScreenActivity.java
new file mode 100644
index 00000000..8dc39275
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LockScreenActivity.java
@@ -0,0 +1,85 @@
+package ml.docilealligator.infinityforreddit.activities;
+
+import android.content.SharedPreferences;
+import android.os.Bundle;
+
+import androidx.annotation.NonNull;
+import androidx.biometric.BiometricManager;
+import androidx.biometric.BiometricPrompt;
+import androidx.core.content.ContextCompat;
+
+import java.util.concurrent.Executor;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import ml.docilealligator.infinityforreddit.Infinity;
+import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
+
+import static androidx.biometric.BiometricManager.Authenticators.BIOMETRIC_STRONG;
+import static androidx.biometric.BiometricManager.Authenticators.DEVICE_CREDENTIAL;
+
+public class LockScreenActivity extends BaseActivity {
+
+ @Inject
+ @Named("default")
+ SharedPreferences mSharedPreferences;
+ @Inject
+ CustomThemeWrapper mCustomThemeWrapper;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ ((Infinity) getApplication()).getAppComponent().inject(this);
+
+ setImmersiveModeNotApplicable();
+
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_look_screen);
+
+ applyCustomTheme();
+
+ BiometricManager biometricManager = BiometricManager.from(this);
+ if (biometricManager.canAuthenticate(BIOMETRIC_STRONG | DEVICE_CREDENTIAL) == BiometricManager.BIOMETRIC_SUCCESS) {
+ Executor executor = ContextCompat.getMainExecutor(this);
+ BiometricPrompt biometricPrompt = new BiometricPrompt(this,
+ executor, new BiometricPrompt.AuthenticationCallback() {
+ @Override
+ public void onAuthenticationSucceeded(
+ @NonNull BiometricPrompt.AuthenticationResult result) {
+ super.onAuthenticationSucceeded(result);
+ finish();
+ }
+ });
+
+ BiometricPrompt.PromptInfo promptInfo = new BiometricPrompt.PromptInfo.Builder()
+ .setTitle(getString(R.string.unlock_account_section))
+ .setAllowedAuthenticators(BIOMETRIC_STRONG | DEVICE_CREDENTIAL)
+ .build();
+
+ biometricPrompt.authenticate(promptInfo);
+ } else {
+ finish();
+ }
+ }
+
+ @Override
+ protected SharedPreferences getDefaultSharedPreferences() {
+ return mSharedPreferences;
+ }
+
+ @Override
+ protected CustomThemeWrapper getCustomThemeWrapper() {
+ return mCustomThemeWrapper;
+ }
+
+ @Override
+ protected void applyCustomTheme() {
+
+ }
+
+ @Override
+ public void onBackPressed() {
+ moveTaskToBack(true);
+ }
+} \ No newline at end of file
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CopyTextBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CopyTextBottomSheetFragment.java
index d29a1510..6e87c4ee 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CopyTextBottomSheetFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CopyTextBottomSheetFragment.java
@@ -39,6 +39,7 @@ public class CopyTextBottomSheetFragment extends RoundedBottomSheetDialogFragmen
TextView copyAllMarkdownTextView;
private Activity activity;
+ private String markdownText;
public CopyTextBottomSheetFragment() {
// Required empty public constructor
@@ -53,7 +54,10 @@ public class CopyTextBottomSheetFragment extends RoundedBottomSheetDialogFragmen
ButterKnife.bind(this, rootView);
String rawText = getArguments().getString(EXTRA_RAW_TEXT);
- String markdownText = getArguments().getString(EXTRA_MARKDOWN).replaceAll("<sup>", "^").replaceAll("</sup>", "");
+ markdownText = getArguments().getString(EXTRA_MARKDOWN);
+ if (markdownText != null) {
+ markdownText = markdownText.replaceAll("<sup>", "^").replaceAll("</sup>", "");
+ }
copyRawTextTextView.setOnClickListener(view -> {
showCopyDialog(rawText);