Sort downloads by size (#6659)
This commit is contained in:
parent
7229cb40e9
commit
922395a448
|
@ -159,6 +159,7 @@ public class CompletedDownloadsFragment extends Fragment
|
|||
menu.findItem(R.id.sort_random).setVisible(false);
|
||||
menu.findItem(R.id.sort_smart_shuffle).setVisible(false);
|
||||
menu.findItem(R.id.keep_sorted).setVisible(false);
|
||||
menu.findItem(R.id.sort_size).setVisible(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -32,6 +32,10 @@ public class MenuItemToSortOrderConverter {
|
|||
return SortOrder.SMART_SHUFFLE_OLD_NEW;
|
||||
} else if (itemId == R.id.sort_smart_shuffle_desc) {
|
||||
return SortOrder.SMART_SHUFFLE_NEW_OLD;
|
||||
} else if (itemId == R.id.sort_size_small_large) {
|
||||
return SortOrder.SIZE_SMALL_LARGE;
|
||||
} else if (itemId == R.id.sort_size_large_small) {
|
||||
return SortOrder.SIZE_LARGE_SMALL;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
|
@ -75,6 +75,22 @@
|
|||
android:title="@string/sort_new_old"/>
|
||||
</menu>
|
||||
</item>
|
||||
|
||||
<item
|
||||
android:id="@+id/sort_size"
|
||||
android:title="@string/size"
|
||||
android:visible="false">
|
||||
|
||||
<menu>
|
||||
<item
|
||||
android:id="@+id/sort_size_small_large"
|
||||
android:title="@string/sort_small_large"/>
|
||||
<item
|
||||
android:id="@+id/sort_size_large_small"
|
||||
android:title="@string/sort_large_small"/>
|
||||
</menu>
|
||||
</item>
|
||||
|
||||
<item
|
||||
android:id="@+id/keep_sorted"
|
||||
android:title="@string/keep_sorted"
|
||||
|
|
|
@ -72,6 +72,12 @@ public class FeedItemPermutors {
|
|||
case SMART_SHUFFLE_NEW_OLD:
|
||||
permutor = (queue) -> smartShuffle(queue, false);
|
||||
break;
|
||||
case SIZE_SMALL_LARGE:
|
||||
comparator = (f1, f2) -> Long.compare(size(f1), size(f2));
|
||||
break;
|
||||
case SIZE_LARGE_SMALL:
|
||||
comparator = (f1, f2) -> Long.compare(size(f2), size(f1));
|
||||
break;
|
||||
}
|
||||
|
||||
if (comparator != null) {
|
||||
|
@ -97,6 +103,10 @@ public class FeedItemPermutors {
|
|||
return (item != null && item.getMedia() != null) ? item.getMedia().getDuration() : 0;
|
||||
}
|
||||
|
||||
private static long size(@Nullable FeedItem item) {
|
||||
return (item != null && item.getMedia() != null) ? item.getMedia().getSize() : 0;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private static String itemLink(@Nullable FeedItem item) {
|
||||
return (item != null && item.getLink() != null)
|
||||
|
|
|
@ -112,6 +112,26 @@ public class FeedItemPermutorsTest {
|
|||
assertTrue(checkIdOrder(itemList, 3, 2, 1)); // after sorting
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPermutorForRule_size_asc() {
|
||||
Permutor<FeedItem> permutor = FeedItemPermutors.getPermutor(SortOrder.SIZE_SMALL_LARGE);
|
||||
|
||||
List<FeedItem> itemList = getTestList();
|
||||
assertTrue(checkIdOrder(itemList, 1, 3, 2)); // before sorting
|
||||
permutor.reorder(itemList);
|
||||
assertTrue(checkIdOrder(itemList, 1, 2, 3)); // after sorting
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPermutorForRule_size_desc() {
|
||||
Permutor<FeedItem> permutor = FeedItemPermutors.getPermutor(SortOrder.SIZE_LARGE_SMALL);
|
||||
|
||||
List<FeedItem> itemList = getTestList();
|
||||
assertTrue(checkIdOrder(itemList, 1, 3, 2)); // before sorting
|
||||
permutor.reorder(itemList);
|
||||
assertTrue(checkIdOrder(itemList, 3, 2, 1)); // after sorting
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPermutorForRule_DURATION_DESC_NullMedia() {
|
||||
Permutor<FeedItem> permutor = FeedItemPermutors.getPermutor(SortOrder.DURATION_LONG_SHORT);
|
||||
|
@ -166,21 +186,21 @@ public class FeedItemPermutorsTest {
|
|||
calendar.set(2019, 0, 1); // January 1st
|
||||
Feed feed1 = new Feed(null, null, "Feed title 1");
|
||||
FeedItem feedItem1 = new FeedItem(1, "Title 1", null, null, calendar.getTime(), 0, feed1);
|
||||
FeedMedia feedMedia1 = new FeedMedia(0, feedItem1, 1000, 0, 0, null, null, null, true, null, 0, 0);
|
||||
FeedMedia feedMedia1 = new FeedMedia(0, feedItem1, 1000, 0, 100, null, null, null, true, null, 0, 0);
|
||||
feedItem1.setMedia(feedMedia1);
|
||||
itemList.add(feedItem1);
|
||||
|
||||
calendar.set(2019, 2, 1); // March 1st
|
||||
Feed feed2 = new Feed(null, null, "Feed title 3");
|
||||
FeedItem feedItem2 = new FeedItem(3, "Title 3", null, null, calendar.getTime(), 0, feed2);
|
||||
FeedMedia feedMedia2 = new FeedMedia(0, feedItem2, 3000, 0, 0, null, null, null, true, null, 0, 0);
|
||||
FeedMedia feedMedia2 = new FeedMedia(0, feedItem2, 3000, 0, 300, null, null, null, true, null, 0, 0);
|
||||
feedItem2.setMedia(feedMedia2);
|
||||
itemList.add(feedItem2);
|
||||
|
||||
calendar.set(2019, 1, 1); // February 1st
|
||||
Feed feed3 = new Feed(null, null, "Feed title 2");
|
||||
FeedItem feedItem3 = new FeedItem(2, "Title 2", null, null, calendar.getTime(), 0, feed3);
|
||||
FeedMedia feedMedia3 = new FeedMedia(0, feedItem3, 2000, 0, 0, null, null, null, true, null, 0, 0);
|
||||
FeedMedia feedMedia3 = new FeedMedia(0, feedItem3, 2000, 0, 200, null, null, null, true, null, 0, 0);
|
||||
feedItem3.setMedia(feedMedia3);
|
||||
itemList.add(feedItem3);
|
||||
|
||||
|
|
|
@ -20,6 +20,8 @@ public enum SortOrder {
|
|||
DURATION_LONG_SHORT(6, INTRA_FEED),
|
||||
EPISODE_FILENAME_A_Z(7, INTRA_FEED),
|
||||
EPISODE_FILENAME_Z_A(8, INTRA_FEED),
|
||||
SIZE_SMALL_LARGE(9, INTRA_FEED),
|
||||
SIZE_LARGE_SMALL(10, INTRA_FEED),
|
||||
FEED_TITLE_A_Z(101, INTER_FEED),
|
||||
FEED_TITLE_Z_A(102, INTER_FEED),
|
||||
RANDOM(103, INTER_FEED),
|
||||
|
|
|
@ -25,6 +25,12 @@ public class FeedItemSortQuery {
|
|||
case DURATION_LONG_SHORT:
|
||||
sortQuery = PodDBAdapter.TABLE_NAME_FEED_MEDIA + "." + PodDBAdapter.KEY_DURATION + " " + "DESC";
|
||||
break;
|
||||
case SIZE_SMALL_LARGE:
|
||||
sortQuery = PodDBAdapter.TABLE_NAME_FEED_MEDIA + "." + PodDBAdapter.KEY_SIZE + " " + "ASC";
|
||||
break;
|
||||
case SIZE_LARGE_SMALL:
|
||||
sortQuery = PodDBAdapter.TABLE_NAME_FEED_MEDIA + "." + PodDBAdapter.KEY_SIZE + " " + "DESC";
|
||||
break;
|
||||
default:
|
||||
sortQuery = "";
|
||||
break;
|
||||
|
|
|
@ -343,6 +343,7 @@
|
|||
<string name="feed_title">Podcast title</string>
|
||||
<string name="random">Random</string>
|
||||
<string name="smart_shuffle">Smart shuffle</string>
|
||||
<string name="size">Size</string>
|
||||
<string name="clear_queue_confirmation_msg">Please confirm that you want to clear the queue of ALL of the episodes in it</string>
|
||||
<string name="time_left_label">Time left:\u0020</string>
|
||||
|
||||
|
@ -771,6 +772,8 @@
|
|||
<string name="sort_old_new">Old \u2192 New</string>
|
||||
<string name="sort_short_long">Short \u2192 Long</string>
|
||||
<string name="sort_long_short">Long \u2192 Short</string>
|
||||
<string name="sort_small_large">Small \u2192 Large</string>
|
||||
<string name="sort_large_small">Large \u2192 Small</string>
|
||||
|
||||
<!-- Share episode dialog -->
|
||||
<string name="share_playback_position_dialog_label">Include playback position</string>
|
||||
|
|
Loading…
Reference in New Issue