Change implementation to use ids instead of uuids

pull/2020/head
Dharanish 1 year ago
parent 6abea29736
commit 0de7c7f8bd

@ -47,7 +47,6 @@ import org.isoron.uhabits.core.commands.CreateHabitCommand
import org.isoron.uhabits.core.commands.EditHabitCommand import org.isoron.uhabits.core.commands.EditHabitCommand
import org.isoron.uhabits.core.commands.RefreshParentGroupCommand import org.isoron.uhabits.core.commands.RefreshParentGroupCommand
import org.isoron.uhabits.core.models.Frequency import org.isoron.uhabits.core.models.Frequency
import org.isoron.uhabits.core.models.Habit
import org.isoron.uhabits.core.models.HabitGroup import org.isoron.uhabits.core.models.HabitGroup
import org.isoron.uhabits.core.models.HabitType import org.isoron.uhabits.core.models.HabitType
import org.isoron.uhabits.core.models.NumericalHabitType import org.isoron.uhabits.core.models.NumericalHabitType
@ -76,7 +75,7 @@ class EditHabitActivity : AppCompatActivity() {
private lateinit var binding: ActivityEditHabitBinding private lateinit var binding: ActivityEditHabitBinding
private lateinit var commandRunner: CommandRunner private lateinit var commandRunner: CommandRunner
var habitUUID: String? = null var habitId = -1L
lateinit var habitType: HabitType lateinit var habitType: HabitType
var parentGroup: HabitGroup? = null var parentGroup: HabitGroup? = null
var unit = "" var unit = ""
@ -99,20 +98,20 @@ class EditHabitActivity : AppCompatActivity() {
binding = ActivityEditHabitBinding.inflate(layoutInflater) binding = ActivityEditHabitBinding.inflate(layoutInflater)
setContentView(binding.root) setContentView(binding.root)
if (intent.hasExtra("parentGroupUUID")) { if (intent.hasExtra("groupId")) {
val parentGroupUUID = intent.getStringExtra("parentGroupUUID") val groupId = intent.getLongExtra("groupId", -1L)
parentGroup = component.habitGroupList.getByUUID(parentGroupUUID) parentGroup = component.habitGroupList.getById(groupId)
} }
if (intent.hasExtra("habitUUID")) { if (intent.hasExtra("habitId")) {
binding.toolbar.title = getString(R.string.edit_habit) binding.toolbar.title = getString(R.string.edit_habit)
habitUUID = intent.getStringExtra("habitUUID")!! habitId = intent.getLongExtra("habitId", -1L)
val habitList = if (parentGroup != null) { val habitList = if (parentGroup != null) {
parentGroup!!.habitList parentGroup!!.habitList
} else { } else {
component.habitList component.habitList
} }
val habit = habitList.getByUUID(habitUUID)!! val habit = habitList.getById(habitId)!!
habitType = habit.type habitType = habit.type
color = habit.color color = habit.color
freqNum = habit.frequency.numerator freqNum = habit.frequency.numerator
@ -133,7 +132,7 @@ class EditHabitActivity : AppCompatActivity() {
} }
if (state != null) { if (state != null) {
habitUUID = state.getString("habitUUID") habitId = state.getLong("habitId")
habitType = HabitType.fromInt(state.getInt("habitType")) habitType = HabitType.fromInt(state.getInt("habitType"))
color = PaletteColor(state.getInt("paletteColor")) color = PaletteColor(state.getInt("paletteColor"))
freqNum = state.getInt("freqNum") freqNum = state.getInt("freqNum")
@ -279,9 +278,8 @@ class EditHabitActivity : AppCompatActivity() {
component.habitList component.habitList
} }
var original: Habit? = null if (habitId > 0) {
if (habitUUID != null) { val original = habitList.getById(habitId)!!
original = habitList.getByUUID(habitUUID)!!
habit.copyFrom(original) habit.copyFrom(original)
} }
@ -303,13 +301,13 @@ class EditHabitActivity : AppCompatActivity() {
} }
habit.type = habitType habit.type = habitType
habit.parent = parentGroup habit.parent = parentGroup
habit.parentID = parentGroup?.id habit.groupId = parentGroup?.id
habit.parentUUID = parentGroup?.uuid habit.groupUUID = parentGroup?.uuid
val command = if (habitUUID != null) { val command = if (habitId > 0) {
EditHabitCommand( EditHabitCommand(
habitList, habitList,
habitUUID!!, habitId,
habit habit
) )
} else { } else {
@ -321,7 +319,7 @@ class EditHabitActivity : AppCompatActivity() {
} }
component.commandRunner.run(command) component.commandRunner.run(command)
if (habit.parentID != null) { if (habit.groupId != null) {
val habitGroupList = component.habitGroupList val habitGroupList = component.habitGroupList
val refreshCommand = RefreshParentGroupCommand(habit, habitGroupList) val refreshCommand = RefreshParentGroupCommand(habit, habitGroupList)
component.commandRunner.run(refreshCommand) component.commandRunner.run(refreshCommand)
@ -395,7 +393,7 @@ class EditHabitActivity : AppCompatActivity() {
override fun onSaveInstanceState(state: Bundle) { override fun onSaveInstanceState(state: Bundle) {
super.onSaveInstanceState(state) super.onSaveInstanceState(state)
with(state) { with(state) {
putString("habitUUID", habitUUID) putLong("habitId", habitId)
putInt("habitType", habitType.value) putInt("habitType", habitType.value)
putInt("paletteColor", color.paletteIndex) putInt("paletteColor", color.paletteIndex)
putInt("androidColor", androidColor) putInt("androidColor", androidColor)

@ -29,7 +29,7 @@ import org.isoron.uhabits.core.models.HabitType
import org.isoron.uhabits.databinding.SelectHabitTypeBinding import org.isoron.uhabits.databinding.SelectHabitTypeBinding
import org.isoron.uhabits.intents.IntentFactory import org.isoron.uhabits.intents.IntentFactory
class HabitTypeDialog(val parentUUID: String? = null) : AppCompatDialogFragment() { class HabitTypeDialog(val groupId: Long? = null) : AppCompatDialogFragment() {
override fun getTheme() = R.style.Translucent override fun getTheme() = R.style.Translucent
override fun onCreateView( override fun onCreateView(
@ -40,13 +40,13 @@ class HabitTypeDialog(val parentUUID: String? = null) : AppCompatDialogFragment(
val binding = SelectHabitTypeBinding.inflate(inflater, container, false) val binding = SelectHabitTypeBinding.inflate(inflater, container, false)
binding.buttonYesNo.setOnClickListener { binding.buttonYesNo.setOnClickListener {
val intent = IntentFactory().startEditActivity(requireActivity(), HabitType.YES_NO.value, parentUUID) val intent = IntentFactory().startEditActivity(requireActivity(), HabitType.YES_NO.value, groupId)
startActivity(intent) startActivity(intent)
dismiss() dismiss()
} }
binding.buttonMeasurable.setOnClickListener { binding.buttonMeasurable.setOnClickListener {
val intent = IntentFactory().startEditActivity(requireActivity(), HabitType.NUMERICAL.value, parentUUID) val intent = IntentFactory().startEditActivity(requireActivity(), HabitType.NUMERICAL.value, groupId)
startActivity(intent) startActivity(intent)
dismiss() dismiss()
} }
@ -57,7 +57,7 @@ class HabitTypeDialog(val parentUUID: String? = null) : AppCompatDialogFragment(
dismiss() dismiss()
} }
if (parentUUID != null) { if (groupId != null) {
binding.buttonHabitGroup.visibility = View.GONE binding.buttonHabitGroup.visibility = View.GONE
} }

@ -166,8 +166,8 @@ class ListHabitsScreen
activity.startActivity(intent) activity.startActivity(intent)
} }
override fun showSelectHabitTypeDialog(parentUUID: String?) { override fun showSelectHabitTypeDialog(groupId: Long?) {
val dialog = HabitTypeDialog(parentUUID) val dialog = HabitTypeDialog(groupId)
dialog.show(activity.supportFragmentManager, "habitType") dialog.show(activity.supportFragmentManager, "habitType")
} }

@ -28,7 +28,7 @@ class AddButtonView(
} }
override fun onClick(v: View) { override fun onClick(v: View) {
(context as ListHabitsActivity).component.listHabitsMenu.behavior.onCreateHabit(habitGroup!!.uuid) (context as ListHabitsActivity).component.listHabitsMenu.behavior.onCreateHabit(habitGroup!!.id)
} }
override fun onDraw(canvas: Canvas) { override fun onDraw(canvas: Canvas) {

@ -34,7 +34,6 @@ import org.isoron.uhabits.core.ui.screens.habits.list.ListHabitsSelectionMenuBeh
import org.isoron.uhabits.core.utils.MidnightTimer import org.isoron.uhabits.core.utils.MidnightTimer
import org.isoron.uhabits.inject.ActivityScope import org.isoron.uhabits.inject.ActivityScope
import java.util.LinkedList import java.util.LinkedList
import java.util.UUID
import javax.inject.Inject import javax.inject.Inject
/** /**
@ -75,10 +74,6 @@ class HabitCardListAdapter @Inject constructor(
return cache.hasNoHabitGroup() return cache.hasNoHabitGroup()
} }
fun hasNoSubHabits(): Boolean {
return cache.hasNoSubHabits()
}
/** /**
* Sets all items as not selected. * Sets all items as not selected.
*/ */
@ -122,22 +117,7 @@ class HabitCardListAdapter @Inject constructor(
} }
override fun getItemId(position: Int): Long { override fun getItemId(position: Int): Long {
val uuidString = cache.getUUIDByPosition(position) return cache.getIdByPosition(position)!!
return if (uuidString != null) {
val formattedUUIDString = formatUUID(uuidString)
val uuid = UUID.fromString(formattedUUIDString)
uuid.mostSignificantBits and Long.MAX_VALUE
} else {
-1
}
}
private fun formatUUID(uuidString: String): String {
return uuidString.substring(0, 8) + "-" +
uuidString.substring(8, 12) + "-" +
uuidString.substring(12, 16) + "-" +
uuidString.substring(16, 20) + "-" +
uuidString.substring(20, 32)
} }
/** /**
@ -165,14 +145,14 @@ class HabitCardListAdapter @Inject constructor(
if (listView == null) return if (listView == null) return
val habit = cache.getHabitByPosition(position) val habit = cache.getHabitByPosition(position)
if (habit != null) { if (habit != null) {
val score = cache.getScore(habit.uuid!!) val score = cache.getScore(habit.id!!)
val checkmarks = cache.getCheckmarks(habit.uuid!!) val checkmarks = cache.getCheckmarks(habit.id!!)
val notes = cache.getNotes(habit.uuid!!) val notes = cache.getNotes(habit.id!!)
val selected = selectedHabits.contains(habit) val selected = selectedHabits.contains(habit)
listView!!.bindCardView(holder, habit, score, checkmarks, notes, selected) listView!!.bindCardView(holder, habit, score, checkmarks, notes, selected)
} else { } else {
val habitGroup = cache.getHabitGroupByPosition(position) val habitGroup = cache.getHabitGroupByPosition(position)
val score = cache.getScore(habitGroup!!.uuid!!) val score = cache.getScore(habitGroup!!.id!!)
val selected = selectedHabitGroups.contains(habitGroup) val selected = selectedHabitGroups.contains(habitGroup)
listView!!.bindGroupCardView(holder, habitGroup, score, selected) listView!!.bindGroupCardView(holder, habitGroup, score, selected)
} }
@ -253,11 +233,11 @@ class HabitCardListAdapter @Inject constructor(
* @param selected list of habits to be removed * @param selected list of habits to be removed
*/ */
override fun performRemove(selected: List<Habit>) { override fun performRemove(selected: List<Habit>) {
for (habit in selected) cache.remove(habit.uuid!!) for (habit in selected) cache.remove(habit.id!!)
} }
override fun performRemoveHabitGroup(selected: List<HabitGroup>) { override fun performRemoveHabitGroup(selected: List<HabitGroup>) {
for (hgr in selected) cache.remove(hgr.uuid!!) for (hgr in selected) cache.remove(hgr.id!!)
} }
/** /**

@ -74,14 +74,14 @@ class ShowHabitActivity : AppCompatActivity(), CommandRunner.Listener {
val appComponent = (applicationContext as HabitsApplication).component val appComponent = (applicationContext as HabitsApplication).component
val habitGroupList = appComponent.habitGroupList val habitGroupList = appComponent.habitGroupList
val parentUUID = intent.getStringExtra("parentUUID") val groupId = intent.getLongExtra("groupId", -1L)
val habitList = if (parentUUID == null) { val habitList = if (groupId > 0) {
appComponent.habitList habitGroupList.getById(groupId)!!.habitList
} else { } else {
habitGroupList.getByUUID(parentUUID)!!.habitList appComponent.habitList
} }
val uuid = intent.getStringExtra("habitUUID")!! val id = intent.getLongExtra("habitId", -1L)
habit = habitList.getByUUID(uuid)!! habit = habitList.getById(id)!!
preferences = appComponent.preferences preferences = appComponent.preferences
commandRunner = appComponent.commandRunner commandRunner = appComponent.commandRunner
widgetUpdater = appComponent.widgetUpdater widgetUpdater = appComponent.widgetUpdater

@ -65,8 +65,8 @@ class IntentFactory
fun startShowHabitActivity(context: Context, habit: Habit): Intent { fun startShowHabitActivity(context: Context, habit: Habit): Intent {
val intent = Intent(context, ShowHabitActivity::class.java) val intent = Intent(context, ShowHabitActivity::class.java)
intent.putExtra("habitUUID", habit.uuid) intent.putExtra("habitId", habit.id)
intent.putExtra("parentUUID", habit.parentUUID) intent.putExtra("groupId", habit.groupId)
return intent return intent
} }
@ -100,17 +100,17 @@ class IntentFactory
fun startEditActivity(context: Context, habit: Habit): Intent { fun startEditActivity(context: Context, habit: Habit): Intent {
val intent = startEditActivity(context) val intent = startEditActivity(context)
intent.putExtra("habitUUID", habit.uuid) intent.putExtra("habitId", habit.id)
intent.putExtra("habitType", habit.type) intent.putExtra("habitType", habit.type)
intent.putExtra("parentGroupUUID", habit.parentUUID) intent.putExtra("groupId", habit.groupId)
return intent return intent
} }
fun startEditActivity(context: Context, habitType: Int, parentUUID: String?): Intent { fun startEditActivity(context: Context, habitType: Int, groupId: Long?): Intent {
val intent = startEditActivity(context) val intent = startEditActivity(context)
intent.putExtra("habitType", habitType) intent.putExtra("habitType", habitType)
if (parentUUID != null) { if (groupId != null) {
intent.putExtra("parentGroupUUID", parentUUID) intent.putExtra("groupId", groupId)
} }
return intent return intent
} }

@ -101,7 +101,13 @@ class ReminderController @Inject constructor(
} }
fun onDismiss(habitGroup: HabitGroup) { fun onDismiss(habitGroup: HabitGroup) {
notificationTray.cancel(habitGroup) if (preferences.shouldMakeNotificationsSticky()) {
// This is a workaround to keep sticky notifications non-dismissible in Android 14+.
// If the notification is dismissed, we immediately reshow it.
notificationTray.reshow(habitGroup)
} else {
notificationTray.cancel(habitGroup)
}
} }
private fun showSnoozeDelayPicker(habit: Habit, context: Context) { private fun showSnoozeDelayPicker(habit: Habit, context: Context) {

@ -24,11 +24,11 @@ import org.isoron.uhabits.core.models.HabitNotFoundException
data class EditHabitCommand( data class EditHabitCommand(
val habitList: HabitList, val habitList: HabitList,
val habitUUID: String, val habitId: Long,
val modified: Habit val modified: Habit
) : Command { ) : Command {
override fun run() { override fun run() {
val habit = habitList.getByUUID(habitUUID) ?: throw HabitNotFoundException() val habit = habitList.getById(habitId) ?: throw HabitNotFoundException()
habit.copyFrom(modified) habit.copyFrom(modified)
habitList.update(habit) habitList.update(habit)
habit.observable.notifyListeners() habit.observable.notifyListeners()

@ -89,7 +89,7 @@ class LoopDBImporter
val modified = modelFactory.buildHabit() val modified = modelFactory.buildHabit()
habitRecord.id = habit.id habitRecord.id = habit.id
habitRecord.copyTo(modified) habitRecord.copyTo(modified)
EditHabitCommand(habitList, habit.uuid!!, modified).run() EditHabitCommand(habitList, habit.id!!, modified).run()
} }
// Reload saved version of the habit // Reload saved version of the habit

@ -40,8 +40,8 @@ data class Habit(
val originalEntries: EntryList, val originalEntries: EntryList,
val scores: ScoreList, val scores: ScoreList,
val streaks: StreakList, val streaks: StreakList,
var parentID: Long? = null, var groupId: Long? = null,
var parentUUID: String? = null var groupUUID: String? = null
) { ) {
init { init {
if (uuid == null) this.uuid = UUID.randomUUID().toString().replace("-", "") if (uuid == null) this.uuid = UUID.randomUUID().toString().replace("-", "")
@ -56,7 +56,7 @@ data class Habit(
val uriString: String val uriString: String
get() = "content://org.isoron.uhabits/habit/$id" get() = "content://org.isoron.uhabits/habit/$id"
fun isSubHabit(): Boolean = parentUUID != null fun isSubHabit(): Boolean = groupUUID != null
fun hasReminder(): Boolean = reminder != null fun hasReminder(): Boolean = reminder != null
@ -129,8 +129,8 @@ data class Habit(
this.unit = other.unit this.unit = other.unit
this.uuid = other.uuid this.uuid = other.uuid
this.parent = other.parent this.parent = other.parent
this.parentID = other.parentID this.groupId = other.groupId
this.parentUUID = other.parentUUID this.groupUUID = other.groupUUID
} }
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {
@ -151,8 +151,8 @@ data class Habit(
if (type != other.type) return false if (type != other.type) return false
if (unit != other.unit) return false if (unit != other.unit) return false
if (uuid != other.uuid) return false if (uuid != other.uuid) return false
if (parentID != other.parentID) return false if (groupId != other.groupId) return false
if (parentUUID != other.parentUUID) return false if (groupUUID != other.groupUUID) return false
return true return true
} }
@ -172,8 +172,8 @@ data class Habit(
result = 31 * result + type.value result = 31 * result + type.value
result = 31 * result + unit.hashCode() result = 31 * result + unit.hashCode()
result = 31 * result + (uuid?.hashCode() ?: 0) result = 31 * result + (uuid?.hashCode() ?: 0)
result = 31 * result + (parentID?.hashCode() ?: 0) result = 31 * result + (groupId?.hashCode() ?: 0)
result = 31 * result + (parentUUID?.hashCode() ?: 0) result = 31 * result + (groupUUID?.hashCode() ?: 0)
return result return result
} }
} }

@ -96,7 +96,7 @@ data class HabitGroup(
this.question = other.question this.question = other.question
this.reminder = other.reminder this.reminder = other.reminder
this.uuid = other.uuid this.uuid = other.uuid
this.habitList.groupID = this.id this.habitList.groupId = this.id
} }
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {

@ -34,7 +34,7 @@ abstract class HabitList : Iterable<Habit> {
@JvmField @JvmField
protected val filter: HabitMatcher protected val filter: HabitMatcher
var groupID: Long? = null var groupId: Long? = null
/** /**
* Creates a new HabitList. * Creates a new HabitList.

@ -59,6 +59,7 @@ class MemoryHabitList : HabitList {
) : super(matcher) { ) : super(matcher) {
this.parent = parent this.parent = parent
this.comparator = comparator this.comparator = comparator
this.groupId = parent.groupId
primaryOrder = parent.primaryOrder primaryOrder = parent.primaryOrder
secondaryOrder = parent.secondaryOrder secondaryOrder = parent.secondaryOrder
parent.observable.addListener { loadFromParent() } parent.observable.addListener { loadFromParent() }

@ -40,7 +40,7 @@ class SQLiteHabitGroupList @Inject constructor(private val modelFactory: ModelFa
val record = HabitGroupRecord() val record = HabitGroupRecord()
record.copyFrom(habitGroup) record.copyFrom(habitGroup)
repository.save(record) repository.save(record)
habitGroup.habitList.groupID = record.id habitGroup.habitList.groupId = record.id
list.add(habitGroup) list.add(habitGroup)
observable.notifyListeners() observable.notifyListeners()
} }

@ -37,14 +37,14 @@ class SQLiteHabitList @Inject constructor(private val modelFactory: ModelFactory
private fun loadRecords() { private fun loadRecords() {
if (loaded) return if (loaded) return
loaded = true loaded = true
list.groupID = this.groupID list.groupId = this.groupId
list.removeAll() list.removeAll()
val records = repository.findAll("order by position") val records = repository.findAll("order by position")
for (rec in records) { for (rec in records) {
val h = modelFactory.buildHabit() val h = modelFactory.buildHabit()
rec.copyTo(h) rec.copyTo(h)
(h.originalEntries as SQLiteEntryList).habitId = h.id (h.originalEntries as SQLiteEntryList).habitId = h.id
if (h.parentID == list.groupID) list.add(h) if (h.groupId == list.groupId) list.add(h)
} }
} }

@ -79,7 +79,7 @@ class HabitGroupRecord {
habitGroup.isArchived = archived != 0 habitGroup.isArchived = archived != 0
habitGroup.position = position!! habitGroup.position = position!!
habitGroup.uuid = uuid habitGroup.uuid = uuid
habitGroup.habitList.groupID = id habitGroup.habitList.groupId = id
if (reminderHour != null && reminderMin != null) { if (reminderHour != null && reminderMin != null) {
habitGroup.reminder = Reminder( habitGroup.reminder = Reminder(
reminderHour!!, reminderHour!!,

@ -88,11 +88,11 @@ class HabitRecord {
@field:Column @field:Column
var uuid: String? = null var uuid: String? = null
@field:Column(name = "parent_id") @field:Column(name = "group_id")
var parentID: Long? = null var groupId: Long? = null
@field:Column(name = "parent_uuid") @field:Column(name = "group_uuid")
var parentUUID: String? = null var groupUUID: String? = null
fun copyFrom(model: Habit) { fun copyFrom(model: Habit) {
id = model.id id = model.id
@ -108,8 +108,8 @@ class HabitRecord {
position = model.position position = model.position
question = model.question question = model.question
uuid = model.uuid uuid = model.uuid
parentID = model.parentID groupId = model.groupId
parentUUID = model.parentUUID groupUUID = model.groupUUID
val (numerator, denominator) = model.frequency val (numerator, denominator) = model.frequency
freqNum = numerator freqNum = numerator
freqDen = denominator freqDen = denominator
@ -138,8 +138,8 @@ class HabitRecord {
habit.unit = unit!! habit.unit = unit!!
habit.position = position!! habit.position = position!!
habit.uuid = uuid habit.uuid = uuid
habit.parentID = parentID habit.groupId = groupId
habit.parentUUID = parentUUID habit.groupUUID = groupUUID
if (reminderHour != null && reminderMin != null) { if (reminderHour != null && reminderMin != null) {
habit.reminder = Reminder( habit.reminder = Reminder(
reminderHour!!, reminderHour!!,

@ -124,6 +124,12 @@ class NotificationTray @Inject constructor(
} }
} }
fun reshow(habitGroup: HabitGroup) {
activeHabitGroups[habitGroup]?.let {
taskRunner.execute(ShowNotificationTask(habitGroup, it))
}
}
interface SystemTray { interface SystemTray {
fun removeNotification(notificationId: Int) fun removeNotification(notificationId: Int)
fun showNotification( fun showNotification(

@ -76,13 +76,13 @@ class HabitCardListCache @Inject constructor(
} }
@Synchronized @Synchronized
fun getCheckmarks(habitUUID: String): IntArray { fun getCheckmarks(habitID: Long): IntArray {
return data.checkmarks[habitUUID]!! return data.checkmarks[habitID]!!
} }
@Synchronized @Synchronized
fun getNotes(habitUUID: String): Array<String> { fun getNotes(habitID: Long): Array<String> {
return data.notes[habitUUID]!! return data.notes[habitID]!!
} }
@Synchronized @Synchronized
@ -123,11 +123,11 @@ class HabitCardListCache @Inject constructor(
} }
@Synchronized @Synchronized
fun getUUIDByPosition(position: Int): String? { fun getIdByPosition(position: Int): Long? {
return if (data.positionTypes[position] == STANDALONE_HABIT || data.positionTypes[position] == SUB_HABIT) { return if (data.positionTypes[position] == STANDALONE_HABIT || data.positionTypes[position] == SUB_HABIT) {
data.positionToHabit[position]!!.uuid data.positionToHabit[position]!!.id
} else { } else {
data.positionToHabitGroup[position]!!.uuid data.positionToHabitGroup[position]!!.id
} }
} }
@ -172,8 +172,8 @@ class HabitCardListCache @Inject constructor(
} }
@Synchronized @Synchronized
fun getScore(uuid: String): Double { fun getScore(id: Long): Double {
return data.scores[uuid]!! return data.scores[id]!!
} }
@Synchronized @Synchronized
@ -185,7 +185,7 @@ class HabitCardListCache @Inject constructor(
@Synchronized @Synchronized
override fun onCommandFinished(command: Command) { override fun onCommandFinished(command: Command) {
if (command is CreateRepetitionCommand) { if (command is CreateRepetitionCommand) {
command.habit.uuid?.let { refreshHabit(it) } command.habit.id?.let { refreshHabit(it) }
} else { } else {
refreshAllHabits() refreshAllHabits()
} }
@ -205,48 +205,48 @@ class HabitCardListCache @Inject constructor(
} }
@Synchronized @Synchronized
fun refreshHabit(uuid: String) { fun refreshHabit(id: Long) {
taskRunner.execute(RefreshTask(uuid)) taskRunner.execute(RefreshTask(id))
} }
@Synchronized @Synchronized
fun remove(uuid: String) { fun remove(id: Long) {
val position = data.uuidToPosition[uuid] ?: return val position = data.idToPosition[id] ?: return
val type = data.positionTypes[position] val type = data.positionTypes[position]
if (type == STANDALONE_HABIT) { if (type == STANDALONE_HABIT) {
val h = data.uuidToHabit[uuid] val h = data.idToHabit[id]
if (h != null) { if (h != null) {
data.habits.removeAt(position) data.habits.removeAt(position)
data.removeWithUUID(uuid) data.removeWithID(id)
data.removeWithPos(position) data.removeWithPos(position)
data.decrementPositions(position + 1, data.positionTypes.size) data.decrementPositions(position + 1, data.positionTypes.size)
listener.onItemRemoved(position) listener.onItemRemoved(position)
} }
} else if (type == SUB_HABIT) { } else if (type == SUB_HABIT) {
val h = data.uuidToHabit[uuid] val h = data.idToHabit[id]
if (h != null) { if (h != null) {
val hgrUUID = h.parentUUID val hgrID = h.groupId
val hgr = data.uuidToHabitGroup[hgrUUID] val hgr = data.idToHabitGroup[hgrID]
val hgrIdx = data.habitGroups.indexOf(hgr) val hgrIdx = data.habitGroups.indexOf(hgr)
data.subHabits[hgrIdx].remove(h) data.subHabits[hgrIdx].remove(h)
data.removeWithUUID(uuid) data.removeWithID(id)
data.removeWithPos(position) data.removeWithPos(position)
data.decrementPositions(position + 1, data.positionTypes.size) data.decrementPositions(position + 1, data.positionTypes.size)
listener.onItemRemoved(position) listener.onItemRemoved(position)
} }
} else if (type == HABIT_GROUP) { } else if (type == HABIT_GROUP) {
val hgr = data.uuidToHabitGroup[uuid] val hgr = data.idToHabitGroup[id]
if (hgr != null) { if (hgr != null) {
val hgrIdx = data.positionIndices[position] val hgrIdx = data.positionIndices[position]
for (habit in data.subHabits[hgrIdx].reversed()) { for (habit in data.subHabits[hgrIdx].reversed()) {
val habitPos = data.uuidToPosition[habit.uuid]!! val habitPos = data.idToPosition[habit.id]!!
data.removeWithUUID(habit.uuid) data.removeWithID(habit.id)
listener.onItemRemoved(habitPos) listener.onItemRemoved(habitPos)
} }
data.subHabits.removeAt(hgrIdx) data.subHabits.removeAt(hgrIdx)
data.habitGroups.removeAt(hgrIdx) data.habitGroups.removeAt(hgrIdx)
data.removeWithUUID(hgr.uuid) data.removeWithID(hgr.id)
data.rebuildPositions() data.rebuildPositions()
listener.onItemRemoved(position) listener.onItemRemoved(position)
} }
@ -295,29 +295,29 @@ class HabitCardListCache @Inject constructor(
} }
private inner class CacheData { private inner class CacheData {
val uuidToHabit: HashMap<String?, Habit> = HashMap() val idToHabit: HashMap<Long?, Habit> = HashMap()
val uuidToHabitGroup: HashMap<String?, HabitGroup> = HashMap() val idToHabitGroup: HashMap<Long?, HabitGroup> = HashMap()
val habits: MutableList<Habit> val habits: MutableList<Habit>
val habitGroups: MutableList<HabitGroup> val habitGroups: MutableList<HabitGroup>
val subHabits: MutableList<MutableList<Habit>> val subHabits: MutableList<MutableList<Habit>>
val uuidToPosition: HashMap<String?, Int> val idToPosition: HashMap<Long?, Int>
val positionTypes: MutableList<Int> val positionTypes: MutableList<Int>
val positionIndices: MutableList<Int> val positionIndices: MutableList<Int>
val positionToHabit: HashMap<Int, Habit> val positionToHabit: HashMap<Int, Habit>
val positionToHabitGroup: HashMap<Int, HabitGroup> val positionToHabitGroup: HashMap<Int, HabitGroup>
val checkmarks: HashMap<String?, IntArray> val checkmarks: HashMap<Long?, IntArray>
val scores: HashMap<String?, Double> val scores: HashMap<Long?, Double>
val notes: HashMap<String?, Array<String>> val notes: HashMap<Long?, Array<String>>
@Synchronized @Synchronized
fun copyCheckmarksFrom(oldData: CacheData) { fun copyCheckmarksFrom(oldData: CacheData) {
val empty = IntArray(checkmarkCount) val empty = IntArray(checkmarkCount)
for (uuid in uuidToHabit.keys) { for (id in idToHabit.keys) {
if (oldData.checkmarks.containsKey(uuid)) { if (oldData.checkmarks.containsKey(id)) {
checkmarks[uuid] = checkmarks[id] =
oldData.checkmarks[uuid]!! oldData.checkmarks[id]!!
} else { } else {
checkmarks[uuid] = empty checkmarks[id] = empty
} }
} }
} }
@ -325,19 +325,19 @@ class HabitCardListCache @Inject constructor(
@Synchronized @Synchronized
fun copyNoteIndicatorsFrom(oldData: CacheData) { fun copyNoteIndicatorsFrom(oldData: CacheData) {
val empty = (0..checkmarkCount).map { "" }.toTypedArray() val empty = (0..checkmarkCount).map { "" }.toTypedArray()
for (uuid in uuidToHabit.keys) { for (id in idToHabit.keys) {
if (oldData.notes.containsKey(uuid)) { if (oldData.notes.containsKey(id)) {
notes[uuid] = notes[id] =
oldData.notes[uuid]!! oldData.notes[id]!!
} else { } else {
notes[uuid] = empty notes[id] = empty
} }
} }
} }
@Synchronized @Synchronized
fun copyScoresFrom(oldData: CacheData) { fun copyScoresFrom(oldData: CacheData) {
for (uuid in uuidToHabit.keys) { for (uuid in idToHabit.keys) {
if (oldData.scores.containsKey(uuid)) { if (oldData.scores.containsKey(uuid)) {
scores[uuid] = scores[uuid] =
oldData.scores[uuid]!! oldData.scores[uuid]!!
@ -345,7 +345,7 @@ class HabitCardListCache @Inject constructor(
scores[uuid] = 0.0 scores[uuid] = 0.0
} }
} }
for (uuid in uuidToHabitGroup.keys) { for (uuid in idToHabitGroup.keys) {
if (oldData.scores.containsKey(uuid)) { if (oldData.scores.containsKey(uuid)) {
scores[uuid] = scores[uuid] =
oldData.scores[uuid]!! oldData.scores[uuid]!!
@ -377,13 +377,13 @@ class HabitCardListCache @Inject constructor(
fun rebuildPositions() { fun rebuildPositions() {
positionToHabit.clear() positionToHabit.clear()
positionToHabitGroup.clear() positionToHabitGroup.clear()
uuidToPosition.clear() idToPosition.clear()
positionTypes.clear() positionTypes.clear()
positionIndices.clear() positionIndices.clear()
var position = 0 var position = 0
for ((idx, h) in habits.withIndex()) { for ((idx, h) in habits.withIndex()) {
uuidToHabit[h.uuid] = h idToHabit[h.id] = h
uuidToPosition[h.uuid] = position idToPosition[h.id] = position
positionToHabit[position] = h positionToHabit[position] = h
positionTypes.add(STANDALONE_HABIT) positionTypes.add(STANDALONE_HABIT)
positionIndices.add(idx) positionIndices.add(idx)
@ -391,8 +391,8 @@ class HabitCardListCache @Inject constructor(
} }
for ((idx, hgr) in habitGroups.withIndex()) { for ((idx, hgr) in habitGroups.withIndex()) {
uuidToHabitGroup[hgr.uuid] = hgr idToHabitGroup[hgr.id] = hgr
uuidToPosition[hgr.uuid] = position idToPosition[hgr.id] = position
positionToHabitGroup[position] = hgr positionToHabitGroup[position] = hgr
positionTypes.add(HABIT_GROUP) positionTypes.add(HABIT_GROUP)
positionIndices.add(idx) positionIndices.add(idx)
@ -400,8 +400,8 @@ class HabitCardListCache @Inject constructor(
position++ position++
for ((hIdx, h) in habitList.withIndex()) { for ((hIdx, h) in habitList.withIndex()) {
uuidToHabit[h.uuid] = h idToHabit[h.id] = h
uuidToPosition[h.uuid] = position idToPosition[h.id] = position
positionToHabit[position] = h positionToHabit[position] = h
positionTypes.add(SUB_HABIT) positionTypes.add(SUB_HABIT)
positionIndices.add(hIdx) positionIndices.add(hIdx)
@ -412,14 +412,14 @@ class HabitCardListCache @Inject constructor(
@Synchronized @Synchronized
fun isValidInsert(habit: Habit, position: Int): Boolean { fun isValidInsert(habit: Habit, position: Int): Boolean {
if (habit.parentUUID == null) { if (habit.groupId == null) {
return position <= habits.size return position <= habits.size
} else { } else {
val parent = uuidToHabitGroup[habit.parentUUID] ?: return false val parent = idToHabitGroup[habit.groupId] ?: return false
val parentPosition = uuidToPosition[habit.parentUUID]!! val parentPosition = idToPosition[habit.groupId]!!
val parentIndex = habitGroups.indexOf(parent) val parentIndex = habitGroups.indexOf(parent)
val nextGroup = habitGroups.getOrNull(parentIndex + 1) val nextGroup = habitGroups.getOrNull(parentIndex + 1)
val nextGroupPosition = uuidToPosition[nextGroup?.uuid] val nextGroupPosition = idToPosition[nextGroup?.id]
return (position > parentPosition && position <= positionTypes.size) && (nextGroupPosition == null || position <= nextGroupPosition) return (position > parentPosition && position <= positionTypes.size) && (nextGroupPosition == null || position <= nextGroupPosition)
} }
} }
@ -443,9 +443,9 @@ class HabitCardListCache @Inject constructor(
positionToHabitGroup.remove(pos) positionToHabitGroup.remove(pos)
} }
} }
for ((key, pos) in uuidToPosition.entries) { for ((key, pos) in idToPosition.entries) {
if (pos in from..to) { if (pos in from..to) {
uuidToPosition[key] = pos + 1 idToPosition[key] = pos + 1
} }
} }
} }
@ -464,9 +464,9 @@ class HabitCardListCache @Inject constructor(
positionToHabitGroup.remove(pos) positionToHabitGroup.remove(pos)
} }
} }
for ((key, pos) in uuidToPosition.entries) { for ((key, pos) in idToPosition.entries) {
if (pos in fromPosition..toPosition) { if (pos in fromPosition..toPosition) {
uuidToPosition[key] = pos - 1 idToPosition[key] = pos - 1
} }
} }
} }
@ -503,7 +503,7 @@ class HabitCardListCache @Inject constructor(
positionTypes.add(checkedToPosition, STANDALONE_HABIT) positionTypes.add(checkedToPosition, STANDALONE_HABIT)
positionIndices.add(checkedToPosition, checkedToPosition) positionIndices.add(checkedToPosition, checkedToPosition)
} else { } else {
val hgr = uuidToHabitGroup[habit.parentUUID] val hgr = idToHabitGroup[habit.groupId]
val hgrIdx = habitGroups.indexOf(hgr) val hgrIdx = habitGroups.indexOf(hgr)
val fromIdx = positionIndices[fromPosition] val fromIdx = positionIndices[fromPosition]
subHabits[hgrIdx].removeAt(fromIdx) subHabits[hgrIdx].removeAt(fromIdx)
@ -513,14 +513,14 @@ class HabitCardListCache @Inject constructor(
} else { } else {
incrementPositions(checkedToPosition, fromPosition - 1) incrementPositions(checkedToPosition, fromPosition - 1)
} }
val toIdx = checkedToPosition - uuidToPosition[hgr!!.uuid]!! - 1 val toIdx = checkedToPosition - idToPosition[hgr!!.id]!! - 1
subHabits[hgrIdx].add(toIdx, habit) subHabits[hgrIdx].add(toIdx, habit)
positionTypes.add(checkedToPosition, SUB_HABIT) positionTypes.add(checkedToPosition, SUB_HABIT)
positionIndices.add(checkedToPosition, toIdx) positionIndices.add(checkedToPosition, toIdx)
} }
positionToHabit[checkedToPosition] = habit positionToHabit[checkedToPosition] = habit
uuidToPosition[habit.uuid] = checkedToPosition idToPosition[habit.id] = checkedToPosition
listener.onItemMoved(fromPosition, checkedToPosition) listener.onItemMoved(fromPosition, checkedToPosition)
} }
@ -546,13 +546,13 @@ class HabitCardListCache @Inject constructor(
listener.onItemMoved(fromPosition, toPosition) listener.onItemMoved(fromPosition, toPosition)
} }
fun removeWithUUID(uuid: String?) { fun removeWithID(id: Long?) {
uuidToPosition.remove(uuid) idToPosition.remove(id)
uuidToHabit.remove(uuid) idToHabit.remove(id)
uuidToHabitGroup.remove(uuid) idToHabitGroup.remove(id)
scores.remove(uuid) scores.remove(id)
notes.remove(uuid) notes.remove(id)
checkmarks.remove(uuid) checkmarks.remove(id)
} }
fun removeWithPos(pos: Int) { fun removeWithPos(pos: Int) {
@ -570,7 +570,7 @@ class HabitCardListCache @Inject constructor(
subHabits = LinkedList() subHabits = LinkedList()
positionTypes = LinkedList() positionTypes = LinkedList()
positionIndices = LinkedList() positionIndices = LinkedList()
uuidToPosition = HashMap() idToPosition = HashMap()
positionToHabit = HashMap() positionToHabit = HashMap()
positionToHabitGroup = HashMap() positionToHabitGroup = HashMap()
checkmarks = HashMap() checkmarks = HashMap()
@ -581,19 +581,19 @@ class HabitCardListCache @Inject constructor(
private inner class RefreshTask : Task { private inner class RefreshTask : Task {
private val newData: CacheData private val newData: CacheData
private val targetUUID: String? private val targetID: Long?
private var isCancelled = false private var isCancelled = false
private var runner: TaskRunner? = null private var runner: TaskRunner? = null
constructor() { constructor() {
newData = CacheData() newData = CacheData()
targetUUID = null targetID = null
isCancelled = false isCancelled = false
} }
constructor(targetUUID: String) { constructor(targetID: Long) {
newData = CacheData() newData = CacheData()
this.targetUUID = targetUUID this.targetID = targetID
} }
@Synchronized @Synchronized
@ -615,8 +615,8 @@ class HabitCardListCache @Inject constructor(
if (isCancelled) return if (isCancelled) return
if (type == STANDALONE_HABIT || type == SUB_HABIT) { if (type == STANDALONE_HABIT || type == SUB_HABIT) {
val habit = newData.positionToHabit[position]!! val habit = newData.positionToHabit[position]!!
if (targetUUID != null && targetUUID != habit.uuid) continue if (targetID != null && targetID != habit.id) continue
newData.scores[habit.uuid] = habit.scores[today].value newData.scores[habit.id] = habit.scores[today].value
val list: MutableList<Int> = ArrayList() val list: MutableList<Int> = ArrayList()
val notes: MutableList<String> = ArrayList() val notes: MutableList<String> = ArrayList()
for ((_, value, note) in habit.computedEntries.getByInterval(dateFrom, today)) { for ((_, value, note) in habit.computedEntries.getByInterval(dateFrom, today)) {
@ -624,13 +624,13 @@ class HabitCardListCache @Inject constructor(
notes.add(note) notes.add(note)
} }
val entries = list.toTypedArray() val entries = list.toTypedArray()
newData.checkmarks[habit.uuid] = ArrayUtils.toPrimitive(entries) newData.checkmarks[habit.id] = ArrayUtils.toPrimitive(entries)
newData.notes[habit.uuid] = notes.toTypedArray() newData.notes[habit.id] = notes.toTypedArray()
runner!!.publishProgress(this, position) runner!!.publishProgress(this, position)
} else if (type == HABIT_GROUP) { } else if (type == HABIT_GROUP) {
val habitGroup = newData.positionToHabitGroup[position]!! val habitGroup = newData.positionToHabitGroup[position]!!
if (targetUUID != null && targetUUID != habitGroup.uuid) continue if (targetID != null && targetID != habitGroup.id) continue
newData.scores[habitGroup.uuid] = habitGroup.scores[today].value newData.scores[habitGroup.id] = habitGroup.scores[today].value
runner!!.publishProgress(this, position) runner!!.publishProgress(this, position)
} }
} }
@ -655,13 +655,13 @@ class HabitCardListCache @Inject constructor(
@Synchronized @Synchronized
private fun performInsert(habit: Habit, position: Int) { private fun performInsert(habit: Habit, position: Int) {
if (!data.isValidInsert(habit, position)) return if (!data.isValidInsert(habit, position)) return
val uuid = habit.uuid val id = habit.id
if (habit.parentUUID == null) { if (habit.groupId == null) {
data.habits.add(position, habit) data.habits.add(position, habit)
data.positionTypes.add(position, STANDALONE_HABIT) data.positionTypes.add(position, STANDALONE_HABIT)
data.positionIndices.add(position, position) data.positionIndices.add(position, position)
} else { } else {
val hgrPos = data.uuidToPosition[habit.parentUUID]!! val hgrPos = data.idToPosition[habit.groupId]!!
val hgrIdx = data.positionIndices[hgrPos] val hgrIdx = data.positionIndices[hgrPos]
val habitIndex = newData.positionIndices[position] val habitIndex = newData.positionIndices[position]
data.subHabits[hgrIdx].add(habitIndex, habit) data.subHabits[hgrIdx].add(habitIndex, habit)
@ -670,18 +670,18 @@ class HabitCardListCache @Inject constructor(
} }
data.incrementPositions(position, data.positionTypes.size - 1) data.incrementPositions(position, data.positionTypes.size - 1)
data.positionToHabit[position] = habit data.positionToHabit[position] = habit
data.uuidToPosition[uuid] = position data.idToPosition[id] = position
data.uuidToHabit[uuid] = habit data.idToHabit[id] = habit
data.scores[uuid] = newData.scores[uuid]!! data.scores[id] = newData.scores[id]!!
data.checkmarks[uuid] = newData.checkmarks[uuid]!! data.checkmarks[id] = newData.checkmarks[id]!!
data.notes[uuid] = newData.notes[uuid]!! data.notes[id] = newData.notes[id]!!
listener.onItemInserted(position) listener.onItemInserted(position)
} }
@Synchronized @Synchronized
private fun performInsert(habitGroup: HabitGroup, position: Int) { private fun performInsert(habitGroup: HabitGroup, position: Int) {
if (!data.isValidInsert(habitGroup, position)) return if (!data.isValidInsert(habitGroup, position)) return
val uuid = habitGroup.uuid val id = habitGroup.id
val prevIdx = newData.positionIndices[position] val prevIdx = newData.positionIndices[position]
val habitList = newData.subHabits[prevIdx] val habitList = newData.subHabits[prevIdx]
val idx = if (data.positionIndices.size > position) { val idx = if (data.positionIndices.size > position) {
@ -692,37 +692,37 @@ class HabitCardListCache @Inject constructor(
data.habitGroups.add(idx, habitGroup) data.habitGroups.add(idx, habitGroup)
data.subHabits.add(prevIdx, habitList) data.subHabits.add(prevIdx, habitList)
data.scores[uuid] = newData.scores[uuid]!! data.scores[id] = newData.scores[id]!!
for (h in habitList) { for (h in habitList) {
data.scores[h.uuid] = newData.scores[h.uuid]!! data.scores[h.id] = newData.scores[h.id]!!
data.checkmarks[h.uuid] = newData.checkmarks[h.uuid]!! data.checkmarks[h.id] = newData.checkmarks[h.id]!!
data.notes[h.uuid] = newData.notes[h.uuid]!! data.notes[h.id] = newData.notes[h.id]!!
} }
data.rebuildPositions() data.rebuildPositions()
listener.onItemInserted(position) listener.onItemInserted(position)
} }
@Synchronized @Synchronized
private fun performUpdate(uuid: String, position: Int) { private fun performUpdate(id: Long, position: Int) {
var unchanged = true var unchanged = true
val oldScore = data.scores[uuid]!! val oldScore = data.scores[id]!!
val newScore = newData.scores[uuid]!! val newScore = newData.scores[id]!!
if (oldScore != newScore) unchanged = false if (oldScore != newScore) unchanged = false
if (data.positionTypes[position] != HABIT_GROUP) { if (data.positionTypes[position] != HABIT_GROUP) {
val oldCheckmarks = data.checkmarks[uuid] val oldCheckmarks = data.checkmarks[id]
val newCheckmarks = newData.checkmarks[uuid]!! val newCheckmarks = newData.checkmarks[id]!!
val oldNoteIndicators = data.notes[uuid] val oldNoteIndicators = data.notes[id]
val newNoteIndicators = newData.notes[uuid]!! val newNoteIndicators = newData.notes[id]!!
if (!Arrays.equals(oldCheckmarks, newCheckmarks)) unchanged = false if (!Arrays.equals(oldCheckmarks, newCheckmarks)) unchanged = false
if (!Arrays.equals(oldNoteIndicators, newNoteIndicators)) unchanged = false if (!Arrays.equals(oldNoteIndicators, newNoteIndicators)) unchanged = false
if (unchanged) return if (unchanged) return
data.checkmarks[uuid] = newCheckmarks data.checkmarks[id] = newCheckmarks
data.notes[uuid] = newNoteIndicators data.notes[id] = newNoteIndicators
} }
if (unchanged) return if (unchanged) return
data.scores[uuid] = newScore data.scores[id] = newScore
listener.onItemChanged(position) listener.onItemChanged(position)
} }
@ -732,12 +732,12 @@ class HabitCardListCache @Inject constructor(
if (type == STANDALONE_HABIT || type == SUB_HABIT) { if (type == STANDALONE_HABIT || type == SUB_HABIT) {
val habit = newData.positionToHabit[currentPosition]!! val habit = newData.positionToHabit[currentPosition]!!
val uuid = habit.uuid ?: throw NullPointerException() val id = habit.id ?: throw NullPointerException()
val prevPosition = data.uuidToPosition[uuid] ?: -1 val prevPosition = data.idToPosition[id] ?: -1
val newPosition = if (type == STANDALONE_HABIT) { val newPosition = if (type == STANDALONE_HABIT) {
currentPosition currentPosition
} else { } else {
val hgrPos = data.uuidToPosition[habit.parentUUID]!! val hgrPos = data.idToPosition[habit.groupId]!!
val hgrIdx = data.positionIndices[hgrPos] val hgrIdx = data.positionIndices[hgrPos]
newData.subHabits[hgrIdx].indexOf(habit) + hgrPos + 1 newData.subHabits[hgrIdx].indexOf(habit) + hgrPos + 1
} }
@ -751,12 +751,12 @@ class HabitCardListCache @Inject constructor(
newPosition newPosition
) )
} }
performUpdate(uuid, currentPosition) performUpdate(id, currentPosition)
} }
} else if (type == HABIT_GROUP) { } else if (type == HABIT_GROUP) {
val habitGroup = newData.positionToHabitGroup[currentPosition]!! val habitGroup = newData.positionToHabitGroup[currentPosition]!!
val uuid = habitGroup.uuid ?: throw NullPointerException() val id = habitGroup.id ?: throw NullPointerException()
val prevPosition = data.uuidToPosition[uuid] ?: -1 val prevPosition = data.idToPosition[id] ?: -1
if (prevPosition < 0) { if (prevPosition < 0) {
performInsert(habitGroup, currentPosition) performInsert(habitGroup, currentPosition)
} else { } else {
@ -767,18 +767,18 @@ class HabitCardListCache @Inject constructor(
currentPosition currentPosition
) )
} }
performUpdate(uuid, currentPosition) performUpdate(id, currentPosition)
} }
} }
} }
@Synchronized @Synchronized
private fun processRemovedHabits() { private fun processRemovedHabits() {
val before: Set<String?> = (data.uuidToHabit.keys).union(data.uuidToHabitGroup.keys) val before: Set<Long?> = (data.idToHabit.keys).union(data.idToHabitGroup.keys)
val after: Set<String?> = (newData.uuidToHabit.keys).union(newData.uuidToHabitGroup.keys) val after: Set<Long?> = (newData.idToHabit.keys).union(newData.idToHabitGroup.keys)
val removed: MutableSet<String?> = TreeSet(before) val removed: MutableSet<Long?> = TreeSet(before)
removed.removeAll(after) removed.removeAll(after)
for (uuid in removed.sortedBy { uuid -> data.uuidToPosition[uuid] }) remove(uuid!!) for (id in removed.sortedBy { data.idToPosition[it] }) remove(id!!)
} }
} }

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

@ -49,5 +49,5 @@ create table HabitGroups (
uuid text uuid text
); );
alter table Habits add column parent_uuid text references habitgroups(uuid); alter table Habits add column group_uuid text references habitgroups(uuid);
alter table Habits add column parent_id integer references habitgroups(id); alter table Habits add column group_id integer references habitgroups(id);
Loading…
Cancel
Save