Fix updating of group score ring on appropriate action

pull/2020/head
Dharanish 1 year ago
parent 3ba214ff61
commit 6b1eed0bdc

@ -45,6 +45,7 @@ import org.isoron.uhabits.activities.common.dialogs.WeekdayPickerDialog
import org.isoron.uhabits.core.commands.CommandRunner
import org.isoron.uhabits.core.commands.CreateHabitCommand
import org.isoron.uhabits.core.commands.EditHabitCommand
import org.isoron.uhabits.core.commands.RefreshParentGroupCommand
import org.isoron.uhabits.core.models.Frequency
import org.isoron.uhabits.core.models.Habit
import org.isoron.uhabits.core.models.HabitGroup
@ -319,6 +320,13 @@ class EditHabitActivity : AppCompatActivity() {
)
}
component.commandRunner.run(command)
if (habit.parentID != null) {
val habitGroupList = component.habitGroupList
val refreshCommand = RefreshParentGroupCommand(habit, habitGroupList)
component.commandRunner.run(refreshCommand)
}
finish()
}

@ -78,6 +78,20 @@ abstract class HabitGroupList : Iterable<HabitGroup> {
return null
}
/**
* Returns the habit with the specified UUID which is
* present in any of the habit groups within this habit group list.
*/
fun getHabitByID(id: Long): Habit? {
for (hgr in this) {
val habit = hgr.habitList.getById(id)
if (habit != null) {
return habit
}
}
return null
}
/**
* Returns the habit group that occupies a certain position.
*

@ -145,7 +145,9 @@ class ScoreList {
) {
var current = to
while (current >= from) {
val habitScores = habitList.map { it.scores[current].value }
val habitScores = habitList
.filter { !it.isArchived }
.map { it.scores[current].value }
val averageScore = if (habitScores.isNotEmpty()) habitScores.average() else 0.0
map[current] = Score(current, averageScore)
current = current.minus(1)

@ -79,8 +79,9 @@ class StreakList {
var current = from
var streakRunning = false
var streakStart = from
val notArchivedHabits = habitList.filter { !it.isArchived }
while (current <= to) {
if (habitList.all { it.streaks.isInStreaks(current) }) {
if (notArchivedHabits.all { it.streaks.isInStreaks(current) }) {
if (!streakRunning) {
streakStart = current
streakRunning = true

@ -25,6 +25,7 @@ import org.isoron.uhabits.core.commands.ChangeHabitGroupColorCommand
import org.isoron.uhabits.core.commands.CommandRunner
import org.isoron.uhabits.core.commands.DeleteHabitGroupsCommand
import org.isoron.uhabits.core.commands.DeleteHabitsCommand
import org.isoron.uhabits.core.commands.RefreshParentGroupCommand
import org.isoron.uhabits.core.commands.UnarchiveHabitsCommand
import org.isoron.uhabits.core.models.Habit
import org.isoron.uhabits.core.models.HabitGroup
@ -61,6 +62,9 @@ class ListHabitsSelectionMenuBehavior @Inject constructor(
fun onArchiveHabits() {
commandRunner.run(ArchiveHabitsCommand(habitList, adapter.getSelectedHabits()))
commandRunner.run(ArchiveHabitGroupsCommand(habitGroupList, adapter.getSelectedHabitGroups()))
for (habit in adapter.getSelectedHabits()) {
commandRunner.run(RefreshParentGroupCommand(habit, habitGroupList))
}
adapter.clearSelection()
}
@ -97,6 +101,9 @@ class ListHabitsSelectionMenuBehavior @Inject constructor(
adapter.performRemoveHabitGroup(adapter.getSelectedHabitGroups())
commandRunner.run(DeleteHabitGroupsCommand(habitGroupList, adapter.getSelectedHabitGroups()))
commandRunner.run(DeleteHabitsCommand(habitList, adapter.getSelectedHabits()))
for (habit in adapter.getSelectedHabits()) {
commandRunner.run(RefreshParentGroupCommand(habit, habitGroupList))
}
adapter.clearSelection()
},
adapter.getSelectedHabits().size + adapter.getSelectedHabitGroups().size
@ -117,6 +124,9 @@ class ListHabitsSelectionMenuBehavior @Inject constructor(
fun onUnarchiveHabits() {
commandRunner.run(UnarchiveHabitsCommand(habitList, adapter.getSelectedHabits()))
for (habit in adapter.getSelectedHabits()) {
commandRunner.run(RefreshParentGroupCommand(habit, habitGroupList))
}
adapter.clearSelection()
}

@ -52,7 +52,7 @@ class EditHabitCommandTest : BaseUnitTest() {
@Test
fun testExecute() {
command = EditHabitCommand(habitList, habit.id!!, modified)
command = EditHabitCommand(habitList, habit.uuid!!, modified)
val originalScore = habit.scores[today].value
assertThat(habit.name, equalTo("original"))
command.run()

@ -67,6 +67,7 @@ class ListHabitsBehaviorTest : BaseUnitTest() {
clearInvocations(habitList)
behavior = ListHabitsBehavior(
habitList,
habitGroupList,
dirFinder,
taskRunner,
screen,

Loading…
Cancel
Save