Skip to content

Commit

Permalink
- Input component bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
samanshah committed May 18, 2024
1 parent 429221c commit 94b70ba
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 32 deletions.
2 changes: 1 addition & 1 deletion PishkhanHelper/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ afterEvaluate {
artifactId = 'pishkhanhelper'

// Version Library Name (Example : "1.0.0")
version = '0.2.0'
version = '0.2.1'
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,50 @@ 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,
@ColorRes backgroundTint: Int? = null,
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)
}
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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()
}
}
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ abstract class EnterOtpCodeFragment : WhyGoogleFragment<FragmentEnterOtpCodeBind

private fun initViews() {
accessViews {
otpCodeInput
otpCodeInput.initOtpCodeInputComponent(
activity = requireActivity(),
doAfterFilled = { hasFilled ->
Expand Down

0 comments on commit 94b70ba

Please sign in to comment.