mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-11 18:29:05 +01:00
Added @UiThread annotations, minor code cleanups.
This commit is contained in:
28
.idea/codeStyleSettings.xml
generated
28
.idea/codeStyleSettings.xml
generated
@@ -37,6 +37,34 @@
|
||||
<JavaCodeStyleSettings>
|
||||
<option name="ANNOTATION_PARAMETER_WRAP" value="1" />
|
||||
</JavaCodeStyleSettings>
|
||||
<Objective-C-extensions>
|
||||
<option name="GENERATE_INSTANCE_VARIABLES_FOR_PROPERTIES" value="ASK" />
|
||||
<option name="RELEASE_STYLE" value="IVAR" />
|
||||
<option name="TYPE_QUALIFIERS_PLACEMENT" value="BEFORE" />
|
||||
<file>
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Import" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Macro" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Typedef" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Enum" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Constant" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Global" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Struct" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="FunctionPredecl" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Function" />
|
||||
</file>
|
||||
<class>
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Property" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Synthesize" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InitMethod" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="StaticMethod" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InstanceMethod" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="DeallocMethod" />
|
||||
</class>
|
||||
<extensions>
|
||||
<pair source="cpp" header="h" />
|
||||
<pair source="c" header="h" />
|
||||
</extensions>
|
||||
</Objective-C-extensions>
|
||||
<XML>
|
||||
<option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" />
|
||||
</XML>
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.briarproject.android.fragment;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.UiThread;
|
||||
import android.support.v4.app.Fragment;
|
||||
|
||||
import org.briarproject.android.ActivityComponent;
|
||||
@@ -39,22 +40,27 @@ public abstract class BaseFragment extends Fragment {
|
||||
listener.onFragmentCreated(getUniqueTag());
|
||||
}
|
||||
|
||||
@UiThread
|
||||
protected void finish() {
|
||||
getActivity().supportFinishAfterTransition();
|
||||
}
|
||||
|
||||
public interface BaseFragmentListener {
|
||||
|
||||
@UiThread
|
||||
void showLoadingScreen(boolean isBlocking, int stringId);
|
||||
|
||||
@UiThread
|
||||
void hideLoadingScreen();
|
||||
|
||||
void runOnUiThread(Runnable runnable);
|
||||
|
||||
void runOnDbThread(Runnable runnable);
|
||||
|
||||
@UiThread
|
||||
ActivityComponent getActivityComponent();
|
||||
|
||||
@UiThread
|
||||
void onFragmentCreated(String tag);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package org.briarproject.android.util;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Typeface;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.ActivityOptionsCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
@@ -25,6 +24,8 @@ import org.briarproject.api.sync.GroupId;
|
||||
import de.hdodenhof.circleimageview.CircleImageView;
|
||||
import im.delight.android.identicons.IdenticonDrawable;
|
||||
|
||||
import static android.content.Context.LAYOUT_INFLATER_SERVICE;
|
||||
import static android.graphics.Typeface.BOLD;
|
||||
import static android.support.v4.app.ActivityOptionsCompat.makeCustomAnimation;
|
||||
import static android.util.TypedValue.COMPLEX_UNIT_PX;
|
||||
import static org.briarproject.android.BriarActivity.GROUP_ID;
|
||||
@@ -42,9 +43,8 @@ public class AuthorView extends RelativeLayout {
|
||||
super(context, attrs);
|
||||
|
||||
LayoutInflater inflater = (LayoutInflater) context
|
||||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
inflater
|
||||
.inflate(R.layout.author_view, this, true);
|
||||
.getSystemService(LAYOUT_INFLATER_SERVICE);
|
||||
inflater.inflate(R.layout.author_view, this, true);
|
||||
|
||||
avatar = (CircleImageView) findViewById(R.id.avatar);
|
||||
avatarIcon = (ImageView) findViewById(R.id.avatarIcon);
|
||||
@@ -75,7 +75,7 @@ public class AuthorView extends RelativeLayout {
|
||||
public void setAuthorStatus(Status status) {
|
||||
trustIndicator.setTrustLevel(status);
|
||||
if (status == OURSELVES) {
|
||||
authorName.setTypeface(authorName.getTypeface(), Typeface.BOLD);
|
||||
authorName.setTypeface(authorName.getTypeface(), BOLD);
|
||||
}
|
||||
|
||||
invalidate();
|
||||
@@ -92,9 +92,8 @@ public class AuthorView extends RelativeLayout {
|
||||
public void setBlogLink(final GroupId groupId) {
|
||||
setClickable(true);
|
||||
TypedValue outValue = new TypedValue();
|
||||
getContext().getTheme()
|
||||
.resolveAttribute(android.R.attr.selectableItemBackground,
|
||||
outValue, true);
|
||||
getContext().getTheme().resolveAttribute(
|
||||
android.R.attr.selectableItemBackground, outValue, true);
|
||||
setBackgroundResource(outValue.resourceId);
|
||||
setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
@@ -106,8 +105,7 @@ public class AuthorView extends RelativeLayout {
|
||||
android.R.anim.slide_in_left,
|
||||
android.R.anim.slide_out_right);
|
||||
Intent[] intents = {i};
|
||||
ContextCompat
|
||||
.startActivities(getContext(), intents,
|
||||
ContextCompat.startActivities(getContext(), intents,
|
||||
options.toBundle());
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user