mirror of
https://codeberg.org/timelimit/timelimit-android.git
synced 2025-10-03 09:49:25 +02:00
Fix incorrect used time at rules that apply per day at days where they do not apply
This commit is contained in:
parent
d5bc1f9881
commit
1cdaed60e1
1 changed files with 19 additions and 6 deletions
|
@ -31,6 +31,7 @@ import io.timelimit.android.logic.RemainingTime
|
||||||
import io.timelimit.android.ui.manage.category.timelimit_rules.TimeLimitRulesHandlers
|
import io.timelimit.android.ui.manage.category.timelimit_rules.TimeLimitRulesHandlers
|
||||||
import io.timelimit.android.ui.util.DateUtil
|
import io.timelimit.android.ui.util.DateUtil
|
||||||
import io.timelimit.android.util.DayNameUtil
|
import io.timelimit.android.util.DayNameUtil
|
||||||
|
import io.timelimit.android.util.Option
|
||||||
import io.timelimit.android.util.TimeTextUtil
|
import io.timelimit.android.util.TimeTextUtil
|
||||||
import kotlin.properties.Delegates
|
import kotlin.properties.Delegates
|
||||||
|
|
||||||
|
@ -159,12 +160,24 @@ class AppAndRuleAdapter: RecyclerView.Adapter<AppAndRuleAdapter.Holder>() {
|
||||||
val binding = holder.itemView.tag as FragmentCategoryTimeLimitRuleItemBinding
|
val binding = holder.itemView.tag as FragmentCategoryTimeLimitRuleItemBinding
|
||||||
val context = binding.root.context
|
val context = binding.root.context
|
||||||
val usedTime = date?.let { date ->
|
val usedTime = date?.let { date ->
|
||||||
RemainingTime.getUsedTime(
|
val dayOfWeekForDailyRule: Option<Int?>? =
|
||||||
usedTimes = usedTimes,
|
if (rule.perDay) {
|
||||||
rule = rule,
|
(0 until 7)
|
||||||
firstDayOfWeekAsEpochDay = date.firstDayOfWeekAsEpochDay,
|
.map { (7 + date.dayOfWeek - it) % 7 } // make the current day the last one
|
||||||
dayOfWeekForDailyRule = if (rule.perDay) date.dayOfWeek else null
|
.firstOrNull { rule.dayMask.toInt() and (1 shl it) != 0 }
|
||||||
).toInt()
|
?.let { Option.Some(it) } // skip calculation if no day matches
|
||||||
|
} else Option.Some(null) // use the value null
|
||||||
|
|
||||||
|
dayOfWeekForDailyRule?.let {
|
||||||
|
RemainingTime.getUsedTime(
|
||||||
|
usedTimes = usedTimes,
|
||||||
|
rule = rule,
|
||||||
|
firstDayOfWeekAsEpochDay = date.firstDayOfWeekAsEpochDay,
|
||||||
|
dayOfWeekForDailyRule =
|
||||||
|
if (it is Option.Some) it.value
|
||||||
|
else null
|
||||||
|
).toInt()
|
||||||
|
}
|
||||||
} ?: 0
|
} ?: 0
|
||||||
|
|
||||||
binding.maxTimeString = rule.maximumTimeInMillis.let { time ->
|
binding.maxTimeString = rule.maximumTimeInMillis.let { time ->
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue