mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-18 05:39:53 +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 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.R;
|
||||||
|
import org.briarproject.briar.android.viewmodel.LiveResult;
|
||||||
import org.briarproject.briar.android.viewmodel.LiveEvent;
|
import org.briarproject.briar.android.viewmodel.LiveEvent;
|
||||||
import org.briarproject.briar.android.viewmodel.MutableLiveEvent;
|
import org.briarproject.briar.android.viewmodel.MutableLiveEvent;
|
||||||
|
|
||||||
@@ -39,7 +42,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;
|
||||||
@@ -97,15 +100,20 @@ 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<>(R.string.unsupported_link));
|
||||||
} catch (DbException | FormatException e) {
|
} catch (DbException | FormatException e) {
|
||||||
logException(LOG, WARNING, 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;
|
return addContactResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -103,15 +103,15 @@ 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()) {
|
||||||
|
Toast.makeText(getContext(), result.getErrorRes(), 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,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="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 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="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