Skip to content
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
18 changes: 9 additions & 9 deletions .github/workflows/check-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
workflow_call:

jobs:
assembleDebug:
assembleAndroidDebug:
runs-on: macos-latest

steps:
Expand All @@ -21,10 +21,10 @@ jobs:
distribution: 'zulu'
java-version: '17'

- name: Assemble Debug
- name: Assemble Android Debug
run: ./gradlew assembleDebug --stacktrace

assembleRelease:
assembleAndroidRelease:
runs-on: macos-latest

steps:
Expand All @@ -37,7 +37,7 @@ jobs:
distribution: 'zulu'
java-version: '17'

- name: Assemble Release
- name: Assemble Android Release
run: ./gradlew assembleRelease --stacktrace

# UI tests on CI are flaky
Expand All @@ -62,9 +62,9 @@ jobs:
# arch: x86_64
# script: ./gradlew connectedCheck --stacktrace

check:
test:
runs-on: macos-latest
needs: [assembleDebug, assembleRelease]
needs: [assembleAndroidDebug, assembleAndroidRelease]

steps:
- name: Checkout code
Expand All @@ -76,12 +76,12 @@ jobs:
distribution: 'zulu'
java-version: '17'

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

detekt:
runs-on: macos-latest
needs: [assembleDebug, assembleRelease]
needs: [assembleAndroidDebug, assembleAndroidRelease]

steps:
- name: Checkout code
Expand Down
19 changes: 19 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,28 @@ captures/
.idea/navEditor.xml
.idea/other.xml
.idea/studiobot.xml
.idea/artifacts

.kotlin

# Xcode
*.xcodeproj/*
!*.xcodeproj/project.pbxproj
!*.xcodeproj/xcshareddata/
!*.xcodeproj/project.xcworkspace/
!*.xcworkspace/contents.xcworkspacedata
**/xcshareddata/WorkspaceSettings.xcsettings
xcuserdata
IDEWorkspaceChecks.plist

# CocoaPods
Pods/

# iOS App packaging
*.ipa
*.dSYM.zip
*.dSYM

# Keystore files
# Uncomment the following lines if you do not want to check your keystore files in.
#*.jks
Expand Down
3 changes: 1 addition & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ android-compileSdk = "34"
java-toolchain = "17"

compose = "1.6.11"
agp = "8.4.2"
agp = "8.3.2"
kotlin = "2.0.0"
publish = "0.29.0"
nexus-publish = "2.0.0"
api-validator = "0.16.3"
atomicfuGradlePlugin = "0.22.0"

Expand Down
5 changes: 0 additions & 5 deletions jsontree/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ kotlin {
publishLibraryVariants("release")
@OptIn(ExperimentalKotlinGradlePluginApi::class)
instrumentedTestVariant.sourceSetTree.set(KotlinSourceSetTree.test)
@OptIn(ExperimentalKotlinGradlePluginApi::class)
compilerOptions {
jvmTarget.set(JvmTarget.JVM_1_8)
}

@OptIn(ExperimentalKotlinGradlePluginApi::class)
instrumentedTestVariant {
Expand Down Expand Up @@ -90,7 +86,6 @@ kotlin {
}
}


android {
namespace = "com.sebastianneubauer.jsontree"
compileSdk = libs.versions.android.compileSdk.get().toInt()
Expand Down
17 changes: 14 additions & 3 deletions sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,13 @@ kotlin {

}



android {
namespace = "com.sebastianneubauer.jsontreesample"
compileSdk = 34

defaultConfig {
minSdk = 24
minSdk = 21
targetSdk = 34
}
sourceSets["main"].apply {
manifest.srcFile("src/androidMain/AndroidManifest.xml")
Expand All @@ -82,6 +81,18 @@ android {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
buildTypes {
getByName("release") {
isMinifyEnabled = true
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
//for testing only, don't do this in your app
signingConfig = signingConfigs.getByName("debug")
}
getByName("debug") {
applicationIdSuffix = ".debug"
signingConfig = signingConfigs.getByName("debug")
}
}
buildFeatures {
compose = true
}
Expand Down
103 changes: 66 additions & 37 deletions sample/src/commonMain/kotlin/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand All @@ -39,22 +40,23 @@ import com.sebastianneubauer.jsontree.defaultLightColors
import com.sebastianneubauer.jsontreesample.ui.theme.JsonTreeTheme
import org.jetbrains.compose.ui.tooling.preview.Preview


@Composable
internal fun App() = JsonTreeTheme {
MainScreen()
}

@OptIn(
ExperimentalMaterial3Api::class, ExperimentalFoundationApi::class, ExperimentalLayoutApi::class
ExperimentalMaterial3Api::class,
ExperimentalFoundationApi::class,
ExperimentalLayoutApi::class
)
@Composable
fun MainScreen() {

private fun MainScreen() {
Scaffold(
modifier = Modifier.safeDrawingPadding(),
topBar = {
CenterAlignedTopAppBar(
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(containerColor = Color.White),
title = {
Text(
modifier = Modifier.padding(horizontal = 16.dp),
Expand All @@ -68,7 +70,9 @@ fun MainScreen() {
contentWindowInsets = WindowInsets(top = 60.dp),
) { padding ->
Column(
modifier = Modifier.fillMaxSize().padding(padding)
modifier = Modifier
.fillMaxSize()
.padding(padding)
) {
var errorMessage: String? by remember { mutableStateOf(null) }
var json: String by remember { mutableStateOf(simpleJson) }
Expand All @@ -78,17 +82,24 @@ fun MainScreen() {
var showItemCount: Boolean by remember { mutableStateOf(true) }
var expandSingleChildren: Boolean by remember { mutableStateOf(true) }

FlowRow {
Button(modifier = Modifier.padding(horizontal = 8.dp), onClick = {
errorMessage = null
json = when (json) {
emptyJson -> simpleJson
simpleJson -> complexJson
complexJson -> invalidJson
invalidJson -> emptyJson
else -> throw IllegalStateException("No JSON selected!")
FlowRow(
modifier = Modifier
.fillMaxWidth()
.background(color = Color.White),
) {
Button(
modifier = Modifier.padding(horizontal = 8.dp),
onClick = {
errorMessage = null
json = when (json) {
emptyJson -> simpleJson
simpleJson -> complexJson
complexJson -> invalidJson
invalidJson -> emptyJson
else -> throw IllegalStateException("No JSON selected!")
}
}
}) {
) {
Text(
text = when (json) {
simpleJson -> "Simple Json"
Expand All @@ -100,36 +111,47 @@ fun MainScreen() {
)
}

Button(modifier = Modifier.padding(horizontal = 8.dp), onClick = {
val newState = when (initialState) {
TreeState.EXPANDED -> TreeState.COLLAPSED
TreeState.COLLAPSED -> TreeState.FIRST_ITEM_EXPANDED
TreeState.FIRST_ITEM_EXPANDED -> TreeState.EXPANDED
Button(
modifier = Modifier.padding(horizontal = 8.dp),
onClick = {
val newState = when (initialState) {
TreeState.EXPANDED -> TreeState.COLLAPSED
TreeState.COLLAPSED -> TreeState.FIRST_ITEM_EXPANDED
TreeState.FIRST_ITEM_EXPANDED -> TreeState.EXPANDED
}
initialState = newState
}
initialState = newState
}) {
) {
Text(text = initialState.name)
}

Button(modifier = Modifier.padding(horizontal = 8.dp),
onClick = { showIndices = !showIndices }) {
Button(
modifier = Modifier.padding(horizontal = 8.dp),
onClick = { showIndices = !showIndices }
) {
Text(text = if (showIndices) "Hide indices" else "Show indices")
}

Button(modifier = Modifier.padding(horizontal = 8.dp),
onClick = { showItemCount = !showItemCount }) {
Button(
modifier = Modifier.padding(horizontal = 8.dp),
onClick = { showItemCount = !showItemCount }
) {
Text(text = if (showItemCount) "Hide item count" else "Show item count")
}

Button(modifier = Modifier.padding(horizontal = 8.dp), onClick = {
colors =
if (colors == defaultLightColors) defaultDarkColors else defaultLightColors
}) {
Button(
modifier = Modifier.padding(horizontal = 8.dp),
onClick = {
colors = if (colors == defaultLightColors) defaultDarkColors else defaultLightColors
}
) {
Text(text = if (colors == defaultLightColors) "Light" else "Dark")
}

Button(modifier = Modifier.padding(horizontal = 8.dp),
onClick = { expandSingleChildren = !expandSingleChildren }) {
Button(
modifier = Modifier.padding(horizontal = 8.dp),
onClick = { expandSingleChildren = !expandSingleChildren }
) {
Text(text = if (expandSingleChildren) "Expand children" else "Don't expand children")
}
}
Expand All @@ -147,12 +169,20 @@ fun MainScreen() {
val error = errorMessage
if (error != null) {
Text(
text = error, color = Color.Black
modifier = Modifier
.fillMaxSize()
.background(
color = if (colors == defaultLightColors) Color.White else Color.Black
),
text = error,
color = if (colors == defaultLightColors) Color.Black else Color.White,
)
} else {
JsonTree(
modifier = Modifier.fillMaxSize()
.horizontalScroll(rememberScrollState()).background(
modifier = Modifier
.fillMaxSize()
.horizontalScroll(rememberScrollState())
.background(
if (colors == defaultLightColors) Color.White else Color.Black
),
contentPadding = PaddingValues(16.dp),
Expand Down Expand Up @@ -191,9 +221,8 @@ fun MainScreen() {
}
}


@Preview
@Composable
fun PreviewMainScreen() = JsonTreeTheme {
private fun PreviewMainScreen() = JsonTreeTheme {
MainScreen()
}