apply the selected event filters on every view, including widgets
This commit is contained in:
parent
e0918b446f
commit
f5fba4c477
|
@ -89,7 +89,7 @@ class WidgetMonthlyConfigureActivity : SimpleActivity(), MonthlyCalendar {
|
||||||
config_bg_seekbar.progress = (mBgAlpha * 100).toInt()
|
config_bg_seekbar.progress = (mBgAlpha * 100).toInt()
|
||||||
updateBgColor()
|
updateBgColor()
|
||||||
|
|
||||||
MonthlyCalendarImpl(this, applicationContext).updateMonthlyCalendar(DateTime().withDayOfMonth(1), false)
|
MonthlyCalendarImpl(this, applicationContext).updateMonthlyCalendar(DateTime().withDayOfMonth(1))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun saveConfig() {
|
private fun saveConfig() {
|
||||||
|
|
|
@ -156,7 +156,7 @@ class EventListWidgetAdapter(val context: Context) : RemoteViewsService.RemoteVi
|
||||||
mediumFontSize = context.config.getFontSize()
|
mediumFontSize = context.config.getFontSize()
|
||||||
val fromTS = DateTime().seconds() - context.config.displayPastEvents * 60
|
val fromTS = DateTime().seconds() - context.config.displayPastEvents * 60
|
||||||
val toTS = DateTime().plusYears(1).seconds()
|
val toTS = DateTime().plusYears(1).seconds()
|
||||||
context.dbHelper.getEventsInBackground(fromTS, toTS, filterEventType = true) {
|
context.dbHelper.getEventsInBackground(fromTS, toTS) {
|
||||||
val listItems = ArrayList<ListItem>(it.size)
|
val listItems = ArrayList<ListItem>(it.size)
|
||||||
val replaceDescription = context.config.replaceDescription
|
val replaceDescription = context.config.replaceDescription
|
||||||
val sorted = it.sortedWith(compareBy({ it.startTS }, { it.endTS }, { it.title }, { if (replaceDescription) it.location else it.description }))
|
val sorted = it.sortedWith(compareBy({ it.startTS }, { it.endTS }, { it.title }, { if (replaceDescription) it.location else it.description }))
|
||||||
|
|
|
@ -146,11 +146,6 @@ fun Context.getRepetitionText(seconds: Int) = when (seconds) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Context.getFilteredEvents(events: List<Event>): ArrayList<Event> {
|
|
||||||
val displayEventTypes = config.displayEventTypes
|
|
||||||
return events.filter { displayEventTypes.contains(it.eventType.toString()) } as ArrayList<Event>
|
|
||||||
}
|
|
||||||
|
|
||||||
fun Context.notifyRunningEvents() {
|
fun Context.notifyRunningEvents() {
|
||||||
dbHelper.getRunningEvents().filter { it.getReminders().isNotEmpty() }.forEach {
|
dbHelper.getRunningEvents().filter { it.getReminders().isNotEmpty() }.forEach {
|
||||||
notifyEvent(it)
|
notifyEvent(it)
|
||||||
|
|
|
@ -15,7 +15,6 @@ import com.simplemobiletools.calendar.activities.SimpleActivity
|
||||||
import com.simplemobiletools.calendar.adapters.DayEventsAdapter
|
import com.simplemobiletools.calendar.adapters.DayEventsAdapter
|
||||||
import com.simplemobiletools.calendar.extensions.config
|
import com.simplemobiletools.calendar.extensions.config
|
||||||
import com.simplemobiletools.calendar.extensions.dbHelper
|
import com.simplemobiletools.calendar.extensions.dbHelper
|
||||||
import com.simplemobiletools.calendar.extensions.getFilteredEvents
|
|
||||||
import com.simplemobiletools.calendar.helpers.DAY_CODE
|
import com.simplemobiletools.calendar.helpers.DAY_CODE
|
||||||
import com.simplemobiletools.calendar.helpers.EVENT_ID
|
import com.simplemobiletools.calendar.helpers.EVENT_ID
|
||||||
import com.simplemobiletools.calendar.helpers.EVENT_OCCURRENCE_TS
|
import com.simplemobiletools.calendar.helpers.EVENT_OCCURRENCE_TS
|
||||||
|
@ -112,15 +111,14 @@ class DayFragment : Fragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun receivedEvents(events: List<Event>) {
|
private fun receivedEvents(events: List<Event>) {
|
||||||
val filtered = context?.getFilteredEvents(events) ?: ArrayList()
|
val newHash = events.hashCode()
|
||||||
val newHash = filtered.hashCode()
|
|
||||||
if (newHash == lastHash || !isAdded) {
|
if (newHash == lastHash || !isAdded) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
lastHash = newHash
|
lastHash = newHash
|
||||||
|
|
||||||
val replaceDescription = context!!.config.replaceDescription
|
val replaceDescription = context!!.config.replaceDescription
|
||||||
val sorted = ArrayList<Event>(filtered.sortedWith(compareBy({ !it.getIsAllDay() }, { it.startTS }, { it.endTS }, { it.title }, {
|
val sorted = ArrayList<Event>(events.sortedWith(compareBy({ !it.getIsAllDay() }, { it.startTS }, { it.endTS }, { it.title }, {
|
||||||
if (replaceDescription) it.location else it.description
|
if (replaceDescription) it.location else it.description
|
||||||
})))
|
})))
|
||||||
|
|
||||||
|
|
|
@ -98,7 +98,7 @@ class EventListFragment : MyFragmentHolder(), RefreshRecyclerViewListener {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
mEvents = context!!.getFilteredEvents(events)
|
mEvents = events
|
||||||
val listItems = context!!.getEventListItems(mEvents)
|
val listItems = context!!.getEventListItems(mEvents)
|
||||||
|
|
||||||
activity?.runOnUiThread {
|
activity?.runOnUiThread {
|
||||||
|
|
|
@ -5,17 +5,16 @@ import android.content.res.Resources
|
||||||
import android.graphics.Rect
|
import android.graphics.Rect
|
||||||
import android.graphics.drawable.ColorDrawable
|
import android.graphics.drawable.ColorDrawable
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.fragment.app.Fragment
|
|
||||||
import android.util.SparseIntArray
|
import android.util.SparseIntArray
|
||||||
import android.view.*
|
import android.view.*
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.RelativeLayout
|
import android.widget.RelativeLayout
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
import com.simplemobiletools.calendar.R
|
import com.simplemobiletools.calendar.R
|
||||||
import com.simplemobiletools.calendar.activities.EventActivity
|
import com.simplemobiletools.calendar.activities.EventActivity
|
||||||
import com.simplemobiletools.calendar.extensions.config
|
import com.simplemobiletools.calendar.extensions.config
|
||||||
import com.simplemobiletools.calendar.extensions.dbHelper
|
import com.simplemobiletools.calendar.extensions.dbHelper
|
||||||
import com.simplemobiletools.calendar.extensions.getFilteredEvents
|
|
||||||
import com.simplemobiletools.calendar.extensions.seconds
|
import com.simplemobiletools.calendar.extensions.seconds
|
||||||
import com.simplemobiletools.calendar.helpers.*
|
import com.simplemobiletools.calendar.helpers.*
|
||||||
import com.simplemobiletools.calendar.helpers.Formatter
|
import com.simplemobiletools.calendar.helpers.Formatter
|
||||||
|
@ -219,14 +218,13 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val newEvents = context!!.getFilteredEvents(events)
|
val newHash = events.hashCode()
|
||||||
val newHash = newEvents.hashCode()
|
|
||||||
if (newHash == lastHash) {
|
if (newHash == lastHash) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
lastHash = newHash
|
lastHash = newHash
|
||||||
this.events = newEvents
|
this.events = events
|
||||||
updateEvents()
|
updateEvents()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -683,15 +683,11 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
||||||
|
|
||||||
fun getEvents(fromTS: Int, toTS: Int, eventId: Int = -1, callback: (events: ArrayList<Event>) -> Unit) {
|
fun getEvents(fromTS: Int, toTS: Int, eventId: Int = -1, callback: (events: ArrayList<Event>) -> Unit) {
|
||||||
Thread {
|
Thread {
|
||||||
getEventsInBackground(fromTS, toTS, eventId, callback = callback)
|
getEventsInBackground(fromTS, toTS, eventId, callback)
|
||||||
}.start()
|
}.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getEventsInBackground(fromTS: Int,
|
fun getEventsInBackground(fromTS: Int, toTS: Int, eventId: Int = -1, callback: (events: ArrayList<Event>) -> Unit) {
|
||||||
toTS: Int,
|
|
||||||
eventId: Int = -1,
|
|
||||||
filterEventType: Boolean = false,
|
|
||||||
callback: (events: ArrayList<Event>) -> Unit) {
|
|
||||||
var events = ArrayList<Event>()
|
var events = ArrayList<Event>()
|
||||||
|
|
||||||
var selection = "$COL_START_TS <= ? AND $COL_END_TS >= ? AND $COL_REPEAT_INTERVAL IS NULL AND $COL_START_TS != 0"
|
var selection = "$COL_START_TS <= ? AND $COL_END_TS >= ? AND $COL_REPEAT_INTERVAL IS NULL AND $COL_START_TS != 0"
|
||||||
|
@ -705,12 +701,10 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
||||||
|
|
||||||
events.addAll(getAllDayEvents(fromTS, eventId))
|
events.addAll(getAllDayEvents(fromTS, eventId))
|
||||||
|
|
||||||
if (filterEventType) {
|
|
||||||
val displayEventTypes = context.config.displayEventTypes
|
val displayEventTypes = context.config.displayEventTypes
|
||||||
events = events.filter {
|
events = events.filter {
|
||||||
displayEventTypes.contains(it.eventType.toString())
|
displayEventTypes.contains(it.eventType.toString())
|
||||||
} as ArrayList<Event>
|
} as ArrayList<Event>
|
||||||
}
|
|
||||||
|
|
||||||
events = events
|
events = events
|
||||||
.asSequence()
|
.asSequence()
|
||||||
|
|
|
@ -3,7 +3,6 @@ package com.simplemobiletools.calendar.helpers
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import com.simplemobiletools.calendar.extensions.config
|
import com.simplemobiletools.calendar.extensions.config
|
||||||
import com.simplemobiletools.calendar.extensions.dbHelper
|
import com.simplemobiletools.calendar.extensions.dbHelper
|
||||||
import com.simplemobiletools.calendar.extensions.getFilteredEvents
|
|
||||||
import com.simplemobiletools.calendar.extensions.seconds
|
import com.simplemobiletools.calendar.extensions.seconds
|
||||||
import com.simplemobiletools.calendar.interfaces.MonthlyCalendar
|
import com.simplemobiletools.calendar.interfaces.MonthlyCalendar
|
||||||
import com.simplemobiletools.calendar.models.DayMonthly
|
import com.simplemobiletools.calendar.models.DayMonthly
|
||||||
|
@ -18,12 +17,10 @@ class MonthlyCalendarImpl(val mCallback: MonthlyCalendar, val mContext: Context)
|
||||||
|
|
||||||
private val mToday: String = DateTime().toString(Formatter.DAYCODE_PATTERN)
|
private val mToday: String = DateTime().toString(Formatter.DAYCODE_PATTERN)
|
||||||
private var mEvents = ArrayList<Event>()
|
private var mEvents = ArrayList<Event>()
|
||||||
private var mFilterEventTypes = true
|
|
||||||
|
|
||||||
lateinit var mTargetDate: DateTime
|
lateinit var mTargetDate: DateTime
|
||||||
|
|
||||||
fun updateMonthlyCalendar(targetDate: DateTime, filterEventTypes: Boolean = true) {
|
fun updateMonthlyCalendar(targetDate: DateTime) {
|
||||||
mFilterEventTypes = filterEventTypes
|
|
||||||
mTargetDate = targetDate
|
mTargetDate = targetDate
|
||||||
val startTS = mTargetDate.minusDays(7).seconds()
|
val startTS = mTargetDate.minusDays(7).seconds()
|
||||||
val endTS = mTargetDate.plusDays(43).seconds()
|
val endTS = mTargetDate.plusDays(43).seconds()
|
||||||
|
@ -130,12 +127,7 @@ class MonthlyCalendarImpl(val mCallback: MonthlyCalendar, val mContext: Context)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun gotEvents(events: ArrayList<Event>) {
|
private fun gotEvents(events: ArrayList<Event>) {
|
||||||
mEvents = if (mFilterEventTypes) {
|
mEvents = events
|
||||||
mContext.getFilteredEvents(events)
|
|
||||||
} else {
|
|
||||||
events
|
|
||||||
}
|
|
||||||
|
|
||||||
getDays(true)
|
getDays(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@ package com.simplemobiletools.calendar.helpers
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.util.SparseArray
|
import android.util.SparseArray
|
||||||
import com.simplemobiletools.calendar.extensions.dbHelper
|
import com.simplemobiletools.calendar.extensions.dbHelper
|
||||||
import com.simplemobiletools.calendar.extensions.getFilteredEvents
|
|
||||||
import com.simplemobiletools.calendar.extensions.seconds
|
import com.simplemobiletools.calendar.extensions.seconds
|
||||||
import com.simplemobiletools.calendar.interfaces.YearlyCalendar
|
import com.simplemobiletools.calendar.interfaces.YearlyCalendar
|
||||||
import com.simplemobiletools.calendar.models.DayYearly
|
import com.simplemobiletools.calendar.models.DayYearly
|
||||||
|
@ -23,10 +22,9 @@ class YearlyCalendarImpl(val callback: YearlyCalendar, val context: Context, val
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun gotEvents(events: MutableList<Event>) {
|
private fun gotEvents(events: MutableList<Event>) {
|
||||||
val filtered = context.getFilteredEvents(events)
|
|
||||||
val arr = SparseArray<ArrayList<DayYearly>>(12)
|
val arr = SparseArray<ArrayList<DayYearly>>(12)
|
||||||
|
|
||||||
filtered.forEach {
|
events.forEach {
|
||||||
val startDateTime = Formatter.getDateTimeFromTS(it.startTS)
|
val startDateTime = Formatter.getDateTimeFromTS(it.startTS)
|
||||||
markDay(arr, startDateTime, it)
|
markDay(arr, startDateTime, it)
|
||||||
|
|
||||||
|
@ -41,7 +39,7 @@ class YearlyCalendarImpl(val callback: YearlyCalendar, val context: Context, val
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
callback.updateYearlyCalendar(arr, filtered.hashCode())
|
callback.updateYearlyCalendar(arr, events.hashCode())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun markDay(arr: SparseArray<ArrayList<DayYearly>>, dateTime: DateTime, event: Event) {
|
private fun markDay(arr: SparseArray<ArrayList<DayYearly>>, dateTime: DateTime, event: Event) {
|
||||||
|
|
Loading…
Reference in New Issue