From 758fbaf2ec208c8c78fe804874b40d099ae29e53 Mon Sep 17 00:00:00 2001 From: Kelian CLERC Date: Thu, 8 Feb 2024 09:54:32 +0100 Subject: [PATCH 1/2] Remove view usage from sample --- .../main/res/layout/fragment_home_cards.xml | 46 +------------------ 1 file changed, 1 insertion(+), 45 deletions(-) diff --git a/sample/src/main/res/layout/fragment_home_cards.xml b/sample/src/main/res/layout/fragment_home_cards.xml index 68392f15..59b80122 100644 --- a/sample/src/main/res/layout/fragment_home_cards.xml +++ b/sample/src/main/res/layout/fragment_home_cards.xml @@ -208,50 +208,6 @@ app:layout_constraintTop_toBottomOf="@+id/homeCardSectionPlasticCardAlertSubtitle" /> - - - - - - - - - - - \ No newline at end of file + From c9bdbe7af6325bb84abbbdc980b56baba590058e Mon Sep 17 00:00:00 2001 From: Kelian CLERC Date: Thu, 8 Feb 2024 09:58:38 +0100 Subject: [PATCH 2/2] Remove legacy RegistrationCodeView and all resources --- .../spendesk/grapes/RegistrationCodeView.kt | 123 ------------------ .../res/layout/view_registration_code.xml | 80 ------------ library/src/main/res/values-hdpi/dimens.xml | 5 - library/src/main/res/values-v26/styles.xml | 19 --- library/src/main/res/values-xhdpi/dimens.xml | 5 - library/src/main/res/values/colors.xml | 8 -- library/src/main/res/values/dimens.xml | 14 -- library/src/main/res/values/styles.xml | 22 ---- 8 files changed, 276 deletions(-) delete mode 100644 library/src/main/java/com/spendesk/grapes/RegistrationCodeView.kt delete mode 100644 library/src/main/res/layout/view_registration_code.xml delete mode 100644 library/src/main/res/values-hdpi/dimens.xml delete mode 100644 library/src/main/res/values-v26/styles.xml delete mode 100644 library/src/main/res/values-xhdpi/dimens.xml diff --git a/library/src/main/java/com/spendesk/grapes/RegistrationCodeView.kt b/library/src/main/java/com/spendesk/grapes/RegistrationCodeView.kt deleted file mode 100644 index c2ce50be..00000000 --- a/library/src/main/java/com/spendesk/grapes/RegistrationCodeView.kt +++ /dev/null @@ -1,123 +0,0 @@ -package com.spendesk.grapes - -import android.content.Context -import android.text.InputFilter -import android.text.TextWatcher -import android.util.AttributeSet -import android.view.LayoutInflater -import android.widget.EditText -import androidx.cardview.widget.CardView -import androidx.core.content.ContextCompat -import androidx.core.widget.doAfterTextChanged -import com.spendesk.grapes.databinding.ViewRegistrationCodeBinding - -/** - * @author danyboucanova - * @since 3/8/21 - */ -class RegistrationCodeView : CardView { - - //region constructors - constructor(context: Context) : super(context) - constructor(context: Context, attributeSet: AttributeSet?) : super(context, attributeSet, 0) - constructor(context: Context, attributeSet: AttributeSet?, defStyleAttr: Int) : super(context, attributeSet, defStyleAttr) - //endregion constructors - - private lateinit var onFirstTextChanged: ((String) -> Unit) - private lateinit var onSecondTextChanged: ((String) -> Unit) - private lateinit var onThirdTextChanged: ((String) -> Unit) - private var activeListeners: Map = mapOf() - - private var maxCodeItemLength: Int = 0 - - data class Configuration( - val maxCodeItemLength: Int, - val firstTextWatcher: ((String) -> Unit), - val secondTextWatcher: ((String) -> Unit), - val thirdTextWatcher: ((String) -> Unit) - ) - - private val binding: ViewRegistrationCodeBinding = ViewRegistrationCodeBinding.inflate(LayoutInflater.from(context), this) - - init { - setupView() - } - - fun updateConfiguration(configuration: Configuration) { - maxCodeItemLength = configuration.maxCodeItemLength - - onFirstTextChanged = configuration.firstTextWatcher - onSecondTextChanged = configuration.secondTextWatcher - onThirdTextChanged = configuration.thirdTextWatcher - - limitTextLength() - bindView() - } - - fun clearText() { - listOf(binding.registrationCodeThirdText, binding.registrationCodeSecondText, binding.registrationCodeFirstText).forEach { it.text?.clear() } - } - - private fun setupView() { - setCardBackgroundColor(ContextCompat.getColor(context, R.color.registrationCodeViewBackground)) - radius = context.resources.getDimensionPixelOffset(R.dimen.registrationCodeViewCardRadius).toFloat() - elevation = context.resources.getDimensionPixelOffset(R.dimen.registrationCodeViewCardElevation).toFloat() - - setOnClickListener { - when { - binding.registrationCodeFirstText.text?.length in 0 until maxCodeItemLength -> binding.registrationCodeFirstText.requestFocus() - binding.registrationCodeSecondText.text?.length in 0 until maxCodeItemLength -> binding.registrationCodeSecondText.requestFocus() - binding.registrationCodeThirdText.text?.length in 0 until maxCodeItemLength -> binding.registrationCodeThirdText.requestFocus() - } - } - } - - private fun bindView() { - handleItem(binding.registrationCodeFirstText, onFirstTextChanged) { - when (it.length) { - maxCodeItemLength -> binding.registrationCodeSecondText.requestFocus() - else -> Unit // Nothing to do here - } - } - - handleItem(binding.registrationCodeSecondText, onSecondTextChanged) { - when (it.length) { - 0 -> binding.registrationCodeFirstText.requestFocus() - maxCodeItemLength -> binding.registrationCodeThirdText.requestFocus() - else -> Unit // Nothing to do here - } - - } - handleItem(binding.registrationCodeThirdText, onThirdTextChanged) { - when (it.length) { - 0 -> binding.registrationCodeSecondText.requestFocus() - else -> Unit // Nothing to do here - } - } - } - - private fun handleItem(registrationCodeItem: EditText, registrationCodeLambda: ((String) -> Unit)?, logicOnTextLength: ((String) -> Unit)) { - removeExistingListener(registrationCodeItem) - - val textWatcher = registrationCodeItem - .doAfterTextChanged { textEditable -> - val itemText = textEditable.toString() - - registrationCodeLambda - ?.invoke(itemText) - .also { logicOnTextLength(itemText) } - } - - activeListeners = activeListeners.plus(registrationCodeItem.id to textWatcher) - } - - private fun removeExistingListener(registrationCodeItem: EditText) { - activeListeners[registrationCodeItem.id]?.let { registrationCodeItem.removeTextChangedListener(it) } - } - - private fun limitTextLength() { - listOf(binding.registrationCodeFirstText, binding.registrationCodeSecondText, binding.registrationCodeThirdText).forEach { - it.filters = arrayOf(InputFilter.LengthFilter(maxCodeItemLength)) - } - } -} diff --git a/library/src/main/res/layout/view_registration_code.xml b/library/src/main/res/layout/view_registration_code.xml deleted file mode 100644 index 6becb0e4..00000000 --- a/library/src/main/res/layout/view_registration_code.xml +++ /dev/null @@ -1,80 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/library/src/main/res/values-hdpi/dimens.xml b/library/src/main/res/values-hdpi/dimens.xml deleted file mode 100644 index cc296ead..00000000 --- a/library/src/main/res/values-hdpi/dimens.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - 0.20 - 18sp - \ No newline at end of file diff --git a/library/src/main/res/values-v26/styles.xml b/library/src/main/res/values-v26/styles.xml deleted file mode 100644 index 1c58fbe8..00000000 --- a/library/src/main/res/values-v26/styles.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/library/src/main/res/values-xhdpi/dimens.xml b/library/src/main/res/values-xhdpi/dimens.xml deleted file mode 100644 index 2af48524..00000000 --- a/library/src/main/res/values-xhdpi/dimens.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - 0.25 - 20sp - \ No newline at end of file diff --git a/library/src/main/res/values/colors.xml b/library/src/main/res/values/colors.xml index 45156937..d3d9e327 100644 --- a/library/src/main/res/values/colors.xml +++ b/library/src/main/res/values/colors.xml @@ -136,14 +136,6 @@ @color/mainWhite - - - @color/colorPrimaryDark - @color/mainWhite - @color/mainWhite - - - @color/mainWhite diff --git a/library/src/main/res/values/dimens.xml b/library/src/main/res/values/dimens.xml index bd4c7722..54191096 100644 --- a/library/src/main/res/values/dimens.xml +++ b/library/src/main/res/values/dimens.xml @@ -88,20 +88,6 @@ - - - 56dp - 12dp - 0dp - 0.35 - 24sp - - 8dp - 2dp - 8dp - - - 16dp diff --git a/library/src/main/res/values/styles.xml b/library/src/main/res/values/styles.xml index 6df08302..aa563a88 100644 --- a/library/src/main/res/values/styles.xml +++ b/library/src/main/res/values/styles.xml @@ -230,28 +230,6 @@ - - - - - - - -