Merge pull request #1246 from mfietz/issue/1244-sort-last-update

Drawer: Sort feeds by publication date
This commit is contained in:
Tom Hennen 2015-10-05 01:35:47 -04:00
commit 1aa1347724
4 changed files with 26 additions and 1 deletions

View File

@ -98,6 +98,7 @@ public class UserPreferences {
private static int EPISODE_CACHE_SIZE_UNLIMITED = -1; private static int EPISODE_CACHE_SIZE_UNLIMITED = -1;
public static int FEED_ORDER_COUNTER = 0; public static int FEED_ORDER_COUNTER = 0;
public static int FEED_ORDER_ALPHABETICAL = 1; public static int FEED_ORDER_ALPHABETICAL = 1;
public static int FEED_ORDER_LAST_UPDATE = 2;
public static int FEED_COUNTER_SHOW_NEW_UNPLAYED_SUM = 0; public static int FEED_COUNTER_SHOW_NEW_UNPLAYED_SUM = 0;
public static int FEED_COUNTER_SHOW_NEW = 1; public static int FEED_COUNTER_SHOW_NEW = 1;
public static int FEED_COUNTER_SHOW_UNPLAYED = 2; public static int FEED_COUNTER_SHOW_UNPLAYED = 2;

View File

@ -8,6 +8,7 @@ import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.Date;
import java.util.List; import java.util.List;
import de.danoeh.antennapod.core.feed.Chapter; import de.danoeh.antennapod.core.feed.Chapter;
@ -947,13 +948,33 @@ public final class DBReader {
return 1; return 1;
} }
}; };
} else { } else if(feedOrder == UserPreferences.FEED_ORDER_ALPHABETICAL) {
comparator = (lhs, rhs) -> { comparator = (lhs, rhs) -> {
if(lhs.getTitle() == null) { if(lhs.getTitle() == null) {
return 1; return 1;
} }
return lhs.getTitle().compareTo(rhs.getTitle()); return lhs.getTitle().compareTo(rhs.getTitle());
}; };
} else {
comparator = (lhs, rhs) -> {
if(lhs.getItems() == null || lhs.getItems().size() == 0) {
List<FeedItem> items = DBReader.getFeedItemList(lhs);
lhs.setItems(items);
}
if(rhs.getItems() == null || rhs.getItems().size() == 0) {
List<FeedItem> items = DBReader.getFeedItemList(rhs);
rhs.setItems(items);
}
if(lhs.getMostRecentItem() == null) {
return 1;
} else if(rhs.getMostRecentItem() == null) {
return -1;
} else {
Date d1 = lhs.getMostRecentItem().getPubDate();
Date d2 = rhs.getMostRecentItem().getPubDate();
return d2.compareTo(d1);
}
};
} }
Collections.sort(feeds, comparator); Collections.sort(feeds, comparator);

View File

@ -132,10 +132,12 @@
<string-array name="nav_drawer_feed_order_options"> <string-array name="nav_drawer_feed_order_options">
<item>@string/drawer_feed_order_unplayed_episodes</item> <item>@string/drawer_feed_order_unplayed_episodes</item>
<item>@string/drawer_feed_order_alphabetical</item> <item>@string/drawer_feed_order_alphabetical</item>
<item>@string/drawer_feed_order_last_update</item>
</string-array> </string-array>
<string-array name="nav_drawer_feed_order_values"> <string-array name="nav_drawer_feed_order_values">
<item>0</item> <item>0</item>
<item>1</item> <item>1</item>
<item>2</item>
</string-array> </string-array>
<string-array name="nav_drawer_feed_counter_options"> <string-array name="nav_drawer_feed_counter_options">

View File

@ -36,6 +36,7 @@
<string name="drawer_preferences">Drawer Preferences</string> <string name="drawer_preferences">Drawer Preferences</string>
<string name="drawer_feed_order_unplayed_episodes">Sort by counter</string> <string name="drawer_feed_order_unplayed_episodes">Sort by counter</string>
<string name="drawer_feed_order_alphabetical">Sort alphabetically</string> <string name="drawer_feed_order_alphabetical">Sort alphabetically</string>
<string name="drawer_feed_order_last_update">Sort by publication date</string>
<string name="drawer_feed_counter_new_unplayed">Number of new and unplayed episodes</string> <string name="drawer_feed_counter_new_unplayed">Number of new and unplayed episodes</string>
<string name="drawer_feed_counter_new">Number of new episodes</string> <string name="drawer_feed_counter_new">Number of new episodes</string>
<string name="drawer_feed_counter_unplayed">Number of unplayed episodes</string> <string name="drawer_feed_counter_unplayed">Number of unplayed episodes</string>