diff --git a/briar-android/res/layout/fragment_blog_post.xml b/briar-android/res/layout/fragment_blog_post.xml index 4f16b3460eeb24ae15c288e577624c53e6426a27..7a0df0d0b5d964b25bd2ef3a6b5c3cd1630f7b3d 100644 --- a/briar-android/res/layout/fragment_blog_post.xml +++ b/briar-android/res/layout/fragment_blog_post.xml @@ -1,78 +1,20 @@ <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" - android:layout_height="wrap_content"> + android:layout_height="match_parent"> - <RelativeLayout - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:padding="@dimen/margin_activity_horizontal"> + <FrameLayout + android:layout_width="wrap_content" + android:layout_height="wrap_content"> - <de.hdodenhof.circleimageview.CircleImageView - android:id="@+id/avatar" - style="@style/BriarAvatar" - android:layout_width="30dp" - android:layout_height="30dp" - android:layout_marginRight="@dimen/margin_medium" - tools:src="@drawable/ic_launcher"/> - - <TextView - android:id="@+id/authorName" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_alignTop="@+id/avatar" - android:layout_toEndOf="@+id/avatar" - android:layout_toRightOf="@+id/avatar" - android:textColor="@color/briar_text_primary" - android:textSize="@dimen/text_size_tiny" - tools:text="Author Name"/> - - <TextView - android:id="@+id/date" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_alignBottom="@id/avatar" - android:layout_below="@+id/authorName" - android:layout_toEndOf="@+id/avatar" - android:layout_toRightOf="@+id/avatar" - android:gravity="bottom" - android:textColor="@color/briar_text_primary" - android:textSize="@dimen/text_size_tiny" - tools:text="yesterday"/> - - <org.briarproject.android.util.TrustIndicatorView - android:id="@+id/trustIndicator" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_marginLeft="@dimen/margin_small" - android:layout_toRightOf="@+id/authorName" - tools:src="@drawable/trust_indicator_verified"/> - - <TextView - android:id="@+id/title" + <include + android:id="@+id/postLayout" + style="@style/BriarCard" + layout="@layout/list_item_blog_post" android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_alignParentLeft="true" - android:layout_alignParentStart="true" - android:layout_below="@+id/avatar" - android:layout_marginTop="@dimen/margin_medium" - android:textColor="@color/briar_text_primary" - android:textSize="@dimen/text_size_large" - android:textStyle="bold" - tools:text="This Is A Blog Post Title"/> - - <TextView - android:id="@+id/body" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:layout_below="@+id/title" - android:layout_marginTop="@dimen/margin_medium" - android:textColor="@color/briar_text_secondary" - android:textSize="@dimen/text_size_medium" - tools:text="Body of Blog Post. This could be insanely large or just a short text as well."/> + android:layout_height="wrap_content"/> - </RelativeLayout> + </FrameLayout> </ScrollView> diff --git a/briar-android/res/layout/list_item_blog_post.xml b/briar-android/res/layout/list_item_blog_post.xml index 4697c461bf8e22f8fdb1832662d565ab7294309f..8b136f2b7d5682623d1adb7a777895fb5a457b8c 100644 --- a/briar-android/res/layout/list_item_blog_post.xml +++ b/briar-android/res/layout/list_item_blog_post.xml @@ -1,5 +1,6 @@ <?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.CardView + android:id="@+id/postLayout" style="@style/BriarCard" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" diff --git a/briar-android/src/org/briarproject/android/blogs/BlogPostFragment.java b/briar-android/src/org/briarproject/android/blogs/BlogPostFragment.java index 7e0cb1c95a29fd18aba6f72c76dc9b5a0cf82f3b..926ce7f37d951713625081a9b9eecc4ddd4a2bd3 100644 --- a/briar-android/src/org/briarproject/android/blogs/BlogPostFragment.java +++ b/briar-android/src/org/briarproject/android/blogs/BlogPostFragment.java @@ -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); } } diff --git a/briar-android/src/org/briarproject/android/blogs/BlogPostViewHolder.java b/briar-android/src/org/briarproject/android/blogs/BlogPostViewHolder.java index 378b3993b7afe3545e6e5312e7b9527aef6b24b6..9cc23d0797e69049f7c36d80808d9cf15c902d5c 100644 --- a/briar-android/src/org/briarproject/android/blogs/BlogPostViewHolder.java +++ b/briar-android/src/org/briarproject/android/blogs/BlogPostViewHolder.java @@ -46,7 +46,7 @@ class BlogPostViewHolder extends RecyclerView.ViewHolder { super(v); ctx = v.getContext(); - layout = (ViewGroup) v; + layout = (ViewGroup) v.findViewById(R.id.postLayout); reblogger = (AuthorView) v.findViewById(R.id.rebloggerView); author = (AuthorView) v.findViewById(R.id.authorView); reblogButton = (ImageView) v.findViewById(R.id.commentView); @@ -67,6 +67,10 @@ class BlogPostViewHolder extends RecyclerView.ViewHolder { reblogButton.setVisibility(GONE); } + void updateDate(long time) { + author.setDate(time); + } + void setTransitionName(MessageId id) { ViewCompat.setTransitionName(layout, getTransitionName(id)); }