mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
Move OnBlogPostClickListener from activity to fragment
This commit is contained in:
@@ -10,6 +10,7 @@ import android.widget.ProgressBar;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.android.fragment.BaseFragment;
|
||||
|
||||
@@ -31,6 +32,7 @@ abstract class BasePostFragment extends BaseFragment {
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(BasePostFragment.class.getName());
|
||||
|
||||
protected MessageId postId;
|
||||
private View view;
|
||||
private ProgressBar progressBar;
|
||||
private BlogPostViewHolder ui;
|
||||
@@ -43,6 +45,11 @@ abstract class BasePostFragment extends BaseFragment {
|
||||
public View onCreateView(LayoutInflater inflater,
|
||||
@Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
// retrieve MessageId of blog post from arguments
|
||||
byte[] p = getArguments().getByteArray(POST_ID);
|
||||
if (p == null) throw new IllegalStateException("No post ID in args");
|
||||
postId = new MessageId(p);
|
||||
|
||||
view = inflater.inflate(R.layout.fragment_blog_post, container,
|
||||
false);
|
||||
progressBar = (ProgressBar) view.findViewById(R.id.progressBar);
|
||||
|
||||
@@ -11,7 +11,6 @@ import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||
import org.briarproject.briar.android.activity.BriarActivity;
|
||||
import org.briarproject.briar.android.blog.BlogPostAdapter.OnBlogPostClickListener;
|
||||
import org.briarproject.briar.android.fragment.BaseFragment.BaseFragmentListener;
|
||||
import org.briarproject.briar.android.sharing.BlogSharingStatusActivity;
|
||||
|
||||
@@ -19,8 +18,8 @@ import javax.inject.Inject;
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@ParametersNotNullByDefault
|
||||
public class BlogActivity extends BriarActivity implements
|
||||
OnBlogPostClickListener, BaseFragmentListener {
|
||||
public class BlogActivity extends BriarActivity
|
||||
implements BaseFragmentListener {
|
||||
|
||||
static final int REQUEST_WRITE_POST = 2;
|
||||
static final int REQUEST_SHARE = 3;
|
||||
@@ -66,10 +65,4 @@ public class BlogActivity extends BriarActivity implements
|
||||
component.inject(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlogPostClick(BlogPostItem post) {
|
||||
BlogPostFragment f = BlogPostFragment.newInstance(post.getId());
|
||||
showNextFragment(f);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.UiThread;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.app.ActivityOptionsCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
@@ -45,7 +44,6 @@ import javax.inject.Inject;
|
||||
import static android.app.Activity.RESULT_OK;
|
||||
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
|
||||
import static android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP;
|
||||
import static android.support.v4.app.ActivityOptionsCompat.makeCustomAnimation;
|
||||
import static android.widget.Toast.LENGTH_SHORT;
|
||||
import static org.briarproject.briar.android.activity.BriarActivity.GROUP_ID;
|
||||
import static org.briarproject.briar.android.blog.BlogActivity.REQUEST_SHARE;
|
||||
@@ -56,7 +54,8 @@ import static org.briarproject.briar.android.controller.SharingController.Sharin
|
||||
@MethodsNotNullByDefault
|
||||
@ParametersNotNullByDefault
|
||||
public class BlogFragment extends BaseFragment
|
||||
implements BlogSharingListener, SharingListener {
|
||||
implements BlogSharingListener, SharingListener,
|
||||
OnBlogPostClickListener {
|
||||
|
||||
private final static String TAG = BlogFragment.class.getName();
|
||||
|
||||
@@ -94,8 +93,7 @@ public class BlogFragment extends BaseFragment
|
||||
|
||||
View v = inflater.inflate(R.layout.fragment_blog, container, false);
|
||||
|
||||
adapter = new BlogPostAdapter(getActivity(),
|
||||
(OnBlogPostClickListener) getActivity());
|
||||
adapter = new BlogPostAdapter(getActivity(), this);
|
||||
list = (BriarRecyclerView) v.findViewById(R.id.postList);
|
||||
list.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
list.setAdapter(adapter);
|
||||
@@ -214,6 +212,12 @@ public class BlogFragment extends BaseFragment
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlogPostClick(BlogPostItem post) {
|
||||
BlogPostFragment f = BlogPostFragment.newInstance(post.getId());
|
||||
showNextFragment(f);
|
||||
}
|
||||
|
||||
private void loadBlogPosts(final boolean reload) {
|
||||
blogController.loadBlogPosts(
|
||||
new UiResultExceptionHandler<Collection<BlogPostItem>, DbException>(
|
||||
|
||||
@@ -23,8 +23,6 @@ public class BlogPostFragment extends BasePostFragment {
|
||||
|
||||
private static final String TAG = BlogPostFragment.class.getName();
|
||||
|
||||
private MessageId postId;
|
||||
|
||||
@Inject
|
||||
BlogController blogController;
|
||||
|
||||
@@ -38,20 +36,6 @@ public class BlogPostFragment extends BasePostFragment {
|
||||
return f;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater,
|
||||
@Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
|
||||
Bundle args = getArguments();
|
||||
byte[] p = args.getByteArray(POST_ID);
|
||||
if (p == null) throw new IllegalStateException("No post ID in args");
|
||||
postId = new MessageId(p);
|
||||
|
||||
return super.onCreateView(inflater, container, savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUniqueTag() {
|
||||
return TAG;
|
||||
|
||||
@@ -26,7 +26,6 @@ public class FeedPostFragment extends BasePostFragment {
|
||||
|
||||
private static final String TAG = FeedPostFragment.class.getName();
|
||||
|
||||
private MessageId postId;
|
||||
private GroupId blogId;
|
||||
|
||||
@Inject
|
||||
@@ -54,10 +53,6 @@ public class FeedPostFragment extends BasePostFragment {
|
||||
if (b == null) throw new IllegalStateException("No group ID in args");
|
||||
blogId = new GroupId(b);
|
||||
|
||||
byte[] p = args.getByteArray(POST_ID);
|
||||
if (p == null) throw new IllegalStateException("No post ID in args");
|
||||
postId = new MessageId(p);
|
||||
|
||||
return super.onCreateView(inflater, container, savedInstanceState);
|
||||
}
|
||||
|
||||
|
||||
@@ -74,8 +74,7 @@ public class ReblogFragment extends BaseFragment implements TextInputListener {
|
||||
blogId = new GroupId(args.getByteArray(GROUP_ID));
|
||||
postId = new MessageId(args.getByteArray(POST_ID));
|
||||
|
||||
View v = inflater.inflate(R.layout.fragment_reblog, container,
|
||||
false);
|
||||
View v = inflater.inflate(R.layout.fragment_reblog, container, false);
|
||||
ui = new ViewHolder(v);
|
||||
ui.post.setTransitionName(postId);
|
||||
ui.input.setSendButtonEnabled(false);
|
||||
|
||||
@@ -6,5 +6,6 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/window_background"
|
||||
app:scrollToEnd="false"
|
||||
tools:context=".android.blog.BlogActivity"/>
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
<ScrollView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/window_background">
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
Reference in New Issue
Block a user