mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-14 21:18:51 -06:00
Fix updating of group score ring on appropriate action
This commit is contained in:
@@ -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.CommandRunner
|
||||||
import org.isoron.uhabits.core.commands.CreateHabitCommand
|
import org.isoron.uhabits.core.commands.CreateHabitCommand
|
||||||
import org.isoron.uhabits.core.commands.EditHabitCommand
|
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.Frequency
|
||||||
import org.isoron.uhabits.core.models.Habit
|
import org.isoron.uhabits.core.models.Habit
|
||||||
import org.isoron.uhabits.core.models.HabitGroup
|
import org.isoron.uhabits.core.models.HabitGroup
|
||||||
@@ -319,6 +320,13 @@ class EditHabitActivity : AppCompatActivity() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
component.commandRunner.run(command)
|
component.commandRunner.run(command)
|
||||||
|
|
||||||
|
if (habit.parentID != null) {
|
||||||
|
val habitGroupList = component.habitGroupList
|
||||||
|
val refreshCommand = RefreshParentGroupCommand(habit, habitGroupList)
|
||||||
|
component.commandRunner.run(refreshCommand)
|
||||||
|
}
|
||||||
|
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -78,6 +78,20 @@ abstract class HabitGroupList : Iterable<HabitGroup> {
|
|||||||
return null
|
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.
|
* Returns the habit group that occupies a certain position.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -145,7 +145,9 @@ class ScoreList {
|
|||||||
) {
|
) {
|
||||||
var current = to
|
var current = to
|
||||||
while (current >= from) {
|
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
|
val averageScore = if (habitScores.isNotEmpty()) habitScores.average() else 0.0
|
||||||
map[current] = Score(current, averageScore)
|
map[current] = Score(current, averageScore)
|
||||||
current = current.minus(1)
|
current = current.minus(1)
|
||||||
|
|||||||
@@ -79,8 +79,9 @@ class StreakList {
|
|||||||
var current = from
|
var current = from
|
||||||
var streakRunning = false
|
var streakRunning = false
|
||||||
var streakStart = from
|
var streakStart = from
|
||||||
|
val notArchivedHabits = habitList.filter { !it.isArchived }
|
||||||
while (current <= to) {
|
while (current <= to) {
|
||||||
if (habitList.all { it.streaks.isInStreaks(current) }) {
|
if (notArchivedHabits.all { it.streaks.isInStreaks(current) }) {
|
||||||
if (!streakRunning) {
|
if (!streakRunning) {
|
||||||
streakStart = current
|
streakStart = current
|
||||||
streakRunning = true
|
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.CommandRunner
|
||||||
import org.isoron.uhabits.core.commands.DeleteHabitGroupsCommand
|
import org.isoron.uhabits.core.commands.DeleteHabitGroupsCommand
|
||||||
import org.isoron.uhabits.core.commands.DeleteHabitsCommand
|
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.commands.UnarchiveHabitsCommand
|
||||||
import org.isoron.uhabits.core.models.Habit
|
import org.isoron.uhabits.core.models.Habit
|
||||||
import org.isoron.uhabits.core.models.HabitGroup
|
import org.isoron.uhabits.core.models.HabitGroup
|
||||||
@@ -61,6 +62,9 @@ class ListHabitsSelectionMenuBehavior @Inject constructor(
|
|||||||
fun onArchiveHabits() {
|
fun onArchiveHabits() {
|
||||||
commandRunner.run(ArchiveHabitsCommand(habitList, adapter.getSelectedHabits()))
|
commandRunner.run(ArchiveHabitsCommand(habitList, adapter.getSelectedHabits()))
|
||||||
commandRunner.run(ArchiveHabitGroupsCommand(habitGroupList, adapter.getSelectedHabitGroups()))
|
commandRunner.run(ArchiveHabitGroupsCommand(habitGroupList, adapter.getSelectedHabitGroups()))
|
||||||
|
for (habit in adapter.getSelectedHabits()) {
|
||||||
|
commandRunner.run(RefreshParentGroupCommand(habit, habitGroupList))
|
||||||
|
}
|
||||||
adapter.clearSelection()
|
adapter.clearSelection()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,6 +101,9 @@ class ListHabitsSelectionMenuBehavior @Inject constructor(
|
|||||||
adapter.performRemoveHabitGroup(adapter.getSelectedHabitGroups())
|
adapter.performRemoveHabitGroup(adapter.getSelectedHabitGroups())
|
||||||
commandRunner.run(DeleteHabitGroupsCommand(habitGroupList, adapter.getSelectedHabitGroups()))
|
commandRunner.run(DeleteHabitGroupsCommand(habitGroupList, adapter.getSelectedHabitGroups()))
|
||||||
commandRunner.run(DeleteHabitsCommand(habitList, adapter.getSelectedHabits()))
|
commandRunner.run(DeleteHabitsCommand(habitList, adapter.getSelectedHabits()))
|
||||||
|
for (habit in adapter.getSelectedHabits()) {
|
||||||
|
commandRunner.run(RefreshParentGroupCommand(habit, habitGroupList))
|
||||||
|
}
|
||||||
adapter.clearSelection()
|
adapter.clearSelection()
|
||||||
},
|
},
|
||||||
adapter.getSelectedHabits().size + adapter.getSelectedHabitGroups().size
|
adapter.getSelectedHabits().size + adapter.getSelectedHabitGroups().size
|
||||||
@@ -117,6 +124,9 @@ class ListHabitsSelectionMenuBehavior @Inject constructor(
|
|||||||
|
|
||||||
fun onUnarchiveHabits() {
|
fun onUnarchiveHabits() {
|
||||||
commandRunner.run(UnarchiveHabitsCommand(habitList, adapter.getSelectedHabits()))
|
commandRunner.run(UnarchiveHabitsCommand(habitList, adapter.getSelectedHabits()))
|
||||||
|
for (habit in adapter.getSelectedHabits()) {
|
||||||
|
commandRunner.run(RefreshParentGroupCommand(habit, habitGroupList))
|
||||||
|
}
|
||||||
adapter.clearSelection()
|
adapter.clearSelection()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ class EditHabitCommandTest : BaseUnitTest() {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testExecute() {
|
fun testExecute() {
|
||||||
command = EditHabitCommand(habitList, habit.id!!, modified)
|
command = EditHabitCommand(habitList, habit.uuid!!, modified)
|
||||||
val originalScore = habit.scores[today].value
|
val originalScore = habit.scores[today].value
|
||||||
assertThat(habit.name, equalTo("original"))
|
assertThat(habit.name, equalTo("original"))
|
||||||
command.run()
|
command.run()
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ class ListHabitsBehaviorTest : BaseUnitTest() {
|
|||||||
clearInvocations(habitList)
|
clearInvocations(habitList)
|
||||||
behavior = ListHabitsBehavior(
|
behavior = ListHabitsBehavior(
|
||||||
habitList,
|
habitList,
|
||||||
|
habitGroupList,
|
||||||
dirFinder,
|
dirFinder,
|
||||||
taskRunner,
|
taskRunner,
|
||||||
screen,
|
screen,
|
||||||
|
|||||||
Reference in New Issue
Block a user