refresh the weekly view if filtering was changed

This commit is contained in:
tibbi 2017-02-12 17:39:26 +01:00
parent bce6f85756
commit cf4f549a57
5 changed files with 41 additions and 3 deletions

View File

@ -132,7 +132,7 @@ class MainActivity : SimpleActivity(), NavigationListener {
private fun showFilterDialog() {
FilterEventTypesDialog(this) {
refreshViewPager()
}
}
@ -159,6 +159,18 @@ class MainActivity : SimpleActivity(), NavigationListener {
mWeekScrollY = 0
}
private fun refreshViewPager() {
if (config.storedView == YEARLY_VIEW) {
} else if (config.storedView == EVENTS_LIST_VIEW) {
} else if (config.storedView == WEEKLY_VIEW) {
(week_view_view_pager.adapter as MyWeekPagerAdapter).refreshEvents(week_view_view_pager.currentItem)
} else {
}
}
private fun tryImportEvents() {
if (hasReadStoragePermission()) {
importEvents()

View File

@ -30,4 +30,10 @@ class MyWeekPagerAdapter(fm: FragmentManager, val mWeekTimestamps: List<Int>, va
mFragments[pos - 1].updateScrollY(y)
mFragments[pos + 1].updateScrollY(y)
}
fun refreshEvents(pos: Int) {
for (i in -1..1) {
mFragments[pos + i].updateEvents()
}
}
}

View File

@ -34,7 +34,10 @@ class FilterEventTypesDialog(val activity: SimpleActivity, val callback: () -> U
private fun confirmEventTypes() {
val selectedItems = (view.filter_event_types_list.adapter as FilterEventTypeAdapter).getSelectedItemsSet()
activity.config.displayEventTypes = selectedItems
if (activity.config.displayEventTypes != selectedItems) {
activity.config.displayEventTypes = selectedItems
callback.invoke()
}
dialog.dismiss()
}
}

View File

@ -122,6 +122,12 @@ fun Context.getReminderText(minutes: Int) = when (minutes) {
}
}
fun Context.getFilteredEvents(events: List<Event>): List<Event> {
val displayEventTypes = config.displayEventTypes
val filtered = events.filter { displayEventTypes.contains(it.eventType.toString()) }
return filtered
}
fun Context.getNewEventTimestampFromCode(dayCode: String) = Formatter.getLocalDateTimeFromCode(dayCode).withTime(13, 0, 0, 0).seconds()
val Context.config: Config get() = Config.newInstance(this)

View File

@ -16,8 +16,10 @@ import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.activities.EventActivity
import com.simplemobiletools.calendar.activities.MainActivity
import com.simplemobiletools.calendar.extensions.config
import com.simplemobiletools.calendar.extensions.getFilteredEvents
import com.simplemobiletools.calendar.extensions.seconds
import com.simplemobiletools.calendar.helpers.*
import com.simplemobiletools.calendar.helpers.Formatter
import com.simplemobiletools.calendar.interfaces.WeeklyCalendar
import com.simplemobiletools.calendar.models.Event
import com.simplemobiletools.calendar.views.MyScrollView
@ -26,6 +28,7 @@ import kotlinx.android.synthetic.main.fragment_week.*
import kotlinx.android.synthetic.main.fragment_week.view.*
import org.joda.time.DateTime
import org.joda.time.Days
import java.util.*
import kotlin.comparisons.compareBy
class WeekFragment : Fragment(), WeeklyCalendar {
@ -45,6 +48,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
private var clickStartTime = 0L
private var selectedGrid: View? = null
private var todayColumnIndex = -1
private var events: List<Event> = ArrayList()
lateinit var inflater: LayoutInflater
lateinit var mView: View
@ -209,9 +213,16 @@ class WeekFragment : Fragment(), WeeklyCalendar {
}
override fun updateWeeklyCalendar(events: List<Event>) {
this.events = events
updateEvents()
}
fun updateEvents() {
if (mWasDestroyed)
return
val filtered = context.getFilteredEvents(events)
initGrid()
val fullHeight = mRes.getDimension(R.dimen.weekly_view_events_height)
val minuteHeight = fullHeight / (24 * 60)
@ -219,7 +230,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
activity.runOnUiThread { mView.week_all_day_holder.removeAllViews() }
var hadAllDayEvent = false
val sorted = events.sortedWith(compareBy({ it.startTS }, { it.endTS }, { it.title }, { it.description }))
val sorted = filtered.sortedWith(compareBy({ it.startTS }, { it.endTS }, { it.title }, { it.description }))
for (event in sorted) {
if (event.isAllDay || Formatter.getDayCodeFromTS(event.startTS) != Formatter.getDayCodeFromTS(event.endTS)) {
hadAllDayEvent = true