-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
102 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
app/src/main/java/com/luisansal/jetpack/utils/AllLowerInputFilter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.luisansal.jetpack.utils | ||
|
||
import android.text.InputFilter | ||
import android.text.SpannableString | ||
import android.text.Spanned | ||
import android.text.TextUtils | ||
|
||
class AllLowerInputFilter : InputFilter { | ||
|
||
override fun filter(source: CharSequence, start: Int, end: Int, dest: Spanned?, dstart: Int, dend: Int): CharSequence? { | ||
|
||
for (i in start until end) { | ||
if (source[i].isUpperCase()) { | ||
val v = CharArray(end - start) | ||
TextUtils.getChars(source, start, end, v, 0) | ||
val s = String(v).toLowerCase() | ||
|
||
return if (source is Spanned) { | ||
val sp = SpannableString(s) | ||
TextUtils.copySpansFrom(source, start, end, null, sp, 0) | ||
sp | ||
} else { | ||
s | ||
} | ||
} | ||
} | ||
|
||
return null // keep original | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
app/src/main/java/com/luisansal/jetpack/utils/BindingAdapters.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.luisansal.jetpack.utils | ||
|
||
import android.text.InputFilter | ||
import android.widget.EditText | ||
import android.widget.ImageView | ||
import androidx.annotation.DrawableRes | ||
import androidx.databinding.BindingAdapter | ||
|
||
@BindingAdapter("toLowerCase") | ||
fun toLowerCase(view: EditText, isLowerCase: Boolean?) { | ||
isLowerCase?.let { | ||
if(it){ | ||
view.filters = arrayOf<InputFilter>(AllLowerInputFilter()) | ||
} else { | ||
view.filters = null | ||
} | ||
} | ||
} | ||
|
||
@BindingAdapter("app:loadImage") | ||
fun loadImage(view: ImageView?, @DrawableRes imageId: Int) { | ||
view?.setImageResource(imageId) | ||
} | ||
|
||
@BindingAdapter("requestFocus") | ||
fun requestFocus(view: EditText, requestFocus: Boolean?) { | ||
requestFocus?.also { | ||
if (it) { | ||
view.requestFocus() | ||
view.showKeyboard() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
include ':app' | ||
include ':core' |