Skip to content

Commit

Permalink
Merge pull request #42 from syxc/kotlin-2.0
Browse files Browse the repository at this point in the history
Kotlin 2.0
  • Loading branch information
syxc authored Jul 4, 2024
2 parents 0bee45e + fbf5bbc commit 41fd426
Show file tree
Hide file tree
Showing 14 changed files with 76 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ class MainActivity : ComponentActivity() {
}

@Composable
fun GreetingView(text: String) {
fun GreetingView(text: String, modifier: Modifier = Modifier) {
Text(text = text)
}

@Preview
@Composable
fun DefaultPreview() {
private fun DefaultPreview() {
AppTheme {
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
Expand Down
1 change: 1 addition & 0 deletions androidApp/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">kmp-app</string>
</resources>
1 change: 1 addition & 0 deletions androidApp/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="android:style/Theme.Material.Light.NoActionBar" />
</resources>
7 changes: 0 additions & 7 deletions androidApp/src/main/res/xml/data_extraction_rules.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>

<!--
Sample data extraction rules file; uncomment and customize as necessary.
See https://developer.android.com/about/versions/12/backup-restore#xml-changes
for details.
-->

<data-extraction-rules>
<cloud-backup>
<exclude domain="root" />
Expand Down
12 changes: 11 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ plugins {
alias(libs.plugins.kotlin.cocoapods) apply false
// alias(libs.plugins.jetbrains.compose) apply false
alias(libs.plugins.compose.compiler) apply false
id("com.jithub.build.logic") apply false
alias(libs.plugins.spotless) apply false
id("com.jithub.build.logic")
}

allprojects {
Expand All @@ -46,6 +47,15 @@ allprojects {
configureCommonKotlin()
}

subprojects {
apply(from = rootProject.file("spotless/spotless.gradle"))
afterEvaluate {
tasks.withType(JavaCompile::class.java) {
dependsOn(tasks.getByName("spotlessApply"))
}
}
}

gradle.taskGraph.whenReady {
tasks.forEach {
/* Encountering the “Unable to make progress running work” Error in Gradle? */
Expand Down
3 changes: 0 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ kotlin.mpp.androidGradlePluginCompatibility.nowarn=true
# https://kotl.in/issue
kotlin.apple.xcodeCompatibility.nowarn=true

# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official

# Android
android.useAndroidX=true
android.enableJetifier=true
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,7 @@ jetbrains-compose = { id = "org.jetbrains.compose", version.ref = "jbr-compose"

compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }

spotless = "com.diffplug.spotless:6.25.0"

[bundles]
asm = []
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ import app.cash.redwood.schema.Widget
interface Schema

@Widget(2)
data class Text(
@Property(1) val text: String?
)
data class Text(@Property(1) val text: String?)

@Widget(3)
data class Button(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ import com.jithub.app.shared.redwood.compose.Button
import com.jithub.app.shared.redwood.compose.Text

@Composable
fun Counter(
modifier: Modifier = Modifier,
value: Int = 0,
labels: StringList? = StringList(listOf())
) {
fun Counter(modifier: Modifier = Modifier, value: Int = 0, labels: StringList? = StringList(listOf())) {
var count by rememberSaveable { mutableIntStateOf(value) }
Column(
width = Constraint.Fill,
Expand Down
Empty file added spotless/copyright.txt
Empty file.
1 change: 1 addition & 0 deletions spotless/copyright.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="utf-8"?>
6 changes: 6 additions & 0 deletions spotless/greclipse.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
org.eclipse.jdt.core.formatter.tabulation.char=space
org.eclipse.jdt.core.formatter.tabulation.size=2
org.eclipse.jdt.core.formatter.indentation.size=2
groovy.formatter.longListLength=110
# Remove unnecessary semicolons.
groovy.formatter.remove.unnecessary.semicolons=true
49 changes: 49 additions & 0 deletions spotless/spotless.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
apply plugin: "com.diffplug.spotless"

// https://github.com/pinterest/ktlint
def ktlintVersion = "1.3.1"

spotless {
java {
target '**/*.java'
targetExclude("**/build/**/*.java", "${rootProject.rootDir}/spotless/**")
toggleOffOn('@formatter:off', '@formatter:on')
// https://github.com/palantir/palantir-java-format
palantirJavaFormat("2.47.0").style("GOOGLE").formatJavadoc(true)
removeUnusedImports()
}

kotlin {
target "**/*.kt"
targetExclude("**/build/**/*.kt", "${rootProject.rootDir}/spotless/**")
ktlint(ktlintVersion).setEditorConfigPath(
"${rootProject.rootDir}/.editorconfig"
).editorConfigOverride(
[
"android" : "true",
"continuation_indent_size" : "2",
// Lowercase names are great for grouping multiple functions and/or types.
"ktlint_standard_filename" : "disabled",
// Making something an expression body should be a choice around readability.
"ktlint_standard_function-expression-body" : "disabled",
"ktlint_function_naming_ignore_when_annotated_with": "Composable",
"ktlint_compose_compositionlocal-allowlist" : "disabled"
]
).customRuleSets(
// https://github.com/mrmans0n/compose-rules
["io.nlopez.compose.rules:ktlint:0.4.5"]
)
}

kotlinGradle {
target("**/*.gradle.kts")
ktlint(ktlintVersion).setEditorConfigPath("${rootProject.rootDir}/.editorconfig")
}

format("xml") {
target("**/*.xml")
targetExclude("**/build/**/*.xml", "**/lint-config/**/*.xml", "${rootProject.rootDir}/spotless/**")
// Look for the first XML tag that isn't a comment (<!--) or the xml declaration (<?xml)
licenseHeaderFile(rootProject.file("spotless/copyright.xml"), "(<[^!?])")
}
}

0 comments on commit 41fd426

Please sign in to comment.