diff options
Diffstat (limited to '')
8 files changed, 77 insertions, 17 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java index 8952cf12..17314525 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java @@ -315,6 +315,11 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie } if(mPost.isCrosspost()) { + ((PostDetailViewHolder) holder).mCrosspostImageView.setOnClickListener(view -> { + Intent crosspostIntent = new Intent(mActivity, ViewPostDetailActivity.class); + crosspostIntent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, mPost.getCrosspostParentId()); + mActivity.startActivity(crosspostIntent); + }); ((PostDetailViewHolder) holder).mCrosspostImageView.setVisibility(View.VISIBLE); } @@ -356,6 +361,14 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie } if(mPost.isNSFW()) { + ((PostDetailViewHolder) holder).mNSFWChip.setOnClickListener(view -> { + Intent intent = new Intent(mActivity, FilteredThingActivity.class); + intent.putExtra(FilteredThingActivity.EXTRA_NAME, mSubredditNamePrefixed.substring(2)); + intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT); + intent.putExtra(FilteredThingActivity.EXTRA_SORT_TYPE, PostDataSource.SORT_TYPE_HOT); + intent.putExtra(FilteredThingActivity.EXTRA_FILTER, Post.NSFW_TYPE); + mActivity.startActivity(intent); + }); ((PostDetailViewHolder) holder).mNSFWChip.setVisibility(View.VISIBLE); } else { ((PostDetailViewHolder) holder).mNSFWChip.setVisibility(View.GONE); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FilteredThingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FilteredThingActivity.java index 37142432..f4425773 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/FilteredThingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FilteredThingActivity.java @@ -217,6 +217,9 @@ public class FilteredThingActivity extends AppCompatActivity implements SortType } switch (filter) { + case Post.NSFW_TYPE: + toolbar.setSubtitle(R.string.nsfw); + break; case Post.TEXT_TYPE: toolbar.setSubtitle(R.string.text); break; @@ -243,10 +246,10 @@ public class FilteredThingActivity extends AppCompatActivity implements SortType bundle.putInt(PostFragment.EXTRA_FILTER, filter); bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken); if(postType == PostDataSource.TYPE_USER) { - bundle.putString(PostFragment.EXTRA_USER_WHERE, getIntent().getExtras().getString(EXTRA_USER_WHERE)); + bundle.putString(PostFragment.EXTRA_USER_WHERE, getIntent().getStringExtra(EXTRA_USER_WHERE)); } if(postType == PostDataSource.TYPE_SEARCH) { - bundle.putString(PostFragment.EXTRA_QUERY, getIntent().getExtras().getString(EXTRA_QUERY)); + bundle.putString(PostFragment.EXTRA_QUERY, getIntent().getStringExtra(EXTRA_QUERY)); } mFragment.setArguments(bundle); getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_filtered_posts_activity, mFragment).commit(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java index c6e75042..3271b434 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java @@ -98,7 +98,7 @@ class ParsePost { try { JSONObject data = allData.getJSONObject(0).getJSONObject(JSONUtils.DATA_KEY); - post = parseBasicData(data, locale, -1); + post = parseBasicData(data, locale); } catch (JSONException e) { Log.e("parsing post error", "message: " + e.getMessage()); parseFailed = true; @@ -115,7 +115,7 @@ class ParsePost { for (int i = 0; i < size; i++) { try { JSONObject data = allData.getJSONObject(i).getJSONObject(JSONUtils.DATA_KEY); - Post post = parseBasicData(data, locale, i); + Post post = parseBasicData(data, locale); if(!(!nsfw && post.isNSFW())) { if (filter == PostFragment.EXTRA_NO_FILTER) { newPosts.add(post); @@ -123,6 +123,8 @@ class ParsePost { newPosts.add(post); } else if (filter == Post.LINK_TYPE && post.getPostType() == Post.NO_PREVIEW_LINK_TYPE) { newPosts.add(post); + } else if(filter == Post.NSFW_TYPE && post.isNSFW()) { + newPosts.add(post); } } } catch (JSONException e) { @@ -151,7 +153,7 @@ class ParsePost { } } - private static Post parseBasicData(JSONObject data, Locale locale, int i) throws JSONException { + private static Post parseBasicData(JSONObject data, Locale locale) throws JSONException { String id = data.getString(JSONUtils.ID_KEY); String fullName = data.getString(JSONUtils.NAME_KEY); String subredditName = data.getString(JSONUtils.SUBREDDIT_KEY); @@ -200,15 +202,18 @@ class ParsePost { if(data.has(JSONUtils.CROSSPOST_PARENT_LIST)) { //Cross post data = data.getJSONArray(JSONUtils.CROSSPOST_PARENT_LIST).getJSONObject(0); - return parseData(data, permalink, id, fullName, subredditName, subredditNamePrefixed, + Post crosspostParent = parseBasicData(data, locale); + Post post = parseData(data, permalink, id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, title, previewUrl, previewWidth, previewHeight, score, voteType, gilded, flair, spoiler, nsfw, stickied, archived, locked, saved, - true, i); + true); + post.setCrosspostParentId(crosspostParent.getId()); + return post; } else { return parseData(data, permalink, id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, title, previewUrl, previewWidth, previewHeight, score, voteType, gilded, flair, spoiler, nsfw, stickied, archived, locked, saved, - false, i); + false); } } @@ -217,7 +222,7 @@ class ParsePost { String formattedPostTime, String title, String previewUrl, int previewWidth, int previewHeight, int score, int voteType, int gilded, String flair, boolean spoiler, boolean nsfw, boolean stickied, boolean archived, - boolean locked, boolean saved, boolean isCrosspost, int i) throws JSONException { + boolean locked, boolean saved, boolean isCrosspost) throws JSONException { Post post; boolean isVideo = data.getBoolean(JSONUtils.IS_VIDEO_KEY); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Post.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Post.java index 99236eac..9a5371c2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Post.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Post.java @@ -8,6 +8,7 @@ import android.os.Parcelable; */ class Post implements Parcelable { + static final int NSFW_TYPE = -1; static final int TEXT_TYPE = 0; static final int IMAGE_TYPE = 1; static final int LINK_TYPE = 2; @@ -47,6 +48,7 @@ class Post implements Parcelable { private boolean isCrosspost; private boolean isDashVideo; private boolean isDownloadableGifOrVideo; + private String crosspostParentId; Post(String id, String fullName, String subredditName, String subredditNamePrefixed, String author, String postTime, String title, String previewUrl, String permalink, int score, int postType, @@ -166,6 +168,7 @@ class Post implements Parcelable { isCrosspost = in.readByte() != 0; isDashVideo = in.readByte() != 0; isDownloadableGifOrVideo = in.readByte() != 0; + crosspostParentId = in.readString(); } public static final Creator<Post> CREATOR = new Creator<Post>() { @@ -373,6 +376,14 @@ class Post implements Parcelable { return isCrosspost; } + public String getCrosspostParentId() { + return crosspostParentId; + } + + public void setCrosspostParentId(String crosspostParentId) { + this.crosspostParentId = crosspostParentId; + } + @Override public void writeToParcel(Parcel parcel, int i) { parcel.writeString(id); @@ -407,5 +418,6 @@ class Post implements Parcelable { parcel.writeByte((byte) (isCrosspost ? 1 : 0)); parcel.writeByte((byte) (isDashVideo ? 1 : 0)); parcel.writeByte((byte) (isDownloadableGifOrVideo ? 1 : 0)); + parcel.writeString(crosspostParentId); } }
\ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java index 1a65da3d..379c3f7d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java @@ -60,7 +60,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { static final String EXTRA_POST_TYPE = "EPT"; static final String EXTRA_SORT_TYPE = "EST"; static final String EXTRA_FILTER = "EF"; - static final int EXTRA_NO_FILTER = -1; + static final int EXTRA_NO_FILTER = -2; static final String EXTRA_ACCESS_TOKEN = "EAT"; private static final String IS_IN_LAZY_MODE_STATE = "IILMS"; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java index fc2b4024..3cc6ed8f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java @@ -309,6 +309,16 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo } if(nsfw) { + if(!(mContext instanceof FilteredThingActivity)) { + ((DataViewHolder) holder).nsfwChip.setOnClickListener(view -> { + Intent intent = new Intent(mContext, FilteredThingActivity.class); + intent.putExtra(FilteredThingActivity.EXTRA_NAME, post.getSubredditNamePrefixed().substring(2)); + intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT); + intent.putExtra(FilteredThingActivity.EXTRA_SORT_TYPE, PostDataSource.SORT_TYPE_HOT); + intent.putExtra(FilteredThingActivity.EXTRA_FILTER, Post.NSFW_TYPE); + mContext.startActivity(intent); + }); + } ((DataViewHolder) holder).nsfwChip.setVisibility(View.VISIBLE); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostViewModel.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostViewModel.java index aef2a574..97fc836b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostViewModel.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostViewModel.java @@ -48,6 +48,7 @@ public class PostViewModel extends ViewModel { (new PagedList.Config.Builder()) .setEnablePlaceholders(false) .setPageSize(25) + .setInitialLoadSizeHint(75) .build(); posts = Transformations.switchMap(NSFWAndSortTypeLiveData, sort -> { @@ -79,6 +80,7 @@ public class PostViewModel extends ViewModel { (new PagedList.Config.Builder()) .setEnablePlaceholders(false) .setPageSize(25) + .setInitialLoadSizeHint(75) .build(); posts = Transformations.switchMap(NSFWAndSortTypeLiveData, sort -> { @@ -110,6 +112,7 @@ public class PostViewModel extends ViewModel { (new PagedList.Config.Builder()) .setEnablePlaceholders(false) .setPageSize(25) + .setInitialLoadSizeHint(75) .build(); posts = Transformations.switchMap(NSFWAndSortTypeLiveData, sort -> { @@ -141,6 +144,7 @@ public class PostViewModel extends ViewModel { (new PagedList.Config.Builder()) .setEnablePlaceholders(false) .setPageSize(25) + .setInitialLoadSizeHint(75) .build(); posts = Transformations.switchMap(sortTypeLiveData, sort -> { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java index bdff4479..fc2cab68 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java @@ -340,6 +340,8 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo mMenu.findItem(R.id.action_edit_flair_view_post_detail_activity).setVisible(true); } + + mMenu.findItem(R.id.action_view_crosspost_parent_view_post_detail_activity).setVisible(mPost.getCrosspostParentId() != null); } mAdapter = new CommentAndPostRecyclerViewAdapter(ViewPostDetailActivity.this, mRetrofit, @@ -429,13 +431,15 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo } else { saveItem.setVisible(false); } - } - if(mMenu != null && mPost.getAuthor().equals(mAccountName)) { - if(mPost.getPostType() == Post.TEXT_TYPE) { - mMenu.findItem(R.id.action_edit_view_post_detail_activity).setVisible(true); + if(mPost.getAuthor().equals(mAccountName)) { + if(mPost.getPostType() == Post.TEXT_TYPE) { + mMenu.findItem(R.id.action_edit_view_post_detail_activity).setVisible(true); + } + mMenu.findItem(R.id.action_delete_view_post_detail_activity).setVisible(true); } - mMenu.findItem(R.id.action_delete_view_post_detail_activity).setVisible(true); + + mMenu.findItem(R.id.action_view_crosspost_parent_view_post_detail_activity).setVisible(mPost.getCrosspostParentId() != null); } mAdapter = new CommentAndPostRecyclerViewAdapter(ViewPostDetailActivity.this, @@ -637,6 +641,8 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo } else { saveItem.setVisible(false); } + + mMenu.findItem(R.id.action_view_crosspost_parent_view_post_detail_activity).setVisible(mPost.getCrosspostParentId() != null); } } @@ -654,7 +660,7 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo mProgressBar.setVisibility(View.GONE); mFetchPostInfoLinearLayout.setVisibility(View.VISIBLE); mFetchPostInfoLinearLayout.setOnClickListener(view -> fetchPostAndCommentsById(subredditId)); - mFetchPostInfoTextView.setText(R.string.load_posts_error); + mFetchPostInfoTextView.setText(R.string.load_post_error); mGlide.load(R.drawable.error_image).into(mFetchPostInfoImageView); } @@ -838,6 +844,8 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo menu.findItem(R.id.action_edit_flair_view_post_detail_activity).setVisible(true); } + + menu.findItem(R.id.action_view_crosspost_parent_view_post_detail_activity).setVisible(mPost.getCrosspostParentId() != null); } return true; } @@ -915,7 +923,12 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo }); } } - break; + return true; + case R.id.action_view_crosspost_parent_view_post_detail_activity: + Intent crosspostIntent = new Intent(this, ViewPostDetailActivity.class); + crosspostIntent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, mPost.getCrosspostParentId()); + startActivity(crosspostIntent); + return true; case R.id.action_edit_view_post_detail_activity: Intent editPostItent = new Intent(this, EditPostActivity.class); editPostItent.putExtra(EditPostActivity.EXTRA_ACCESS_TOKEN, mAccessToken); |