diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt index efb55b929..d41afb247 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt @@ -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() diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/MyWeekPagerAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/MyWeekPagerAdapter.kt index 9e2fea2bf..41c0bb287 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/MyWeekPagerAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/MyWeekPagerAdapter.kt @@ -30,4 +30,10 @@ class MyWeekPagerAdapter(fm: FragmentManager, val mWeekTimestamps: List, va mFragments[pos - 1].updateScrollY(y) mFragments[pos + 1].updateScrollY(y) } + + fun refreshEvents(pos: Int) { + for (i in -1..1) { + mFragments[pos + i].updateEvents() + } + } } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/FilterEventTypesDialog.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/FilterEventTypesDialog.kt index c8f918190..dc179c072 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/FilterEventTypesDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/FilterEventTypesDialog.kt @@ -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() } } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt index 4cc9bcbbe..57842a54e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt @@ -122,6 +122,12 @@ fun Context.getReminderText(minutes: Int) = when (minutes) { } } +fun Context.getFilteredEvents(events: List): List { + 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) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/WeekFragment.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/WeekFragment.kt index ba433e0a5..29954e834 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/WeekFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/WeekFragment.kt @@ -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 = ArrayList() lateinit var inflater: LayoutInflater lateinit var mView: View @@ -209,9 +213,16 @@ class WeekFragment : Fragment(), WeeklyCalendar { } override fun updateWeeklyCalendar(events: List) { + 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