mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 03:09:04 +01:00
Show Blog Posts always in the same design
This also adds comments to the blog post detail screen that were previously missing.
This commit is contained in:
@@ -1,31 +1,23 @@
|
||||
package org.briarproject.android.blogs;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.ActivityComponent;
|
||||
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.MessageId;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import im.delight.android.identicons.IdenticonDrawable;
|
||||
|
||||
import static org.briarproject.android.util.AndroidUtils.MIN_RESOLUTION;
|
||||
|
||||
public class BlogPostFragment extends BaseFragment {
|
||||
@@ -35,6 +27,7 @@ public class BlogPostFragment extends BaseFragment {
|
||||
private static final Logger LOG = Logger.getLogger(TAG);
|
||||
private static final String BLOG_POST_ID = "briar.BLOG_POST_ID";
|
||||
|
||||
private View view;
|
||||
private MessageId postId;
|
||||
private BlogPostViewHolder ui;
|
||||
private BlogPostItem post;
|
||||
@@ -63,10 +56,10 @@ public class BlogPostFragment extends BaseFragment {
|
||||
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,
|
||||
view = inflater.inflate(R.layout.fragment_blog_post, container,
|
||||
false);
|
||||
ui = new BlogPostViewHolder(v);
|
||||
return v;
|
||||
ui = new BlogPostViewHolder(view);
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -84,26 +77,21 @@ public class BlogPostFragment extends BaseFragment {
|
||||
public void onResultUi(BlogPostItem post) {
|
||||
listener.hideLoadingScreen();
|
||||
BlogPostFragment.this.post = post;
|
||||
bind();
|
||||
ui.bindItem(post);
|
||||
startPeriodicUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExceptionUi(DbException exception) {
|
||||
// TODO: Decide how to handle errors in the UI
|
||||
getActivity().finish();
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
startPeriodicUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
stopPeriodicUpdate();
|
||||
}
|
||||
|
||||
@@ -123,56 +111,25 @@ public class BlogPostFragment extends BaseFragment {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
private void bind() {
|
||||
Author author = post.getAuthor();
|
||||
IdenticonDrawable d = new IdenticonDrawable(author.getId().getBytes());
|
||||
ui.avatar.setImageDrawable(d);
|
||||
ui.authorName.setText(author.getName());
|
||||
ui.trust.setTrustLevel(post.getAuthorStatus());
|
||||
Context ctx = getContext();
|
||||
if (ctx != null) {
|
||||
ui.date.setText(AndroidUtils.formatDate(ctx, post.getTimestamp()));
|
||||
}
|
||||
ui.body.setText(post.getBody());
|
||||
}
|
||||
|
||||
private static class BlogPostViewHolder {
|
||||
|
||||
private final ImageView avatar;
|
||||
private final TextView authorName;
|
||||
private final TrustIndicatorView trust;
|
||||
private final TextView date;
|
||||
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);
|
||||
date = (TextView) v.findViewById(R.id.date);
|
||||
body = (TextView) v.findViewById(R.id.body);
|
||||
}
|
||||
}
|
||||
|
||||
private void startPeriodicUpdate() {
|
||||
refresher = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (ui == null || post == null) return;
|
||||
if (ui == null) return;
|
||||
LOG.info("Updating Content...");
|
||||
|
||||
ui.date.setText(AndroidUtils
|
||||
.formatDate(getActivity(), post.getTimestamp()));
|
||||
ui.date.postDelayed(refresher, MIN_RESOLUTION);
|
||||
ui.updateDate(post.getTimestamp());
|
||||
view.postDelayed(refresher, MIN_RESOLUTION);
|
||||
}
|
||||
};
|
||||
LOG.info("Adding Handler Callback");
|
||||
ui.date.postDelayed(refresher, MIN_RESOLUTION);
|
||||
view.postDelayed(refresher, MIN_RESOLUTION);
|
||||
}
|
||||
|
||||
private void stopPeriodicUpdate() {
|
||||
if (refresher != null && ui != null) {
|
||||
LOG.info("Removing Handler Callback");
|
||||
ui.date.removeCallbacks(refresher);
|
||||
view.removeCallbacks(refresher);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user