mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 03:09:04 +01:00
Make BlogController thread-safe. #555
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package org.briarproject.android.blogs;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
@@ -10,16 +9,15 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.ActivityComponent;
|
||||
import org.briarproject.android.controller.handler.UiResultHandler;
|
||||
import org.briarproject.android.controller.handler.UiResultExceptionHandler;
|
||||
import org.briarproject.android.fragment.BaseFragment;
|
||||
import org.briarproject.android.util.AndroidUtils;
|
||||
import org.briarproject.android.util.TrustIndicatorView;
|
||||
import org.briarproject.api.db.DbException;
|
||||
import org.briarproject.api.identity.Author;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
import org.briarproject.util.StringUtils;
|
||||
|
||||
@@ -30,31 +28,27 @@ import javax.inject.Inject;
|
||||
import im.delight.android.identicons.IdenticonDrawable;
|
||||
|
||||
import static android.view.View.GONE;
|
||||
import static android.widget.Toast.LENGTH_SHORT;
|
||||
import static org.briarproject.android.BriarActivity.GROUP_ID;
|
||||
import static org.briarproject.android.util.AndroidUtils.MIN_RESOLUTION;
|
||||
|
||||
public class BlogPostFragment extends BaseFragment {
|
||||
|
||||
public final static String TAG = BlogPostFragment.class.getName();
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(TAG);
|
||||
private static final String BLOG_POST_ID = "briar.BLOG_POST_ID";
|
||||
|
||||
private final static String BLOG_POST_ID = "briar.BLOG_NAME";
|
||||
|
||||
private GroupId groupId;
|
||||
private MessageId postId;
|
||||
private BlogPostViewHolder ui;
|
||||
private BlogPostItem post = null;
|
||||
private Runnable refresher = null;
|
||||
private BlogPostItem post;
|
||||
private Runnable refresher;
|
||||
|
||||
@Inject
|
||||
BlogController blogController;
|
||||
|
||||
static BlogPostFragment newInstance(GroupId groupId, MessageId postId) {
|
||||
static BlogPostFragment newInstance(MessageId postId) {
|
||||
BlogPostFragment f = new BlogPostFragment();
|
||||
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putByteArray(GROUP_ID, groupId.getBytes());
|
||||
bundle.putByteArray(BLOG_POST_ID, postId.getBytes());
|
||||
|
||||
f.setArguments(bundle);
|
||||
@@ -65,15 +59,11 @@ public class BlogPostFragment extends BaseFragment {
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
byte[] b = getArguments().getByteArray(GROUP_ID);
|
||||
if (b == null) throw new IllegalStateException("No Group found.");
|
||||
groupId = new GroupId(b);
|
||||
byte[] p = getArguments().getByteArray(BLOG_POST_ID);
|
||||
if (p == null) throw new IllegalStateException("No MessageId found.");
|
||||
postId = new MessageId(p);
|
||||
byte[] b = getArguments().getByteArray(BLOG_POST_ID);
|
||||
if (b == null) throw new IllegalStateException("No post ID in args");
|
||||
postId = new MessageId(b);
|
||||
|
||||
View v = inflater.inflate(R.layout.fragment_blog_post, container,
|
||||
false);
|
||||
@@ -89,21 +79,20 @@ public class BlogPostFragment extends BaseFragment {
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
blogController.loadBlog(groupId, false,
|
||||
new UiResultHandler<Boolean>((Activity) listener) {
|
||||
blogController.loadBlogPost(postId,
|
||||
new UiResultExceptionHandler<BlogPostItem, DbException>(
|
||||
getActivity()) {
|
||||
@Override
|
||||
public void onResultUi(Boolean result) {
|
||||
public void onResultUi(BlogPostItem post) {
|
||||
listener.hideLoadingScreen();
|
||||
if (result) {
|
||||
post = blogController.getBlogPost(postId);
|
||||
if (post != null) {
|
||||
bind();
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(getActivity(),
|
||||
R.string.blogs_blog_post_failed_to_load,
|
||||
LENGTH_SHORT).show();
|
||||
}
|
||||
BlogPostFragment.this.post = post;
|
||||
bind();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExceptionUi(DbException exception) {
|
||||
// TODO: Decide how to handle errors in the UI
|
||||
getActivity().finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -157,14 +146,15 @@ public class BlogPostFragment extends BaseFragment {
|
||||
}
|
||||
|
||||
private static class BlogPostViewHolder {
|
||||
private ImageView avatar;
|
||||
private TextView authorName;
|
||||
private TrustIndicatorView trust;
|
||||
private TextView date;
|
||||
private TextView title;
|
||||
private TextView body;
|
||||
|
||||
BlogPostViewHolder(View v) {
|
||||
private final ImageView avatar;
|
||||
private final TextView authorName;
|
||||
private final TrustIndicatorView trust;
|
||||
private final TextView date;
|
||||
private final TextView title;
|
||||
private final TextView body;
|
||||
|
||||
private BlogPostViewHolder(View v) {
|
||||
avatar = (ImageView) v.findViewById(R.id.avatar);
|
||||
authorName = (TextView) v.findViewById(R.id.authorName);
|
||||
trust = (TrustIndicatorView) v.findViewById(R.id.trustIndicator);
|
||||
|
||||
Reference in New Issue
Block a user