mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
Merge branch '1973-make-use-of-handle-exception' into 'master'
Make more use of DbViewModel#handleException() Closes #1973 See merge request briar/briar!1427
This commit is contained in:
4
.idea/inspectionProfiles/Project_Default.xml
generated
4
.idea/inspectionProfiles/Project_Default.xml
generated
@@ -1,6 +1,10 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="MissingOverrideAnnotation" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="ignoreObjectMethods" value="true" />
|
||||
<option name="ignoreAnonymousClassMethods" value="false" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="WeakerAccess" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="SUGGEST_PACKAGE_LOCAL_FOR_MEMBERS" value="true" />
|
||||
<option name="SUGGEST_PACKAGE_LOCAL_FOR_TOP_CLASSES" value="true" />
|
||||
|
||||
@@ -57,6 +57,7 @@ public class Author implements Nameable {
|
||||
/**
|
||||
* Returns the author's name.
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -146,10 +146,12 @@ abstract class PowerView extends ConstraintLayout {
|
||||
|
||||
static final Parcelable.Creator<SavedState> CREATOR
|
||||
= new Parcelable.Creator<SavedState>() {
|
||||
@Override
|
||||
public SavedState createFromParcel(Parcel in) {
|
||||
return new SavedState(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SavedState[] newArray(int size) {
|
||||
return new SavedState[size];
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ public class UnlockActivity extends BaseActivity {
|
||||
component.inject(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle state) {
|
||||
super.onCreate(state);
|
||||
overridePendingTransition(0, 0);
|
||||
|
||||
@@ -19,23 +19,15 @@ import org.briarproject.briar.api.conversation.ConversationManager;
|
||||
import org.briarproject.briar.api.identity.AuthorManager;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||
|
||||
@NotNullByDefault
|
||||
class ContactListViewModel extends ContactsViewModel {
|
||||
|
||||
private static final Logger LOG =
|
||||
getLogger(ContactListViewModel.class.getName());
|
||||
|
||||
private final AndroidNotificationManager notificationManager;
|
||||
|
||||
private final MutableLiveData<Boolean> hasPendingContacts =
|
||||
@@ -76,7 +68,7 @@ class ContactListViewModel extends ContactsViewModel {
|
||||
!contactManager.getPendingContacts().isEmpty();
|
||||
hasPendingContacts.postValue(hasPending);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
handleException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -86,6 +86,7 @@ import static org.briarproject.briar.android.contact.add.nearby.AddNearbyContact
|
||||
import static org.briarproject.briar.android.contact.add.nearby.AddNearbyContactViewModel.BluetoothDecision.NO_ADAPTER;
|
||||
import static org.briarproject.briar.android.contact.add.nearby.AddNearbyContactViewModel.BluetoothDecision.REFUSED;
|
||||
import static org.briarproject.briar.android.contact.add.nearby.AddNearbyContactViewModel.BluetoothDecision.UNKNOWN;
|
||||
import static org.briarproject.briar.android.util.UiUtils.handleException;
|
||||
|
||||
@NotNullByDefault
|
||||
class AddNearbyContactViewModel extends AndroidViewModel
|
||||
@@ -485,7 +486,7 @@ class AddNearbyContactViewModel extends AndroidViewModel
|
||||
conn.getReader().dispose(true, true);
|
||||
conn.getWriter().dispose(true);
|
||||
} catch (IOException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
handleException(getApplication(), androidExecutor, LOG, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ public class AddContactViewModel extends DbViewModel {
|
||||
try {
|
||||
handshakeLink.postValue(contactManager.getHandshakeLink());
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
handleException(e);
|
||||
// the UI should stay disabled in this case,
|
||||
// leaving the user unable to proceed
|
||||
}
|
||||
|
||||
@@ -26,25 +26,18 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.bramble.api.contact.PendingContactState.OFFLINE;
|
||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||
|
||||
@NotNullByDefault
|
||||
public class PendingContactListViewModel extends DbViewModel
|
||||
implements EventListener {
|
||||
|
||||
private final Logger LOG =
|
||||
getLogger(PendingContactListViewModel.class.getName());
|
||||
|
||||
private final ContactManager contactManager;
|
||||
private final RendezvousPoller rendezvousPoller;
|
||||
private final EventBus eventBus;
|
||||
@@ -106,7 +99,7 @@ public class PendingContactListViewModel extends DbViewModel
|
||||
pendingContacts.postValue(items);
|
||||
hasInternetConnection.postValue(online);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
handleException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -120,7 +113,7 @@ public class PendingContactListViewModel extends DbViewModel
|
||||
try {
|
||||
contactManager.removePendingContact(id);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
handleException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -237,7 +237,7 @@ public class ConversationViewModel extends DbViewModel
|
||||
} catch (NoSuchContactException e) {
|
||||
contactDeleted.postValue(true);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
handleException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -249,7 +249,7 @@ public class ConversationViewModel extends DbViewModel
|
||||
conversationManager.setReadFlag(g, m, true);
|
||||
logDuration(LOG, "Marking read", start);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
handleException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -261,7 +261,7 @@ public class ConversationViewModel extends DbViewModel
|
||||
alias.isEmpty() ? null : alias);
|
||||
loadContact(contactId);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
handleException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -402,7 +402,7 @@ public class ConversationViewModel extends DbViewModel
|
||||
autoDeleteManager.setAutoDeleteTimer(txn, c, timer));
|
||||
autoDeleteTimer.postValue(timer);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
handleException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -453,7 +453,7 @@ public class ConversationViewModel extends DbViewModel
|
||||
try {
|
||||
checkFeaturesAndOnboarding(contactId);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
handleException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -40,10 +40,8 @@ import androidx.annotation.UiThread;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.bramble.util.LogUtils.logDuration;
|
||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||
import static org.briarproject.bramble.util.LogUtils.now;
|
||||
import static org.briarproject.briar.api.forum.ForumManager.CLIENT_ID;
|
||||
|
||||
@@ -126,7 +124,7 @@ class ForumListViewModel extends DbViewModel implements EventListener {
|
||||
}
|
||||
}
|
||||
|
||||
public void loadForums() {
|
||||
void loadForums() {
|
||||
loadFromDb(this::loadForums, forumItems::setValue);
|
||||
}
|
||||
|
||||
@@ -169,7 +167,7 @@ class ForumListViewModel extends DbViewModel implements EventListener {
|
||||
logDuration(LOG, "Loading available", start);
|
||||
numInvitations.postValue(available);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
handleException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -50,10 +50,8 @@ import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import static android.widget.Toast.LENGTH_SHORT;
|
||||
import static java.lang.Math.max;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.bramble.util.LogUtils.logDuration;
|
||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||
import static org.briarproject.bramble.util.LogUtils.now;
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@@ -116,6 +114,7 @@ class ForumViewModel extends ThreadListViewModel<ForumPostItem> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void clearNotifications() {
|
||||
notificationManager.clearForumPostNotification(groupId);
|
||||
}
|
||||
@@ -127,7 +126,7 @@ class ForumViewModel extends ThreadListViewModel<ForumPostItem> {
|
||||
Forum f = forumManager.getForum(groupId);
|
||||
forum.postValue(f);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
handleException(e);
|
||||
}
|
||||
});
|
||||
return forum;
|
||||
@@ -167,7 +166,7 @@ class ForumViewModel extends ThreadListViewModel<ForumPostItem> {
|
||||
clock.currentTimeMillis());
|
||||
createMessage(text, timestamp, parentId, author);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
handleException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -191,7 +190,7 @@ class ForumViewModel extends ThreadListViewModel<ForumPostItem> {
|
||||
ForumPostItem item = new ForumPostItem(header, text);
|
||||
addItem(item, true);
|
||||
});
|
||||
}, e -> logException(LOG, WARNING, e));
|
||||
}, this::handleException);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -200,11 +199,12 @@ class ForumViewModel extends ThreadListViewModel<ForumPostItem> {
|
||||
try {
|
||||
forumManager.setReadFlag(groupId, item.getId(), true);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
handleException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadSharingContacts() {
|
||||
runOnDbThread(true, txn -> {
|
||||
Collection<Contact> contacts =
|
||||
@@ -212,7 +212,7 @@ class ForumViewModel extends ThreadListViewModel<ForumPostItem> {
|
||||
Collection<ContactId> contactIds = new ArrayList<>(contacts.size());
|
||||
for (Contact c : contacts) contactIds.add(c.getId());
|
||||
txn.attach(() -> sharingController.addAll(contactIds));
|
||||
}, e -> logException(LOG, WARNING, e));
|
||||
}, this::handleException);
|
||||
}
|
||||
|
||||
void deleteForum() {
|
||||
@@ -220,12 +220,13 @@ class ForumViewModel extends ThreadListViewModel<ForumPostItem> {
|
||||
try {
|
||||
Forum f = forumManager.getForum(groupId);
|
||||
forumManager.removeForum(f);
|
||||
androidExecutor.runOnUiThread(() -> Toast
|
||||
.makeText(getApplication(), R.string.forum_left_toast,
|
||||
LENGTH_SHORT).show());
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
handleException(e);
|
||||
}
|
||||
});
|
||||
Toast.makeText(getApplication(), R.string.forum_left_toast,
|
||||
LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@ class IntroductionViewModel extends ContactsViewModel {
|
||||
introductionInfo.postValue(
|
||||
new IntroductionInfo(c1, c2, possible));
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
handleException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ public class NavDrawerViewModel extends DbViewModel {
|
||||
}
|
||||
}
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
handleException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -109,7 +109,7 @@ public class NavDrawerViewModel extends DbViewModel {
|
||||
settings.putInt(EXPIRY_DATE_WARNING, date);
|
||||
settingsManager.mergeSettings(settings, SETTINGS_NAMESPACE);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
handleException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -156,7 +156,7 @@ public class NavDrawerViewModel extends DbViewModel {
|
||||
settings.getBoolean(SHOW_TRANSPORTS_ONBOARDING, true);
|
||||
showTransportsOnboarding.postValue(show);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
handleException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -170,7 +170,7 @@ public class NavDrawerViewModel extends DbViewModel {
|
||||
settings.putBoolean(SHOW_TRANSPORTS_ONBOARDING, false);
|
||||
settingsManager.mergeSettings(settings, SETTINGS_NAMESPACE);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
handleException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -45,12 +45,10 @@ import static android.bluetooth.BluetoothAdapter.ACTION_STATE_CHANGED;
|
||||
import static android.bluetooth.BluetoothAdapter.EXTRA_STATE;
|
||||
import static android.bluetooth.BluetoothAdapter.STATE_ON;
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.bramble.api.plugin.Plugin.PREF_PLUGIN_ENABLE;
|
||||
import static org.briarproject.bramble.api.plugin.Plugin.State.STARTING_STOPPING;
|
||||
import static org.briarproject.bramble.util.LogUtils.logDuration;
|
||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||
import static org.briarproject.bramble.util.LogUtils.now;
|
||||
|
||||
@NotNullByDefault
|
||||
@@ -197,7 +195,7 @@ public class PluginViewModel extends DbViewModel implements EventListener {
|
||||
BluetoothConstants.DEFAULT_PREF_PLUGIN_ENABLE);
|
||||
btEnabledSetting.postValue(bt);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
handleException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -228,7 +226,7 @@ public class PluginViewModel extends DbViewModel implements EventListener {
|
||||
settingsManager.mergeSettings(s, namespace);
|
||||
logDuration(LOG, "Merging settings", start);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
handleException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -51,10 +51,8 @@ import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import static java.lang.Math.max;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.bramble.util.LogUtils.logDuration;
|
||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||
import static org.briarproject.bramble.util.LogUtils.now;
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@@ -140,6 +138,7 @@ class GroupViewModel extends ThreadListViewModel<GroupMessageItem> {
|
||||
loadPrivateGroup(groupId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void clearNotifications() {
|
||||
notificationManager.clearGroupMessageNotification(groupId);
|
||||
}
|
||||
@@ -152,7 +151,7 @@ class GroupViewModel extends ThreadListViewModel<GroupMessageItem> {
|
||||
Author author = identityManager.getLocalAuthor();
|
||||
isCreator.postValue(g.getCreator().equals(author));
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
handleException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -210,7 +209,7 @@ class GroupViewModel extends ThreadListViewModel<GroupMessageItem> {
|
||||
timestamp = max(clock.currentTimeMillis(), timestamp + 1);
|
||||
createMessage(text, timestamp, parentId, author, previousMsgId);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
handleException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -235,7 +234,7 @@ class GroupViewModel extends ThreadListViewModel<GroupMessageItem> {
|
||||
txn.attach(() ->
|
||||
addItem(buildItem(header, text), true)
|
||||
);
|
||||
}, e -> logException(LOG, WARNING, e));
|
||||
}, this::handleException);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -244,11 +243,12 @@ class GroupViewModel extends ThreadListViewModel<GroupMessageItem> {
|
||||
try {
|
||||
privateGroupManager.setReadFlag(groupId, item.getId(), true);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
handleException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadSharingContacts() {
|
||||
runOnDbThread(true, txn -> {
|
||||
Collection<GroupMember> members =
|
||||
@@ -259,7 +259,7 @@ class GroupViewModel extends ThreadListViewModel<GroupMessageItem> {
|
||||
contactIds.add(m.getContactId());
|
||||
}
|
||||
txn.attach(() -> sharingController.addAll(contactIds));
|
||||
}, e -> logException(LOG, WARNING, e));
|
||||
}, this::handleException);
|
||||
}
|
||||
|
||||
void deletePrivateGroup() {
|
||||
@@ -267,7 +267,7 @@ class GroupViewModel extends ThreadListViewModel<GroupMessageItem> {
|
||||
try {
|
||||
privateGroupManager.removePrivateGroup(groupId);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
handleException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -48,10 +48,8 @@ import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.bramble.util.LogUtils.logDuration;
|
||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||
import static org.briarproject.bramble.util.LogUtils.now;
|
||||
import static org.briarproject.briar.api.privategroup.PrivateGroupManager.CLIENT_ID;
|
||||
|
||||
@@ -202,7 +200,7 @@ class GroupListViewModel extends DbViewModel implements EventListener {
|
||||
groupManager.removePrivateGroup(g);
|
||||
logDuration(LOG, "Removing group", start);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
handleException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -213,7 +211,7 @@ class GroupListViewModel extends DbViewModel implements EventListener {
|
||||
int i = groupInvitationManager.getInvitations().size();
|
||||
numInvitations.postValue(i);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
handleException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ class SettingsViewModel extends DbViewModel implements EventListener {
|
||||
settingsManager.getSettings(TOR_NAMESPACE));
|
||||
logDuration(LOG, "Loading settings", start);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
handleException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -169,7 +169,7 @@ class SettingsViewModel extends DbViewModel implements EventListener {
|
||||
ownIdentityInfo.postValue(
|
||||
new OwnIdentityInfo(localAuthor, authorInfo));
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
handleException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -41,9 +41,7 @@ import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@ParametersNotNullByDefault
|
||||
@@ -160,7 +158,7 @@ public abstract class ThreadListViewModel<I extends ThreadItem>
|
||||
storedMessageId);
|
||||
}
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
handleException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -223,7 +221,7 @@ public abstract class ThreadListViewModel<I extends ThreadItem>
|
||||
try {
|
||||
messageTracker.storeMessageId(groupId, messageId);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
handleException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.android.material.textfield.TextInputLayout;
|
||||
|
||||
@@ -32,12 +33,16 @@ import org.briarproject.bramble.api.contact.Contact;
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||
import org.briarproject.bramble.api.system.AndroidExecutor;
|
||||
import org.briarproject.bramble.util.StringUtils;
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.android.reporting.FeedbackActivity;
|
||||
import org.briarproject.briar.android.view.ArticleMovementMethod;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import androidx.annotation.AnyThread;
|
||||
import androidx.annotation.AttrRes;
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.annotation.ColorRes;
|
||||
@@ -84,6 +89,7 @@ import static android.view.KeyEvent.ACTION_DOWN;
|
||||
import static android.view.KeyEvent.KEYCODE_ENTER;
|
||||
import static android.view.inputmethod.EditorInfo.IME_NULL;
|
||||
import static android.view.inputmethod.InputMethodManager.SHOW_IMPLICIT;
|
||||
import static android.widget.Toast.LENGTH_LONG;
|
||||
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_TIME;
|
||||
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM;
|
||||
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO;
|
||||
@@ -95,7 +101,9 @@ import static androidx.core.graphics.drawable.DrawableCompat.setTint;
|
||||
import static androidx.core.view.ViewCompat.LAYOUT_DIRECTION_RTL;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
import static java.util.concurrent.TimeUnit.DAYS;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static org.briarproject.bramble.util.AndroidUtils.getSupportedImageContentTypes;
|
||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||
import static org.briarproject.briar.BuildConfig.APPLICATION_ID;
|
||||
import static org.briarproject.briar.android.TestingConstants.EXPIRY_DATE;
|
||||
import static org.briarproject.briar.android.reporting.CrashReportActivity.EXTRA_APP_LOGCAT;
|
||||
@@ -472,4 +480,26 @@ public class UiUtils {
|
||||
setTint(requireNonNull(icon), getColor(ctx, R.color.color_primary));
|
||||
return icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs the exception and shows a Toast to the user.
|
||||
* <p>
|
||||
* Errors that are likely or expected to happen should not use this method
|
||||
* and show proper error states in UI.
|
||||
*/
|
||||
@AnyThread
|
||||
public static void handleException(Context context,
|
||||
AndroidExecutor androidExecutor, Logger logger, Exception e) {
|
||||
logException(logger, WARNING, e);
|
||||
androidExecutor.runOnUiThread(() -> {
|
||||
String msg = "Error: " + e.getClass().getSimpleName();
|
||||
if (!StringUtils.isNullOrEmpty(e.getMessage())) {
|
||||
msg += " " + e.getMessage();
|
||||
}
|
||||
if (e.getCause() != null) {
|
||||
msg += " caused by " + e.getCause().getClass().getSimpleName();
|
||||
}
|
||||
Toast.makeText(context, msg, LENGTH_LONG).show();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.briarproject.briar.android.viewmodel;
|
||||
|
||||
import android.app.Application;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||
import org.briarproject.bramble.api.db.DbCallable;
|
||||
@@ -12,7 +11,7 @@ import org.briarproject.bramble.api.db.TransactionManager;
|
||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.system.AndroidExecutor;
|
||||
import org.briarproject.bramble.util.StringUtils;
|
||||
import org.briarproject.briar.android.util.UiUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -34,7 +33,6 @@ import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import static android.widget.Toast.LENGTH_LONG;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||
@@ -262,17 +260,7 @@ public abstract class DbViewModel extends AndroidViewModel {
|
||||
*/
|
||||
@AnyThread
|
||||
protected void handleException(Exception e) {
|
||||
logException(LOG, WARNING, e);
|
||||
androidExecutor.runOnUiThread(() -> {
|
||||
String msg = "Error: " + e.getClass().getSimpleName();
|
||||
if (!StringUtils.isNullOrEmpty(e.getMessage())) {
|
||||
msg += " " + e.getMessage();
|
||||
}
|
||||
if (e.getCause() != null) {
|
||||
msg += " caused by " + e.getCause().getClass().getSimpleName();
|
||||
}
|
||||
Toast.makeText(getApplication(), msg, LENGTH_LONG).show();
|
||||
});
|
||||
UiUtils.handleException(getApplication(), androidExecutor, LOG, e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -84,6 +84,7 @@ class IntroducerSession extends Session<IntroducerState> {
|
||||
this(sessionId, groupId, author, -1, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SessionId getSessionId() {
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user