mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 21:29:54 +01:00
Do real check if mailbox is set up
This commit is contained in:
@@ -3,7 +3,9 @@ package org.briarproject.briar.android.mailbox;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.mailbox.MailboxStatus;
|
||||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
@@ -57,6 +59,10 @@ public class MailboxActivity extends BriarActivity {
|
|||||||
onQrCodeWrong();
|
onQrCodeWrong();
|
||||||
} else if (state instanceof MailboxState.OfflineInSetup) {
|
} else if (state instanceof MailboxState.OfflineInSetup) {
|
||||||
onOffline();
|
onOffline();
|
||||||
|
} else if (state instanceof MailboxState.IsSetup) {
|
||||||
|
onIsSetup(((MailboxState.IsSetup) state).mailboxStatus);
|
||||||
|
} else {
|
||||||
|
throw new AssertionError("Unknown state: " + state);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -107,4 +113,9 @@ public class MailboxActivity extends BriarActivity {
|
|||||||
OfflineFragment.TAG);
|
OfflineFragment.TAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void onIsSetup(MailboxStatus mailboxStatus) {
|
||||||
|
// TODO
|
||||||
|
Toast.makeText(this, "NOT IMPLEMENTED", Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.briarproject.briar.android.mailbox;
|
package org.briarproject.briar.android.mailbox;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.mailbox.MailboxProperties;
|
import org.briarproject.bramble.api.mailbox.MailboxProperties;
|
||||||
|
import org.briarproject.bramble.api.mailbox.MailboxStatus;
|
||||||
|
|
||||||
class MailboxState {
|
class MailboxState {
|
||||||
|
|
||||||
@@ -21,6 +22,12 @@ class MailboxState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO add other states
|
static class IsSetup extends MailboxState {
|
||||||
|
final MailboxStatus mailboxStatus;
|
||||||
|
|
||||||
|
IsSetup(MailboxStatus mailboxStatus) {
|
||||||
|
this.mailboxStatus = mailboxStatus;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
|||||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||||
import org.briarproject.bramble.api.mailbox.MailboxAuthToken;
|
import org.briarproject.bramble.api.mailbox.MailboxAuthToken;
|
||||||
import org.briarproject.bramble.api.mailbox.MailboxProperties;
|
import org.briarproject.bramble.api.mailbox.MailboxProperties;
|
||||||
|
import org.briarproject.bramble.api.mailbox.MailboxSettingsManager;
|
||||||
|
import org.briarproject.bramble.api.mailbox.MailboxStatus;
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.plugin.Plugin;
|
import org.briarproject.bramble.api.plugin.Plugin;
|
||||||
import org.briarproject.bramble.api.plugin.PluginManager;
|
import org.briarproject.bramble.api.plugin.PluginManager;
|
||||||
@@ -51,6 +53,7 @@ class MailboxViewModel extends DbViewModel
|
|||||||
private final CryptoComponent crypto;
|
private final CryptoComponent crypto;
|
||||||
private final QrCodeDecoder qrCodeDecoder;
|
private final QrCodeDecoder qrCodeDecoder;
|
||||||
private final PluginManager pluginManager;
|
private final PluginManager pluginManager;
|
||||||
|
private final MailboxSettingsManager mailboxSettingsManager;
|
||||||
|
|
||||||
private final MutableLiveData<MailboxState> state = new MutableLiveData<>();
|
private final MutableLiveData<MailboxState> state = new MutableLiveData<>();
|
||||||
|
|
||||||
@@ -63,25 +66,28 @@ class MailboxViewModel extends DbViewModel
|
|||||||
AndroidExecutor androidExecutor,
|
AndroidExecutor androidExecutor,
|
||||||
@IoExecutor Executor ioExecutor,
|
@IoExecutor Executor ioExecutor,
|
||||||
CryptoComponent crypto,
|
CryptoComponent crypto,
|
||||||
PluginManager pluginManager) {
|
PluginManager pluginManager,
|
||||||
|
MailboxSettingsManager mailboxSettingsManager) {
|
||||||
super(app, dbExecutor, lifecycleManager, db, androidExecutor);
|
super(app, dbExecutor, lifecycleManager, db, androidExecutor);
|
||||||
this.crypto = crypto;
|
this.crypto = crypto;
|
||||||
this.pluginManager = pluginManager;
|
this.pluginManager = pluginManager;
|
||||||
|
this.mailboxSettingsManager = mailboxSettingsManager;
|
||||||
qrCodeDecoder = new QrCodeDecoder(androidExecutor, ioExecutor, this);
|
qrCodeDecoder = new QrCodeDecoder(androidExecutor, ioExecutor, this);
|
||||||
checkIfSetup();
|
checkIfSetup();
|
||||||
}
|
}
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
private void checkIfSetup() {
|
private void checkIfSetup() {
|
||||||
runOnDbThread(() -> {
|
runOnDbThread(true, txn -> {
|
||||||
// TODO really check if mailbox is setup/paired/linked
|
MailboxProperties props =
|
||||||
try {
|
mailboxSettingsManager.getOwnMailboxProperties(txn);
|
||||||
Thread.sleep(1000);
|
if (props == null) state.postValue(new NotSetup());
|
||||||
} catch (InterruptedException e) {
|
else {
|
||||||
e.printStackTrace();
|
MailboxStatus mailboxStatus =
|
||||||
|
mailboxSettingsManager.getOwnMailboxStatus(txn);
|
||||||
|
state.postValue(new MailboxState.IsSetup(mailboxStatus));
|
||||||
}
|
}
|
||||||
state.postValue(new NotSetup());
|
}, this::handleException);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user