Fix UI around receiving multiple returned shards

This commit is contained in:
ameba23
2021-04-19 10:07:06 +02:00
parent ad3c9e101c
commit bdbc377c8f
3 changed files with 18 additions and 14 deletions

View File

@@ -104,15 +104,7 @@ public class OwnerReturnShardActivity extends BaseActivity
@Override
public void onBackPressed() {
// TODO should we cancel the return shard task here?
if (viewModel.getState()
.getValue() instanceof SecretOwnerTask.State.Failure) {
// re-create this activity when going back in failed state
Intent i = new Intent(this, OwnerReturnShardActivity.class);
i.setFlags(FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
} else {
super.onBackPressed();
}
super.onBackPressed();
}
private void showQrCodeFragment() {
@@ -136,10 +128,13 @@ public class OwnerReturnShardActivity extends BaseActivity
"Success - got shard" + (added ? "" : " duplicate"),
Toast.LENGTH_SHORT).show();
if (added && viewModel.canRecover()) {
Toast.makeText(this,
"Secret key recovered!",
Toast.LENGTH_LONG).show();
finish();
return;
}
onBackPressed();
// finish();
} else if (state instanceof SecretOwnerTask.State.Failure) {
// TODO error screen, handle reason
Toast.makeText(this,

View File

@@ -137,8 +137,6 @@ class OwnerReturnShardViewModel extends AndroidViewModel
@UiThread
public void startListening() {
ioExecutor.execute(() -> {
task.cancel();
// wait until really cancelled
task.start(this, getWifiIpv4Address());
});
// KeyAgreementTask oldTask = task;
@@ -208,8 +206,12 @@ class OwnerReturnShardViewModel extends AndroidViewModel
// Use ISO 8859-1 to encode bytes directly as a string
String content = new String(payloadBytes, ISO_8859_1);
qrCodeBitmap = QrCodeUtils.createQrCode(dm, content);
this.state.postValue(state);
this.state.postValue(state);
});
} else if (state instanceof SecretOwnerTask.State.Success) {
// startClicked.setEvent(true);
this.state.postValue(state);
// TODO do same for failure
} else {
this.state.postValue(state);
}

View File

@@ -62,6 +62,13 @@ public class SecretOwnerTaskImpl extends ReturnShardTaskImpl
LOG.info("InetAddress is " + inetAddress);
socketAddress = new InetSocketAddress(inetAddress, PORT);
// If we have a socket already open, close it and start fresh
if (serverSocket != null) {
try {
serverSocket.close();
} catch (IOException ignored) {}
}
// Start listening on socketAddress
try {
LOG.info("Binding socket");