Update the events selector. Fix #95
This commit is contained in:
parent
d91471d1ee
commit
ff171d4022
@ -16,17 +16,13 @@ class EventRepository(val context: Context) {
|
|||||||
private val realm by lazy { Realm.getDefaultInstance() }
|
private val realm by lazy { Realm.getDefaultInstance() }
|
||||||
|
|
||||||
fun saveEvents(eventList: ArrayList<Event>) {
|
fun saveEvents(eventList: ArrayList<Event>) {
|
||||||
realm.executeTransactionAsync { realm ->
|
realm.executeTransaction { realm ->
|
||||||
realm.where(Event::class.java).findAll().deleteAllFromRealm()
|
realm.where(Event::class.java).findAll().deleteAllFromRealm()
|
||||||
realm.copyToRealm(eventList)
|
realm.copyToRealm(eventList)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun resetNextEventData() {
|
fun resetNextEventData() {
|
||||||
realm.executeTransactionAsync {
|
|
||||||
it.where(Event::class.java).findAll().deleteAllFromRealm()
|
|
||||||
}
|
|
||||||
|
|
||||||
Preferences.bulk {
|
Preferences.bulk {
|
||||||
remove(Preferences::nextEventId)
|
remove(Preferences::nextEventId)
|
||||||
remove(Preferences::nextEventName)
|
remove(Preferences::nextEventName)
|
||||||
@ -95,8 +91,13 @@ class EventRepository(val context: Context) {
|
|||||||
|
|
||||||
fun getEvents(): RealmResults<Event> {
|
fun getEvents(): RealmResults<Event> {
|
||||||
val now = Calendar.getInstance().timeInMillis
|
val now = Calendar.getInstance().timeInMillis
|
||||||
|
realm.refresh()
|
||||||
return realm.where(Event::class.java).greaterThan("endDate", now).findAll()
|
return realm.where(Event::class.java).greaterThan("endDate", now).findAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getEventsCount(): Int = getEvents().size
|
fun getEventsCount(): Int = getEvents().size
|
||||||
|
|
||||||
|
fun close() {
|
||||||
|
realm.close()
|
||||||
|
}
|
||||||
}
|
}
|
@ -30,7 +30,7 @@ object Preferences : KotprefModel() {
|
|||||||
var customLocationLon by stringPref(key = "PREF_CUSTOM_LOCATION_LON", default = "")
|
var customLocationLon by stringPref(key = "PREF_CUSTOM_LOCATION_LON", default = "")
|
||||||
var customLocationAdd by stringPref(key = "PREF_CUSTOM_LOCATION_ADD", default = "")
|
var customLocationAdd by stringPref(key = "PREF_CUSTOM_LOCATION_ADD", default = "")
|
||||||
var dateFormat by stringPref(default = "")
|
var dateFormat by stringPref(default = "")
|
||||||
var isDateCapitalize by booleanPref(default = false)
|
var isDateCapitalize by booleanPref(default = true)
|
||||||
var weatherRefreshPeriod by intPref(key = "PREF_WEATHER_REFRESH_PERIOD", default = 1)
|
var weatherRefreshPeriod by intPref(key = "PREF_WEATHER_REFRESH_PERIOD", default = 1)
|
||||||
var showUntil by intPref(key = "PREF_SHOW_UNTIL", default = 1)
|
var showUntil by intPref(key = "PREF_SHOW_UNTIL", default = 1)
|
||||||
var calendarAppName by stringPref(key = "PREF_CALENDAR_APP_NAME", default = "")
|
var calendarAppName by stringPref(key = "PREF_CALENDAR_APP_NAME", default = "")
|
||||||
|
@ -31,6 +31,12 @@ object CalendarHelper {
|
|||||||
val eventList = ArrayList<Event>()
|
val eventList = ArrayList<Event>()
|
||||||
|
|
||||||
val now = Calendar.getInstance()
|
val now = Calendar.getInstance()
|
||||||
|
val begin = Calendar.getInstance().apply {
|
||||||
|
set(Calendar.MILLISECOND, 0)
|
||||||
|
set(Calendar.SECOND, 0)
|
||||||
|
set(Calendar.MINUTE, 0)
|
||||||
|
set(Calendar.HOUR_OF_DAY, 0)
|
||||||
|
}
|
||||||
val limit = Calendar.getInstance()
|
val limit = Calendar.getInstance()
|
||||||
when (Preferences.showUntil) {
|
when (Preferences.showUntil) {
|
||||||
0 -> limit.add(Calendar.HOUR, 3)
|
0 -> limit.add(Calendar.HOUR, 3)
|
||||||
@ -45,7 +51,7 @@ object CalendarHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val builder = CalendarContract.Instances.CONTENT_URI.buildUpon()
|
val builder = CalendarContract.Instances.CONTENT_URI.buildUpon()
|
||||||
ContentUris.appendId(builder, now.timeInMillis)
|
ContentUris.appendId(builder, begin.timeInMillis)
|
||||||
ContentUris.appendId(builder, limit.timeInMillis)
|
ContentUris.appendId(builder, limit.timeInMillis)
|
||||||
|
|
||||||
if (!context.checkGrantedPermission(
|
if (!context.checkGrantedPermission(
|
||||||
@ -56,14 +62,14 @@ object CalendarHelper {
|
|||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
val provider = CalendarProvider(context)
|
val provider = CalendarProvider(context)
|
||||||
val data = provider.getInstances(now.timeInMillis, limit.timeInMillis)
|
val data = provider.getInstances(begin.timeInMillis, limit.timeInMillis)
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
val instances = data.list
|
val instances = data.list
|
||||||
for (instance in instances) {
|
for (instance in instances) {
|
||||||
try {
|
try {
|
||||||
val e = provider.getEvent(instance.eventId)
|
val e = provider.getEvent(instance.eventId)
|
||||||
Log.d("ciao", "evento: $e")
|
Log.d("ciao", "evento: $instance")
|
||||||
if (e != null && !e.deleted && instance.begin <= limit.timeInMillis && (Preferences.calendarAllDay || !e.allDay) && !getFilteredCalendarIdList().contains(
|
if (e != null && !e.deleted && instance.begin <= limit.timeInMillis && now.timeInMillis < instance.end && (Preferences.calendarAllDay || !e.allDay) && !getFilteredCalendarIdList().contains(
|
||||||
e.calendarId
|
e.calendarId
|
||||||
) && (Preferences.showDeclinedEvents || e.selfAttendeeStatus.toInt() != CalendarContract.Attendees.ATTENDEE_STATUS_DECLINED)
|
) && (Preferences.showDeclinedEvents || e.selfAttendeeStatus.toInt() != CalendarContract.Attendees.ATTENDEE_STATUS_DECLINED)
|
||||||
) {
|
) {
|
||||||
|
@ -114,19 +114,40 @@ object IntentHelper {
|
|||||||
if (Preferences.calendarAppPackage == "") {
|
if (Preferences.calendarAppPackage == "") {
|
||||||
Intent(Intent.ACTION_VIEW).apply {
|
Intent(Intent.ACTION_VIEW).apply {
|
||||||
data = uri
|
data = uri
|
||||||
putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, e.startDate)
|
if (!e.allDay) {
|
||||||
putExtra(CalendarContract.EXTRA_EVENT_END_TIME, e.endDate)
|
putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, e.startDate)
|
||||||
// putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, if (e.allDay) 1 else 0)
|
putExtra(CalendarContract.EXTRA_EVENT_END_TIME, e.endDate)
|
||||||
// type = "vnd.android.cursor.item/event"
|
} else {
|
||||||
|
val start = Calendar.getInstance().apply {
|
||||||
|
timeInMillis = e.startDate
|
||||||
|
}
|
||||||
|
val end = Calendar.getInstance().apply {
|
||||||
|
timeInMillis = e.endDate
|
||||||
|
}
|
||||||
|
|
||||||
|
putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, e.startDate + start.timeZone.getOffset(start.timeInMillis))
|
||||||
|
putExtra(CalendarContract.EXTRA_EVENT_END_TIME, e.endDate + end.timeZone.getOffset(end.timeInMillis))
|
||||||
|
putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, 1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
getCalendarIntent(context).apply {
|
getCalendarIntent(context).apply {
|
||||||
action = Intent.ACTION_VIEW
|
action = Intent.ACTION_VIEW
|
||||||
data = uri
|
data = uri
|
||||||
putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, e.startDate)
|
if (!e.allDay) {
|
||||||
putExtra(CalendarContract.EXTRA_EVENT_END_TIME, e.endDate)
|
putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, e.startDate)
|
||||||
// putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, if (e.allDay) 1 else 0)
|
putExtra(CalendarContract.EXTRA_EVENT_END_TIME, e.endDate)
|
||||||
// type = "vnd.android.cursor.item/event"
|
} else {
|
||||||
|
val start = Calendar.getInstance().apply {
|
||||||
|
timeInMillis = e.startDate
|
||||||
|
}
|
||||||
|
val end = Calendar.getInstance().apply {
|
||||||
|
timeInMillis = e.endDate
|
||||||
|
}
|
||||||
|
putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, start.timeInMillis + start.timeZone.getOffset(start.timeInMillis))
|
||||||
|
putExtra(CalendarContract.EXTRA_EVENT_END_TIME, end.timeInMillis + end.timeZone.getOffset(end.timeInMillis))
|
||||||
|
putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, 1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user