mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
[android] Add error message for unsupported handshake link version
This commit is contained in:
@@ -8,10 +8,13 @@ import android.support.annotation.NonNull;
|
||||
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.R;
|
||||
import org.briarproject.briar.android.viewmodel.LiveResult;
|
||||
import org.briarproject.briar.android.viewmodel.LiveEvent;
|
||||
import org.briarproject.briar.android.viewmodel.MutableLiveEvent;
|
||||
|
||||
@@ -39,7 +42,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;
|
||||
@@ -97,15 +100,20 @@ 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<>(R.string.unsupported_link));
|
||||
} catch (DbException | FormatException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
addContactResult.postValue(false);
|
||||
addContactResult.postValue(
|
||||
new LiveResult<>(R.string.adding_contact_error));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
LiveData<Boolean> getAddContactResult() {
|
||||
public LiveData<LiveResult<Boolean>> getAddContactResult() {
|
||||
return addContactResult;
|
||||
}
|
||||
|
||||
|
||||
@@ -103,15 +103,15 @@ 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()) {
|
||||
Toast.makeText(getContext(), result.getErrorRes(), 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();
|
||||
});
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package org.briarproject.briar.android.viewmodel;
|
||||
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StringRes;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
@NotNullByDefault
|
||||
public class LiveResult<T> {
|
||||
|
||||
@Nullable
|
||||
private T result;
|
||||
@StringRes
|
||||
private int errorRes;
|
||||
|
||||
public LiveResult(T result) {
|
||||
this.result = result;
|
||||
this.errorRes = 0;
|
||||
}
|
||||
|
||||
public LiveResult(@StringRes int errorRes) {
|
||||
this.result = null;
|
||||
this.errorRes = errorRes;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public T getResultOrNull() {
|
||||
return result;
|
||||
}
|
||||
|
||||
@StringRes
|
||||
public int getErrorRes() {
|
||||
return errorRes;
|
||||
}
|
||||
|
||||
public boolean hasError() {
|
||||
return errorRes != 0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -200,6 +200,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 is not supported. Please upgrade Briar 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 -->
|
||||
|
||||
Reference in New Issue
Block a user