diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/views/NumberButtonView.kt b/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/views/NumberButtonView.kt index 03fe66e53..be2baa446 100644 --- a/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/views/NumberButtonView.kt +++ b/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/views/NumberButtonView.kt @@ -189,16 +189,19 @@ class NumberButtonView( textSize = dim(R.dimen.smallTextSize) typeface = getFontAwesome() } + value >= 0 -> { label = value.toShortString() typeface = BOLD_TYPEFACE textSize = dim(R.dimen.smallTextSize) } + preferences.areQuestionMarksEnabled -> { label = resources.getString(R.string.fa_question) typeface = getFontAwesome() textSize = dim(R.dimen.smallerTextSize) } + else -> { label = "0" typeface = BOLD_TYPEFACE @@ -212,14 +215,23 @@ class NumberButtonView( pUnit.color = activeColor if (units.isBlank()) { + // Draw number without units rect.set(0f, 0f, width.toFloat(), height.toFloat()) rect.offset(0f, 0.5f * em) canvas.drawText(label, rect.centerX(), rect.centerY(), pNumber) } else { + // Draw number rect.set(0f, 0f, width.toFloat(), height.toFloat()) canvas.drawText(label, rect.centerX(), rect.centerY(), pNumber) + + // Draw units + val maxUnitsWidth = width * 0.9f + var trimmedUnits = units + while (trimmedUnits.length > 2 && pUnit.measureText(trimmedUnits) > maxUnitsWidth) { + trimmedUnits = trimmedUnits.dropLast(2) + "…" + } rect.offset(0f, 1.3f * em) - canvas.drawText(units, rect.centerX(), rect.centerY(), pUnit) + canvas.drawText(trimmedUnits, rect.centerX(), rect.centerY(), pUnit) } drawNotesIndicator(canvas, color, em, notes) diff --git a/uhabits-android/src/main/res/layout/show_habit_subtitle.xml b/uhabits-android/src/main/res/layout/show_habit_subtitle.xml index 7361b4565..837b264d9 100644 --- a/uhabits-android/src/main/res/layout/show_habit_subtitle.xml +++ b/uhabits-android/src/main/res/layout/show_habit_subtitle.xml @@ -1,5 +1,4 @@ - -