diff options
author | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2023-02-20 17:01:54 +0000 |
---|---|---|
committer | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2023-02-20 17:01:54 +0000 |
commit | 9db90a04317dcdcc5cce6b0954371b62084153a8 (patch) | |
tree | 2c05c4b5ad5d380f124acc65ddcc172e46021904 | |
parent | c1190c0d87b3a1a3875ebba0f53cce65ae299390 (diff) | |
download | infinity-for-reddit-9db90a04317dcdcc5cce6b0954371b62084153a8.tar infinity-for-reddit-9db90a04317dcdcc5cce6b0954371b62084153a8.tar.gz infinity-for-reddit-9db90a04317dcdcc5cce6b0954371b62084153a8.tar.bz2 infinity-for-reddit-9db90a04317dcdcc5cce6b0954371b62084153a8.tar.lz infinity-for-reddit-9db90a04317dcdcc5cce6b0954371b62084153a8.tar.xz infinity-for-reddit-9db90a04317dcdcc5cce6b0954371b62084153a8.tar.zst infinity-for-reddit-9db90a04317dcdcc5cce6b0954371b62084153a8.zip |
Fix https://github.com/Docile-Alligator/Infinity-For-Reddit/issues/736
5 files changed, 55 insertions, 30 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java index 74c0ef53..de67008f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java @@ -22,7 +22,6 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.content.res.AppCompatResources; import androidx.constraintlayout.widget.ConstraintLayout; import androidx.constraintlayout.widget.ConstraintSet; import androidx.recyclerview.widget.ItemTouchHelper; @@ -1908,7 +1907,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi mIsSingleCommentThreadMode = false; mSingleCommentId = null; notifyItemRemoved(0); - mFragment.changeToNomalThreadMode(); + mFragment.changeToNormalThreadMode(); } }); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java index d7a2d918..3455998a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java @@ -813,10 +813,10 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic children.clear(); } this.sortType = sortType.getType(); - if (!mSharedPreferences.getBoolean(SharedPreferencesUtils.RESPECT_SUBREDDIT_RECOMMENDED_COMMENT_SORT_TYPE, false) - && mSharedPreferences.getBoolean(SharedPreferencesUtils.SAVE_SORT_TYPE, true)) { + if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SAVE_SORT_TYPE, true)) { mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_POST_COMMENT, sortType.getType().name()).apply(); } + mRespectSubredditRecommendedSortType = false; fetchCommentsRespectRecommendedSort(false, sortType.getType()); } @@ -1425,6 +1425,17 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic private void fetchCommentsRespectRecommendedSort(boolean changeRefreshState, SortType.Type sortType) { if (mRespectSubredditRecommendedSortType && mPost != null) { + if (mPost.getSuggestedSort() != null && !mPost.getSuggestedSort().equals("null") && !mPost.getSuggestedSort().equals("")) { + try { + SortType.Type sortTypeType = SortType.Type.valueOf(mPost.getSuggestedSort().toUpperCase(Locale.US)); + activity.setTitle(sortTypeType.fullName); + ViewPostDetailFragment.this.sortType = sortTypeType; + fetchComments(changeRefreshState, ViewPostDetailFragment.this.sortType); + return; + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } + } FetchSubredditData.fetchSubredditData(mOauthRetrofit, mRetrofit, mPost.getSubredditName(), mAccessToken, new FetchSubredditData.FetchSubredditDataListener() { @Override @@ -1586,8 +1597,8 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic mFetchPostInfoLinearLayout.setVisibility(View.GONE); mGlide.clear(mFetchPostInfoImageView); - if (fetchComments) { - fetchCommentsRespectRecommendedSort(!fetchPost); + if (!fetchPost && fetchComments) { + fetchCommentsRespectRecommendedSort(true); } if (fetchPost) { @@ -1605,9 +1616,14 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic mPost = post; mPostAdapter.updatePost(mPost); EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition)); - isRefreshing = false; setupMenu(); mSwipeRefreshLayout.setRefreshing(false); + + if (fetchComments) { + fetchCommentsRespectRecommendedSort(true); + } else { + isRefreshing = false; + } } } @@ -1842,7 +1858,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic }); } - public void changeToNomalThreadMode() { + public void changeToNormalThreadMode() { isSingleCommentThreadMode = false; mSingleCommentId = null; mRespectSubredditRecommendedSortType = mSharedPreferences.getBoolean(SharedPreferencesUtils.RESPECT_SUBREDDIT_RECOMMENDED_COMMENT_SORT_TYPE, false); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java index 27ef3385..d63c42d3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java @@ -13,7 +13,6 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; -import java.util.Objects; import java.util.concurrent.Executor; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -147,6 +146,7 @@ public class ParsePost { } String authorFlair = data.isNull(JSONUtils.AUTHOR_FLAIR_TEXT_KEY) ? "" : data.getString(JSONUtils.AUTHOR_FLAIR_TEXT_KEY); String distinguished = data.getString(JSONUtils.DISTINGUISHED_KEY); + String suggestedSort = data.has(JSONUtils.SUGGESTED_SORT_KEY) ? data.getString(JSONUtils.SUGGESTED_SORT_KEY) : null; long postTime = data.getLong(JSONUtils.CREATED_UTC_KEY) * 1000; String title = data.getString(JSONUtils.TITLE_KEY); int score = data.getInt(JSONUtils.SCORE_KEY); @@ -236,7 +236,7 @@ public class ParsePost { postTime, title, previews, score, voteType, nComments, upvoteRatio, flair, awardingsBuilder.toString(), nAwards, hidden, spoiler, nsfw, stickied, archived, locked, saved, deleted, removed, true, - distinguished); + distinguished, suggestedSort); post.setCrosspostParentId(crosspostParent.getId()); return post; } else { @@ -245,7 +245,7 @@ public class ParsePost { postTime, title, previews, score, voteType, nComments, upvoteRatio, flair, awardingsBuilder.toString(), nAwards, hidden, spoiler, nsfw, stickied, archived, locked, saved, deleted, removed, false, - distinguished); + distinguished, suggestedSort); } } @@ -257,7 +257,7 @@ public class ParsePost { String awards, int nAwards, boolean hidden, boolean spoiler, boolean nsfw, boolean stickied, boolean archived, boolean locked, boolean saved, boolean deleted, boolean removed, boolean isCrosspost, - String distinguished) throws JSONException { + String distinguished, String suggestedSort) throws JSONException { Post post; boolean isVideo = data.getBoolean(JSONUtils.IS_VIDEO_KEY); @@ -272,7 +272,7 @@ public class ParsePost { post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, authorFlair, authorFlairHTML, postTimeMillis, title, permalink, score, postType, voteType, nComments, upvoteRatio, flair, awards, nAwards, hidden, spoiler, nsfw, - stickied, archived, locked, saved, isCrosspost, distinguished); + stickied, archived, locked, saved, isCrosspost, distinguished, suggestedSort); } else { if (path.endsWith(".jpg") || path.endsWith(".png") || path.endsWith(".jpeg")) { //Image post @@ -281,7 +281,7 @@ public class ParsePost { post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, authorFlair, authorFlairHTML, postTimeMillis, title, url, permalink, score, postType, voteType, nComments, upvoteRatio, flair, awards, nAwards, hidden, - spoiler, nsfw, stickied, archived, locked, saved, isCrosspost, distinguished); + spoiler, nsfw, stickied, archived, locked, saved, isCrosspost, distinguished, suggestedSort); if (previews.isEmpty()) { previews.add(new Post.Preview(url, 0, 0, "", "")); @@ -298,7 +298,7 @@ public class ParsePost { post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, authorFlair, authorFlairHTML, postTimeMillis, title, permalink, score, postType, voteType, nComments, upvoteRatio, flair, awards, nAwards, hidden, spoiler, nsfw, stickied, - archived, locked, saved, isCrosspost, distinguished); + archived, locked, saved, isCrosspost, distinguished, suggestedSort); post.setVideoUrl(videoUrl); post.setVideoDownloadUrl(videoDownloadUrl); @@ -308,7 +308,7 @@ public class ParsePost { post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, authorFlair, authorFlairHTML, postTimeMillis, title, url, permalink, score, postType, voteType, nComments, upvoteRatio, flair, awards, nAwards, hidden, - spoiler, nsfw, stickied, archived, locked, saved, isCrosspost, distinguished); + spoiler, nsfw, stickied, archived, locked, saved, isCrosspost, distinguished, suggestedSort); if (data.isNull(JSONUtils.SELFTEXT_KEY)) { post.setSelfText(""); } else { @@ -372,7 +372,7 @@ public class ParsePost { post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, authorFlair, authorFlairHTML, postTimeMillis, title, permalink, score, postType, voteType, nComments, upvoteRatio, flair, awards, nAwards, hidden, spoiler, nsfw, stickied, - archived, locked, saved, isCrosspost, distinguished); + archived, locked, saved, isCrosspost, distinguished, suggestedSort); post.setPreviews(previews); post.setVideoUrl(videoUrl); @@ -390,7 +390,7 @@ public class ParsePost { post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, authorFlair, authorFlairHTML, postTimeMillis, title, permalink, score, postType, voteType, nComments, upvoteRatio, flair, awards, nAwards, hidden, spoiler, nsfw, stickied, - archived, locked, saved, isCrosspost, distinguished); + archived, locked, saved, isCrosspost, distinguished, suggestedSort); post.setPreviews(previews); post.setVideoUrl(url); post.setVideoDownloadUrl(url); @@ -406,7 +406,7 @@ public class ParsePost { post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, authorFlair, authorFlairHTML, postTimeMillis, title, permalink, score, postType, voteType, nComments, upvoteRatio, flair, awards, nAwards, hidden, spoiler, nsfw, stickied, - archived, locked, saved, isCrosspost, distinguished); + archived, locked, saved, isCrosspost, distinguished, suggestedSort); post.setPreviews(previews); post.setVideoUrl(videoUrl); post.setVideoDownloadUrl(videoDownloadUrl); @@ -420,7 +420,7 @@ public class ParsePost { authorFlair, authorFlairHTML, postTimeMillis, title, url, permalink, score, postType, voteType, nComments, upvoteRatio, flair, awards, nAwards, hidden, spoiler, nsfw, stickied, archived, locked, saved, isCrosspost, - distinguished); + distinguished, suggestedSort); if (previews.isEmpty()) { previews.add(new Post.Preview(url, 0, 0, "", "")); @@ -433,7 +433,7 @@ public class ParsePost { authorFlair, authorFlairHTML, postTimeMillis, title, url, permalink, score, postType, voteType, nComments, upvoteRatio, flair, awards, nAwards, hidden, spoiler, nsfw, stickied, archived, locked, saved, isCrosspost, - distinguished); + distinguished, suggestedSort); post.setPreviews(previews); post.setVideoUrl(url); @@ -449,7 +449,7 @@ public class ParsePost { authorFlair, authorFlairHTML, postTimeMillis, title, url, permalink, score, postType, voteType, nComments, upvoteRatio, flair, awards, nAwards, hidden, spoiler, nsfw, stickied, archived, locked, saved, isCrosspost, - distinguished); + distinguished, suggestedSort); post.setPreviews(previews); post.setVideoUrl(url); post.setVideoDownloadUrl(url); @@ -462,7 +462,7 @@ public class ParsePost { authorFlair, authorFlairHTML, postTimeMillis, title, url, permalink, score, postType, voteType, nComments, upvoteRatio, flair, awards, nAwards, hidden, spoiler, nsfw, stickied, archived, locked, saved, isCrosspost, - distinguished); + distinguished, suggestedSort); post.setPreviews(previews); post.setVideoUrl(url); post.setVideoDownloadUrl(url); @@ -475,7 +475,7 @@ public class ParsePost { authorFlair, authorFlairHTML, postTimeMillis, title, permalink, score, postType, voteType, nComments, upvoteRatio, flair, awards, nAwards, hidden, spoiler, nsfw, stickied, archived, locked, saved, isCrosspost, - distinguished); + distinguished, suggestedSort); //Need attention post.setPreviews(previews); @@ -487,7 +487,7 @@ public class ParsePost { authorFlair, authorFlairHTML, postTimeMillis, title, url, permalink, score, postType, voteType, nComments, upvoteRatio, flair, awards, nAwards, hidden, spoiler, nsfw, stickied, archived, locked, saved, isCrosspost, - distinguished); + distinguished, suggestedSort); if (data.isNull(JSONUtils.SELFTEXT_KEY)) { post.setSelfText(""); } else { @@ -530,7 +530,7 @@ public class ParsePost { post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, authorFlair, authorFlairHTML, postTimeMillis, title, url, permalink, score, postType, voteType, nComments, upvoteRatio, flair, awards, nAwards, hidden, - spoiler, nsfw, stickied, archived, locked, saved, isCrosspost, distinguished); + spoiler, nsfw, stickied, archived, locked, saved, isCrosspost, distinguished, suggestedSort); if (previews.isEmpty()) { previews.add(new Post.Preview(url, 0, 0, "", "")); @@ -543,7 +543,7 @@ public class ParsePost { post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, authorFlair, authorFlairHTML, postTimeMillis, title, url, permalink, score, postType, voteType, nComments, upvoteRatio, flair, awards, nAwards, hidden, - spoiler, nsfw, stickied, archived, locked, saved, isCrosspost, distinguished); + spoiler, nsfw, stickied, archived, locked, saved, isCrosspost, distinguished, suggestedSort); post.setPreviews(previews); post.setVideoUrl(url); post.setVideoDownloadUrl(url); @@ -554,7 +554,7 @@ public class ParsePost { post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, authorFlair, authorFlairHTML, postTimeMillis, title, url, permalink, score, postType, voteType, nComments, upvoteRatio, flair, awards, nAwards, hidden, - spoiler, nsfw, stickied, archived, locked, saved, isCrosspost, distinguished); + spoiler, nsfw, stickied, archived, locked, saved, isCrosspost, distinguished, suggestedSort); //Need attention if (data.isNull(JSONUtils.SELFTEXT_KEY)) { post.setSelfText(""); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java index 7e73b0bc..90577a2c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java @@ -78,6 +78,7 @@ public class Post implements Parcelable { private boolean isRead; private String crosspostParentId; private String distinguished; + private String suggestedSort; private ArrayList<Preview> previews = new ArrayList<>(); private ArrayList<Gallery> gallery = new ArrayList<>(); @@ -86,7 +87,7 @@ public class Post implements Parcelable { String title, String permalink, int score, int postType, int voteType, int nComments, int upvoteRatio, String flair, String awards, int nAwards, boolean hidden, boolean spoiler, boolean nsfw, boolean stickied, boolean archived, boolean locked, boolean saved, - boolean isCrosspost, String distinguished) { + boolean isCrosspost, String distinguished, String suggestedSort) { this.id = id; this.fullName = fullName; this.subredditName = subredditName; @@ -115,6 +116,7 @@ public class Post implements Parcelable { this.saved = saved; this.isCrosspost = isCrosspost; this.distinguished = distinguished; + this.suggestedSort = suggestedSort; isRead = false; } @@ -123,7 +125,7 @@ public class Post implements Parcelable { String url, String permalink, int score, int postType, int voteType, int nComments, int upvoteRatio, String flair, String awards, int nAwards, boolean hidden, boolean spoiler, boolean nsfw, boolean stickied, boolean archived, boolean locked, boolean saved, - boolean isCrosspost, String distinguished) { + boolean isCrosspost, String distinguished, String suggestedSort) { this.id = id; this.fullName = fullName; this.subredditName = subredditName; @@ -153,6 +155,7 @@ public class Post implements Parcelable { this.saved = saved; this.isCrosspost = isCrosspost; this.distinguished = distinguished; + this.suggestedSort = suggestedSort; isRead = false; } @@ -202,6 +205,7 @@ public class Post implements Parcelable { isRead = in.readByte() != 0; crosspostParentId = in.readString(); distinguished = in.readString(); + suggestedSort = in.readString(); in.readTypedList(previews, Preview.CREATOR); in.readTypedList(gallery, Gallery.CREATOR); } @@ -399,6 +403,10 @@ public class Post implements Parcelable { return distinguished != null && distinguished.equals("admin"); } + public String getSuggestedSort() { + return suggestedSort; + } + public String getAwards() { return awards; } @@ -587,6 +595,7 @@ public class Post implements Parcelable { parcel.writeByte((byte) (isRead ? 1 : 0)); parcel.writeString(crosspostParentId); parcel.writeString(distinguished); + parcel.writeString(suggestedSort); parcel.writeTypedList(previews); parcel.writeTypedList(gallery); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/JSONUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/JSONUtils.java index 968dcbae..2726311a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/JSONUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/JSONUtils.java @@ -180,4 +180,5 @@ public class JSONUtils { public static final String STATUS_KEY = "status"; public static final String URLS_KEY = "urls"; public static final String HD_KEY = "hd"; + public static final String SUGGESTED_SORT_KEY = "suggested_sort"; } |