Skip to content

Commit

Permalink
remove unnecessary setters for add icon and add icon enable
Browse files Browse the repository at this point in the history
  • Loading branch information
yasemin.aksoy committed Feb 1, 2022
1 parent 540a0e8 commit 314ccef
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 31 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/ComponentVersions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ object ComponentVersions {
const val phoneNumberVersion = "1.0.2"
const val dialogsVersion = "1.2.8"
const val cardInputViewVersion = "1.1.3"
const val quantityPickerViewVersion = "1.2.7"
const val quantityPickerViewVersion = "1.2.8"
const val timelineViewVersion = "1.0.0"
const val touchDelegatorVersion = "1.0.0"
const val fitOptionMessageView = "1.0.0"
Expand Down
2 changes: 0 additions & 2 deletions libraries/quantity-picker-view/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ To set programmatically, you can call `QuantityPickerView.setQuantityPickerViewS
| setQuantity | quantity: Int | To set quantity immediately. |
| setMaxQuantity | maxQuantity: Int | To set maxQuantity immediately. |
| setMinQuantity | minQuantity: Int | To set minQuantity immediately. |
| setAddIconDrawable | icon: Drawable | To set addIconDrawable immediately. |
| setBackgroundImageDrawable | background: Drawable | To set backgroundImageDrawable immediately. |
| setAddButtonEnabled | enable: Boolean | To set enable to addButton immediately |
| stopLoading | | To stop current loading.|
| reset | | To stop loading and set currentQuantity to 0. |
| incrementQuantityBy | quantity | increments current total quantity by quantity parameter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,13 @@ class QuantityPickerView : ConstraintLayout {
imageAdd.setOnClickListener {
if (viewState?.isLoading() == true) return@setOnClickListener

if (viewState?.addButtonEnabled == true) {
setQuantityPickerViewState(
if (onAddClicked?.invoke(viewState?.currentQuantity ?: 0) == true) {
viewState?.getWithLoading()
} else {
viewState?.getWithAddValue()
}
)
}
setQuantityPickerViewState(
if (onAddClicked?.invoke(viewState?.currentQuantity ?: 0) == true) {
viewState?.getWithLoading()
} else {
viewState?.getWithAddValue()
}
)
}
}

Expand Down Expand Up @@ -169,16 +167,8 @@ class QuantityPickerView : ConstraintLayout {
fun setMinQuantity(minQuantity: Int) =
setQuantityPickerViewState(binding.viewState?.getWithMinQuantity(minQuantity))

fun setAddIconDrawable(icon: Drawable) {
setQuantityPickerViewState(binding.viewState?.getIconAddDrawable(icon))
}

fun setBackgroundImageDrawable(background: Drawable){
setQuantityPickerViewState(binding.viewState?.getBackgroundDrawable(background))
}

fun setAddButtonEnabled(enable: Boolean) {
setQuantityPickerViewState(binding.viewState?.getAddButtonEnabled(enable))
setQuantityPickerViewState(binding.viewState?.getWithBackgroundDrawable(background))
}

fun stopLoading() = setQuantityPickerViewState(binding.viewState?.stopLoading())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ data class QuantityPickerViewState(
@ColorInt private val quantityTextColor: Int,
private val quantityTextSize: Int,
private val quantityTextStyle: Int = 0,
val addButtonEnabled: Boolean = true,
val currentQuantity: Int = 0,
val backgroundDrawable: Drawable,
@ColorInt val progressTintColor: Int,
Expand Down Expand Up @@ -159,18 +158,10 @@ data class QuantityPickerViewState(
return copy(minQuantity = minQuantity, showLoading = false)
}

internal fun getIconAddDrawable(icon: Drawable): QuantityPickerViewState {
return copy(addIconDrawable = icon)
}

internal fun getBackgroundDrawable(background: Drawable): QuantityPickerViewState {
internal fun getWithBackgroundDrawable(background: Drawable): QuantityPickerViewState {
return copy(backgroundDrawable = background)
}

internal fun getAddButtonEnabled(enable: Boolean): QuantityPickerViewState {
return copy(addButtonEnabled = enable)
}

internal fun stopLoading(): QuantityPickerViewState =
copy(showLoading = false, expansionState = expansionState.expand())

Expand Down

0 comments on commit 314ccef

Please sign in to comment.