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)
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 {

View File

@ -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) {

View File

@ -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<Event> = ArrayList()
var prevEventsHash = 0
private var mEvents: List<Event> = 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<Event>) {
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<ListItem>(events.size)
val sorted = events.sortedWith(compareBy({ it.startTS }, { it.endTS }, { it.title }, { it.description }))
mEvents = filtered
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))
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)
}