#635 - Show indeterminate unlock progress (in place of the unlock button) while authenticating
This commit is contained in:
parent
44ca3c02c5
commit
be432e7b4f
2 changed files with 40 additions and 12 deletions
|
@ -28,7 +28,6 @@ import android.os.Bundle;
|
||||||
import com.google.android.material.textfield.TextInputEditText;
|
import com.google.android.material.textfield.TextInputEditText;
|
||||||
import com.google.android.material.textfield.TextInputLayout;
|
import com.google.android.material.textfield.TextInputLayout;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.appcompat.widget.Toolbar;
|
import androidx.appcompat.widget.Toolbar;
|
||||||
import android.text.InputType;
|
import android.text.InputType;
|
||||||
import android.text.method.PasswordTransformationMethod;
|
import android.text.method.PasswordTransformationMethod;
|
||||||
|
@ -40,6 +39,7 @@ import android.view.WindowManager.LayoutParams;
|
||||||
import android.view.inputmethod.EditorInfo;
|
import android.view.inputmethod.EditorInfo;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
@ -65,6 +65,7 @@ public class AuthenticateActivity extends ThemedActivity
|
||||||
|
|
||||||
private TextInputEditText passwordInput;
|
private TextInputEditText passwordInput;
|
||||||
private Button unlockButton;
|
private Button unlockButton;
|
||||||
|
private ProgressBar unlockProgress;
|
||||||
|
|
||||||
private AuthenticationTask activeTask;
|
private AuthenticationTask activeTask;
|
||||||
|
|
||||||
|
@ -116,7 +117,7 @@ public class AuthenticateActivity extends ThemedActivity
|
||||||
initPasswordLabelView(v);
|
initPasswordLabelView(v);
|
||||||
initPasswordLayoutView(v);
|
initPasswordLayoutView(v);
|
||||||
initPasswordInputView(v);
|
initPasswordInputView(v);
|
||||||
initUnlockButtonView(v);
|
initUnlockViews(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initPasswordLabelView(View v) {
|
private void initPasswordLabelView(View v) {
|
||||||
|
@ -148,9 +149,12 @@ public class AuthenticateActivity extends ThemedActivity
|
||||||
passwordInput.setOnEditorActionListener(this);
|
passwordInput.setOnEditorActionListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initUnlockButtonView(View v) {
|
private void initUnlockViews(View v) {
|
||||||
unlockButton = v.findViewById(R.id.buttonUnlock);
|
unlockButton = v.findViewById(R.id.buttonUnlock);
|
||||||
unlockButton.setOnClickListener(this);
|
unlockButton.setOnClickListener(this);
|
||||||
|
unlockButton.setVisibility(View.VISIBLE);
|
||||||
|
unlockProgress = v.findViewById(R.id.unlockProgress);
|
||||||
|
unlockProgress.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -168,11 +172,20 @@ public class AuthenticateActivity extends ThemedActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startAuthTask(String plainPassword) {
|
private void startAuthTask(String plainPassword) {
|
||||||
|
// Don't start another task if this was already started.
|
||||||
|
if (activeTask != null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
displayUnlockProgress();
|
||||||
|
activeTask = new AuthenticationTask(this, this::handleResult, isAuthUpgrade, existingAuthCredentials, plainPassword);
|
||||||
|
activeTask.execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void displayUnlockProgress() {
|
||||||
passwordInput.setEnabled(false);
|
passwordInput.setEnabled(false);
|
||||||
unlockButton.setEnabled(false);
|
unlockButton.setEnabled(false);
|
||||||
Callback callback = this::handleResult;
|
unlockButton.setVisibility(View.INVISIBLE);
|
||||||
activeTask = new AuthenticationTask(this, callback, isAuthUpgrade, existingAuthCredentials, plainPassword);
|
unlockProgress.setVisibility(View.VISIBLE);
|
||||||
activeTask.execute();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleResult(Result result) {
|
private void handleResult(Result result) {
|
||||||
|
@ -203,7 +216,8 @@ public class AuthenticateActivity extends ThemedActivity
|
||||||
/** @return true if the task was active and was completed, false otherwise. */
|
/** @return true if the task was active and was completed, false otherwise. */
|
||||||
private boolean completeTaskIfActive() {
|
private boolean completeTaskIfActive() {
|
||||||
try {
|
try {
|
||||||
// This will cause the main thread to wait, but it'll ensure that the task completes.
|
// This will cause the main thread to lock, but ensures that our Activity result will be set.
|
||||||
|
// This task shouldn't take more than 1-2 seconds to complete from starting.
|
||||||
if (activeTask != null) {
|
if (activeTask != null) {
|
||||||
handleResult(activeTask.get());
|
handleResult(activeTask.get());
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -34,12 +34,26 @@
|
||||||
<requestFocus/>
|
<requestFocus/>
|
||||||
</com.google.android.material.textfield.TextInputLayout>
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
|
<RelativeLayout
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="end">
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/buttonUnlock"
|
android:id="@+id/buttonUnlock"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="end"
|
|
||||||
style="?android:attr/buttonBarButtonStyle"
|
style="?android:attr/buttonBarButtonStyle"
|
||||||
android:text="@string/auth_button_unlock" />
|
android:text="@string/auth_button_unlock" />
|
||||||
|
|
||||||
|
<ProgressBar
|
||||||
|
android:id="@+id/unlockProgress"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
style="?android:attr/progressBarStyle"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
|
android:layout_alignEnd="@id/buttonUnlock"/>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
Loading…
Reference in a new issue