Feedlist and list with unread items are now sorted
This commit is contained in:
parent
e705ed2bee
commit
fdd5c2dc7e
|
@ -2,12 +2,14 @@ package de.podfetcher.feed;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import de.podfetcher.activity.MediaplayerActivity;
|
import de.podfetcher.activity.MediaplayerActivity;
|
||||||
import de.podfetcher.asynctask.DownloadStatus;
|
import de.podfetcher.asynctask.DownloadStatus;
|
||||||
import de.podfetcher.service.PlaybackService;
|
import de.podfetcher.service.PlaybackService;
|
||||||
import de.podfetcher.storage.*;
|
import de.podfetcher.storage.*;
|
||||||
|
import de.podfetcher.util.FeedtitleComparator;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
|
@ -130,7 +132,7 @@ public class FeedManager {
|
||||||
mediaFile.delete();
|
mediaFile.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
adapter.removeFeed(feed);
|
adapter.removeFeed(feed);
|
||||||
adapter.close();
|
adapter.close();
|
||||||
return feeds.remove(feed);
|
return feeds.remove(feed);
|
||||||
|
@ -148,6 +150,7 @@ public class FeedManager {
|
||||||
unreadItems.remove(item);
|
unreadItems.remove(item);
|
||||||
} else {
|
} else {
|
||||||
unreadItems.add(item);
|
unreadItems.add(item);
|
||||||
|
Collections.sort(unreadItems, new FeedItemPubdateComparator());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,7 +194,7 @@ public class FeedManager {
|
||||||
adapter.setQueue(queue);
|
adapter.setQueue(queue);
|
||||||
adapter.close();
|
adapter.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Uses external adapter. */
|
/** Uses external adapter. */
|
||||||
public void removeQueueItem(FeedItem item, PodDBAdapter adapter) {
|
public void removeQueueItem(FeedItem item, PodDBAdapter adapter) {
|
||||||
boolean removed = queue.remove(item);
|
boolean removed = queue.remove(item);
|
||||||
|
@ -219,6 +222,7 @@ public class FeedManager {
|
||||||
|
|
||||||
private void addNewFeed(Context context, Feed feed) {
|
private void addNewFeed(Context context, Feed feed) {
|
||||||
feeds.add(feed);
|
feeds.add(feed);
|
||||||
|
Collections.sort(feeds, new FeedtitleComparator());
|
||||||
PodDBAdapter adapter = new PodDBAdapter(context);
|
PodDBAdapter adapter = new PodDBAdapter(context);
|
||||||
adapter.open();
|
adapter.open();
|
||||||
feed.setId(setFeed(feed, adapter));
|
feed.setId(setFeed(feed, adapter));
|
||||||
|
@ -297,7 +301,7 @@ public class FeedManager {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Updates Information of an existing Feeditem. Uses external adapter. */
|
/** Updates Information of an existing Feeditem. Uses external adapter. */
|
||||||
public long setFeedItem(FeedItem item, PodDBAdapter adapter) {
|
public long setFeedItem(FeedItem item, PodDBAdapter adapter) {
|
||||||
if (adapter != null) {
|
if (adapter != null) {
|
||||||
|
@ -307,7 +311,7 @@ public class FeedManager {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Updates Information of an existing Feedimage. Uses external adapter. */
|
/** Updates Information of an existing Feedimage. Uses external adapter. */
|
||||||
public long setFeedImage(FeedImage image, PodDBAdapter adapter) {
|
public long setFeedImage(FeedImage image, PodDBAdapter adapter) {
|
||||||
if (adapter != null) {
|
if (adapter != null) {
|
||||||
|
@ -317,8 +321,11 @@ public class FeedManager {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Updates Information of an existing Feedmedia object. Uses external adapter. */
|
/**
|
||||||
|
* Updates Information of an existing Feedmedia object. Uses external
|
||||||
|
* adapter.
|
||||||
|
*/
|
||||||
public long setFeedImage(FeedMedia media, PodDBAdapter adapter) {
|
public long setFeedImage(FeedMedia media, PodDBAdapter adapter) {
|
||||||
if (adapter != null) {
|
if (adapter != null) {
|
||||||
return adapter.setMedia(media);
|
return adapter.setMedia(media);
|
||||||
|
@ -327,8 +334,11 @@ public class FeedManager {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Updates Information of an existing Feed. Creates and opens its own adapter. */
|
/**
|
||||||
|
* Updates Information of an existing Feed. Creates and opens its own
|
||||||
|
* adapter.
|
||||||
|
*/
|
||||||
public long setFeed(Context context, Feed feed) {
|
public long setFeed(Context context, Feed feed) {
|
||||||
PodDBAdapter adapter = new PodDBAdapter(context);
|
PodDBAdapter adapter = new PodDBAdapter(context);
|
||||||
adapter.open();
|
adapter.open();
|
||||||
|
@ -337,7 +347,10 @@ public class FeedManager {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Updates information of an existing FeedItem. Creates and opens its own adapter.*/
|
/**
|
||||||
|
* Updates information of an existing FeedItem. Creates and opens its own
|
||||||
|
* adapter.
|
||||||
|
*/
|
||||||
public long setFeedItem(Context context, FeedItem item) {
|
public long setFeedItem(Context context, FeedItem item) {
|
||||||
PodDBAdapter adapter = new PodDBAdapter(context);
|
PodDBAdapter adapter = new PodDBAdapter(context);
|
||||||
adapter.open();
|
adapter.open();
|
||||||
|
@ -346,7 +359,10 @@ public class FeedManager {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Updates information of an existing FeedImage. Creates and opens its own adapter. */
|
/**
|
||||||
|
* Updates information of an existing FeedImage. Creates and opens its own
|
||||||
|
* adapter.
|
||||||
|
*/
|
||||||
public long setFeedImage(Context context, FeedImage image) {
|
public long setFeedImage(Context context, FeedImage image) {
|
||||||
PodDBAdapter adapter = new PodDBAdapter(context);
|
PodDBAdapter adapter = new PodDBAdapter(context);
|
||||||
adapter.open();
|
adapter.open();
|
||||||
|
@ -355,7 +371,10 @@ public class FeedManager {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Updates information of an existing FeedMedia object. Creates and opens its own adapter. */
|
/**
|
||||||
|
* Updates information of an existing FeedMedia object. Creates and opens
|
||||||
|
* its own adapter.
|
||||||
|
*/
|
||||||
public long setFeedMedia(Context context, FeedMedia media) {
|
public long setFeedMedia(Context context, FeedMedia media) {
|
||||||
PodDBAdapter adapter = new PodDBAdapter(context);
|
PodDBAdapter adapter = new PodDBAdapter(context);
|
||||||
adapter.open();
|
adapter.open();
|
||||||
|
@ -448,6 +467,8 @@ public class FeedManager {
|
||||||
extractDownloadLogFromCursor(context, adapter);
|
extractDownloadLogFromCursor(context, adapter);
|
||||||
extractQueueFromCursor(context, adapter);
|
extractQueueFromCursor(context, adapter);
|
||||||
adapter.close();
|
adapter.close();
|
||||||
|
Collections.sort(feeds, new FeedtitleComparator());
|
||||||
|
Collections.sort(unreadItems, new FeedItemPubdateComparator());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void extractFeedlistFromCursor(Context context, PodDBAdapter adapter) {
|
private void extractFeedlistFromCursor(Context context, PodDBAdapter adapter) {
|
||||||
|
@ -526,19 +547,24 @@ public class FeedManager {
|
||||||
if (!item.read) {
|
if (!item.read) {
|
||||||
unreadItems.add(item);
|
unreadItems.add(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
// extract chapters
|
// extract chapters
|
||||||
Cursor chapterCursor = adapter.getSimpleChaptersOfFeedItemCursor(item);
|
Cursor chapterCursor = adapter
|
||||||
|
.getSimpleChaptersOfFeedItemCursor(item);
|
||||||
if (chapterCursor.moveToFirst()) {
|
if (chapterCursor.moveToFirst()) {
|
||||||
item.setSimpleChapters(new ArrayList<SimpleChapter>());
|
item.setSimpleChapters(new ArrayList<SimpleChapter>());
|
||||||
do {
|
do {
|
||||||
SimpleChapter chapter = new SimpleChapter(chapterCursor.getLong(chapterCursor.getColumnIndex(PodDBAdapter.KEY_START)),
|
SimpleChapter chapter = new SimpleChapter(
|
||||||
chapterCursor.getString(chapterCursor.getColumnIndex(PodDBAdapter.KEY_TITLE)));
|
chapterCursor
|
||||||
|
.getLong(chapterCursor
|
||||||
|
.getColumnIndex(PodDBAdapter.KEY_START)),
|
||||||
|
chapterCursor.getString(chapterCursor
|
||||||
|
.getColumnIndex(PodDBAdapter.KEY_TITLE)));
|
||||||
item.getSimpleChapters().add(chapter);
|
item.getSimpleChapters().add(chapter);
|
||||||
} while (chapterCursor.moveToNext());
|
} while (chapterCursor.moveToNext());
|
||||||
}
|
}
|
||||||
chapterCursor.close();
|
chapterCursor.close();
|
||||||
|
|
||||||
items.add(item);
|
items.add(item);
|
||||||
} while (itemlistCursor.moveToNext());
|
} while (itemlistCursor.moveToNext());
|
||||||
}
|
}
|
||||||
|
@ -585,7 +611,7 @@ public class FeedManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void extractQueueFromCursor(Context context, PodDBAdapter adapter) {
|
private void extractQueueFromCursor(Context context, PodDBAdapter adapter) {
|
||||||
Log.d(TAG, "Extracting Downloadqueue");
|
Log.d(TAG, "Extracting Queue");
|
||||||
Cursor cursor = adapter.getQueueCursor();
|
Cursor cursor = adapter.getQueueCursor();
|
||||||
if (cursor.moveToFirst()) {
|
if (cursor.moveToFirst()) {
|
||||||
do {
|
do {
|
||||||
|
@ -594,9 +620,8 @@ public class FeedManager {
|
||||||
Feed feed = getFeed(cursor.getLong(cursor
|
Feed feed = getFeed(cursor.getLong(cursor
|
||||||
.getColumnIndex(PodDBAdapter.KEY_FEED)));
|
.getColumnIndex(PodDBAdapter.KEY_FEED)));
|
||||||
if (feed != null) {
|
if (feed != null) {
|
||||||
FeedItem item = getFeedItem(
|
FeedItem item = getFeedItem(cursor.getLong(cursor
|
||||||
cursor.getColumnIndex(PodDBAdapter.KEY_FEEDITEM),
|
.getColumnIndex(PodDBAdapter.KEY_FEEDITEM)), feed);
|
||||||
feed);
|
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
queue.add(index, item);
|
queue.add(index, item);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
package de.podfetcher.util;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
|
import de.podfetcher.feed.FeedItem;
|
||||||
|
|
||||||
|
/** Compares the pubDate of two FeedItems for sorting*/
|
||||||
|
public class FeedItemPubdateComparator implements Comparator<FeedItem> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compare(FeedItem lhs, FeedItem rhs) {
|
||||||
|
return -lhs.getPubDate().compareTo(rhs.getPubDate());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package de.podfetcher.util;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
|
import de.podfetcher.feed.Feed;
|
||||||
|
|
||||||
|
/** Compares the title of two feeds for sorting. */
|
||||||
|
public class FeedtitleComparator implements Comparator<Feed> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compare(Feed lhs, Feed rhs) {
|
||||||
|
return lhs.getTitle().compareTo(rhs.getTitle());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue