-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add subtract remove icons moved to QuantityIcons
- Loading branch information
burak.ozturk1
committed
Sep 17, 2024
1 parent
309ffbc
commit 2092918
Showing
11 changed files
with
137 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 6 additions & 9 deletions
15
...-picker-compose/src/main/java/com/trendyol/uicomponents/quantitypicker/QuantityAddIcon.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,31 @@ | ||
package com.trendyol.uicomponents.quantitypicker | ||
|
||
import androidx.annotation.DrawableRes | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.interaction.MutableInteractionSource | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.Icon | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.unit.dp | ||
|
||
@Composable | ||
internal fun QuantityAddIcon( | ||
@DrawableRes addIconResId: Int, | ||
iconTintColor: Color, | ||
showLoading: Boolean, | ||
icons: QuantityIcons, | ||
quantityData: QuantityPickerViewData, | ||
onAddClick: (() -> Unit)? | ||
) { | ||
Icon( | ||
painter = painterResource(id = addIconResId), | ||
painter = painterResource(id = icons.addIconResId), | ||
tint = quantityData.getAddIconColor(icons.iconColor, icons.disabledColor), | ||
contentDescription = null, | ||
modifier = Modifier | ||
.clickable( | ||
enabled = showLoading.not(), | ||
enabled = quantityData.isAddButtonEnabled(), | ||
onClick = { onAddClick?.invoke() }, | ||
interactionSource = MutableInteractionSource(), | ||
indication = null, | ||
) | ||
.padding(8.dp), | ||
tint = iconTintColor | ||
.padding(8.dp) | ||
) | ||
} |
7 changes: 0 additions & 7 deletions
7
...ity-picker-compose/src/main/java/com/trendyol/uicomponents/quantitypicker/QuantityData.kt
This file was deleted.
Oops, something went wrong.
25 changes: 25 additions & 0 deletions
25
...ty-picker-compose/src/main/java/com/trendyol/uicomponents/quantitypicker/QuantityIcons.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.trendyol.uicomponents.quantitypicker | ||
|
||
import androidx.annotation.DrawableRes | ||
import androidx.compose.ui.graphics.Color | ||
import com.trendyol.quantitypickercompose.R | ||
|
||
data class QuantityIcons( | ||
@DrawableRes val addIconResId: Int = R.drawable.ic_plus, | ||
@DrawableRes val subtractIconResId: Int = R.drawable.ic_subtract, | ||
@DrawableRes val removeIconResId: Int? = R.drawable.ic_trash, | ||
val iconColor: Color, | ||
val disabledColor: Color, | ||
) { | ||
companion object { | ||
val default = QuantityIcons( | ||
addIconResId = R.drawable.ic_plus, | ||
subtractIconResId = R.drawable.ic_subtract, | ||
removeIconResId = R.drawable.ic_trash, | ||
iconColor = QuantityPickerDefaults.defaultColor, | ||
disabledColor = QuantityPickerDefaults.disabledColor | ||
) | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...-compose/src/main/java/com/trendyol/uicomponents/quantitypicker/QuantityPickerViewData.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.trendyol.uicomponents.quantitypicker | ||
|
||
import androidx.compose.ui.graphics.Color | ||
|
||
data class QuantityPickerViewData( | ||
val minQuantity: Int = -1, | ||
val maxQuantity: Int = -1, | ||
val currentQuantity: Int = 0 | ||
) { | ||
fun isAddButtonEnabled(): Boolean { | ||
return (isMaxQuantitySet() && currentQuantity >= maxQuantity).not() | ||
} | ||
|
||
private fun isMaxQuantitySet(): Boolean { | ||
return maxQuantity != -1 | ||
} | ||
|
||
fun getAddIconColor(iconTintColor: Color, disableTintColor: Color): Color { | ||
return if (isAddButtonEnabled()) iconTintColor else disableTintColor | ||
} | ||
|
||
fun isSubtractButtonEnabled(): Boolean { | ||
return (currentQuantity > minQuantity) | ||
} | ||
|
||
fun getSubtractButtonColor(iconTintColor: Color, disableTintColor: Color): Color { | ||
return if (isSubtractButtonEnabled()) iconTintColor else disableTintColor | ||
} | ||
} |
Oops, something went wrong.