Search in sources :

Example 1 with SortOrder

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();
}
Also used : NonNull(androidx.annotation.NonNull) SortOrder(de.danoeh.antennapod.model.feed.SortOrder) IntraFeedSortDialog(de.danoeh.antennapod.dialog.IntraFeedSortDialog)

Example 2 with SortOrder

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
            }
        }
    }
}
Also used : SortOrder(de.danoeh.antennapod.model.feed.SortOrder) Test(org.junit.Test)

Example 3 with SortOrder

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));
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) SortOrder(de.danoeh.antennapod.model.feed.SortOrder)

Example 4 with SortOrder

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;
}
Also used : DialogInterface(android.content.DialogInterface) SortOrder(de.danoeh.antennapod.model.feed.SortOrder) ConfirmationDialog(de.danoeh.antennapod.core.dialog.ConfirmationDialog)

Aggregations

SortOrder (de.danoeh.antennapod.model.feed.SortOrder)4 DialogInterface (android.content.DialogInterface)1 NonNull (androidx.annotation.NonNull)1 ConfirmationDialog (de.danoeh.antennapod.core.dialog.ConfirmationDialog)1 IntraFeedSortDialog (de.danoeh.antennapod.dialog.IntraFeedSortDialog)1 FeedItem (de.danoeh.antennapod.model.feed.FeedItem)1 Test (org.junit.Test)1