Skip to content

Commit

Permalink
Define Parcelable in Event
Browse files Browse the repository at this point in the history
  • Loading branch information
J-Jamet committed Jul 27, 2017
1 parent 53e3637 commit 67e6758
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<Reminder> reminders;


Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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<CalendarEvent> CREATOR = new Parcelable.Creator<CalendarEvent>() {
public CalendarEvent createFromParcel(Parcel in) {
return new CalendarEvent(in);
}

public CalendarEvent[] newArray(int size) {
return new CalendarEvent[size];
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class Contact implements Parcelable{
private Uri imageThumbnailUri;
private Uri imageUri;
private DateUnknownYear birthday;
private CalendarEvent birthdayEvent;
private List<PhoneNumber> phoneNumbers;

public Contact(long id, String lookupKey, String name) {
Expand All @@ -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) {
Expand All @@ -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());
}

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -182,6 +195,8 @@ public void setPhoneNumbers(List<PhoneNumber> phoneNumbers) {
this.phoneNumbers = phoneNumbers;
}



public boolean containsImage() {
return imageUri!=null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 67e6758

Please sign in to comment.