From 19b7a1f645963c044c5db3cc412292733bd5d810 Mon Sep 17 00:00:00 2001 From: Purvesh Dodiya <75968935+purvesh-d@users.noreply.github.com> Date: Wed, 20 Mar 2024 11:36:13 +0530 Subject: [PATCH] Develop to main (#54) * :racehorse: UNT-13932 Disabled button click when it's in loading state * :racehorse: #38 Added shouldAutoMoveToIdleState parameter. * :zap: Dependency version updated. * :zap: jitpack yml updated * Readme updated --------- --- README.md | 5 +- app/build.gradle | 18 +++---- .../MainActivity.kt | 29 +++++----- build.gradle | 8 +-- gradle/wrapper/gradle-wrapper.properties | 2 +- jitpack.yml | 5 +- ssjetpackcomposeprogressbutton/build.gradle | 14 ++--- .../SSJetPackComposeProgressButton.kt | 53 +++++++++++-------- 8 files changed, 74 insertions(+), 60 deletions(-) diff --git a/README.md b/README.md index 4ccbdce..7685eac 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ # SSJetPackComposeProgressButton ### _SSJetPackComposeProgressButton is an elegant button with a different loading animations which makes your app attractive._ -[![Build Status](https://travis-ci.org/joemccann/dillinger.svg?branch=master)][git-repo-url] [![](https://jitpack.io/v/SimformSolutionsPvtLtd/SSJetPackComposeProgressButton.svg)](https://jitpack.io/#SimformSolutionsPvtLtd/SSJetPackComposeProgressButton) [![Kotlin Version](https://img.shields.io/badge/Kotlin-v1.5.10-blue.svg)](https://kotlinlang.org) [![Platform](https://img.shields.io/badge/Platform-Android-green.svg?style=flat)](https://www.android.com/) [![API](https://img.shields.io/badge/API-21%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=21) [![Android Arsenal]( https://img.shields.io/badge/Android%20Arsenal-SSJetPackComposeProgressButton-green.svg?style=flat )]( https://android-arsenal.com/details/1/8302 ) +[![CI Status](https://img.shields.io/github/v/release/SimformSolutionsPvtLtd/SSJetPackComposeProgressButton?style=flat)](https://travis-ci.org/SimformSolutionsPvtLtd/SSJetPackComposeProgressButton) [![](https://jitpack.io/v/SimformSolutionsPvtLtd/SSJetPackComposeProgressButton.svg)](https://jitpack.io/#SimformSolutionsPvtLtd/SSJetPackComposeProgressButton) [![Kotlin Version](https://img.shields.io/badge/Kotlin-v1.5.10-blue.svg)](https://kotlinlang.org) [![Platform](https://img.shields.io/badge/Platform-Android-green.svg?style=flat)](https://www.android.com/) [![API](https://img.shields.io/badge/API-21%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=21) [![Android Arsenal]( https://img.shields.io/badge/Android%20Arsenal-SSJetPackComposeProgressButton-green.svg?style=flat )]( https://android-arsenal.com/details/1/8302 ) # Jetpack Compose Jetpack Compose is Android’s modern toolkit for building native UI. It simplifies and accelerates UI development on Android. Quickly bring your app to life with less code, powerful tools, and intuitive Kotlin APIs. @@ -48,7 +48,7 @@ Please get **Android Studio Arctic Fox 2020.3.1** or above [from here](https://d ```groovy dependencies { - implementation 'com.github.SimformSolutionsPvtLtd:SSJetPackComposeProgressButton:1.0.7' + implementation 'com.github.SimformSolutionsPvtLtd:SSJetPackComposeProgressButton:1.0.8' } ``` @@ -155,6 +155,7 @@ Please get **Android Studio Arctic Fox 2020.3.1** or above [from here](https://d | `customLoadingIconPainter` | painter [Painter] to draw your custom loading icon. | `painterResource(id = R.drawable.simform_logo)` | | `customLoadingEffect` | Custom loading animation type like roation, zoom in out etc. | `SSCustomLoadingEffect( rotation = false, zoomInOut = false, colorChanger = false)` | | `customLoadingPadding` | Spacing between button border and loading icon. | `0` | +| `shouldAutoMoveToIdleState` | In case of success/failure state after defined time it move back to idle state. | `true` | ## Our JetPackCompose Sample [SSComposeCookBook](https://github.com/SimformSolutionsPvtLtd/SSComposeCookBook) : A Collection of major Jetpack compose UI components which are commonly used. diff --git a/app/build.gradle b/app/build.gradle index 10783a5..da9ef84 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -4,12 +4,12 @@ plugins { } android { - compileSdk 33 + compileSdk 34 defaultConfig { applicationId "com.simform.ssjetpackcomposeprogressbutton" minSdk 21 - targetSdk 33 + targetSdk 34 versionCode 2 versionName "1.0.7" @@ -26,11 +26,11 @@ android { } } compileOptions { - sourceCompatibility JavaVersion.VERSION_11 - targetCompatibility JavaVersion.VERSION_11 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } kotlinOptions { - jvmTarget = '11' + jvmTarget = '17' } buildFeatures { compose true @@ -41,11 +41,11 @@ android { } dependencies { - implementation 'androidx.appcompat:appcompat:1.6.0-rc01' - implementation 'com.google.android.material:material:1.6.1' - implementation "androidx.compose.ui:ui:1.2.1" + implementation 'androidx.appcompat:appcompat:1.6.1' + implementation 'com.google.android.material:material:1.11.0' + implementation "androidx.compose.ui:ui:1.5.4" implementation "androidx.compose.material:material:$compose_version" implementation "androidx.compose.ui:ui-tooling:$compose_version" - implementation 'androidx.activity:activity-compose:1.5.1' + implementation 'androidx.activity:activity-compose:1.8.2' implementation project(path: ':ssjetpackcomposeprogressbutton') } \ No newline at end of file diff --git a/app/src/main/java/com/simform/ssjetpackcomposeprogressbutton/MainActivity.kt b/app/src/main/java/com/simform/ssjetpackcomposeprogressbutton/MainActivity.kt index a73c997..0ae3c82 100644 --- a/app/src/main/java/com/simform/ssjetpackcomposeprogressbutton/MainActivity.kt +++ b/app/src/main/java/com/simform/ssjetpackcomposeprogressbutton/MainActivity.kt @@ -165,7 +165,7 @@ fun SSLoadingButtonExample() { item { SSJetPackComposeProgressButton( assetColor = colorResource(id = R.color.pink), - colors = ButtonDefaults.buttonColors(backgroundColor = Color.White), + colors = ButtonDefaults.buttonColors(backgroundColor = Color.White, disabledBackgroundColor = Color.White), buttonBorderStroke = BorderStroke(COMMON_BORDER_WIDTH.dp, SolidColor(colorResource(id = R.color.pink))), type = SSButtonType.CIRCLE, onClick = { roundedProgressState2 = SSButtonState.LOADING }, @@ -174,11 +174,12 @@ fun SSLoadingButtonExample() { height = COMMON_HEIGHT.dp, padding = PaddingValues(TWELVE.dp), cornerRadius = COMMON_CORNER_RADIUS, - leftImagePainter = rememberVectorPainter(image = Icons.Default.Home) + leftImagePainter = rememberVectorPainter(image = Icons.Default.Home), + shouldAutoMoveToIdleState = false ) SSJetPackComposeProgressButton( assetColor = colorResource(id = R.color.pink), - colors = ButtonDefaults.buttonColors(backgroundColor = Color.White), + colors = ButtonDefaults.buttonColors(backgroundColor = Color.White, disabledBackgroundColor = Color.White), buttonBorderStroke = BorderStroke( COMMON_BORDER_WIDTH.dp, SolidColor(colorResource(id = R.color.pink)) @@ -194,7 +195,7 @@ fun SSLoadingButtonExample() { ) SSJetPackComposeProgressButton( assetColor = colorResource(id = R.color.pink), - colors = ButtonDefaults.buttonColors(backgroundColor = Color.White), + colors = ButtonDefaults.buttonColors(backgroundColor = Color.White, disabledBackgroundColor = Color.White), buttonBorderStroke = BorderStroke(COMMON_BORDER_WIDTH.dp, SolidColor(colorResource(id = R.color.pink))), type = SSButtonType.ZOOM_IN_OUT_CIRCLE, onClick = { zoomInOutState = SSButtonState.LOADING }, @@ -207,7 +208,7 @@ fun SSLoadingButtonExample() { ) SSJetPackComposeProgressButton( assetColor = colorResource(id = R.color.pink), - colors = ButtonDefaults.buttonColors(backgroundColor = Color.White), + colors = ButtonDefaults.buttonColors(backgroundColor = Color.White, disabledBackgroundColor = Color.White), buttonBorderStroke = BorderStroke(COMMON_BORDER_WIDTH.dp, SolidColor(colorResource(id = R.color.pink))), type = SSButtonType.CLOCK, onClick = { clockState = SSButtonState.LOADING }, @@ -220,7 +221,7 @@ fun SSLoadingButtonExample() { ) SSJetPackComposeProgressButton( assetColor = colorResource(id = R.color.pink), - colors = ButtonDefaults.buttonColors(backgroundColor = Color.White), + colors = ButtonDefaults.buttonColors(backgroundColor = Color.White, disabledBackgroundColor = Color.White), buttonBorderStroke = BorderStroke(COMMON_BORDER_WIDTH.dp, SolidColor(colorResource(id = R.color.pink))), type = SSButtonType.SPIRAL, onClick = { spiralState = SSButtonState.LOADING }, @@ -233,7 +234,7 @@ fun SSLoadingButtonExample() { ) SSJetPackComposeProgressButton( assetColor = Color.White, - colors = ButtonDefaults.buttonColors(backgroundColor = colorResource(id = R.color.pink)), + colors = ButtonDefaults.buttonColors(backgroundColor = colorResource(id = R.color.pink), disabledBackgroundColor = colorResource(id = R.color.pink)), type = SSButtonType.CIRCLE, onClick = { roundedProgressState = SSButtonState.LOADING }, buttonState = roundedProgressState, @@ -254,12 +255,12 @@ fun SSLoadingButtonExample() { leftImagePainter = rememberVectorPainter(image = Icons.Default.FavoriteBorder), padding = PaddingValues(TWELVE.dp), cornerRadius = COMMON_CORNER_RADIUS, - colors = ButtonDefaults.buttonColors(backgroundColor = colorResource(id = R.color.pink)), + colors = ButtonDefaults.buttonColors(backgroundColor = colorResource(id = R.color.pink), disabledBackgroundColor = colorResource(id = R.color.pink)), hourHandColor = colorResource(id = R.color.handColor) ) SSJetPackComposeProgressButton( assetColor = Color.White, - colors = ButtonDefaults.buttonColors(backgroundColor = colorResource(id = R.color.pink)), + colors = ButtonDefaults.buttonColors(backgroundColor = colorResource(id = R.color.pink), disabledBackgroundColor = colorResource(id = R.color.pink)), type = SSButtonType.ZOOM_IN_OUT_CIRCLE, onClick = { ssTextButtonState = SSButtonState.LOADING }, buttonState = ssTextButtonState, @@ -290,7 +291,7 @@ fun SSLoadingButtonExample() { blinkingIcon = true, padding = PaddingValues(TWELVE.dp), cornerRadius = COMMON_CORNER_RADIUS, - colors = ButtonDefaults.buttonColors(backgroundColor = colorResource(id = R.color.pink)) + colors = ButtonDefaults.buttonColors(backgroundColor = colorResource(id = R.color.pink), disabledBackgroundColor = colorResource(id = R.color.pink)) ) SSJetPackComposeProgressButton( assetColor = Color.White, @@ -307,7 +308,7 @@ fun SSLoadingButtonExample() { fontWeight = FontWeight.Bold, padding = PaddingValues(TWELVE.dp), cornerRadius = COMMON_CORNER_RADIUS, - colors = ButtonDefaults.buttonColors(backgroundColor = colorResource(id = R.color.pink)) + colors = ButtonDefaults.buttonColors(backgroundColor = colorResource(id = R.color.pink), disabledBackgroundColor = colorResource(id = R.color.pink)) ) Spacer(modifier = Modifier.size(COMMON_HEIGHT.dp)) SSJetPackComposeProgressButton( @@ -324,7 +325,7 @@ fun SSLoadingButtonExample() { zoomInOut = false, colorChanger = false ), - colors = ButtonDefaults.buttonColors(backgroundColor = Color.White), + colors = ButtonDefaults.buttonColors(backgroundColor = Color.White, disabledBackgroundColor = Color.White), padding = PaddingValues(TWELVE.dp), cornerRadius = COMMON_CORNER_RADIUS, text = stringResource(id = R.string.simform), @@ -348,7 +349,7 @@ fun SSLoadingButtonExample() { zoomInOut = true, colorChanger = false ), - colors = ButtonDefaults.buttonColors(backgroundColor = Color.White), + colors = ButtonDefaults.buttonColors(backgroundColor = Color.White, disabledBackgroundColor = Color.White), padding = PaddingValues(TWELVE.dp), cornerRadius = COMMON_CORNER_RADIUS, text = stringResource(id = R.string.simform), @@ -372,7 +373,7 @@ fun SSLoadingButtonExample() { zoomInOut = false, colorChanger = true ), - colors = ButtonDefaults.buttonColors(backgroundColor = Color.White), + colors = ButtonDefaults.buttonColors(backgroundColor = Color.White, disabledBackgroundColor = Color.White), padding = PaddingValues(ten.dp), cornerRadius = COMMON_CORNER_RADIUS, text = stringResource(id = R.string.simform), diff --git a/build.gradle b/build.gradle index b7a51f6..22685da 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ buildscript { ext { - compose_version = '1.2.1' + compose_version = '1.5.4' compose_compiler = '1.3.1' } repositories { @@ -8,16 +8,16 @@ buildscript { mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:7.2.2' + classpath 'com.android.tools.build:gradle:7.4.2' classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10' } configurations { - all { + configureEach { exclude group: 'androidx.lifecycle', module: 'lifecycle-viewmodel-ktx' } } } -task clean(type: Delete) { +tasks.register('clean', Delete) { delete rootProject.buildDir } \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e70a5f4..2e42103 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Thu May 06 09:44:53 IST 2021 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/jitpack.yml b/jitpack.yml index 46c8529..80847d7 100644 --- a/jitpack.yml +++ b/jitpack.yml @@ -1,2 +1,5 @@ jdk: - - openjdk11 \ No newline at end of file + - openjdk17 +before_install: + - sdk install java 17.0.3-tem + - sdk use java 17.0.3-tem diff --git a/ssjetpackcomposeprogressbutton/build.gradle b/ssjetpackcomposeprogressbutton/build.gradle index deb1aab..45d2a1e 100644 --- a/ssjetpackcomposeprogressbutton/build.gradle +++ b/ssjetpackcomposeprogressbutton/build.gradle @@ -19,11 +19,11 @@ afterEvaluate { } android { - compileSdk 33 + compileSdk 34 defaultConfig { minSdk 21 - targetSdk 33 + targetSdk 34 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" consumerProguardFiles "consumer-rules.pro" @@ -37,12 +37,12 @@ android { } compileOptions { - sourceCompatibility JavaVersion.VERSION_11 - targetCompatibility JavaVersion.VERSION_11 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } kotlinOptions { - jvmTarget = '11' + jvmTarget = '17' } buildFeatures { @@ -58,8 +58,8 @@ android { dependencies { testImplementation 'junit:junit:4.13.2' - androidTestImplementation 'androidx.test.ext:junit:1.1.3' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' + androidTestImplementation 'androidx.test.ext:junit:1.1.5' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' implementation "androidx.compose.ui:ui:$compose_version" implementation "androidx.compose.material:material:$compose_version" } \ No newline at end of file diff --git a/ssjetpackcomposeprogressbutton/src/main/java/com/simform/ssjetpackcomposeprogressbuttonlibrary/SSJetPackComposeProgressButton.kt b/ssjetpackcomposeprogressbutton/src/main/java/com/simform/ssjetpackcomposeprogressbuttonlibrary/SSJetPackComposeProgressButton.kt index d0fddbb..0e6e1f2 100644 --- a/ssjetpackcomposeprogressbutton/src/main/java/com/simform/ssjetpackcomposeprogressbuttonlibrary/SSJetPackComposeProgressButton.kt +++ b/ssjetpackcomposeprogressbutton/src/main/java/com/simform/ssjetpackcomposeprogressbuttonlibrary/SSJetPackComposeProgressButton.kt @@ -86,6 +86,7 @@ import kotlinx.coroutines.delay * @param customLoadingIconPainter painter [Painter] to draw your custom loading icon. * @param customLoadingEffect custom loading animation type. * @param customLoadingPadding spacing between button border and loading icon. + * @param shouldAutoMoveToIdleState In case of success/failure state after defined time it move back to idle state */ @Composable @@ -124,7 +125,8 @@ fun SSJetPackComposeProgressButton( zoomInOut = false, colorChanger = false ), - customLoadingPadding: Int = ZERO + customLoadingPadding: Int = ZERO, + shouldAutoMoveToIdleState: Boolean = true ) { var buttonWidth by remember { mutableStateOf(width) } var buttonHeight by remember { mutableStateOf(height) } @@ -175,17 +177,20 @@ fun SSJetPackComposeProgressButton( successIconAlphaValue = oneFloat progressAlphaValue = zeroFloat cornerRadiusValue = fifty - //Delay to show success icon and then IDLE state - delay((speedMillis * two).toLong()) - if (height > width) { - buttonHeight = height - } else { - buttonWidth = width + + if (shouldAutoMoveToIdleState) { + //Delay to show success icon and then IDLE state + delay((speedMillis * two).toLong()) + if (height > width) { + buttonHeight = height + } else { + buttonWidth = width + } + iconAlphaValue = oneFloat + failureAlphaValue = zeroFloat + successIconAlphaValue = zeroFloat + cornerRadiusValue = cornerRadius } - iconAlphaValue = oneFloat - failureAlphaValue = zeroFloat - successIconAlphaValue = zeroFloat - cornerRadiusValue = cornerRadius }) } SSButtonState.FAILURE -> { @@ -200,17 +205,21 @@ fun SSJetPackComposeProgressButton( progressAlphaValue = zeroFloat failureAlphaValue = oneFloat cornerRadiusValue = fifty - //Delay to show failure icon and then IDLE state - delay((speedMillis * two).toLong()) - if (height > width) { - buttonHeight = height - } else { - buttonWidth = width + + if (shouldAutoMoveToIdleState) { + //Delay to show failure icon and then IDLE state + delay((speedMillis * two).toLong()) + + if (height > width) { + buttonHeight = height + } else { + buttonWidth = width + } + iconAlphaValue = oneFloat + failureAlphaValue = zeroFloat + successIconAlphaValue = zeroFloat + cornerRadiusValue = cornerRadius } - iconAlphaValue = oneFloat - failureAlphaValue = zeroFloat - successIconAlphaValue = zeroFloat - cornerRadiusValue = cornerRadius }) } } @@ -230,7 +239,7 @@ fun SSJetPackComposeProgressButton( durationMillis = speedMillis ) ), - enabled = enabled, + enabled = enabled && buttonState != SSButtonState.LOADING, elevation = elevation, shape = RoundedCornerShape(ssAnimateIntAsState(cornerRadiusValue, speedMillis)), border = buttonBorderStroke,