mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-14 04:58:52 -06:00
Implement saving of sub habits but breaks updating group score ring
This commit is contained in:
@@ -97,7 +97,7 @@ class HabitCardView(
|
||||
set(value) {
|
||||
scoreRing.setPercentage(value.toFloat())
|
||||
scoreRing.setPrecision(1.0f / 16)
|
||||
behavior.onChangeScore(habit!!)
|
||||
// behavior.onChangeScore(habit!!)
|
||||
}
|
||||
|
||||
var unit
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
package org.isoron.uhabits.core.commands
|
||||
|
||||
import org.isoron.uhabits.core.models.Habit
|
||||
import org.isoron.uhabits.core.models.HabitGroup
|
||||
import org.isoron.uhabits.core.models.HabitList
|
||||
|
||||
data class DeleteHabitsCommand(
|
||||
@@ -30,7 +31,7 @@ data class DeleteHabitsCommand(
|
||||
if (!h.isSubHabit()) {
|
||||
habitList.remove(h)
|
||||
} else {
|
||||
val list = h.parent!!.habitList
|
||||
val list = (h.parent as HabitGroup).habitList
|
||||
list.remove(h)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ data class HabitGroup(
|
||||
) {
|
||||
init {
|
||||
if (uuid == null) this.uuid = UUID.randomUUID().toString().replace("-", "")
|
||||
habitList.groupUUID = this.uuid
|
||||
// habitList.groupID = this.id
|
||||
}
|
||||
|
||||
var observable = ModelObservable()
|
||||
@@ -78,7 +78,7 @@ data class HabitGroup(
|
||||
this.question = other.question
|
||||
this.reminder = other.reminder
|
||||
this.uuid = other.uuid
|
||||
this.habitList.groupUUID = this.uuid
|
||||
this.habitList.groupID = this.id
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
|
||||
@@ -34,7 +34,7 @@ abstract class HabitList : Iterable<Habit> {
|
||||
@JvmField
|
||||
protected val filter: HabitMatcher
|
||||
|
||||
var groupUUID: String? = null
|
||||
var groupID: Long? = null
|
||||
|
||||
/**
|
||||
* Creates a new HabitList.
|
||||
|
||||
@@ -40,6 +40,7 @@ class SQLiteHabitGroupList @Inject constructor(private val modelFactory: ModelFa
|
||||
record.copyFrom(habitGroup)
|
||||
repository.save(record)
|
||||
habitGroup.id = record.id
|
||||
habitGroup.habitList.groupID = record.id
|
||||
list.add(habitGroup)
|
||||
observable.notifyListeners()
|
||||
}
|
||||
|
||||
@@ -37,18 +37,15 @@ class SQLiteHabitList @Inject constructor(private val modelFactory: ModelFactory
|
||||
private fun loadRecords() {
|
||||
if (loaded) return
|
||||
loaded = true
|
||||
list.groupUUID = this.groupUUID
|
||||
list.groupID = this.groupID
|
||||
list.removeAll()
|
||||
val records = repository.findAll("order by position")
|
||||
var shouldRebuildOrder = false
|
||||
for ((expectedPosition, rec) in records.withIndex()) {
|
||||
if (rec.position != expectedPosition) shouldRebuildOrder = true
|
||||
for (rec in records) {
|
||||
val h = modelFactory.buildHabit()
|
||||
rec.copyTo(h)
|
||||
(h.originalEntries as SQLiteEntryList).habitId = h.id
|
||||
if (h.parentUUID == list.groupUUID) list.add(h)
|
||||
if (h.parentID == list.groupID) list.add(h)
|
||||
}
|
||||
if (shouldRebuildOrder) rebuildOrder()
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
@@ -129,19 +126,6 @@ class SQLiteHabitList @Inject constructor(private val modelFactory: ModelFactory
|
||||
return list.iterator()
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
private fun rebuildOrder() {
|
||||
val records = repository.findAll("order by position")
|
||||
repository.executeAsTransaction {
|
||||
for ((pos, r) in records.withIndex()) {
|
||||
if (r.position != pos) {
|
||||
r.position = pos
|
||||
repository.save(r)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
override fun remove(h: Habit) {
|
||||
loadRecords()
|
||||
@@ -153,7 +137,6 @@ class SQLiteHabitList @Inject constructor(private val modelFactory: ModelFactory
|
||||
h.originalEntries.clear()
|
||||
repository.remove(record)
|
||||
}
|
||||
rebuildOrder()
|
||||
observable.notifyListeners()
|
||||
}
|
||||
|
||||
@@ -206,7 +189,6 @@ class SQLiteHabitList @Inject constructor(private val modelFactory: ModelFactory
|
||||
@Synchronized
|
||||
override fun repair() {
|
||||
loadRecords()
|
||||
rebuildOrder()
|
||||
observable.notifyListeners()
|
||||
}
|
||||
|
||||
|
||||
@@ -79,6 +79,7 @@ class HabitGroupRecord {
|
||||
habitGroup.isArchived = archived != 0
|
||||
habitGroup.position = position!!
|
||||
habitGroup.uuid = uuid
|
||||
habitGroup.habitList.groupID = id
|
||||
if (reminderHour != null && reminderMin != null) {
|
||||
habitGroup.reminder = Reminder(
|
||||
reminderHour!!,
|
||||
|
||||
@@ -146,7 +146,7 @@ class HabitCardListCache @Inject constructor(
|
||||
|
||||
@get:Synchronized
|
||||
val subHabitCount: Int
|
||||
get() = data.subHabits.sumOf { it.size() }
|
||||
get() = data.subHabits.sumOf { it.size }
|
||||
|
||||
@get:Synchronized
|
||||
@set:Synchronized
|
||||
@@ -279,8 +279,9 @@ class HabitCardListCache @Inject constructor(
|
||||
fun setFilter(matcher: HabitMatcher) {
|
||||
filteredHabits = habits.getFiltered(matcher)
|
||||
filteredHabitGroups = habitGroups.getFiltered(matcher)
|
||||
for (idx in filteredSubHabits.indices) {
|
||||
filteredSubHabits[idx] = filteredSubHabits[idx].getFiltered(matcher)
|
||||
filteredSubHabits.clear()
|
||||
for (hgr in filteredHabitGroups) {
|
||||
filteredSubHabits.add(hgr.habitList.getFiltered(matcher))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -306,7 +307,7 @@ class HabitCardListCache @Inject constructor(
|
||||
val uuidToHabitGroup: HashMap<String?, HabitGroup> = HashMap()
|
||||
val habits: MutableList<Habit>
|
||||
val habitGroups: MutableList<HabitGroup>
|
||||
val subHabits: MutableList<HabitList>
|
||||
val subHabits: MutableList<MutableList<Habit>>
|
||||
val uuidToPosition: HashMap<String?, Int>
|
||||
val positionTypes: MutableList<Int>
|
||||
val positionToHabit: HashMap<Int, Habit>
|
||||
@@ -368,15 +369,14 @@ class HabitCardListCache @Inject constructor(
|
||||
habits.add(h)
|
||||
}
|
||||
|
||||
for (hgr in filteredHabitGroups) {
|
||||
for ((index, hgr) in filteredHabitGroups.withIndex()) {
|
||||
if (hgr.uuid == null) continue
|
||||
habitGroups.add(hgr)
|
||||
val habitList = hgr.habitList
|
||||
subHabits.add(habitList)
|
||||
|
||||
for (h in habitList) {
|
||||
if (h.uuid == null) continue
|
||||
val habitList = LinkedList<Habit>()
|
||||
for (h in filteredSubHabits[index]) {
|
||||
habitList.add(h)
|
||||
}
|
||||
subHabits.add(habitList)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -654,6 +654,10 @@ class HabitCardListCache @Inject constructor(
|
||||
data.habits.add(position, habit)
|
||||
data.positionTypes.add(position, STANDALONE_HABIT)
|
||||
} else {
|
||||
val hgr = data.uuidToHabitGroup[habit.parentUUID]
|
||||
val hgrIdx = data.habitGroups.indexOf(hgr)
|
||||
val habitIndex = newData.subHabits[hgrIdx].indexOf(habit)
|
||||
data.subHabits[hgrIdx].add(habitIndex, habit)
|
||||
data.positionTypes.add(position, SUB_HABIT)
|
||||
}
|
||||
data.incrementPositions(position, data.positionTypes.size - 1)
|
||||
|
||||
@@ -1,8 +1,3 @@
|
||||
alter table Habits add column skip_days integer not null default 0;
|
||||
alter table Habits add column skip_days_list integer not null default 0;
|
||||
alter table Habits add column parent_id integer;
|
||||
alter table Habits add column parent_uuid text;
|
||||
|
||||
create table HabitGroups (
|
||||
id integer primary key autoincrement,
|
||||
archived integer,
|
||||
@@ -16,4 +11,7 @@ create table HabitGroups (
|
||||
reminder_min integer,
|
||||
question text not null default "",
|
||||
uuid text
|
||||
);
|
||||
);
|
||||
|
||||
alter table Habits add column parent_uuid text references habitgroups(uuid);
|
||||
alter table Habits add column parent_id integer references habitgroups(id);
|
||||
Reference in New Issue
Block a user