update yearly view after changing filtering

This commit is contained in:
tibbi 2017-02-12 18:02:27 +01:00
parent cf4f549a57
commit c9f3e6fec3
4 changed files with 19 additions and 4 deletions

View File

@ -161,7 +161,7 @@ class MainActivity : SimpleActivity(), NavigationListener {
private fun refreshViewPager() {
if (config.storedView == YEARLY_VIEW) {
(main_view_pager.adapter as MyYearPagerAdapter).refreshEvents(main_view_pager.currentItem)
} else if (config.storedView == EVENTS_LIST_VIEW) {
} else if (config.storedView == WEEKLY_VIEW) {

View File

@ -4,11 +4,13 @@ import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.support.v4.app.FragmentStatePagerAdapter
import android.util.SparseArray
import com.simplemobiletools.calendar.fragments.YearFragment
import com.simplemobiletools.calendar.helpers.YEAR_LABEL
import com.simplemobiletools.calendar.interfaces.NavigationListener
class MyYearPagerAdapter(fm: FragmentManager, val mYears: List<Int>, val mListener: NavigationListener) : FragmentStatePagerAdapter(fm) {
private val mFragments = SparseArray<YearFragment>()
override fun getCount() = mYears.size
@ -20,6 +22,14 @@ class MyYearPagerAdapter(fm: FragmentManager, val mYears: List<Int>, val mListen
val fragment = YearFragment()
fragment.arguments = bundle
fragment.setListener(mListener)
mFragments.put(position, fragment)
return fragment
}
fun refreshEvents(pos: Int) {
for (i in -1..1) {
mFragments[pos + i].updateEvents()
}
}
}

View File

@ -46,7 +46,10 @@ class YearFragment : Fragment(), YearlyCalendar {
mSundayFirst = sundayFirst
setupMonths()
}
updateEvents()
}
fun updateEvents() {
mCalendar.getEvents(mYear)
}

View File

@ -2,6 +2,7 @@ package com.simplemobiletools.calendar.helpers
import android.content.Context
import android.util.SparseArray
import com.simplemobiletools.calendar.extensions.getFilteredEvents
import com.simplemobiletools.calendar.extensions.seconds
import com.simplemobiletools.calendar.interfaces.YearlyCalendar
import com.simplemobiletools.calendar.models.Event
@ -18,13 +19,14 @@ class YearlyCalendarImpl(val callback: YearlyCalendar, val context: Context, val
}
override fun gotEvents(events: MutableList<Event>) {
val filtered = context.getFilteredEvents(events)
val arr = SparseArray<ArrayList<Int>>(12)
for (event in events) {
val startDateTime = DateTime().withMillis(event.startTS * 1000L)
for ((id, startTS, endTS) in filtered) {
val startDateTime = DateTime().withMillis(startTS * 1000L)
markDay(arr, startDateTime)
val startCode = Formatter.getDayCodeFromDateTime(startDateTime)
val endDateTime = DateTime().withMillis(event.endTS * 1000L)
val endDateTime = DateTime().withMillis(endTS * 1000L)
val endCode = Formatter.getDayCodeFromDateTime(endDateTime)
if (startCode != endCode) {
var currDateTime = startDateTime