/
EditTextUtils.kt
31 lines (23 loc) 路 1.12 KB
/
EditTextUtils.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package openfoodfacts.github.scrachx.openfood.utils
import android.widget.EditText
import com.hootsuite.nachos.NachoTextView
import openfoodfacts.github.scrachx.openfood.features.shared.views.CustomValidatingEditTextView
import openfoodfacts.github.scrachx.openfood.models.Nutriments
fun EditText?.getContent() = this?.text?.toString()
/**
* @return true if the edit text string value is not empty
*/
fun EditText?.isNotEmpty() = !isEmpty()
fun EditText.isContentDifferent(toCompare: String?): Boolean {
val fieldValue = getContent()
return !(fieldValue.isNullOrEmpty() && toCompare.isNullOrEmpty()
|| !fieldValue.isNullOrEmpty() && fieldValue == toCompare)
}
/**
* @return true if the edit text string value is empty or null
*/
fun EditText?.isEmpty() = this.getContent().isNullOrEmpty()
fun NachoTextView.areChipsEquals(toCompare: List<String>) =
chipValues.toTypedArray() contentEquals toCompare.toTypedArray()
fun NachoTextView.areChipsDifferent(toCompare: List<String>) = !areChipsEquals(toCompare)
fun CustomValidatingEditTextView.hasUnit() = entryName != Nutriments.PH && entryName != Nutriments.ALCOHOL