Skip to content

Commit

Permalink
Merge pull request #129 from Trendyol/feature/quantityPickerCompose
Browse files Browse the repository at this point in the history
Feature/quantity picker compose
  • Loading branch information
burakztrk authored Sep 25, 2024
2 parents 9f021d5 + 2092918 commit 57e3e5e
Show file tree
Hide file tree
Showing 29 changed files with 986 additions and 17 deletions.
34 changes: 20 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,41 @@ UI Components includes several custom views for Android platform to make develop
<img src="images/uic3.png" width="240"/> <img src="images/uic4.png" width="240"/>
<img src="images/uic5.png" width="240"/> <img src="images/timeline-view.png" width="240"/>
<img src="images/suggestion-input-view-1.gif" width="240"/> <img src="images/quantity-picker-view-1.gif" width="240"/>
<img src="images/fitoptionmessageview.png" width="240"/>
<img src="images/quantity-picker-compose.gif" width="240"/>
<img src="images/fitoptionmessageview.png" width="240"/>

## Why?

## Why? ##
[Trendyol](https://play.google.com/store/apps/details?id=trendyol.com) Android application, we are using several custom view implementations that can be useful for other apps.

## Components ##
## Components

* [Rating Bar](libraries/rating-bar): **RatingBarView**, easy to use and customizable rating view.
* [Rating Bar Compose](libraries/rating-bar-compose): **RatingBar**, easy to use and customizable ratingBar for compose.
* [Dialogs](libraries/dialogs): **Dialogs** is collection of BottomSheetDialogs to present user an info, agreement or list.
* [Toolbar](libraries/toolbar): **Toolbar** is customizable and easy to use component.
* [SuggestionInputView](libraries/suggestion-input-view): **SuggestionInputView** allows selecting pre-selected options or entering a custom option.
* [CardInputView](libraries/card-input-view): **CardInputView** for get debit/credit card inputs and validations.
* [QuantityPickerView](libraries/quantity-picker-view): **QuantityPickerView** for picking quantity easily without keyboard input.
* [QuantityPickerCompose](libraries/quantity-picker-compose): **QuantityPickerView** for picking quantity easily without keyboard input.
* [TimelineView](libraries/timeline-view): **TimelineView** for creating a timeline and show actions on it.
* [TimelineViewCompose](libraries/timeline-view-compose): **TimelineView** for creating a timeline for compose and show actions on it.
* [FitOptionMessage](libraries/fit-option-message-view): **FitOptionMessageView** for displaying text views with clipped imageviews.

License
--------
Copyright 2022 Trendyol.com
-------

Copyright 2022 Trendyol.com

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0

http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Binary file added images/quantity-picker-compose.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions libraries/quantity-picker-compose/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
100 changes: 100 additions & 0 deletions libraries/quantity-picker-compose/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
quantityPickerComposeVersion= **quantity-picker-compose-1.0.1** [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

## QuantityPicker

QuantityPicker is compose component to add/remove anything

<img src="../../images/quantity-picker-compose.gif" width="240"/>

## Installation

- To implement **QuantityPicker** to your Android project via Gradle, you need to add JitPack repository to your root/project level build.gradle.

```gradle
allprojects {
repositories { ... maven { url 'https://jitpack.io' } }
}
```

- After adding JitPack repository, you can add **QuantityPicker** dependency to your app/module level build.gradle.

```gradle
dependencies {
implementation "com.github.Trendyol.android-ui-components:quantity-picker-compose:$quantityPickerComposeVersion"
}
```

## Usage

You can add **QuantityPicker** wherever you want with your modifier


| Attribute | Type | Description |
| ------------------- | ----------------------- | ------------------------------------------------------------ |
| modifier | Modifier | Compose modifier for QuantityPicker |
| direction | QuantityPickerDirection | Picker Direction Vertical or Horizontal |
| icons | QuantityIcons | Drawables for add subtract remove and colors |
| quantityTextShape | QuantityPickerShape | Compose shape for quantity text. |
| quantityPickerShape | QuantityPickerShape | Background of all view also defines border if it is not null |
| textStyle | TextStyle | Text style for quantity text |
| quantityData | QuantityData | Quantity values. It has min,max,current and postfix |
| showLoading | Boolean | Loading state |
| progressColor | Color | Color for loading progress indicator |
| onAddClick | (() -> Unit) | Listener for add button clicks |
| onSubtractClick | (() -> Unit) | Listener for subtract clicks |

## Implementation

If you don't need any customization

```kotlin
QuantityPicker(
modifier = modifier,
quantityData = quantityData,
showLoading = isLoading,
onAddClick = { },
onSubtractClick = { }
)
```

If you need background or custom modifier for quantity text and all view

```kotlin
QuantityPicker(
textStyle = Typography.body2,
quantityData = quantityData,
icons: QuantityIcons = QuantityIcons( // QuantityIcons.default
addIconResId = R.drawable.ic_plus,
subtractIconResId = R.drawable.ic_subtract,
removeIconResId = R.drawable.ic_trash,
iconColor = QuantityPickerDefaults.defaultColor,
disabledColor = QuantityPickerDefaults.disabledColor
),
quantityPickerShape = QuantityPickerShape( // QuantityPickerDefaults.quantityShape,
shape = RoundedCornerShape(50),
borderColor = MyQuantityPickerPrimaryColor,
borderWidth = 1.dp
),
quantityTextShape = QuantityPickerShape( // QuantityPickerDefaults.quantityTextShape
shape = RoundedCornerShape(50),
borderColor = MyQuantityPickerPrimaryColor,
borderWidth = 1.dp
),
showLoading = isLoading,
progressColor = MyQuantityPickerPrimaryColor, // QuantityPickerDefaults.defaultColor
onAddClick = { },
onSubtractClick = { }
)
```

# Contributors

This library is maintained mainly by Trendyol Android Team members but also other Android lovers contributes.

# License

```
Copyright 2023 Trendyol.com Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
```
48 changes: 48 additions & 0 deletions libraries/quantity-picker-compose/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
plugins {
id(Plugins.androidLibrary)
id(Plugins.kotlinAndroid)
id(Plugins.mavenPublish)
id(Plugins.compose) version "2.0.0"
}

kotlin.jvmToolchain(17)

android {
namespace = "com.trendyol.quantitypickercompose"
compileSdk = 33

defaultConfig {
minSdk = Configs.minSdkVersion
vectorDrawables.useSupportLibrary = true
}

buildTypes {
getByName<com.android.build.gradle.internal.dsl.BuildType>("release") {
isMinifyEnabled = false
setProguardFiles(
mutableListOf(
getDefaultProguardFile("proguard-android.txt"),
"proguard-rules.pro"
)
)
}
}
buildFeatures {
compose = true
}

composeOptions {
kotlinCompilerExtensionVersion = Dependencies.kotlinCompilerExtensionVersion
}
}

dependencies {

val composeBom = platform(Dependencies.composeBom)
implementation(composeBom)
implementation(Dependencies.composeMaterial)
implementation(Dependencies.composeUiTooling)
implementation(Dependencies.composeCoil)
implementation(Dependencies.composeRuntime)
implementation(Dependencies.composeConstraintLayout)
}
Empty file.
21 changes: 21 additions & 0 deletions libraries/quantity-picker-compose/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.trendyol.uicomponents.quantitypicker

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.res.painterResource
import androidx.compose.ui.unit.dp

@Composable
internal fun QuantityAddIcon(
icons: QuantityIcons,
quantityData: QuantityPickerViewData,
onAddClick: (() -> Unit)?
) {
Icon(
painter = painterResource(id = icons.addIconResId),
tint = quantityData.getAddIconColor(icons.iconColor, icons.disabledColor),
contentDescription = null,
modifier = Modifier
.clickable(
enabled = quantityData.isAddButtonEnabled(),
onClick = { onAddClick?.invoke() },
interactionSource = MutableInteractionSource(),
indication = null,
)
.padding(8.dp)
)
}
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
)
}
}


Loading

0 comments on commit 57e3e5e

Please sign in to comment.