From c08d06df2e2339906cd175de55c95fe6bc59e12c Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Wed, 5 May 2021 15:51:34 +0800 Subject: Fix app crashes in CopyTextBottomSheetFragment. Add LockScreenActivity. --- app/src/main/AndroidManifest.xml | 5 +- .../infinityforreddit/AppComponent.java | 5 +- .../infinityforreddit/Infinity.java | 54 +++++++++++++- .../activities/LockScreenActivity.java | 85 ++++++++++++++++++++++ .../CopyTextBottomSheetFragment.java | 6 +- app/src/main/res/layout/activity_look_screen.xml | 9 +++ 6 files changed, 158 insertions(+), 6 deletions(-) create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/activities/LockScreenActivity.java create mode 100644 app/src/main/res/layout/activity_look_screen.xml (limited to 'app/src') diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 97dc80d3..4cde57e7 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -32,7 +32,10 @@ android:theme="@style/AppTheme" android:usesCleartextTraffic="true" tools:replace="android:label"> - + 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("", "^").replaceAll("", ""); + markdownText = getArguments().getString(EXTRA_MARKDOWN); + if (markdownText != null) { + markdownText = markdownText.replaceAll("", "^").replaceAll("", ""); + } copyRawTextTextView.setOnClickListener(view -> { showCopyDialog(rawText); diff --git a/app/src/main/res/layout/activity_look_screen.xml b/app/src/main/res/layout/activity_look_screen.xml new file mode 100644 index 00000000..ff5c4fc4 --- /dev/null +++ b/app/src/main/res/layout/activity_look_screen.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file -- cgit v1.2.3