make the grid columnt count dynamic at weekly view

This commit is contained in:
tibbi 2020-06-08 16:02:31 +02:00
parent 783890bf46
commit 507719af7c
4 changed files with 17 additions and 3 deletions

View File

@ -42,4 +42,10 @@ class MyWeekPagerAdapter(fm: FragmentManager, private val mWeekTimestamps: List<
mFragments[pos - 1]?.updateNotVisibleViewScaleLevel()
mFragments[pos + 1]?.updateNotVisibleViewScaleLevel()
}
fun updateVisibleDaysCount(pos: Int, count: Int) {
for (i in -1..1) {
mFragments[pos + i]?.updateVisibleDaysCount(count)
}
}
}

View File

@ -169,6 +169,13 @@ class WeekFragment : Fragment(), WeeklyCalendar {
}
}
fun updateVisibleDaysCount(count: Int) {
mView.week_horizontal_grid_holder.apply {
daysCount = count
invalidate()
}
}
private fun setupDayLabels() {
var curDay = Formatter.getDateTimeFromTS(weekTimestamp)
val textColor = config.textColor

View File

@ -207,6 +207,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)
}
override fun refreshEvents() {

View File

@ -10,8 +10,8 @@ import com.simplemobiletools.calendar.pro.extensions.getWeeklyViewItemHeight
class WeeklyViewGrid(context: Context, attrs: AttributeSet, defStyle: Int) : View(context, attrs, defStyle) {
private val ROWS_CNT = 24
private val COLS_CNT = 7
private var paint = Paint(Paint.ANTI_ALIAS_FLAG)
var daysCount = 7
constructor(context: Context, attrs: AttributeSet) : this(context, attrs, 0)
@ -27,8 +27,8 @@ class WeeklyViewGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
canvas.drawLine(0f, y, width.toFloat(), y, paint)
}
val rowWidth = width / COLS_CNT.toFloat()
for (i in 0 until COLS_CNT) {
val rowWidth = width / daysCount.toFloat()
for (i in 0 until daysCount) {
val x = rowWidth * i.toFloat()
canvas.drawLine(x, 0f, x, height.toFloat(), paint)
}