mirror of
https://codeberg.org/timelimit/opentimelimit-android.git
synced 2025-10-05 10:49:29 +02:00
Improve switching to detailed mode in blocked time area editor
This commit is contained in:
parent
dbd29af815
commit
0d149157d4
2 changed files with 14 additions and 4 deletions
|
@ -225,10 +225,20 @@ class BlockedTimeAreasFragment : Fragment() {
|
|||
}
|
||||
|
||||
detailed_mode.setOnCheckedChangeListener { _, isChecked ->
|
||||
items.value = when (isChecked) {
|
||||
val oldValue = items.value
|
||||
val newValue = when (isChecked) {
|
||||
true -> MinuteOfWeekItems
|
||||
false -> FifteenMinutesOfWeekItems
|
||||
}
|
||||
|
||||
if (oldValue != newValue) {
|
||||
val currentlyVisiblePosition = layoutManager.findFirstVisibleItemPosition()
|
||||
val currentlyVisibleItem = oldValue!!.getItemAtPosition(currentlyVisiblePosition)
|
||||
val newVisiblePosition = newValue.getPositionOfItem(currentlyVisibleItem)
|
||||
|
||||
items.value = newValue
|
||||
layoutManager.scrollToPositionWithOffset(newVisiblePosition, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ object FifteenMinutesOfWeekItems: BlockedTimeItems() {
|
|||
val hour = itemWithinDay / itemsPerHour
|
||||
val itemInHour = itemWithinDay % itemsPerHour
|
||||
|
||||
return MinuteTile(day, hour, itemInHour * 15, 15)
|
||||
return MinuteTile(day, hour, itemInHour * minutesPerTile, minutesPerTile)
|
||||
}
|
||||
|
||||
override fun getDayOfPosition(position: Int): Int {
|
||||
|
@ -50,7 +50,7 @@ object FifteenMinutesOfWeekItems: BlockedTimeItems() {
|
|||
|
||||
override fun getPositionOfItem(item: Item) = when(item) {
|
||||
is DayHeader -> item.day * itemsPerDay
|
||||
is HourHeader -> item.day * itemsPerDay + 0 + itemsPerHour * item.hour
|
||||
is MinuteTile -> item.day * itemsPerDay + 0 + itemsPerHour * item.hour + 1 + item.minute * 15
|
||||
is HourHeader -> item.day * itemsPerDay + 1 + itemsPerHour * item.hour
|
||||
is MinuteTile -> item.day * itemsPerDay + 1 + itemsPerHour * item.hour + 0 + item.minute / minutesPerTile
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue