Add Habits to groups without displaying

This commit is contained in:
Dharanish
2024-07-03 00:17:40 +02:00
parent 17e6c4f6e9
commit cac62c0278
13 changed files with 50 additions and 21 deletions

View File

@@ -132,6 +132,7 @@ data class Habit(
this.type = other.type
this.unit = other.unit
this.uuid = other.uuid
this.parent = other.parent
this.parentID = other.parentID
this.parentUUID = other.parentUUID
}

View File

@@ -19,6 +19,7 @@ data class HabitGroup(
) {
init {
if (uuid == null) this.uuid = UUID.randomUUID().toString().replace("-", "")
habitList.groupUUID = this.uuid
}
var observable = ModelObservable()
@@ -77,6 +78,7 @@ data class HabitGroup(
this.question = other.question
this.reminder = other.reminder
this.uuid = other.uuid
this.habitList.groupUUID = this.uuid
}
override fun equals(other: Any?): Boolean {

View File

@@ -34,6 +34,8 @@ abstract class HabitList : Iterable<Habit> {
@JvmField
protected val filter: HabitMatcher
var groupUUID: String? = null
/**
* Creates a new HabitList.
*

View File

@@ -22,8 +22,6 @@ import org.isoron.uhabits.core.models.Habit
import org.isoron.uhabits.core.models.HabitList
import org.isoron.uhabits.core.models.HabitMatcher
import org.isoron.uhabits.core.utils.DateUtils.Companion.getTodayWithOffset
import java.util.ArrayList
import java.util.Comparator
import java.util.LinkedList
import java.util.Objects

View File

@@ -37,6 +37,7 @@ class SQLiteHabitList @Inject constructor(private val modelFactory: ModelFactory
private fun loadRecords() {
if (loaded) return
loaded = true
list.groupUUID = this.groupUUID
list.removeAll()
val records = repository.findAll("order by position")
var shouldRebuildOrder = false
@@ -45,7 +46,7 @@ class SQLiteHabitList @Inject constructor(private val modelFactory: ModelFactory
val h = modelFactory.buildHabit()
rec.copyTo(h)
(h.originalEntries as SQLiteEntryList).habitId = h.id
list.add(h)
if (h.parentUUID == list.groupUUID) list.add(h)
}
if (shouldRebuildOrder) rebuildOrder()
}

View File

@@ -476,7 +476,7 @@ class HabitCardListCache @Inject constructor(
logger.error("performMove: $fromPosition for habit group is out of bounds")
return
}
data.habitGroups.removeAt(fromPosition)
data.habitGroups.removeAt(fromPosition - data.habits.size)
// Workaround for https://github.com/iSoron/uhabits/issues/968
val checkedToPosition = if (toPosition < data.habits.size) {

View File

@@ -33,8 +33,8 @@ class ListHabitsMenuBehavior @Inject constructor(
private var showCompleted: Boolean
private var showArchived: Boolean
fun onCreateHabit() {
screen.showSelectHabitTypeDialog()
fun onCreateHabit(parentUUID: String? = null) {
screen.showSelectHabitTypeDialog(parentUUID)
}
fun onViewFAQ() {
@@ -132,7 +132,7 @@ class ListHabitsMenuBehavior @Inject constructor(
fun showAboutScreen()
fun showFAQScreen()
fun showSettingsScreen()
fun showSelectHabitTypeDialog()
fun showSelectHabitTypeDialog(parentUUID: String? = null)
}
init {