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

@@ -47,6 +47,7 @@ import org.isoron.uhabits.core.commands.CreateHabitCommand
import org.isoron.uhabits.core.commands.EditHabitCommand
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.HabitType
import org.isoron.uhabits.core.models.NumericalHabitType
import org.isoron.uhabits.core.models.PaletteColor
@@ -76,6 +77,7 @@ class EditHabitActivity : AppCompatActivity() {
var habitId = -1L
lateinit var habitType: HabitType
var parentGroup: HabitGroup? = null
var unit = ""
var color = PaletteColor(11)
var androidColor = 0
@@ -110,6 +112,7 @@ class EditHabitActivity : AppCompatActivity() {
reminderMin = it.minute
reminderDays = it.days
}
parentGroup = habit.parent
binding.nameInput.setText(habit.name)
binding.questionInput.setText(habit.question)
binding.notesInput.setText(habit.description)
@@ -117,6 +120,10 @@ class EditHabitActivity : AppCompatActivity() {
binding.targetInput.setText(habit.targetValue.toString())
} else {
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) {
@@ -260,9 +267,15 @@ class EditHabitActivity : AppCompatActivity() {
val component = (application as HabitsApplication).component
val habit = component.modelFactory.buildHabit()
val habitList = if (parentGroup != null) {
parentGroup!!.habitList
} else {
component.habitList
}
var original: Habit? = null
if (habitId >= 0) {
original = component.habitList.getById(habitId)!!
original = habitList.getById(habitId)!!
habit.copyFrom(original)
}
@@ -283,17 +296,20 @@ class EditHabitActivity : AppCompatActivity() {
habit.unit = binding.unitInput.text.trim().toString()
}
habit.type = habitType
habit.parent = parentGroup
habit.parentID = parentGroup?.id
habit.parentUUID = parentGroup?.uuid
val command = if (habitId >= 0) {
EditHabitCommand(
component.habitList,
habitList,
habitId,
habit
)
} else {
CreateHabitCommand(
component.modelFactory,
component.habitList,
habitList,
habit
)
}

View File

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

View File

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

View File

@@ -8,18 +8,19 @@ import android.text.TextPaint
import android.view.View
import android.view.View.MeasureSpec.EXACTLY
import org.isoron.uhabits.R
import org.isoron.uhabits.activities.habits.list.ListHabitsActivity
import org.isoron.uhabits.core.models.HabitGroup
import org.isoron.uhabits.utils.getFontAwesome
import org.isoron.uhabits.utils.sp
import org.isoron.uhabits.utils.sres
import org.isoron.uhabits.utils.toMeasureSpec
class AddButtonView(
context: Context
context: Context,
var habitGroup: HabitGroup?
) : View(context),
View.OnClickListener {
var onEdit: () -> Unit = { }
private var drawer = Drawer()
init {
@@ -27,7 +28,7 @@ class AddButtonView(
}
override fun onClick(v: View) {
onEdit()
(context as ListHabitsActivity).component.listHabitsMenu.behavior.onCreateHabit(habitGroup!!.uuid)
}
override fun onDraw(canvas: Canvas) {

View File

@@ -41,6 +41,7 @@ class HabitGroupCardView(
}
field = newHabitGroup
if (newHabitGroup != null) copyAttributesFrom(newHabitGroup)
addButtonView.habitGroup = newHabitGroup
}
var score
@@ -79,7 +80,7 @@ class HabitGroupCardView(
setTypeface(typeface, Typeface.BOLD)
}
addButtonView = AddButtonView(context)
addButtonView = AddButtonView(context, habitGroup)
innerFrame = LinearLayout(context).apply {
gravity = Gravity.CENTER_VERTICAL

View File

@@ -97,9 +97,12 @@ class IntentFactory
return intent
}
fun startEditActivity(context: Context, habitType: Int): Intent {
fun startEditActivity(context: Context, habitType: Int, parentUUID: String?): Intent {
val intent = startEditActivity(context)
intent.putExtra("habitType", habitType)
if (parentUUID != null) {
intent.putExtra("parentGroupUUID", parentUUID)
}
return intent
}