mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-14 21:18:51 -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.commands.EditHabitCommand
|
||||||
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.Habit
|
||||||
|
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
|
||||||
import org.isoron.uhabits.core.models.PaletteColor
|
import org.isoron.uhabits.core.models.PaletteColor
|
||||||
@@ -76,6 +77,7 @@ class EditHabitActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
var habitId = -1L
|
var habitId = -1L
|
||||||
lateinit var habitType: HabitType
|
lateinit var habitType: HabitType
|
||||||
|
var parentGroup: HabitGroup? = null
|
||||||
var unit = ""
|
var unit = ""
|
||||||
var color = PaletteColor(11)
|
var color = PaletteColor(11)
|
||||||
var androidColor = 0
|
var androidColor = 0
|
||||||
@@ -110,6 +112,7 @@ 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)
|
||||||
@@ -117,6 +120,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) {
|
||||||
@@ -260,9 +267,15 @@ class EditHabitActivity : AppCompatActivity() {
|
|||||||
val component = (application as HabitsApplication).component
|
val component = (application as HabitsApplication).component
|
||||||
val habit = component.modelFactory.buildHabit()
|
val habit = component.modelFactory.buildHabit()
|
||||||
|
|
||||||
|
val habitList = if (parentGroup != null) {
|
||||||
|
parentGroup!!.habitList
|
||||||
|
} else {
|
||||||
|
component.habitList
|
||||||
|
}
|
||||||
|
|
||||||
var original: Habit? = null
|
var original: Habit? = null
|
||||||
if (habitId >= 0) {
|
if (habitId >= 0) {
|
||||||
original = component.habitList.getById(habitId)!!
|
original = habitList.getById(habitId)!!
|
||||||
habit.copyFrom(original)
|
habit.copyFrom(original)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -283,17 +296,20 @@ class EditHabitActivity : AppCompatActivity() {
|
|||||||
habit.unit = binding.unitInput.text.trim().toString()
|
habit.unit = binding.unitInput.text.trim().toString()
|
||||||
}
|
}
|
||||||
habit.type = habitType
|
habit.type = habitType
|
||||||
|
habit.parent = parentGroup
|
||||||
|
habit.parentID = parentGroup?.id
|
||||||
|
habit.parentUUID = parentGroup?.uuid
|
||||||
|
|
||||||
val command = if (habitId >= 0) {
|
val command = if (habitId >= 0) {
|
||||||
EditHabitCommand(
|
EditHabitCommand(
|
||||||
component.habitList,
|
habitList,
|
||||||
habitId,
|
habitId,
|
||||||
habit
|
habit
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
CreateHabitCommand(
|
CreateHabitCommand(
|
||||||
component.modelFactory,
|
component.modelFactory,
|
||||||
component.habitList,
|
habitList,
|
||||||
habit
|
habit
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 : AppCompatDialogFragment() {
|
class HabitTypeDialog(val parentUUID: String? = 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 : 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)
|
val intent = IntentFactory().startEditActivity(requireActivity(), HabitType.YES_NO.value, parentUUID)
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.buttonMeasurable.setOnClickListener {
|
binding.buttonMeasurable.setOnClickListener {
|
||||||
val intent = IntentFactory().startEditActivity(requireActivity(), HabitType.NUMERICAL.value)
|
val intent = IntentFactory().startEditActivity(requireActivity(), HabitType.NUMERICAL.value, parentUUID)
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
@@ -57,6 +57,10 @@ class HabitTypeDialog : AppCompatDialogFragment() {
|
|||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (parentUUID != null) {
|
||||||
|
binding.buttonHabitGroup.visibility = View.GONE
|
||||||
|
}
|
||||||
|
|
||||||
binding.background.setOnClickListener {
|
binding.background.setOnClickListener {
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -164,8 +164,8 @@ class ListHabitsScreen
|
|||||||
activity.startActivity(intent)
|
activity.startActivity(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun showSelectHabitTypeDialog() {
|
override fun showSelectHabitTypeDialog(parentUUID: String?) {
|
||||||
val dialog = HabitTypeDialog()
|
val dialog = HabitTypeDialog(parentUUID)
|
||||||
dialog.show(activity.supportFragmentManager, "habitType")
|
dialog.show(activity.supportFragmentManager, "habitType")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,18 +8,19 @@ import android.text.TextPaint
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.View.MeasureSpec.EXACTLY
|
import android.view.View.MeasureSpec.EXACTLY
|
||||||
import org.isoron.uhabits.R
|
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.getFontAwesome
|
||||||
import org.isoron.uhabits.utils.sp
|
import org.isoron.uhabits.utils.sp
|
||||||
import org.isoron.uhabits.utils.sres
|
import org.isoron.uhabits.utils.sres
|
||||||
import org.isoron.uhabits.utils.toMeasureSpec
|
import org.isoron.uhabits.utils.toMeasureSpec
|
||||||
|
|
||||||
class AddButtonView(
|
class AddButtonView(
|
||||||
context: Context
|
context: Context,
|
||||||
|
var habitGroup: HabitGroup?
|
||||||
) : View(context),
|
) : View(context),
|
||||||
View.OnClickListener {
|
View.OnClickListener {
|
||||||
|
|
||||||
var onEdit: () -> Unit = { }
|
|
||||||
|
|
||||||
private var drawer = Drawer()
|
private var drawer = Drawer()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
@@ -27,7 +28,7 @@ class AddButtonView(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onClick(v: View) {
|
override fun onClick(v: View) {
|
||||||
onEdit()
|
(context as ListHabitsActivity).component.listHabitsMenu.behavior.onCreateHabit(habitGroup!!.uuid)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDraw(canvas: Canvas) {
|
override fun onDraw(canvas: Canvas) {
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ class HabitGroupCardView(
|
|||||||
}
|
}
|
||||||
field = newHabitGroup
|
field = newHabitGroup
|
||||||
if (newHabitGroup != null) copyAttributesFrom(newHabitGroup)
|
if (newHabitGroup != null) copyAttributesFrom(newHabitGroup)
|
||||||
|
addButtonView.habitGroup = newHabitGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
var score
|
var score
|
||||||
@@ -79,7 +80,7 @@ class HabitGroupCardView(
|
|||||||
setTypeface(typeface, Typeface.BOLD)
|
setTypeface(typeface, Typeface.BOLD)
|
||||||
}
|
}
|
||||||
|
|
||||||
addButtonView = AddButtonView(context)
|
addButtonView = AddButtonView(context, habitGroup)
|
||||||
|
|
||||||
innerFrame = LinearLayout(context).apply {
|
innerFrame = LinearLayout(context).apply {
|
||||||
gravity = Gravity.CENTER_VERTICAL
|
gravity = Gravity.CENTER_VERTICAL
|
||||||
|
|||||||
@@ -97,9 +97,12 @@ class IntentFactory
|
|||||||
return intent
|
return intent
|
||||||
}
|
}
|
||||||
|
|
||||||
fun startEditActivity(context: Context, habitType: Int): Intent {
|
fun startEditActivity(context: Context, habitType: Int, parentUUID: String?): Intent {
|
||||||
val intent = startEditActivity(context)
|
val intent = startEditActivity(context)
|
||||||
intent.putExtra("habitType", habitType)
|
intent.putExtra("habitType", habitType)
|
||||||
|
if (parentUUID != null) {
|
||||||
|
intent.putExtra("parentGroupUUID", parentUUID)
|
||||||
|
}
|
||||||
return intent
|
return intent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -132,6 +132,7 @@ data class Habit(
|
|||||||
this.type = other.type
|
this.type = other.type
|
||||||
this.unit = other.unit
|
this.unit = other.unit
|
||||||
this.uuid = other.uuid
|
this.uuid = other.uuid
|
||||||
|
this.parent = other.parent
|
||||||
this.parentID = other.parentID
|
this.parentID = other.parentID
|
||||||
this.parentUUID = other.parentUUID
|
this.parentUUID = other.parentUUID
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ data class HabitGroup(
|
|||||||
) {
|
) {
|
||||||
init {
|
init {
|
||||||
if (uuid == null) this.uuid = UUID.randomUUID().toString().replace("-", "")
|
if (uuid == null) this.uuid = UUID.randomUUID().toString().replace("-", "")
|
||||||
|
habitList.groupUUID = this.uuid
|
||||||
}
|
}
|
||||||
|
|
||||||
var observable = ModelObservable()
|
var observable = ModelObservable()
|
||||||
@@ -77,6 +78,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.groupUUID = this.uuid
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ abstract class HabitList : Iterable<Habit> {
|
|||||||
@JvmField
|
@JvmField
|
||||||
protected val filter: HabitMatcher
|
protected val filter: HabitMatcher
|
||||||
|
|
||||||
|
var groupUUID: String? = null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new HabitList.
|
* 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.HabitList
|
||||||
import org.isoron.uhabits.core.models.HabitMatcher
|
import org.isoron.uhabits.core.models.HabitMatcher
|
||||||
import org.isoron.uhabits.core.utils.DateUtils.Companion.getTodayWithOffset
|
import org.isoron.uhabits.core.utils.DateUtils.Companion.getTodayWithOffset
|
||||||
import java.util.ArrayList
|
|
||||||
import java.util.Comparator
|
|
||||||
import java.util.LinkedList
|
import java.util.LinkedList
|
||||||
import java.util.Objects
|
import java.util.Objects
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ 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.groupUUID = this.groupUUID
|
||||||
list.removeAll()
|
list.removeAll()
|
||||||
val records = repository.findAll("order by position")
|
val records = repository.findAll("order by position")
|
||||||
var shouldRebuildOrder = false
|
var shouldRebuildOrder = false
|
||||||
@@ -45,7 +46,7 @@ class SQLiteHabitList @Inject constructor(private val modelFactory: ModelFactory
|
|||||||
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
|
||||||
list.add(h)
|
if (h.parentUUID == list.groupUUID) list.add(h)
|
||||||
}
|
}
|
||||||
if (shouldRebuildOrder) rebuildOrder()
|
if (shouldRebuildOrder) rebuildOrder()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -476,7 +476,7 @@ class HabitCardListCache @Inject constructor(
|
|||||||
logger.error("performMove: $fromPosition for habit group is out of bounds")
|
logger.error("performMove: $fromPosition for habit group is out of bounds")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
data.habitGroups.removeAt(fromPosition)
|
data.habitGroups.removeAt(fromPosition - data.habits.size)
|
||||||
|
|
||||||
// Workaround for https://github.com/iSoron/uhabits/issues/968
|
// Workaround for https://github.com/iSoron/uhabits/issues/968
|
||||||
val checkedToPosition = if (toPosition < data.habits.size) {
|
val checkedToPosition = if (toPosition < data.habits.size) {
|
||||||
|
|||||||
@@ -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() {
|
fun onCreateHabit(parentUUID: String? = null) {
|
||||||
screen.showSelectHabitTypeDialog()
|
screen.showSelectHabitTypeDialog(parentUUID)
|
||||||
}
|
}
|
||||||
|
|
||||||
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()
|
fun showSelectHabitTypeDialog(parentUUID: String? = null)
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
|||||||
Reference in New Issue
Block a user