aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/ml/docilealligator/infinityforreddit/message/Message.java
blob: 4ef2563e80d0c086921fe80422184f9137e129ee (plain) (blame)
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
package ml.docilealligator.infinityforreddit.message;

import android.os.Parcel;
import android.os.Parcelable;

import java.util.ArrayList;

public class Message implements Parcelable {
    public static final String TYPE_COMMENT = "t1";
    public static final String TYPE_ACCOUNT = "t2";
    public static final String TYPE_LINK = "t3";
    public static final String TYPE_MESSAGE = "t4";
    public static final String TYPE_SUBREDDIT = "t5";
    static final String TYPE_AWARD = "t6";

    private final String kind;
    private final String subredditName;
    private final String subredditNamePrefixed;
    private final String id;
    private final String fullname;
    private final String subject;
    private final String author;
    private final String destination;
    private final String parentFullName;
    private final String title;
    private final String body;
    private final String context;
    private final String distinguished;
    private final String formattedTime;
    private final boolean wasComment;
    private boolean isNew;
    private final int score;
    private final int nComments;
    private final long timeUTC;
    private ArrayList<Message> replies;

    Message(String kind, String subredditName, String subredditNamePrefixed, String id, String fullname,
            String subject, String author, String destination, String parentFullName, String title, String body,
            String context, String distinguished, String formattedTime, boolean wasComment, boolean isNew,
            int score, int nComments, long timeUTC) {
        this.kind = kind;
        this.subredditName = subredditName;
        this.subredditNamePrefixed = subredditNamePrefixed;
        this.id = id;
        this.fullname = fullname;
        this.subject = subject;
        this.author = author;
        this.destination = destination;
        this.parentFullName = parentFullName;
        this.title = title;
        this.body = body;
        this.context = context;
        this.distinguished = distinguished;
        this.formattedTime = formattedTime;
        this.wasComment = wasComment;
        this.isNew = isNew;
        this.score = score;
        this.nComments = nComments;
        this.timeUTC = timeUTC;
    }


    protected Message(Parcel in) {
        kind = in.readString();
        subredditName = in.readString();
        subredditNamePrefixed = in.readString();
        id = in.readString();
        fullname = in.readString();
        subject = in.readString();
        author = in.readString();
        destination = in.readString();
        parentFullName = in.readString();
        title = in.readString();
        body = in.readString();
        context = in.readString();
        distinguished = in.readString();
        formattedTime = in.readString();
        wasComment = in.readByte() != 0;
        isNew = in.readByte() != 0;
        score = in.readInt();
        nComments = in.readInt();
        timeUTC = in.readLong();
        replies = in.createTypedArrayList(Message.CREATOR);
    }

    public static final Creator<Message> CREATOR = new Creator<Message>() {
        @Override
        public Message createFromParcel(Parcel in) {
            return new Message(in);
        }

        @Override
        public Message[] newArray(int size) {
            return new Message[size];
        }
    };

    public String getKind() {
        return kind;
    }

    public String getSubredditName() {
        return subredditName;
    }

    public String getSubredditNamePrefixed() {
        return subredditNamePrefixed;
    }

    public String getId() {
        return id;
    }

    public String getFullname() {
        return fullname;
    }

    public String getSubject() {
        return subject;
    }

    public String getAuthor() {
        return author;
    }

    public boolean isAuthorDeleted() {
        return author != null && author.equals("[deleted]");
    }

    public String getDestination() {
        return destination;
    }

    public boolean isDestinationDeleted()
    {
        return destination != null && destination.equals("[deleted]");
    }

    public String getParentFullName() {
        return parentFullName;
    }

    public String getTitle() {
        return title;
    }

    public String getBody() {
        return body;
    }

    public String getContext() {
        return context;
    }

    public String getDistinguished() {
        return distinguished;
    }

    public String getFormattedTime() {
        return formattedTime;
    }

    public boolean wasComment() {
        return wasComment;
    }

    public boolean isNew() {
        return isNew;
    }

    public void setNew(boolean isNew) {
        this.isNew = isNew;
    }

    public int getScore() {
        return score;
    }

    public int getnComments() {
        return nComments;
    }

    public long getTimeUTC() {
        return timeUTC;
    }

    public ArrayList<Message> getReplies() {
        return replies;
    }

    public void setReplies(ArrayList<Message> replies) {
        this.replies = replies;
    }

    public void addReply(Message reply) {
        if (replies == null) {
            replies = new ArrayList<>();
        }
        replies.add(reply);
    }

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

    @Override
    public void writeToParcel(Parcel parcel, int i) {
        parcel.writeString(kind);
        parcel.writeString(subredditName);
        parcel.writeString(subredditNamePrefixed);
        parcel.writeString(id);
        parcel.writeString(fullname);
        parcel.writeString(subject);
        parcel.writeString(author);
        parcel.writeString(destination);
        parcel.writeString(parentFullName);
        parcel.writeString(title);
        parcel.writeString(body);
        parcel.writeString(context);
        parcel.writeString(distinguished);
        parcel.writeString(formattedTime);
        parcel.writeByte((byte) (wasComment ? 1 : 0));
        parcel.writeByte((byte) (isNew ? 1 : 0));
        parcel.writeInt(score);
        parcel.writeInt(nComments);
        parcel.writeLong(timeUTC);
        parcel.writeTypedList(replies);
    }
}