From 67e67584a2a44e699bf2c94e56e9b98be080acef Mon Sep 17 00:00:00 2001 From: JJamet Date: Thu, 27 Jul 2017 23:06:12 +0200 Subject: [PATCH] Define Parcelable in Event --- .../remembirthday/element/CalendarEvent.java | 54 ++++++++++++++----- .../remembirthday/element/Contact.java | 19 ++++++- .../remembirthday/provider/EventProvider.java | 5 -- 3 files changed, 58 insertions(+), 20 deletions(-) diff --git a/RememBirthday-UI/src/main/java/com/kunzisoft/remembirthday/element/CalendarEvent.java b/RememBirthday-UI/src/main/java/com/kunzisoft/remembirthday/element/CalendarEvent.java index 4f45b27..35383bc 100644 --- a/RememBirthday-UI/src/main/java/com/kunzisoft/remembirthday/element/CalendarEvent.java +++ b/RememBirthday-UI/src/main/java/com/kunzisoft/remembirthday/element/CalendarEvent.java @@ -1,9 +1,10 @@ package com.kunzisoft.remembirthday.element; +import android.os.Parcel; +import android.os.Parcelable; import android.text.format.DateUtils; import org.joda.time.DateTime; -import org.joda.time.Days; import org.joda.time.Seconds; import java.util.ArrayList; @@ -16,15 +17,13 @@ * Created by joker on 27/07/17. */ -public class CalendarEvent { +public class CalendarEvent implements Parcelable { - private Long id; - private String lookupKey; + private long id; private Date dateStart; private Date dateStop; private boolean allDay; private String title; - private List reminders; @@ -33,11 +32,23 @@ public CalendarEvent(Date date) { } public CalendarEvent(Date dateStart, Date dateStop) { + this.id = -1; this.dateStart = dateStart; this.dateStop = dateStop; + this.allDay = false; + this.title = ""; this.reminders = new ArrayList<>(); } + private CalendarEvent(Parcel in) { + id = in.readLong(); + dateStart = (Date) in.readSerializable(); + dateStop = (Date) in.readSerializable(); + allDay = in.readByte() != 0; + title = in.readString(); + reminders = in.readArrayList(Reminder.class.getClassLoader()); + } + public Long getId() { return id; } @@ -46,14 +57,6 @@ public void setId(Long id) { this.id = id; } - public String getLookupKey() { - return lookupKey; - } - - public void setLookupKey(String lookupKey) { - this.lookupKey = lookupKey; - } - public Date getDate() { return dateStart; } @@ -159,4 +162,29 @@ public String toString() { ", title='" + title + '\'' + '}'; } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel parcel, int i) { + parcel.writeLong(id); + parcel.writeSerializable(dateStart); + parcel.writeSerializable(dateStop); + parcel.writeByte((byte) (allDay ? 1 : 0)); + parcel.writeString(title); + parcel.writeList(reminders); + } + + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { + public CalendarEvent createFromParcel(Parcel in) { + return new CalendarEvent(in); + } + + public CalendarEvent[] newArray(int size) { + return new CalendarEvent[size]; + } + }; } diff --git a/RememBirthday-UI/src/main/java/com/kunzisoft/remembirthday/element/Contact.java b/RememBirthday-UI/src/main/java/com/kunzisoft/remembirthday/element/Contact.java index a4b7af6..b908b43 100644 --- a/RememBirthday-UI/src/main/java/com/kunzisoft/remembirthday/element/Contact.java +++ b/RememBirthday-UI/src/main/java/com/kunzisoft/remembirthday/element/Contact.java @@ -28,6 +28,7 @@ public class Contact implements Parcelable{ private Uri imageThumbnailUri; private Uri imageUri; private DateUnknownYear birthday; + private CalendarEvent birthdayEvent; private List phoneNumbers; public Contact(long id, String lookupKey, String name) { @@ -45,7 +46,7 @@ public Contact(long id, String lookupKey, long rawId, String name, DateUnknownYe this.name = name; this.imageThumbnailUri = null; this.imageUri = null; - this.birthday = birthday; + setBirthday(birthday); } public Contact(String name) { @@ -64,7 +65,7 @@ private Contact(Parcel in) { name = in.readString(); imageThumbnailUri = in.readParcelable(Uri.class.getClassLoader()); imageUri = in.readParcelable(Uri.class.getClassLoader()); - birthday = in.readParcelable(DateUnknownYear.class.getClassLoader()); + setBirthday((DateUnknownYear) in.readParcelable(DateUnknownYear.class.getClassLoader())); phoneNumbers = in.readArrayList(PhoneNumber.class.getClassLoader()); } @@ -138,6 +139,18 @@ public DateUnknownYear getBirthday() { public void setBirthday(DateUnknownYear date) { this.birthday = date; + if(date != null) { + setBirthdayEvent(new CalendarEvent(date.getDate())); + } else + setBirthdayEvent(null); + } + + public CalendarEvent getBirthdayEvent() { + return birthdayEvent; + } + + private void setBirthdayEvent(CalendarEvent birthdayEvent) { + this.birthdayEvent = birthdayEvent; } public boolean isPhoneNumberInit() { @@ -182,6 +195,8 @@ public void setPhoneNumbers(List phoneNumbers) { this.phoneNumbers = phoneNumbers; } + + public boolean containsImage() { return imageUri!=null; } diff --git a/RememBirthday-UI/src/main/java/com/kunzisoft/remembirthday/provider/EventProvider.java b/RememBirthday-UI/src/main/java/com/kunzisoft/remembirthday/provider/EventProvider.java index 5f7ab3b..9212a52 100644 --- a/RememBirthday-UI/src/main/java/com/kunzisoft/remembirthday/provider/EventProvider.java +++ b/RememBirthday-UI/src/main/java/com/kunzisoft/remembirthday/provider/EventProvider.java @@ -14,20 +14,15 @@ import android.provider.ContactsContract; import android.support.annotation.Nullable; import android.text.TextUtils; -import android.text.format.DateUtils; import android.util.Log; import com.kunzisoft.remembirthday.element.CalendarEvent; import com.kunzisoft.remembirthday.element.Contact; import com.kunzisoft.remembirthday.element.DateUnknownYear; -import com.kunzisoft.remembirthday.element.Reminder; import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; import java.util.HashSet; import java.util.List; -import java.util.TimeZone; /** * Created by joker on 27/07/17.