#635 - Reset our callback in onResume instead of onCreate

This ensure that if the user goes home, the callback will be reset when coming back (since onCreate doesn't get called most of the time in this instance).
This commit is contained in:
Joshua Soberg 2021-02-01 22:03:25 -05:00
parent b52accb2aa
commit 3eb0094204

View file

@ -62,8 +62,6 @@ public class AuthenticateActivity extends ThemedActivity
private String existingAuthCredentials; private String existingAuthCredentials;
private boolean isAuthUpgrade = false; private boolean isAuthUpgrade = false;
private boolean isTaskRunning = false;
private TextInputLayout passwordLayout; private TextInputLayout passwordLayout;
private TextInputEditText passwordInput; private TextInputEditText passwordInput;
private Button unlockButton; private Button unlockButton;
@ -72,8 +70,6 @@ public class AuthenticateActivity extends ThemedActivity
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
checkBackgroundTask();
if (! settings.getScreenshotsEnabled()) if (! settings.getScreenshotsEnabled())
getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE); getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE);
@ -101,23 +97,10 @@ public class AuthenticateActivity extends ThemedActivity
setContentView(R.layout.activity_container); setContentView(R.layout.activity_container);
initToolbar(); initToolbar();
initPasswordViews(); initPasswordViews();
if (isTaskRunning) {
setupUiForRunningTask();
}
getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
} }
private void checkBackgroundTask() {
TaskFragment taskFragment = findTaskFragment();
if (taskFragment != null) {
// If we have the task fragment in our fragment manager, we know that we started the
// task before a configuration change and need to set a new callback.
isTaskRunning = true;
taskFragment.task.setCallback(this::handleResult);
}
}
@Nullable @Nullable
private TaskFragment findTaskFragment() { private TaskFragment findTaskFragment() {
return (TaskFragment) getFragmentManager().findFragmentByTag(TAG_TASK_FRAGMENT); return (TaskFragment) getFragmentManager().findFragmentByTag(TAG_TASK_FRAGMENT);
@ -174,8 +157,23 @@ public class AuthenticateActivity extends ThemedActivity
unlockProgress = v.findViewById(R.id.unlockProgress); unlockProgress = v.findViewById(R.id.unlockProgress);
} }
@Override
public void onResume() {
super.onResume();
checkBackgroundTask();
}
private void checkBackgroundTask() {
TaskFragment taskFragment = findTaskFragment();
if (taskFragment != null) {
// If we have the task fragment in our fragment manager, we know that we started the
// task before a configuration change and need to set a new callback.
taskFragment.task.setCallback(this::handleResult);
setupUiForRunningTask();
}
}
private void setupUiForRunningTask() { private void setupUiForRunningTask() {
isTaskRunning = true;
passwordLayout.setEnabled(false); passwordLayout.setEnabled(false);
passwordInput.setEnabled(false); passwordInput.setEnabled(false);
unlockButton.setEnabled(false); unlockButton.setEnabled(false);