mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2024-12-27 16:53:28 +01:00
just update monthly fragments at event rechecking, dont recreate them
This commit is contained in:
parent
91d5c3dd00
commit
e77ceeff2a
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ class MonthFragment : Fragment(), MonthlyCalendar {
|
||||
updateCalendar()
|
||||
}
|
||||
|
||||
private fun updateCalendar() {
|
||||
fun updateCalendar() {
|
||||
mCalendar?.updateMonthlyCalendar(Formatter.getDateTimeFromCode(mDayCode))
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user