mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-03-03 10:57:41 +01:00
properly prefill weekly view fragments
This commit is contained in:
parent
31d334ab1f
commit
0f51133e6d
@ -8,6 +8,7 @@ import androidx.fragment.app.FragmentStatePagerAdapter
|
||||
import com.simplemobiletools.calendar.pro.fragments.WeekFragment
|
||||
import com.simplemobiletools.calendar.pro.helpers.WEEK_START_TIMESTAMP
|
||||
import com.simplemobiletools.calendar.pro.interfaces.WeekFragmentListener
|
||||
import com.simplemobiletools.commons.helpers.DAY_SECONDS
|
||||
|
||||
class MyWeekPagerAdapter(fm: FragmentManager, private val mWeekTimestamps: List<Long>, private val mListener: WeekFragmentListener) : FragmentStatePagerAdapter(fm) {
|
||||
private val mFragments = SparseArray<WeekFragment>()
|
||||
@ -43,7 +44,10 @@ class MyWeekPagerAdapter(fm: FragmentManager, private val mWeekTimestamps: List<
|
||||
mFragments[pos + 1]?.updateNotVisibleViewScaleLevel()
|
||||
}
|
||||
|
||||
fun updateVisibleDaysCount(pos: Int, count: Int) {
|
||||
fun updateVisibleDaysCount(pos: Int, count: Int, currentWeekTimestamp: Long) {
|
||||
mFragments[pos - 1]?.updateWeekStartTimestamp(currentWeekTimestamp - count * DAY_SECONDS)
|
||||
mFragments[pos + 1]?.updateWeekStartTimestamp(currentWeekTimestamp + count * DAY_SECONDS)
|
||||
|
||||
for (i in -1..1) {
|
||||
mFragments[pos + i]?.updateVisibleDaysCount(count)
|
||||
}
|
||||
|
@ -185,6 +185,11 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
||||
setupDayLabels()
|
||||
}
|
||||
|
||||
fun updateWeekStartTimestamp(newTimestamp: Long) {
|
||||
weekTimestamp = newTimestamp
|
||||
updateCalendar()
|
||||
}
|
||||
|
||||
private fun addDayColumns() {
|
||||
mView.week_events_columns_holder.removeAllViews()
|
||||
(0 until config.weeklyViewDays).forEach {
|
||||
|
@ -23,6 +23,7 @@ import com.simplemobiletools.calendar.pro.interfaces.WeekFragmentListener
|
||||
import com.simplemobiletools.calendar.pro.views.MyScrollView
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.WEEK_SECONDS
|
||||
import com.simplemobiletools.commons.helpers.mydebug
|
||||
import com.simplemobiletools.commons.views.MyViewPager
|
||||
import kotlinx.android.synthetic.main.fragment_week_holder.view.*
|
||||
import org.joda.time.DateTime
|
||||
@ -133,10 +134,11 @@ class WeekFragmentsHolder : MyFragmentHolder(), WeekFragmentListener {
|
||||
private fun getWeekTimestamps(targetSeconds: Long): List<Long> {
|
||||
val weekTSs = ArrayList<Long>(PREFILLED_WEEKS)
|
||||
val dateTime = Formatter.getDateTimeFromTS(targetSeconds)
|
||||
var currentWeek = dateTime.minusWeeks(PREFILLED_WEEKS / 2)
|
||||
val shownWeekDays = context!!.config.weeklyViewDays
|
||||
var currentWeek = dateTime.minusDays(PREFILLED_WEEKS / 2 * shownWeekDays)
|
||||
for (i in 0 until PREFILLED_WEEKS) {
|
||||
weekTSs.add(currentWeek.seconds())
|
||||
currentWeek = currentWeek.plusWeeks(1)
|
||||
currentWeek = currentWeek.plusDays(shownWeekDays)
|
||||
}
|
||||
return weekTSs
|
||||
}
|
||||
@ -206,7 +208,7 @@ class WeekFragmentsHolder : MyFragmentHolder(), WeekFragmentListener {
|
||||
|
||||
private fun updateDaysCount(cnt: Int) {
|
||||
weekHolder!!.week_view_days_count.text = context!!.resources.getQuantityString(R.plurals.days, cnt, cnt)
|
||||
(viewPager?.adapter as? MyWeekPagerAdapter)?.updateVisibleDaysCount(viewPager!!.currentItem, cnt)
|
||||
(viewPager?.adapter as? MyWeekPagerAdapter)?.updateVisibleDaysCount(viewPager!!.currentItem, cnt, currentWeekTS)
|
||||
}
|
||||
|
||||
override fun refreshEvents() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user