mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
Merge branch '610-result-handlers-can-return-results-to-destroyed-activities-fragments' into '637-effect-of-touching-a-post-is-inconsistent'
Check if activity is still alive before returning results to it Closes #610 See merge request !312
This commit is contained in:
@@ -2,7 +2,7 @@ package org.briarproject.android;
|
||||
|
||||
import android.support.annotation.UiThread;
|
||||
|
||||
interface Destroyable {
|
||||
public interface Destroyable {
|
||||
|
||||
@UiThread
|
||||
boolean hasBeenDestroyed();
|
||||
|
||||
@@ -209,7 +209,7 @@ public class BlogFragment extends BaseFragment implements
|
||||
public void onBlogPostAdded(BlogPostHeader header, final boolean local) {
|
||||
blogController.loadBlogPost(header,
|
||||
new UiResultExceptionHandler<BlogPostItem, DbException>(
|
||||
getActivity()) {
|
||||
listener) {
|
||||
@Override
|
||||
public void onResultUi(BlogPostItem post) {
|
||||
adapter.add(post);
|
||||
@@ -233,7 +233,7 @@ public class BlogFragment extends BaseFragment implements
|
||||
void loadBlogPosts(final boolean reload) {
|
||||
blogController.loadBlogPosts(
|
||||
new UiResultExceptionHandler<Collection<BlogPostItem>, DbException>(
|
||||
getActivity()) {
|
||||
listener) {
|
||||
@Override
|
||||
public void onResultUi(Collection<BlogPostItem> posts) {
|
||||
if (posts.size() > 0) {
|
||||
@@ -254,8 +254,7 @@ public class BlogFragment extends BaseFragment implements
|
||||
|
||||
private void loadBlog() {
|
||||
blogController.loadBlog(
|
||||
new UiResultExceptionHandler<BlogItem, DbException>(
|
||||
getActivity()) {
|
||||
new UiResultExceptionHandler<BlogItem, DbException>(listener) {
|
||||
@Override
|
||||
public void onResultUi(BlogItem blog) {
|
||||
setToolbarTitle(blog.getBlog().getAuthor());
|
||||
@@ -333,7 +332,7 @@ public class BlogFragment extends BaseFragment implements
|
||||
|
||||
private void deleteBlog() {
|
||||
blogController.deleteBlog(
|
||||
new UiResultExceptionHandler<Void, DbException>(getActivity()) {
|
||||
new UiResultExceptionHandler<Void, DbException>(listener) {
|
||||
@Override
|
||||
public void onResultUi(Void result) {
|
||||
Toast.makeText(getActivity(),
|
||||
|
||||
@@ -62,7 +62,7 @@ public class BlogPostFragment extends BasePostFragment {
|
||||
super.onStart();
|
||||
blogController.loadBlogPost(postId,
|
||||
new UiResultExceptionHandler<BlogPostItem, DbException>(
|
||||
getActivity()) {
|
||||
listener) {
|
||||
@Override
|
||||
public void onResultUi(BlogPostItem post) {
|
||||
onBlogPostLoaded(post);
|
||||
|
||||
@@ -45,7 +45,7 @@ public class BlogPostPagerFragment extends BasePostPagerFragment {
|
||||
void loadBlogPosts(final MessageId select) {
|
||||
blogController.loadBlogPosts(
|
||||
new UiResultExceptionHandler<Collection<BlogPostItem>, DbException>(
|
||||
getActivity()) {
|
||||
listener) {
|
||||
@Override
|
||||
public void onResultUi(Collection<BlogPostItem> posts) {
|
||||
onBlogPostsLoaded(select, posts);
|
||||
@@ -61,7 +61,7 @@ public class BlogPostPagerFragment extends BasePostPagerFragment {
|
||||
void loadBlogPost(BlogPostHeader header) {
|
||||
blogController.loadBlogPost(header,
|
||||
new UiResultExceptionHandler<BlogPostItem, DbException>(
|
||||
getActivity()) {
|
||||
listener) {
|
||||
@Override
|
||||
public void onResultUi(BlogPostItem post) {
|
||||
addPost(post);
|
||||
|
||||
@@ -108,7 +108,7 @@ public class FeedFragment extends BaseFragment implements
|
||||
});
|
||||
feedController.loadBlogPosts(
|
||||
new UiResultExceptionHandler<Collection<BlogPostItem>, DbException>(
|
||||
getActivity()) {
|
||||
listener) {
|
||||
@Override
|
||||
public void onResultUi(Collection<BlogPostItem> posts) {
|
||||
if (posts.isEmpty()) {
|
||||
@@ -175,7 +175,7 @@ public class FeedFragment extends BaseFragment implements
|
||||
public void onBlogPostAdded(BlogPostHeader header, final boolean local) {
|
||||
feedController.loadBlogPost(header,
|
||||
new UiResultExceptionHandler<BlogPostItem, DbException>(
|
||||
getActivity()) {
|
||||
listener) {
|
||||
@Override
|
||||
public void onResultUi(BlogPostItem post) {
|
||||
adapter.add(post);
|
||||
|
||||
@@ -65,7 +65,7 @@ public class FeedPostFragment extends BasePostFragment {
|
||||
super.onStart();
|
||||
feedController.loadBlogPost(blogId, postId,
|
||||
new UiResultExceptionHandler<BlogPostItem, DbException>(
|
||||
getActivity()) {
|
||||
listener) {
|
||||
@Override
|
||||
public void onResultUi(BlogPostItem post) {
|
||||
onBlogPostLoaded(post);
|
||||
|
||||
@@ -44,7 +44,7 @@ public class FeedPostPagerFragment extends BasePostPagerFragment {
|
||||
void loadBlogPosts(final MessageId select) {
|
||||
feedController.loadBlogPosts(
|
||||
new UiResultExceptionHandler<Collection<BlogPostItem>, DbException>(
|
||||
getActivity()) {
|
||||
listener) {
|
||||
@Override
|
||||
public void onResultUi(Collection<BlogPostItem> posts) {
|
||||
onBlogPostsLoaded(select, posts);
|
||||
@@ -60,7 +60,7 @@ public class FeedPostPagerFragment extends BasePostPagerFragment {
|
||||
void loadBlogPost(BlogPostHeader header) {
|
||||
feedController.loadBlogPost(header,
|
||||
new UiResultExceptionHandler<BlogPostItem, DbException>(
|
||||
getActivity()) {
|
||||
listener) {
|
||||
@Override
|
||||
public void onResultUi(BlogPostItem post) {
|
||||
addPost(post);
|
||||
|
||||
@@ -106,7 +106,7 @@ public class ReblogFragment extends BaseFragment {
|
||||
// TODO: Load blog post when fragment is created. #631
|
||||
feedController.loadBlogPost(blogId, postId,
|
||||
new UiResultExceptionHandler<BlogPostItem, DbException>(
|
||||
getActivity()) {
|
||||
listener) {
|
||||
@Override
|
||||
public void onResultUi(BlogPostItem result) {
|
||||
item = result;
|
||||
@@ -148,7 +148,7 @@ public class ReblogFragment extends BaseFragment {
|
||||
private void send() {
|
||||
String comment = getComment();
|
||||
feedController.repeatPost(item, comment,
|
||||
new UiResultExceptionHandler<Void, DbException>(getActivity()) {
|
||||
new UiResultExceptionHandler<Void, DbException>(listener) {
|
||||
@Override
|
||||
public void onResultUi(Void result) {
|
||||
// do nothing, this fragment is gone already
|
||||
|
||||
@@ -1,33 +1,36 @@
|
||||
package org.briarproject.android.controller.handler;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.support.annotation.UiThread;
|
||||
|
||||
import org.briarproject.android.fragment.BaseFragment.BaseFragmentListener;
|
||||
|
||||
public abstract class UiResultExceptionHandler<R, E extends Exception>
|
||||
implements ResultExceptionHandler<R, E> {
|
||||
|
||||
private final Activity activity;
|
||||
private final BaseFragmentListener listener;
|
||||
|
||||
public UiResultExceptionHandler(Activity activity) {
|
||||
this.activity = activity;
|
||||
protected UiResultExceptionHandler(BaseFragmentListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResult(final R result) {
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
listener.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
onResultUi(result);
|
||||
if (!listener.hasBeenDestroyed())
|
||||
onResultUi(result);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onException(final E exception) {
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
listener.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
onExceptionUi(exception);
|
||||
if (!listener.hasBeenDestroyed())
|
||||
onExceptionUi(exception);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,22 +1,24 @@
|
||||
package org.briarproject.android.controller.handler;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.support.annotation.UiThread;
|
||||
|
||||
import org.briarproject.android.fragment.BaseFragment.BaseFragmentListener;
|
||||
|
||||
public abstract class UiResultHandler<R> implements ResultHandler<R> {
|
||||
|
||||
private final Activity activity;
|
||||
private final BaseFragmentListener listener;
|
||||
|
||||
public UiResultHandler(Activity activity) {
|
||||
this.activity = activity;
|
||||
protected UiResultHandler(BaseFragmentListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResult(final R result) {
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
listener.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
onResultUi(result);
|
||||
if (!listener.hasBeenDestroyed())
|
||||
onResultUi(result);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.support.annotation.UiThread;
|
||||
import android.support.v4.app.Fragment;
|
||||
|
||||
import org.briarproject.android.ActivityComponent;
|
||||
import org.briarproject.android.Destroyable;
|
||||
|
||||
public abstract class BaseFragment extends Fragment {
|
||||
|
||||
@@ -45,7 +46,7 @@ public abstract class BaseFragment extends Fragment {
|
||||
getActivity().supportFinishAfterTransition();
|
||||
}
|
||||
|
||||
public interface BaseFragmentListener {
|
||||
public interface BaseFragmentListener extends Destroyable {
|
||||
|
||||
@UiThread
|
||||
void showLoadingScreen(boolean isBlocking, int stringId);
|
||||
|
||||
Reference in New Issue
Block a user