Fix habit group creation

This commit is contained in:
Dharanish
2024-07-02 16:10:02 +02:00
parent 676f141d99
commit 17e6c4f6e9
4 changed files with 12 additions and 3 deletions

View File

@@ -56,6 +56,8 @@ data class Habit(
val uriString: String
get() = "content://org.isoron.uhabits/habit/$id"
fun isSubHabit(): Boolean = parentUUID != null
fun hasReminder(): Boolean = reminder != null
fun isCompletedToday(): Boolean {

View File

@@ -472,6 +472,10 @@ class HabitCardListCache @Inject constructor(
fromPosition: Int,
toPosition: Int
) {
if (fromPosition < data.habits.size || fromPosition > data.habits.size + data.habitGroups.size) {
logger.error("performMove: $fromPosition for habit group is out of bounds")
return
}
data.habitGroups.removeAt(fromPosition)
// Workaround for https://github.com/iSoron/uhabits/issues/968
@@ -536,7 +540,7 @@ class HabitCardListCache @Inject constructor(
val habitGroup = newData.habitGroups[currentPosition - data.habits.size]
val uuid = habitGroup.uuid
val prevPosition = data.habitGroups.indexOf(habitGroup) + data.habits.size
if (prevPosition < 0) {
if (prevPosition < data.habits.size) {
performInsert(habitGroup, currentPosition)
} else {
if (prevPosition != currentPosition) {