mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-19 14:19:53 +01:00
Show an error fragment when contact exchange fails
This commit is contained in:
@@ -27,6 +27,7 @@ import org.briarproject.briar.android.introduction.ContactChooserFragment;
|
|||||||
import org.briarproject.briar.android.introduction.IntroductionActivity;
|
import org.briarproject.briar.android.introduction.IntroductionActivity;
|
||||||
import org.briarproject.briar.android.introduction.IntroductionMessageFragment;
|
import org.briarproject.briar.android.introduction.IntroductionMessageFragment;
|
||||||
import org.briarproject.briar.android.keyagreement.ContactExchangeActivity;
|
import org.briarproject.briar.android.keyagreement.ContactExchangeActivity;
|
||||||
|
import org.briarproject.briar.android.keyagreement.ContactExchangeErrorFragment;
|
||||||
import org.briarproject.briar.android.keyagreement.IntroFragment;
|
import org.briarproject.briar.android.keyagreement.IntroFragment;
|
||||||
import org.briarproject.briar.android.keyagreement.KeyAgreementActivity;
|
import org.briarproject.briar.android.keyagreement.KeyAgreementActivity;
|
||||||
import org.briarproject.briar.android.keyagreement.KeyAgreementFragment;
|
import org.briarproject.briar.android.keyagreement.KeyAgreementFragment;
|
||||||
@@ -208,4 +209,6 @@ public interface ActivityComponent {
|
|||||||
void inject(SettingsFragment fragment);
|
void inject(SettingsFragment fragment);
|
||||||
|
|
||||||
void inject(ScreenFilterDialogFragment fragment);
|
void inject(ScreenFilterDialogFragment fragment);
|
||||||
|
|
||||||
|
void inject(ContactExchangeErrorFragment fragment);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import org.briarproject.bramble.api.keyagreement.KeyAgreementResult;
|
|||||||
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;
|
||||||
import org.briarproject.briar.R.string;
|
|
||||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||||
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
@@ -48,7 +47,7 @@ public class ContactExchangeActivity extends KeyAgreementActivity implements
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable Bundle state) {
|
public void onCreate(@Nullable Bundle state) {
|
||||||
super.onCreate(state);
|
super.onCreate(state);
|
||||||
getSupportActionBar().setTitle(string.add_contact_title);
|
getSupportActionBar().setTitle(R.string.add_contact_title);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startContactExchange(KeyAgreementResult result) {
|
private void startContactExchange(KeyAgreementResult result) {
|
||||||
@@ -75,7 +74,7 @@ public class ContactExchangeActivity extends KeyAgreementActivity implements
|
|||||||
public void contactExchangeSucceeded(Author remoteAuthor) {
|
public void contactExchangeSucceeded(Author remoteAuthor) {
|
||||||
runOnUiThreadUnlessDestroyed(() -> {
|
runOnUiThreadUnlessDestroyed(() -> {
|
||||||
String contactName = remoteAuthor.getName();
|
String contactName = remoteAuthor.getName();
|
||||||
String format = getString(string.contact_added_toast);
|
String format = getString(R.string.contact_added_toast);
|
||||||
String text = String.format(format, contactName);
|
String text = String.format(format, contactName);
|
||||||
Toast.makeText(ContactExchangeActivity.this, text, LENGTH_LONG)
|
Toast.makeText(ContactExchangeActivity.this, text, LENGTH_LONG)
|
||||||
.show();
|
.show();
|
||||||
@@ -87,7 +86,7 @@ public class ContactExchangeActivity extends KeyAgreementActivity implements
|
|||||||
public void duplicateContact(Author remoteAuthor) {
|
public void duplicateContact(Author remoteAuthor) {
|
||||||
runOnUiThreadUnlessDestroyed(() -> {
|
runOnUiThreadUnlessDestroyed(() -> {
|
||||||
String contactName = remoteAuthor.getName();
|
String contactName = remoteAuthor.getName();
|
||||||
String format = getString(string.contact_already_exists);
|
String format = getString(R.string.contact_already_exists);
|
||||||
String text = String.format(format, contactName);
|
String text = String.format(format, contactName);
|
||||||
Toast.makeText(ContactExchangeActivity.this, text, LENGTH_LONG)
|
Toast.makeText(ContactExchangeActivity.this, text, LENGTH_LONG)
|
||||||
.show();
|
.show();
|
||||||
@@ -98,18 +97,14 @@ public class ContactExchangeActivity extends KeyAgreementActivity implements
|
|||||||
@Override
|
@Override
|
||||||
public void contactExchangeFailed() {
|
public void contactExchangeFailed() {
|
||||||
runOnUiThreadUnlessDestroyed(() -> {
|
runOnUiThreadUnlessDestroyed(() -> {
|
||||||
Toast.makeText(ContactExchangeActivity.this,
|
showErrorFragment(R.string.contact_exchange_failed);
|
||||||
string.contact_exchange_failed, LENGTH_LONG).show();
|
|
||||||
finish();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
@Override
|
@Override
|
||||||
public void keyAgreementFailed() {
|
public void keyAgreementFailed() {
|
||||||
// TODO show failure somewhere persistent?
|
showErrorFragment(R.string.connection_failed);
|
||||||
Toast.makeText(this, R.string.connection_failed,
|
|
||||||
LENGTH_LONG).show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
@@ -124,14 +119,12 @@ public class ContactExchangeActivity extends KeyAgreementActivity implements
|
|||||||
return getString(R.string.authenticating_with_device);
|
return getString(R.string.authenticating_with_device);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
@UiThread
|
@UiThread
|
||||||
@Override
|
@Override
|
||||||
public String keyAgreementAborted(boolean remoteAborted) {
|
public String keyAgreementAborted(boolean remoteAborted) {
|
||||||
// TODO show abort somewhere persistent?
|
showErrorFragment(remoteAborted ? R.string.connection_aborted_remote :
|
||||||
Toast.makeText(this,
|
R.string.connection_aborted_local);
|
||||||
remoteAborted ? R.string.connection_aborted_remote :
|
|
||||||
R.string.connection_aborted_local, LENGTH_LONG)
|
|
||||||
.show();
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,6 +132,6 @@ public class ContactExchangeActivity extends KeyAgreementActivity implements
|
|||||||
@Override
|
@Override
|
||||||
public String keyAgreementFinished(KeyAgreementResult result) {
|
public String keyAgreementFinished(KeyAgreementResult result) {
|
||||||
startContactExchange(result);
|
startContactExchange(result);
|
||||||
return getString(string.exchanging_contact_details);
|
return getString(R.string.exchanging_contact_details);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,118 @@
|
|||||||
|
package org.briarproject.briar.android.keyagreement;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
import android.text.SpannableStringBuilder;
|
||||||
|
import android.text.method.LinkMovementMethod;
|
||||||
|
import android.text.style.ClickableSpan;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import org.acra.ACRA;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.system.AndroidExecutor;
|
||||||
|
import org.briarproject.briar.R;
|
||||||
|
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||||
|
import org.briarproject.briar.android.fragment.BaseFragment;
|
||||||
|
import org.briarproject.briar.android.util.UserFeedback;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
@MethodsNotNullByDefault
|
||||||
|
@ParametersNotNullByDefault
|
||||||
|
public class ContactExchangeErrorFragment extends BaseFragment {
|
||||||
|
|
||||||
|
public static final String TAG =
|
||||||
|
ContactExchangeErrorFragment.class.getName();
|
||||||
|
private static final String ERROR_MSG = "errorMessage";
|
||||||
|
|
||||||
|
public static ContactExchangeErrorFragment newInstance(String message) {
|
||||||
|
ContactExchangeErrorFragment f = new ContactExchangeErrorFragment();
|
||||||
|
Bundle args = new Bundle();
|
||||||
|
args.putString(ERROR_MSG, message);
|
||||||
|
f.setArguments(args);
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
AndroidExecutor androidExecutor;
|
||||||
|
|
||||||
|
private String errorMessage;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUniqueTag() {
|
||||||
|
return TAG;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
Bundle args = getArguments();
|
||||||
|
if (args == null) {
|
||||||
|
throw new IllegalArgumentException("Use newInstance()");
|
||||||
|
}
|
||||||
|
errorMessage = args.getString(ERROR_MSG);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater,
|
||||||
|
@Nullable ViewGroup container,
|
||||||
|
@Nullable Bundle savedInstanceState) {
|
||||||
|
View v = inflater
|
||||||
|
.inflate(R.layout.fragment_error_contact_exchange, container,
|
||||||
|
false);
|
||||||
|
|
||||||
|
// make feedback link clickable
|
||||||
|
TextView explanation = v.findViewById(R.id.errorMessage);
|
||||||
|
SpannableStringBuilder ssb =
|
||||||
|
new SpannableStringBuilder(explanation.getText());
|
||||||
|
ClickableSpan[] spans =
|
||||||
|
ssb.getSpans(0, ssb.length(), ClickableSpan.class);
|
||||||
|
if (spans.length != 1) throw new AssertionError();
|
||||||
|
ClickableSpan span = spans[0];
|
||||||
|
int start = ssb.getSpanStart(span);
|
||||||
|
int end = ssb.getSpanEnd(span);
|
||||||
|
ssb.removeSpan(span);
|
||||||
|
ClickableSpan cSpan = new ClickableSpan() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
triggerFeedback();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ssb.setSpan(cSpan, start + 1, end, 0);
|
||||||
|
explanation.setText(ssb);
|
||||||
|
explanation.setMovementMethod(new LinkMovementMethod());
|
||||||
|
|
||||||
|
// technical error message
|
||||||
|
TextView msg = v.findViewById(R.id.errorMessageTech);
|
||||||
|
msg.setText(errorMessage);
|
||||||
|
|
||||||
|
// buttons
|
||||||
|
Button tryAgain = v.findViewById(R.id.tryAgainButton);
|
||||||
|
tryAgain.setOnClickListener(view -> {
|
||||||
|
if (getActivity() != null) getActivity().onBackPressed();
|
||||||
|
});
|
||||||
|
Button cancel = v.findViewById(R.id.cancelButton);
|
||||||
|
cancel.setOnClickListener(view -> finish());
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void injectFragment(ActivityComponent component) {
|
||||||
|
component.inject(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void triggerFeedback() {
|
||||||
|
finish();
|
||||||
|
androidExecutor.runOnBackgroundThread(
|
||||||
|
() -> ACRA.getErrorReporter()
|
||||||
|
.handleException(new UserFeedback(), false));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ import android.content.DialogInterface.OnClickListener;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.StringRes;
|
||||||
import android.support.annotation.UiThread;
|
import android.support.annotation.UiThread;
|
||||||
import android.support.v4.app.ActivityCompat;
|
import android.support.v4.app.ActivityCompat;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
@@ -28,6 +29,7 @@ import org.briarproject.briar.android.activity.BriarActivity;
|
|||||||
import org.briarproject.briar.android.fragment.BaseFragment;
|
import org.briarproject.briar.android.fragment.BaseFragment;
|
||||||
import org.briarproject.briar.android.fragment.BaseFragment.BaseFragmentListener;
|
import org.briarproject.briar.android.fragment.BaseFragment.BaseFragmentListener;
|
||||||
import org.briarproject.briar.android.keyagreement.IntroFragment.IntroScreenSeenListener;
|
import org.briarproject.briar.android.keyagreement.IntroFragment.IntroScreenSeenListener;
|
||||||
|
import org.briarproject.briar.android.keyagreement.KeyAgreementFragment.KeyAgreementEventListener;
|
||||||
import org.briarproject.briar.android.util.UiUtils;
|
import org.briarproject.briar.android.util.UiUtils;
|
||||||
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
@@ -50,7 +52,7 @@ import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_PERMI
|
|||||||
@ParametersNotNullByDefault
|
@ParametersNotNullByDefault
|
||||||
public abstract class KeyAgreementActivity extends BriarActivity implements
|
public abstract class KeyAgreementActivity extends BriarActivity implements
|
||||||
BaseFragmentListener, IntroScreenSeenListener,
|
BaseFragmentListener, IntroScreenSeenListener,
|
||||||
KeyAgreementFragment.KeyAgreementEventListener {
|
KeyAgreementEventListener {
|
||||||
|
|
||||||
private enum BluetoothState {
|
private enum BluetoothState {
|
||||||
UNKNOWN, NO_ADAPTER, WAITING, REFUSED, ENABLED
|
UNKNOWN, NO_ADAPTER, WAITING, REFUSED, ENABLED
|
||||||
@@ -185,6 +187,12 @@ public abstract class KeyAgreementActivity extends BriarActivity implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void showErrorFragment(@StringRes int errorResId) {
|
||||||
|
String errorMessage = getString(errorResId);
|
||||||
|
BaseFragment f = ContactExchangeErrorFragment.newInstance(errorMessage);
|
||||||
|
showNextFragment(f);
|
||||||
|
}
|
||||||
|
|
||||||
private boolean checkPermissions() {
|
private boolean checkPermissions() {
|
||||||
if (ContextCompat.checkSelfPermission(this, CAMERA) !=
|
if (ContextCompat.checkSelfPermission(this, CAMERA) !=
|
||||||
PERMISSION_GRANTED) {
|
PERMISSION_GRANTED) {
|
||||||
|
|||||||
@@ -0,0 +1,105 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<ScrollView
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:fillViewport="true">
|
||||||
|
|
||||||
|
<android.support.constraint.ConstraintLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/errorTitle"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="16dp"
|
||||||
|
android:text="@string/connection_error_title"
|
||||||
|
android:textColor="?android:attr/textColorPrimary"
|
||||||
|
android:textSize="@dimen/text_size_large"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"/>
|
||||||
|
|
||||||
|
<android.support.v7.widget.AppCompatImageView
|
||||||
|
android:id="@+id/errorIcon"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="16dp"
|
||||||
|
android:layout_marginRight="16dp"
|
||||||
|
android:src="@drawable/qr_code_intro"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/errorTitle"
|
||||||
|
app:tint="?attr/colorControlNormal"
|
||||||
|
tools:ignore="ContentDescription"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/errorMessage"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginEnd="16dp"
|
||||||
|
android:layout_marginLeft="16dp"
|
||||||
|
android:layout_marginRight="16dp"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:text="@string/connection_error_explanation"
|
||||||
|
android:textColor="?android:attr/textColorPrimary"
|
||||||
|
android:textSize="@dimen/text_size_medium"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/errorIcon"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/errorMessageTech"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="16dp"
|
||||||
|
android:layout_marginBottom="8dp"
|
||||||
|
android:alpha="0.5"
|
||||||
|
android:background="@color/card_background"
|
||||||
|
android:fontFamily="monospace"
|
||||||
|
android:padding="8dp"
|
||||||
|
android:textColor="@color/briar_red"
|
||||||
|
android:textSize="@dimen/text_size_medium"
|
||||||
|
app:layout_constraintBottom_toTopOf="@+id/tryAgainButton"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/errorMessage"
|
||||||
|
tools:text="@string/connection_failed"/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/tryAgainButton"
|
||||||
|
style="@style/BriarButtonFlat.Positive"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="8dp"
|
||||||
|
android:layout_marginEnd="8dp"
|
||||||
|
android:layout_marginRight="8dp"
|
||||||
|
android:text="@string/try_again_button"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintHorizontal_weight="1"
|
||||||
|
app:layout_constraintStart_toEndOf="@+id/cancelButton"/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/cancelButton"
|
||||||
|
style="@style/BriarButtonFlat.Negative"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="8dp"
|
||||||
|
android:layout_marginEnd="8dp"
|
||||||
|
android:layout_marginLeft="8dp"
|
||||||
|
android:layout_marginRight="8dp"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:text="@string/cancel"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toStartOf="@+id/tryAgainButton"
|
||||||
|
app:layout_constraintHorizontal_chainStyle="spread"
|
||||||
|
app:layout_constraintHorizontal_weight="1"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"/>
|
||||||
|
|
||||||
|
</android.support.constraint.ConstraintLayout>
|
||||||
|
</ScrollView>
|
||||||
@@ -147,6 +147,8 @@
|
|||||||
<string name="authenticating_with_device">Authenticating with device\u2026</string>
|
<string name="authenticating_with_device">Authenticating with device\u2026</string>
|
||||||
<string name="connection_aborted_local">Connection aborted! This could mean that someone is trying to interfere with your connection</string>
|
<string name="connection_aborted_local">Connection aborted! This could mean that someone is trying to interfere with your connection</string>
|
||||||
<string name="connection_aborted_remote">Connection aborted by your contact! This could mean that someone is trying to interfere with your connection</string>
|
<string name="connection_aborted_remote">Connection aborted by your contact! This could mean that someone is trying to interfere with your connection</string>
|
||||||
|
<string name="connection_error_title">Could not connect to your contact</string>
|
||||||
|
<string name="connection_error_explanation">Please check that you\'re both connected to the same Wi-Fi network.\n\nIf this problem persists, please <a href="feedback">send feedback</a> to help us improve the app.</string>
|
||||||
|
|
||||||
<!-- Introductions -->
|
<!-- Introductions -->
|
||||||
<string name="introduction_onboarding_title">Introduce your contacts</string>
|
<string name="introduction_onboarding_title">Introduce your contacts</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user