mirror of
https://github.com/AntennaPod/AntennaPod.git
synced 2024-12-23 23:41:36 +01:00
Options to sort queue by date
This commit is contained in:
parent
efcbbfe2b9
commit
520ed8327c
@ -174,6 +174,12 @@ public class QueueFragment extends Fragment {
|
||||
DBTasks.refreshAllFeeds(getActivity(), feeds);
|
||||
}
|
||||
return true;
|
||||
case R.id.queue_sort_date_asc:
|
||||
DBWriter.sortQueueItemByDate(getActivity(), true, true);
|
||||
return true;
|
||||
case R.id.queue_sort_date_desc:
|
||||
DBWriter.sortQueueItemByDate(getActivity(), false, true);
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
@ -9,5 +9,19 @@
|
||||
android:menuCategory="container"
|
||||
custom:showAsAction="ifRoom"
|
||||
android:icon="?attr/navigation_refresh"/>
|
||||
|
||||
</menu>
|
||||
|
||||
<item
|
||||
android:id="@+id/queue_sort"
|
||||
android:title="@string/sort">
|
||||
|
||||
<menu>
|
||||
<item
|
||||
android:id="@+id/queue_sort_date_asc"
|
||||
android:title="@string/date_asc"/>
|
||||
<item
|
||||
android:id="@+id/queue_sort_date_desc"
|
||||
android:title="@string/date_desc"/>
|
||||
</menu>
|
||||
</item>
|
||||
|
||||
</menu>
|
||||
|
@ -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;
|
||||
@ -587,6 +589,49 @@ public class DBWriter {
|
||||
adapter.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user