mirror of
https://github.com/afollestad/nock-nock.git
synced 2025-04-22 04:25:16 +00:00
Limit interval input field to 6 characters, resolves #17.
This commit is contained in:
parent
6dfff5bb12
commit
77a98b161b
4 changed files with 81 additions and 23 deletions
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Licensed under Apache-2.0
|
||||
*
|
||||
* Designed and developed by Aidan Follestad (@afollestad)
|
||||
*/
|
||||
package com.afollestad.nocknock.viewcomponents.ext
|
||||
|
||||
import android.view.View
|
||||
import android.widget.AdapterView
|
||||
import android.widget.Spinner
|
||||
|
||||
fun Spinner.onItemSelected(cb: (Int) -> Unit) {
|
||||
onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
||||
override fun onNothingSelected(parent: AdapterView<*>?) = Unit
|
||||
|
||||
override fun onItemSelected(
|
||||
parent: AdapterView<*>?,
|
||||
view: View?,
|
||||
position: Int,
|
||||
id: Long
|
||||
) = cb(position)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* Licensed under Apache-2.0
|
||||
*
|
||||
* Designed and developed by Aidan Follestad (@afollestad)
|
||||
*/
|
||||
package com.afollestad.nocknock.viewcomponents.ext
|
||||
|
||||
import android.widget.TextView
|
||||
|
||||
fun TextView.trimmedText() = text.toString().trim()
|
||||
|
||||
fun TextView.textAsLong(): Long {
|
||||
val text = trimmedText()
|
||||
return if (text.isEmpty()) 0L else text.toLong()
|
||||
}
|
||||
|
||||
///** @author https://stackoverflow.com/a/53296137/309644 */
|
||||
//fun EditText.addFilter(filter: InputFilter) {
|
||||
// filters =
|
||||
// if (filters.isNullOrEmpty()) {
|
||||
// arrayOf(filter)
|
||||
// } else {
|
||||
// filters
|
||||
// .toMutableList()
|
||||
// .apply {
|
||||
// removeAll { it.javaClass == filter.javaClass }
|
||||
// add(filter)
|
||||
// }
|
||||
// .toTypedArray()
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//fun <T : InputFilter> EditText.removeFilters(type: Class<in T>) {
|
||||
// filters =
|
||||
// if (filters.isNullOrEmpty()) {
|
||||
// filters
|
||||
// } else {
|
||||
// filters
|
||||
// .toMutableList()
|
||||
// .apply {
|
||||
// removeAll { it.javaClass == type }
|
||||
// }
|
||||
// .toTypedArray()
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//fun EditText.setMaxLength(maxLength: Int) {
|
||||
// if (maxLength <= 0) {
|
||||
// removeFilters(LengthFilter::class.java)
|
||||
// } else {
|
||||
// if (text.length > maxLength) {
|
||||
// setText(text.subSequence(0, maxLength))
|
||||
// setSelection(text.length)
|
||||
// }
|
||||
// addFilter(LengthFilter(maxLength))
|
||||
// }
|
||||
//}
|
|
@ -10,9 +10,6 @@ import android.view.View.GONE
|
|||
import android.view.View.INVISIBLE
|
||||
import android.view.View.VISIBLE
|
||||
import android.view.ViewTreeObserver
|
||||
import android.widget.AdapterView
|
||||
import android.widget.Spinner
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.DimenRes
|
||||
|
||||
fun View.show() {
|
||||
|
@ -29,26 +26,6 @@ fun View.hide() {
|
|||
|
||||
fun View.showOrHide(show: Boolean) = if (show) show() else hide()
|
||||
|
||||
fun TextView.trimmedText() = text.toString().trim()
|
||||
|
||||
fun TextView.textAsLong(): Long {
|
||||
val text = trimmedText()
|
||||
return if (text.isEmpty()) 0L else text.toLong()
|
||||
}
|
||||
|
||||
fun Spinner.onItemSelected(cb: (Int) -> Unit) {
|
||||
onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
||||
override fun onNothingSelected(parent: AdapterView<*>?) = Unit
|
||||
|
||||
override fun onItemSelected(
|
||||
parent: AdapterView<*>?,
|
||||
view: View?,
|
||||
position: Int,
|
||||
id: Long
|
||||
) = cb(position)
|
||||
}
|
||||
}
|
||||
|
||||
fun View.onLayout(cb: () -> Unit) {
|
||||
if (this.viewTreeObserver.isAlive) {
|
||||
this.viewTreeObserver.addOnGlobalLayoutListener(
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
android:fontFamily="sans-serif-light"
|
||||
android:hint="0"
|
||||
android:inputType="number"
|
||||
android:maxLength="6"
|
||||
android:textSize="@dimen/body_font_size"
|
||||
tools:ignore="Autofill,HardcodedText,LabelFor"
|
||||
/>
|
||||
|
|
Loading…
Add table
Reference in a new issue