Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate project to Jetpack Compose #27

Merged
merged 9 commits into from
Nov 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ jobs:
steps:
- uses: actions/checkout@v1

- name: set up JDK 1.8
- name: set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 1.8
java-version: 11

- name: Build with Gradle
run: ./gradlew build test
4 changes: 2 additions & 2 deletions .github/workflows/style-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ jobs:
steps:
- uses: actions/checkout@v1

- name: set up JDK 1.8
- name: set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 1.8
java-version: 11

- name: Ktlint check
run: ./gradlew ktlintCheck
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 23 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 11 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ android {
}

buildFeatures {
viewBinding true
compose true
}

composeOptions {
kotlinCompilerExtensionVersion "1.0.5"
}
}

Expand All @@ -53,9 +57,12 @@ dependencies {
implementation libs.kotlinStdLib
implementation libs.appCompat
implementation libs.coreKtx
implementation libs.fragmentKtx
implementation libs.constraintLayout
implementation libs.materialComponents

implementation libs.composeActivity
implementation libs.composeMaterial
implementation libs.composeTooling
implementation libs.accompanistSysUi
implementation libs.accompanistInsets

testImplementation libs.junit

Expand Down
6 changes: 4 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:label="Crashy App"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
15 changes: 7 additions & 8 deletions app/src/main/java/com/haroldadmin/crashyapp/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package com.haroldadmin.crashyapp

import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import com.haroldadmin.crashyapp.databinding.ActivityMainBinding
import com.haroldadmin.crashyapp.ui.pages.HomePage
import com.haroldadmin.crashyapp.ui.theme.CrashyAppTheme

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)

binding.crashButton.setOnClickListener {
throw BecauseICanException()
setContent {
CrashyAppTheme {
HomePage()
}
}
}
}

private class BecauseICanException : Exception("This exception is thrown purely because it can be thrown")
41 changes: 41 additions & 0 deletions app/src/main/java/com/haroldadmin/crashyapp/ui/pages/HomePage.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.haroldadmin.crashyapp.ui.pages

import androidx.compose.foundation.layout.*
import androidx.compose.material.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp

@Composable
fun HomePage() {
Scaffold(
topBar = {
TopAppBar {
Text(text = "Crashy App", style = MaterialTheme.typography.h6)
}
}
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
modifier = Modifier
.padding(8.dp)
.fillMaxWidth()
.fillMaxHeight()
) {
Text(
text = "Press the button below to see error screen from WhatTheStack!",
textAlign = TextAlign.Center
)
Spacer(modifier = Modifier.height(16.dp))
Button(onClick = { throw BecauseICanException() }) {
Text(text = "Crash!")
}
}
}
}

private class BecauseICanException :
Exception("This exception is thrown purely because it can be thrown")
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.haroldadmin.crashyapp.ui.theme

import androidx.compose.material.MaterialTheme
import androidx.compose.material.lightColors
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color

private val ColorPalette = lightColors(
primary = Color(0xffd32f2f),
primaryVariant = Color(0xff9a0007),
secondary = Color(0xff616161),
secondaryVariant = Color(0x33373737),
)

@Composable
fun CrashyAppTheme(
content: @Composable () -> Unit
) {
MaterialTheme(colors = ColorPalette, content = content)
}
32 changes: 0 additions & 32 deletions app/src/main/res/layout/activity_main.xml

This file was deleted.

11 changes: 0 additions & 11 deletions app/src/main/res/values/colors.xml

This file was deleted.

3 changes: 0 additions & 3 deletions app/src/main/res/values/strings.xml

This file was deleted.

11 changes: 1 addition & 10 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
<resources>

<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<item name="colorPrimary">@color/primaryColor</item>
<item name="colorPrimaryVariant">@color/primaryLightColor</item>
<item name="colorPrimaryDark">@color/primaryDarkColor</item>
<item name="colorOnPrimary">@color/primaryTextColor</item>
<item name="colorSecondary">@color/secondaryColor</item>
<item name="colorSecondaryVariant">@color/secondaryLightColor</item>
<item name="colorOnSecondary">@color/secondaryTextColor</item>
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
</style>

</resources>
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
buildscript {
ext.buildConfig = [
"applicationId": "com.haroldadmin.crashyapp",
"compileSdk" : 29,
"compileSdk" : 31,
"minSdk" : 21,
"targetSdk" : 29,
"targetSdk" : 31,
"versionCode" : 1,
"versionName" : "0.0.1"
]
Expand Down Expand Up @@ -33,7 +33,7 @@ allprojects {
subprojects {
apply plugin: "org.jlleitschuh.gradle.ktlint"
ktlint {
version = "0.36.0"
version = "0.43.0"
ignoreFailures = false
disabledRules = ["no-wildcard-imports"]
}
Expand Down
12 changes: 10 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
kotlin = "1.5.20"
agp = "4.2.0"
kotlin = "1.5.31"
agp = "7.0.3"
ktlint = "10.1.0"
appCompat = "1.3.0"
coreTest = "2.0.0"
Expand All @@ -17,9 +17,17 @@ espressoCore = "3.2.0"
mockk = "1.9.3"
robolectric = "4.3.1"
startup = "1.0.0"
composeActivity = "1.3.1"
compose = "1.0.5"
accompanist = "0.21.3-beta"

[libraries]

composeActivity = { module = "androidx.activity:activity-compose", version.ref = "composeActivity" }
composeMaterial = { module = "androidx.compose.material:material", version.ref = "compose" }
composeTooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "compose" }
accompanistSysUi = { module = "com.google.accompanist:accompanist-systemuicontroller", version.ref = "accompanist" }
accompanistInsets = { module = "com.google.accompanist:accompanist-insets", version.ref = "accompanist" }
agp = { module = "com.android.tools.build:gradle", version.ref = "agp" }
kotlinGradlePlugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
ktlintGradlePlugin = { module = "org.jlleitschuh.gradle:ktlint-gradle", version.ref = "ktlint" }
Expand Down
16 changes: 11 additions & 5 deletions what-the-stack/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ android {
}

buildFeatures {
viewBinding true
compose true
}

composeOptions {
kotlinCompilerExtensionVersion libs.versions.compose.get()
}
}

Expand All @@ -46,11 +50,13 @@ dependencies {
implementation libs.kotlinStdLib
implementation libs.appCompat
implementation libs.coreKtx
implementation libs.fragmentKtx
implementation libs.constraintLayout
implementation libs.materialComponents
implementation libs.startup
implementation libs.insetter

implementation libs.composeActivity
implementation libs.composeMaterial
implementation libs.composeTooling
implementation libs.accompanistSysUi
implementation libs.accompanistInsets

testImplementation libs.junit
testImplementation libs.mockk
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.haroldadmin.whatthestack

import android.os.Parcelable
import kotlinx.android.parcel.Parcelize
import kotlinx.parcelize.Parcelize

/**
* Represents the data of the exception to be displayed to the user.
Expand Down
Loading