|
|
@ -75,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 habitId = -1L
|
|
|
|
var habitUUID: String? = null
|
|
|
|
lateinit var habitType: HabitType
|
|
|
|
lateinit var habitType: HabitType
|
|
|
|
var parentGroup: HabitGroup? = null
|
|
|
|
var parentGroup: HabitGroup? = null
|
|
|
|
var unit = ""
|
|
|
|
var unit = ""
|
|
|
@ -98,10 +98,20 @@ class EditHabitActivity : AppCompatActivity() {
|
|
|
|
binding = ActivityEditHabitBinding.inflate(layoutInflater)
|
|
|
|
binding = ActivityEditHabitBinding.inflate(layoutInflater)
|
|
|
|
setContentView(binding.root)
|
|
|
|
setContentView(binding.root)
|
|
|
|
|
|
|
|
|
|
|
|
if (intent.hasExtra("habitId")) {
|
|
|
|
if (intent.hasExtra("parentGroupUUID")) {
|
|
|
|
|
|
|
|
val parentGroupUUID = intent.getStringExtra("parentGroupUUID")
|
|
|
|
|
|
|
|
parentGroup = component.habitGroupList.getByUUID(parentGroupUUID)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (intent.hasExtra("habitUUID")) {
|
|
|
|
binding.toolbar.title = getString(R.string.edit_habit)
|
|
|
|
binding.toolbar.title = getString(R.string.edit_habit)
|
|
|
|
habitId = intent.getLongExtra("habitId", -1)
|
|
|
|
habitUUID = intent.getStringExtra("habitUUID")!!
|
|
|
|
val habit = component.habitList.getById(habitId)!!
|
|
|
|
val habitList = if (parentGroup != null) {
|
|
|
|
|
|
|
|
parentGroup!!.habitList
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
component.habitList
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
val habit = habitList.getByUUID(habitUUID)!!
|
|
|
|
habitType = habit.type
|
|
|
|
habitType = habit.type
|
|
|
|
color = habit.color
|
|
|
|
color = habit.color
|
|
|
|
freqNum = habit.frequency.numerator
|
|
|
|
freqNum = habit.frequency.numerator
|
|
|
@ -112,7 +122,6 @@ class EditHabitActivity : AppCompatActivity() {
|
|
|
|
reminderMin = it.minute
|
|
|
|
reminderMin = it.minute
|
|
|
|
reminderDays = it.days
|
|
|
|
reminderDays = it.days
|
|
|
|
}
|
|
|
|
}
|
|
|
|
parentGroup = habit.parent
|
|
|
|
|
|
|
|
binding.nameInput.setText(habit.name)
|
|
|
|
binding.nameInput.setText(habit.name)
|
|
|
|
binding.questionInput.setText(habit.question)
|
|
|
|
binding.questionInput.setText(habit.question)
|
|
|
|
binding.notesInput.setText(habit.description)
|
|
|
|
binding.notesInput.setText(habit.description)
|
|
|
@ -120,14 +129,10 @@ class EditHabitActivity : AppCompatActivity() {
|
|
|
|
binding.targetInput.setText(habit.targetValue.toString())
|
|
|
|
binding.targetInput.setText(habit.targetValue.toString())
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
habitType = HabitType.fromInt(intent.getIntExtra("habitType", HabitType.YES_NO.value))
|
|
|
|
habitType = HabitType.fromInt(intent.getIntExtra("habitType", HabitType.YES_NO.value))
|
|
|
|
if (intent.hasExtra("parentGroupUUID")) {
|
|
|
|
|
|
|
|
val parentGroupUUID = intent.getStringExtra("parentGroupUUID")!!
|
|
|
|
|
|
|
|
parentGroup = component.habitGroupList.getByUUID(parentGroupUUID)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (state != null) {
|
|
|
|
if (state != null) {
|
|
|
|
habitId = state.getLong("habitId")
|
|
|
|
habitUUID = state.getString("habitUUID")
|
|
|
|
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")
|
|
|
@ -274,8 +279,8 @@ class EditHabitActivity : AppCompatActivity() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var original: Habit? = null
|
|
|
|
var original: Habit? = null
|
|
|
|
if (habitId >= 0) {
|
|
|
|
if (habitUUID != null) {
|
|
|
|
original = habitList.getById(habitId)!!
|
|
|
|
original = habitList.getByUUID(habitUUID)!!
|
|
|
|
habit.copyFrom(original)
|
|
|
|
habit.copyFrom(original)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -300,10 +305,10 @@ class EditHabitActivity : AppCompatActivity() {
|
|
|
|
habit.parentID = parentGroup?.id
|
|
|
|
habit.parentID = parentGroup?.id
|
|
|
|
habit.parentUUID = parentGroup?.uuid
|
|
|
|
habit.parentUUID = parentGroup?.uuid
|
|
|
|
|
|
|
|
|
|
|
|
val command = if (habitId >= 0) {
|
|
|
|
val command = if (habitUUID != null) {
|
|
|
|
EditHabitCommand(
|
|
|
|
EditHabitCommand(
|
|
|
|
habitList,
|
|
|
|
habitList,
|
|
|
|
habitId,
|
|
|
|
habitUUID!!,
|
|
|
|
habit
|
|
|
|
habit
|
|
|
|
)
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -382,7 +387,7 @@ class EditHabitActivity : AppCompatActivity() {
|
|
|
|
override fun onSaveInstanceState(state: Bundle) {
|
|
|
|
override fun onSaveInstanceState(state: Bundle) {
|
|
|
|
super.onSaveInstanceState(state)
|
|
|
|
super.onSaveInstanceState(state)
|
|
|
|
with(state) {
|
|
|
|
with(state) {
|
|
|
|
putLong("habitId", habitId)
|
|
|
|
putString("habitUUID", habitUUID)
|
|
|
|
putInt("habitType", habitType.value)
|
|
|
|
putInt("habitType", habitType.value)
|
|
|
|
putInt("paletteColor", color.paletteIndex)
|
|
|
|
putInt("paletteColor", color.paletteIndex)
|
|
|
|
putInt("androidColor", androidColor)
|
|
|
|
putInt("androidColor", androidColor)
|
|
|
|