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
47 changes: 47 additions & 0 deletions androidApp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
plugins {
alias(libs.plugins.androidApplication)
alias(libs.plugins.composeCompiler)
}

android {
namespace = "dev.skymansandy.jsoncmpsample"
compileSdk {
version = release(36)
}

defaultConfig {
applicationId = "dev.skymansandy.jsoncmpsample"
minSdk = 24
targetSdk = 36
versionCode = 1
versionName = "1.0"
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
buildFeatures {
compose = true
}
}

dependencies {
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.activity.compose)
implementation(platform(libs.androidx.compose.bom))
implementation(libs.compose.ui)
implementation(libs.compose.material3)
implementation(libs.compose.uiToolingPreview)
debugImplementation(libs.compose.uiTooling)
implementation(project(":composeApp"))
}
21 changes: 21 additions & 0 deletions androidApp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.JsonCmpSample">

<activity
android:exported="true"
android:name=".JsonCmpSampleActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package dev.skymansandy.jsoncmpsample

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import dev.skymansandy.jsoncmpsample.ui.App

internal class JsonCmpSampleActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
App()
}
}
}
4 changes: 4 additions & 0 deletions androidApp/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">JsonCMP Sample</string>
</resources>
8 changes: 8 additions & 0 deletions androidApp/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.JsonCmpSample" parent="android:Theme.Material.Light.NoActionBar">
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
</style>
</resources>
116 changes: 0 additions & 116 deletions composeApp/src/commonMain/kotlin/dev/skymansandy/jsoncmpsample/App.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package dev.skymansandy.jsoncmpsample.data

val sampleJson = """
{
"name": "JsonCMP",
"version": "1.0.0",
"description": "Kotlin Multiplatform Compose JSON viewer and editor",
"platforms": ["Android", "iOS", "JVM Desktop"],
"features": {
"viewer": true,
"editor": true,
"search": true,
"folding": true,
"sorting": true
},
"themes": [
{"name": "Dark", "type": "dark"},
{"name": "Light", "type": "light"},
{"name": "Monokai", "type": "dark"},
{"name": "Dracula", "type": "dark"},
{"name": "Solarized Dark", "type": "dark"}
],
"author": {
"name": "skymansandy",
"github": "https://github.com/skymansandy"
},
"license": "Apache-2.0",
"stars": null
}
""".trimIndent()
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package dev.skymansandy.jsoncmpsample.model

import dev.skymansandy.jsoncmp.helper.constants.colors.JsonCmpColors

enum class ThemeOption(val label: String, val colors: JsonCmpColors) {
Dark("Dark", JsonCmpColors.Dark),
Light("Light", JsonCmpColors.Light),
Monokai("Monokai", JsonCmpColors.Monokai),
Dracula("Dracula", JsonCmpColors.Dracula),
SolarizedDark("Solarized", JsonCmpColors.SolarizedDark),
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package dev.skymansandy.jsoncmpsample.ui

import androidx.compose.foundation.background
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.FilterChip
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.MaterialTheme.typography
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.darkColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import dev.skymansandy.jsoncmp.JsonCMP
import dev.skymansandy.jsoncmp.config.rememberJsonEditorState
import dev.skymansandy.jsoncmpsample.data.sampleJson
import dev.skymansandy.jsoncmpsample.model.ThemeOption

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun App() {
MaterialTheme(
colorScheme = darkColorScheme(),
) {
Scaffold(
topBar = {
TopAppBar(
title = { Text("JsonCMP Sample") },
)
},
) {
var searchQuery by remember { mutableStateOf("") }
var selectedTheme by remember { mutableStateOf(ThemeOption.Dark) }
val state = rememberJsonEditorState(
initialJson = sampleJson,
isEditing = true,
)

Column(
modifier = Modifier
.fillMaxSize()
.background(selectedTheme.colors.background)
.padding(it),
) {
Row(
modifier = Modifier
.fillMaxWidth()
.horizontalScroll(rememberScrollState())
.padding(horizontal = 8.dp, vertical = 4.dp),
horizontalArrangement = Arrangement.spacedBy(4.dp),
) {
ThemeOption.entries.forEach { theme ->
FilterChip(
selected = selectedTheme == theme,
onClick = { selectedTheme = theme },
label = { Text(theme.label) },
)
}
}

Row(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 8.dp, vertical = 4.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(8.dp),
) {
OutlinedTextField(
value = searchQuery,
onValueChange = { searchQuery = it },
modifier = Modifier.weight(1f),
label = { Text("Search") },
singleLine = true,
)
Column(
horizontalAlignment = Alignment.CenterHorizontally,
) {
Switch(
checked = state.isEditing,
onCheckedChange = { state.isEditing = it },
)
Text(
text = if (state.isEditing) "Edit" else "View",
style = typography.labelSmall,
)
}
}

JsonCMP(
modifier = Modifier
.fillMaxWidth()
.weight(1f),
state = state,
searchQuery = searchQuery,
colors = selectedTheme.colors,
)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.skymansandy.jsoncmpsample

import androidx.compose.ui.window.ComposeUIViewController
import dev.skymansandy.jsoncmpsample.ui.App

@Suppress("FunctionNaming")
fun MainViewController() = ComposeUIViewController { App() }
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dev.skymansandy.jsoncmpsample

import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application
import dev.skymansandy.jsoncmpsample.ui.App

fun main() {
application {
Expand Down
Loading
Loading