Skip to content

Commit

Permalink
refactor: maxLength filter
Browse files Browse the repository at this point in the history
Kotlin cleanup
  • Loading branch information
david-allison committed Jan 31, 2024
1 parent 24c52a9 commit fe10e0a
Showing 1 changed file with 1 addition and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package com.ichi2.preferences

import android.content.Context
import android.text.InputFilter
import android.text.InputFilter.LengthFilter
import android.text.InputType
import android.util.AttributeSet
Expand Down Expand Up @@ -142,13 +141,7 @@ open class NumberRangePreference : android.preference.EditTextPreference, AutoFo
editText.inputType = InputType.TYPE_CLASS_NUMBER

// Set max number of digits
val maxLength = max.toString().length
// Clone the existing filters so we don't override them, then append our one at the end.
val filters = editText.filters
val newFilters = arrayOfNulls<InputFilter>(filters.size + 1)
System.arraycopy(filters, 0, newFilters, 0, filters.size)
newFilters[newFilters.size - 1] = LengthFilter(maxLength)
editText.filters = newFilters
editText.filters += LengthFilter(max.toString().length)
}
var value: Int
/**
Expand Down

0 comments on commit fe10e0a

Please sign in to comment.