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