Implement sub habit reordering within group

This commit is contained in:
Dharanish
2024-07-07 00:29:58 +02:00
parent be81a06e62
commit 8df1fb765c
2 changed files with 7 additions and 3 deletions

View File

@@ -259,10 +259,11 @@ class HabitCardListCache @Inject constructor(
@Synchronized
fun reorder(from: Int, to: Int) {
if (from == to) return
if (data.positionTypes[from] == STANDALONE_HABIT) {
val type = data.positionTypes[from]
if (type == STANDALONE_HABIT || type == SUB_HABIT) {
val habit = data.positionToHabit[from]!!
data.performMove(habit, from, to)
} else if (data.positionTypes[from] == HABIT_GROUP) {
} else {
val habitGroup = data.positionToHabitGroup[from]!!
data.performMove(habitGroup, from, to)
}

View File

@@ -112,7 +112,10 @@ open class ListHabitsBehavior @Inject constructor(
}
fun onReorderHabit(from: Habit, to: Habit) {
taskRunner.execute { habitList.reorder(from, to) }
if (from.parent == to.parent) {
val list = from.parent?.habitList ?: habitList
taskRunner.execute { list.reorder(from, to) }
}
}
fun onRepairDB() {