mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 03:39:05 +01:00
Added @UiThread annotations, minor code cleanups.
This commit is contained in:
@@ -13,8 +13,10 @@ import java.util.Collection;
|
||||
|
||||
public interface BaseController {
|
||||
|
||||
@UiThread
|
||||
void onStart();
|
||||
|
||||
@UiThread
|
||||
void onStop();
|
||||
|
||||
void loadBlogPosts(GroupId g,
|
||||
|
||||
@@ -67,11 +67,11 @@ public class BlogActivity extends BriarActivity implements
|
||||
groupId = new GroupId(b);
|
||||
blogController.setGroupId(groupId);
|
||||
|
||||
// Name of the Blog from Intent
|
||||
// Name of the blog
|
||||
blogName = i.getStringExtra(BLOG_NAME);
|
||||
if (blogName != null) setTitle(blogName);
|
||||
|
||||
// Is this our blog and was it just created?
|
||||
// Was this blog just created?
|
||||
isNew = i.getBooleanExtra(IS_NEW_BLOG, false);
|
||||
|
||||
setContentView(R.layout.activity_blog);
|
||||
|
||||
@@ -13,13 +13,16 @@ import java.util.List;
|
||||
@UiThread
|
||||
class BlogCommentItem extends BlogPostItem {
|
||||
|
||||
private static final BlogCommentComparator COMPARATOR =
|
||||
new BlogCommentComparator();
|
||||
|
||||
private final BlogPostHeader postHeader;
|
||||
private final List<BlogCommentHeader> comments = new ArrayList<>();
|
||||
|
||||
BlogCommentItem(BlogCommentHeader header) {
|
||||
super(header, null);
|
||||
postHeader = collectComments(header);
|
||||
Collections.sort(comments, new BlogCommentComparator());
|
||||
Collections.sort(comments, COMPARATOR);
|
||||
}
|
||||
|
||||
private BlogPostHeader collectComments(BlogPostHeader header) {
|
||||
@@ -54,10 +57,9 @@ class BlogCommentItem extends BlogPostItem {
|
||||
private static class BlogCommentComparator
|
||||
implements Comparator<BlogCommentHeader> {
|
||||
@Override
|
||||
public int compare(org.briarproject.api.blogs.BlogCommentHeader h1,
|
||||
org.briarproject.api.blogs.BlogCommentHeader h2) {
|
||||
public int compare(BlogCommentHeader h1, BlogCommentHeader h2) {
|
||||
// re-use same comparator used for blog posts, but reverse it
|
||||
return BlogCommentItem.compare(h2, h1);
|
||||
return BlogPostItem.compare(h2, h1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,20 +38,20 @@ public class BlogControllerImpl extends BaseControllerImpl
|
||||
} else {
|
||||
throw new IllegalStateException(
|
||||
"An activity that injects the BlogController must " +
|
||||
"implement the BlogPostListener");
|
||||
"implement the OnBlogPostAddedListener");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResume() {
|
||||
super.onStart();
|
||||
super.onStart(); // TODO: Should be called when activity starts. #609
|
||||
notificationManager.blockNotification(groupId);
|
||||
notificationManager.clearBlogPostNotification(groupId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityPause() {
|
||||
super.onStop();
|
||||
super.onStop(); // TODO: Should be called when activity stops. #609
|
||||
notificationManager.unblockNotification(groupId);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.briarproject.android.blogs;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.UiThread;
|
||||
|
||||
import org.briarproject.api.blogs.BlogPostHeader;
|
||||
import org.briarproject.api.identity.Author;
|
||||
@@ -9,7 +10,7 @@ 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
|
||||
@UiThread
|
||||
class BlogPostItem implements Comparable<BlogPostItem> {
|
||||
|
||||
private final BlogPostHeader header;
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.briarproject.android.blogs;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.support.annotation.UiThread;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.app.ActivityOptionsCompat;
|
||||
import android.support.v4.view.ViewCompat;
|
||||
@@ -28,11 +29,10 @@ import static org.briarproject.android.BriarActivity.GROUP_ID;
|
||||
import static org.briarproject.android.blogs.BlogActivity.POST_ID;
|
||||
import static org.briarproject.api.blogs.MessageType.POST;
|
||||
|
||||
public class BlogPostViewHolder extends RecyclerView.ViewHolder {
|
||||
@UiThread
|
||||
class BlogPostViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private final Context ctx;
|
||||
private OnBlogPostClickListener listener;
|
||||
|
||||
private final ViewGroup layout;
|
||||
private final AuthorView reblogger;
|
||||
private final AuthorView author;
|
||||
@@ -40,6 +40,8 @@ public class BlogPostViewHolder extends RecyclerView.ViewHolder {
|
||||
private final TextView body;
|
||||
private final ViewGroup commentContainer;
|
||||
|
||||
private OnBlogPostClickListener listener;
|
||||
|
||||
BlogPostViewHolder(View v) {
|
||||
super(v);
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.briarproject.android.blogs;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.transition.Fade;
|
||||
import android.transition.Transition;
|
||||
@@ -14,8 +15,6 @@ import org.briarproject.android.fragment.BaseFragment.BaseFragmentListener;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
|
||||
import static android.os.Build.VERSION.SDK_INT;
|
||||
import static android.os.Build.VERSION_CODES.LOLLIPOP;
|
||||
import static org.briarproject.android.blogs.BlogActivity.POST_ID;
|
||||
|
||||
public class ReblogActivity extends BriarActivity implements
|
||||
@@ -25,7 +24,7 @@ public class ReblogActivity extends BriarActivity implements
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (SDK_INT >= LOLLIPOP) {
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
setTransition();
|
||||
}
|
||||
|
||||
@@ -80,7 +79,7 @@ public class ReblogActivity extends BriarActivity implements
|
||||
|
||||
}
|
||||
|
||||
@TargetApi(LOLLIPOP)
|
||||
@TargetApi(21)
|
||||
private void setTransition() {
|
||||
Transition fade = new Fade();
|
||||
fade.excludeTarget(android.R.id.statusBarBackground, true);
|
||||
|
||||
@@ -33,7 +33,6 @@ public class ReblogFragment extends BaseFragment {
|
||||
|
||||
public static final String TAG = ReblogFragment.class.getName();
|
||||
|
||||
|
||||
private BaseFragmentListener listener;
|
||||
private ViewHolder ui;
|
||||
private GroupId blogId;
|
||||
@@ -104,6 +103,7 @@ public class ReblogFragment extends BaseFragment {
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
|
||||
// TODO: Load blog post when fragment is created. #631
|
||||
feedController.loadBlogPost(blogId, postId,
|
||||
new UiResultExceptionHandler<BlogPostItem, DbException>(
|
||||
getActivity()) {
|
||||
@@ -112,6 +112,7 @@ public class ReblogFragment extends BaseFragment {
|
||||
item = result;
|
||||
bindViewHolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExceptionUi(DbException exception) {
|
||||
// TODO
|
||||
@@ -123,6 +124,8 @@ public class ReblogFragment extends BaseFragment {
|
||||
private void bindViewHolder() {
|
||||
if (item == null) return;
|
||||
|
||||
hideProgressBar();
|
||||
|
||||
ui.post.bindItem(item);
|
||||
ui.post.hideReblogButton();
|
||||
|
||||
@@ -134,7 +137,6 @@ public class ReblogFragment extends BaseFragment {
|
||||
}
|
||||
});
|
||||
ui.publish.setEnabled(true);
|
||||
hideProgressBar();
|
||||
ui.scrollView.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -151,6 +153,7 @@ public class ReblogFragment extends BaseFragment {
|
||||
public void onResultUi(Void result) {
|
||||
// do nothing, this fragment is gone already
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExceptionUi(DbException exception) {
|
||||
// do nothing, this fragment is gone already
|
||||
@@ -177,6 +180,7 @@ public class ReblogFragment extends BaseFragment {
|
||||
}
|
||||
|
||||
private static class ViewHolder {
|
||||
|
||||
private final ScrollView scrollView;
|
||||
private final ProgressBar progressBar;
|
||||
private final BlogPostViewHolder post;
|
||||
|
||||
Reference in New Issue
Block a user