just update monthly fragments at event rechecking, dont recreate them

This commit is contained in:
tibbi 2018-02-10 11:42:03 +01:00
parent 91d5c3dd00
commit e77ceeff2a
3 changed files with 13 additions and 2 deletions

View File

@ -4,11 +4,14 @@ 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.MonthFragment
import com.simplemobiletools.calendar.helpers.DAY_CODE
import com.simplemobiletools.calendar.interfaces.NavigationListener
class MyMonthPagerAdapter(fm: FragmentManager, private val mCodes: List<String>, private val mListener: NavigationListener) : FragmentStatePagerAdapter(fm) {
private val mFragments = SparseArray<MonthFragment>()
override fun getCount() = mCodes.size
override fun getItem(position: Int): Fragment {
@ -20,6 +23,14 @@ class MyMonthPagerAdapter(fm: FragmentManager, private val mCodes: List<String>,
fragment.arguments = bundle
fragment.listener = mListener
mFragments.put(position, fragment)
return fragment
}
fun updateCalendars(pos: Int) {
for (i in -1..1) {
mFragments[pos + i]?.updateCalendar()
}
}
}

View File

@ -78,7 +78,7 @@ class MonthFragment : Fragment(), MonthlyCalendar {
updateCalendar()
}
private fun updateCalendar() {
fun updateCalendar() {
mCalendar?.updateMonthlyCalendar(Formatter.getDateTimeFromCode(mDayCode))
}

View File

@ -98,7 +98,7 @@ class MonthFragmentsHolder : MyFragmentHolder(), NavigationListener {
}
override fun refreshEvents() {
setupFragment()
(viewPager?.adapter as? MyMonthPagerAdapter)?.updateCalendars(viewPager?.currentItem ?: 0)
}
override fun shouldGoToTodayBeVisible() = currentDayCode.getMonthCode() != todayDayCode.getMonthCode()