mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-14 04:58:52 -06:00
Add Habits to groups without displaying
This commit is contained in:
@@ -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
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -34,6 +34,8 @@ abstract class HabitList : Iterable<Habit> {
|
||||
@JvmField
|
||||
protected val filter: HabitMatcher
|
||||
|
||||
var groupUUID: String? = null
|
||||
|
||||
/**
|
||||
* Creates a new HabitList.
|
||||
*
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user