Statistics for Feeds with no items are now loaded correctly. fixes #283

This commit is contained in:
daniel oeh 2013-09-23 10:37:43 +02:00
parent aa3675bc83
commit e38746f906
3 changed files with 33 additions and 4 deletions

View File

@ -89,7 +89,7 @@ public class FeedlistAdapter extends BaseAdapter {
if (DownloadRequester.getInstance().isDownloadingFile(feed)) {
holder.lastUpdate.setText(R.string.refreshing_label);
} else {
if (feedItemStatistics.getNumberOfItems() > 0) {
if (feedItemStatistics.lastUpdateKnown()) {
holder.lastUpdate.setText(convertView.getResources().getString(
R.string.most_recent_prefix)
+ DateUtils.getRelativeTimeSpanString(

View File

@ -11,13 +11,29 @@ public class FeedItemStatistics {
private int numberOfNewItems;
private int numberOfInProgressItems;
private Date lastUpdate;
private static final Date UNKNOWN_DATE = new Date(0);
/**
* Creates new FeedItemStatistics object.
*
* @param feedID ID of the feed.
* @param numberOfItems Number of items that this feed has.
* @param numberOfNewItems Number of unread items this feed has.
* @param numberOfInProgressItems Number of items that the user has started listening to.
* @param lastUpdate pubDate of the latest episode. A lastUpdate value of 0 will be interpreted as DATE_UNKOWN if
* numberOfItems is 0.
*/
public FeedItemStatistics(long feedID, int numberOfItems, int numberOfNewItems, int numberOfInProgressItems, Date lastUpdate) {
this.feedID = feedID;
this.numberOfItems = numberOfItems;
this.numberOfNewItems = numberOfNewItems;
this.numberOfInProgressItems = numberOfInProgressItems;
if (numberOfItems > 0) {
this.lastUpdate = (lastUpdate != null) ? (Date) lastUpdate.clone() : null;
} else {
this.lastUpdate = UNKNOWN_DATE;
}
}
public long getFeedID() {
@ -36,7 +52,19 @@ public class FeedItemStatistics {
return numberOfInProgressItems;
}
/**
* Returns the pubDate of the latest item in the feed. Users of this method
* should check if this value is unkown or not by calling lastUpdateKnown() first.
*/
public Date getLastUpdate() {
return (lastUpdate != null) ? (Date) lastUpdate.clone() : null;
}
/**
* Returns true if the lastUpdate value is known. The lastUpdate value is unkown if the
* feed has no items.
*/
public boolean lastUpdateKnown() {
return lastUpdate != UNKNOWN_DATE;
}
}

View File

@ -1017,14 +1017,15 @@ public class PodDBAdapter {
* Select number of items, new items, the date of the latest episode and the number of episodes in progress. The result
* is sorted by the title of the feed.
*/
private static final String FEED_STATISTICS_QUERY = "SELECT feed, num_items, new_items, latest_episode, in_progress FROM " +
private static final String FEED_STATISTICS_QUERY = "SELECT Feeds.id, num_items, new_items, latest_episode, in_progress FROM " +
" Feeds LEFT JOIN " +
"(SELECT feed,count(*) AS num_items," +
" COUNT(CASE WHEN read=0 THEN 1 END) AS new_items," +
" MAX(pubDate) AS latest_episode," +
" COUNT(CASE WHEN position>0 THEN 1 END) AS in_progress," +
" COUNT(CASE WHEN downloaded=1 THEN 1 END) AS episodes_downloaded " +
" FROM FeedItems LEFT JOIN FeedMedia ON FeedItems.id=FeedMedia.feeditem GROUP BY FeedItems.feed)" +
" INNER JOIN Feeds ON Feeds.id = feed ORDER BY Feeds.title;";
" ON Feeds.id = feed ORDER BY Feeds.title;";
public Cursor getFeedStatisticsCursor() {
return db.rawQuery(FEED_STATISTICS_QUERY, null);