Added Android code
[wl-app.git] / Android / folioreader / src / main / java / com / folioreader / model / HighlightImpl.java
1 package com.folioreader.model;
2
3 import android.os.Parcel;
4 import android.os.Parcelable;
5
6 import java.util.Date;
7
8 /**
9  * This data structure holds information about an individual highlight.
10  *
11  * @author mahavir on 5/12/16.
12  */
13
14 public class HighlightImpl implements Parcelable, HighLight {
15
16     public static final String INTENT = HighlightImpl.class.getName();
17     public static final String BROADCAST_EVENT = "highlight_broadcast_event";
18
19     /**
20      * Database id
21      */
22     private int id;
23     /**
24      * <p> Book id, which can be provided to intent to folio reader, if not provided id is
25      * used from epub's dc:identifier field in metadata.
26      * <p>for reference, look here:
27      * <a href="http://www.idpf.org/epub/30/spec/epub30-publications.html#sec-package-metadata-identifiers">IDPF</a>.</p>
28      * in case identifier is not found in the epub,
29      * <a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#hashCode()">hash code</a>
30      * of book title is used also if book title is not found then
31      * hash code of the book file name is used.
32      * </p>
33      */
34     private String bookId;
35     /**
36      * Highlighted text content text content.
37      */
38     private String content;
39     /**
40      * Date time when highlight is created (format:- MMM dd, yyyy | HH:mm).
41      */
42     private Date date;
43     /**
44      * Field defines the color of the highlight. {@link HighlightStyle}
45      */
46     private String type;
47     /**
48      * Page index in the book taken from Epub spine reference.
49      */
50     private int pageNumber;
51     /**
52      * href of the page from the Epub spine list.
53      */
54     private String pageId;
55     /**
56      * <p> Contains highlight meta data in terms of rangy format.</p>
57      * <strong>format </strong>:- start$end$id$class$containerId.
58      * <p>for reference, look here: <a href="https://github.com/timdown/rangy">rangy</a>.</p>
59      */
60     private String rangy;
61
62     /**
63      * Unique identifier for a highlight for sync across devices.
64      * <p>for reference, look here:
65      * <a href = "https://docs.oracle.com/javase/7/docs/api/java/util/UUID.html#toString()">UUID</a>.</p>
66      */
67     private String uuid;
68
69     /**
70      * Note linked to the highlight (optional)
71      */
72     private String note;
73
74     public enum HighlightStyle {
75         Yellow,
76         Green,
77         Blue,
78         Pink,
79         Underline,
80         TextColor,
81         DottetUnderline,
82         Normal;
83
84         /**
85          * Return CSS class for HighlightStyle.
86          */
87         public static String classForStyle(HighlightStyle style) {
88             switch (style) {
89                 case Yellow:
90                     return "yellow";
91                 case Green:
92                     return "green";
93                 case Blue:
94                     return "blue";
95                 case Pink:
96                     return "pink";
97                 case Underline:
98                     return "underline";
99                 case DottetUnderline:
100                     return "mediaOverlayStyle1";
101                 case TextColor:
102                     return "mediaOverlayStyle2";
103                 default:
104                     return "mediaOverlayStyle0";
105
106             }
107         }
108     }
109
110     public HighlightImpl(int id, String bookId, String content, Date date, String type,
111                          int pageNumber, String pageId,
112                          String rangy, String note, String uuid) {
113         this.id = id;
114         this.bookId = bookId;
115         this.content = content;
116         this.date = date;
117         this.type = type;
118         this.pageNumber = pageNumber;
119         this.pageId = pageId;
120         this.rangy = rangy;
121         this.note = note;
122         this.uuid = uuid;
123     }
124
125     public HighlightImpl() {
126     }
127
128     protected HighlightImpl(Parcel in) {
129         readFromParcel(in);
130     }
131
132     public int getId() {
133         return id;
134     }
135
136     public void setId(int id) {
137         this.id = id;
138     }
139
140     public String getBookId() {
141         return bookId;
142     }
143
144     public void setBookId(String bookId) {
145         this.bookId = bookId;
146     }
147
148     public String getContent() {
149         return content;
150     }
151
152     public void setContent(String content) {
153         this.content = content;
154     }
155
156     public Date getDate() {
157         return date;
158     }
159
160     public void setDate(Date date) {
161         this.date = date;
162     }
163
164     public String getType() {
165         return type;
166     }
167
168     public String getPageId() {
169         return pageId;
170     }
171
172     public void setPageId(String pageId) {
173         this.pageId = pageId;
174     }
175
176     public String getRangy() {
177         return rangy;
178     }
179
180     public void setRangy(String rangy) {
181         this.rangy = rangy;
182     }
183
184     public void setType(String type) {
185         this.type = type;
186     }
187
188     public int getPageNumber() {
189         return pageNumber;
190     }
191
192     public void setPageNumber(int pageNumber) {
193         this.pageNumber = pageNumber;
194     }
195
196     public String getNote() {
197         return note;
198     }
199
200     public String getUUID() {
201         return uuid;
202     }
203
204     public void setUUID(String uuid) {
205         this.uuid = uuid;
206     }
207
208     public void setNote(String note) {
209         this.note = note;
210     }
211
212     @Override
213     public boolean equals(Object o) {
214         if (this == o) return true;
215         if (o == null || getClass() != o.getClass()) return false;
216
217         HighlightImpl highlightImpl = (HighlightImpl) o;
218
219         return id == highlightImpl.id
220                 && (bookId != null ? bookId.equals(highlightImpl.bookId) : highlightImpl.bookId == null
221                 && (content != null ? content.equals(highlightImpl.content) : highlightImpl.content == null
222                 && (date != null ? date.equals(highlightImpl.date) : highlightImpl.date == null
223                 && (type != null ? type.equals(highlightImpl.type) : highlightImpl.type == null))));
224     }
225
226     @Override
227     public int hashCode() {
228         int result = id;
229         result = 31 * result + (bookId != null ? bookId.hashCode() : 0);
230         result = 31 * result + (content != null ? content.hashCode() : 0);
231         result = 31 * result + (date != null ? date.hashCode() : 0);
232         result = 31 * result + (type != null ? type.hashCode() : 0);
233         return result;
234     }
235
236     @Override
237     public String toString() {
238         return "HighlightImpl{" +
239                 "id=" + id +
240                 ", bookId='" + bookId + '\'' +
241                 ", content='" + content + '\'' +
242                 ", date=" + date +
243                 ", type='" + type + '\'' +
244                 ", pageNumber=" + pageNumber +
245                 ", pageId='" + pageId + '\'' +
246                 ", rangy='" + rangy + '\'' +
247                 ", note='" + note + '\'' +
248                 ", uuid='" + uuid + '\'' +
249                 '}';
250     }
251
252     @Override
253     public int describeContents() {
254         return 0;
255     }
256
257     @Override
258     public void writeToParcel(Parcel dest, int flags) {
259         dest.writeInt(id);
260         dest.writeString(bookId);
261         dest.writeString(pageId);
262         dest.writeString(rangy);
263         dest.writeString(content);
264         dest.writeSerializable(date);
265         dest.writeString(type);
266         dest.writeInt(pageNumber);
267         dest.writeString(note);
268         dest.writeString(uuid);
269     }
270
271     private void readFromParcel(Parcel in) {
272         id = in.readInt();
273         bookId = in.readString();
274         pageId = in.readString();
275         rangy = in.readString();
276         content = in.readString();
277         date = (Date) in.readSerializable();
278         type = in.readString();
279         pageNumber = in.readInt();
280         note = in.readString();
281         uuid = in.readString();
282     }
283
284     public static final Creator<HighlightImpl> CREATOR = new Creator<HighlightImpl>() {
285         @Override
286         public HighlightImpl createFromParcel(Parcel in) {
287             return new HighlightImpl(in);
288         }
289
290         @Override
291         public HighlightImpl[] newArray(int size) {
292             return new HighlightImpl[size];
293         }
294     };
295 }