Skip to content

Commit 8f24024

Browse files
committed
Limit length of numerical habit units to 7
1 parent 897a236 commit 8f24024

File tree

4 files changed

+9
-0
lines changed

4 files changed

+9
-0
lines changed

uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/edit/EditHabitActivity.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,10 @@ class EditHabitActivity : AppCompatActivity() {
314314
binding.targetInput.error = getString(R.string.validation_cannot_be_blank)
315315
isValid = false
316316
}
317+
if (binding.unitInput.text.length > resources.getInteger(R.integer.unit_name_max_length)) {
318+
binding.unitInput.error = getString(R.string.validation_unit_too_long)
319+
isValid = false
320+
}
317321
}
318322
return isValid
319323
}

uhabits-android/src/main/res/layout/activity_edit_habit.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@
167167
android:id="@+id/unitInput"
168168
android:maxLines="1"
169169
android:ems="10"
170+
android:maxLength="@integer/unit_name_max_length"
170171
android:hint="@string/measurable_units_example"/>
171172
</LinearLayout>
172173
</FrameLayout>

uhabits-android/src/main/res/values/constants.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
<string name="bugReportTo">[email protected]</string>
2929
<string name="bugReportSubject">Bug Report - Loop Habit Tracker</string>
3030
<string name="syncBaseURL" formatted="false">https://sync.loophabits.org</string>
31+
32+
<!-- Maximum length for unit names in numerical habits -->
33+
<integer name="unit_name_max_length">7</integer>
3134

3235
<string-array name="snooze_picker_names">
3336
<item>@string/interval_15_minutes</item>

uhabits-android/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,4 +235,5 @@
235235
<string name="pref_midnight_delay_description">Wait until 3:00 AM to show a new day. Useful if you typically go to sleep after midnight. Requires app restart.</string>
236236
<string name="pref_animations_title">Disable animations</string>
237237
<string name="pref_animations_description">Disable confetti animation after adding a checkmark.</string>
238+
<string name="validation_unit_too_long">Unit name is too long.</string>
238239
</resources>

0 commit comments

Comments
 (0)