Merge branch 'unsupported-handshake-link' into 'master'

Add error message for unsupported handshake link version

See merge request briar/briar!1091
This commit is contained in:
akwizgran
2019-05-26 14:36:24 +00:00
5 changed files with 63 additions and 11 deletions

View File

@@ -7,11 +7,13 @@ import android.arch.lifecycle.MutableLiveData;
import android.support.annotation.Nullable;
import org.briarproject.bramble.api.FormatException;
import org.briarproject.bramble.api.UnsupportedVersionException;
import org.briarproject.bramble.api.contact.ContactManager;
import org.briarproject.bramble.api.db.DatabaseExecutor;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.briar.android.viewmodel.LiveEvent;
import org.briarproject.briar.android.viewmodel.LiveResult;
import org.briarproject.briar.android.viewmodel.MutableLiveEvent;
import java.util.concurrent.Executor;
@@ -38,7 +40,7 @@ public class AddContactViewModel extends AndroidViewModel {
new MutableLiveData<>();
private final MutableLiveEvent<Boolean> remoteLinkEntered =
new MutableLiveEvent<>();
private final MutableLiveData<Boolean> addContactResult =
private final MutableLiveData<LiveResult<Boolean>> addContactResult =
new MutableLiveData<>();
@Nullable
private String remoteHandshakeLink;
@@ -96,15 +98,18 @@ public class AddContactViewModel extends AndroidViewModel {
dbExecutor.execute(() -> {
try {
contactManager.addPendingContact(remoteHandshakeLink, nickname);
addContactResult.postValue(true);
addContactResult.postValue(new LiveResult<>(true));
} catch (UnsupportedVersionException e) {
logException(LOG, WARNING, e);
addContactResult.postValue(new LiveResult<>(e));
} catch (DbException | FormatException e) {
logException(LOG, WARNING, e);
addContactResult.postValue(false);
addContactResult.postValue(new LiveResult<>(e));
}
});
}
LiveData<Boolean> getAddContactResult() {
public LiveData<LiveResult<Boolean>> getAddContactResult() {
return addContactResult;
}

View File

@@ -146,7 +146,7 @@ public class LinkExchangeFragment extends BaseFragment {
return null;
}
linkInputLayout.setError(null);
return linkWithoutSchema;
return link.toString();
}
linkInputLayout.setError(getString(R.string.invalid_link));
linkInput.requestFocus();

View File

@@ -14,6 +14,7 @@ import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.Toast;
import org.briarproject.bramble.api.UnsupportedVersionException;
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
import org.briarproject.briar.R;
@@ -103,15 +104,21 @@ public class NicknameFragment extends BaseFragment {
addButton.setVisibility(INVISIBLE);
progressBar.setVisibility(VISIBLE);
viewModel.getAddContactResult().observe(this, success -> {
if (success == null) return;
if (success) {
viewModel.getAddContactResult().observe(this, result -> {
if (result == null) return;
if (result.hasError()) {
int stringRes;
if (result
.getException() instanceof UnsupportedVersionException) {
stringRes = R.string.unsupported_link;
} else {
stringRes = R.string.adding_contact_error;
}
Toast.makeText(getContext(), stringRes, LENGTH_LONG).show();
} else {
Intent intent = new Intent(getActivity(),
PendingContactListActivity.class);
startActivity(intent);
} else {
Toast.makeText(getContext(), R.string.adding_contact_error,
LENGTH_LONG).show();
}
finish();
});

View File

@@ -0,0 +1,39 @@
package org.briarproject.briar.android.viewmodel;
import android.support.annotation.Nullable;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
@NotNullByDefault
public class LiveResult<T> {
@Nullable
private T result;
@Nullable
private Exception exception;
public LiveResult(T result) {
this.result = result;
this.exception = null;
}
public LiveResult(Exception exception) {
this.result = null;
this.exception = exception;
}
@Nullable
public T getResultOrNull() {
return result;
}
@Nullable
public Exception getException() {
return exception;
}
public boolean hasError() {
return exception != null;
}
}

View File

@@ -202,6 +202,7 @@
<string name="own_link_error">Enter your contact\'s link, not your own</string>
<string name="nickname_missing">Please enter a nickname</string>
<string name="invalid_link">Invalid link</string>
<string name="unsupported_link">This link comes from a newer version of Briar. Please upgrade to the latest version and try again.</string>
<string name="intent_own_link">You opened your own link. Use the one of the contact you want to add!</string>
<string name="missing_link">Please enter a link</string>
<!-- This is a numeral indicating the first step in a series of screens -->