Skip to content

Commit

Permalink
EditText扩展调整
Browse files Browse the repository at this point in the history
1. 删除setTextPro
2. 改addTextLengthListener -> addTextLengthLimit
  • Loading branch information
你需要一台永动机 committed Aug 4, 2020
1 parent 9430aac commit 39151e4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
File renamed without changes.
25 changes: 11 additions & 14 deletions lib/src/main/java/com/pmm/ui/ktx/EditText.kt
Original file line number Diff line number Diff line change
Expand Up @@ -152,32 +152,29 @@ fun EditText.addClearView(clearView: View? = null, keyWordListener: ((keyWord: S
}
}

/**
* 设置文本时 自动将角标显示都尾部
*/
fun EditText.setTextPro(text: CharSequence) {
this.setText(text)
this.setSelectionEnd()
}

/**
* 添加监听字数视图,且设置限制字数
* @param limitLength 限制字数
* @param textCallback 文本监听者
* @param overTextCallback 超过限制字数的回调
*/
fun EditText.addTextLengthListener(
textLengthListener: ((textLength: Int) -> Unit)? = null,
limitLength: Int = -1
fun EditText.addTextLengthLimit(
limitLength: Int = -1,
textCallback: ((content: String) -> Unit)? = null,
overTextCallback: (() -> Unit)? = null
) {
val edit = this;
this.addTextChangedListener(object : MyTextWatcher {

override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
val content = s.toString()
if (limitLength != -1 && content.length > limitLength) {
edit.setText(content.substring(0, content.length - 1))
overTextCallback?.invoke()
edit.setText(content.substring(0, limitLength))
edit.setSelectionEnd()
return
}
textLengthListener?.invoke(content.length)
textCallback?.invoke(content)
}
})
}

Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ annotation class ShareContentType {
* @param shareText 分享文本
* @param shareContentType 分享内容类型
*/
fun Context.share(shareFile: File? = null, shareText: String = "", @ShareContentType shareContentType: String = ShareContentType.TEXT) {
fun Context.share(
shareFile: File? = null,
shareText: String = "",
@ShareContentType shareContentType: String = ShareContentType.TEXT
) {
val shareIntent = Intent(Intent.ACTION_SEND)
shareIntent.type = shareContentType
if (shareContentType == ShareContentType.TEXT) {
Expand Down
File renamed without changes.

0 comments on commit 39151e4

Please sign in to comment.