Skip to content

Commit fbddf8c

Browse files
authored
Merge pull request #12 from Vaibhav2002/JetpackCompose
Jetpack compose
2 parents 2fbf71c + 4aae050 commit fbddf8c

24 files changed

Lines changed: 399 additions & 5 deletions

.idea/gradle.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.

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 20 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: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ class MainActivity : AppCompatActivity() {
179179
}
180180

181181
}
182-
```
182+
183183
🌟 You are all set!
184184

185185
## 🍰 Contribute

app/build.gradle

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@ android {
99

1010
defaultConfig {
1111
applicationId "dev.sagar.progressbutton"
12-
minSdkVersion 21
12+
minSdkVersion 26
1313
targetSdkVersion 30
1414
versionCode 1
1515
versionName "1.0"
1616

1717
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
18+
19+
vectorDrawables {
20+
useSupportLibrary true
21+
}
1822
}
1923

2024
buildTypes {
@@ -29,10 +33,16 @@ android {
2933
}
3034
kotlinOptions {
3135
jvmTarget = '1.8'
36+
useIR = true
3237
}
3338
buildFeatures {
3439
viewBinding true
40+
compose true
3541
}
42+
composeOptions {
43+
kotlinCompilerExtensionVersion compose_version
44+
}
45+
3646
}
3747

3848
dependencies {
@@ -42,6 +52,7 @@ dependencies {
4252
implementation 'androidx.appcompat:appcompat:1.3.0'
4353
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
4454
implementation project(path: ':progress-button')
55+
implementation project(path: ':progress-button-compose')
4556
testImplementation 'junit:junit:4.+'
4657
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
4758
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
@@ -54,4 +65,11 @@ dependencies {
5465
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.3.1"
5566
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.3.1"
5667

68+
69+
70+
implementation "androidx.compose.ui:ui:$compose_version"
71+
implementation "androidx.compose.material:material:$compose_version"
72+
implementation "androidx.compose.ui:ui-tooling:$compose_version"
73+
implementation 'androidx.activity:activity-compose:1.3.0-beta02'
74+
5775
}

app/src/main/AndroidManifest.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@
1818
<category android:name="android.intent.category.LAUNCHER" />
1919
</intent-filter>
2020
</activity>
21+
22+
23+
<activity
24+
android:name=".ComposeActivity"
25+
android:exported="true"
26+
android:label="@string/title_activity_compose"
27+
android:theme="@style/Theme.ProgressButton.NoActionBar" />
2128
</application>
2229

2330
</manifest>
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package dev.sagar.progressbutton
2+
3+
import android.os.Bundle
4+
import androidx.activity.ComponentActivity
5+
import androidx.activity.compose.setContent
6+
import androidx.compose.foundation.ExperimentalFoundationApi
7+
import androidx.compose.foundation.layout.* // ktlint-disable no-wildcard-imports
8+
import androidx.compose.foundation.shape.RoundedCornerShape
9+
import androidx.compose.material.Button
10+
import androidx.compose.material.Surface
11+
import androidx.compose.material.Text
12+
import androidx.compose.runtime.* // ktlint-disable no-wildcard-imports
13+
import androidx.compose.ui.Alignment
14+
import androidx.compose.ui.Modifier
15+
import androidx.compose.ui.graphics.Color
16+
import androidx.compose.ui.tooling.preview.Preview
17+
import androidx.compose.ui.unit.dp
18+
import dev.sagar.progress_button_compose.ButtonState
19+
import dev.sagar.progress_button_compose.ProgressButton
20+
import dev.sagar.progress_button_compose.ProgressButtonColors
21+
22+
class ComposeActivity : ComponentActivity() {
23+
@ExperimentalFoundationApi
24+
override fun onCreate(savedInstanceState: Bundle?) {
25+
super.onCreate(savedInstanceState)
26+
setContent {
27+
Surface(color = Color.White) {
28+
MainScreenContent()
29+
}
30+
}
31+
}
32+
}
33+
34+
@ExperimentalFoundationApi
35+
@Composable
36+
@Preview
37+
fun MainScreenContent() {
38+
39+
var buttonState by remember {
40+
mutableStateOf(ButtonState.DISABLED)
41+
}
42+
43+
Column(
44+
modifier = Modifier
45+
.fillMaxSize()
46+
.padding(32.dp),
47+
verticalArrangement = Arrangement.Center,
48+
horizontalAlignment = Alignment.CenterHorizontally
49+
) {
50+
ProgressButton(
51+
buttonState = buttonState,
52+
text = "Button",
53+
completedText = "Finished",
54+
shape = RoundedCornerShape(12.dp),
55+
modifier = Modifier
56+
.fillMaxWidth(),
57+
progressButtonColors = ProgressButtonColors()
58+
) { }
59+
60+
Spacer(modifier = Modifier.height(100.dp))
61+
62+
ControlButton(text = "Enable") {
63+
buttonState = ButtonState.ENABLED
64+
}
65+
Spacer(modifier = Modifier.height(16.dp))
66+
ControlButton(text = "Disable") {
67+
buttonState = ButtonState.DISABLED
68+
}
69+
Spacer(modifier = Modifier.height(16.dp))
70+
ControlButton(text = "Loading") {
71+
buttonState = ButtonState.LOADING
72+
}
73+
Spacer(modifier = Modifier.height(16.dp))
74+
ControlButton(text = "Finished") {
75+
buttonState = ButtonState.FINISHED
76+
}
77+
}
78+
}
79+
80+
@Composable
81+
fun ControlButton(text: String, onClick: () -> Unit) {
82+
Button(onClick = onClick, contentPadding = PaddingValues(horizontal = 16.dp)) {
83+
Text(text = text, color = Color.White)
84+
}
85+
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package dev.sagar.progressbutton
22

3+
import android.content.Intent
34
import android.os.Bundle
45
import android.widget.Toast
56
import androidx.appcompat.app.AppCompatActivity
@@ -75,6 +76,12 @@ class MainActivity : AppCompatActivity() {
7576
progressButton.reset()
7677
}
7778

79+
switchToCompose.setOnClickListener {
80+
Intent(this@MainActivity, ComposeActivity::class.java).also {
81+
startActivity(it)
82+
}
83+
}
84+
7885
progressButton.attachToLiveData(sampleLiveData, this@MainActivity)
7986
}
8087
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,17 @@
9292
app:layout_constraintStart_toStartOf="@+id/editTextTextPersonName"
9393
app:layout_constraintTop_toBottomOf="@+id/editTextTextPersonName" />
9494

95+
<androidx.appcompat.widget.AppCompatButton
96+
android:id="@+id/switchToCompose"
97+
android:layout_width="wrap_content"
98+
android:layout_height="wrap_content"
99+
android:layout_marginTop="32dp"
100+
android:background="?attr/colorSecondary"
101+
android:paddingHorizontal="16dp"
102+
android:text="Switch To Compose Activity"
103+
android:textColor="@color/black"
104+
app:layout_constraintEnd_toEndOf="parent"
105+
app:layout_constraintStart_toStartOf="parent"
106+
app:layout_constraintTop_toBottomOf="@+id/progressButton" />
107+
95108
</androidx.constraintlayout.widget.ConstraintLayout>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
<resources>
22
<string name="app_name">ProgressButton</string>
3+
<string name="title_activity_compose">ComposeActivity</string>
34
</resources>

0 commit comments

Comments
 (0)