Fix app behavior on rotate/theme change
This commit is contained in:
parent
0153f72aaa
commit
8a06d5eb4d
@ -33,7 +33,8 @@
|
|||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:theme="@style/Theme.CringeAuthenticator.None">
|
android:theme="@style/Theme.CringeAuthenticator.None"
|
||||||
|
android:configChanges="orientation|screenSize">
|
||||||
</activity>
|
</activity>
|
||||||
<activity android:name=".scanner.QRScannerActivity"
|
<activity android:name=".scanner.QRScannerActivity"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
|
@ -4,7 +4,6 @@ import android.content.Intent;
|
|||||||
import android.media.MediaPlayer;
|
import android.media.MediaPlayer;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
@ -23,8 +22,6 @@ public class IntroActivity extends AppCompatActivity {
|
|||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
Log.i("AMOGUS", "CREATE");
|
|
||||||
|
|
||||||
if (!SettingsUtil.isIntroVideoEnabled(this)) {
|
if (!SettingsUtil.isIntroVideoEnabled(this)) {
|
||||||
openMainActivity();
|
openMainActivity();
|
||||||
return;
|
return;
|
||||||
|
@ -16,6 +16,7 @@ import android.widget.Toast;
|
|||||||
|
|
||||||
import androidx.activity.result.ActivityResultLauncher;
|
import androidx.activity.result.ActivityResultLauncher;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.appcompat.app.ActionBar;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.biometric.BiometricManager;
|
import androidx.biometric.BiometricManager;
|
||||||
@ -30,6 +31,7 @@ import com.cringe_studios.cringe_authenticator.databinding.DialogInputCodeTotpBi
|
|||||||
import com.cringe_studios.cringe_authenticator.fragment.GroupFragment;
|
import com.cringe_studios.cringe_authenticator.fragment.GroupFragment;
|
||||||
import com.cringe_studios.cringe_authenticator.fragment.HomeFragment;
|
import com.cringe_studios.cringe_authenticator.fragment.HomeFragment;
|
||||||
import com.cringe_studios.cringe_authenticator.fragment.MenuFragment;
|
import com.cringe_studios.cringe_authenticator.fragment.MenuFragment;
|
||||||
|
import com.cringe_studios.cringe_authenticator.fragment.NamedFragment;
|
||||||
import com.cringe_studios.cringe_authenticator.fragment.SettingsFragment;
|
import com.cringe_studios.cringe_authenticator.fragment.SettingsFragment;
|
||||||
import com.cringe_studios.cringe_authenticator.scanner.QRScannerContract;
|
import com.cringe_studios.cringe_authenticator.scanner.QRScannerContract;
|
||||||
import com.cringe_studios.cringe_authenticator.util.DialogCallback;
|
import com.cringe_studios.cringe_authenticator.util.DialogCallback;
|
||||||
@ -42,10 +44,16 @@ import java.util.concurrent.Executor;
|
|||||||
|
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
private static final long LOCK_TIMEOUT = 10000;
|
||||||
|
|
||||||
private ActivityMainBinding binding;
|
private ActivityMainBinding binding;
|
||||||
|
|
||||||
private ActivityResultLauncher<Void> startQRCodeScan;
|
private ActivityResultLauncher<Void> startQRCodeScan;
|
||||||
|
|
||||||
|
private boolean unlocked;
|
||||||
|
|
||||||
|
private long pauseTime;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@ -72,7 +80,10 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if(SettingsUtil.isBiometricLock(this) && BiometricManager.from(this).canAuthenticate(BIOMETRIC_STRONG | DEVICE_CREDENTIAL) == BiometricManager.BIOMETRIC_SUCCESS) {
|
boolean supportsBiometricAuth = BiometricManager.from(this).canAuthenticate(BIOMETRIC_STRONG | DEVICE_CREDENTIAL) == BiometricManager.BIOMETRIC_SUCCESS;
|
||||||
|
boolean recentlyUnlocked = savedInstanceState != null && (System.currentTimeMillis() - savedInstanceState.getLong("pauseTime", 0L) < LOCK_TIMEOUT);
|
||||||
|
|
||||||
|
if(!recentlyUnlocked && SettingsUtil.isBiometricLock(this) && supportsBiometricAuth) {
|
||||||
BiometricPrompt.PromptInfo info = new BiometricPrompt.PromptInfo.Builder()
|
BiometricPrompt.PromptInfo info = new BiometricPrompt.PromptInfo.Builder()
|
||||||
.setTitle("Cringe Authenticator")
|
.setTitle("Cringe Authenticator")
|
||||||
.setSubtitle("Unlock the authenticator")
|
.setSubtitle("Unlock the authenticator")
|
||||||
@ -101,6 +112,8 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void launchApp() {
|
private void launchApp() {
|
||||||
|
unlocked = true;
|
||||||
|
|
||||||
binding = ActivityMainBinding.inflate(getLayoutInflater());
|
binding = ActivityMainBinding.inflate(getLayoutInflater());
|
||||||
setContentView(binding.getRoot());
|
setContentView(binding.getRoot());
|
||||||
|
|
||||||
@ -110,7 +123,13 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
binding.fabScan.setOnClickListener(view -> scanCode());
|
binding.fabScan.setOnClickListener(view -> scanCode());
|
||||||
binding.fabInput.setOnClickListener(view -> inputCode());
|
binding.fabInput.setOnClickListener(view -> inputCode());
|
||||||
|
|
||||||
NavigationUtil.navigate(this, HomeFragment.class, null);
|
Fragment fragment = NavigationUtil.getCurrentFragment(this);
|
||||||
|
if(fragment instanceof NamedFragment) {
|
||||||
|
ActionBar bar = getSupportActionBar();
|
||||||
|
if(bar != null) bar.setTitle(((NamedFragment) fragment).getName());
|
||||||
|
}else {
|
||||||
|
NavigationUtil.navigate(this, HomeFragment.class, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -303,4 +322,17 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
this.pauseTime = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
if(unlocked) {
|
||||||
|
outState.putLong("pauseTime", pauseTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user