mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-19 00:01:08 +01:00
Simplify PIN opt-out code.
This commit is contained in:
@@ -19,50 +19,30 @@ public final class PinOptOutDialog {
|
||||
|
||||
private static final String TAG = Log.tag(PinOptOutDialog.class);
|
||||
|
||||
public static void showForSkip(@NonNull Context context, @NonNull Runnable onSuccess, @NonNull Runnable onFailed) {
|
||||
show(context,
|
||||
true,
|
||||
onSuccess,
|
||||
onFailed);
|
||||
}
|
||||
|
||||
public static void showForOptOut(@NonNull Context context, @NonNull Runnable onSuccess, @NonNull Runnable onFailed) {
|
||||
show(context,
|
||||
false,
|
||||
onSuccess,
|
||||
onFailed);
|
||||
}
|
||||
|
||||
private static void show(@NonNull Context context,
|
||||
boolean isForSkip,
|
||||
@NonNull Runnable onSuccess,
|
||||
@NonNull Runnable onFailed)
|
||||
{
|
||||
public static void show(@NonNull Context context, @NonNull Runnable onSuccess) {
|
||||
Log.i(TAG, "show()");
|
||||
AlertDialog dialog = new AlertDialog.Builder(context)
|
||||
.setTitle(R.string.PinOptOutDialog_warning)
|
||||
.setMessage(R.string.PinOptOutDialog_if_you_disable_the_pin_you_will_lose_all_data)
|
||||
.setCancelable(true)
|
||||
.setPositiveButton(R.string.PinOptOutDialog_disable_pin, (d, which) -> {
|
||||
Log.i(TAG, "Disable clicked.");
|
||||
d.dismiss();
|
||||
AlertDialog progress = SimpleProgressDialog.show(context);
|
||||
|
||||
SimpleTask.run(() -> {
|
||||
if (isForSkip) {
|
||||
PinState.onPinCreationSkipped();
|
||||
} else {
|
||||
PinState.onPinOptOut();
|
||||
}
|
||||
return true;
|
||||
PinState.onPinOptOut();
|
||||
return null;
|
||||
}, success -> {
|
||||
if (success) {
|
||||
onSuccess.run();
|
||||
} else {
|
||||
onFailed.run();
|
||||
}
|
||||
Log.i(TAG, "Disable operation finished.");
|
||||
onSuccess.run();
|
||||
progress.dismiss();
|
||||
});
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, (d, which) -> d.dismiss())
|
||||
.setNegativeButton(android.R.string.cancel, (d, which) -> {
|
||||
Log.i(TAG, "Cancel clicked.");
|
||||
d.dismiss();
|
||||
})
|
||||
.create();
|
||||
|
||||
dialog.setOnShowListener(dialogInterface -> {
|
||||
|
||||
@@ -202,19 +202,6 @@ public final class PinState {
|
||||
updateState(buildInferredStateFromOtherFields());
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked when the user has chosen to skip PIN creation.
|
||||
*/
|
||||
@WorkerThread
|
||||
public static synchronized void onPinCreationSkipped() {
|
||||
Log.i(TAG, "onPinCreationSkipped()");
|
||||
assertState(State.NO_REGISTRATION_LOCK);
|
||||
|
||||
optOutOfPin();
|
||||
|
||||
updateState(buildInferredStateFromOtherFields());
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked whenever a Signal PIN user enables registration lock.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user