Skip to content

Commit

Permalink
1.添加导航库voyager
Browse files Browse the repository at this point in the history
2.修复sqldelight Could not find "co.touchlab:stately-common的问题。见:sqldelight/sqldelight#4356 (comment)
  • Loading branch information
LaputaZeej committed Mar 12, 2024
1 parent 85b79aa commit e51f2f2
Show file tree
Hide file tree
Showing 56 changed files with 2,482 additions and 42 deletions.
50 changes: 20 additions & 30 deletions composeApp/src/commonMain/kotlin/App.kt
Original file line number Diff line number Diff line change
@@ -1,40 +1,30 @@
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material.Button
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import com.yunext.virtuals.ui.screen.DemoScreen
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.painterResource
import com.yunext.virtuals.ui.screen.VoyagerApp
import org.jetbrains.compose.ui.tooling.preview.Preview

import org.jetbrains.compose.resources.DrawableResource

@OptIn(ExperimentalResourceApi::class)
@Composable
@Preview
fun App() {
MaterialTheme {
var showContent by remember { mutableStateOf(false) }
Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) {

DemoScreen()
Button(onClick = { showContent = !showContent }) {
Text("Click me!")
}
AnimatedVisibility(showContent) {
val greeting = remember { Greeting().greet() }
Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) {
//Image(painterResource(Res.drawable.compose_multiplatform), null)
Image(painterResource(DrawableResource("compose-multiplatform.xml")), null)
Text("Compose: $greeting")
}
}
}
// var showContent by remember { mutableStateOf(false) }
// Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) {
//
// DemoScreen()
// Button(onClick = { showContent = !showContent }) {
// Text("Click me!")
// }
// AnimatedVisibility(showContent) {
// val greeting = remember { Greeting().greet() }
// Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) {
// //Image(painterResource(Res.drawable.compose_multiplatform), null)
// Image(painterResource(DrawableResource("compose-multiplatform.xml")), null)
// Text("Compose: $greeting")
// }
// }
// }
// VoyagerDemoApp()
// SplashScreen()
VoyagerApp()
}
}
26 changes: 26 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ kotlinx-coroutines = "1.8.0"
#sqlDelight = "1.5.5"
sqlDelight2 = "2.0.1"
sqlite = "3.42.0.0"
statelyCommon = "1.2.5"
voyager = "1.0.0"

koin = "3.4.3"
koin-compose = "1.0.4"
hilt = "2.49"

[libraries]
# test
Expand All @@ -53,10 +59,22 @@ ktor-server-core = { module = "io.ktor:ktor-server-core-jvm", version.ref = "kto
ktor-server-netty = { module = "io.ktor:ktor-server-netty-jvm", version.ref = "ktor" }
ktor-server-tests = { module = "io.ktor:ktor-server-tests-jvm", version.ref = "ktor" }
ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
ktor-client-cio = { module = "io.ktor:ktor-client-cio", version.ref = "ktor" }
ktor-client-okhttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "ktor" }
ktor-client-darwin = { module = "io.ktor:ktor-client-darwin", version.ref = "ktor" }
ktor-client-content-negotiation = { module = "io.ktor:ktor-client-content-negotiation", version.ref = "ktor" }
ktor-serialization-kotlinx-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktor" }
# voyager
voyager-navigator = { module = "cafe.adriel.voyager:voyager-navigator", version.ref = "voyager" }
voyager-screenModel = { module = "cafe.adriel.voyager:voyager-screenmodel", version.ref = "voyager" }
voyager-bottomSheetNavigator = { module = "cafe.adriel.voyager:voyager-bottom-sheet-navigator", version.ref = "voyager" }
voyager-tabNavigator = { module = "cafe.adriel.voyager:voyager-tab-navigator", version.ref = "voyager" }
voyager-transitions = { module = "cafe.adriel.voyager:voyager-transitions", version.ref = "voyager" }
voyager-koin = { module = "cafe.adriel.voyager:voyager-koin", version.ref = "voyager" }
voyager-hilt = { module = "cafe.adriel.voyager:voyager-hilt", version.ref = "voyager" }
voyager-kodein = { module = "cafe.adriel.voyager:voyager-kodein", version.ref = "voyager" }
voyager-rxjava = { module = "cafe.adriel.voyager:voyager-rxjava", version.ref = "voyager" }


# publish
nexus-publish = { module = "io.github.gradle-nexus.publish-plugin:io.github.gradle-nexus.publish-plugin.gradle.plugin", version.ref = "nexus-publish" } # publish lib
Expand Down Expand Up @@ -86,7 +104,15 @@ sqlDelight2-driver-android = { module = "app.cash.sqldelight:android-driver", ve
sqlDelight2-driver-native = { module = "app.cash.sqldelight:native-driver", version.ref = "sqlDelight2" }
sqlDelight2-driver-sqlite = { module = "app.cash.sqldelight:sqlite-driver", version.ref = "sqlDelight2" }
#sqlite = { module = "org.xerial:sqlite-jdbc", version.ref = "sqlite" }
sqlite-stately-common = { module = "co.touchlab:stately-common", version.ref = "statelyCommon" }
sqlite-stately-concurrency = { module = "co.touchlab:stately-concurrency", version.ref = "statelyCommon" }

# DI
#koin = { module = "io.insert-koin:koin-androidx-compose", version.ref = "koin" }
#koin-compose = { module = "io.insert-koin:koin-compose", version.ref = "koin-compose" }
#hilt-android = { module = "com.google.dagger:hilt-android", version.ref = "hilt" }
#hilt-compiler = { module = "com.google.dagger:hilt-compiler", version.ref = "hilt" }
#pluginHilt = { module = "com.google.dagger:hilt-android-gradle-plugin", version.ref = "hilt" }


[plugins]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ actual fun hdMD5(text: String, upperCase: Boolean): String? {

private const val BASE = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"

actual fun hdRandomString(length: Int): String {
actual fun hdUUID(length: Int): String {
require(length > 0) {
"hdRandomString length must > 0"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package com.yunext.kmp.common.util

expect fun hdMD5(text: String, upperCase: Boolean = false): String?
expect fun hdRandomString(length:Int): String
expect fun hdUUID(length:Int): String

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ actual fun hdMD5(text: String, upperCase: Boolean): String? {

private const val BASE = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"

actual fun hdRandomString(length: Int): String {
actual fun hdUUID(length: Int): String {
require(length > 0) {
"hdRandomString length must > 0"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ actual fun hdMD5(text: String, upperCase: Boolean): String? {

private const val BASE = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"

actual fun hdRandomString(length: Int): String {
actual fun hdUUID(length: Int): String {
require(length > 0) {
"hdRandomString length must > 0"
}
Expand Down
20 changes: 20 additions & 0 deletions hdcommon/src/jvmTest/kotlin/com/yunext/kmp/common/JvmLoggerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,29 @@ package com.yunext.kmp.common

import kotlin.test.Test

private data class Rect(val a: Int, val b: Int)
//private data class Rect2(val a: Int, val b: Int)

private operator fun (List<Rect>)?.plus(rect: Rect?): (List<Rect>) = listOf()
//private operator fun Rect?.plus(rect: Any?):Rect? = this?:Rect(0,0)
//private operator fun Rect?.plus(rect: Rect?) = Rect((this?.a ?: 0) + (rect?.a ?: 0), (this?.b ?: 0) + (rect?.b ?: 0))

//private operator fun Rect2?.plus(rect: Rect2?) =
// Rect2((this?.a ?: 0) + (rect?.a ?: 0), (this?.b ?: 0) + (rect?.b ?: 0))

private fun test() {
val c = null as? List<Rect>
val r = (null as? List<Rect>) + null
println("---> r = $r ")
// val a: Rect? = null
// val b: Rect? = null
// val ab = a + b
}

class JvmLoggerTest {

@Test
fun `test 3rd element`() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.yunext.kmp.common

internal data class Rect2(val a: Int, val b: Int)

internal operator fun Rect2?.plus(rect: Rect2?) = Rect2((this?.a ?: 0) + (rect?.a ?: 0), (this?.b ?: 0) + (rect?.b ?: 0))
2 changes: 2 additions & 0 deletions hddb/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ kotlin {
dependencies {
//put your multiplatform dependencies here
implementation(projects.hdcontext)
implementation(libs.sqlite.stately.common)
implementation(libs.sqlite.stately.concurrency)
}
}
val commonTest by getting {
Expand Down
22 changes: 22 additions & 0 deletions hdhttp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.androidLibrary)
alias(libs.plugins.kotlinSerialization)
//id("module.publication")
}

Expand All @@ -24,13 +25,34 @@ kotlin {
dependencies {
//put your multiplatform dependencies here
implementation(projects.hdcontext)

api(libs.kotlinx.datetime)
api(libs.kotlinx.coroutines.core)
api(libs.ktor.client.core)
api(libs.ktor.client.cio)
api(libs.ktor.client.content.negotiation)
api(libs.ktor.serialization.kotlinx.json)

}
}
val commonTest by getting {
dependencies {
implementation(libs.kotlin.test)
}
}

androidMain.dependencies {
api(libs.kotlinx.coroutines.android)
api(libs.ktor.client.okhttp)
}

iosMain.dependencies {
api(libs.ktor.client.darwin)
}

jvmMain.dependencies{
api(libs.ktor.client.okhttp)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.yunext.kmp.http

import io.ktor.client.request.get
import io.ktor.client.statement.bodyAsText

suspend fun testKtor(): String {
// val response = client.get("https://ktor.io/docs/")
// val response = client.get("https://iot2.qinyuan.cn/web/api/common/getAdvertisement")
// val response = hdHttpClient.get("https://www.baidu.com")
val response =
hdHttpClient.get("https://iot2.qinyuan.cn/web/api/common/getFiles/64c763bd93b173b23a289558 ")
return "findAll" + "\n" + response.bodyAsText()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.yunext.kmp.http

import io.ktor.client.HttpClient
import io.ktor.client.engine.cio.CIO

val hdHttpClient by lazy {
HttpClient(CIO)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.yunext.kmp.http

import kotlinx.coroutines.runBlocking
import org.junit.Test


class HDHttpClientJVMTest {

@Test
fun t1(){
runBlocking {
val result = testKtor()
println("result :$result")
assert(result.isNotEmpty())
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.yunext.kmp.resource.color

import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color

val xf98 = Color(0xFFFF9988)
val x98f = Color(0xFF8899ff)
val x9f8 = Color(0xFF99ff88)

val app_blue_1 = Color(0xff00DBE5)
val app_blue_2 = Color(0xff339DFF)
val app_appColor = Color(0xff339DFF)
val app_textColor_333333 = Color(0xff333333)
val app_textColor_666666 = Color(0xff666666)
val app_textColor_999999 = Color(0xff999999)
val app_red = Color(0xffEC6161)
val app_red_light = app_red.copy(alpha = .1f)
val app_orange = Color(0xffFFA70B)
val app_orange_light = Color(0xffFFA70B).copy(alpha = .15f)
val app_blue_light = app_appColor.copy(alpha = .1f)
val app_gray = Color(0xffDEDFE0)
val app_gray_f4f5f7 = Color(0xffF4F5F7)
val app_gray_light = app_gray.copy(alpha = .6f)
val app_background_70 = Color(1f, 1f, 1f, 0.7f)


val app_brush_item_content_spec = Brush.verticalGradient(colors = listOf(Color(0xffF7F8FA), Color(0xFFEFF0F2)))
val app_background_brush = Brush.verticalGradient(colors = listOf(Color(0xFFF4F7FB), Color(0xFFF0F4FC)))
val app_button_brush = Brush.linearGradient(colors = listOf(app_blue_1, app_blue_2))
val app_button_brush_debug = Brush.linearGradient(colors = listOf(China.r_yan_zhi_hong, China.g_bo_he_lv))
49 changes: 49 additions & 0 deletions hdui/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.androidLibrary)
alias(libs.plugins.jetbrainsCompose)
}

kotlin {
targetHierarchy.default()
jvm()
androidTarget {
compilations.all {
kotlinOptions {
jvmTarget = "1.8"
}
}
}
iosX64()
iosArm64()
iosSimulatorArm64()

sourceSets {
val commonMain by getting {
dependencies {
//put your multiplatform dependencies here
implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.material3)
implementation(compose.ui)
implementation(compose.components.resources)
// implementation(compose.components.uiToolingPreview)

implementation(projects.hdresource)
}
}
val commonTest by getting {
dependencies {
implementation(libs.kotlin.test)
}
}
}
}

android {
namespace = "org.jetbrains.kotlinx.multiplatform.library.template"
compileSdk = libs.versions.android.compileSdk.get().toInt()
defaultConfig {
minSdk = libs.versions.android.minSdk.get().toInt()
}
}
Loading

0 comments on commit e51f2f2

Please sign in to comment.