sort in podcast screen - logic, no db persistence yet.
This commit is contained in:
parent
aa6897f256
commit
be7db6cef1
|
@ -34,6 +34,7 @@ import org.greenrobot.eventbus.EventBus;
|
|||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import de.danoeh.antennapod.R;
|
||||
|
@ -52,6 +53,7 @@ import de.danoeh.antennapod.core.feed.FeedEvent;
|
|||
import de.danoeh.antennapod.core.feed.FeedItem;
|
||||
import de.danoeh.antennapod.core.feed.FeedItemFilter;
|
||||
import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||
import de.danoeh.antennapod.core.feed.IntraFeedSortOrder;
|
||||
import de.danoeh.antennapod.core.glide.ApGlideSettings;
|
||||
import de.danoeh.antennapod.core.glide.FastBlurTransformation;
|
||||
import de.danoeh.antennapod.core.service.download.DownloadService;
|
||||
|
@ -63,6 +65,7 @@ import de.danoeh.antennapod.core.storage.DownloadRequester;
|
|||
import de.danoeh.antennapod.core.util.FeedItemUtil;
|
||||
import de.danoeh.antennapod.core.util.LongList;
|
||||
import de.danoeh.antennapod.core.util.Optional;
|
||||
import de.danoeh.antennapod.core.util.comparator.FeedItemPubdateComparator;
|
||||
import de.danoeh.antennapod.core.util.gui.MoreContentListFooterUtil;
|
||||
import de.danoeh.antennapod.dialog.EpisodesApplyActionFragment;
|
||||
import de.danoeh.antennapod.dialog.RenameFeedDialog;
|
||||
|
@ -625,13 +628,26 @@ public class FeedItemlistFragment extends ListFragment {
|
|||
|
||||
@NonNull
|
||||
private Optional<Feed> loadData() {
|
||||
// TODO-2524: apply sorting, either at db level or here
|
||||
Feed feed = DBReader.getFeed(feedID);
|
||||
if (feed != null && feed.getItemFilter() != null) {
|
||||
DBReader.loadAdditionalFeedItemListData(feed.getItems());
|
||||
FeedItemFilter filter = feed.getItemFilter();
|
||||
feed.setItems(filter.filter(feed.getItems()));
|
||||
}
|
||||
IntraFeedSortOrder sortOrder = feed.getSortOrder();
|
||||
if (sortOrder != null) {
|
||||
long tS = System.currentTimeMillis(); // TODO-2524:
|
||||
if (sortOrder == IntraFeedSortOrder.DATE_OLD_NEW) {
|
||||
List<FeedItem> feedItems = feed.getItems();
|
||||
Collections.sort(feedItems, FeedItemPubdateComparator.ascending);
|
||||
feed.setItems(feedItems);
|
||||
} else {
|
||||
System.err.println("DBG - to-implement: " + sortOrder); // TODO-2524:
|
||||
}
|
||||
long tE = System.currentTimeMillis();
|
||||
System.err.println("DBG - sort elapsed time: " + (tE -tS) +
|
||||
"ms ; " + "num items: " + feed.getItems().size() + ", order: " + sortOrder); // TODO: 2524
|
||||
}
|
||||
return Optional.ofNullable(feed);
|
||||
}
|
||||
|
||||
|
|
|
@ -122,7 +122,7 @@ public class FeedMenuHandler {
|
|||
@Override
|
||||
protected void updateSort(@NonNull IntraFeedSortOrder sortOrder) {
|
||||
selectedFeed.setSortOrder(sortOrder);
|
||||
// TODO-2524: update in db
|
||||
DBWriter.setFeedItemSortOrder(selectedFeed.getId(), sortOrder);
|
||||
}
|
||||
};
|
||||
sortDialog.openDialog();
|
||||
|
|
|
@ -6,7 +6,8 @@ import org.apache.commons.lang3.builder.ToStringStyle;
|
|||
public class FeedEvent {
|
||||
|
||||
public enum Action {
|
||||
FILTER_CHANGED
|
||||
FILTER_CHANGED,
|
||||
SORT_ORDER_CHANGED
|
||||
}
|
||||
|
||||
private final Action action;
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.content.Context;
|
|||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
|
@ -30,6 +31,7 @@ import de.danoeh.antennapod.core.feed.FeedEvent;
|
|||
import de.danoeh.antennapod.core.feed.FeedItem;
|
||||
import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||
import de.danoeh.antennapod.core.feed.FeedPreferences;
|
||||
import de.danoeh.antennapod.core.feed.IntraFeedSortOrder;
|
||||
import de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeAction;
|
||||
import de.danoeh.antennapod.core.preferences.GpodnetPreferences;
|
||||
import de.danoeh.antennapod.core.preferences.PlaybackPreferences;
|
||||
|
@ -944,6 +946,19 @@ public class DBWriter {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Set item sort order of the feed
|
||||
*
|
||||
*/
|
||||
public static Future<?> setFeedItemSortOrder(long feedId, @Nullable IntraFeedSortOrder sortOrder) {
|
||||
return dbExec.submit(() -> {
|
||||
PodDBAdapter adapter = PodDBAdapter.getInstance();
|
||||
adapter.open();
|
||||
// adapter.setFeedItemSortOrder(feedId, sortOrder);
|
||||
adapter.close();
|
||||
EventBus.getDefault().post(new FeedEvent(FeedEvent.Action.SORT_ORDER_CHANGED, feedId));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the statistics in DB
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package de.danoeh.antennapod.core.util.comparator;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
|
||||
import de.danoeh.antennapod.core.feed.FeedItem;
|
||||
|
@ -7,6 +8,9 @@ import de.danoeh.antennapod.core.feed.FeedItem;
|
|||
/** Compares the pubDate of two FeedItems for sorting*/
|
||||
public class FeedItemPubdateComparator implements Comparator<FeedItem> {
|
||||
|
||||
public static final Comparator<FeedItem> descending = new FeedItemPubdateComparator();
|
||||
public static final Comparator<FeedItem> ascending = Collections.reverseOrder(new FeedItemPubdateComparator());
|
||||
|
||||
/** Returns a new instance of this comparator in reverse order.
|
||||
public static FeedItemPubdateComparator newInstance() {
|
||||
FeedItemPubdateComparator
|
||||
|
|
Loading…
Reference in New Issue