Skip to content

Commit

Permalink
add attribute to add icon enable
Browse files Browse the repository at this point in the history
  • Loading branch information
yasemin.aksoy committed Jan 31, 2022
1 parent e19985f commit cf73c79
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
2 changes: 2 additions & 0 deletions libraries/quantity-picker-view/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ 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. |
| 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,13 +103,15 @@ class QuantityPickerView : ConstraintLayout {
imageAdd.setOnClickListener {
if (viewState?.isLoading() == true) return@setOnClickListener

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

Expand Down Expand Up @@ -248,6 +250,7 @@ class QuantityPickerView : ConstraintLayout {
)
val quantityTextStyle =
it.getInt(R.styleable.QuantityPickerView_qpv_quantityTextStyle, 0)
val addButtonEnabled = it.getBoolean(R.styleable.QuantityPickerView_qpv_addButtonEnabled, true)
val currentQuantity = it.getInt(R.styleable.QuantityPickerView_qpv_currentQuantity, 0)
val maxQuantity = it.getInt(R.styleable.QuantityPickerView_qpv_maxQuantity, -1)
val minQuantity = it.getInt(R.styleable.QuantityPickerView_qpv_minQuantity, -1)
Expand Down Expand Up @@ -314,6 +317,7 @@ class QuantityPickerView : ConstraintLayout {
quantityTextColor = quantityTextColor,
quantityTextSize = quantityTextSize,
quantityTextStyle = quantityTextStyle,
addButtonEnabled = addButtonEnabled,
currentQuantity = currentQuantity,
backgroundDrawable = background,
progressTintColor = progressTintColor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ 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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<enum name="bold" value="1" />
<enum name="italic" value="2" />
</attr>
<attr name="qpv_addButtonEnabled" format="boolean" />
<attr name="qpv_currentQuantity" format="integer" />
<attr name="qpv_maxQuantity" format="integer" />
<attr name="qpv_minQuantity" format="integer" />
Expand Down

0 comments on commit cf73c79

Please sign in to comment.