mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 19:29:06 +01:00
Merge branch '2173-unlink-mailbox' into 'master'
Implement UI for unpairing the mailbox Closes #2173 See merge request briar/briar!1637
This commit is contained in:
@@ -2,6 +2,7 @@ package org.briarproject.bramble.api.mailbox;
|
||||
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@@ -41,4 +42,10 @@ public interface MailboxManager {
|
||||
*/
|
||||
boolean checkConnection();
|
||||
|
||||
/**
|
||||
* Unpairs the owner's mailbox and tries to wipe it.
|
||||
* As this makes a network call, it should be run on the {@link IoExecutor}.
|
||||
*/
|
||||
@IoExecutor
|
||||
void unPair() throws DbException;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,8 @@ public interface MailboxSettingsManager {
|
||||
void setOwnMailboxProperties(Transaction txn, MailboxProperties p)
|
||||
throws DbException;
|
||||
|
||||
void removeOwnMailboxProperties(Transaction txn) throws DbException;
|
||||
|
||||
MailboxStatus getOwnMailboxStatus(Transaction txn) throws DbException;
|
||||
|
||||
void recordSuccessfulConnection(Transaction txn, long now)
|
||||
|
||||
@@ -131,4 +131,18 @@ class MailboxManagerImpl implements MailboxManager {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unPair() throws DbException {
|
||||
MailboxProperties properties = db.transactionWithNullableResult(true,
|
||||
mailboxSettingsManager::getOwnMailboxProperties);
|
||||
try {
|
||||
api.wipeMailbox(properties);
|
||||
} catch (IOException | MailboxApi.ApiException e) {
|
||||
// We wipe on a best-effort basis.
|
||||
// If we can't do it, we still unpair.
|
||||
logException(LOG, WARNING, e);
|
||||
}
|
||||
db.transaction(false,
|
||||
mailboxSettingsManager::removeOwnMailboxProperties);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,6 +75,17 @@ class MailboxSettingsManagerImpl implements MailboxSettingsManager {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeOwnMailboxProperties(Transaction txn) throws DbException {
|
||||
Settings s = new Settings();
|
||||
s.put(SETTINGS_KEY_ONION, "");
|
||||
s.put(SETTINGS_KEY_TOKEN, "");
|
||||
settingsManager.mergeSettings(txn, s, SETTINGS_NAMESPACE);
|
||||
for (MailboxHook hook : hooks) {
|
||||
hook.mailboxUnpaired(txn);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MailboxStatus getOwnMailboxStatus(Transaction txn)
|
||||
throws DbException {
|
||||
|
||||
@@ -12,7 +12,6 @@ import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.briarproject.bramble.api.mailbox.MailboxStatus;
|
||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||
@@ -25,6 +24,7 @@ import androidx.annotation.ColorRes;
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.UiThread;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
@@ -53,10 +53,13 @@ public class MailboxStatusFragment extends Fragment {
|
||||
private final Handler handler = new Handler(Looper.getMainLooper());
|
||||
@Nullable // UiThread
|
||||
private Runnable refresher = null;
|
||||
private boolean showUnlinkWarning = true;
|
||||
|
||||
private ImageView imageView;
|
||||
private TextView statusTitleView;
|
||||
private TextView statusInfoView;
|
||||
private Button unlinkButton;
|
||||
private ProgressBar unlinkProgress;
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
@@ -101,10 +104,11 @@ public class MailboxStatusFragment extends Fragment {
|
||||
|
||||
// TODO
|
||||
// * Implement UI for warning user when mailbox is unreachable #2175
|
||||
// * add "Unlink" button confirmation dialog and functionality #2173
|
||||
Button unlinkButton = v.findViewById(R.id.unlinkButton);
|
||||
unlinkButton.setOnClickListener(view -> Toast.makeText(requireContext(),
|
||||
"NOT IMPLEMENTED", Toast.LENGTH_SHORT).show());
|
||||
unlinkButton = v.findViewById(R.id.unlinkButton);
|
||||
unlinkProgress = v.findViewById(R.id.unlinkProgress);
|
||||
unlinkButton.setOnClickListener(view ->
|
||||
onUnlinkButtonClicked(showUnlinkWarning)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -130,14 +134,17 @@ public class MailboxStatusFragment extends Fragment {
|
||||
iconRes = R.drawable.ic_check_circle_outline;
|
||||
title = getString(R.string.mailbox_status_connected_title);
|
||||
tintRes = R.color.briar_brand_green;
|
||||
showUnlinkWarning = true;
|
||||
} else if (status.getAttemptsSinceSuccess() < NUM_FAILURES) {
|
||||
iconRes = R.drawable.ic_help_outline_white;
|
||||
title = getString(R.string.mailbox_status_problem_title);
|
||||
tintRes = R.color.briar_orange_500;
|
||||
showUnlinkWarning = false;
|
||||
} else {
|
||||
tintRes = R.color.briar_red_500;
|
||||
title = getString(R.string.mailbox_status_failure_title);
|
||||
iconRes = R.drawable.alerts_and_states_error;
|
||||
showUnlinkWarning = false;
|
||||
}
|
||||
imageView.setImageResource(iconRes);
|
||||
int color = getColor(requireContext(), tintRes);
|
||||
@@ -167,4 +174,26 @@ public class MailboxStatusFragment extends Fragment {
|
||||
}
|
||||
}
|
||||
|
||||
private void onUnlinkButtonClicked(boolean showWarning) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(requireContext(),
|
||||
R.style.BriarDialogTheme);
|
||||
builder.setTitle(R.string.mailbox_status_unlink_dialog_title);
|
||||
String msg = getString(R.string.mailbox_status_unlink_dialog_question);
|
||||
if (showWarning) {
|
||||
msg = getString(R.string.mailbox_status_unlink_dialog_warning) +
|
||||
"\n\n" + msg;
|
||||
}
|
||||
builder.setMessage(msg);
|
||||
builder.setPositiveButton(R.string.cancel,
|
||||
(dialog, which) -> dialog.cancel());
|
||||
builder.setNegativeButton(R.string.mailbox_status_unlink_button,
|
||||
(dialog, which) -> {
|
||||
beginDelayedTransition((ViewGroup) requireView());
|
||||
unlinkButton.setVisibility(INVISIBLE);
|
||||
unlinkProgress.setVisibility(VISIBLE);
|
||||
viewModel.unlink();
|
||||
});
|
||||
builder.show();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.google.zxing.Result;
|
||||
|
||||
import org.briarproject.bramble.api.Consumer;
|
||||
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.TransactionManager;
|
||||
import org.briarproject.bramble.api.event.Event;
|
||||
import org.briarproject.bramble.api.event.EventBus;
|
||||
@@ -220,6 +221,18 @@ class MailboxViewModel extends DbViewModel
|
||||
return liveData;
|
||||
}
|
||||
|
||||
@UiThread
|
||||
void unlink() {
|
||||
ioExecutor.execute(() -> {
|
||||
try {
|
||||
mailboxManager.unPair();
|
||||
pairingState.postEvent(new MailboxState.NotSetup());
|
||||
} catch (DbException e) {
|
||||
handleException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@UiThread
|
||||
LiveEvent<MailboxState> getPairingState() {
|
||||
return pairingState;
|
||||
|
||||
@@ -83,4 +83,15 @@
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/unlinkProgress"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="invisible"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/unlinkButton"
|
||||
app:layout_constraintEnd_toEndOf="@+id/unlinkButton"
|
||||
app:layout_constraintStart_toStartOf="@+id/unlinkButton"
|
||||
app:layout_constraintTop_toTopOf="@+id/unlinkButton"
|
||||
tools:visibility="visible" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
@@ -651,6 +651,9 @@
|
||||
<!-- Indicates that there never was a connection to the mailbox. Last connection: Never -->
|
||||
<string name="mailbox_status_connected_never">Never</string>
|
||||
<string name="mailbox_status_unlink_button">Unlink</string>
|
||||
<string name="mailbox_status_unlink_dialog_title">Unlink mailbox?</string>
|
||||
<string name="mailbox_status_unlink_dialog_question">Are you sure you want to unlink your Mailbox?</string>
|
||||
<string name="mailbox_status_unlink_dialog_warning">If you unlink your Mailbox, you won\'t be able to receive messages while Briar is offline.</string>
|
||||
|
||||
<!-- Conversation Settings -->
|
||||
<string name="disappearing_messages_title">Disappearing messages</string>
|
||||
|
||||
Reference in New Issue
Block a user