Changes due to feedback in pull request #3315
This commit is contained in:
parent
906142cbf3
commit
fe9f0c8e7e
|
@ -49,6 +49,7 @@ import de.danoeh.antennapod.core.util.Converter;
|
|||
import de.danoeh.antennapod.core.util.FeedItemUtil;
|
||||
import de.danoeh.antennapod.core.util.LongList;
|
||||
import de.danoeh.antennapod.core.util.QueueSorter;
|
||||
import de.danoeh.antennapod.core.util.SortOrder;
|
||||
import de.danoeh.antennapod.dialog.EpisodesApplyActionFragment;
|
||||
import de.danoeh.antennapod.menuhandler.FeedItemMenuHandler;
|
||||
import de.danoeh.antennapod.menuhandler.MenuItemUtils;
|
||||
|
@ -277,19 +278,17 @@ public class QueueFragment extends Fragment {
|
|||
MenuItemUtils.refreshLockItem(getActivity(), menu);
|
||||
|
||||
// Show Lock Item only if queue is sorted manually
|
||||
boolean sortedAutomatically = UserPreferences.isQueueSortedAutomatically();
|
||||
boolean keepSorted = UserPreferences.isQueueKeepSorted();
|
||||
MenuItem lockItem = menu.findItem(R.id.queue_lock);
|
||||
lockItem.setVisible(!sortedAutomatically);
|
||||
lockItem.setVisible(!keepSorted);
|
||||
|
||||
// Random sort is not supported in keep sorted mode
|
||||
MenuItem sortRandomItem = menu.findItem(R.id.queue_sort_random);
|
||||
sortRandomItem.setVisible(!keepSorted);
|
||||
|
||||
// Set keep sorted checkbox
|
||||
MenuItem sortedAutomaticallyItem = menu.findItem(R.id.queue_sort_automatically);
|
||||
sortedAutomaticallyItem.setChecked(sortedAutomatically);
|
||||
|
||||
// Hide sort menu items for sort orders that are not supported by automatic sort.
|
||||
MenuItem sortRandomItem = menu.findItem(R.id.queue_sort_random);
|
||||
sortRandomItem.setVisible(!sortedAutomatically);
|
||||
MenuItem sortSmartShuffleItem = menu.findItem(R.id.queue_sort_smart_shuffle);
|
||||
sortSmartShuffleItem.setVisible(!sortedAutomatically);
|
||||
MenuItem keepSortedItem = menu.findItem(R.id.queue_keep_sorted);
|
||||
keepSortedItem.setChecked(keepSorted);
|
||||
|
||||
isUpdatingFeeds = MenuItemUtils.updateRefreshMenuItem(menu, R.id.refresh_item, updateRefreshMenuItemChecker);
|
||||
}
|
||||
|
@ -339,52 +338,49 @@ public class QueueFragment extends Fragment {
|
|||
((MainActivity) requireActivity()) .loadChildFragment(
|
||||
EpisodesApplyActionFragment.newInstance(queue, ACTION_DELETE | ACTION_REMOVE_FROM_QUEUE));
|
||||
return true;
|
||||
case R.id.queue_sort_automatically:
|
||||
boolean sortedAutomaticallyOld = UserPreferences.isQueueSortedAutomatically();
|
||||
boolean sortedAutomaticallyNew = !sortedAutomaticallyOld;
|
||||
if (sortedAutomaticallyNew) {
|
||||
// We have to choose an initially sort order, let's sort by episode date
|
||||
UserPreferences.QueueSortOrder sortOrder = UserPreferences.QueueSortOrder.DATE_NEW_OLD;
|
||||
UserPreferences.setQueueSortOrder(sortOrder);
|
||||
QueueSorter.sort(QueueSorter.queueSortOrder2Rule(sortOrder), true);
|
||||
} else {
|
||||
UserPreferences.setQueueSortOrder(UserPreferences.QueueSortOrder.MANUALLY);
|
||||
}
|
||||
// Update sort menu items visibility and state
|
||||
getActivity().invalidateOptionsMenu();
|
||||
return true;
|
||||
case R.id.queue_sort_episode_title_asc:
|
||||
queueSortOrderChanged(QueueSorter.Rule.EPISODE_TITLE_ASC);
|
||||
setSortOrder(SortOrder.EPISODE_TITLE_A_Z);
|
||||
return true;
|
||||
case R.id.queue_sort_episode_title_desc:
|
||||
queueSortOrderChanged(QueueSorter.Rule.EPISODE_TITLE_DESC);
|
||||
setSortOrder(SortOrder.EPISODE_TITLE_Z_A);
|
||||
return true;
|
||||
case R.id.queue_sort_date_asc:
|
||||
queueSortOrderChanged(QueueSorter.Rule.DATE_ASC);
|
||||
setSortOrder(SortOrder.DATE_OLD_NEW);
|
||||
return true;
|
||||
case R.id.queue_sort_date_desc:
|
||||
queueSortOrderChanged(QueueSorter.Rule.DATE_DESC);
|
||||
setSortOrder(SortOrder.DATE_NEW_OLD);
|
||||
return true;
|
||||
case R.id.queue_sort_duration_asc:
|
||||
queueSortOrderChanged(QueueSorter.Rule.DURATION_ASC);
|
||||
setSortOrder(SortOrder.DURATION_SHORT_LONG);
|
||||
return true;
|
||||
case R.id.queue_sort_duration_desc:
|
||||
queueSortOrderChanged(QueueSorter.Rule.DURATION_DESC);
|
||||
setSortOrder(SortOrder.DURATION_LONG_SHORT);
|
||||
return true;
|
||||
case R.id.queue_sort_feed_title_asc:
|
||||
queueSortOrderChanged(QueueSorter.Rule.FEED_TITLE_ASC);
|
||||
setSortOrder(SortOrder.FEED_TITLE_A_Z);
|
||||
return true;
|
||||
case R.id.queue_sort_feed_title_desc:
|
||||
queueSortOrderChanged(QueueSorter.Rule.FEED_TITLE_DESC);
|
||||
setSortOrder(SortOrder.FEED_TITLE_Z_A);
|
||||
return true;
|
||||
case R.id.queue_sort_random:
|
||||
queueSortOrderChanged(QueueSorter.Rule.RANDOM);
|
||||
setSortOrder(SortOrder.RANDOM);
|
||||
return true;
|
||||
case R.id.queue_sort_smart_shuffle_asc:
|
||||
queueSortOrderChanged(QueueSorter.Rule.SMART_SHUFFLE_ASC);
|
||||
setSortOrder(SortOrder.SMART_SHUFFLE_OLD_NEW);
|
||||
return true;
|
||||
case R.id.queue_sort_smart_shuffle_desc:
|
||||
queueSortOrderChanged(QueueSorter.Rule.SMART_SHUFFLE_DESC);
|
||||
setSortOrder(SortOrder.SMART_SHUFFLE_NEW_OLD);
|
||||
return true;
|
||||
case R.id.queue_keep_sorted:
|
||||
boolean keepSortedOld = UserPreferences.isQueueKeepSorted();
|
||||
boolean keepSortedNew = !keepSortedOld;
|
||||
UserPreferences.setQueueKeepSorted(keepSortedNew);
|
||||
if (keepSortedNew) {
|
||||
SortOrder sortOrder = UserPreferences.getQueueKeepSortedOrder();
|
||||
QueueSorter.sort(sortOrder, true);
|
||||
}
|
||||
// Update sort menu items and list lock elements
|
||||
getActivity().recreate();
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
|
@ -395,20 +391,19 @@ public class QueueFragment extends Fragment {
|
|||
}
|
||||
|
||||
/**
|
||||
* Sorts the queue on user interaction.
|
||||
* If the queue is sorted automatically, the new sort order is stored in the preferences.
|
||||
* This method is called if the user clicks on a sort order menu item.
|
||||
*
|
||||
* @param rule Sort rule.
|
||||
* If the queue is in keep sorted mode, the new sort order is stored in the preferences and
|
||||
* the queue is sorted. Otherwise the queue is just sorted.
|
||||
*
|
||||
* @param sortOrder New sort order.
|
||||
*/
|
||||
private void queueSortOrderChanged(QueueSorter.Rule rule) {
|
||||
boolean sortedAutomatically = UserPreferences.isQueueSortedAutomatically();
|
||||
UserPreferences.QueueSortOrder sortOrder = QueueSorter.rule2QueueSortOrder(rule);
|
||||
// remember sort order to keep queue sorted
|
||||
if (sortedAutomatically && sortOrder != null) {
|
||||
UserPreferences.setQueueSortOrder(sortOrder);
|
||||
private void setSortOrder(SortOrder sortOrder) {
|
||||
boolean keepSorted = UserPreferences.isQueueKeepSorted();
|
||||
if (keepSorted) {
|
||||
UserPreferences.setQueueKeepSortedOrder(sortOrder);
|
||||
}
|
||||
// Sort queue
|
||||
QueueSorter.sort(rule, true);
|
||||
QueueSorter.sort(sortOrder, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -67,17 +67,17 @@ public class FeedItemMenuHandler {
|
|||
}
|
||||
boolean hasMedia = selectedItem.getMedia() != null;
|
||||
boolean isPlaying = hasMedia && selectedItem.getState() == FeedItem.State.PLAYING;
|
||||
boolean sortedAutomatically = UserPreferences.isQueueSortedAutomatically();
|
||||
boolean keepSorted = UserPreferences.isQueueKeepSorted();
|
||||
|
||||
if (!isPlaying) {
|
||||
mi.setItemVisibility(R.id.skip_episode_item, false);
|
||||
}
|
||||
|
||||
boolean isInQueue = selectedItem.isTagged(FeedItem.TAG_QUEUE);
|
||||
if (queueAccess == null || queueAccess.size() == 0 || queueAccess.get(0) == selectedItem.getId() || sortedAutomatically) {
|
||||
if (queueAccess == null || queueAccess.size() == 0 || queueAccess.get(0) == selectedItem.getId() || keepSorted) {
|
||||
mi.setItemVisibility(R.id.move_to_top_item, false);
|
||||
}
|
||||
if (queueAccess == null || queueAccess.size() == 0 || queueAccess.get(queueAccess.size()-1) == selectedItem.getId() || sortedAutomatically) {
|
||||
if (queueAccess == null || queueAccess.size() == 0 || queueAccess.get(queueAccess.size()-1) == selectedItem.getId() || keepSorted) {
|
||||
mi.setItemVisibility(R.id.move_to_bottom_item, false);
|
||||
}
|
||||
if (!isInQueue) {
|
||||
|
|
|
@ -28,11 +28,6 @@
|
|||
android:title="@string/sort">
|
||||
|
||||
<menu>
|
||||
<item
|
||||
android:id="@+id/queue_sort_automatically"
|
||||
android:title="@string/sort_automatically"
|
||||
android:checkable="true" />
|
||||
|
||||
<item
|
||||
android:id="@+id/queue_sort_date"
|
||||
android:title="@string/date">
|
||||
|
@ -107,6 +102,11 @@
|
|||
android:title="@string/sort_new_to_old"/>
|
||||
</menu>
|
||||
</item>
|
||||
|
||||
<item
|
||||
android:id="@+id/queue_keep_sorted"
|
||||
android:title="@string/keep_sorted"
|
||||
android:checkable="true" />
|
||||
</menu>
|
||||
</item>
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ import de.danoeh.antennapod.core.storage.APNullCleanupAlgorithm;
|
|||
import de.danoeh.antennapod.core.storage.APQueueCleanupAlgorithm;
|
||||
import de.danoeh.antennapod.core.storage.EpisodeCleanupAlgorithm;
|
||||
import de.danoeh.antennapod.core.util.Converter;
|
||||
import de.danoeh.antennapod.core.util.SortOrder;
|
||||
import de.danoeh.antennapod.core.util.download.AutoUpdateManager;
|
||||
|
||||
/**
|
||||
|
@ -54,10 +55,11 @@ public class UserPreferences {
|
|||
private static final String PREF_SHOW_DOWNLOAD_REPORT = "prefShowDownloadReport";
|
||||
public static final String PREF_BACK_BUTTON_BEHAVIOR = "prefBackButtonBehavior";
|
||||
private static final String PREF_BACK_BUTTON_GO_TO_PAGE = "prefBackButtonGoToPage";
|
||||
public static final String PREF_QUEUE_SORT_ORDER = "prefQueueSortOrder";
|
||||
|
||||
// Queue
|
||||
private static final String PREF_QUEUE_ADD_TO_FRONT = "prefQueueAddToFront";
|
||||
public static final String PREF_QUEUE_KEEP_SORTED = "prefQueueKeepSorted";
|
||||
public static final String PREF_QUEUE_KEEP_SORTED_ORDER = "prefQueueKeepSortedOrder";
|
||||
|
||||
// Playback
|
||||
public static final String PREF_PAUSE_ON_HEADSET_DISCONNECT = "prefPauseOnHeadsetDisconnect";
|
||||
|
@ -493,7 +495,7 @@ public class UserPreferences {
|
|||
|
||||
public static boolean isQueueLocked() {
|
||||
return prefs.getBoolean(PREF_QUEUE_LOCKED, false)
|
||||
|| isQueueSortedAutomatically();
|
||||
|| isQueueKeepSorted();
|
||||
}
|
||||
|
||||
public static void setFastForwardSecs(int secs) {
|
||||
|
@ -870,36 +872,60 @@ public class UserPreferences {
|
|||
}
|
||||
|
||||
/**
|
||||
* Supported episode queue sort orders.
|
||||
* Use enum instead of integer to avoid mistakes at later maintenance changes.
|
||||
* Returns if the queue is in keep sorted mode.
|
||||
*
|
||||
* @see #getQueueKeepSortedOrder()
|
||||
*/
|
||||
public enum QueueSortOrder {
|
||||
MANUALLY, DATE_NEW_OLD, DATE_OLD_NEW, DURATION_SHORT_LONG, DURATION_LONG_SHORT,
|
||||
EPISODE_TITLE_A_Z, EPISODE_TITLE_Z_A, FEED_TITLE_A_Z, FEED_TITLE_Z_A
|
||||
public static boolean isQueueKeepSorted() {
|
||||
return prefs.getBoolean(PREF_QUEUE_KEEP_SORTED, false);
|
||||
}
|
||||
|
||||
public static QueueSortOrder getQueueSortOrder() {
|
||||
String sortOrderStr = prefs.getString(PREF_QUEUE_SORT_ORDER, "default");
|
||||
return parseQueueSortOrder(sortOrderStr);
|
||||
}
|
||||
|
||||
public static void setQueueSortOrder(QueueSortOrder queueSortOrder) {
|
||||
/**
|
||||
* Enables/disables the keep sorted mode of the queue.
|
||||
*
|
||||
* @see #setQueueKeepSortedOrder(SortOrder)
|
||||
*/
|
||||
public static void setQueueKeepSorted(boolean keepSorted) {
|
||||
prefs.edit()
|
||||
.putString(PREF_QUEUE_SORT_ORDER, queueSortOrder.name())
|
||||
.putBoolean(PREF_QUEUE_KEEP_SORTED, keepSorted)
|
||||
.apply();
|
||||
}
|
||||
|
||||
public static QueueSortOrder parseQueueSortOrder(String value) {
|
||||
try {
|
||||
return QueueSortOrder.valueOf(value);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// default value
|
||||
return QueueSortOrder.MANUALLY;
|
||||
}
|
||||
/**
|
||||
* Returns the sort order for the queue keep sorted mode.
|
||||
* Note: This value is stored independently from the keep sorted state.
|
||||
*
|
||||
* @see #isQueueKeepSorted()
|
||||
*/
|
||||
public static SortOrder getQueueKeepSortedOrder() {
|
||||
String sortOrderStr = prefs.getString(PREF_QUEUE_KEEP_SORTED_ORDER, "use-default");
|
||||
return parseSortOrder(sortOrderStr);
|
||||
}
|
||||
|
||||
public static boolean isQueueSortedAutomatically() {
|
||||
QueueSortOrder sortedOrder = getQueueSortOrder();
|
||||
return sortedOrder != QueueSortOrder.MANUALLY;
|
||||
/**
|
||||
* Sets the sort order for the queue keep sorted mode.
|
||||
*
|
||||
* @see #setQueueKeepSorted(boolean)
|
||||
*/
|
||||
public static void setQueueKeepSortedOrder(SortOrder sortOrder) {
|
||||
if (sortOrder == null) {
|
||||
return;
|
||||
}
|
||||
prefs.edit()
|
||||
.putString(PREF_QUEUE_KEEP_SORTED_ORDER, sortOrder.name())
|
||||
.apply();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the string representation to its enum value. If the string value is unknown,
|
||||
* a default value is retuned.
|
||||
*/
|
||||
private static SortOrder parseSortOrder(String value) {
|
||||
try {
|
||||
return SortOrder.valueOf(value);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// default value
|
||||
return SortOrder.DATE_NEW_OLD;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,11 +11,8 @@ import android.util.Log;
|
|||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
@ -45,6 +42,7 @@ import de.danoeh.antennapod.core.util.IntentUtils;
|
|||
import de.danoeh.antennapod.core.util.LongList;
|
||||
import de.danoeh.antennapod.core.util.Permutor;
|
||||
import de.danoeh.antennapod.core.util.QueueSorter;
|
||||
import de.danoeh.antennapod.core.util.SortOrder;
|
||||
|
||||
/**
|
||||
* Provides methods for writing data to AntennaPod's database.
|
||||
|
@ -404,21 +402,21 @@ public class DBWriter {
|
|||
}
|
||||
|
||||
/**
|
||||
* Sorts the queue depending on the configured sort order. If manual order is configured, the queue is not modified.
|
||||
* Sorts the queue depending on the configured sort order.
|
||||
* If the queue is not in keep sorted mode, nothing happens.
|
||||
*
|
||||
* @param queue The queue to be sorted.
|
||||
* @param events Replaces the events by a single SORT event if the list has to be sorted automatically.
|
||||
*/
|
||||
private static void applySortOrder(List<FeedItem> queue, List<QueueEvent> events) {
|
||||
if (!UserPreferences.isQueueSortedAutomatically()) {
|
||||
// automatic sort order is disabled, don't change anything
|
||||
if (!UserPreferences.isQueueKeepSorted()) {
|
||||
// queue is not in keep sorted mode, there's nothing to do
|
||||
return;
|
||||
}
|
||||
|
||||
// Sort queue by configured sort order
|
||||
UserPreferences.QueueSortOrder sortOrder = UserPreferences.getQueueSortOrder();
|
||||
QueueSorter.Rule sortRule = QueueSorter.queueSortOrder2Rule(sortOrder);
|
||||
Permutor<FeedItem> permutor = QueueSorter.getPermutor(sortRule);
|
||||
SortOrder sortOrder = UserPreferences.getQueueKeepSortedOrder();
|
||||
Permutor<FeedItem> permutor = QueueSorter.getPermutor(sortOrder);
|
||||
permutor.reorder(queue);
|
||||
|
||||
// Replace ADDED events by a single SORTED event
|
||||
|
|
|
@ -9,68 +9,54 @@ import java.util.Map;
|
|||
|
||||
import de.danoeh.antennapod.core.feed.FeedItem;
|
||||
import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||
import de.danoeh.antennapod.core.storage.DBWriter;
|
||||
|
||||
/**
|
||||
* Provides method for sorting the queue according to rules.
|
||||
*/
|
||||
public class QueueSorter {
|
||||
public enum Rule {
|
||||
EPISODE_TITLE_ASC,
|
||||
EPISODE_TITLE_DESC,
|
||||
DATE_ASC,
|
||||
DATE_DESC,
|
||||
DURATION_ASC,
|
||||
DURATION_DESC,
|
||||
FEED_TITLE_ASC,
|
||||
FEED_TITLE_DESC,
|
||||
RANDOM,
|
||||
SMART_SHUFFLE_ASC,
|
||||
SMART_SHUFFLE_DESC
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the queue by the given rule and sends a broadcast update.
|
||||
* Sorts the queue by the given sort order and sends a broadcast update.
|
||||
*
|
||||
* @param rule Sort rule.
|
||||
* @param sortOrder Sort order.
|
||||
* @param broadcastUpdate Send broadcast update?
|
||||
*/
|
||||
public static void sort(Rule rule, boolean broadcastUpdate) {
|
||||
Permutor<FeedItem> permutor = getPermutor(rule);
|
||||
public static void sort(SortOrder sortOrder, boolean broadcastUpdate) {
|
||||
Permutor<FeedItem> permutor = getPermutor(sortOrder);
|
||||
if (permutor != null) {
|
||||
DBWriter.reorderQueue(permutor, broadcastUpdate);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Permutor that sorts a list appropriate to the given sort rule.
|
||||
* Returns a Permutor that sorts a list appropriate to the given sort order.
|
||||
*
|
||||
* @param rule Sort rule.
|
||||
* @return Permutor that sorts a list appropriate to the given sort rule. <code>null</code> if the rule is unknown or <code>null</code>.
|
||||
* @param sortOrder Sort order.
|
||||
* @return Permutor that sorts a list appropriate to the given sort order. <code>null</code> if the order is unknown or <code>null</code>.
|
||||
*/
|
||||
public static Permutor<FeedItem> getPermutor(Rule rule) {
|
||||
if (rule == null) {
|
||||
public static Permutor<FeedItem> getPermutor(SortOrder sortOrder) {
|
||||
if (sortOrder == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Comparator<FeedItem> comparator = null;
|
||||
Permutor<FeedItem> permutor = null;
|
||||
|
||||
switch (rule) {
|
||||
case EPISODE_TITLE_ASC:
|
||||
switch (sortOrder) {
|
||||
case EPISODE_TITLE_A_Z:
|
||||
comparator = (f1, f2) -> f1.getTitle().compareTo(f2.getTitle());
|
||||
break;
|
||||
case EPISODE_TITLE_DESC:
|
||||
case EPISODE_TITLE_Z_A:
|
||||
comparator = (f1, f2) -> f2.getTitle().compareTo(f1.getTitle());
|
||||
break;
|
||||
case DATE_ASC:
|
||||
case DATE_OLD_NEW:
|
||||
comparator = (f1, f2) -> f1.getPubDate().compareTo(f2.getPubDate());
|
||||
break;
|
||||
case DATE_DESC:
|
||||
case DATE_NEW_OLD:
|
||||
comparator = (f1, f2) -> f2.getPubDate().compareTo(f1.getPubDate());
|
||||
break;
|
||||
case DURATION_ASC:
|
||||
case DURATION_SHORT_LONG:
|
||||
comparator = (f1, f2) -> {
|
||||
FeedMedia f1Media = f1.getMedia();
|
||||
FeedMedia f2Media = f2.getMedia();
|
||||
|
@ -83,7 +69,7 @@ public class QueueSorter {
|
|||
return duration1 - duration2;
|
||||
};
|
||||
break;
|
||||
case DURATION_DESC:
|
||||
case DURATION_LONG_SHORT:
|
||||
comparator = (f1, f2) -> {
|
||||
FeedMedia f1Media = f1.getMedia();
|
||||
FeedMedia f2Media = f2.getMedia();
|
||||
|
@ -93,19 +79,19 @@ public class QueueSorter {
|
|||
return -1 * (duration1 - duration2);
|
||||
};
|
||||
break;
|
||||
case FEED_TITLE_ASC:
|
||||
case FEED_TITLE_A_Z:
|
||||
comparator = (f1, f2) -> f1.getFeed().getTitle().compareTo(f2.getFeed().getTitle());
|
||||
break;
|
||||
case FEED_TITLE_DESC:
|
||||
case FEED_TITLE_Z_A:
|
||||
comparator = (f1, f2) -> f2.getFeed().getTitle().compareTo(f1.getFeed().getTitle());
|
||||
break;
|
||||
case RANDOM:
|
||||
permutor = Collections::shuffle;
|
||||
break;
|
||||
case SMART_SHUFFLE_ASC:
|
||||
case SMART_SHUFFLE_OLD_NEW:
|
||||
permutor = (queue) -> smartShuffle(queue, true);
|
||||
break;
|
||||
case SMART_SHUFFLE_DESC:
|
||||
case SMART_SHUFFLE_NEW_OLD:
|
||||
permutor = (queue) -> smartShuffle(queue, false);
|
||||
break;
|
||||
}
|
||||
|
@ -117,70 +103,6 @@ public class QueueSorter {
|
|||
return permutor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a QueueSortOrder value to its corresponding Rule value.
|
||||
*
|
||||
* @param sortOrder Sort order.
|
||||
* @return Rule value corresponding to the given sort order. <code>null</code> if the sort order is unknown or <code>null</code>.
|
||||
*/
|
||||
public static Rule queueSortOrder2Rule(UserPreferences.QueueSortOrder sortOrder) {
|
||||
if (sortOrder == null) {
|
||||
return null;
|
||||
}
|
||||
switch (sortOrder) {
|
||||
case DATE_NEW_OLD:
|
||||
return QueueSorter.Rule.DATE_DESC;
|
||||
case DATE_OLD_NEW:
|
||||
return QueueSorter.Rule.DATE_ASC;
|
||||
case DURATION_SHORT_LONG:
|
||||
return QueueSorter.Rule.DURATION_ASC;
|
||||
case DURATION_LONG_SHORT:
|
||||
return QueueSorter.Rule.DURATION_DESC;
|
||||
case EPISODE_TITLE_A_Z:
|
||||
return QueueSorter.Rule.EPISODE_TITLE_ASC;
|
||||
case EPISODE_TITLE_Z_A:
|
||||
return QueueSorter.Rule.EPISODE_TITLE_DESC;
|
||||
case FEED_TITLE_A_Z:
|
||||
return QueueSorter.Rule.FEED_TITLE_ASC;
|
||||
case FEED_TITLE_Z_A:
|
||||
return QueueSorter.Rule.FEED_TITLE_DESC;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Rule value to its corresponding QueueSortOrder value.
|
||||
*
|
||||
* @param rule Rule value.
|
||||
* @return QueueSortOrder value corresponding to the given Rule value. <code>null</code> if the Rule value is unsupported or <code>null</code>.
|
||||
*/
|
||||
public static UserPreferences.QueueSortOrder rule2QueueSortOrder(Rule rule) {
|
||||
if (rule == null) {
|
||||
return null;
|
||||
}
|
||||
switch (rule) {
|
||||
case EPISODE_TITLE_ASC:
|
||||
return UserPreferences.QueueSortOrder.EPISODE_TITLE_A_Z;
|
||||
case EPISODE_TITLE_DESC:
|
||||
return UserPreferences.QueueSortOrder.EPISODE_TITLE_Z_A;
|
||||
case DATE_ASC:
|
||||
return UserPreferences.QueueSortOrder.DATE_OLD_NEW;
|
||||
case DATE_DESC:
|
||||
return UserPreferences.QueueSortOrder.DATE_NEW_OLD;
|
||||
case DURATION_ASC:
|
||||
return UserPreferences.QueueSortOrder.DURATION_SHORT_LONG;
|
||||
case DURATION_DESC:
|
||||
return UserPreferences.QueueSortOrder.DURATION_LONG_SHORT;
|
||||
case FEED_TITLE_ASC:
|
||||
return UserPreferences.QueueSortOrder.FEED_TITLE_A_Z;
|
||||
case FEED_TITLE_DESC:
|
||||
return UserPreferences.QueueSortOrder.FEED_TITLE_Z_A;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements a reordering by pubdate that avoids consecutive episodes from the same feed in
|
||||
* the queue.
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
package de.danoeh.antennapod.core.util;
|
||||
|
||||
/**
|
||||
* Provides sort orders to sort a list of episodes.
|
||||
*/
|
||||
public enum SortOrder {
|
||||
EPISODE_TITLE_A_Z,
|
||||
EPISODE_TITLE_Z_A,
|
||||
DATE_OLD_NEW,
|
||||
DATE_NEW_OLD,
|
||||
DURATION_SHORT_LONG,
|
||||
DURATION_LONG_SHORT,
|
||||
FEED_TITLE_A_Z,
|
||||
FEED_TITLE_Z_A,
|
||||
RANDOM,
|
||||
SMART_SHUFFLE_OLD_NEW,
|
||||
SMART_SHUFFLE_NEW_OLD
|
||||
}
|
|
@ -276,7 +276,7 @@
|
|||
<string name="move_to_top_label">Zum Anfang verschieben</string>
|
||||
<string name="move_to_bottom_label">Zum Ende verschieben</string>
|
||||
<string name="sort">Sortieren</string>
|
||||
<string name="sort_automatically">Automatisch sortieren</string>
|
||||
<string name="keep_sorted">Automatisch sortieren</string>
|
||||
<string name="date">Datum</string>
|
||||
<string name="duration">Dauer</string>
|
||||
<string name="episode_title">Episodentitel</string>
|
||||
|
|
|
@ -294,7 +294,7 @@
|
|||
<string name="move_to_top_label">Move to top</string>
|
||||
<string name="move_to_bottom_label">Move to bottom</string>
|
||||
<string name="sort">Sort</string>
|
||||
<string name="sort_automatically">Keep sorted</string>
|
||||
<string name="keep_sorted">Keep sorted</string>
|
||||
<string name="date">Date</string>
|
||||
<string name="duration">Duration</string>
|
||||
<string name="episode_title">Episode title</string>
|
||||
|
|
|
@ -25,7 +25,7 @@ public class QueueSorterTest {
|
|||
|
||||
@Test
|
||||
public void testPermutorForRule_EPISODE_TITLE_ASC() {
|
||||
Permutor<FeedItem> permutor = QueueSorter.getPermutor(QueueSorter.Rule.EPISODE_TITLE_ASC);
|
||||
Permutor<FeedItem> permutor = QueueSorter.getPermutor(SortOrder.EPISODE_TITLE_A_Z);
|
||||
|
||||
List<FeedItem> itemList = getTestList();
|
||||
assertTrue(checkIdOrder(itemList, 1, 3, 2)); // before sorting
|
||||
|
@ -35,7 +35,7 @@ public class QueueSorterTest {
|
|||
|
||||
@Test
|
||||
public void testPermutorForRule_EPISODE_TITLE_DESC() {
|
||||
Permutor<FeedItem> permutor = QueueSorter.getPermutor(QueueSorter.Rule.EPISODE_TITLE_DESC);
|
||||
Permutor<FeedItem> permutor = QueueSorter.getPermutor(SortOrder.EPISODE_TITLE_Z_A);
|
||||
|
||||
List<FeedItem> itemList = getTestList();
|
||||
assertTrue(checkIdOrder(itemList, 1, 3, 2)); // before sorting
|
||||
|
@ -45,7 +45,7 @@ public class QueueSorterTest {
|
|||
|
||||
@Test
|
||||
public void testPermutorForRule_DATE_ASC() {
|
||||
Permutor<FeedItem> permutor = QueueSorter.getPermutor(QueueSorter.Rule.DATE_ASC);
|
||||
Permutor<FeedItem> permutor = QueueSorter.getPermutor(SortOrder.DATE_OLD_NEW);
|
||||
|
||||
List<FeedItem> itemList = getTestList();
|
||||
assertTrue(checkIdOrder(itemList, 1, 3, 2)); // before sorting
|
||||
|
@ -55,7 +55,7 @@ public class QueueSorterTest {
|
|||
|
||||
@Test
|
||||
public void testPermutorForRule_DATE_DESC() {
|
||||
Permutor<FeedItem> permutor = QueueSorter.getPermutor(QueueSorter.Rule.DATE_DESC);
|
||||
Permutor<FeedItem> permutor = QueueSorter.getPermutor(SortOrder.DATE_NEW_OLD);
|
||||
|
||||
List<FeedItem> itemList = getTestList();
|
||||
assertTrue(checkIdOrder(itemList, 1, 3, 2)); // before sorting
|
||||
|
@ -65,7 +65,7 @@ public class QueueSorterTest {
|
|||
|
||||
@Test
|
||||
public void testPermutorForRule_DURATION_ASC() {
|
||||
Permutor<FeedItem> permutor = QueueSorter.getPermutor(QueueSorter.Rule.DURATION_ASC);
|
||||
Permutor<FeedItem> permutor = QueueSorter.getPermutor(SortOrder.DURATION_SHORT_LONG);
|
||||
|
||||
List<FeedItem> itemList = getTestList();
|
||||
assertTrue(checkIdOrder(itemList, 1, 3, 2)); // before sorting
|
||||
|
@ -75,7 +75,7 @@ public class QueueSorterTest {
|
|||
|
||||
@Test
|
||||
public void testPermutorForRule_DURATION_DESC() {
|
||||
Permutor<FeedItem> permutor = QueueSorter.getPermutor(QueueSorter.Rule.DURATION_DESC);
|
||||
Permutor<FeedItem> permutor = QueueSorter.getPermutor(SortOrder.DURATION_LONG_SHORT);
|
||||
|
||||
List<FeedItem> itemList = getTestList();
|
||||
assertTrue(checkIdOrder(itemList, 1, 3, 2)); // before sorting
|
||||
|
@ -85,7 +85,7 @@ public class QueueSorterTest {
|
|||
|
||||
@Test
|
||||
public void testPermutorForRule_FEED_TITLE_ASC() {
|
||||
Permutor<FeedItem> permutor = QueueSorter.getPermutor(QueueSorter.Rule.FEED_TITLE_ASC);
|
||||
Permutor<FeedItem> permutor = QueueSorter.getPermutor(SortOrder.FEED_TITLE_A_Z);
|
||||
|
||||
List<FeedItem> itemList = getTestList();
|
||||
assertTrue(checkIdOrder(itemList, 1, 3, 2)); // before sorting
|
||||
|
@ -95,7 +95,7 @@ public class QueueSorterTest {
|
|||
|
||||
@Test
|
||||
public void testPermutorForRule_FEED_TITLE_DESC() {
|
||||
Permutor<FeedItem> permutor = QueueSorter.getPermutor(QueueSorter.Rule.FEED_TITLE_DESC);
|
||||
Permutor<FeedItem> permutor = QueueSorter.getPermutor(SortOrder.FEED_TITLE_Z_A);
|
||||
|
||||
List<FeedItem> itemList = getTestList();
|
||||
assertTrue(checkIdOrder(itemList, 1, 3, 2)); // before sorting
|
||||
|
|
Loading…
Reference in New Issue