mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-19 14:19:53 +01:00
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:
@@ -7,11 +7,13 @@ import android.arch.lifecycle.MutableLiveData;
|
|||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.FormatException;
|
import org.briarproject.bramble.api.FormatException;
|
||||||
|
import org.briarproject.bramble.api.UnsupportedVersionException;
|
||||||
import org.briarproject.bramble.api.contact.ContactManager;
|
import org.briarproject.bramble.api.contact.ContactManager;
|
||||||
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.briar.android.viewmodel.LiveEvent;
|
import org.briarproject.briar.android.viewmodel.LiveEvent;
|
||||||
|
import org.briarproject.briar.android.viewmodel.LiveResult;
|
||||||
import org.briarproject.briar.android.viewmodel.MutableLiveEvent;
|
import org.briarproject.briar.android.viewmodel.MutableLiveEvent;
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
@@ -38,7 +40,7 @@ public class AddContactViewModel extends AndroidViewModel {
|
|||||||
new MutableLiveData<>();
|
new MutableLiveData<>();
|
||||||
private final MutableLiveEvent<Boolean> remoteLinkEntered =
|
private final MutableLiveEvent<Boolean> remoteLinkEntered =
|
||||||
new MutableLiveEvent<>();
|
new MutableLiveEvent<>();
|
||||||
private final MutableLiveData<Boolean> addContactResult =
|
private final MutableLiveData<LiveResult<Boolean>> addContactResult =
|
||||||
new MutableLiveData<>();
|
new MutableLiveData<>();
|
||||||
@Nullable
|
@Nullable
|
||||||
private String remoteHandshakeLink;
|
private String remoteHandshakeLink;
|
||||||
@@ -96,15 +98,18 @@ public class AddContactViewModel extends AndroidViewModel {
|
|||||||
dbExecutor.execute(() -> {
|
dbExecutor.execute(() -> {
|
||||||
try {
|
try {
|
||||||
contactManager.addPendingContact(remoteHandshakeLink, nickname);
|
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) {
|
} catch (DbException | FormatException e) {
|
||||||
logException(LOG, WARNING, e);
|
logException(LOG, WARNING, e);
|
||||||
addContactResult.postValue(false);
|
addContactResult.postValue(new LiveResult<>(e));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
LiveData<Boolean> getAddContactResult() {
|
public LiveData<LiveResult<Boolean>> getAddContactResult() {
|
||||||
return addContactResult;
|
return addContactResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ public class LinkExchangeFragment extends BaseFragment {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
linkInputLayout.setError(null);
|
linkInputLayout.setError(null);
|
||||||
return linkWithoutSchema;
|
return link.toString();
|
||||||
}
|
}
|
||||||
linkInputLayout.setError(getString(R.string.invalid_link));
|
linkInputLayout.setError(getString(R.string.invalid_link));
|
||||||
linkInput.requestFocus();
|
linkInput.requestFocus();
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import android.widget.Button;
|
|||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.UnsupportedVersionException;
|
||||||
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;
|
||||||
@@ -103,15 +104,21 @@ public class NicknameFragment extends BaseFragment {
|
|||||||
addButton.setVisibility(INVISIBLE);
|
addButton.setVisibility(INVISIBLE);
|
||||||
progressBar.setVisibility(VISIBLE);
|
progressBar.setVisibility(VISIBLE);
|
||||||
|
|
||||||
viewModel.getAddContactResult().observe(this, success -> {
|
viewModel.getAddContactResult().observe(this, result -> {
|
||||||
if (success == null) return;
|
if (result == null) return;
|
||||||
if (success) {
|
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(),
|
Intent intent = new Intent(getActivity(),
|
||||||
PendingContactListActivity.class);
|
PendingContactListActivity.class);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
} else {
|
|
||||||
Toast.makeText(getContext(), R.string.adding_contact_error,
|
|
||||||
LENGTH_LONG).show();
|
|
||||||
}
|
}
|
||||||
finish();
|
finish();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -202,6 +202,7 @@
|
|||||||
<string name="own_link_error">Enter your contact\'s link, not your own</string>
|
<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="nickname_missing">Please enter a nickname</string>
|
||||||
<string name="invalid_link">Invalid link</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="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>
|
<string name="missing_link">Please enter a link</string>
|
||||||
<!-- This is a numeral indicating the first step in a series of screens -->
|
<!-- This is a numeral indicating the first step in a series of screens -->
|
||||||
|
|||||||
Reference in New Issue
Block a user