summaryrefslogtreecommitdiff
path: root/src/de/danoeh/antennapod/storage/FeedItemStatistics.java
blob: 8cb04075699f57229a3ff1c41d7ab93f41c1c0cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package de.danoeh.antennapod.storage;

import java.util.Date;

/**
 * Contains information about a feed's items.
 */
public class FeedItemStatistics {
    private long feedID;
    private int numberOfItems;
    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() {
        return feedID;
    }

    public int getNumberOfItems() {
        return numberOfItems;
    }

    public int getNumberOfNewItems() {
        return numberOfNewItems;
    }

    public int getNumberOfInProgressItems() {
        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;
    }
}