Skip to content

Commit 1181651

Browse files
committed
::boom: Introducing breaking changes -
- Added the jetpack compose support - Added the method *setState* to change the button state using the enum - Renamed the button state from setActivate() to setLoading()
1 parent bdffd38 commit 1181651

9 files changed

Lines changed: 38 additions & 22 deletions

File tree

.idea/discord.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ class MainActivity : AppCompatActivity() {
151151
Toast.makeText(this@MainActivity, "On click!", Toast.LENGTH_SHORT).show()
152152
}
153153

154-
btnActivate.setOnClickListener {
155-
// Activate state
156-
progressButton.activate()
154+
btnLoading.setOnClickListener {
155+
// Loading state
156+
progressButton.loading()
157157
}
158158

159159
btnFinish.setOnClickListener {

app/src/main/java/dev/sagar/progressbutton/MainActivity.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ class MainActivity : AppCompatActivity() {
5151
Toast.makeText(this@MainActivity, "On click!", Toast.LENGTH_SHORT).show()
5252
}
5353

54-
btnActivate.setOnClickListener {
55-
// Activate state
56-
progressButton.activate()
54+
btnLoading.setOnClickListener {
55+
// Loading state
56+
progressButton.loading()
5757
}
5858

5959
btnFinish.setOnClickListener {

app/src/main/res/layout/activity_main.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
app:layout_constraintTop_toBottomOf="@+id/editTextTextPersonName2" />
1919

2020
<Button
21-
android:id="@+id/btnActivate"
21+
android:id="@+id/btnLoading"
2222
android:layout_width="@dimen/button_width"
2323
android:layout_height="wrap_content"
2424
android:layout_marginStart="24dp"
2525
android:layout_marginBottom="24dp"
26-
android:text="Activate"
26+
android:text="Loading"
2727
app:layout_constraintBottom_toTopOf="@+id/btnEnable"
2828
app:layout_constraintStart_toStartOf="parent" />
2929

@@ -32,7 +32,7 @@
3232
android:layout_width="@dimen/button_width"
3333
android:layout_height="wrap_content"
3434
android:text="Finish"
35-
app:layout_constraintBottom_toBottomOf="@+id/btnActivate"
35+
app:layout_constraintBottom_toBottomOf="@+id/btnLoading"
3636
app:layout_constraintEnd_toEndOf="@+id/btnDisable" />
3737

3838
<Button
@@ -43,7 +43,7 @@
4343
android:layout_marginBottom="24dp"
4444
android:text="Enable"
4545
app:layout_constraintBottom_toTopOf="@+id/btnReset"
46-
app:layout_constraintEnd_toEndOf="@+id/btnActivate"
46+
app:layout_constraintEnd_toEndOf="@+id/btnLoading"
4747
app:layout_constraintStart_toStartOf="parent" />
4848

4949
<Button

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ buildscript {
77
mavenCentral()
88
}
99
dependencies {
10-
classpath "com.android.tools.build:gradle:7.0.0-beta04"
10+
classpath 'com.android.tools.build:gradle:7.0.0'
1111
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.10"
1212

1313
// NOTE: Do not place your application dependencies here; they belong

progress-button-compose/build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ android {
1010
defaultConfig {
1111
minSdkVersion 26
1212
targetSdkVersion 30
13-
versionCode 1
14-
versionName "1.0"
1513

1614
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1715
consumerProguardFiles "consumer-rules.pro"

progress-button/build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ android {
1010
defaultConfig {
1111
minSdkVersion 21
1212
targetSdkVersion 30
13-
versionCode 1
14-
versionName "1.0"
1513

1614
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1715
consumerProguardFiles "consumer-rules.pro"

progress-button/src/main/java/dev/sagar/progress_button/ProgressButton.kt

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@ class ProgressButton @JvmOverloads constructor(
194194
if (isVibrationEnabled) {
195195
if ((
196196
ContextCompat.checkSelfPermission(
197-
context,
198-
Manifest.permission.VIBRATE
199-
) == PackageManager.PERMISSION_GRANTED
197+
context,
198+
Manifest.permission.VIBRATE
199+
) == PackageManager.PERMISSION_GRANTED
200200
)
201201
) {
202202
vibrateOnClick()
@@ -405,9 +405,9 @@ class ProgressButton @JvmOverloads constructor(
405405
}
406406

407407
/**
408-
* Set the button state to activate for loading purpose
408+
* Set the button state to loading for loading purpose
409409
*/
410-
fun activate() {
410+
fun loading() {
411411
currentState = ButtonStates.LOADING
412412
for (editText in disableViews) {
413413
editText.isEnabled = false
@@ -480,17 +480,29 @@ class ProgressButton @JvmOverloads constructor(
480480
* Helps when u have a livedata in your viewModel and you want to update button state
481481
* according to the livedata
482482
*/
483-
484483
fun attachToLiveData(state: LiveData<ButtonStates>, lifecycleOwner: LifecycleOwner) {
485484
buttonStatesLiveData = state
486485
buttonStatesLiveData?.observe(lifecycleOwner) {
487486
when (it) {
488-
ButtonStates.LOADING -> activate()
487+
ButtonStates.LOADING -> loading()
489488
ButtonStates.ENABLED -> enable()
490489
ButtonStates.DISABLED -> disable()
491490
ButtonStates.FINISHED -> finished()
492491
else -> reset()
493492
}
494493
}
495494
}
495+
496+
/**
497+
* Added the enum support to change the Button state using [ButtonStates] enum
498+
*/
499+
fun setState(state: ButtonStates) {
500+
when (state) {
501+
ButtonStates.LOADING -> loading()
502+
ButtonStates.ENABLED -> enable()
503+
ButtonStates.DISABLED -> disable()
504+
ButtonStates.FINISHED -> finished()
505+
else -> reset()
506+
}
507+
}
496508
}

0 commit comments

Comments
 (0)