mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-14 21:18:51 -06:00
Fix habit group creation
This commit is contained in:
@@ -136,10 +136,11 @@ class HabitCardView(
|
|||||||
init {
|
init {
|
||||||
scoreRing = RingView(context).apply {
|
scoreRing = RingView(context).apply {
|
||||||
val thickness = dp(3f)
|
val thickness = dp(3f)
|
||||||
val margin = dp(8f).toInt()
|
val rightMargin = dp(8f).toInt()
|
||||||
val ringSize = dp(15f).toInt()
|
val ringSize = dp(15f).toInt()
|
||||||
|
val leftMargin = if (habit?.isSubHabit() == true) dp(30f).toInt() else dp(8f).toInt()
|
||||||
layoutParams = LinearLayout.LayoutParams(ringSize, ringSize).apply {
|
layoutParams = LinearLayout.LayoutParams(ringSize, ringSize).apply {
|
||||||
setMargins(margin, 0, margin, 0)
|
setMargins(leftMargin, 0, rightMargin, 0)
|
||||||
gravity = Gravity.CENTER
|
gravity = Gravity.CENTER
|
||||||
}
|
}
|
||||||
setThickness(thickness)
|
setThickness(thickness)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.isoron.uhabits.activities.habits.list.views
|
package org.isoron.uhabits.activities.habits.list.views
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.graphics.Typeface
|
||||||
import android.graphics.text.LineBreaker.BREAK_STRATEGY_BALANCED
|
import android.graphics.text.LineBreaker.BREAK_STRATEGY_BALANCED
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Build.VERSION.SDK_INT
|
import android.os.Build.VERSION.SDK_INT
|
||||||
@@ -75,6 +76,7 @@ class HabitGroupCardView(
|
|||||||
if (SDK_INT >= Build.VERSION_CODES.Q) {
|
if (SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
breakStrategy = BREAK_STRATEGY_BALANCED
|
breakStrategy = BREAK_STRATEGY_BALANCED
|
||||||
}
|
}
|
||||||
|
setTypeface(typeface, Typeface.BOLD)
|
||||||
}
|
}
|
||||||
|
|
||||||
addButtonView = AddButtonView(context)
|
addButtonView = AddButtonView(context)
|
||||||
|
|||||||
@@ -56,6 +56,8 @@ 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 hasReminder(): Boolean = reminder != null
|
fun hasReminder(): Boolean = reminder != null
|
||||||
|
|
||||||
fun isCompletedToday(): Boolean {
|
fun isCompletedToday(): Boolean {
|
||||||
|
|||||||
@@ -472,6 +472,10 @@ class HabitCardListCache @Inject constructor(
|
|||||||
fromPosition: Int,
|
fromPosition: Int,
|
||||||
toPosition: Int
|
toPosition: Int
|
||||||
) {
|
) {
|
||||||
|
if (fromPosition < data.habits.size || fromPosition > data.habits.size + data.habitGroups.size) {
|
||||||
|
logger.error("performMove: $fromPosition for habit group is out of bounds")
|
||||||
|
return
|
||||||
|
}
|
||||||
data.habitGroups.removeAt(fromPosition)
|
data.habitGroups.removeAt(fromPosition)
|
||||||
|
|
||||||
// Workaround for https://github.com/iSoron/uhabits/issues/968
|
// Workaround for https://github.com/iSoron/uhabits/issues/968
|
||||||
@@ -536,7 +540,7 @@ class HabitCardListCache @Inject constructor(
|
|||||||
val habitGroup = newData.habitGroups[currentPosition - data.habits.size]
|
val habitGroup = newData.habitGroups[currentPosition - data.habits.size]
|
||||||
val uuid = habitGroup.uuid
|
val uuid = habitGroup.uuid
|
||||||
val prevPosition = data.habitGroups.indexOf(habitGroup) + data.habits.size
|
val prevPosition = data.habitGroups.indexOf(habitGroup) + data.habits.size
|
||||||
if (prevPosition < 0) {
|
if (prevPosition < data.habits.size) {
|
||||||
performInsert(habitGroup, currentPosition)
|
performInsert(habitGroup, currentPosition)
|
||||||
} else {
|
} else {
|
||||||
if (prevPosition != currentPosition) {
|
if (prevPosition != currentPosition) {
|
||||||
|
|||||||
Reference in New Issue
Block a user