Sort type converters - part 2 (#1244)

* Use and store sort type as enum for comments

* Use and store sort type as enum for posts

* Use sort type enum for search

* Remove unused reddit api methods

These were missed in the first "sort type" pr
This commit is contained in:
Sergei Kozelko 2022-11-27 20:22:36 +08:00 committed by GitHub
parent 9a3b9115ff
commit 44dcf64475
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 86 additions and 200 deletions

View File

@ -164,9 +164,9 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
@State @State
PostFilter postFilter; PostFilter postFilter;
@State @State
String sortType; SortType.Type sortType;
@State @State
String sortTime; SortType.Time sortTime;
@State @State
ArrayList<String> readPostList; ArrayList<String> readPostList;
@State @State
@ -535,111 +535,55 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
switch (postType) { switch (postType) {
case PostPagingSource.TYPE_SUBREDDIT: case PostPagingSource.TYPE_SUBREDDIT:
if (mAccessToken == null) { if (mAccessToken == null) {
if (sortTime != null) { call = api.getSubredditBestPosts(subredditName, sortType, sortTime, afterKey);
call = api.getSubredditBestPosts(subredditName, sortType, sortTime, afterKey);
} else {
call = api.getSubredditBestPosts(subredditName, sortType, afterKey);
}
} else { } else {
if (sortTime != null) { call = api.getSubredditBestPostsOauth(subredditName, sortType,
call = api.getSubredditBestPostsOauth(subredditName, sortType, sortTime, afterKey, APIUtils.getOAuthHeader(mAccessToken));
sortTime, afterKey, APIUtils.getOAuthHeader(mAccessToken));
} else {
call = api.getSubredditBestPostsOauth(subredditName, sortType,
afterKey, APIUtils.getOAuthHeader(mAccessToken));
}
} }
break; break;
case PostPagingSource.TYPE_USER: case PostPagingSource.TYPE_USER:
if (mAccessToken == null) { if (mAccessToken == null) {
if (sortTime != null) { call = api.getUserPosts(username, afterKey, sortType, sortTime);
call = api.getUserPosts(username, afterKey, sortType,
sortTime);
} else {
call = api.getUserPosts(username, afterKey, sortType);
}
} else { } else {
if (sortTime != null) { call = api.getUserPostsOauth(username, userWhere, afterKey, sortType,
call = api.getUserPostsOauth(username, userWhere, afterKey, sortType, sortTime, APIUtils.getOAuthHeader(mAccessToken));
sortTime, APIUtils.getOAuthHeader(mAccessToken));
} else {
call = api.getUserPostsOauth(username, userWhere, afterKey, sortType,
APIUtils.getOAuthHeader(mAccessToken));
}
} }
break; break;
case PostPagingSource.TYPE_SEARCH: case PostPagingSource.TYPE_SEARCH:
if (subredditName == null) { if (subredditName == null) {
if (mAccessToken == null) { if (mAccessToken == null) {
if (sortTime != null) { call = api.searchPosts(query, afterKey, sortType, sortTime,
call = api.searchPosts(query, afterKey, sortType, sortTime, trendingSource);
trendingSource);
} else {
call = api.searchPosts(query, afterKey, sortType, trendingSource);
}
} else { } else {
if (sortTime != null) { call = api.searchPostsOauth(query, afterKey, sortType,
call = api.searchPostsOauth(query, afterKey, sortType, sortTime, trendingSource, APIUtils.getOAuthHeader(mAccessToken));
sortTime, trendingSource, APIUtils.getOAuthHeader(mAccessToken));
} else {
call = api.searchPostsOauth(query, afterKey, sortType, trendingSource,
APIUtils.getOAuthHeader(mAccessToken));
}
} }
} else { } else {
if (mAccessToken == null) { if (mAccessToken == null) {
if (sortTime != null) { call = api.searchPostsInSpecificSubreddit(subredditName, query,
call = api.searchPostsInSpecificSubreddit(subredditName, query, sortType, sortTime, afterKey);
sortType, sortTime, afterKey);
} else {
call = api.searchPostsInSpecificSubreddit(subredditName, query,
sortType, afterKey);
}
} else { } else {
if (sortTime != null) { call = api.searchPostsInSpecificSubredditOauth(subredditName, query,
call = api.searchPostsInSpecificSubredditOauth(subredditName, query, sortType, sortTime, afterKey,
sortType, sortTime, afterKey, APIUtils.getOAuthHeader(mAccessToken));
APIUtils.getOAuthHeader(mAccessToken));
} else {
call = api.searchPostsInSpecificSubredditOauth(subredditName, query,
sortType, afterKey,
APIUtils.getOAuthHeader(mAccessToken));
}
} }
} }
break; break;
case PostPagingSource.TYPE_MULTI_REDDIT: case PostPagingSource.TYPE_MULTI_REDDIT:
if (mAccessToken == null) { if (mAccessToken == null) {
if (sortTime != null) { call = api.getMultiRedditPosts(multiPath, afterKey, sortTime);
call = api.getMultiRedditPosts(multiPath, afterKey, sortTime);
} else {
call = api.getMultiRedditPosts(multiPath, afterKey);
}
} else { } else {
if (sortTime != null) { call = api.getMultiRedditPostsOauth(multiPath, afterKey,
call = api.getMultiRedditPostsOauth(multiPath, afterKey, sortTime, APIUtils.getOAuthHeader(mAccessToken));
sortTime, APIUtils.getOAuthHeader(mAccessToken));
} else {
call = api.getMultiRedditPostsOauth(multiPath, afterKey,
APIUtils.getOAuthHeader(mAccessToken));
}
} }
break; break;
case PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE: case PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE:
//case PostPagingSource.TYPE_ANONYMOUS_MULTIREDDIT //case PostPagingSource.TYPE_ANONYMOUS_MULTIREDDIT
if (sortTime != null) { call = api.getSubredditBestPosts(subredditName, sortType, sortTime, afterKey);
call = api.getSubredditBestPosts(subredditName, sortType, sortTime, afterKey);
} else {
call = api.getSubredditBestPosts(subredditName, sortType, afterKey);
}
break; break;
default: default:
if (sortTime != null) { call = api.getBestPosts(sortType, sortTime, afterKey,
call = api.getBestPosts(sortType, sortTime, afterKey, APIUtils.getOAuthHeader(mAccessToken));
APIUtils.getOAuthHeader(mAccessToken));
} else {
call = api.getBestPosts(sortType, afterKey, APIUtils.getOAuthHeader(mAccessToken));
}
} }
try { try {
@ -806,8 +750,8 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
this.query = event.query; this.query = event.query;
this.trendingSource = event.trendingSource; this.trendingSource = event.trendingSource;
this.postFilter = event.postFilter; this.postFilter = event.postFilter;
this.sortType = event.sortType.getType().value; this.sortType = event.sortType.getType();
this.sortTime = event.sortType.getTime() == null ? null : event.sortType.getTime().value; this.sortTime = event.sortType.getTime();
this.readPostList = event.readPostList; this.readPostList = event.readPostList;
if (sectionsPagerAdapter != null) { if (sectionsPagerAdapter != null) {

View File

@ -48,6 +48,7 @@ import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import me.saket.bettermovementmethod.BetterLinkMovementMethod; import me.saket.bettermovementmethod.BetterLinkMovementMethod;
import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.SaveThing; import ml.docilealligator.infinityforreddit.SaveThing;
import ml.docilealligator.infinityforreddit.SortType;
import ml.docilealligator.infinityforreddit.VoteThing; import ml.docilealligator.infinityforreddit.VoteThing;
import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.BaseActivity;
import ml.docilealligator.infinityforreddit.activities.CommentActivity; import ml.docilealligator.infinityforreddit.activities.CommentActivity;
@ -626,7 +627,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
((LoadMoreChildCommentsViewHolder) holder).placeholderTextView.setText(R.string.loading); ((LoadMoreChildCommentsViewHolder) holder).placeholderTextView.setText(R.string.loading);
Retrofit retrofit = mAccessToken == null ? mRetrofit : mOauthRetrofit; Retrofit retrofit = mAccessToken == null ? mRetrofit : mOauthRetrofit;
String sortType = mCommentRecyclerViewAdapterCallback.getSortType(); SortType.Type sortType = mCommentRecyclerViewAdapterCallback.getSortType();
FetchComment.fetchMoreComment(mExecutor, new Handler(), retrofit, mAccessToken, FetchComment.fetchMoreComment(mExecutor, new Handler(), retrofit, mAccessToken,
parentComment.getMoreChildrenIds(), parentComment.getMoreChildrenIds(),
mExpandChildren, mPost.getFullName(), sortType, new FetchComment.FetchMoreCommentListener() { mExpandChildren, mPost.getFullName(), sortType, new FetchComment.FetchMoreCommentListener() {
@ -1180,7 +1181,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
void retryFetchingMoreComments(); void retryFetchingMoreComments();
String getSortType(); SortType.Type getSortType();
} }
public class CommentViewHolder extends RecyclerView.ViewHolder { public class CommentViewHolder extends RecyclerView.ViewHolder {

View File

@ -57,28 +57,15 @@ public interface RedditAPI {
@GET("user/{username}/about.json?raw_json=1") @GET("user/{username}/about.json?raw_json=1")
Call<String> getUserDataOauth(@HeaderMap Map<String, String> headers, @Path("username") String username); Call<String> getUserDataOauth(@HeaderMap Map<String, String> headers, @Path("username") String username);
@GET("user/{username}/comments.json?raw_json=1")
Call<String> getUserComments(@Path("username") String username, @Query("after") String after,
@Query("sort") SortType.Type sortType);
@GET("user/{username}/comments.json?raw_json=1") @GET("user/{username}/comments.json?raw_json=1")
Call<String> getUserComments(@Path("username") String username, @Query("after") String after, Call<String> getUserComments(@Path("username") String username, @Query("after") String after,
@Query("sort") SortType.Type sortType, @Query("t") SortType.Time sortTime); @Query("sort") SortType.Type sortType, @Query("t") SortType.Time sortTime);
@GET("user/{username}/comments.json?raw_json=1")
Call<String> getUserCommentsOauth(@HeaderMap Map<String, String> headers, @Path("username") String username,
@Query("after") String after, @Query("sort") SortType.Type sortType);
@GET("user/{username}/comments.json?raw_json=1") @GET("user/{username}/comments.json?raw_json=1")
Call<String> getUserCommentsOauth(@HeaderMap Map<String, String> headers, @Path("username") String username, Call<String> getUserCommentsOauth(@HeaderMap Map<String, String> headers, @Path("username") String username,
@Query("after") String after, @Query("sort") SortType.Type sortType, @Query("after") String after, @Query("sort") SortType.Type sortType,
@Query("t") SortType.Time sortTime); @Query("t") SortType.Time sortTime);
@GET("user/{username}/{where}.json?&type=comments&raw_json=1&limit=25")
Call<String> getUserSavedCommentsOauth(@Path("username") String username, @Path("where") String where,
@Query("after") String lastItem, @Query("sort") SortType.Type sortType,
@HeaderMap Map<String, String> headers);
@GET("user/{username}/{where}.json?&type=comments&raw_json=1&limit=25") @GET("user/{username}/{where}.json?&type=comments&raw_json=1&limit=25")
Call<String> getUserSavedCommentsOauth(@Path("username") String username, @Path("where") String where, Call<String> getUserSavedCommentsOauth(@Path("username") String username, @Path("where") String where,
@Query("after") String lastItem, @Query("sort") SortType.Type sortType, @Query("after") String lastItem, @Query("sort") SortType.Type sortType,
@ -96,12 +83,12 @@ public interface RedditAPI {
@GET("subreddits/search.json?raw_json=1") @GET("subreddits/search.json?raw_json=1")
Call<String> searchSubreddits(@Query("q") String subredditName, @Query("after") String after, Call<String> searchSubreddits(@Query("q") String subredditName, @Query("after") String after,
@Query("sort") String sort, @Query("include_over_18") int nsfw, @Query("sort") SortType.Type sort, @Query("include_over_18") int nsfw,
@HeaderMap Map<String, String> headers); @HeaderMap Map<String, String> headers);
@GET("search.json?raw_json=1&type=user") @GET("search.json?raw_json=1&type=user")
Call<String> searchUsers(@Query("q") String profileName, @Query("after") String after, Call<String> searchUsers(@Query("q") String profileName, @Query("after") String after,
@Query("sort") String sort, @Query("include_over_18") int nsfw); @Query("sort") SortType.Type sort, @Query("include_over_18") int nsfw);
@FormUrlEncoded @FormUrlEncoded
@POST("api/comment") @POST("api/comment")
@ -130,19 +117,19 @@ public interface RedditAPI {
@GET("/comments/{id}/placeholder/{singleCommentId}.json?raw_json=1") @GET("/comments/{id}/placeholder/{singleCommentId}.json?raw_json=1")
Call<String> getPostAndCommentsSingleThreadByIdOauth(@Path("id") String id, @Path("singleCommentId") String singleCommentId, Call<String> getPostAndCommentsSingleThreadByIdOauth(@Path("id") String id, @Path("singleCommentId") String singleCommentId,
@Query("sort") String sortType, @Query("context") String contextNumber, @Query("sort") SortType.Type sortType, @Query("context") String contextNumber,
@HeaderMap Map<String, String> headers); @HeaderMap Map<String, String> headers);
@GET("/comments/{id}.json?raw_json=1") @GET("/comments/{id}.json?raw_json=1")
Call<String> getPostAndCommentsByIdOauth(@Path("id") String id, @Query("sort") String sortType, Call<String> getPostAndCommentsByIdOauth(@Path("id") String id, @Query("sort") SortType.Type sortType,
@HeaderMap Map<String, String> headers); @HeaderMap Map<String, String> headers);
@GET("/comments/{id}/placeholder/{singleCommentId}.json?raw_json=1") @GET("/comments/{id}/placeholder/{singleCommentId}.json?raw_json=1")
Call<String> getPostAndCommentsSingleThreadById(@Path("id") String id, @Path("singleCommentId") String singleCommentId, Call<String> getPostAndCommentsSingleThreadById(@Path("id") String id, @Path("singleCommentId") String singleCommentId,
@Query("sort") String sortType, @Query("context") String contextNumber); @Query("sort") SortType.Type sortType, @Query("context") String contextNumber);
@GET("/comments/{id}.json?raw_json=1") @GET("/comments/{id}.json?raw_json=1")
Call<String> getPostAndCommentsById(@Path("id") String id, @Query("sort") String sortType); Call<String> getPostAndCommentsById(@Path("id") String id, @Query("sort") SortType.Type sortType);
@Multipart @Multipart
@POST(".") @POST(".")
@ -336,106 +323,58 @@ public interface RedditAPI {
@HeaderMap Map<String, String> headers); @HeaderMap Map<String, String> headers);
@GET("{sortType}?raw_json=1") @GET("{sortType}?raw_json=1")
Call<String> getBestPosts(@Path("sortType") String sortType, @Query("after") String lastItem, @HeaderMap Map<String, String> headers); Call<String> getBestPosts(@Path("sortType") SortType.Type sortType, @Query("t") SortType.Time sortTime,
@GET("{sortType}?raw_json=1")
Call<String> getBestPosts(@Path("sortType") String sortType, @Query("t") String sortTime,
@Query("after") String lastItem, @HeaderMap Map<String, String> headers); @Query("after") String lastItem, @HeaderMap Map<String, String> headers);
@GET("r/{subredditName}/{sortType}.json?raw_json=1&limit=25&always_show_media=1") @GET("r/{subredditName}/{sortType}.json?raw_json=1&limit=25&always_show_media=1")
Call<String> getSubredditBestPostsOauth(@Path("subredditName") String subredditName, @Path("sortType") String sortType, Call<String> getSubredditBestPostsOauth(@Path("subredditName") String subredditName, @Path("sortType") SortType.Type sortType,
@Query("after") String lastItem, @HeaderMap Map<String, String> headers); @Query("t") SortType.Time sortTime, @Query("after") String lastItem,
@GET("r/{subredditName}/{sortType}.json?raw_json=1&limit=25&always_show_media=1")
Call<String> getSubredditBestPostsOauth(@Path("subredditName") String subredditName, @Path("sortType") String sortType,
@Query("t") String sortTime, @Query("after") String lastItem,
@HeaderMap Map<String, String> headers); @HeaderMap Map<String, String> headers);
@GET("r/{subredditName}/{sortType}.json?raw_json=1&limit=25&always_show_media=1") @GET("r/{subredditName}/{sortType}.json?raw_json=1&limit=25&always_show_media=1")
Call<String> getSubredditBestPosts(@Path("subredditName") String subredditName, @Path("sortType") String sortType, Call<String> getSubredditBestPosts(@Path("subredditName") String subredditName, @Path("sortType") SortType.Type sortType,
@Query("after") String lastItem); @Query("t") SortType.Time sortTime, @Query("after") String lastItem);
@GET("r/{subredditName}/{sortType}.json?raw_json=1&limit=25&always_show_media=1")
Call<String> getSubredditBestPosts(@Path("subredditName") String subredditName, @Path("sortType") String sortType,
@Query("t") String sortTime, @Query("after") String lastItem);
@GET("user/{username}/{where}.json?&type=links&raw_json=1&limit=25") @GET("user/{username}/{where}.json?&type=links&raw_json=1&limit=25")
Call<String> getUserPostsOauth(@Path("username") String username, @Path("where") String where, Call<String> getUserPostsOauth(@Path("username") String username, @Path("where") String where,
@Query("after") String lastItem, @Query("sort") String sortType, @HeaderMap Map<String, String> headers); @Query("after") String lastItem, @Query("sort") SortType.Type sortType,
@Query("t") SortType.Time sortTime, @HeaderMap Map<String, String> headers);
@GET("user/{username}/{where}.json?&type=links&raw_json=1&limit=25")
Call<String> getUserPostsOauth(@Path("username") String username, @Path("where") String where,
@Query("after") String lastItem, @Query("sort") String sortType,
@Query("t") String sortTime, @HeaderMap Map<String, String> headers);
@GET("user/{username}/submitted.json?raw_json=1&limit=25") @GET("user/{username}/submitted.json?raw_json=1&limit=25")
Call<String> getUserPosts(@Path("username") String username, @Query("after") String lastItem, Call<String> getUserPosts(@Path("username") String username, @Query("after") String lastItem,
@Query("sort") String sortType); @Query("sort") SortType.Type sortType, @Query("t") SortType.Time sortTime);
@GET("user/{username}/submitted.json?raw_json=1&limit=25")
Call<String> getUserPosts(@Path("username") String username, @Query("after") String lastItem,
@Query("sort") String sortType, @Query("t") String sortTime);
@GET("search.json?include_over_18=1&raw_json=1&type=link") @GET("search.json?include_over_18=1&raw_json=1&type=link")
Call<String> searchPostsOauth(@Query("q") String query, @Query("after") String after, Call<String> searchPostsOauth(@Query("q") String query, @Query("after") String after,
@Query("sort") String sort, @Query("source") String source, @Query("sort") SortType.Type sort, @Query("t") SortType.Time sortTime,
@HeaderMap Map<String, String> headers);
@GET("search.json?include_over_18=1&raw_json=1&type=link")
Call<String> searchPostsOauth(@Query("q") String query, @Query("after") String after,
@Query("sort") String sort, @Query("t") String sortTime,
@Query("source") String source, @Query("source") String source,
@HeaderMap Map<String, String> headers); @HeaderMap Map<String, String> headers);
@GET("search.json?include_over_18=1&raw_json=1&type=link") @GET("search.json?include_over_18=1&raw_json=1&type=link")
Call<String> searchPosts(@Query("q") String query, @Query("after") String after, Call<String> searchPosts(@Query("q") String query, @Query("after") String after,
@Query("sort") String sort, @Query("source") String source); @Query("sort") SortType.Type sort, @Query("t") SortType.Time sortTime,
@GET("search.json?include_over_18=1&raw_json=1&type=link")
Call<String> searchPosts(@Query("q") String query, @Query("after") String after,
@Query("sort") String sort, @Query("t") String sortTime,
@Query("source") String source); @Query("source") String source);
@GET("r/{subredditName}/search.json?include_over_18=1&raw_json=1&type=link&restrict_sr=true") @GET("r/{subredditName}/search.json?include_over_18=1&raw_json=1&type=link&restrict_sr=true")
Call<String> searchPostsInSpecificSubredditOauth(@Path("subredditName") String subredditName, Call<String> searchPostsInSpecificSubredditOauth(@Path("subredditName") String subredditName,
@Query("q") String query, @Query("sort") String sort, @Query("q") String query, @Query("sort") SortType.Type sort,
@Query("after") String after, @Query("t") SortType.Time sortTime, @Query("after") String after,
@HeaderMap Map<String, String> headers); @HeaderMap Map<String, String> headers);
@GET("r/{subredditName}/search.json?include_over_18=1&raw_json=1&type=link&restrict_sr=true") @GET("r/{subredditName}/search.json?include_over_18=1&raw_json=1&type=link&restrict_sr=true")
Call<String> searchPostsInSpecificSubredditOauth(@Path("subredditName") String subredditName,
@Query("q") String query, @Query("sort") String sort,
@Query("t") String sortTime, @Query("after") String after,
@HeaderMap Map<String, String> headers);
@GET("r/{subredditName}/search.json?include_over_18=1&raw_json=1&type=link&restrict_sr=true")
Call<String> searchPostsInSpecificSubreddit(@Path("subredditName") String subredditName, Call<String> searchPostsInSpecificSubreddit(@Path("subredditName") String subredditName,
@Query("q") String query, @Query("sort") String sort, @Query("q") String query, @Query("sort") SortType.Type sort,
@Query("after") String after); @Query("t") SortType.Time sortTime, @Query("after") String after);
@GET("r/{subredditName}/search.json?include_over_18=1&raw_json=1&type=link&restrict_sr=true")
Call<String> searchPostsInSpecificSubreddit(@Path("subredditName") String subredditName,
@Query("q") String query, @Query("sort") String sort,
@Query("t") String sortTime, @Query("after") String after);
@GET("{multipath}?raw_json=1") @GET("{multipath}?raw_json=1")
Call<String> getMultiRedditPosts(@Path(value = "multipath", encoded = true) String multiPath, Call<String> getMultiRedditPosts(@Path(value = "multipath", encoded = true) String multiPath,
@Query("after") String after); @Query("after") String after, @Query("t") SortType.Time sortTime);
@GET("{multipath}?raw_json=1")
Call<String> getMultiRedditPosts(@Path(value = "multipath", encoded = true) String multiPath,
@Query("after") String after, @Query("t") String sortTime);
@GET("{multipath}.json?raw_json=1") @GET("{multipath}.json?raw_json=1")
Call<String> getMultiRedditPostsOauth(@Path(value = "multipath", encoded = true) String multiPath, Call<String> getMultiRedditPostsOauth(@Path(value = "multipath", encoded = true) String multiPath,
@Query("after") String after, @Query("t") String sortTime, @Query("after") String after, @Query("t") SortType.Time sortTime,
@HeaderMap Map<String, String> headers); @HeaderMap Map<String, String> headers);
@GET("{multipath}.json?raw_json=1")
Call<String> getMultiRedditPostsOauth(@Path(value = "multipath", encoded = true) String multiPath,
@Query("after") String after, @HeaderMap Map<String, String> headers);
@POST("r/{subredditName}/api/delete_sr_icon") @POST("r/{subredditName}/api/delete_sr_icon")
Call<String> deleteSrIcon(@HeaderMap Map<String, String> headers, @Path("subredditName") String subredditName); Call<String> deleteSrIcon(@HeaderMap Map<String, String> headers, @Path("subredditName") String subredditName);
@ -458,9 +397,9 @@ public interface RedditAPI {
@FormUrlEncoded @FormUrlEncoded
@POST("/api/morechildren.json?raw_json=1&api_type=json") @POST("/api/morechildren.json?raw_json=1&api_type=json")
Call<String> moreChildren(@Field("link_id") String linkId, @Field("children") String children, @Field("sort") String sort); Call<String> moreChildren(@Field("link_id") String linkId, @Field("children") String children, @Field("sort") SortType.Type sort);
@FormUrlEncoded @FormUrlEncoded
@POST("/api/morechildren.json?raw_json=1&api_type=json") @POST("/api/morechildren.json?raw_json=1&api_type=json")
Call<String> moreChildrenOauth(@Field("link_id") String linkId, @Field("children") String children, @Field("sort") String sort, @HeaderMap Map<String, String> headers); Call<String> moreChildrenOauth(@Field("link_id") String linkId, @Field("children") String children, @Field("sort") SortType.Type sort, @HeaderMap Map<String, String> headers);
} }

View File

@ -52,10 +52,10 @@ public class PostCommentSortTypeBottomSheetFragment extends LandscapeExpandedRou
// Required empty public constructor // Required empty public constructor
} }
public static PostCommentSortTypeBottomSheetFragment getNewInstance(String currentSortTypeValue) { public static PostCommentSortTypeBottomSheetFragment getNewInstance(SortType.Type currentSortType) {
PostCommentSortTypeBottomSheetFragment fragment = new PostCommentSortTypeBottomSheetFragment(); PostCommentSortTypeBottomSheetFragment fragment = new PostCommentSortTypeBottomSheetFragment();
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString(EXTRA_CURRENT_SORT_TYPE, currentSortTypeValue); bundle.putSerializable(EXTRA_CURRENT_SORT_TYPE, currentSortType);
fragment.setArguments(bundle); fragment.setArguments(bundle);
return fragment; return fragment;
} }
@ -68,22 +68,22 @@ public class PostCommentSortTypeBottomSheetFragment extends LandscapeExpandedRou
View rootView = inflater.inflate(R.layout.fragment_post_comment_sort_type_bottom_sheet, container, false); View rootView = inflater.inflate(R.layout.fragment_post_comment_sort_type_bottom_sheet, container, false);
ButterKnife.bind(this, rootView); ButterKnife.bind(this, rootView);
String currentSortType = getArguments().getString(EXTRA_CURRENT_SORT_TYPE); SortType.Type currentSortType = (SortType.Type) getArguments().getSerializable(EXTRA_CURRENT_SORT_TYPE);
if (currentSortType.equals(SortType.Type.BEST.value) || currentSortType.equals(SortType.Type.CONFIDENCE.value)) { if (currentSortType.equals(SortType.Type.BEST) || currentSortType.equals(SortType.Type.CONFIDENCE)) {
confidenceTypeTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(confidenceTypeTextView.getCompoundDrawablesRelative()[0], null, AppCompatResources.getDrawable(activity, R.drawable.ic_round_check_circle_day_night_24dp), null); confidenceTypeTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(confidenceTypeTextView.getCompoundDrawablesRelative()[0], null, AppCompatResources.getDrawable(activity, R.drawable.ic_round_check_circle_day_night_24dp), null);
} else if (currentSortType.equals(SortType.Type.TOP.value)) { } else if (currentSortType.equals(SortType.Type.TOP)) {
topTypeTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(topTypeTextView.getCompoundDrawablesRelative()[0], null, AppCompatResources.getDrawable(activity, R.drawable.ic_round_check_circle_day_night_24dp), null); topTypeTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(topTypeTextView.getCompoundDrawablesRelative()[0], null, AppCompatResources.getDrawable(activity, R.drawable.ic_round_check_circle_day_night_24dp), null);
} else if (currentSortType.equals(SortType.Type.NEW.value)) { } else if (currentSortType.equals(SortType.Type.NEW)) {
newTypeTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(newTypeTextView.getCompoundDrawablesRelative()[0], null, AppCompatResources.getDrawable(activity, R.drawable.ic_round_check_circle_day_night_24dp), null); newTypeTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(newTypeTextView.getCompoundDrawablesRelative()[0], null, AppCompatResources.getDrawable(activity, R.drawable.ic_round_check_circle_day_night_24dp), null);
} else if (currentSortType.equals(SortType.Type.CONTROVERSIAL.value)) { } else if (currentSortType.equals(SortType.Type.CONTROVERSIAL)) {
controversialTypeTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(controversialTypeTextView.getCompoundDrawablesRelative()[0], null, AppCompatResources.getDrawable(activity, R.drawable.ic_round_check_circle_day_night_24dp), null); controversialTypeTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(controversialTypeTextView.getCompoundDrawablesRelative()[0], null, AppCompatResources.getDrawable(activity, R.drawable.ic_round_check_circle_day_night_24dp), null);
} else if (currentSortType.equals(SortType.Type.OLD.value)) { } else if (currentSortType.equals(SortType.Type.OLD)) {
oldTypeTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(oldTypeTextView.getCompoundDrawablesRelative()[0], null, AppCompatResources.getDrawable(activity, R.drawable.ic_round_check_circle_day_night_24dp), null); oldTypeTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(oldTypeTextView.getCompoundDrawablesRelative()[0], null, AppCompatResources.getDrawable(activity, R.drawable.ic_round_check_circle_day_night_24dp), null);
} else if (currentSortType.equals(SortType.Type.RANDOM.value)) { } else if (currentSortType.equals(SortType.Type.RANDOM)) {
randomTypeTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(randomTypeTextView.getCompoundDrawablesRelative()[0], null, AppCompatResources.getDrawable(activity, R.drawable.ic_round_check_circle_day_night_24dp), null); randomTypeTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(randomTypeTextView.getCompoundDrawablesRelative()[0], null, AppCompatResources.getDrawable(activity, R.drawable.ic_round_check_circle_day_night_24dp), null);
} else if (currentSortType.equals(SortType.Type.QA.value)) { } else if (currentSortType.equals(SortType.Type.QA)) {
qaTypeTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(qaTypeTextView.getCompoundDrawablesRelative()[0], null, AppCompatResources.getDrawable(activity, R.drawable.ic_round_check_circle_day_night_24dp), null); qaTypeTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(qaTypeTextView.getCompoundDrawablesRelative()[0], null, AppCompatResources.getDrawable(activity, R.drawable.ic_round_check_circle_day_night_24dp), null);
} else if (currentSortType.equals(SortType.Type.LIVE.value)) { } else if (currentSortType.equals(SortType.Type.LIVE)) {
liveTypeTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(liveTypeTextView.getCompoundDrawablesRelative()[0], null, AppCompatResources.getDrawable(activity, R.drawable.ic_round_check_circle_day_night_24dp), null); liveTypeTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(liveTypeTextView.getCompoundDrawablesRelative()[0], null, AppCompatResources.getDrawable(activity, R.drawable.ic_round_check_circle_day_night_24dp), null);
} }

View File

@ -9,6 +9,7 @@ import java.util.ArrayList;
import java.util.Locale; import java.util.Locale;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import ml.docilealligator.infinityforreddit.SortType;
import ml.docilealligator.infinityforreddit.apis.RedditAPI; import ml.docilealligator.infinityforreddit.apis.RedditAPI;
import ml.docilealligator.infinityforreddit.utils.APIUtils; import ml.docilealligator.infinityforreddit.utils.APIUtils;
import retrofit2.Call; import retrofit2.Call;
@ -19,7 +20,7 @@ import retrofit2.Retrofit;
public class FetchComment { public class FetchComment {
public static void fetchComments(Executor executor, Handler handler, Retrofit retrofit, public static void fetchComments(Executor executor, Handler handler, Retrofit retrofit,
@Nullable String accessToken, String article, @Nullable String accessToken, String article,
String commentId, String sortType, String contextNumber, boolean expandChildren, String commentId, SortType.Type sortType, String contextNumber, boolean expandChildren,
Locale locale, FetchCommentListener fetchCommentListener) { Locale locale, FetchCommentListener fetchCommentListener) {
RedditAPI api = retrofit.create(RedditAPI.class); RedditAPI api = retrofit.create(RedditAPI.class);
Call<String> comments; Call<String> comments;
@ -73,7 +74,7 @@ public class FetchComment {
@Nullable String accessToken, @Nullable String accessToken,
ArrayList<String> allChildren, ArrayList<String> allChildren,
boolean expandChildren, String postFullName, boolean expandChildren, String postFullName,
String sortType, SortType.Type sortType,
FetchMoreCommentListener fetchMoreCommentListener) { FetchMoreCommentListener fetchMoreCommentListener) {
if (allChildren == null) { if (allChildren == null) {
return; return;

View File

@ -210,7 +210,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
@State @State
String mMessageFullname; String mMessageFullname;
@State @State
String sortType; SortType.Type sortType;
@State @State
boolean mRespectSubredditRecommendedSortType; boolean mRespectSubredditRecommendedSortType;
@State @State
@ -553,13 +553,12 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
mMessageFullname = getArguments().getString(EXTRA_MESSAGE_FULLNAME); mMessageFullname = getArguments().getString(EXTRA_MESSAGE_FULLNAME);
if (!mRespectSubredditRecommendedSortType || isSingleCommentThreadMode) { if (!mRespectSubredditRecommendedSortType || isSingleCommentThreadMode) {
SortType.Type sortTypeType = loadSortType(); sortType = loadSortType();
activity.setTitle(sortTypeType.fullName); activity.setTitle(sortType.fullName);
sortType = sortTypeType.value;
} }
} else { } else {
if (sortType != null) { if (sortType != null) {
activity.setTitle(SortType.Type.valueOf(sortType.toUpperCase()).fullName); activity.setTitle(sortType.fullName);
} }
} }
@ -621,7 +620,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
} }
@Override @Override
public String getSortType() { public SortType.Type getSortType() {
return sortType; return sortType;
} }
}); });
@ -816,12 +815,12 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
if (children != null) { if (children != null) {
children.clear(); children.clear();
} }
this.sortType = sortType.getType().value; this.sortType = sortType.getType();
if (!mSharedPreferences.getBoolean(SharedPreferencesUtils.RESPECT_SUBREDDIT_RECOMMENDED_COMMENT_SORT_TYPE, false) if (!mSharedPreferences.getBoolean(SharedPreferencesUtils.RESPECT_SUBREDDIT_RECOMMENDED_COMMENT_SORT_TYPE, false)
&& mSharedPreferences.getBoolean(SharedPreferencesUtils.SAVE_SORT_TYPE, true)) { && mSharedPreferences.getBoolean(SharedPreferencesUtils.SAVE_SORT_TYPE, true)) {
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_POST_COMMENT, sortType.getType().name()).apply(); mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_POST_COMMENT, sortType.getType().name()).apply();
} }
fetchCommentsRespectRecommendedSort(false, false, sortType.getType().value); fetchCommentsRespectRecommendedSort(false, false, sortType.getType());
} }
@NonNull @NonNull
@ -1331,7 +1330,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
} }
@Override @Override
public String getSortType() { public SortType.Type getSortType() {
return sortType; return sortType;
} }
}); });
@ -1429,7 +1428,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
}); });
} }
private void fetchCommentsRespectRecommendedSort(boolean changeRefreshState, boolean checkSortState, String sortType) { private void fetchCommentsRespectRecommendedSort(boolean changeRefreshState, boolean checkSortState, SortType.Type sortType) {
if (mRespectSubredditRecommendedSortType && mPost != null) { if (mRespectSubredditRecommendedSortType && mPost != null) {
FetchSubredditData.fetchSubredditData(mOauthRetrofit, mRetrofit, mPost.getSubredditName(), mAccessToken, FetchSubredditData.fetchSubredditData(mOauthRetrofit, mRetrofit, mPost.getSubredditName(), mAccessToken,
new FetchSubredditData.FetchSubredditDataListener() { new FetchSubredditData.FetchSubredditDataListener() {
@ -1444,7 +1443,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
sortTypeType = SortType.Type.valueOf(suggestedCommentSort.toUpperCase(Locale.US)); sortTypeType = SortType.Type.valueOf(suggestedCommentSort.toUpperCase(Locale.US));
} }
activity.setTitle(sortTypeType.fullName); activity.setTitle(sortTypeType.fullName);
ViewPostDetailFragment.this.sortType = sortTypeType.value; ViewPostDetailFragment.this.sortType = sortTypeType;
fetchComments(changeRefreshState, checkSortState, ViewPostDetailFragment.this.sortType); fetchComments(changeRefreshState, checkSortState, ViewPostDetailFragment.this.sortType);
} }
@ -1453,7 +1452,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
mRespectSubredditRecommendedSortType = false; mRespectSubredditRecommendedSortType = false;
SortType.Type sortTypeType = loadSortType(); SortType.Type sortTypeType = loadSortType();
activity.setTitle(sortTypeType.fullName); activity.setTitle(sortTypeType.fullName);
ViewPostDetailFragment.this.sortType = sortTypeType.value; ViewPostDetailFragment.this.sortType = sortTypeType;
} }
}); });
} else { } else {
@ -1461,7 +1460,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
} }
} }
private void fetchComments(boolean changeRefreshState, boolean checkSortState, String sortType) { private void fetchComments(boolean changeRefreshState, boolean checkSortState, SortType.Type sortType) {
isFetchingComments = true; isFetchingComments = true;
mCommentsAdapter.setSingleComment(mSingleCommentId, isSingleCommentThreadMode); mCommentsAdapter.setSingleComment(mSingleCommentId, isSingleCommentThreadMode);
mCommentsAdapter.initiallyLoading(); mCommentsAdapter.initiallyLoading();

View File

@ -9,6 +9,7 @@ import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import ml.docilealligator.infinityforreddit.SortType;
import ml.docilealligator.infinityforreddit.apis.RedditAPI; import ml.docilealligator.infinityforreddit.apis.RedditAPI;
import ml.docilealligator.infinityforreddit.utils.APIUtils; import ml.docilealligator.infinityforreddit.utils.APIUtils;
import retrofit2.Call; import retrofit2.Call;
@ -54,7 +55,7 @@ public class FetchSubredditData {
}); });
} }
static void fetchSubredditListingData(Retrofit retrofit, String query, String after, String sortType, String accessToken, static void fetchSubredditListingData(Retrofit retrofit, String query, String after, SortType.Type sortType, String accessToken,
boolean nsfw, final FetchSubredditListingDataListener fetchSubredditListingDataListener) { boolean nsfw, final FetchSubredditListingDataListener fetchSubredditListingDataListener) {
RedditAPI api = retrofit.create(RedditAPI.class); RedditAPI api = retrofit.create(RedditAPI.class);

View File

@ -52,7 +52,7 @@ public class SubredditListingDataSource extends PageKeyedDataSource<String, Subr
public void loadInitial(@NonNull LoadInitialParams<String> params, @NonNull LoadInitialCallback<String, SubredditData> callback) { public void loadInitial(@NonNull LoadInitialParams<String> params, @NonNull LoadInitialCallback<String, SubredditData> callback) {
initialLoadStateLiveData.postValue(NetworkState.LOADING); initialLoadStateLiveData.postValue(NetworkState.LOADING);
FetchSubredditData.fetchSubredditListingData(retrofit, query, null, sortType.getType().value, accessToken, nsfw, FetchSubredditData.fetchSubredditListingData(retrofit, query, null, sortType.getType(), accessToken, nsfw,
new FetchSubredditData.FetchSubredditListingDataListener() { new FetchSubredditData.FetchSubredditListingDataListener() {
@Override @Override
public void onFetchSubredditListingDataSuccess(ArrayList<SubredditData> subredditData, String after) { public void onFetchSubredditListingDataSuccess(ArrayList<SubredditData> subredditData, String after) {
@ -87,7 +87,7 @@ public class SubredditListingDataSource extends PageKeyedDataSource<String, Subr
return; return;
} }
FetchSubredditData.fetchSubredditListingData(retrofit, query, params.key, sortType.getType().value, accessToken, nsfw, FetchSubredditData.fetchSubredditListingData(retrofit, query, params.key, sortType.getType(), accessToken, nsfw,
new FetchSubredditData.FetchSubredditListingDataListener() { new FetchSubredditData.FetchSubredditListingDataListener() {
@Override @Override
public void onFetchSubredditListingDataSuccess(ArrayList<SubredditData> subredditData, String after) { public void onFetchSubredditListingDataSuccess(ArrayList<SubredditData> subredditData, String after) {

View File

@ -5,6 +5,7 @@ import androidx.annotation.NonNull;
import java.util.ArrayList; import java.util.ArrayList;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SortType;
import ml.docilealligator.infinityforreddit.apis.RedditAPI; import ml.docilealligator.infinityforreddit.apis.RedditAPI;
import ml.docilealligator.infinityforreddit.utils.APIUtils; import ml.docilealligator.infinityforreddit.utils.APIUtils;
import retrofit2.Call; import retrofit2.Call;
@ -53,7 +54,7 @@ public class FetchUserData {
}); });
} }
public static void fetchUserListingData(Retrofit retrofit, String query, String after, String sortType, boolean nsfw, public static void fetchUserListingData(Retrofit retrofit, String query, String after, SortType.Type sortType, boolean nsfw,
FetchUserListingDataListener fetchUserListingDataListener) { FetchUserListingDataListener fetchUserListingDataListener) {
RedditAPI api = retrofit.create(RedditAPI.class); RedditAPI api = retrofit.create(RedditAPI.class);

View File

@ -50,7 +50,7 @@ public class UserListingDataSource extends PageKeyedDataSource<String, UserData>
public void loadInitial(@NonNull PageKeyedDataSource.LoadInitialParams<String> params, @NonNull PageKeyedDataSource.LoadInitialCallback<String, UserData> callback) { public void loadInitial(@NonNull PageKeyedDataSource.LoadInitialParams<String> params, @NonNull PageKeyedDataSource.LoadInitialCallback<String, UserData> callback) {
initialLoadStateLiveData.postValue(NetworkState.LOADING); initialLoadStateLiveData.postValue(NetworkState.LOADING);
FetchUserData.fetchUserListingData(retrofit, query, null, sortType.getType().value, nsfw, FetchUserData.fetchUserListingData(retrofit, query, null, sortType.getType(), nsfw,
new FetchUserData.FetchUserListingDataListener() { new FetchUserData.FetchUserListingDataListener() {
@Override @Override
public void onFetchUserListingDataSuccess(ArrayList<UserData> UserData, String after) { public void onFetchUserListingDataSuccess(ArrayList<UserData> UserData, String after) {
@ -81,7 +81,7 @@ public class UserListingDataSource extends PageKeyedDataSource<String, UserData>
return; return;
} }
FetchUserData.fetchUserListingData(retrofit, query, params.key, sortType.getType().value, nsfw, FetchUserData.fetchUserListingData(retrofit, query, params.key, sortType.getType(), nsfw,
new FetchUserData.FetchUserListingDataListener() { new FetchUserData.FetchUserListingDataListener() {
@Override @Override
public void onFetchUserListingDataSuccess(ArrayList<UserData> UserData, String after) { public void onFetchUserListingDataSuccess(ArrayList<UserData> UserData, String after) {