mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-14 21:18:51 -06:00
Fixed sorting habit groups and sub habits by score
This commit is contained in:
@@ -136,6 +136,17 @@ abstract class HabitList : Iterable<Habit> {
|
|||||||
*/
|
*/
|
||||||
abstract fun remove(h: Habit)
|
abstract fun remove(h: Habit)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the reference to the habit from the list at the given position.
|
||||||
|
*
|
||||||
|
* Does not affect the repository or records
|
||||||
|
*
|
||||||
|
* If the given habit is not in the list, does nothing.
|
||||||
|
*
|
||||||
|
* @param h the habit to be removed.
|
||||||
|
*/
|
||||||
|
abstract fun removeAt(position: Int)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes all the habits from the list.
|
* Removes all the habits from the list.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -191,6 +191,13 @@ class MemoryHabitList : HabitList {
|
|||||||
observable.notifyListeners()
|
observable.notifyListeners()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
|
override fun removeAt(position: Int) {
|
||||||
|
throwIfHasParent()
|
||||||
|
list.removeAt(position)
|
||||||
|
observable.notifyListeners()
|
||||||
|
}
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
override fun reorder(from: Habit, to: Habit) {
|
override fun reorder(from: Habit, to: Habit) {
|
||||||
throwIfHasParent()
|
throwIfHasParent()
|
||||||
|
|||||||
@@ -157,6 +157,12 @@ class SQLiteHabitList @Inject constructor(private val modelFactory: ModelFactory
|
|||||||
observable.notifyListeners()
|
observable.notifyListeners()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
|
override fun removeAt(position: Int) {
|
||||||
|
loadRecords()
|
||||||
|
list.removeAt(position)
|
||||||
|
}
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
override fun removeAll() {
|
override fun removeAll() {
|
||||||
list.removeAll()
|
list.removeAll()
|
||||||
|
|||||||
@@ -261,11 +261,6 @@ class HabitCardListCache @Inject constructor(
|
|||||||
@Synchronized
|
@Synchronized
|
||||||
fun reorder(from: Int, to: Int) {
|
fun reorder(from: Int, to: Int) {
|
||||||
if (from == to) return
|
if (from == to) return
|
||||||
val uuid = if (data.positionTypes[from] == STANDALONE_HABIT) {
|
|
||||||
data.positionToHabit[from]!!.uuid
|
|
||||||
} else {
|
|
||||||
data.positionToHabitGroup[from]!!.uuid
|
|
||||||
}
|
|
||||||
if (data.positionTypes[from] == STANDALONE_HABIT) {
|
if (data.positionTypes[from] == STANDALONE_HABIT) {
|
||||||
val habit = data.positionToHabit[from]!!
|
val habit = data.positionToHabit[from]!!
|
||||||
data.performMove(habit, from, to)
|
data.performMove(habit, from, to)
|
||||||
@@ -423,10 +418,7 @@ class HabitCardListCache @Inject constructor(
|
|||||||
if (habit.parentUUID == null) {
|
if (habit.parentUUID == null) {
|
||||||
return position <= habits.size
|
return position <= habits.size
|
||||||
} else {
|
} else {
|
||||||
val parent = uuidToHabitGroup[habit.parentUUID]
|
val parent = uuidToHabitGroup[habit.parentUUID] ?: return false
|
||||||
if (parent == null) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
val parentPosition = uuidToPosition[habit.parentUUID]!!
|
val parentPosition = uuidToPosition[habit.parentUUID]!!
|
||||||
val parentIndex = habitGroups.indexOf(parent)
|
val parentIndex = habitGroups.indexOf(parent)
|
||||||
val nextGroup = habitGroups.getOrNull(parentIndex + 1)
|
val nextGroup = habitGroups.getOrNull(parentIndex + 1)
|
||||||
@@ -494,7 +486,7 @@ class HabitCardListCache @Inject constructor(
|
|||||||
// Workaround for https://github.com/iSoron/uhabits/issues/968
|
// Workaround for https://github.com/iSoron/uhabits/issues/968
|
||||||
val checkedToPosition = if (toPosition > positionTypes.size) {
|
val checkedToPosition = if (toPosition > positionTypes.size) {
|
||||||
logger.error("performMove: $toPosition for habit is strictly higher than ${habits.size}")
|
logger.error("performMove: $toPosition for habit is strictly higher than ${habits.size}")
|
||||||
positionTypes.size
|
positionTypes.size - 1
|
||||||
} else {
|
} else {
|
||||||
toPosition
|
toPosition
|
||||||
}
|
}
|
||||||
@@ -515,15 +507,16 @@ class HabitCardListCache @Inject constructor(
|
|||||||
} else {
|
} else {
|
||||||
val hgr = uuidToHabitGroup[habit.parentUUID]
|
val hgr = uuidToHabitGroup[habit.parentUUID]
|
||||||
val hgrIdx = habitGroups.indexOf(hgr)
|
val hgrIdx = habitGroups.indexOf(hgr)
|
||||||
val h = positionToHabit[fromPosition]!!
|
val fromIdx = subHabits[hgrIdx].indexOf(habit)
|
||||||
subHabits[hgrIdx].remove(h)
|
subHabits[hgrIdx].removeAt(fromIdx)
|
||||||
positionTypes.removeAt(fromPosition)
|
positionTypes.removeAt(fromPosition)
|
||||||
if (fromPosition < checkedToPosition) {
|
if (fromPosition < checkedToPosition) {
|
||||||
decrementPositions(fromPosition + 1, checkedToPosition)
|
decrementPositions(fromPosition + 1, checkedToPosition)
|
||||||
} else {
|
} else {
|
||||||
incrementPositions(checkedToPosition, fromPosition - 1)
|
incrementPositions(checkedToPosition, fromPosition - 1)
|
||||||
}
|
}
|
||||||
subHabits[hgrIdx].add(checkedToPosition - uuidToPosition[hgr!!.uuid]!! - 1, habit)
|
val toIdx = checkedToPosition - uuidToPosition[hgr!!.uuid]!! - 1
|
||||||
|
subHabits[hgrIdx].add(toIdx, habit)
|
||||||
positionTypes.add(checkedToPosition, SUB_HABIT)
|
positionTypes.add(checkedToPosition, SUB_HABIT)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user