mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-18 14:47:46 +01:00
Include Organizer and Reminders when reading calendar events
Also use the named column indexes instead of numeric ids when retrieving the contents to make it more clear and more robust in case further fields are added later. Reminders are set as absolute timestamp.
This commit is contained in:
parent
2190c82ed7
commit
173e2d29b0
@ -16,21 +16,24 @@
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
package nodomain.freeyourgadget.gadgetbridge.util.calendar;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class CalendarEvent {
|
||||
private long begin;
|
||||
private long end;
|
||||
private long id;
|
||||
private String title;
|
||||
private String description;
|
||||
private String location;
|
||||
private String calName;
|
||||
private String calAccountName;
|
||||
private int color;
|
||||
private boolean allDay;
|
||||
private final long begin;
|
||||
private final long end;
|
||||
private final long id;
|
||||
private final String title;
|
||||
private final String description;
|
||||
private final String location;
|
||||
private final String calName;
|
||||
private final String calAccountName;
|
||||
private final String organizer;
|
||||
private final int color;
|
||||
private final boolean allDay;
|
||||
private List<Long> remindersAbsoluteTs;
|
||||
|
||||
public CalendarEvent(long begin, long end, long id, String title, String description, String location, String calName, String calAccountName, int color, boolean allDay) {
|
||||
public CalendarEvent(long begin, long end, long id, String title, String description, String location, String calName, String calAccountName, int color, boolean allDay, String organizer) {
|
||||
this.begin = begin;
|
||||
this.end = end;
|
||||
this.id = id;
|
||||
@ -41,6 +44,15 @@ public class CalendarEvent {
|
||||
this.calAccountName = calAccountName;
|
||||
this.color = color;
|
||||
this.allDay = allDay;
|
||||
this.organizer = organizer;
|
||||
}
|
||||
|
||||
public List<Long> getRemindersAbsoluteTs() {
|
||||
return remindersAbsoluteTs;
|
||||
}
|
||||
|
||||
public void setRemindersAbsoluteTs(List<Long> remindersAbsoluteTs) {
|
||||
this.remindersAbsoluteTs = remindersAbsoluteTs;
|
||||
}
|
||||
|
||||
public long getBegin() {
|
||||
@ -76,6 +88,10 @@ public class CalendarEvent {
|
||||
return title;
|
||||
}
|
||||
|
||||
public String getOrganizer() {
|
||||
return organizer;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
@ -117,7 +133,9 @@ public class CalendarEvent {
|
||||
Objects.equals(this.getCalName(), e.getCalName()) &&
|
||||
Objects.equals(this.getCalAccountName(), e.getCalAccountName()) &&
|
||||
(this.getColor() == e.getColor()) &&
|
||||
(this.isAllDay() == e.isAllDay());
|
||||
(this.isAllDay() == e.isAllDay()) &&
|
||||
Objects.equals(this.getOrganizer(), e.getOrganizer()) &&
|
||||
Objects.equals(this.getRemindersAbsoluteTs(), e.getRemindersAbsoluteTs());
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@ -135,6 +153,8 @@ public class CalendarEvent {
|
||||
result = 31 * result + Objects.hash(calAccountName);
|
||||
result = 31 * result + Integer.valueOf(color).hashCode();
|
||||
result = 31 * result + Boolean.valueOf(allDay).hashCode();
|
||||
result = 31 * result + Objects.hash(organizer);
|
||||
result = 31 * result + Objects.hash(remindersAbsoluteTs);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,6 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
||||
|
||||
@ -60,10 +59,12 @@ public class CalendarManager {
|
||||
Instances.TITLE,
|
||||
Instances.DESCRIPTION,
|
||||
Instances.EVENT_LOCATION,
|
||||
Instances.ORGANIZER,
|
||||
Instances.CALENDAR_DISPLAY_NAME,
|
||||
CalendarContract.Calendars.ACCOUNT_NAME,
|
||||
Instances.CALENDAR_COLOR,
|
||||
Instances.ALL_DAY
|
||||
Instances.ALL_DAY,
|
||||
Instances.EVENT_ID //needed for reminders
|
||||
};
|
||||
|
||||
private static final int lookahead_days = 7;
|
||||
@ -98,26 +99,54 @@ public class CalendarManager {
|
||||
return calendarEventList;
|
||||
}
|
||||
while (evtCursor.moveToNext()) {
|
||||
long start = evtCursor.getLong(1);
|
||||
long end = evtCursor.getLong(2);
|
||||
long start = evtCursor.getLong(evtCursor.getColumnIndexOrThrow(Instances.BEGIN));
|
||||
long end = evtCursor.getLong(evtCursor.getColumnIndexOrThrow(Instances.END));
|
||||
if (end == 0) {
|
||||
LOG.info("no end time, will parse duration string");
|
||||
Time time = new Time(); //FIXME: deprecated FTW
|
||||
time.parse(evtCursor.getString(3));
|
||||
time.parse(evtCursor.getString(evtCursor.getColumnIndexOrThrow(Instances.DURATION)));
|
||||
end = start + time.toMillis(false);
|
||||
}
|
||||
CalendarEvent calEvent = new CalendarEvent(
|
||||
start,
|
||||
end,
|
||||
evtCursor.getLong(0),
|
||||
evtCursor.getString(4),
|
||||
evtCursor.getString(5),
|
||||
evtCursor.getString(6),
|
||||
evtCursor.getString(7),
|
||||
evtCursor.getString(8),
|
||||
evtCursor.getInt(9),
|
||||
!evtCursor.getString(10).equals("0")
|
||||
evtCursor.getLong(evtCursor.getColumnIndexOrThrow(Instances._ID)),
|
||||
evtCursor.getString(evtCursor.getColumnIndexOrThrow(Instances.TITLE)),
|
||||
evtCursor.getString(evtCursor.getColumnIndexOrThrow(Instances.DESCRIPTION)),
|
||||
evtCursor.getString(evtCursor.getColumnIndexOrThrow(Instances.EVENT_LOCATION)),
|
||||
evtCursor.getString(evtCursor.getColumnIndexOrThrow(Instances.CALENDAR_DISPLAY_NAME)),
|
||||
evtCursor.getString(evtCursor.getColumnIndexOrThrow(CalendarContract.Calendars.ACCOUNT_NAME)),
|
||||
evtCursor.getInt(evtCursor.getColumnIndexOrThrow(Instances.CALENDAR_COLOR)),
|
||||
!evtCursor.getString(evtCursor.getColumnIndexOrThrow(Instances.ALL_DAY)).equals("0"),
|
||||
evtCursor.getString(evtCursor.getColumnIndexOrThrow(Instances.ORGANIZER))
|
||||
);
|
||||
|
||||
|
||||
// Query reminders for this event
|
||||
final Cursor reminderCursor = mContext.getContentResolver().query(
|
||||
CalendarContract.Reminders.CONTENT_URI,
|
||||
null,
|
||||
CalendarContract.Reminders.EVENT_ID + " = ?",
|
||||
new String[]{String.valueOf(evtCursor.getLong(evtCursor.getColumnIndexOrThrow(Instances.EVENT_ID)))},
|
||||
null
|
||||
);
|
||||
|
||||
if (reminderCursor != null && reminderCursor.getCount() > 0) {
|
||||
final List<Long> reminders = new ArrayList<>();
|
||||
while (reminderCursor.moveToNext()) {
|
||||
int minutes = reminderCursor.getInt(reminderCursor.getColumnIndexOrThrow(CalendarContract.Reminders.MINUTES));
|
||||
int method = reminderCursor.getInt(reminderCursor.getColumnIndexOrThrow(CalendarContract.Reminders.METHOD));
|
||||
LOG.debug("Reminder Method: {}, Minutes: {}", method, minutes);
|
||||
|
||||
if (method == 1) //METHOD_ALERT
|
||||
reminders.add(calEvent.getBegin() + minutes * 60 * 1000);
|
||||
|
||||
}
|
||||
reminderCursor.close();
|
||||
|
||||
calEvent.setRemindersAbsoluteTs(reminders);
|
||||
}
|
||||
|
||||
if (!calendarIsBlacklisted(calEvent.getUniqueCalName())) {
|
||||
calendarEventList.add(calEvent);
|
||||
} else {
|
||||
|
@ -25,22 +25,25 @@ public class CalendarEventTest extends TestBase {
|
||||
@Test
|
||||
public void testHashCode() {
|
||||
CalendarEvent c1 =
|
||||
new CalendarEvent(BEGIN, END, ID_1, "something", null, null, CALNAME_1, CALACCOUNTNAME_1, COLOR_1, false);
|
||||
new CalendarEvent(BEGIN, END, ID_1, "something", null, null, CALNAME_1, CALACCOUNTNAME_1, COLOR_1, false, null);
|
||||
CalendarEvent c2 =
|
||||
new CalendarEvent(BEGIN, END, ID_1, null, "something", null, CALNAME_1, CALACCOUNTNAME_1, COLOR_1, false);
|
||||
new CalendarEvent(BEGIN, END, ID_1, null, "something", null, CALNAME_1, CALACCOUNTNAME_1, COLOR_1, false, null);
|
||||
CalendarEvent c3 =
|
||||
new CalendarEvent(BEGIN, END, ID_1, null, null, "something", CALNAME_1, CALACCOUNTNAME_1, COLOR_1, false);
|
||||
new CalendarEvent(BEGIN, END, ID_1, null, null, "something", CALNAME_1, CALACCOUNTNAME_1, COLOR_1, false, null);
|
||||
CalendarEvent c4 =
|
||||
new CalendarEvent(BEGIN, END, ID_1, null, null, "something", CALNAME_1, CALACCOUNTNAME_1, COLOR_1, false, "some");
|
||||
|
||||
assertEquals(c1.hashCode(), c1.hashCode());
|
||||
assertNotEquals(c1.hashCode(), c2.hashCode());
|
||||
assertNotEquals(c2.hashCode(), c3.hashCode());
|
||||
assertNotEquals(c3.hashCode(), c4.hashCode());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSync() {
|
||||
List<CalendarEvent> eventList = new ArrayList<>();
|
||||
eventList.add(new CalendarEvent(BEGIN, END, ID_1, null, "something", null, CALNAME_1, CALACCOUNTNAME_1, COLOR_1, false));
|
||||
eventList.add(new CalendarEvent(BEGIN, END, ID_1, null, "something", null, CALNAME_1, CALACCOUNTNAME_1, COLOR_1, false, null));
|
||||
|
||||
GBDevice dummyGBDevice = createDummyGDevice("00:00:01:00:03");
|
||||
dummyGBDevice.setState(GBDevice.State.INITIALIZED);
|
||||
@ -49,7 +52,7 @@ public class CalendarEventTest extends TestBase {
|
||||
|
||||
testCR.syncCalendar(eventList);
|
||||
|
||||
eventList.add(new CalendarEvent(BEGIN, END, ID_2, null, "something", null, CALNAME_1, CALACCOUNTNAME_1, COLOR_1, false));
|
||||
eventList.add(new CalendarEvent(BEGIN, END, ID_2, null, "something", null, CALNAME_1, CALACCOUNTNAME_1, COLOR_1, false, null));
|
||||
testCR.syncCalendar(eventList);
|
||||
|
||||
CalendarSyncStateDao calendarSyncStateDao = daoSession.getCalendarSyncStateDao();
|
||||
|
Loading…
Reference in New Issue
Block a user