diff options
author | drabux <drabux@fouragan.net> | 2015-01-22 23:37:07 -0500 |
---|---|---|
committer | drabux <drabux@fouragan.net> | 2015-01-22 23:37:07 -0500 |
commit | 520ed8327c5d04134619f47eebf3c81615665f13 (patch) | |
tree | ddd3d0ad3b2923923449ba347b620cb8c494331c /core/src/main | |
parent | efcbbfe2b93182dbb8458fdf049816b8710ba8af (diff) | |
download | AntennaPod-520ed8327c5d04134619f47eebf3c81615665f13.zip |
Options to sort queue by date
Diffstat (limited to 'core/src/main')
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java | 45 | ||||
-rw-r--r-- | core/src/main/res/values/strings.xml | 3 |
2 files changed, 48 insertions, 0 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java index d71d19433..41dde8656 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java @@ -24,6 +24,8 @@ import org.shredzone.flattr4j.model.Flattr; import java.io.File; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; +import java.util.Collections; +import java.util.Comparator; import java.util.Date; import java.util.LinkedList; import java.util.List; @@ -588,6 +590,49 @@ public class DBWriter { } /** + * Sort the FeedItems in the queue by date. + * <p/> + * This function must be run using the ExecutorService (dbExec). + * + * @param context A context that is used for opening a database connection. + * @param asc true sort by ascending order + * false sort by descending order + * @param broadcastUpdate true if this operation should trigger a QueueUpdateBroadcast. This option should be set to + * false if the caller wants to avoid unexpected updates of the GUI. + */ + public static void sortQueueItemByDate(final Context context, final boolean asc, final boolean broadcastUpdate) { + final PodDBAdapter adapter = new PodDBAdapter(context); + adapter.open(); + final List<FeedItem> queue = DBReader.getQueue(context, adapter); + + if (queue != null) { + if (asc) { + Collections.sort(queue, new Comparator<FeedItem>() { + public int compare(FeedItem f1, FeedItem f2) { + return f1.getPubDate().compareTo(f2.getPubDate()); + } + }); + } else { + Collections.sort(queue, new Comparator<FeedItem>() { + public int compare(FeedItem f1, FeedItem f2) { + return f2.getPubDate().compareTo(f1.getPubDate()); + } + }); + } + + adapter.setQueue(queue); + if (broadcastUpdate) { + EventDistributor.getInstance() + .sendQueueUpdateBroadcast(); + } + + } else { + Log.e(TAG, "sortQueueItemByDate: Could not load queue"); + } + adapter.close(); + } + + /** * Sets the 'read'-attribute of a FeedItem to the specified value. * * @param context A context that is used for opening a database connection. diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index 130007016..d76cc533b 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -159,6 +159,9 @@ <string name="removed_from_queue">Item removed</string> <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="date_asc">ascending date</string> + <string name="date_desc">descending date</string> <!-- Flattr --> <string name="flattr_auth_label">Flattr sign-in</string> |