mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-02-17 12:20:51 +01:00
properly update yearly calendar at some change, don't recreate it
This commit is contained in:
parent
bffb0ba0a1
commit
a5a84a400a
@ -4,10 +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
|
||||
|
||||
class MyYearPagerAdapter(fm: FragmentManager, val mYears: List<Int>) : FragmentStatePagerAdapter(fm) {
|
||||
private val mFragments = SparseArray<YearFragment>()
|
||||
|
||||
override fun getCount() = mYears.size
|
||||
|
||||
override fun getItem(position: Int): Fragment {
|
||||
@ -18,6 +21,14 @@ class MyYearPagerAdapter(fm: FragmentManager, val mYears: List<Int>) : FragmentS
|
||||
val fragment = YearFragment()
|
||||
fragment.arguments = bundle
|
||||
|
||||
mFragments.put(position, fragment)
|
||||
|
||||
return fragment
|
||||
}
|
||||
|
||||
fun updateCalendars(pos: Int) {
|
||||
for (i in -1..1) {
|
||||
mFragments[pos + i]?.updateCalendar()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ class YearFragment : Fragment(), YearlyCalendar {
|
||||
setupMonths()
|
||||
|
||||
mCalendar = YearlyCalendarImpl(this, context!!, mYear)
|
||||
|
||||
return mView
|
||||
}
|
||||
|
||||
@ -52,10 +53,10 @@ class YearFragment : Fragment(), YearlyCalendar {
|
||||
mSundayFirst = sundayFirst
|
||||
setupMonths()
|
||||
}
|
||||
updateEvents()
|
||||
updateCalendar()
|
||||
}
|
||||
|
||||
fun updateEvents() {
|
||||
fun updateCalendar() {
|
||||
mCalendar?.getEvents(mYear)
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,7 @@ class YearFragmentsHolder : MyFragmentHolder() {
|
||||
}
|
||||
|
||||
override fun refreshEvents() {
|
||||
setupFragment()
|
||||
(viewPager?.adapter as? MyYearPagerAdapter)?.updateCalendars(viewPager?.currentItem ?: 0)
|
||||
}
|
||||
|
||||
override fun shouldGoToTodayBeVisible() = currentYear != todayYear
|
||||
|
Loading…
x
Reference in New Issue
Block a user