Merge pull request #2222 from Vladuken/fix/improve-ui-performance-of-habits-list

Improvement:  UI performance of Habit List drag&drop
This commit is contained in:
2025-12-13 09:50:09 -06:00
committed by GitHub
5 changed files with 32 additions and 8 deletions

View File

@@ -36,12 +36,14 @@ abstract class ButtonPanelView<T : View>(
var buttonCount = 0 var buttonCount = 0
set(value) { set(value) {
if (field == value) return
field = value field = value
inflateButtons() inflateButtons()
} }
var dataOffset = 0 var dataOffset = 0
set(value) { set(value) {
if (field == value) return
field = value field = value
setupButtons() setupButtons()
} }

View File

@@ -135,6 +135,7 @@ class CheckmarkButtonView(
private val bgColor = sres.getColor(R.attr.cardBgColor) private val bgColor = sres.getColor(R.attr.cardBgColor)
private val lowContrastColor = sres.getColor(R.attr.contrast40) private val lowContrastColor = sres.getColor(R.attr.contrast40)
private val mediumContrastColor = sres.getColor(R.attr.contrast60) private val mediumContrastColor = sres.getColor(R.attr.contrast60)
private val pNotesIndicator = Paint()
private val paint = TextPaint().apply { private val paint = TextPaint().apply {
typeface = getFontAwesome() typeface = getFontAwesome()
@@ -192,7 +193,13 @@ class CheckmarkButtonView(
canvas.drawText(label, rect.centerX(), rect.centerY(), paint) canvas.drawText(label, rect.centerX(), rect.centerY(), paint)
} }
drawNotesIndicator(canvas, color, em, notes) drawNotesIndicator(
pNotesIndicator = pNotesIndicator,
canvas = canvas,
color = color,
size = em,
notes = notes,
)
} }
} }
} }

View File

@@ -70,6 +70,8 @@ class HabitCardListAdapter @Inject constructor(
* Sets all items as not selected. * Sets all items as not selected.
*/ */
override fun clearSelection() { override fun clearSelection() {
if (selected.isEmpty()) return
selected.clear() selected.clear()
notifyDataSetChanged() notifyDataSetChanged()
observable.notifyListeners() observable.notifyListeners()

View File

@@ -145,6 +145,8 @@ class NumberButtonView(
private val lowContrast: Int private val lowContrast: Int
private val mediumContrast: Int private val mediumContrast: Int
private val pNotesIndicator = Paint()
private val paint = TextPaint().apply { private val paint = TextPaint().apply {
typeface = getFontAwesome() typeface = getFontAwesome()
isAntiAlias = true isAntiAlias = true
@@ -234,7 +236,13 @@ class NumberButtonView(
canvas.drawText(trimmedUnits, rect.centerX(), rect.centerY(), pUnit) canvas.drawText(trimmedUnits, rect.centerX(), rect.centerY(), pUnit)
} }
drawNotesIndicator(canvas, color, em, notes) drawNotesIndicator(
pNotesIndicator = pNotesIndicator,
canvas = canvas,
color = color,
size = em,
notes = notes,
)
} }
} }
} }

View File

@@ -210,13 +210,18 @@ fun View.sp(value: Float) = InterfaceUtils.spToPixels(context, value)
fun View.dp(value: Float) = InterfaceUtils.dpToPixels(context, value) fun View.dp(value: Float) = InterfaceUtils.dpToPixels(context, value)
fun View.str(id: Int) = resources.getString(id) fun View.str(id: Int) = resources.getString(id)
fun View.drawNotesIndicator(canvas: Canvas, color: Int, size: Float, notes: String) { fun View.drawNotesIndicator(
val pNotesIndicator = Paint() pNotesIndicator: Paint,
canvas: Canvas,
color: Int,
size: Float,
notes: String,
) {
if (notes.isBlank()) return
pNotesIndicator.color = color pNotesIndicator.color = color
if (notes.isNotBlank()) {
val cy = 0.8f * size val cy = 0.8f * size
canvas.drawCircle(width.toFloat() - cy, cy, 8f, pNotesIndicator) canvas.drawCircle(width.toFloat() - cy, cy, 8f, pNotesIndicator)
}
} }
val View.sres: StyledResources val View.sres: StyledResources