diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/MyMonthPagerAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/MyMonthPagerAdapter.kt index 6dcbd50c6..17ed299cb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/MyMonthPagerAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/MyMonthPagerAdapter.kt @@ -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, private val mListener: NavigationListener) : FragmentStatePagerAdapter(fm) { + private val mFragments = SparseArray() + override fun getCount() = mCodes.size override fun getItem(position: Int): Fragment { @@ -20,6 +23,14 @@ class MyMonthPagerAdapter(fm: FragmentManager, private val mCodes: List, 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() + } + } } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/MonthFragment.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/MonthFragment.kt index 67c17a1ec..3eec7a054 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/MonthFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/MonthFragment.kt @@ -78,7 +78,7 @@ class MonthFragment : Fragment(), MonthlyCalendar { updateCalendar() } - private fun updateCalendar() { + fun updateCalendar() { mCalendar?.updateMonthlyCalendar(Formatter.getDateTimeFromCode(mDayCode)) } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/MonthFragmentsHolder.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/MonthFragmentsHolder.kt index 2254039f1..930953498 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/MonthFragmentsHolder.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/MonthFragmentsHolder.kt @@ -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()