mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-11 18:29:05 +01:00
Merge branch '636-blogpostfragment-should-use-the-same-layout-as-the-blog-feed' into 'master'
Show Blog Posts always in the same design This also adds comments to the blog post detail screen that were previously missing. It re-uses the existing `BlogPostViewHolder` and its `bind()` methods effectively reducing the amount of code necessary. Closes #636 See merge request !307
This commit is contained in:
@@ -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"
|
||||
<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_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"/>
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<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"
|
||||
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."/>
|
||||
|
||||
</RelativeLayout>
|
||||
</FrameLayout>
|
||||
|
||||
</ScrollView>
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user