filter events on the eventlist

This commit is contained in:
tibbi 2017-02-12 18:32:19 +01:00
parent bb6073ac11
commit b99c74666f
3 changed files with 16 additions and 12 deletions

View File

@ -60,7 +60,6 @@ class MainActivity : SimpleActivity(), NavigationListener {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main) setContentView(R.layout.activity_main)
calendar_fab.setOnClickListener { addNewEvent() } calendar_fab.setOnClickListener { addNewEvent() }
updateViewPager()
checkWhatsNewDialog() checkWhatsNewDialog()
} }
@ -163,7 +162,7 @@ class MainActivity : SimpleActivity(), NavigationListener {
if (config.storedView == YEARLY_VIEW) { if (config.storedView == YEARLY_VIEW) {
(main_view_pager.adapter as MyYearPagerAdapter).refreshEvents(main_view_pager.currentItem) (main_view_pager.adapter as MyYearPagerAdapter).refreshEvents(main_view_pager.currentItem)
} else if (config.storedView == EVENTS_LIST_VIEW) { } else if (config.storedView == EVENTS_LIST_VIEW) {
fillEventsList()
} else if (config.storedView == WEEKLY_VIEW) { } else if (config.storedView == WEEKLY_VIEW) {
(week_view_view_pager.adapter as MyWeekPagerAdapter).refreshEvents(week_view_view_pager.currentItem) (week_view_view_pager.adapter as MyWeekPagerAdapter).refreshEvents(week_view_view_pager.currentItem)
} else { } else {

View File

@ -190,7 +190,7 @@ class SettingsActivity : SimpleActivity() {
if (uri == null) { if (uri == null) {
config.reminderSound = "" config.reminderSound = ""
} else { } 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() config.reminderSound = uri.toString()
} }
} else if (requestCode == REQUEST_ACCOUNT_NAME && resultData?.extras != null) { } else if (requestCode == REQUEST_ACCOUNT_NAME && resultData?.extras != null) {

View File

@ -11,6 +11,7 @@ import com.simplemobiletools.calendar.activities.EventActivity
import com.simplemobiletools.calendar.activities.SimpleActivity import com.simplemobiletools.calendar.activities.SimpleActivity
import com.simplemobiletools.calendar.adapters.EventListAdapter import com.simplemobiletools.calendar.adapters.EventListAdapter
import com.simplemobiletools.calendar.extensions.config import com.simplemobiletools.calendar.extensions.config
import com.simplemobiletools.calendar.extensions.getFilteredEvents
import com.simplemobiletools.calendar.extensions.seconds import com.simplemobiletools.calendar.extensions.seconds
import com.simplemobiletools.calendar.helpers.DBHelper import com.simplemobiletools.calendar.helpers.DBHelper
import com.simplemobiletools.calendar.helpers.EVENT_ID import com.simplemobiletools.calendar.helpers.EVENT_ID
@ -28,8 +29,8 @@ import java.util.*
import kotlin.comparisons.compareBy import kotlin.comparisons.compareBy
class EventListFragment : Fragment(), DBHelper.GetEventsListener, DBHelper.EventUpdateListener, DeleteItemsListener { class EventListFragment : Fragment(), DBHelper.GetEventsListener, DBHelper.EventUpdateListener, DeleteItemsListener {
var mAllEvents: MutableList<Event> = ArrayList() private var mEvents: List<Event> = ArrayList()
var prevEventsHash = 0 private var prevEventsHash = 0
lateinit var mView: View lateinit var mView: View
override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): 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<Event>) { override fun gotEvents(events: MutableList<Event>) {
val hash = events.hashCode() if (context == null)
if (prevEventsHash == hash || context == null) return
val filtered = context.getFilteredEvents(events)
val hash = filtered.hashCode()
if (prevEventsHash == hash)
return return
prevEventsHash = hash prevEventsHash = hash
val listItems = ArrayList<ListItem>(events.size) mEvents = filtered
val sorted = events.sortedWith(compareBy({ it.startTS }, { it.endTS }, { it.title }, { it.description })) val listItems = ArrayList<ListItem>(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)) val sublist = sorted.subList(0, Math.min(sorted.size, 100))
var prevCode = "" var prevCode = ""
sublist.forEach { 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)) listItems.add(ListEvent(it.id, it.startTS, it.endTS, it.title, it.description, it.isAllDay))
} }
mAllEvents = events
if (activity == null) if (activity == null)
return return
@ -86,8 +91,8 @@ class EventListFragment : Fragment(), DBHelper.GetEventsListener, DBHelper.Event
} }
private fun checkPlaceholderVisibility() { private fun checkPlaceholderVisibility() {
mView.calendar_empty_list_placeholder.beVisibleIf(mAllEvents.isEmpty()) mView.calendar_empty_list_placeholder.beVisibleIf(mEvents.isEmpty())
mView.calendar_events_list.beGoneIf(mAllEvents.isEmpty()) mView.calendar_events_list.beGoneIf(mEvents.isEmpty())
if (activity != null) if (activity != null)
mView.calendar_empty_list_placeholder.setTextColor(activity.config.textColor) mView.calendar_empty_list_placeholder.setTextColor(activity.config.textColor)
} }