summaryrefslogtreecommitdiff
path: root/org.fox.ttrss/src/main/java/org/fox/ttrss/types/Feed.java
blob: 9cbe9f83739cc02292d6361bc067e34a8a63e204 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package org.fox.ttrss.types;

import android.content.Context;
import android.os.Parcel;
import android.os.Parcelable;

import org.fox.ttrss.R;

public class Feed implements Comparable<Feed>, Parcelable {
	public String feed_url;
	public String title;
	public int id;
	public int unread;
	public boolean has_icon;
	public int cat_id;
	public int last_updated;
	public int order_id;
	public boolean is_cat;
    public boolean always_display_as_feed;
    public String display_title;
	
	public Feed(int id, String title, boolean is_cat) {
		this.id = id;
		this.title = title;
		this.is_cat = is_cat;
	}

	// TODO: maybe add special categories? (, bool isCat)
	public static String getSpecialFeedTitleById(Context context, int feedId) {
		switch (feedId) {
			case -1:
				return context.getString(R.string.feed_starred_articles);
			case -2:
				return context.getString(R.string.feed_published_articles);
			case -3:
				return context.getString(R.string.fresh_articles);
			case -4:
				return context.getString(R.string.feed_all_articles);
			case -6:
				return context.getString(R.string.feed_recently_read);
			case 0:
				return context.getString(R.string.feed_archived_articles);
			default:
				return null;
		}
	}
	
	public Feed(Parcel in) {
		readFromParcel(in);
	}
	
	public Feed() {
		
	}
	
	public boolean equals(Feed feed) {
		if (feed == this) 
			return true;
		
		if (feed == null)
			return false;
		
		return feed.id == this.id && (this.title == null || this.title.equals(feed.title)) && this.is_cat == feed.is_cat;
	}
	
	@Override
	public int compareTo(Feed feed) {
		if (feed.unread != this.unread)
			return feed.unread - this.unread;
		else
			return this.title.compareTo(feed.title);
	}

	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel out, int flags) {
		out.writeString(feed_url);
		out.writeString(title);
		out.writeInt(id);
		out.writeInt(unread);
		out.writeInt(has_icon ? 1 : 0);
		out.writeInt(cat_id);
		out.writeInt(last_updated);
		out.writeInt(is_cat ? 1 : 0);
		out.writeInt(order_id);
        out.writeInt(always_display_as_feed ? 1 : 0);
        out.writeString(display_title);
	}
	
	public void readFromParcel(Parcel in) {
		feed_url = in.readString();
		title = in.readString();
		id = in.readInt();
		unread = in.readInt();
		has_icon = in.readInt() == 1;
		cat_id = in.readInt();
		last_updated = in.readInt();
		is_cat = in.readInt() == 1;
		order_id = in.readInt();
        always_display_as_feed = in.readInt() == 1;
        display_title = in.readString();
	}
	
	@SuppressWarnings("rawtypes")
	public static final Parcelable.Creator CREATOR =
    	new Parcelable.Creator() {
            public Feed createFromParcel(Parcel in) {
                return new Feed(in);
            }
 
            public Feed[] newArray(int size) {
                return new Feed[size];
            }
        };
}