Refactor handleDbException to handleException

This commit is contained in:
Torsten Grote
2021-01-04 15:39:02 -03:00
parent f882e46b33
commit 6409a3b179
21 changed files with 59 additions and 51 deletions

View File

@@ -6,7 +6,6 @@ import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
import org.briarproject.briar.R;
@@ -240,7 +239,7 @@ public abstract class BaseActivity extends AppCompatActivity
}
@UiThread
public void handleDbException(DbException e) {
public void handleException(Exception e) {
supportFinishAfterTransition();
}

View File

@@ -232,7 +232,7 @@ public class BlogFragment extends BaseFragment
@Override
public void onExceptionUi(DbException exception) {
handleDbException(exception);
handleException(exception);
}
}
);
@@ -277,7 +277,7 @@ public class BlogFragment extends BaseFragment
@Override
public void onExceptionUi(DbException exception) {
handleDbException(exception);
handleException(exception);
}
});
}
@@ -296,7 +296,7 @@ public class BlogFragment extends BaseFragment
@Override
public void onExceptionUi(DbException exception) {
handleDbException(exception);
handleException(exception);
}
});
}
@@ -318,7 +318,7 @@ public class BlogFragment extends BaseFragment
@Override
public void onExceptionUi(DbException exception) {
handleDbException(exception);
handleException(exception);
}
});
}
@@ -398,7 +398,7 @@ public class BlogFragment extends BaseFragment
@Override
public void onExceptionUi(DbException exception) {
handleDbException(exception);
handleException(exception);
}
});
}

View File

@@ -58,7 +58,7 @@ public class BlogPostFragment extends BasePostFragment implements BlogListener {
@Override
public void onExceptionUi(DbException exception) {
handleDbException(exception);
handleException(exception);
}
});
}

View File

@@ -156,7 +156,7 @@ public class FeedFragment extends BaseFragment implements
@Override
public void onExceptionUi(DbException exception) {
handleDbException(exception);
handleException(exception);
}
});
}
@@ -187,7 +187,7 @@ public class FeedFragment extends BaseFragment implements
@Override
public void onExceptionUi(DbException exception) {
handleDbException(exception);
handleException(exception);
}
});
}
@@ -242,7 +242,7 @@ public class FeedFragment extends BaseFragment implements
@Override
public void onExceptionUi(DbException exception) {
handleDbException(exception);
handleException(exception);
}
}
);

View File

@@ -79,7 +79,7 @@ public class FeedPostFragment extends BasePostFragment {
@Override
public void onExceptionUi(DbException exception) {
handleDbException(exception);
handleException(exception);
}
});
}

View File

@@ -101,7 +101,7 @@ public class ReblogFragment extends BaseFragment implements SendListener {
@Override
public void onExceptionUi(DbException exception) {
handleDbException(exception);
handleException(exception);
}
});
@@ -128,7 +128,7 @@ public class ReblogFragment extends BaseFragment implements SendListener {
new UiExceptionHandler<DbException>(this) {
@Override
public void onExceptionUi(DbException exception) {
handleDbException(exception);
handleException(exception);
}
});
finish();

View File

@@ -133,7 +133,7 @@ public abstract class BaseContactSelectorFragment<I extends SelectableContactIte
@Override
public void onExceptionUi(DbException exception) {
handleDbException(exception);
handleException(exception);
}
});
}

View File

@@ -156,7 +156,7 @@ public class ForumActivity extends
@Override
public void onExceptionUi(DbException exception) {
handleDbException(exception);
handleException(exception);
}
});
}

View File

@@ -5,7 +5,6 @@ import android.content.Context;
import android.os.Bundle;
import android.view.MenuItem;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
import org.briarproject.briar.android.DestroyableContext;
@@ -77,7 +76,7 @@ public abstract class BaseFragment extends Fragment
void showNextFragment(BaseFragment f);
@UiThread
void handleDbException(DbException e);
void handleException(Exception e);
}
@CallSuper
@@ -100,8 +99,8 @@ public abstract class BaseFragment extends Fragment
}
@UiThread
protected void handleDbException(DbException e) {
listener.handleDbException(e);
protected void handleException(Exception e) {
listener.handleException(e);
}
}

View File

@@ -17,7 +17,6 @@ import android.widget.TextView;
import com.google.android.material.navigation.NavigationView;
import com.google.android.material.navigation.NavigationView.OnNavigationItemSelectedListener;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
@@ -365,7 +364,7 @@ public class NavDrawerActivity extends BriarActivity implements
}
@Override
public void handleDbException(DbException e) {
public void handleException(Exception e) {
// Do nothing for now
}

View File

@@ -106,7 +106,7 @@ public class GroupActivity extends
@Override
public void onExceptionUi(DbException exception) {
handleDbException(exception);
handleException(exception);
}
});
}
@@ -125,7 +125,7 @@ public class GroupActivity extends
@Override
public void onExceptionUi(DbException exception) {
handleDbException(exception);
handleException(exception);
}
});
}
@@ -264,7 +264,7 @@ public class GroupActivity extends
// GroupRemovedEvent being fired
@Override
public void onExceptionUi(DbException exception) {
handleDbException(exception);
handleException(exception);
}
});
}

View File

@@ -51,7 +51,7 @@ public class CreateGroupActivity extends BriarActivity
@Override
public void onExceptionUi(DbException exception) {
handleDbException(exception);
handleException(exception);
}
});
}

View File

@@ -69,7 +69,7 @@ public class GroupInviteActivity extends ContactSelectorActivity
@Override
public void onExceptionUi(DbException exception) {
setResult(RESULT_CANCELED);
handleDbException(exception);
handleException(exception);
}
});
}

View File

@@ -12,7 +12,6 @@ import android.view.ViewGroup;
import com.google.android.material.snackbar.Snackbar;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
import org.briarproject.briar.R;
@@ -24,8 +23,6 @@ import org.briarproject.briar.android.privategroup.list.GroupViewHolder.OnGroupR
import org.briarproject.briar.android.util.BriarSnackbarBuilder;
import org.briarproject.briar.android.view.BriarRecyclerView;
import java.util.List;
import javax.annotation.Nullable;
import javax.inject.Inject;
@@ -78,15 +75,12 @@ public class GroupListFragment extends BaseFragment implements
list.setEmptyAction(R.string.groups_list_empty_action);
list.setLayoutManager(new LinearLayoutManager(getContext()));
list.setAdapter(adapter);
viewModel.getGroupItems().observe(getViewLifecycleOwner(), result -> {
List<GroupItem> items = result.getResultOrNull();
if (items == null && result.getException() instanceof DbException) {
handleDbException((DbException) result.getException());
} else {
adapter.submitList(items);
if (requireNonNull(items).size() == 0) list.showData();
}
});
viewModel.getGroupItems().observe(getViewLifecycleOwner(), result ->
result.onError(this::handleException).onSuccess(items -> {
adapter.submitList(items);
if (requireNonNull(items).size() == 0) list.showData();
})
);
Snackbar snackbar = new BriarSnackbarBuilder()
.setAction(R.string.show, this)

View File

@@ -124,7 +124,7 @@ public class GroupMemberListActivity extends BriarActivity
@Override
public void onExceptionUi(DbException exception) {
handleDbException(exception);
handleException(exception);
}
});
}

View File

@@ -80,7 +80,7 @@ public class RevealContactsActivity extends ContactSelectorActivity
@Override
public void onExceptionUi(DbException exception) {
handleDbException(exception);
handleException(exception);
}
});
}
@@ -120,7 +120,7 @@ public class RevealContactsActivity extends ContactSelectorActivity
new UiExceptionHandler<DbException>(this) {
@Override
public void onExceptionUi(DbException exception) {
handleDbException(exception);
handleException(exception);
}
});
}
@@ -137,7 +137,7 @@ public class RevealContactsActivity extends ContactSelectorActivity
new UiExceptionHandler<DbException>(this) {
@Override
public void onExceptionUi(DbException exception) {
handleDbException(exception);
handleException(exception);
}
});
supportFinishAfterTransition();

View File

@@ -98,7 +98,7 @@ public abstract class InvitationActivity<I extends InvitationItem>
@Override
public void onExceptionUi(DbException exception) {
handleDbException(exception);
handleException(exception);
}
});
}
@@ -110,7 +110,7 @@ public abstract class InvitationActivity<I extends InvitationItem>
new UiExceptionHandler<DbException>(this) {
@Override
public void onExceptionUi(DbException exception) {
handleDbException(exception);
handleException(exception);
}
});
}

View File

@@ -59,7 +59,7 @@ public class ShareBlogActivity extends ShareActivity {
Toast.makeText(ShareBlogActivity.this,
R.string.blogs_sharing_error, LENGTH_SHORT)
.show();
handleDbException(exception);
handleException(exception);
}
});

View File

@@ -59,7 +59,7 @@ public class ShareForumActivity extends ShareActivity {
Toast.makeText(ShareForumActivity.this,
R.string.forum_share_error, LENGTH_SHORT)
.show();
handleDbException(exception);
handleException(exception);
}
});
}

View File

@@ -152,7 +152,7 @@ public abstract class ThreadListActivity<G extends NamedGroup, I extends ThreadI
@Override
public void onExceptionUi(DbException exception) {
handleDbException(exception);
handleException(exception);
}
});
}
@@ -183,7 +183,7 @@ public abstract class ThreadListActivity<G extends NamedGroup, I extends ThreadI
@Override
public void onExceptionUi(DbException exception) {
handleDbException(exception);
handleException(exception);
}
});
}
@@ -214,7 +214,7 @@ public abstract class ThreadListActivity<G extends NamedGroup, I extends ThreadI
@Override
public void onExceptionUi(DbException exception) {
handleDbException(exception);
handleException(exception);
}
});
}
@@ -351,7 +351,7 @@ public abstract class ThreadListActivity<G extends NamedGroup, I extends ThreadI
@Override
public void onExceptionUi(DbException exception) {
handleDbException(exception);
handleException(exception);
}
};
getController().createAndStoreMessage(text, replyItem, handler);

View File

@@ -3,6 +3,7 @@ package org.briarproject.briar.android.viewmodel;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import androidx.annotation.Nullable;
import androidx.core.util.Consumer;
@NotNullByDefault
public class LiveResult<T> {
@@ -36,4 +37,20 @@ public class LiveResult<T> {
return exception != null;
}
/**
* Runs the given function, if {@link #hasError()} is true.
*/
public LiveResult<T> onError(Consumer<Exception> fun) {
if (exception != null) fun.accept(exception);
return this;
}
/**
* Runs the given function, if {@link #hasError()} is false.
*/
public LiveResult<T> onSuccess(Consumer<T> fun) {
if (result != null) fun.accept(result);
return this;
}
}