diff options
author | Alex Ning <chineseperson5@gmail.com> | 2019-08-30 03:35:44 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2019-08-30 03:35:44 +0000 |
commit | a5a77fca04debc52d7ac02181f0d6e0e9b8db052 (patch) | |
tree | f5992d08c22cf8587541bebc3bb2072c032124d4 | |
parent | 92762974fff5b9b18a7696b7562daf5f55e46472 (diff) | |
download | infinity-for-reddit-a5a77fca04debc52d7ac02181f0d6e0e9b8db052.tar infinity-for-reddit-a5a77fca04debc52d7ac02181f0d6e0e9b8db052.tar.gz infinity-for-reddit-a5a77fca04debc52d7ac02181f0d6e0e9b8db052.tar.bz2 infinity-for-reddit-a5a77fca04debc52d7ac02181f0d6e0e9b8db052.tar.lz infinity-for-reddit-a5a77fca04debc52d7ac02181f0d6e0e9b8db052.tar.xz infinity-for-reddit-a5a77fca04debc52d7ac02181f0d6e0e9b8db052.tar.zst infinity-for-reddit-a5a77fca04debc52d7ac02181f0d6e0e9b8db052.zip |
View crosspost parent in ViewPostDetailActivity when clicking the crosspost icon or select Crosspost parent menu item in toolbar. Filter NSFW posts in FilteredThingActivity is now available.
14 files changed, 95 insertions, 25 deletions
diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser Binary files differindex b4c3a5c8..d2551b59 100644 --- a/.idea/caches/build_file_checksums.ser +++ b/.idea/caches/build_file_checksums.ser diff --git a/.idea/caches/gradle_models.ser b/.idea/caches/gradle_models.ser Binary files differindex 321d1240..5191ed48 100644 --- a/.idea/caches/gradle_models.ser +++ b/.idea/caches/gradle_models.ser diff --git a/app/build.gradle b/app/build.gradle index 3ddc20d7..05b8c29d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -55,7 +55,7 @@ dependencies { androidTestImplementation "androidx.room:room-testing:$rootProject.roomVersion" // Lifecycle components implementation "androidx.lifecycle:lifecycle-extensions:$rootProject.archLifecycleVersion" - annotationProcessor "androidx.lifecycle:lifecycle-compiler:$rootProject.archLifecycleVersion" + annotationProcessor "androidx.lifecycle:lifecycle-common-java8:$rootProject.archLifecycleVersion" implementation 'io.reactivex.rxjava2:rxandroid:2.1.0' implementation 'io.reactivex.rxjava2:rxjava:2.2.0' implementation 'com.squareup.retrofit2:retrofit:2.6.1' 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); diff --git a/app/src/main/res/menu/view_post_detail_activity.xml b/app/src/main/res/menu/view_post_detail_activity.xml index 756f51b7..83888218 100644 --- a/app/src/main/res/menu/view_post_detail_activity.xml +++ b/app/src/main/res/menu/view_post_detail_activity.xml @@ -11,7 +11,7 @@ <item android:id="@+id/action_save_view_post_detail_activity" android:orderInCategory="2" - android:title="@string/action_add_comment" + android:title="@string/action_save_post" app:showAsAction="ifRoom" android:visible="false" /> @@ -22,34 +22,41 @@ app:showAsAction="never" /> <item - android:id="@+id/action_edit_view_post_detail_activity" + android:id="@+id/action_view_crosspost_parent_view_post_detail_activity" android:orderInCategory="4" + android:title="@string/action_view_crosspost_parent" + app:showAsAction="never" + android:visible="false" /> + + <item + android:id="@+id/action_edit_view_post_detail_activity" + android:orderInCategory="5" android:title="@string/action_edit_post" app:showAsAction="never" android:visible="false" /> <item android:id="@+id/action_delete_view_post_detail_activity" - android:orderInCategory="5" + android:orderInCategory="6" android:title="@string/action_delete_post" app:showAsAction="never" android:visible="false" /> <item android:id="@+id/action_nsfw_view_post_detail_activity" - android:orderInCategory="6" + android:orderInCategory="7" app:showAsAction="never" android:visible="false" /> <item android:id="@+id/action_spoiler_view_post_detail_activity" - android:orderInCategory="7" + android:orderInCategory="8" app:showAsAction="never" android:visible="false" /> <item android:id="@+id/action_edit_flair_view_post_detail_activity" - android:orderInCategory="8" + android:orderInCategory="9" android:title="@string/action_edit_flair" app:showAsAction="never" android:visible="false" /> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1cde4e7a..0eb7335c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -23,6 +23,8 @@ <string name="action_download">Download</string> <string name="action_refresh">Refresh</string> <string name="action_add_comment">Add a comment</string> + <string name="action_save_post">Save post</string> + <string name="action_view_crosspost_parent">Crosspost parent</string> <string name="action_search">Search</string> <string name="action_start_lazy_mode">Start Lazy Mode</string> <string name="action_stop_lazy_mode">Stop Lazy Mode</string> @@ -44,6 +46,7 @@ <string name="tap_to_retry">Error loading image. Tap to retry.</string> <string name="load_posts_error">Error loading posts.\nTap to retry.</string> + <string name="load_post_error">Error loading this post.\nTap to retry.</string> <string name="search_subreddits_error">Error searching subreddits.\nTap to retry.</string> <string name="search_users_error">Error searching users.\nTap to retry.</string> <string name="no_posts">No posts found</string> diff --git a/build.gradle b/build.gradle index e08c9801..fe345c9d 100644 --- a/build.gradle +++ b/build.gradle @@ -31,6 +31,6 @@ task clean(type: Delete) { } ext { - roomVersion = '2.2.0-alpha02' + roomVersion = '2.2.0-beta01' archLifecycleVersion = '2.2.0-alpha03' }
\ No newline at end of file |