mirror of
https://github.com/oxen-io/session-android.git
synced 2025-06-10 08:18:34 +00:00
Simplify PIN opt-out code.
This commit is contained in:
parent
e27fc512b4
commit
4b961d2d8f
@ -215,11 +215,6 @@ abstract class BaseKbsPinFragment<ViewModel extends BaseKbsPinViewModel> extends
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void onPinSkipped() {
|
private void onPinSkipped() {
|
||||||
PinOptOutDialog.showForSkip(requireContext(),
|
PinOptOutDialog.show(requireContext(), this::closeNavGraphBranch);
|
||||||
this::closeNavGraphBranch,
|
|
||||||
() -> {
|
|
||||||
PinState.onPinCreateFailure();
|
|
||||||
closeNavGraphBranch();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -126,11 +126,6 @@ public final class KbsSplashFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void onPinSkipped() {
|
private void onPinSkipped() {
|
||||||
PinOptOutDialog.showForSkip(requireContext(),
|
PinOptOutDialog.show(requireContext(), () -> requireActivity().finish());
|
||||||
() -> requireActivity().finish(),
|
|
||||||
() -> {
|
|
||||||
PinState.onPinCreateFailure();
|
|
||||||
requireActivity().finish();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,50 +19,30 @@ public final class PinOptOutDialog {
|
|||||||
|
|
||||||
private static final String TAG = Log.tag(PinOptOutDialog.class);
|
private static final String TAG = Log.tag(PinOptOutDialog.class);
|
||||||
|
|
||||||
public static void showForSkip(@NonNull Context context, @NonNull Runnable onSuccess, @NonNull Runnable onFailed) {
|
public static void show(@NonNull Context context, @NonNull Runnable onSuccess) {
|
||||||
show(context,
|
Log.i(TAG, "show()");
|
||||||
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)
|
|
||||||
{
|
|
||||||
AlertDialog dialog = new AlertDialog.Builder(context)
|
AlertDialog dialog = new AlertDialog.Builder(context)
|
||||||
.setTitle(R.string.PinOptOutDialog_warning)
|
.setTitle(R.string.PinOptOutDialog_warning)
|
||||||
.setMessage(R.string.PinOptOutDialog_if_you_disable_the_pin_you_will_lose_all_data)
|
.setMessage(R.string.PinOptOutDialog_if_you_disable_the_pin_you_will_lose_all_data)
|
||||||
.setCancelable(true)
|
.setCancelable(true)
|
||||||
.setPositiveButton(R.string.PinOptOutDialog_disable_pin, (d, which) -> {
|
.setPositiveButton(R.string.PinOptOutDialog_disable_pin, (d, which) -> {
|
||||||
|
Log.i(TAG, "Disable clicked.");
|
||||||
d.dismiss();
|
d.dismiss();
|
||||||
AlertDialog progress = SimpleProgressDialog.show(context);
|
AlertDialog progress = SimpleProgressDialog.show(context);
|
||||||
|
|
||||||
SimpleTask.run(() -> {
|
SimpleTask.run(() -> {
|
||||||
if (isForSkip) {
|
PinState.onPinOptOut();
|
||||||
PinState.onPinCreationSkipped();
|
return null;
|
||||||
} else {
|
|
||||||
PinState.onPinOptOut();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}, success -> {
|
}, success -> {
|
||||||
if (success) {
|
Log.i(TAG, "Disable operation finished.");
|
||||||
onSuccess.run();
|
onSuccess.run();
|
||||||
} else {
|
|
||||||
onFailed.run();
|
|
||||||
}
|
|
||||||
progress.dismiss();
|
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();
|
.create();
|
||||||
|
|
||||||
dialog.setOnShowListener(dialogInterface -> {
|
dialog.setOnShowListener(dialogInterface -> {
|
||||||
|
@ -202,19 +202,6 @@ public final class PinState {
|
|||||||
updateState(buildInferredStateFromOtherFields());
|
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.
|
* Invoked whenever a Signal PIN user enables registration lock.
|
||||||
*/
|
*/
|
||||||
|
@ -82,12 +82,11 @@ public class AdvancedPinPreferenceFragment extends ListSummaryPreferenceFragment
|
|||||||
.setPositiveButton(android.R.string.ok, (d, which) -> d.dismiss())
|
.setPositiveButton(android.R.string.ok, (d, which) -> d.dismiss())
|
||||||
.show();
|
.show();
|
||||||
} else if (!enabled) {
|
} else if (!enabled) {
|
||||||
PinOptOutDialog.showForOptOut(requireContext(),
|
PinOptOutDialog.show(requireContext(),
|
||||||
() -> {
|
() -> {
|
||||||
updatePreferenceState();
|
updatePreferenceState();
|
||||||
Snackbar.make(requireView(), R.string.ApplicationPreferencesActivity_pin_disabled, Snackbar.LENGTH_SHORT).setTextColor(Color.WHITE).show();
|
Snackbar.make(requireView(), R.string.ApplicationPreferencesActivity_pin_disabled, Snackbar.LENGTH_SHORT).setTextColor(Color.WHITE).show();
|
||||||
},
|
});
|
||||||
() -> Toast.makeText(requireContext(), R.string.ApplicationPreferencesActivity_failed_to_disable_pins_try_again_later, Toast.LENGTH_LONG).show());
|
|
||||||
} else {
|
} else {
|
||||||
startActivityForResult(CreateKbsPinActivity.getIntentForPinCreate(requireContext()), CreateKbsPinActivity.REQUEST_NEW_PIN);
|
startActivityForResult(CreateKbsPinActivity.getIntentForPinCreate(requireContext()), CreateKbsPinActivity.REQUEST_NEW_PIN);
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,6 @@
|
|||||||
<string name="ApplicationPreferencesActivity_privacy_summary_screen_lock">Screen lock %1$s</string>
|
<string name="ApplicationPreferencesActivity_privacy_summary_screen_lock">Screen lock %1$s</string>
|
||||||
<string name="ApplicationPreferencesActivity_appearance_summary">Theme %1$s, Language %2$s</string>
|
<string name="ApplicationPreferencesActivity_appearance_summary">Theme %1$s, Language %2$s</string>
|
||||||
<string name="ApplicationPreferencesActivity_pins_are_required_for_registration_lock">PINs are required for registration lock. To disable PINs, please first disable registration lock.</string>
|
<string name="ApplicationPreferencesActivity_pins_are_required_for_registration_lock">PINs are required for registration lock. To disable PINs, please first disable registration lock.</string>
|
||||||
<string name="ApplicationPreferencesActivity_failed_to_disable_pins_try_again_later">Failed to disable PINs. Try again later.</string>
|
|
||||||
<string name="ApplicationPreferencesActivity_pin_created">PIN created.</string>
|
<string name="ApplicationPreferencesActivity_pin_created">PIN created.</string>
|
||||||
<string name="ApplicationPreferencesActivity_pin_disabled">PIN disabled.</string>
|
<string name="ApplicationPreferencesActivity_pin_disabled">PIN disabled.</string>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user