mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-11 18:29:05 +01:00
Show Personal Blog When Clicking On Post in Combined Blog Feed
Closes #415
This commit is contained in:
@@ -9,10 +9,4 @@
|
||||
android:title="@string/blogs_write_blog_post"
|
||||
app:showAsAction="ifRoom"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/action_delete_blog"
|
||||
android:icon="@drawable/action_delete_white"
|
||||
android:title="@string/blogs_delete_blog"
|
||||
app:showAsAction="never"/>
|
||||
|
||||
</menu>
|
||||
@@ -278,6 +278,7 @@
|
||||
<string name="blogs_blog_failed_to_load">Blog failed to load</string>
|
||||
<string name="blogs_blog_post_failed_to_load">Blog Post failed to load</string>
|
||||
<string name="blogs_feed_empty_state">This is the global blog feed.\n\nIt looks like nobody blogged anything, yet.\n\nBe the first and tap the pen icon to write a new blog post.</string>
|
||||
<string name="blogs_personal_blog">%s\'s Personal Blog</string>
|
||||
<string name="blogs_delete_blog">Delete Blog</string>
|
||||
<string name="blogs_delete_blog_dialog_message">Are you sure that you want to delete this Blog and all posts?\nNote that this will not delete the blog from other people\'s devices.</string>
|
||||
<string name="blogs_delete_blog_ok">Delete Blog</string>
|
||||
|
||||
@@ -126,7 +126,7 @@ public class BlogActivity extends BriarActivity implements BlogPostListener,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlogPostClick(final int position) {
|
||||
public void onBlogPostClick(int position, BlogPostItem post) {
|
||||
loadBlogPosts(position, true);
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ public class BlogControllerImpl extends DbControllerImpl
|
||||
@Override
|
||||
public void eventOccurred(Event e) {
|
||||
if (e instanceof BlogPostAddedEvent) {
|
||||
final BlogPostAddedEvent m = (BlogPostAddedEvent) e;
|
||||
BlogPostAddedEvent m = (BlogPostAddedEvent) e;
|
||||
if (m.getGroupId().equals(groupId)) {
|
||||
LOG.info("New blog post added");
|
||||
if (posts == null) {
|
||||
@@ -89,8 +89,8 @@ public class BlogControllerImpl extends DbControllerImpl
|
||||
final BlogPostHeader header = m.getHeader();
|
||||
// FIXME: Don't make blocking calls in event handlers
|
||||
try {
|
||||
final byte[] body = blogManager.getPostBody(header.getId());
|
||||
final BlogPostItem post = new BlogPostItem(header, body);
|
||||
byte[] body = blogManager.getPostBody(header.getId());
|
||||
BlogPostItem post = new BlogPostItem(groupId, header, body);
|
||||
posts.add(post);
|
||||
listener.onBlogPostAdded(post, m.isLocal());
|
||||
} catch (DbException ex) {
|
||||
@@ -130,7 +130,7 @@ public class BlogControllerImpl extends DbControllerImpl
|
||||
blogManager.getPostHeaders(g);
|
||||
for (BlogPostHeader h : header) {
|
||||
byte[] body = blogManager.getPostBody(h.getId());
|
||||
newPosts.add(new BlogPostItem(h, body));
|
||||
newPosts.add(new BlogPostItem(g, h, body));
|
||||
}
|
||||
posts.addAll(newPosts);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
|
||||
@@ -146,9 +146,6 @@ public class BlogFragment extends BaseFragment implements BlogPostListener {
|
||||
ActivityCompat.startActivityForResult(getActivity(), i,
|
||||
REQUEST_WRITE_POST, options.toBundle());
|
||||
return true;
|
||||
case R.id.action_delete_blog:
|
||||
showDeleteDialog();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ class BlogPostAdapter extends
|
||||
ui.layout.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
listener.onBlogPostClick(ui.getAdapterPosition());
|
||||
listener.onBlogPostClick(ui.getAdapterPosition(), post);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -160,7 +160,7 @@ class BlogPostAdapter extends
|
||||
}
|
||||
|
||||
interface OnBlogPostClickListener {
|
||||
void onBlogPostClick(int position);
|
||||
void onBlogPostClick(int position, BlogPostItem post);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,16 +5,19 @@ import android.support.annotation.NonNull;
|
||||
import org.briarproject.api.blogs.BlogPostHeader;
|
||||
import org.briarproject.api.identity.Author;
|
||||
import org.briarproject.api.identity.Author.Status;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
|
||||
// This class is not thread-safe
|
||||
class BlogPostItem implements Comparable<BlogPostItem> {
|
||||
|
||||
private final GroupId groupId;
|
||||
private final BlogPostHeader header;
|
||||
private final byte[] body;
|
||||
private boolean read;
|
||||
|
||||
BlogPostItem(BlogPostHeader header, byte[] body) {
|
||||
BlogPostItem(GroupId groupId, BlogPostHeader header, byte[] body) {
|
||||
this.groupId = groupId;
|
||||
this.header = header;
|
||||
this.body = body;
|
||||
read = header.isRead();
|
||||
@@ -24,6 +27,10 @@ class BlogPostItem implements Comparable<BlogPostItem> {
|
||||
return header.getId();
|
||||
}
|
||||
|
||||
public GroupId getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return header.getTitle();
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.briarproject.api.event.EventBus;
|
||||
import org.briarproject.api.event.EventListener;
|
||||
import org.briarproject.api.identity.Author;
|
||||
import org.briarproject.api.identity.IdentityManager;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -57,16 +58,9 @@ public class FeedControllerImpl extends DbControllerImpl
|
||||
|
||||
LOG.info("New blog post added");
|
||||
if (listener != null) {
|
||||
final BlogPostAddedEvent m = (BlogPostAddedEvent) e;
|
||||
final BlogPostHeader header = m.getHeader();
|
||||
try {
|
||||
final byte[] body = blogManager.getPostBody(header.getId());
|
||||
final BlogPostItem post = new BlogPostItem(header, body);
|
||||
listener.onBlogPostAdded(post);
|
||||
} catch (DbException ex) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, ex.toString(), ex);
|
||||
}
|
||||
BlogPostAddedEvent m = (BlogPostAddedEvent) e;
|
||||
BlogPostHeader header = m.getHeader();
|
||||
addPost(m.getGroupId(), header);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +81,7 @@ public class FeedControllerImpl extends DbControllerImpl
|
||||
blogManager.getPostHeaders(b.getId());
|
||||
for (BlogPostHeader h : header) {
|
||||
byte[] body = blogManager.getPostBody(h.getId());
|
||||
posts.add(new BlogPostItem(h, body));
|
||||
posts.add(new BlogPostItem(b.getId(), h, body));
|
||||
}
|
||||
}
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
@@ -132,4 +126,21 @@ public class FeedControllerImpl extends DbControllerImpl
|
||||
public void setOnBlogPostAddedListener(OnBlogPostAddedListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
private void addPost(final GroupId groupId, final BlogPostHeader header) {
|
||||
runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
byte[] body = blogManager.getPostBody(header.getId());
|
||||
BlogPostItem post = new BlogPostItem(groupId, header, body);
|
||||
listener.onBlogPostAdded(post);
|
||||
} catch (DbException ex) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, ex.toString(), ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import static android.support.design.widget.Snackbar.LENGTH_LONG;
|
||||
import static android.support.v4.app.ActivityOptionsCompat.makeCustomAnimation;
|
||||
import static org.briarproject.android.BriarActivity.GROUP_ID;
|
||||
import static org.briarproject.android.blogs.BlogActivity.BLOG_NAME;
|
||||
import static org.briarproject.android.blogs.BlogActivity.IS_MY_BLOG;
|
||||
import static org.briarproject.android.blogs.BlogActivity.REQUEST_WRITE_POST;
|
||||
|
||||
public class FeedFragment extends BaseFragment implements
|
||||
@@ -168,8 +169,22 @@ public class FeedFragment extends BaseFragment implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlogPostClick(int position) {
|
||||
// noop
|
||||
public void onBlogPostClick(int position, BlogPostItem post) {
|
||||
byte[] groupId = post.getGroupId().getBytes();
|
||||
String name = getString(R.string.blogs_personal_blog,
|
||||
post.getAuthor().getName());
|
||||
boolean myBlog = personalBlog != null &&
|
||||
personalBlog.getId().equals(post.getGroupId());
|
||||
|
||||
Intent i = new Intent(getActivity(), BlogActivity.class);
|
||||
i.putExtra(GROUP_ID, groupId);
|
||||
i.putExtra(BLOG_NAME, name);
|
||||
i.putExtra(IS_MY_BLOG, myBlog);
|
||||
ActivityOptionsCompat options =
|
||||
makeCustomAnimation(getActivity(),
|
||||
android.R.anim.slide_in_left,
|
||||
android.R.anim.slide_out_right);
|
||||
startActivity(i, options.toBundle());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user