mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Use a new WasUnpaired state that shows a dialog over a blank fragment
This commit is contained in:
@@ -11,6 +11,7 @@ import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||
import org.briarproject.briar.android.activity.BriarActivity;
|
||||
import org.briarproject.briar.android.fragment.FinalFragment;
|
||||
import org.briarproject.briar.android.view.BlankFragment;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@@ -54,8 +55,7 @@ public class MailboxActivity extends BriarActivity {
|
||||
|
||||
viewModel.getPairingState().observeEvent(this, state -> {
|
||||
if (state instanceof MailboxState.NotSetup) {
|
||||
MailboxState.NotSetup s = (MailboxState.NotSetup) state;
|
||||
onNotSetup(s.tellUserToWipeMailbox);
|
||||
onNotSetup();
|
||||
} else if (state instanceof MailboxState.ShowDownload) {
|
||||
onShowDownload();
|
||||
} else if (state instanceof MailboxState.ScanningQrCode) {
|
||||
@@ -70,6 +70,9 @@ public class MailboxActivity extends BriarActivity {
|
||||
onCameraError();
|
||||
} else if (state instanceof MailboxState.IsPaired) {
|
||||
onIsPaired(((MailboxState.IsPaired) state).isOnline);
|
||||
} else if (state instanceof MailboxState.WasUnpaired) {
|
||||
MailboxState.WasUnpaired s = (MailboxState.WasUnpaired) state;
|
||||
onUnPaired(s.tellUserToWipeMailbox);
|
||||
} else {
|
||||
throw new AssertionError("Unknown state: " + state);
|
||||
}
|
||||
@@ -97,17 +100,8 @@ public class MailboxActivity extends BriarActivity {
|
||||
}
|
||||
}
|
||||
|
||||
private void onNotSetup(boolean tellUserToWipeMailbox) {
|
||||
private void onNotSetup() {
|
||||
progressBar.setVisibility(INVISIBLE);
|
||||
if (tellUserToWipeMailbox) {
|
||||
AlertDialog.Builder builder =
|
||||
new AlertDialog.Builder(this, R.style.BriarDialogTheme);
|
||||
builder.setTitle(R.string.mailbox_status_unlink_no_wipe_title);
|
||||
builder.setMessage(R.string.mailbox_status_unlink_no_wipe_message);
|
||||
builder.setNeutralButton(R.string.got_it,
|
||||
(dialog, which) -> dialog.cancel());
|
||||
builder.show();
|
||||
}
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
.replace(R.id.fragmentContainer, new SetupIntroFragment(),
|
||||
SetupIntroFragment.TAG)
|
||||
@@ -137,7 +131,7 @@ public class MailboxActivity extends BriarActivity {
|
||||
if (fm.getBackStackEntryCount() == 0) {
|
||||
// We re-launched into an existing state,
|
||||
// need to re-populate the back stack.
|
||||
onNotSetup(false);
|
||||
onNotSetup();
|
||||
onShowDownload();
|
||||
}
|
||||
Fragment f;
|
||||
@@ -201,4 +195,22 @@ public class MailboxActivity extends BriarActivity {
|
||||
showFragment(getSupportFragmentManager(), f, tag, false);
|
||||
}
|
||||
|
||||
private void onUnPaired(boolean tellUserToWipeMailbox) {
|
||||
if (tellUserToWipeMailbox) {
|
||||
showFragment(getSupportFragmentManager(), new BlankFragment(),
|
||||
BlankFragment.TAG);
|
||||
AlertDialog.Builder builder =
|
||||
new AlertDialog.Builder(this, R.style.BriarDialogTheme);
|
||||
builder.setTitle(R.string.mailbox_status_unlink_no_wipe_title);
|
||||
builder.setMessage(R.string.mailbox_status_unlink_no_wipe_message);
|
||||
builder.setNeutralButton(R.string.got_it,
|
||||
(dialog, which) -> dialog.cancel());
|
||||
builder.setOnCancelListener(
|
||||
dialog -> supportFinishAfterTransition());
|
||||
builder.show();
|
||||
} else {
|
||||
supportFinishAfterTransition();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,15 +5,6 @@ import org.briarproject.bramble.api.mailbox.MailboxPairingState;
|
||||
class MailboxState {
|
||||
|
||||
static class NotSetup extends MailboxState {
|
||||
final boolean tellUserToWipeMailbox;
|
||||
|
||||
NotSetup() {
|
||||
this(false);
|
||||
}
|
||||
|
||||
NotSetup(boolean tellUserToWipeMailbox) {
|
||||
this.tellUserToWipeMailbox = tellUserToWipeMailbox;
|
||||
}
|
||||
}
|
||||
|
||||
static class ShowDownload extends MailboxState {
|
||||
@@ -44,4 +35,12 @@ class MailboxState {
|
||||
}
|
||||
}
|
||||
|
||||
static class WasUnpaired extends MailboxState {
|
||||
final boolean tellUserToWipeMailbox;
|
||||
|
||||
WasUnpaired(boolean tellUserToWipeMailbox) {
|
||||
this.tellUserToWipeMailbox = tellUserToWipeMailbox;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ class MailboxViewModel extends DbViewModel
|
||||
ioExecutor.execute(() -> {
|
||||
try {
|
||||
boolean wasWiped = mailboxManager.unPair();
|
||||
pairingState.postEvent(new MailboxState.NotSetup(!wasWiped));
|
||||
pairingState.postEvent(new MailboxState.WasUnpaired(!wasWiped));
|
||||
} catch (DbException e) {
|
||||
handleException(e);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package org.briarproject.briar.android.view;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@ParametersNotNullByDefault
|
||||
public class BlankFragment extends Fragment {
|
||||
public static final String TAG = BlankFragment.class.getName();
|
||||
}
|
||||
Reference in New Issue
Block a user