Add toast message for skip days on History editor

pull/2012/head
Dharanish 1 year ago
parent f0a40bcac6
commit efdf216323

@ -38,6 +38,7 @@ import org.isoron.uhabits.activities.common.dialogs.CheckmarkDialog
import org.isoron.uhabits.activities.common.dialogs.ConfirmDeleteDialog import org.isoron.uhabits.activities.common.dialogs.ConfirmDeleteDialog
import org.isoron.uhabits.activities.common.dialogs.HistoryEditorDialog import org.isoron.uhabits.activities.common.dialogs.HistoryEditorDialog
import org.isoron.uhabits.activities.common.dialogs.NumberDialog import org.isoron.uhabits.activities.common.dialogs.NumberDialog
import org.isoron.uhabits.core.commands.BlockSkippedDayCommand
import org.isoron.uhabits.core.commands.Command import org.isoron.uhabits.core.commands.Command
import org.isoron.uhabits.core.commands.CommandRunner import org.isoron.uhabits.core.commands.CommandRunner
import org.isoron.uhabits.core.models.Habit import org.isoron.uhabits.core.models.Habit
@ -70,6 +71,7 @@ class ShowHabitActivity : AppCompatActivity(), CommandRunner.Listener {
private val scope = CoroutineScope(Dispatchers.Main) private val scope = CoroutineScope(Dispatchers.Main)
private lateinit var presenter: ShowHabitPresenter private lateinit var presenter: ShowHabitPresenter
private val screen = Screen() private val screen = Screen()
val activity = (this as AppCompatActivity)
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -138,9 +140,20 @@ class ShowHabitActivity : AppCompatActivity(), CommandRunner.Listener {
} }
override fun onCommandFinished(command: Command) { override fun onCommandFinished(command: Command) {
val msg = getExecuteString(command)
if (msg != null) activity.showMessage(msg)
screen.refresh() screen.refresh()
} }
private fun getExecuteString(command: Command): String? {
return when (command) {
is BlockSkippedDayCommand -> {
getString(R.string.toast_day_auto_skip)
}
else -> null
}
}
inner class Screen : ShowHabitMenuPresenter.Screen, ShowHabitPresenter.Screen { inner class Screen : ShowHabitMenuPresenter.Screen, ShowHabitPresenter.Screen {
override fun updateWidgets() { override fun updateWidgets() {
widgetUpdater.updateWidgets() widgetUpdater.updateWidgets()

@ -48,7 +48,8 @@ open class EntryList {
/** /**
* Returns one entry for each day in the given interval. The first element corresponds to the * Returns one entry for each day in the given interval. The first element corresponds to the
* newest entry, and the last element corresponds to the oldest. The interval endpoints are * newest entry, and the last element corresponds to the oldest. The interval endpoints are
* included. * included. Takes into account whether days are to be regularly skipped and returns SKIP
* accordingly.
*/ */
@Synchronized @Synchronized
open fun getByInterval(from: Timestamp, to: Timestamp, skipDays: SkipDays = SkipDays.NONE): List<Entry> { open fun getByInterval(from: Timestamp, to: Timestamp, skipDays: SkipDays = SkipDays.NONE): List<Entry> {

@ -63,6 +63,7 @@ class ScoreList {
/** /**
* Recomputes all scores between the provided [from] and [to] timestamps. * Recomputes all scores between the provided [from] and [to] timestamps.
* Takes into account whether some days of the week are automatically skipped.
*/ */
@Synchronized @Synchronized
fun recompute( fun recompute(

@ -18,6 +18,12 @@
*/ */
package org.isoron.uhabits.core.models package org.isoron.uhabits.core.models
/**
* If [isSkipDays] is enabled, then the selected [days] of the week are regularly skipped, and
* the score is automatically calculated based on that. For measurable weekly tasks and weekly
* boolean tasks with frequency < 1, the target is not changed but distributed over the rest of the
* days of the week.
*/
data class SkipDays( data class SkipDays(
val isSkipDays: Boolean, val isSkipDays: Boolean,
val days: WeekdayList val days: WeekdayList

@ -46,6 +46,8 @@ class StreakList {
.filter { it.value > 0 } .filter { it.value > 0 }
.map { it.timestamp } .map { it.timestamp }
.toTypedArray() .toTypedArray()
// gets all the values to make sure that streaks do no consist of just SKIP entries
val values = computedEntries val values = computedEntries
.getByInterval(from, to, skipDays) .getByInterval(from, to, skipDays)
.filter { it.value > 0 } .filter { it.value > 0 }

Loading…
Cancel
Save