use of de.danoeh.antennapod.model.feed.SortOrder in project AntennaPod by AntennaPod.
the class FeedMenuHandler method showSortDialog.
private static void showSortDialog(Context context, Feed selectedFeed) {
IntraFeedSortDialog sortDialog = new IntraFeedSortDialog(context, selectedFeed.getSortOrder(), selectedFeed.isLocalFeed()) {
@Override
protected void updateSort(@NonNull SortOrder sortOrder) {
selectedFeed.setSortOrder(sortOrder);
DBWriter.setFeedItemSortOrder(selectedFeed.getId(), sortOrder);
}
};
sortDialog.openDialog();
}
use of de.danoeh.antennapod.model.feed.SortOrder in project AntennaPod by AntennaPod.
the class FeedTest method testSetSortOrder_OnlyIntraFeedSortAllowed.
@Test
public void testSetSortOrder_OnlyIntraFeedSortAllowed() throws Exception {
for (SortOrder sortOrder : SortOrder.values()) {
if (sortOrder.scope == SortOrder.Scope.INTRA_FEED) {
// should be okay
original.setSortOrder(sortOrder);
} else {
try {
original.setSortOrder(sortOrder);
fail("SortOrder " + sortOrder + " should not be allowed on a feed");
} catch (IllegalArgumentException iae) {
// expected exception
}
}
}
}
use of de.danoeh.antennapod.model.feed.SortOrder in project AntennaPod by AntennaPod.
the class DBWriter method applySortOrder.
/**
* 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.isQueueKeepSorted()) {
// queue is not in keep sorted mode, there's nothing to do
return;
}
// Sort queue by configured sort order
SortOrder sortOrder = UserPreferences.getQueueKeepSortedOrder();
if (sortOrder == SortOrder.RANDOM) {
// do not shuffle the list on every change
return;
}
Permutor<FeedItem> permutor = FeedItemPermutors.getPermutor(sortOrder);
permutor.reorder(queue);
// Replace ADDED events by a single SORTED event
events.clear();
events.add(QueueEvent.sorted(queue));
}
use of de.danoeh.antennapod.model.feed.SortOrder in project AntennaPod by AntennaPod.
the class QueueFragment method onMenuItemClick.
@Override
public boolean onMenuItemClick(MenuItem item) {
final int itemId = item.getItemId();
if (itemId == R.id.queue_lock) {
toggleQueueLock();
return true;
} else if (itemId == R.id.refresh_item) {
AutoUpdateManager.runImmediate(requireContext());
return true;
} else if (itemId == R.id.clear_queue) {
// make sure the user really wants to clear the queue
ConfirmationDialog conDialog = new ConfirmationDialog(getActivity(), R.string.clear_queue_label, R.string.clear_queue_confirmation_msg) {
@Override
public void onConfirmButtonPressed(DialogInterface dialog) {
dialog.dismiss();
DBWriter.clearQueue();
}
};
conDialog.createNewDialog().show();
return true;
} else if (itemId == R.id.queue_sort_episode_title_asc) {
setSortOrder(SortOrder.EPISODE_TITLE_A_Z);
return true;
} else if (itemId == R.id.queue_sort_episode_title_desc) {
setSortOrder(SortOrder.EPISODE_TITLE_Z_A);
return true;
} else if (itemId == R.id.queue_sort_date_asc) {
setSortOrder(SortOrder.DATE_OLD_NEW);
return true;
} else if (itemId == R.id.queue_sort_date_desc) {
setSortOrder(SortOrder.DATE_NEW_OLD);
return true;
} else if (itemId == R.id.queue_sort_duration_asc) {
setSortOrder(SortOrder.DURATION_SHORT_LONG);
return true;
} else if (itemId == R.id.queue_sort_duration_desc) {
setSortOrder(SortOrder.DURATION_LONG_SHORT);
return true;
} else if (itemId == R.id.queue_sort_feed_title_asc) {
setSortOrder(SortOrder.FEED_TITLE_A_Z);
return true;
} else if (itemId == R.id.queue_sort_feed_title_desc) {
setSortOrder(SortOrder.FEED_TITLE_Z_A);
return true;
} else if (itemId == R.id.queue_sort_random) {
setSortOrder(SortOrder.RANDOM);
return true;
} else if (itemId == R.id.queue_sort_smart_shuffle_asc) {
setSortOrder(SortOrder.SMART_SHUFFLE_OLD_NEW);
return true;
} else if (itemId == R.id.queue_sort_smart_shuffle_desc) {
setSortOrder(SortOrder.SMART_SHUFFLE_NEW_OLD);
return true;
} else if (itemId == R.id.queue_keep_sorted) {
boolean keepSortedOld = UserPreferences.isQueueKeepSorted();
boolean keepSortedNew = !keepSortedOld;
UserPreferences.setQueueKeepSorted(keepSortedNew);
if (keepSortedNew) {
SortOrder sortOrder = UserPreferences.getQueueKeepSortedOrder();
DBWriter.reorderQueue(sortOrder, true);
}
if (recyclerAdapter != null) {
recyclerAdapter.updateDragDropEnabled();
}
refreshToolbarState();
return true;
} else if (itemId == R.id.action_search) {
((MainActivity) getActivity()).loadChildFragment(SearchFragment.newInstance());
return true;
}
return false;
}
Aggregations