From 76045daada0a86b5561ea196de35f4f61fcaf796 Mon Sep 17 00:00:00 2001 From: Tianzhu Qiao Date: Sun, 22 Nov 2020 17:18:29 -0800 Subject: [PATCH] Update onEditorAction callback. --- .../main/java/com/feiyilin/app/MainActivity.kt | 12 ++++++++++++ form/src/main/java/com/feiyilin/form/FormItem.kt | 12 ++++++++++++ .../com/feiyilin/form/FormRecyclerAdapter.kt | 12 ++++++++---- .../java/com/feiyilin/form/FormViewHolder.kt | 2 +- images/item_text_password.png | Bin 0 -> 9876 bytes 5 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 images/item_text_password.png diff --git a/app/src/main/java/com/feiyilin/app/MainActivity.kt b/app/src/main/java/com/feiyilin/app/MainActivity.kt index a32b273..52d6d03 100644 --- a/app/src/main/java/com/feiyilin/app/MainActivity.kt +++ b/app/src/main/java/com/feiyilin/app/MainActivity.kt @@ -45,6 +45,10 @@ class MainActivity : FormActivity() { .inputType(EditorInfo.TYPE_CLASS_NUMBER) +FormItemText().title("Phone").tag("phone") .inputType(EditorInfo.TYPE_CLASS_PHONE).imeOptions(EditorInfo.IME_ACTION_PREVIOUS) + .onEditorAction {item, _, _ -> + Toast.makeText(this@MainActivity, "EditorAction on ${item.title}", Toast.LENGTH_SHORT).show() + false + } +FormItemPassword().title("Password").tag("password") +FormItemLabel().title("Label").tag("label") .subTitle("subtitle of label") @@ -377,6 +381,14 @@ class MainActivity : FormActivity() { } } } + + override fun onEditorAction( + item: FormItem, + actionId: Int, + viewHolder: RecyclerView.ViewHolder + ): Boolean { + return super.onEditorAction(item, actionId, viewHolder) + } } } diff --git a/form/src/main/java/com/feiyilin/form/FormItem.kt b/form/src/main/java/com/feiyilin/form/FormItem.kt index 6c70ee5..1946e78 100644 --- a/form/src/main/java/com/feiyilin/form/FormItem.kt +++ b/form/src/main/java/com/feiyilin/form/FormItem.kt @@ -95,6 +95,7 @@ open class FormItem { var onStartReorder: ((viewHolder: RecyclerView.ViewHolder) -> Boolean)? = null var onMoveItem: ((src: Int, dest: Int) -> Boolean)? = null var onSwipedAction: ((action: FormSwipeAction, viewHolder: RecyclerView.ViewHolder) -> Boolean)? = null + var onEditorAction: ((actionId: Int, viewHolder: RecyclerView.ViewHolder) -> Boolean)? = null } fun T.title(title: String) = apply { @@ -229,6 +230,17 @@ fun T.onSwipedAction(callback: ((item: T, action: FormSwipeAction } } +fun T.onEditorAction(callback: ((item: T, actionId: Int, viewHolder: RecyclerView.ViewHolder) -> Boolean)?) = apply { + if (callback == null) { + this.onEditorAction = null + } else { + this.onEditorAction = { actionId, viewHolder -> + callback.invoke(this, actionId, viewHolder) + } + } +} + + open class FormItemLabel : FormItem() { } diff --git a/form/src/main/java/com/feiyilin/form/FormRecyclerAdapter.kt b/form/src/main/java/com/feiyilin/form/FormRecyclerAdapter.kt index 133fe40..2fbc077 100644 --- a/form/src/main/java/com/feiyilin/form/FormRecyclerAdapter.kt +++ b/form/src/main/java/com/feiyilin/form/FormRecyclerAdapter.kt @@ -28,7 +28,7 @@ interface FormItemCallback { return false } - fun onEditAction(item: FormItem, actionId: Int, viewHolder: RecyclerView.ViewHolder): Boolean { + fun onEditorAction(item: FormItem, actionId: Int, viewHolder: RecyclerView.ViewHolder): Boolean { return false } fun getMinItemHeight(item: FormItem): Int { @@ -483,9 +483,13 @@ open class FormRecyclerAdapter( return listener?.onSwipedAction(item, action, viewHolder) ?: false } - override fun onEditAction(item: FormItem, actionId: Int, viewHolder: RecyclerView.ViewHolder): Boolean { - super.onEditAction(item, actionId, viewHolder) - if (listener?.onEditAction(item, actionId, viewHolder) == true) { + override fun onEditorAction(item: FormItem, actionId: Int, viewHolder: RecyclerView.ViewHolder): Boolean { + super.onEditorAction(item, actionId, viewHolder) + if (item.onEditorAction != null) { + if (item.onEditorAction?.invoke(actionId, viewHolder) == true) { + return true + } + } else if (listener?.onEditorAction(item, actionId, viewHolder) == true) { return true } when (actionId) { diff --git a/form/src/main/java/com/feiyilin/form/FormViewHolder.kt b/form/src/main/java/com/feiyilin/form/FormViewHolder.kt index 3af7004..a7bc7ed 100644 --- a/form/src/main/java/com/feiyilin/form/FormViewHolder.kt +++ b/form/src/main/java/com/feiyilin/form/FormViewHolder.kt @@ -246,7 +246,7 @@ open class FormBaseTextViewHolder(inflater: LayoutInflater, resource: Int, paren } valueView?.setOnEditorActionListener { v, actionId, _ -> item?.let { - listener?.onEditAction(it, actionId, this) + listener?.onEditorAction(it, actionId, this) return@setOnEditorActionListener true } false diff --git a/images/item_text_password.png b/images/item_text_password.png new file mode 100644 index 0000000000000000000000000000000000000000..54e6efedabab40b4102d97ae2a09e722f70d81e2 GIT binary patch literal 9876 zcmeHtAY0~ey*5{$%%nL#gX_YhS6|VsHrBzOim8O1dMS&S1_)Euz(Q;2oreR`fH2^Wl5>O(1AB08YmoYC&0$$;^M;U!pUmuV9xfKpP!$Nor8^og9U(Kadd;h z4P9Aajt~AM@*g^qrjEuA7Itt8TNw2PT|*;VC%6y|%>|?X{{6X6xP{r@oM4WBi3JGA zcCo_tn3bLFe?l{LwfO&_U99|x_EWAu**&=+CZGtlh1&v$;b375fx%53>>PlDx!9yI z$CIDz{uhY9xBe$B1qTaLK=_~7kN?8HJoh`igslz0&e8FL+kfCM&;1UsZ0cxh?Q}t2 z4Q2uV?*@OHzJzrlw}7IBtEsh?q=k(s>`zV{0I&aX<#$X8TWebf6+1&?(~Ir>M7cEe zJM>RJnwR*n^RZuMbZO}?)F*5gif~CW{?xjkvw+$O<2_;fuL=v}eIZu@ESClakrY#P z#aKtXeOKF|YTHsU#SgJ2d5Peb4B(LorF%bcgKa#hiz|e zih?k%{POT6#veL1H>W7u4`Oj-)D3SBQvmn!8*cywBz=@}-{to$i7sH{*qNNs1FqsXoaGBz zXXfp9eJ>!sHOb$*A+ z{f1&X_dBme!*NfJR*M$OCt>({!-tD0wmg&8rF}f=mwnPq{q2MK7=zEuMKwldJ&6>a zq-^@uq^!D79yDBKu*S`C5anbwSZ<>;SZ1X$n6FiOz9FvSyr6oGFPhB&_Qid*0MS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