Fix habit group creation

pull/2020/head
Dharanish 1 year ago
parent 676f141d99
commit 17e6c4f6e9

@ -136,10 +136,11 @@ class HabitCardView(
init {
scoreRing = RingView(context).apply {
val thickness = dp(3f)
val margin = dp(8f).toInt()
val rightMargin = dp(8f).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 {
setMargins(margin, 0, margin, 0)
setMargins(leftMargin, 0, rightMargin, 0)
gravity = Gravity.CENTER
}
setThickness(thickness)

@ -1,6 +1,7 @@
package org.isoron.uhabits.activities.habits.list.views
import android.content.Context
import android.graphics.Typeface
import android.graphics.text.LineBreaker.BREAK_STRATEGY_BALANCED
import android.os.Build
import android.os.Build.VERSION.SDK_INT
@ -75,6 +76,7 @@ class HabitGroupCardView(
if (SDK_INT >= Build.VERSION_CODES.Q) {
breakStrategy = BREAK_STRATEGY_BALANCED
}
setTypeface(typeface, Typeface.BOLD)
}
addButtonView = AddButtonView(context)

@ -56,6 +56,8 @@ data class Habit(
val uriString: String
get() = "content://org.isoron.uhabits/habit/$id"
fun isSubHabit(): Boolean = parentUUID != null
fun hasReminder(): Boolean = reminder != null
fun isCompletedToday(): Boolean {

@ -472,6 +472,10 @@ class HabitCardListCache @Inject constructor(
fromPosition: 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)
// 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 uuid = habitGroup.uuid
val prevPosition = data.habitGroups.indexOf(habitGroup) + data.habits.size
if (prevPosition < 0) {
if (prevPosition < data.habits.size) {
performInsert(habitGroup, currentPosition)
} else {
if (prevPosition != currentPosition) {

Loading…
Cancel
Save