diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index df39362..84240f9 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -33,7 +33,8 @@ android:name=".MainActivity" android:exported="true" android:label="@string/app_name" - android:theme="@style/Theme.CringeAuthenticator.None"> + android:theme="@style/Theme.CringeAuthenticator.None" + android:configChanges="orientation|screenSize"> startQRCodeScan; + private boolean unlocked; + + private long pauseTime; + @Override protected void onCreate(Bundle 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() .setTitle("Cringe Authenticator") .setSubtitle("Unlock the authenticator") @@ -101,6 +112,8 @@ public class MainActivity extends AppCompatActivity { } private void launchApp() { + unlocked = true; + binding = ActivityMainBinding.inflate(getLayoutInflater()); setContentView(binding.getRoot()); @@ -110,7 +123,13 @@ public class MainActivity extends AppCompatActivity { binding.fabScan.setOnClickListener(view -> scanCode()); 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 @@ -303,4 +322,17 @@ public class MainActivity extends AppCompatActivity { .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); + } + } } \ No newline at end of file