1 package com.folioreader.model;
3 import android.os.Parcel;
4 import android.os.Parcelable;
9 * This data structure holds information about an individual highlight.
11 * @author mahavir on 5/12/16.
14 public class HighlightImpl implements Parcelable, HighLight {
16 public static final String INTENT = HighlightImpl.class.getName();
17 public static final String BROADCAST_EVENT = "highlight_broadcast_event";
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.
34 private String bookId;
36 * Highlighted text content text content.
38 private String content;
40 * Date time when highlight is created (format:- MMM dd, yyyy | HH:mm).
44 * Field defines the color of the highlight. {@link HighlightStyle}
48 * Page index in the book taken from Epub spine reference.
50 private int pageNumber;
52 * href of the page from the Epub spine list.
54 private String pageId;
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>
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>
70 * Note linked to the highlight (optional)
74 public enum HighlightStyle {
85 * Return CSS class for HighlightStyle.
87 public static String classForStyle(HighlightStyle style) {
100 return "mediaOverlayStyle1";
102 return "mediaOverlayStyle2";
104 return "mediaOverlayStyle0";
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) {
114 this.bookId = bookId;
115 this.content = content;
118 this.pageNumber = pageNumber;
119 this.pageId = pageId;
125 public HighlightImpl() {
128 protected HighlightImpl(Parcel in) {
136 public void setId(int id) {
140 public String getBookId() {
144 public void setBookId(String bookId) {
145 this.bookId = bookId;
148 public String getContent() {
152 public void setContent(String content) {
153 this.content = content;
156 public Date getDate() {
160 public void setDate(Date date) {
164 public String getType() {
168 public String getPageId() {
172 public void setPageId(String pageId) {
173 this.pageId = pageId;
176 public String getRangy() {
180 public void setRangy(String rangy) {
184 public void setType(String type) {
188 public int getPageNumber() {
192 public void setPageNumber(int pageNumber) {
193 this.pageNumber = pageNumber;
196 public String getNote() {
200 public String getUUID() {
204 public void setUUID(String uuid) {
208 public void setNote(String note) {
213 public boolean equals(Object o) {
214 if (this == o) return true;
215 if (o == null || getClass() != o.getClass()) return false;
217 HighlightImpl highlightImpl = (HighlightImpl) o;
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))));
227 public int hashCode() {
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);
237 public String toString() {
238 return "HighlightImpl{" +
240 ", bookId='" + bookId + '\'' +
241 ", content='" + content + '\'' +
243 ", type='" + type + '\'' +
244 ", pageNumber=" + pageNumber +
245 ", pageId='" + pageId + '\'' +
246 ", rangy='" + rangy + '\'' +
247 ", note='" + note + '\'' +
248 ", uuid='" + uuid + '\'' +
253 public int describeContents() {
258 public void writeToParcel(Parcel dest, int flags) {
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);
271 private void readFromParcel(Parcel in) {
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();
284 public static final Creator<HighlightImpl> CREATOR = new Creator<HighlightImpl>() {
286 public HighlightImpl createFromParcel(Parcel in) {
287 return new HighlightImpl(in);
291 public HighlightImpl[] newArray(int size) {
292 return new HighlightImpl[size];