apply the selected event filters on every view, including widgets

This commit is contained in:
tibbi 2018-10-24 13:59:33 +02:00
parent e0918b446f
commit f5fba4c477
9 changed files with 18 additions and 43 deletions

View File

@ -89,7 +89,7 @@ class WidgetMonthlyConfigureActivity : SimpleActivity(), MonthlyCalendar {
config_bg_seekbar.progress = (mBgAlpha * 100).toInt()
updateBgColor()
MonthlyCalendarImpl(this, applicationContext).updateMonthlyCalendar(DateTime().withDayOfMonth(1), false)
MonthlyCalendarImpl(this, applicationContext).updateMonthlyCalendar(DateTime().withDayOfMonth(1))
}
private fun saveConfig() {

View File

@ -156,7 +156,7 @@ class EventListWidgetAdapter(val context: Context) : RemoteViewsService.RemoteVi
mediumFontSize = context.config.getFontSize()
val fromTS = DateTime().seconds() - context.config.displayPastEvents * 60
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 replaceDescription = context.config.replaceDescription
val sorted = it.sortedWith(compareBy({ it.startTS }, { it.endTS }, { it.title }, { if (replaceDescription) it.location else it.description }))

View File

@ -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() {
dbHelper.getRunningEvents().filter { it.getReminders().isNotEmpty() }.forEach {
notifyEvent(it)

View File

@ -15,7 +15,6 @@ import com.simplemobiletools.calendar.activities.SimpleActivity
import com.simplemobiletools.calendar.adapters.DayEventsAdapter
import com.simplemobiletools.calendar.extensions.config
import com.simplemobiletools.calendar.extensions.dbHelper
import com.simplemobiletools.calendar.extensions.getFilteredEvents
import com.simplemobiletools.calendar.helpers.DAY_CODE
import com.simplemobiletools.calendar.helpers.EVENT_ID
import com.simplemobiletools.calendar.helpers.EVENT_OCCURRENCE_TS
@ -112,15 +111,14 @@ class DayFragment : Fragment() {
}
private fun receivedEvents(events: List<Event>) {
val filtered = context?.getFilteredEvents(events) ?: ArrayList()
val newHash = filtered.hashCode()
val newHash = events.hashCode()
if (newHash == lastHash || !isAdded) {
return
}
lastHash = newHash
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
})))

View File

@ -98,7 +98,7 @@ class EventListFragment : MyFragmentHolder(), RefreshRecyclerViewListener {
return
}
mEvents = context!!.getFilteredEvents(events)
mEvents = events
val listItems = context!!.getEventListItems(mEvents)
activity?.runOnUiThread {

View File

@ -5,17 +5,16 @@ import android.content.res.Resources
import android.graphics.Rect
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.util.SparseIntArray
import android.view.*
import android.widget.ImageView
import android.widget.RelativeLayout
import android.widget.TextView
import androidx.fragment.app.Fragment
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.activities.EventActivity
import com.simplemobiletools.calendar.extensions.config
import com.simplemobiletools.calendar.extensions.dbHelper
import com.simplemobiletools.calendar.extensions.getFilteredEvents
import com.simplemobiletools.calendar.extensions.seconds
import com.simplemobiletools.calendar.helpers.*
import com.simplemobiletools.calendar.helpers.Formatter
@ -219,14 +218,13 @@ class WeekFragment : Fragment(), WeeklyCalendar {
return
}
val newEvents = context!!.getFilteredEvents(events)
val newHash = newEvents.hashCode()
val newHash = events.hashCode()
if (newHash == lastHash) {
return
}
lastHash = newHash
this.events = newEvents
this.events = events
updateEvents()
}

View File

@ -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) {
Thread {
getEventsInBackground(fromTS, toTS, eventId, callback = callback)
getEventsInBackground(fromTS, toTS, eventId, callback)
}.start()
}
fun getEventsInBackground(fromTS: Int,
toTS: Int,
eventId: Int = -1,
filterEventType: Boolean = false,
callback: (events: ArrayList<Event>) -> Unit) {
fun getEventsInBackground(fromTS: Int, toTS: Int, eventId: Int = -1, callback: (events: ArrayList<Event>) -> Unit) {
var events = ArrayList<Event>()
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))
if (filterEventType) {
val displayEventTypes = context.config.displayEventTypes
events = events.filter {
displayEventTypes.contains(it.eventType.toString())
} as ArrayList<Event>
}
val displayEventTypes = context.config.displayEventTypes
events = events.filter {
displayEventTypes.contains(it.eventType.toString())
} as ArrayList<Event>
events = events
.asSequence()

View File

@ -3,7 +3,6 @@ package com.simplemobiletools.calendar.helpers
import android.content.Context
import com.simplemobiletools.calendar.extensions.config
import com.simplemobiletools.calendar.extensions.dbHelper
import com.simplemobiletools.calendar.extensions.getFilteredEvents
import com.simplemobiletools.calendar.extensions.seconds
import com.simplemobiletools.calendar.interfaces.MonthlyCalendar
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 var mEvents = ArrayList<Event>()
private var mFilterEventTypes = true
lateinit var mTargetDate: DateTime
fun updateMonthlyCalendar(targetDate: DateTime, filterEventTypes: Boolean = true) {
mFilterEventTypes = filterEventTypes
fun updateMonthlyCalendar(targetDate: DateTime) {
mTargetDate = targetDate
val startTS = mTargetDate.minusDays(7).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>) {
mEvents = if (mFilterEventTypes) {
mContext.getFilteredEvents(events)
} else {
events
}
mEvents = events
getDays(true)
}
}

View File

@ -3,7 +3,6 @@ package com.simplemobiletools.calendar.helpers
import android.content.Context
import android.util.SparseArray
import com.simplemobiletools.calendar.extensions.dbHelper
import com.simplemobiletools.calendar.extensions.getFilteredEvents
import com.simplemobiletools.calendar.extensions.seconds
import com.simplemobiletools.calendar.interfaces.YearlyCalendar
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>) {
val filtered = context.getFilteredEvents(events)
val arr = SparseArray<ArrayList<DayYearly>>(12)
filtered.forEach {
events.forEach {
val startDateTime = Formatter.getDateTimeFromTS(it.startTS)
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) {