Permalink
Browse files

Added Best sort for front page

  • Loading branch information...
QuantumBadger committed Jun 24, 2018
1 parent a378ff2 commit 1e0538f32c52c9b5d3a72d68f3c4488ac546754f
View
@@ -3,6 +3,7 @@ New icon (based on concept by marty-arts)
Left-handed mode preference
Allow marking as NSFW/spoilers when submitting post
Show post/comment immediately after submitting
Added "Best" sort for front page
Fixed search to match new reddit API (thanks to ianmcxa)
Visual fix for comments containing only whitespace (thanks to Briscoooe)
Updated Dutch translation (thanks to Ghostkeeper)
@@ -137,6 +137,7 @@ public boolean onCreateOptionsMenu(final Menu menu) {
controller.isUserCommentListing(),
false,
controller.isSortable(),
false,
null,
false,
true,
@@ -677,6 +677,8 @@ public boolean onCreateOptionsMenu(final Menu menu) {
final boolean postsSortable = postListingController != null && postListingController.isSortable();
final boolean commentsSortable = commentListingController != null && commentListingController.isSortable();
final boolean isFrontPage = postListingController != null && postListingController.isFrontPage();
final RedditAccount user = RedditAccountManager.getInstance(this).getDefaultAccount();
final RedditSubredditSubscriptionManager.SubredditSubscriptionState subredditSubscriptionState;
final RedditSubredditSubscriptionManager subredditSubscriptionManager
@@ -732,8 +734,10 @@ public boolean onCreateOptionsMenu(final Menu menu) {
commentsVisible,
false,
false,
false, postsSortable,
false,
postsSortable,
commentsSortable,
isFrontPage,
subredditSubscriptionState,
postsVisible && subredditDescription != null && subredditDescription.length() > 0,
true,
@@ -98,7 +98,23 @@ public void onCreate(final Bundle savedInstanceState) {
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
OptionsMenuUtility.prepare(this, menu, false, false, true, false, false, false, false, false, null, false, false, null, null);
OptionsMenuUtility.prepare(
this,
menu,
false,
false,
true,
false,
false,
false,
false,
false,
false,
null,
false,
false,
null,
null);
if(mFragment != null) {
mFragment.onCreateOptionsMenu(menu);
@@ -74,6 +74,7 @@
final boolean subredditsVisible, final boolean postsVisible, final boolean commentsVisible,
final boolean areSearchResults, final boolean isUserPostListing,
final boolean isUserCommentListing, final boolean postsSortable, final boolean commentsSortable,
final boolean isFrontPage,
final RedditSubredditSubscriptionManager.SubredditSubscriptionState subredditSubscriptionState,
final boolean subredditHasSidebar,
final boolean pastCommentsSupported,
@@ -88,12 +89,11 @@
} else if(!subredditsVisible && postsVisible && !commentsVisible) {
if(postsSortable) {
if (areSearchResults)
addAllSearchSorts(activity, menu, true);
else if(isUserPostListing)
addAllPostSorts(activity, menu, true, false);
else
addAllPostSorts(activity, menu, true, true);
addAllPostSorts(activity, menu, true, !isUserPostListing, isFrontPage);
}
add(activity, menu, Option.REFRESH_POSTS, false);
if(optionsMenuItemsPrefs.contains(OptionsMenuItemsPref.PAST)) add(activity, menu, Option.PAST_POSTS, false);
@@ -145,7 +145,7 @@ else if(commentsSortable && isUserCommentListing)
if (areSearchResults)
addAllSearchSorts(activity, sortMenu, false);
else
addAllPostSorts(activity, sortMenu, false, true);
addAllPostSorts(activity, sortMenu, false, !isUserPostListing, isFrontPage);
}
if(commentsSortable) addAllCommentSorts(activity, sortMenu, false);
@@ -163,7 +163,7 @@ else if(commentsSortable && isUserCommentListing)
if (areSearchResults)
addAllSearchSorts(activity, menu, true);
else
addAllPostSorts(activity, menu, true, true);
addAllPostSorts(activity, menu, true, !isUserPostListing, isFrontPage);
}
add(activity, menu, Option.PAST_POSTS, false);
}
@@ -482,7 +482,12 @@ public boolean onMenuItemClick(final MenuItem item) {
}
}
private static void addAllPostSorts(final AppCompatActivity activity, final Menu menu, final boolean icon, final boolean includeRising) {
private static void addAllPostSorts(
final AppCompatActivity activity,
final Menu menu,
final boolean icon,
final boolean includeRising,
final boolean includeBest) {
final SubMenu sortPosts = menu.addSubMenu(R.string.options_sort_posts);
@@ -496,6 +501,8 @@ private static void addAllPostSorts(final AppCompatActivity activity, final Menu
if(includeRising)
addSort(activity, sortPosts, R.string.sort_posts_rising, PostSort.RISING);
addSort(activity, sortPosts, R.string.sort_posts_controversial, PostSort.CONTROVERSIAL);
if(includeBest)
addSort(activity, sortPosts, R.string.sort_posts_best, PostSort.BEST);
final SubMenu sortPostsTop = sortPosts.addSubMenu(R.string.sort_posts_top);
@@ -191,8 +191,10 @@ public boolean onCreateOptionsMenu(final Menu menu) {
false,
controller.isSearchResults(),
controller.isUserPostListing(),
false, controller.isSortable(),
false,
controller.isSortable(),
true,
controller.isFrontPage(),
subredditSubscriptionState,
subredditDescription != null && subredditDescription.length() > 0,
false,
@@ -71,6 +71,11 @@ public boolean isSortable() {
|| (url.pathType() == RedditURLParser.SEARCH_POST_LISTING_URL);
}
public boolean isFrontPage() {
return url.pathType() == RedditURLParser.SUBREDDIT_POST_LISTING_URL
&& url.asSubredditPostListURL().type == SubredditPostListURL.Type.FRONTPAGE;
}
public final void setSort(final PostSort order) {
if(url.pathType() == RedditURLParser.SUBREDDIT_POST_LISTING_URL) {
url = url.asSubredditPostListURL().sort(order);
@@ -23,7 +23,7 @@
import org.quantumbadger.redreader.common.General;
public enum PostSort {
HOT, NEW, RISING, TOP_HOUR, TOP_DAY, TOP_WEEK, TOP_MONTH, TOP_YEAR, TOP_ALL, CONTROVERSIAL,
HOT, NEW, RISING, TOP_HOUR, TOP_DAY, TOP_WEEK, TOP_MONTH, TOP_YEAR, TOP_ALL, CONTROVERSIAL, BEST,
// Sorts related to Search Listings
RELEVANCE, COMMENTS, TOP;
@@ -53,6 +53,9 @@ public static PostSort parse(@Nullable String sort, @Nullable String t) {
} else if(sort.equals("new")) {
return NEW;
} else if(sort.equals("best")) {
return BEST;
} else if(sort.equals("controversial")) {
return CONTROVERSIAL;
@@ -104,6 +107,7 @@ public void addToSubredditListingUri(@NonNull final Uri.Builder builder) {
case NEW:
case RISING:
case CONTROVERSIAL:
case BEST:
builder.appendEncodedPath(General.asciiLowercase(name()));
break;
@@ -1078,4 +1078,6 @@
<string name="comment_reply_done_norefresh">Reply sent.</string>
<string name="sort_posts_best">Best</string>
</resources>

0 comments on commit 1e0538f

Please sign in to comment.