Start implementing app lock feature.

This commit is contained in:
Alex Ning 2021-09-03 14:52:59 +08:00
parent c0c89fb16a
commit 39b5beb5c5
8 changed files with 117 additions and 20 deletions

View File

@ -173,8 +173,8 @@ dependencies {
implementation "androidx.startup:startup-runtime:1.0.0"
implementation 'com.github.FunkyMuse:Crashy:1.1.0'
//implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
//annotationProcessor "androidx.lifecycle:compiler:2.2.0"
implementation "androidx.lifecycle:lifecycle-process:2.3.1"
implementation "androidx.lifecycle:lifecycle-common-java8:2.3.1"
implementation 'androidx.palette:palette:1.0.0'

View File

@ -11,7 +11,10 @@ import android.view.WindowManager;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.OnLifecycleEvent;
import androidx.lifecycle.ProcessLifecycleOwner;
import com.evernote.android.state.StateSaver;
import com.livefront.bridge.Bridge;
@ -23,6 +26,7 @@ import org.greenrobot.eventbus.Subscribe;
import javax.inject.Inject;
import javax.inject.Named;
import ml.docilealligator.infinityforreddit.activities.LockScreenActivity;
import ml.docilealligator.infinityforreddit.broadcastreceivers.NetworkWifiStatusReceiver;
import ml.docilealligator.infinityforreddit.broadcastreceivers.WallpaperChangeReceiver;
import ml.docilealligator.infinityforreddit.events.ChangeNetworkStatusEvent;
@ -33,7 +37,7 @@ import ml.docilealligator.infinityforreddit.utils.Utils;
public class Infinity extends Application implements LifecycleObserver {
private AppComponent mAppComponent;
private NetworkWifiStatusReceiver mNetworkWifiStatusReceiver;
//private boolean lock = false;
private boolean lock = false;
private boolean isSecureMode;
@Inject
@Named("default")
@ -66,11 +70,11 @@ public class Infinity extends Application implements LifecycleObserver {
@Override
public void onActivityResumed(@NonNull Activity activity) {
/*if (lock && !(activity instanceof LockScreenActivity)) {
if (lock && !(activity instanceof LockScreenActivity)) {
lock = false;
Intent intent = new Intent(activity, LockScreenActivity.class);
activity.startActivity(intent);
}*/
}
}
@Override
@ -94,7 +98,7 @@ public class Infinity extends Application implements LifecycleObserver {
}
});
//ProcessLifecycleOwner.get().getLifecycle().addObserver(this);
ProcessLifecycleOwner.get().getLifecycle().addObserver(this);
Bridge.initialize(getApplicationContext(), new SavedStateHandler() {
@Override
@ -119,7 +123,7 @@ public class Infinity extends Application implements LifecycleObserver {
registerReceiver(new WallpaperChangeReceiver(), new IntentFilter(Intent.ACTION_WALLPAPER_CHANGED));
}
/*@OnLifecycleEvent(Lifecycle.Event.ON_START)
@OnLifecycleEvent(Lifecycle.Event.ON_START)
public void appInForeground() {
lock = true;
}
@ -127,7 +131,7 @@ public class Infinity extends Application implements LifecycleObserver {
@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
public void appInBackground(){
}*/
}
public AppComponent getAppComponent() {
return mAppComponent;

View File

@ -5,23 +5,32 @@ import static androidx.biometric.BiometricManager.Authenticators.DEVICE_CREDENTI
import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.biometric.BiometricManager;
import androidx.biometric.BiometricPrompt;
import androidx.core.content.ContextCompat;
import com.google.android.material.button.MaterialButton;
import java.util.concurrent.Executor;
import javax.inject.Inject;
import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
public class LockScreenActivity extends BaseActivity {
@BindView(R.id.text_view_lock_screen_activity)
TextView textView;
@BindView(R.id.unlock_button_lock_screen_activity)
MaterialButton unlockButton;
@Inject
@Named("default")
SharedPreferences mSharedPreferences;
@ -35,10 +44,20 @@ public class LockScreenActivity extends BaseActivity {
setImmersiveModeNotApplicable();
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_look_screen);
setContentView(R.layout.activity_lock_screen);
ButterKnife.bind(this);
applyCustomTheme();
unlockButton.setOnClickListener(view -> {
authenticate();
});
authenticate();
}
private void authenticate() {
BiometricManager biometricManager = BiometricManager.from(this);
if (biometricManager.canAuthenticate(BIOMETRIC_STRONG | DEVICE_CREDENTIAL) == BiometricManager.BIOMETRIC_SUCCESS) {
Executor executor = ContextCompat.getMainExecutor(this);
@ -75,7 +94,9 @@ public class LockScreenActivity extends BaseActivity {
@Override
protected void applyCustomTheme() {
textView.setTextColor(mCustomThemeWrapper.getPrimaryTextColor());
unlockButton.setTextColor(mCustomThemeWrapper.getButtonTextColor());
unlockButton.setBackgroundColor(mCustomThemeWrapper.getColorPrimaryLightTheme());
}
@Override

View File

@ -570,7 +570,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
}
} else {
if (post.getAuthorIconUrl() == null) {
String authorName = post.getAuthor().equals("[deleted]") ? post.getSubredditNamePrefixed().substring(2) : post.getAuthor();
String authorName = post.getAuthor().equals("[deleted]") ? post.getSubredditName() : post.getAuthor();
mFragment.loadIcon(authorName, post.getAuthor().equals("[deleted]"), (subredditOrUserName, iconUrl) -> {
if (mActivity != null && getItemCount() > 0) {
if (iconUrl == null || iconUrl.equals("") && authorName.equals(subredditOrUserName)) {

View File

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/lottie_animation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:lottie_autoPlay="true"
app:lottie_loop="true"
app:lottie_rawRes="@raw/lock_screen" />
<TextView
android:id="@+id/text_view_lock_screen_activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="?attr/font_family"
android:text="Whoa there!!!"
android:textSize="?attr/font_20"
app:layout_constraintBottom_toTopOf="@+id/unlock_button_lock_screen_activity"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/lottie_animation_view"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed" />
<com.google.android.material.button.MaterialButton
android:id="@+id/unlock_button_lock_screen_activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Unlock"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/lottie_animation_view"
app:layout_constraintTop_toBottomOf="@+id/text_view_lock_screen_activity" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.LockScreenActivity">
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/lottie_animation_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
app:layout_constraintTop_toTopOf="parent"
app:lottie_autoPlay="true"
app:lottie_loop="true"
app:lottie_rawRes="@raw/lock_screen" />
<TextView
android:id="@+id/text_view_lock_screen_activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Whoa there!!!"
android:textSize="?attr/font_20"
android:fontFamily="?attr/font_family"
app:layout_constraintTop_toBottomOf="@id/lottie_animation_view"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<com.google.android.material.button.MaterialButton
android:id="@+id/unlock_button_lock_screen_activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Unlock"
app:layout_constraintTop_toBottomOf="@id/text_view_lock_screen_activity"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.LockScreenActivity">
</androidx.constraintlayout.widget.ConstraintLayout>

File diff suppressed because one or more lines are too long