Fix entries of transferred habits and dragging and dropping of groups

pull/2020/head
Dharanish 1 year ago
parent e85f5822b6
commit 0ae5a53594

@ -52,18 +52,18 @@ class HabitCardListController @Inject constructor(
val habitFrom = adapter.getHabit(from) val habitFrom = adapter.getHabit(from)
val habitTo = adapter.getHabit(to) val habitTo = adapter.getHabit(to)
if (habitFrom != null && habitTo != null) { if (habitFrom != null) {
adapter.performReorder(from, to) if (habitTo != null) {
behavior.onReorderHabit(habitFrom, habitTo) adapter.performReorder(from, to)
behavior.onReorderHabit(habitFrom, habitTo)
}
return return
} }
val hgrFrom = adapter.getHabitGroup(from) val hgrFrom = adapter.getHabitGroup(from)!!
val hgrTo = adapter.getHabitGroup(to) val hgrTo = adapter.getHabitGroup(to) ?: return
if (hgrFrom != null && hgrTo != null) { adapter.performReorder(from, to)
adapter.performReorder(from, to) behavior.onReorderHabitGroup(hgrFrom, hgrTo)
behavior.onReorderHabitGroup(hgrFrom, hgrTo)
}
} }
override fun onItemClick(position: Int) { override fun onItemClick(position: Int) {

@ -28,13 +28,15 @@ data class AddToGroupCommand(
val selected: List<Habit> val selected: List<Habit>
) : Command { ) : Command {
override fun run() { override fun run() {
for (h in selected) { for (habit in selected) {
val oldGroup = h.group val entries = habit.originalEntries.getKnown()
(oldGroup?.habitList ?: habitList).remove(h) val oldGroup = habit.group
h.groupId = hgr.id (oldGroup?.habitList ?: habitList).remove(habit)
h.groupUUID = hgr.uuid habit.groupId = hgr.id
h.group = hgr habit.groupUUID = hgr.uuid
hgr.habitList.add(h) habit.group = hgr
hgr.habitList.add(habit)
entries.forEach { habit.originalEntries.add(it) }
} }
} }
} }

@ -28,11 +28,13 @@ data class RemoveFromGroupCommand(
override fun run() { override fun run() {
for (habit in selected) { for (habit in selected) {
val hgr = habit.group!! val hgr = habit.group!!
val entries = habit.originalEntries.getKnown()
hgr.habitList.remove(habit) hgr.habitList.remove(habit)
habit.groupId = null habit.groupId = null
habit.group = null habit.group = null
habit.groupUUID = null habit.groupUUID = null
habitList.add(habit) habitList.add(habit)
entries.forEach { habit.originalEntries.add(it) }
} }
} }
} }

@ -534,7 +534,7 @@ class HabitCardListCache @Inject constructor(
if (!isValidInsert(habitGroup, toPosition)) return if (!isValidInsert(habitGroup, toPosition)) return
val fromIdx = positionIndices[fromPosition] val fromIdx = positionIndices[fromPosition]
val habitList = subHabits[fromIdx] val habitList = subHabits[fromIdx]
val toIdx = habitGroups.indexOf(positionToHabitGroup[toPosition]) - (if (fromPosition < toPosition) 1 else 0) val toIdx = habitGroups.indexOf(positionToHabitGroup[toPosition])
habitGroups.removeAt(fromIdx) habitGroups.removeAt(fromIdx)
subHabits.removeAt(fromIdx) subHabits.removeAt(fromIdx)

Loading…
Cancel
Save