Skip to content

Commit d545829

Browse files
Merge pull request #93 from snappdevelopment/multiplatform-fixes
Several adjustments for the multiplatform project
2 parents 93ecceb + 07d5239 commit d545829

File tree

6 files changed

+109
-56
lines changed

6 files changed

+109
-56
lines changed

.github/workflows/check-pr.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
workflow_call:
99

1010
jobs:
11-
assembleDebug:
11+
assembleAndroidDebug:
1212
runs-on: macos-latest
1313

1414
steps:
@@ -21,10 +21,10 @@ jobs:
2121
distribution: 'zulu'
2222
java-version: '17'
2323

24-
- name: Assemble Debug
24+
- name: Assemble Android Debug
2525
run: ./gradlew assembleDebug --stacktrace
2626

27-
assembleRelease:
27+
assembleAndroidRelease:
2828
runs-on: macos-latest
2929

3030
steps:
@@ -37,7 +37,7 @@ jobs:
3737
distribution: 'zulu'
3838
java-version: '17'
3939

40-
- name: Assemble Release
40+
- name: Assemble Android Release
4141
run: ./gradlew assembleRelease --stacktrace
4242

4343
# UI tests on CI are flaky
@@ -62,9 +62,9 @@ jobs:
6262
# arch: x86_64
6363
# script: ./gradlew connectedCheck --stacktrace
6464

65-
check:
65+
test:
6666
runs-on: macos-latest
67-
needs: [assembleDebug, assembleRelease]
67+
needs: [assembleAndroidDebug, assembleAndroidRelease]
6868

6969
steps:
7070
- name: Checkout code
@@ -76,12 +76,12 @@ jobs:
7676
distribution: 'zulu'
7777
java-version: '17'
7878

79-
- name: Run checks
80-
run: ./gradlew check --stacktrace
79+
- name: Run tests
80+
run: ./gradlew :jsontree:jvmTest --tests com.sebastianneubauer.jsontree.JsonTreeParserTest --stacktrace
8181

8282
detekt:
8383
runs-on: macos-latest
84-
needs: [assembleDebug, assembleRelease]
84+
needs: [assembleAndroidDebug, assembleAndroidRelease]
8585

8686
steps:
8787
- name: Checkout code

.gitignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,28 @@ captures/
5959
.idea/navEditor.xml
6060
.idea/other.xml
6161
.idea/studiobot.xml
62+
.idea/artifacts
6263

6364
.kotlin
6465

66+
# Xcode
67+
*.xcodeproj/*
68+
!*.xcodeproj/project.pbxproj
69+
!*.xcodeproj/xcshareddata/
70+
!*.xcodeproj/project.xcworkspace/
71+
!*.xcworkspace/contents.xcworkspacedata
72+
**/xcshareddata/WorkspaceSettings.xcsettings
73+
xcuserdata
74+
IDEWorkspaceChecks.plist
75+
76+
# CocoaPods
77+
Pods/
78+
79+
# iOS App packaging
80+
*.ipa
81+
*.dSYM.zip
82+
*.dSYM
83+
6584
# Keystore files
6685
# Uncomment the following lines if you do not want to check your keystore files in.
6786
#*.jks

gradle/libs.versions.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ android-compileSdk = "34"
55
java-toolchain = "17"
66

77
compose = "1.6.11"
8-
agp = "8.4.2"
8+
agp = "8.3.2"
99
kotlin = "2.0.0"
1010
publish = "0.29.0"
11-
nexus-publish = "2.0.0"
1211
api-validator = "0.16.3"
1312
atomicfuGradlePlugin = "0.22.0"
1413

jsontree/build.gradle.kts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ kotlin {
1717
publishLibraryVariants("release")
1818
@OptIn(ExperimentalKotlinGradlePluginApi::class)
1919
instrumentedTestVariant.sourceSetTree.set(KotlinSourceSetTree.test)
20-
@OptIn(ExperimentalKotlinGradlePluginApi::class)
21-
compilerOptions {
22-
jvmTarget.set(JvmTarget.JVM_1_8)
23-
}
2420

2521
@OptIn(ExperimentalKotlinGradlePluginApi::class)
2622
instrumentedTestVariant {
@@ -90,7 +86,6 @@ kotlin {
9086
}
9187
}
9288

93-
9489
android {
9590
namespace = "com.sebastianneubauer.jsontree"
9691
compileSdk = libs.versions.android.compileSdk.get().toInt()

sample/build.gradle.kts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,13 @@ kotlin {
6565

6666
}
6767

68-
69-
7068
android {
7169
namespace = "com.sebastianneubauer.jsontreesample"
7270
compileSdk = 34
7371

7472
defaultConfig {
75-
minSdk = 24
73+
minSdk = 21
74+
targetSdk = 34
7675
}
7776
sourceSets["main"].apply {
7877
manifest.srcFile("src/androidMain/AndroidManifest.xml")
@@ -82,6 +81,18 @@ android {
8281
sourceCompatibility = JavaVersion.VERSION_17
8382
targetCompatibility = JavaVersion.VERSION_17
8483
}
84+
buildTypes {
85+
getByName("release") {
86+
isMinifyEnabled = true
87+
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
88+
//for testing only, don't do this in your app
89+
signingConfig = signingConfigs.getByName("debug")
90+
}
91+
getByName("debug") {
92+
applicationIdSuffix = ".debug"
93+
signingConfig = signingConfigs.getByName("debug")
94+
}
95+
}
8596
buildFeatures {
8697
compose = true
8798
}

sample/src/commonMain/kotlin/App.kt

Lines changed: 66 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import androidx.compose.material3.ExperimentalMaterial3Api
2222
import androidx.compose.material3.MaterialTheme
2323
import androidx.compose.material3.Scaffold
2424
import androidx.compose.material3.Text
25+
import androidx.compose.material3.TopAppBarDefaults
2526
import androidx.compose.runtime.Composable
2627
import androidx.compose.runtime.getValue
2728
import androidx.compose.runtime.mutableStateOf
@@ -39,22 +40,23 @@ import com.sebastianneubauer.jsontree.defaultLightColors
3940
import com.sebastianneubauer.jsontreesample.ui.theme.JsonTreeTheme
4041
import org.jetbrains.compose.ui.tooling.preview.Preview
4142

42-
4343
@Composable
4444
internal fun App() = JsonTreeTheme {
4545
MainScreen()
4646
}
4747

4848
@OptIn(
49-
ExperimentalMaterial3Api::class, ExperimentalFoundationApi::class, ExperimentalLayoutApi::class
49+
ExperimentalMaterial3Api::class,
50+
ExperimentalFoundationApi::class,
51+
ExperimentalLayoutApi::class
5052
)
5153
@Composable
52-
fun MainScreen() {
53-
54+
private fun MainScreen() {
5455
Scaffold(
5556
modifier = Modifier.safeDrawingPadding(),
5657
topBar = {
5758
CenterAlignedTopAppBar(
59+
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(containerColor = Color.White),
5860
title = {
5961
Text(
6062
modifier = Modifier.padding(horizontal = 16.dp),
@@ -68,7 +70,9 @@ fun MainScreen() {
6870
contentWindowInsets = WindowInsets(top = 60.dp),
6971
) { padding ->
7072
Column(
71-
modifier = Modifier.fillMaxSize().padding(padding)
73+
modifier = Modifier
74+
.fillMaxSize()
75+
.padding(padding)
7276
) {
7377
var errorMessage: String? by remember { mutableStateOf(null) }
7478
var json: String by remember { mutableStateOf(simpleJson) }
@@ -78,17 +82,24 @@ fun MainScreen() {
7882
var showItemCount: Boolean by remember { mutableStateOf(true) }
7983
var expandSingleChildren: Boolean by remember { mutableStateOf(true) }
8084

81-
FlowRow {
82-
Button(modifier = Modifier.padding(horizontal = 8.dp), onClick = {
83-
errorMessage = null
84-
json = when (json) {
85-
emptyJson -> simpleJson
86-
simpleJson -> complexJson
87-
complexJson -> invalidJson
88-
invalidJson -> emptyJson
89-
else -> throw IllegalStateException("No JSON selected!")
85+
FlowRow(
86+
modifier = Modifier
87+
.fillMaxWidth()
88+
.background(color = Color.White),
89+
) {
90+
Button(
91+
modifier = Modifier.padding(horizontal = 8.dp),
92+
onClick = {
93+
errorMessage = null
94+
json = when (json) {
95+
emptyJson -> simpleJson
96+
simpleJson -> complexJson
97+
complexJson -> invalidJson
98+
invalidJson -> emptyJson
99+
else -> throw IllegalStateException("No JSON selected!")
100+
}
90101
}
91-
}) {
102+
) {
92103
Text(
93104
text = when (json) {
94105
simpleJson -> "Simple Json"
@@ -100,36 +111,47 @@ fun MainScreen() {
100111
)
101112
}
102113

103-
Button(modifier = Modifier.padding(horizontal = 8.dp), onClick = {
104-
val newState = when (initialState) {
105-
TreeState.EXPANDED -> TreeState.COLLAPSED
106-
TreeState.COLLAPSED -> TreeState.FIRST_ITEM_EXPANDED
107-
TreeState.FIRST_ITEM_EXPANDED -> TreeState.EXPANDED
114+
Button(
115+
modifier = Modifier.padding(horizontal = 8.dp),
116+
onClick = {
117+
val newState = when (initialState) {
118+
TreeState.EXPANDED -> TreeState.COLLAPSED
119+
TreeState.COLLAPSED -> TreeState.FIRST_ITEM_EXPANDED
120+
TreeState.FIRST_ITEM_EXPANDED -> TreeState.EXPANDED
121+
}
122+
initialState = newState
108123
}
109-
initialState = newState
110-
}) {
124+
) {
111125
Text(text = initialState.name)
112126
}
113127

114-
Button(modifier = Modifier.padding(horizontal = 8.dp),
115-
onClick = { showIndices = !showIndices }) {
128+
Button(
129+
modifier = Modifier.padding(horizontal = 8.dp),
130+
onClick = { showIndices = !showIndices }
131+
) {
116132
Text(text = if (showIndices) "Hide indices" else "Show indices")
117133
}
118134

119-
Button(modifier = Modifier.padding(horizontal = 8.dp),
120-
onClick = { showItemCount = !showItemCount }) {
135+
Button(
136+
modifier = Modifier.padding(horizontal = 8.dp),
137+
onClick = { showItemCount = !showItemCount }
138+
) {
121139
Text(text = if (showItemCount) "Hide item count" else "Show item count")
122140
}
123141

124-
Button(modifier = Modifier.padding(horizontal = 8.dp), onClick = {
125-
colors =
126-
if (colors == defaultLightColors) defaultDarkColors else defaultLightColors
127-
}) {
142+
Button(
143+
modifier = Modifier.padding(horizontal = 8.dp),
144+
onClick = {
145+
colors = if (colors == defaultLightColors) defaultDarkColors else defaultLightColors
146+
}
147+
) {
128148
Text(text = if (colors == defaultLightColors) "Light" else "Dark")
129149
}
130150

131-
Button(modifier = Modifier.padding(horizontal = 8.dp),
132-
onClick = { expandSingleChildren = !expandSingleChildren }) {
151+
Button(
152+
modifier = Modifier.padding(horizontal = 8.dp),
153+
onClick = { expandSingleChildren = !expandSingleChildren }
154+
) {
133155
Text(text = if (expandSingleChildren) "Expand children" else "Don't expand children")
134156
}
135157
}
@@ -147,12 +169,20 @@ fun MainScreen() {
147169
val error = errorMessage
148170
if (error != null) {
149171
Text(
150-
text = error, color = Color.Black
172+
modifier = Modifier
173+
.fillMaxSize()
174+
.background(
175+
color = if (colors == defaultLightColors) Color.White else Color.Black
176+
),
177+
text = error,
178+
color = if (colors == defaultLightColors) Color.Black else Color.White,
151179
)
152180
} else {
153181
JsonTree(
154-
modifier = Modifier.fillMaxSize()
155-
.horizontalScroll(rememberScrollState()).background(
182+
modifier = Modifier
183+
.fillMaxSize()
184+
.horizontalScroll(rememberScrollState())
185+
.background(
156186
if (colors == defaultLightColors) Color.White else Color.Black
157187
),
158188
contentPadding = PaddingValues(16.dp),
@@ -191,9 +221,8 @@ fun MainScreen() {
191221
}
192222
}
193223

194-
195224
@Preview
196225
@Composable
197-
fun PreviewMainScreen() = JsonTreeTheme {
226+
private fun PreviewMainScreen() = JsonTreeTheme {
198227
MainScreen()
199228
}

0 commit comments

Comments
 (0)