Pass String instead of the TextView

This commit is contained in:
goapunk
2018-06-20 18:36:39 +02:00
parent 497213e56d
commit 0ad20037ae
2 changed files with 28 additions and 19 deletions

View File

@@ -2,7 +2,6 @@ package org.briarproject.briar.android.keyagreement;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.UiThread; import android.support.annotation.UiThread;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import org.briarproject.bramble.api.contact.ContactExchangeListener; import org.briarproject.bramble.api.contact.ContactExchangeListener;
@@ -115,31 +114,31 @@ public class ContactExchangeActivity extends KeyAgreementActivity implements
@UiThread @UiThread
@Override @Override
public void keyAgreementWaiting(TextView status) { public String keyAgreementWaiting() {
status.setText(R.string.waiting_for_contact_to_scan); return getString(R.string.waiting_for_contact_to_scan);
} }
@UiThread @UiThread
@Override @Override
public void keyAgreementStarted(TextView status) { public String keyAgreementStarted() {
status.setText(R.string.authenticating_with_device); return getString(R.string.authenticating_with_device);
} }
@UiThread @UiThread
@Override @Override
public void keyAgreementAborted(boolean remoteAborted) { public String keyAgreementAborted(boolean remoteAborted) {
// TODO show abort somewhere persistent? // TODO show abort somewhere persistent?
Toast.makeText(this, Toast.makeText(this,
remoteAborted ? R.string.connection_aborted_remote : remoteAborted ? R.string.connection_aborted_remote :
R.string.connection_aborted_local, LENGTH_LONG) R.string.connection_aborted_local, LENGTH_LONG)
.show(); .show();
return null;
} }
@UiThread @UiThread
@Override @Override
public void keyAgreementFinished(TextView status, public String keyAgreementFinished(KeyAgreementResult result) {
KeyAgreementResult result) {
status.setText(R.string.exchanging_contact_details);
startContactExchange(result); startContactExchange(result);
return getString(string.exchanging_contact_details);
} }
} }

View File

@@ -31,6 +31,7 @@ import org.briarproject.bramble.api.keyagreement.event.KeyAgreementStartedEvent;
import org.briarproject.bramble.api.keyagreement.event.KeyAgreementWaitingEvent; import org.briarproject.bramble.api.keyagreement.event.KeyAgreementWaitingEvent;
import org.briarproject.bramble.api.lifecycle.IoExecutor; import org.briarproject.bramble.api.lifecycle.IoExecutor;
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault; import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault; import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
import org.briarproject.briar.R; import org.briarproject.briar.R;
import org.briarproject.briar.android.activity.ActivityComponent; import org.briarproject.briar.android.activity.ActivityComponent;
@@ -90,7 +91,8 @@ public class KeyAgreementFragment extends BaseEventFragment
private KeyAgreementTask task; private KeyAgreementTask task;
private KeyAgreementEventListener listener; private KeyAgreementEventListener listener;
public static KeyAgreementFragment newInstance(KeyAgreementEventListener listener) { public static KeyAgreementFragment newInstance(
KeyAgreementEventListener listener) {
Bundle args = new Bundle(); Bundle args = new Bundle();
KeyAgreementFragment fragment = new KeyAgreementFragment(); KeyAgreementFragment fragment = new KeyAgreementFragment();
fragment.listener = listener; fragment.listener = listener;
@@ -281,14 +283,14 @@ public class KeyAgreementFragment extends BaseEventFragment
private void keyAgreementWaiting() { private void keyAgreementWaiting() {
runOnUiThreadUnlessDestroyed( runOnUiThreadUnlessDestroyed(
() -> listener.keyAgreementWaiting(status)); () -> status.setText(listener.keyAgreementWaiting()));
} }
private void keyAgreementStarted() { private void keyAgreementStarted() {
runOnUiThreadUnlessDestroyed(() -> { runOnUiThreadUnlessDestroyed(() -> {
qrCodeView.setVisibility(INVISIBLE); qrCodeView.setVisibility(INVISIBLE);
statusView.setVisibility(VISIBLE); statusView.setVisibility(VISIBLE);
listener.keyAgreementStarted(status); status.setText(listener.keyAgreementStarted());
}); });
} }
@@ -297,15 +299,14 @@ public class KeyAgreementFragment extends BaseEventFragment
reset(); reset();
qrCodeView.setVisibility(VISIBLE); qrCodeView.setVisibility(VISIBLE);
statusView.setVisibility(INVISIBLE); statusView.setVisibility(INVISIBLE);
status.setText(""); status.setText(listener.keyAgreementAborted(remoteAborted));
listener.keyAgreementAborted(remoteAborted);
}); });
} }
private void keyAgreementFinished(KeyAgreementResult result) { private void keyAgreementFinished(KeyAgreementResult result) {
runOnUiThreadUnlessDestroyed(() -> { runOnUiThreadUnlessDestroyed(() -> {
statusView.setVisibility(VISIBLE); statusView.setVisibility(VISIBLE);
listener.keyAgreementFinished(status, result); status.setText(listener.keyAgreementFinished(result));
}); });
} }
@@ -341,21 +342,30 @@ public class KeyAgreementFragment extends BaseEventFragment
getActivity().getSupportFragmentManager().popBackStack(); getActivity().getSupportFragmentManager().popBackStack();
} }
@NotNullByDefault
interface KeyAgreementEventListener { interface KeyAgreementEventListener {
@UiThread @UiThread
void keyAgreementFailed(); void keyAgreementFailed();
// Should return a string to be displayed as status.
@UiThread @UiThread
void keyAgreementWaiting(TextView status); @Nullable
String keyAgreementWaiting();
// Should return a string to be displayed as status.
@UiThread @UiThread
void keyAgreementStarted(TextView status); @Nullable
String keyAgreementStarted();
// Should return a string to be displayed as status.
@UiThread @UiThread
void keyAgreementAborted(boolean remoteAborted); @Nullable
String keyAgreementAborted(boolean remoteAborted);
// Should return a string to be displayed as status.
@UiThread @UiThread
void keyAgreementFinished(TextView status, KeyAgreementResult result); @Nullable
String keyAgreementFinished(KeyAgreementResult result);
} }
} }