Docile-Alligator 2023-02-20 12:01:54 -05:00
parent c1190c0d87
commit 9db90a0431
5 changed files with 55 additions and 30 deletions

View File

@ -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();
}
});

View File

@ -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);

View File

@ -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("");

View File

@ -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);
}

View File

@ -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";
}