mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-19 14:19:53 +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"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<ScrollView
|
<ScrollView
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<RelativeLayout
|
<FrameLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content">
|
||||||
android:padding="@dimen/margin_activity_horizontal">
|
|
||||||
|
|
||||||
<de.hdodenhof.circleimageview.CircleImageView
|
<include
|
||||||
android:id="@+id/avatar"
|
android:id="@+id/postLayout"
|
||||||
style="@style/BriarAvatar"
|
style="@style/BriarCard"
|
||||||
android:layout_width="30dp"
|
layout="@layout/list_item_blog_post"
|
||||||
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_width="wrap_content"
|
||||||
android:layout_height="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
|
</FrameLayout>
|
||||||
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>
|
|
||||||
|
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<android.support.v7.widget.CardView
|
<android.support.v7.widget.CardView
|
||||||
|
android:id="@+id/postLayout"
|
||||||
style="@style/BriarCard"
|
style="@style/BriarCard"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
|||||||
@@ -1,31 +1,23 @@
|
|||||||
package org.briarproject.android.blogs;
|
package org.briarproject.android.blogs;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import org.briarproject.R;
|
import org.briarproject.R;
|
||||||
import org.briarproject.android.ActivityComponent;
|
import org.briarproject.android.ActivityComponent;
|
||||||
import org.briarproject.android.controller.handler.UiResultExceptionHandler;
|
import org.briarproject.android.controller.handler.UiResultExceptionHandler;
|
||||||
import org.briarproject.android.fragment.BaseFragment;
|
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.db.DbException;
|
||||||
import org.briarproject.api.identity.Author;
|
|
||||||
import org.briarproject.api.sync.MessageId;
|
import org.briarproject.api.sync.MessageId;
|
||||||
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import im.delight.android.identicons.IdenticonDrawable;
|
|
||||||
|
|
||||||
import static org.briarproject.android.util.AndroidUtils.MIN_RESOLUTION;
|
import static org.briarproject.android.util.AndroidUtils.MIN_RESOLUTION;
|
||||||
|
|
||||||
public class BlogPostFragment extends BaseFragment {
|
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 Logger LOG = Logger.getLogger(TAG);
|
||||||
private static final String BLOG_POST_ID = "briar.BLOG_POST_ID";
|
private static final String BLOG_POST_ID = "briar.BLOG_POST_ID";
|
||||||
|
|
||||||
|
private View view;
|
||||||
private MessageId postId;
|
private MessageId postId;
|
||||||
private BlogPostViewHolder ui;
|
private BlogPostViewHolder ui;
|
||||||
private BlogPostItem post;
|
private BlogPostItem post;
|
||||||
@@ -63,10 +56,10 @@ public class BlogPostFragment extends BaseFragment {
|
|||||||
if (b == null) throw new IllegalStateException("No post ID in args");
|
if (b == null) throw new IllegalStateException("No post ID in args");
|
||||||
postId = new MessageId(b);
|
postId = new MessageId(b);
|
||||||
|
|
||||||
View v = inflater.inflate(R.layout.fragment_blog_post, container,
|
view = inflater.inflate(R.layout.fragment_blog_post, container,
|
||||||
false);
|
false);
|
||||||
ui = new BlogPostViewHolder(v);
|
ui = new BlogPostViewHolder(view);
|
||||||
return v;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -84,26 +77,21 @@ public class BlogPostFragment extends BaseFragment {
|
|||||||
public void onResultUi(BlogPostItem post) {
|
public void onResultUi(BlogPostItem post) {
|
||||||
listener.hideLoadingScreen();
|
listener.hideLoadingScreen();
|
||||||
BlogPostFragment.this.post = post;
|
BlogPostFragment.this.post = post;
|
||||||
bind();
|
ui.bindItem(post);
|
||||||
|
startPeriodicUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onExceptionUi(DbException exception) {
|
public void onExceptionUi(DbException exception) {
|
||||||
// TODO: Decide how to handle errors in the UI
|
// TODO: Decide how to handle errors in the UI
|
||||||
getActivity().finish();
|
finish();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onStop() {
|
||||||
super.onResume();
|
super.onStop();
|
||||||
startPeriodicUpdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPause() {
|
|
||||||
super.onPause();
|
|
||||||
stopPeriodicUpdate();
|
stopPeriodicUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,56 +111,25 @@ public class BlogPostFragment extends BaseFragment {
|
|||||||
return TAG;
|
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() {
|
private void startPeriodicUpdate() {
|
||||||
refresher = new Runnable() {
|
refresher = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (ui == null || post == null) return;
|
if (ui == null) return;
|
||||||
LOG.info("Updating Content...");
|
LOG.info("Updating Content...");
|
||||||
|
|
||||||
ui.date.setText(AndroidUtils
|
ui.updateDate(post.getTimestamp());
|
||||||
.formatDate(getActivity(), post.getTimestamp()));
|
view.postDelayed(refresher, MIN_RESOLUTION);
|
||||||
ui.date.postDelayed(refresher, MIN_RESOLUTION);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
LOG.info("Adding Handler Callback");
|
LOG.info("Adding Handler Callback");
|
||||||
ui.date.postDelayed(refresher, MIN_RESOLUTION);
|
view.postDelayed(refresher, MIN_RESOLUTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void stopPeriodicUpdate() {
|
private void stopPeriodicUpdate() {
|
||||||
if (refresher != null && ui != null) {
|
if (refresher != null && ui != null) {
|
||||||
LOG.info("Removing Handler Callback");
|
LOG.info("Removing Handler Callback");
|
||||||
ui.date.removeCallbacks(refresher);
|
view.removeCallbacks(refresher);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ class BlogPostViewHolder extends RecyclerView.ViewHolder {
|
|||||||
super(v);
|
super(v);
|
||||||
|
|
||||||
ctx = v.getContext();
|
ctx = v.getContext();
|
||||||
layout = (ViewGroup) v;
|
layout = (ViewGroup) v.findViewById(R.id.postLayout);
|
||||||
reblogger = (AuthorView) v.findViewById(R.id.rebloggerView);
|
reblogger = (AuthorView) v.findViewById(R.id.rebloggerView);
|
||||||
author = (AuthorView) v.findViewById(R.id.authorView);
|
author = (AuthorView) v.findViewById(R.id.authorView);
|
||||||
reblogButton = (ImageView) v.findViewById(R.id.commentView);
|
reblogButton = (ImageView) v.findViewById(R.id.commentView);
|
||||||
@@ -67,6 +67,10 @@ class BlogPostViewHolder extends RecyclerView.ViewHolder {
|
|||||||
reblogButton.setVisibility(GONE);
|
reblogButton.setVisibility(GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void updateDate(long time) {
|
||||||
|
author.setDate(time);
|
||||||
|
}
|
||||||
|
|
||||||
void setTransitionName(MessageId id) {
|
void setTransitionName(MessageId id) {
|
||||||
ViewCompat.setTransitionName(layout, getTransitionName(id));
|
ViewCompat.setTransitionName(layout, getTransitionName(id));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user