Skip to content

Commit

Permalink
1.添加资源加载
Browse files Browse the repository at this point in the history
问题:compose插件会根据CompseApp下/composeResources/里的文件生成Res类和Resource0类,但是在lib-module下iosApp使用会报错MissingResourceException。JetBrains/compose-multiplatform#4392
解决:暂时使用接口HDResProvider依赖注入ComposeApp生成的资源。同时引入ksp想通过ksp自动生成HDResProvider的实现类,避免手动注入。
2.引入voyager完成导航功能。
3.添加设备列表、添加设备页面。
  • Loading branch information
LaputaZeej committed Mar 14, 2024
1 parent e51f2f2 commit 8e125ff
Show file tree
Hide file tree
Showing 159 changed files with 6,723 additions and 657 deletions.
11 changes: 11 additions & 0 deletions composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.androidApplication)
alias(libs.plugins.jetbrainsCompose)
alias(libs.plugins.ksp)
}

kotlin {
Expand Down Expand Up @@ -33,6 +34,7 @@ kotlin {
baseName = "ComposeApp"
isStatic = false
}

compilations.all {
kotlinOptions.freeCompilerArgs += arrayOf("-linker-options", "-lsqlite3")
}
Expand All @@ -45,19 +47,23 @@ kotlin {
androidMain.dependencies {
implementation(libs.compose.ui.tooling.preview)
implementation(libs.androidx.activity.compose)

}
commonMain.dependencies {
implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.material)
implementation(compose.material3)
implementation(compose.ui)
implementation(compose.components.resources)
implementation(compose.components.uiToolingPreview)
implementation(projects.shared)
//
implementation(projects.hdcontext)
implementation(projects.hdcommon)
implementation(projects.hdresource)
}

desktopMain.dependencies {
implementation(compose.desktop.currentOs)
}
Expand Down Expand Up @@ -109,3 +115,8 @@ compose.desktop {
}
}
}

dependencies {
ksp(projects.hdresourceKsp)
implementation(projects.hdresource)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package com.yunext.virtuals
import android.app.Application
import com.yunext.kmp.common.logger.HDLogger
import com.yunext.kmp.context.initHDContext
import com.yunext.virtuals.ui.initHDRes

class HDApp : Application() {
override fun onCreate() {
super.onCreate()
initHDContext(){
HDLogger.debug = true
this.init(this@HDApp)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.yunext.virtuals

import App
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
package com.yunext.virtuals

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.*
import com.yunext.kmp.common.logger.HDLogger
import com.yunext.virtuals.ui.initHDRes
import com.yunext.virtuals.ui.screen.VoyagerApp
import org.jetbrains.compose.ui.tooling.preview.Preview
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch

private val initApp:CoroutineScope.()->Unit = {
launch {
HDLogger.debug = true
initHDRes(HDResProviderImpl)
}
}

@Composable
@Preview
fun App() {

MaterialTheme {
// var showContent by remember { mutableStateOf(false) }
// Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) {
Expand All @@ -25,6 +38,16 @@ fun App() {
// }
// VoyagerDemoApp()
// SplashScreen()
VoyagerApp()
var hasInit by remember {
mutableStateOf(false)
}

LaunchedEffect(Unit) {
initApp()
hasInit = true
}
AnimatedVisibility(hasInit) {
VoyagerApp()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package com.yunext.virtuals

import com.yunext.kmp.resource.color.China
import com.yunext.virtuals.ui.HDRes
import com.yunext.virtuals.ui.HDResProvider
import hdvirtuals.composeapp.generated.resources.Res
import hdvirtuals.composeapp.generated.resources.ic_app
import hdvirtuals.composeapp.generated.resources.icon_app_hadlinks
import hdvirtuals.composeapp.generated.resources.icon_twins_4g
import hdvirtuals.composeapp.generated.resources.icon_twins_add_btn_click
import hdvirtuals.composeapp.generated.resources.icon_twins_add_btn_nor
import hdvirtuals.composeapp.generated.resources.icon_twins_add_click
import hdvirtuals.composeapp.generated.resources.icon_twins_add_nor
import hdvirtuals.composeapp.generated.resources.icon_twins_body_bg
import hdvirtuals.composeapp.generated.resources.icon_twins_checked
import hdvirtuals.composeapp.generated.resources.icon_twins_close_btn
import hdvirtuals.composeapp.generated.resources.icon_twins_close_click
import hdvirtuals.composeapp.generated.resources.icon_twins_close_nor
import hdvirtuals.composeapp.generated.resources.icon_twins_distribution_network
import hdvirtuals.composeapp.generated.resources.icon_twins_fail
import hdvirtuals.composeapp.generated.resources.icon_twins_label_bg
import hdvirtuals.composeapp.generated.resources.icon_twins_label_short_bg
import hdvirtuals.composeapp.generated.resources.icon_twins_log
import hdvirtuals.composeapp.generated.resources.icon_twins_more_click
import hdvirtuals.composeapp.generated.resources.icon_twins_more_nor
import hdvirtuals.composeapp.generated.resources.icon_twins_no_data
import hdvirtuals.composeapp.generated.resources.icon_twins_no_device
import hdvirtuals.composeapp.generated.resources.icon_twins_offline
import hdvirtuals.composeapp.generated.resources.icon_twins_on_btn
import hdvirtuals.composeapp.generated.resources.icon_twins_refresh
import hdvirtuals.composeapp.generated.resources.icon_twins_return_click
import hdvirtuals.composeapp.generated.resources.icon_twins_return_nor
import hdvirtuals.composeapp.generated.resources.icon_twins_search
import hdvirtuals.composeapp.generated.resources.icon_twins_search_close
import hdvirtuals.composeapp.generated.resources.icon_twins_set_up
import hdvirtuals.composeapp.generated.resources.icon_twins_success
import hdvirtuals.composeapp.generated.resources.icon_twins_uncheck
import hdvirtuals.composeapp.generated.resources.icon_twins_wifi
import org.jetbrains.compose.resources.DrawableResource
import org.jetbrains.compose.resources.ExperimentalResourceApi



//@Deprecated("todo with ksp")
//@HDResource("drawable")
//interface DrawableProvider : HDResProvider

@OptIn(ExperimentalResourceApi::class)
object HDResProviderImpl : HDResProvider {
override val HDRes.drawable.ic_app: DrawableResource
get() = Res.drawable.ic_app
override val HDRes.drawable.icon_app_hadlinks: DrawableResource
get() = Res.drawable.icon_app_hadlinks
override val HDRes.drawable.icon_twins_4g: DrawableResource
get() = Res.drawable.icon_twins_4g
override val HDRes.drawable.icon_twins_add_btn_click: DrawableResource
get() = Res.drawable.icon_twins_add_btn_click
override val HDRes.drawable.icon_twins_add_btn_nor: DrawableResource
get() = Res.drawable.icon_twins_add_btn_nor
override val HDRes.drawable.icon_twins_add_click: DrawableResource
get() = Res.drawable.icon_twins_add_click
override val HDRes.drawable.icon_twins_add_nor: DrawableResource
get() = Res.drawable.icon_twins_add_nor
override val HDRes.drawable.icon_twins_body_bg: DrawableResource
get() = Res.drawable.icon_twins_body_bg
override val HDRes.drawable.icon_twins_checked: DrawableResource
get() = Res.drawable.icon_twins_checked
override val HDRes.drawable.icon_twins_close_btn: DrawableResource
get() = Res.drawable.icon_twins_close_btn
override val HDRes.drawable.icon_twins_close_click: DrawableResource
get() = Res.drawable.icon_twins_close_click
override val HDRes.drawable.icon_twins_close_nor: DrawableResource
get() = Res.drawable.icon_twins_close_nor
override val HDRes.drawable.icon_twins_distribution_network: DrawableResource
get() = Res.drawable.icon_twins_distribution_network
override val HDRes.drawable.icon_twins_fail: DrawableResource
get() = Res.drawable.icon_twins_fail
override val HDRes.drawable.icon_twins_label_bg: DrawableResource
get() = Res.drawable.icon_twins_label_bg
override val HDRes.drawable.icon_twins_label_short_bg: DrawableResource
get() = Res.drawable.icon_twins_label_short_bg
override val HDRes.drawable.icon_twins_log: DrawableResource
get() = Res.drawable.icon_twins_log
override val HDRes.drawable.icon_twins_more_click: DrawableResource
get() = Res.drawable.icon_twins_more_click
override val HDRes.drawable.icon_twins_more_nor: DrawableResource
get() = Res.drawable.icon_twins_more_nor
override val HDRes.drawable.icon_twins_no_data: DrawableResource
get() = Res.drawable.icon_twins_no_data
override val HDRes.drawable.icon_twins_no_device: DrawableResource
get() = Res.drawable.icon_twins_no_device
override val HDRes.drawable.icon_twins_offline: DrawableResource
get() = Res.drawable.icon_twins_offline
override val HDRes.drawable.icon_twins_on_btn: DrawableResource
get() = Res.drawable.icon_twins_on_btn
override val HDRes.drawable.icon_twins_refresh: DrawableResource
get() = Res.drawable.icon_twins_refresh
override val HDRes.drawable.icon_twins_return_click: DrawableResource
get() = Res.drawable.icon_twins_return_click
override val HDRes.drawable.icon_twins_return_nor: DrawableResource
get() = Res.drawable.icon_twins_return_nor
override val HDRes.drawable.icon_twins_search: DrawableResource
get() = Res.drawable.icon_twins_search
override val HDRes.drawable.icon_twins_search_close: DrawableResource
get() = Res.drawable.icon_twins_search_close
override val HDRes.drawable.icon_twins_set_up: DrawableResource
get() = Res.drawable.icon_twins_set_up
override val HDRes.drawable.icon_twins_success: DrawableResource
get() = Res.drawable.icon_twins_success
override val HDRes.drawable.icon_twins_uncheck: DrawableResource
get() = Res.drawable.icon_twins_uncheck
override val HDRes.drawable.icon_twins_wifi: DrawableResource
get() = Res.drawable.icon_twins_wifi
}
2 changes: 1 addition & 1 deletion composeApp/src/desktopMain/kotlin/main.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import androidx.compose.runtime.Composable
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application
import com.yunext.virtuals.App

fun main() = application {
Window(onCloseRequest = ::exitApplication, title = "HDVirtuals") {
Expand Down
1 change: 1 addition & 0 deletions composeApp/src/iosMain/kotlin/MainViewController.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import androidx.compose.ui.window.ComposeUIViewController
import com.yunext.virtuals.App

fun MainViewController() = ComposeUIViewController { App() }
6 changes: 5 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ junit = "4.13.2"
kotlin = "1.9.22"
ktor = "2.3.9"
logback = "1.5.3"
ksp = "1.9.21-1.0.15" # ksp
ksp = "1.9.22-1.0.17" # ksp
kotlinpoet-ksp = "1.12.0"
kotlinpoet = "1.15.2"
nexus-publish = "2.0.0-rc-1" # publish lib
Expand Down Expand Up @@ -83,6 +83,7 @@ nexus-publish = { module = "io.github.gradle-nexus.publish-plugin:io.github.grad
ksp-api = { module = "com.google.devtools.ksp:symbol-processing-api", version.ref = "ksp" }
kotlinpoet-ksp = { module = "com.squareup:kotlinpoet-ksp", version.ref = "kotlinpoet-ksp" }
kotlinpoet = { module = "com.squareup:kotlinpoet", version.ref = "kotlinpoet" }
kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin" }

# kotlinx
kotlinx-datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version.ref = "kotlinx-datetime" }
Expand All @@ -91,6 +92,9 @@ androidx-core-i18n = { group = "androidx.core", name = "core-i18n", version.ref

kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" }
kotlinx-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "kotlinx-coroutines" }
# https://github.com/Kotlin/kotlinx.coroutines/blob/master/ui/coroutines-guide-ui.md
kotlinx-coroutines-swing = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-swing", version.ref = "kotlinx-coroutines" }
kotlinx-coroutines-javax = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-javax", version.ref = "kotlinx-coroutines" }

#sqlDelight
#sqlDelight-runtime = {module = "com.squareup.sqldelight:runtime", version.ref = "sqlDelight" }
Expand Down
1 change: 1 addition & 0 deletions hdcommon/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ kotlin {
val commonMain by getting {
dependencies {
//put your multiplatform dependencies here
implementation(libs.kotlinx.datetime)
}
}
val commonTest by getting {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.yunext.kmp.common.logger

import android.util.Log

actual interface HDLogger {
actual var debug: Boolean
actual fun d(tag: String, msg: String)
Expand All @@ -10,15 +12,23 @@ actual interface HDLogger {
actual companion object : HDLogger {
override var debug: Boolean = false
actual override fun d(tag: String, msg: String) {
if (!debug)return
Log.d(tag,msg)
}

actual override fun i(tag: String, msg: String) {
if (!debug)return
Log.i(tag,msg)
}

actual override fun w(tag: String, msg: String) {
if (!debug)return
Log.w(tag,msg)
}

actual override fun e(tag: String, msg: String) {
if (!debug)return
Log.e(tag,msg)
}

}
Expand Down
17 changes: 17 additions & 0 deletions hdcommon/src/commonMain/kotlin/com/yunext/kmp/common/TODO.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.yunext.kmp.common

@Retention(AnnotationRetention.SOURCE)
@Target(
AnnotationTarget.EXPRESSION,
AnnotationTarget.CLASS,
AnnotationTarget.FUNCTION,
AnnotationTarget.PROPERTY,
AnnotationTarget.ANNOTATION_CLASS,
AnnotationTarget.CONSTRUCTOR,
AnnotationTarget.PROPERTY_GETTER,
AnnotationTarget.PROPERTY_SETTER, AnnotationTarget.LOCAL_VARIABLE
)
@Repeatable
annotation class TODO(
val msg: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.yunext.kmp.common.util

import kotlinx.datetime.Clock

fun currentTime() = Clock.System.now().toEpochMilliseconds()
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@ actual interface HDLogger {
actual companion object : HDLogger {
override var debug: Boolean = false
actual override fun d(tag: String, msg: String) {
println("[$tag][D] $msg")
}

actual override fun i(tag: String, msg: String) {
println("[$tag][I] $msg")
}

actual override fun w(tag: String, msg: String) {
println("[$tag][W] $msg")
}

actual override fun e(tag: String, msg: String) {
println("[$tag][E] $msg")
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@ actual interface HDLogger {
actual companion object : HDLogger {
override var debug: Boolean = false
actual override fun d(tag: String, msg: String) {
println("[$tag][D] $msg")
}

actual override fun i(tag: String, msg: String) {
println("[$tag][I] $msg")
}

actual override fun w(tag: String, msg: String) {
println("[$tag][W] $msg")
}

actual override fun e(tag: String, msg: String) {
println("[$tag][E] $msg")
}

}
Expand Down
8 changes: 8 additions & 0 deletions hdhttp/src/commonMain/kotlin/com/yunext/kmp/http/LoginResp.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.yunext.kmp.http

import com.yunext.kmp.http.core.HttpResponse

data class LoginResp(
val token: String? = "",
val authCode: String? = "",
) : HttpResponse
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.yunext.kmp.http

class ProductResp {
}
Loading

0 comments on commit 8e125ff

Please sign in to comment.