diff --git a/PishkhanHelper/build.gradle b/PishkhanHelper/build.gradle index c677eb6..564da69 100644 --- a/PishkhanHelper/build.gradle +++ b/PishkhanHelper/build.gradle @@ -94,7 +94,7 @@ afterEvaluate { artifactId = 'pishkhanhelper' // Version Library Name (Example : "1.0.0") - version = '0.2.0' + version = '0.2.1' } } } diff --git a/PishkhanHelper/src/main/java/ir/ayantech/pishkhanhelper/components/InputComponent.kt b/PishkhanHelper/src/main/java/ir/ayantech/pishkhanhelper/components/InputComponent.kt index 5412716..ac0f7db 100644 --- a/PishkhanHelper/src/main/java/ir/ayantech/pishkhanhelper/components/InputComponent.kt +++ b/PishkhanHelper/src/main/java/ir/ayantech/pishkhanhelper/components/InputComponent.kt @@ -24,14 +24,30 @@ import ir.ayantech.pishkhanhelper.helper.textChanges import ir.ayantech.whygoogle.helper.BooleanCallBack import ir.ayantech.whygoogle.helper.SimpleCallBack -fun View.initInputComponent() { - ComponentInputBinding.bind(this).apply { - initInputComponent() - } +fun View.initInputComponent( + context: Context, + hint: String? = null, + text: String? = null, + @ColorRes backgroundTint: Int? = null, + inputType: Int = InputType.TYPE_CLASS_TEXT, + helperText: String? = null, + maxLength: Int? = null, + textAlignment: Int? = null, +) { + ComponentInputBinding.bind(this).initInputComponent( + context, + hint, + text, + backgroundTint, + inputType, + helperText, + maxLength, + textAlignment, + ) } @SuppressLint("ClickableViewAccessibility") -fun View.initInputComponent( +fun ViewBinding.initInputComponent( context: Context, hint: String? = null, text: String? = null, @@ -39,19 +55,19 @@ fun View.initInputComponent( inputType: Int = InputType.TYPE_CLASS_TEXT, helperText: String? = null, maxLength: Int? = null, - @DrawableRes startDrawable: Int? = null, - @DrawableRes endDrawable: Int? = null, - @ColorRes startIconColor: Int? = null, - @ColorRes endIconColor: Int? = null, - onStartIconClicked: SimpleCallBack? = null, - onEndIconClicked: SimpleCallBack? = null, textAlignment: Int? = null, - onStartIconTouchListener: OnTouchListener? = null, - onEndIconTouchListener: OnTouchListener? = null, - @DimenRes startIconPadding: Int? = null, - @DimenRes endIconPadding: Int? = null, +// @DrawableRes startDrawable: Int? = null, +// @DrawableRes endDrawable: Int? = null, +// @ColorRes startIconColor: Int? = null, +// @ColorRes endIconColor: Int? = null, +// onStartIconClicked: SimpleCallBack? = null, +// onEndIconClicked: SimpleCallBack? = null, +// onStartIconTouchListener: OnTouchListener? = null, +// onEndIconTouchListener: OnTouchListener? = null, +// @DimenRes startIconPadding: Int? = null, +// @DimenRes endIconPadding: Int? = null, ) { - ComponentInputBinding.bind(this).apply { + (this as? ComponentInputBinding)?.let { backgroundTint?.let { textInputLayout.boxBackgroundColor = getColor(context, backgroundTint) } @@ -93,12 +109,12 @@ fun View.initInputComponent( } } -fun View.initPhoneNumberInputComponent( +fun ViewBinding.initPhoneNumberInputComponent( activity: Activity, doAfterFilled: BooleanCallBack? = null, onEditorActionListener: SimpleCallBack? = null ) { - ComponentInputBinding.bind(this).apply { + (this as? ComponentInputBinding)?.let { initInputComponent( context = activity, hint = activity.getString(R.string.phone_number), @@ -118,13 +134,13 @@ fun View.initPhoneNumberInputComponent( } } -fun View.initOtpCodeInputComponent( +fun ViewBinding.initOtpCodeInputComponent( activity: Activity, doAfterFilled: BooleanCallBack? = null, onEditorActionListener: SimpleCallBack? = null, maxLength: Int? = null ) { - ComponentInputBinding.bind(this).apply { + (this as? ComponentInputBinding)?.let { initInputComponent( context = activity, hint = activity.getString(R.string.otp_code), @@ -144,16 +160,16 @@ fun View.initOtpCodeInputComponent( } } -fun View.getInputComponentText() = ComponentInputBinding.bind(this).textInputEditText.text?.toString() ?: "" +fun ViewBinding.getInputComponentText() = (this as? ComponentInputBinding)?.textInputEditText?.text?.toString() ?: "" -fun View.setInputComponentText(text: String?) { - ComponentInputBinding.bind(this).apply { +fun ViewBinding.setInputComponentText(text: String?) { + (this as? ComponentInputBinding)?.let { textInputEditText.setText(text) } } -fun View.placeInputComponentCursorToEnd() { - ComponentInputBinding.bind(this).apply { +fun ViewBinding.placeInputComponentCursorToEnd() { + (this as? ComponentInputBinding)?.let { textInputEditText.placeCursorToEnd() } } @@ -162,20 +178,20 @@ fun View.placeInputComponentCursorToEnd() { // root.changeVisibility(show = show) //} -fun View.setInputComponentAfterTextChangesListener(afterTextChangedCallback: AfterTextChangedCallback) { - ComponentInputBinding.bind(this).apply { +fun ViewBinding.setInputComponentAfterTextChangesListener(afterTextChangedCallback: AfterTextChangedCallback) { + (this as? ComponentInputBinding)?.let { textInputEditText.textChanges(afterTextChangedCallback = afterTextChangedCallback) } } -fun View.setInputComponentError(text: String?) { - ComponentInputBinding.bind(this).apply { +fun ViewBinding.setInputComponentError(text: String?) { + (this as? ComponentInputBinding)?.let { textInputLayout.error = text } } -fun View.requestFocusInputComponent(selectAll: Boolean = true) { - ComponentInputBinding.bind(this).apply { +fun ViewBinding.requestFocusInputComponent(selectAll: Boolean = true) { + (this as? ComponentInputBinding)?.let { textInputEditText.requestFocus() if (selectAll) textInputEditText.selectAll() diff --git a/PishkhanHelper/src/main/java/ir/ayantech/pishkhanhelper/fragment/login/EnterOtpCodeFragment.kt b/PishkhanHelper/src/main/java/ir/ayantech/pishkhanhelper/fragment/login/EnterOtpCodeFragment.kt index ab0fcf4..6ab1c6d 100644 --- a/PishkhanHelper/src/main/java/ir/ayantech/pishkhanhelper/fragment/login/EnterOtpCodeFragment.kt +++ b/PishkhanHelper/src/main/java/ir/ayantech/pishkhanhelper/fragment/login/EnterOtpCodeFragment.kt @@ -36,6 +36,7 @@ abstract class EnterOtpCodeFragment : WhyGoogleFragment