Skip to content

Commit 5f9b660

Browse files
authored
Migrate project to Jetpack Compose (#27)
* feat: Switch to versions catalog and AGP 7 * feat: Refactor library module to use jetpack compose * feat: Migrate sample app to jetpack compose * fix: Use JDK 11 in CI * fix: Update ktlint * lint: Fix lint errors * fix: Use the same version for compose material and tooling libs * fix: Inline single use composables, make filenames consistent with composables, use version references in build.gradle * fix: Replace deprecated Handler constructor
1 parent 9208819 commit 5f9b660

36 files changed

+563
-411
lines changed

.github/workflows/android.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ jobs:
88
steps:
99
- uses: actions/checkout@v1
1010

11-
- name: set up JDK 1.8
11+
- name: set up JDK 11
1212
uses: actions/setup-java@v1
1313
with:
14-
java-version: 1.8
14+
java-version: 11
1515

1616
- name: Build with Gradle
1717
run: ./gradlew build test

.github/workflows/style-check.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ jobs:
88
steps:
99
- uses: actions/checkout@v1
1010

11-
- name: set up JDK 1.8
11+
- name: set up JDK 11
1212
uses: actions/setup-java@v1
1313
with:
14-
java-version: 1.8
14+
java-version: 11
1515

1616
- name: Ktlint check
1717
run: ./gradlew ktlintCheck

.idea/compiler.xml

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

app/build.gradle

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ android {
4141
}
4242

4343
buildFeatures {
44-
viewBinding true
44+
compose true
45+
}
46+
47+
composeOptions {
48+
kotlinCompilerExtensionVersion "1.0.5"
4549
}
4650
}
4751

@@ -53,9 +57,12 @@ dependencies {
5357
implementation libs.kotlinStdLib
5458
implementation libs.appCompat
5559
implementation libs.coreKtx
56-
implementation libs.fragmentKtx
57-
implementation libs.constraintLayout
58-
implementation libs.materialComponents
60+
61+
implementation libs.composeActivity
62+
implementation libs.composeMaterial
63+
implementation libs.composeTooling
64+
implementation libs.accompanistSysUi
65+
implementation libs.accompanistInsets
5966

6067
testImplementation libs.junit
6168

app/src/main/AndroidManifest.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
<application
66
android:allowBackup="true"
77
android:icon="@mipmap/ic_launcher"
8-
android:label="@string/app_name"
8+
android:label="Crashy App"
99
android:roundIcon="@mipmap/ic_launcher_round"
1010
android:supportsRtl="true"
1111
android:theme="@style/AppTheme">
12-
<activity android:name=".MainActivity">
12+
<activity
13+
android:name=".MainActivity"
14+
android:exported="true">
1315
<intent-filter>
1416
<action android:name="android.intent.action.MAIN" />
1517

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
package com.haroldadmin.crashyapp
22

33
import android.os.Bundle
4+
import androidx.activity.compose.setContent
45
import androidx.appcompat.app.AppCompatActivity
5-
import com.haroldadmin.crashyapp.databinding.ActivityMainBinding
6+
import com.haroldadmin.crashyapp.ui.pages.HomePage
7+
import com.haroldadmin.crashyapp.ui.theme.CrashyAppTheme
68

79
class MainActivity : AppCompatActivity() {
810

911
override fun onCreate(savedInstanceState: Bundle?) {
1012
super.onCreate(savedInstanceState)
11-
val binding = ActivityMainBinding.inflate(layoutInflater)
12-
setContentView(binding.root)
13-
14-
binding.crashButton.setOnClickListener {
15-
throw BecauseICanException()
13+
setContent {
14+
CrashyAppTheme {
15+
HomePage()
16+
}
1617
}
1718
}
1819
}
19-
20-
private class BecauseICanException : Exception("This exception is thrown purely because it can be thrown")
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.haroldadmin.crashyapp.ui.pages
2+
3+
import androidx.compose.foundation.layout.*
4+
import androidx.compose.material.*
5+
import androidx.compose.runtime.Composable
6+
import androidx.compose.ui.Alignment
7+
import androidx.compose.ui.Modifier
8+
import androidx.compose.ui.text.style.TextAlign
9+
import androidx.compose.ui.unit.dp
10+
11+
@Composable
12+
fun HomePage() {
13+
Scaffold(
14+
topBar = {
15+
TopAppBar {
16+
Text(text = "Crashy App", style = MaterialTheme.typography.h6)
17+
}
18+
}
19+
) {
20+
Column(
21+
horizontalAlignment = Alignment.CenterHorizontally,
22+
verticalArrangement = Arrangement.Center,
23+
modifier = Modifier
24+
.padding(8.dp)
25+
.fillMaxWidth()
26+
.fillMaxHeight()
27+
) {
28+
Text(
29+
text = "Press the button below to see error screen from WhatTheStack!",
30+
textAlign = TextAlign.Center
31+
)
32+
Spacer(modifier = Modifier.height(16.dp))
33+
Button(onClick = { throw BecauseICanException() }) {
34+
Text(text = "Crash!")
35+
}
36+
}
37+
}
38+
}
39+
40+
private class BecauseICanException :
41+
Exception("This exception is thrown purely because it can be thrown")
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.haroldadmin.crashyapp.ui.theme
2+
3+
import androidx.compose.material.MaterialTheme
4+
import androidx.compose.material.lightColors
5+
import androidx.compose.runtime.Composable
6+
import androidx.compose.ui.graphics.Color
7+
8+
private val ColorPalette = lightColors(
9+
primary = Color(0xffd32f2f),
10+
primaryVariant = Color(0xff9a0007),
11+
secondary = Color(0xff616161),
12+
secondaryVariant = Color(0x33373737),
13+
)
14+
15+
@Composable
16+
fun CrashyAppTheme(
17+
content: @Composable () -> Unit
18+
) {
19+
MaterialTheme(colors = ColorPalette, content = content)
20+
}

0 commit comments

Comments
 (0)