From b99c74666fea355519823ec30b076ea78ce5a5a6 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 12 Feb 2017 18:32:19 +0100 Subject: [PATCH] filter events on the eventlist --- .../calendar/activities/MainActivity.kt | 3 +-- .../calendar/activities/SettingsActivity.kt | 2 +- .../calendar/fragments/EventListFragment.kt | 23 +++++++++++-------- 3 files changed, 16 insertions(+), 12 deletions(-) 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 e2ae87348..66a717050 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt @@ -60,7 +60,6 @@ class MainActivity : SimpleActivity(), NavigationListener { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) calendar_fab.setOnClickListener { addNewEvent() } - updateViewPager() checkWhatsNewDialog() } @@ -163,7 +162,7 @@ class MainActivity : SimpleActivity(), NavigationListener { if (config.storedView == YEARLY_VIEW) { (main_view_pager.adapter as MyYearPagerAdapter).refreshEvents(main_view_pager.currentItem) } else if (config.storedView == EVENTS_LIST_VIEW) { - + fillEventsList() } else if (config.storedView == WEEKLY_VIEW) { (week_view_view_pager.adapter as MyWeekPagerAdapter).refreshEvents(week_view_view_pager.currentItem) } else { diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt index 14e50d584..a9701f008 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt @@ -190,7 +190,7 @@ class SettingsActivity : SimpleActivity() { if (uri == null) { config.reminderSound = "" } else { - settings_reminder_sound.text = RingtoneManager.getRingtone(this, uri as Uri).getTitle(this) + settings_reminder_sound.text = RingtoneManager.getRingtone(this, uri as Uri)?.getTitle(this) config.reminderSound = uri.toString() } } else if (requestCode == REQUEST_ACCOUNT_NAME && resultData?.extras != null) { diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/EventListFragment.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/EventListFragment.kt index f06e4d51f..d0d53be1a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/EventListFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/EventListFragment.kt @@ -11,6 +11,7 @@ import com.simplemobiletools.calendar.activities.EventActivity import com.simplemobiletools.calendar.activities.SimpleActivity import com.simplemobiletools.calendar.adapters.EventListAdapter import com.simplemobiletools.calendar.extensions.config +import com.simplemobiletools.calendar.extensions.getFilteredEvents import com.simplemobiletools.calendar.extensions.seconds import com.simplemobiletools.calendar.helpers.DBHelper import com.simplemobiletools.calendar.helpers.EVENT_ID @@ -28,8 +29,8 @@ import java.util.* import kotlin.comparisons.compareBy class EventListFragment : Fragment(), DBHelper.GetEventsListener, DBHelper.EventUpdateListener, DeleteItemsListener { - var mAllEvents: MutableList = ArrayList() - var prevEventsHash = 0 + private var mEvents: List = ArrayList() + private var prevEventsHash = 0 lateinit var mView: View override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? { @@ -51,13 +52,18 @@ class EventListFragment : Fragment(), DBHelper.GetEventsListener, DBHelper.Event } override fun gotEvents(events: MutableList) { - val hash = events.hashCode() - if (prevEventsHash == hash || context == null) + if (context == null) + return + + val filtered = context.getFilteredEvents(events) + val hash = filtered.hashCode() + if (prevEventsHash == hash) return prevEventsHash = hash - val listItems = ArrayList(events.size) - val sorted = events.sortedWith(compareBy({ it.startTS }, { it.endTS }, { it.title }, { it.description })) + mEvents = filtered + val listItems = ArrayList(mEvents.size) + val sorted = mEvents.sortedWith(compareBy({ it.startTS }, { it.endTS }, { it.title }, { it.description })) val sublist = sorted.subList(0, Math.min(sorted.size, 100)) var prevCode = "" sublist.forEach { @@ -70,7 +76,6 @@ class EventListFragment : Fragment(), DBHelper.GetEventsListener, DBHelper.Event listItems.add(ListEvent(it.id, it.startTS, it.endTS, it.title, it.description, it.isAllDay)) } - mAllEvents = events if (activity == null) return @@ -86,8 +91,8 @@ class EventListFragment : Fragment(), DBHelper.GetEventsListener, DBHelper.Event } private fun checkPlaceholderVisibility() { - mView.calendar_empty_list_placeholder.beVisibleIf(mAllEvents.isEmpty()) - mView.calendar_events_list.beGoneIf(mAllEvents.isEmpty()) + mView.calendar_empty_list_placeholder.beVisibleIf(mEvents.isEmpty()) + mView.calendar_events_list.beGoneIf(mEvents.isEmpty()) if (activity != null) mView.calendar_empty_list_placeholder.setTextColor(activity.config.textColor) }