From 247db57c5b289e4c4f8dfab9bc8d9b53baaf7aff Mon Sep 17 00:00:00 2001 From: 985892345 Date: Wed, 1 Jan 2025 21:10:48 +0800 Subject: [PATCH 1/4] =?UTF-8?q?:construction:=20login=20=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E5=88=9D=E6=AD=A5=E9=87=8D=E6=9E=84=E4=B8=BA=20compose?= =?UTF-8?q?=EF=BC=88=E6=9A=82=E6=97=B6=E4=BE=9D=E8=B5=96=E5=86=B2=E7=AA=81?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/kotlin/manager.app.gradle.kts | 1 - .../src/main/kotlin/kmp.compose.gradle.kts | 1 + .../src/desktopMain/kotlin/CyxbsDesktopApp.kt | 15 +- .../src/wasmJsMain/kotlin/CyxbsWasmJsApp.kt | 11 +- .../test/src/wasmJsMain/resources/index.html | 5 +- ...eViewModel.kt => BaseViewModel.android.kt} | 27 +- .../cyxbs/components/base/ui/BaseViewModel.kt | 39 + .../cyxbs/components/base/utils/ToastUtils.kt | 10 +- .../base/ui/BaseViewModel.desktop.kt | 11 + .../base/ui/BaseViewModel.wasmJs.kt | 9 + cyxbs-components/config/build.gradle.kts | 1 + .../cyxbs/components/config/color/AppColor.kt | 35 + .../utils/compose/Window.android.kt | 20 + .../utils/extensions/Log.android.kt | 13 + .../extensions/{Toast.kt => Toast.android.kt} | 30 +- .../cyxbs/components/utils/compose/Color.kt | 47 +- .../cyxbs/components/utils/compose/Window.kt | 14 + .../cyxbs/components/utils/extensions/Log.kt | 14 + .../components/utils/extensions/Toast.kt | 18 + .../utils/compose/Window.desktop.kt | 21 + .../utils/extensions/Log.desktop.kt | 11 + .../utils/extensions/Toast.desktop.kt | 8 + .../components/utils/compose/Window.wasmJs.kt | 21 + .../components/utils/extensions/Log.wasmJs.kt | 11 + .../utils/extensions/Toast.wasmJs.kt | 10 + .../grades/ui/viewModel/ContainerViewModel.kt | 1 + cyxbs-pages/login/build.gradle.kts | 1 + .../pages/login/login/ui/LoginActivity.kt | 228 +-- .../login/login/viewmodel/LoginViewModel.kt | 109 - .../pages/login/network/LoginApiService.kt | 4 +- .../login/viewmodel/LoginViewModel.android.kt | 134 ++ .../drawable/login_ic_password.xml | 18 + .../drawable/login_ic_username.xml | 18 + .../files/lottie_check_login.json | 704 +++++++ .../files/lottie_login_anim.json | 1755 +++++++++++++++++ .../com/cyxbs/pages/login/ui/LoginCmpose.kt | 533 +++++ .../pages/login/viewmodel/LoginViewModel.kt | 60 + .../login/viewmodel/LoginViewModel.desktop.kt | 25 + .../login/viewmodel/LoginViewModel.wasmJs.kt | 25 + .../map/ui/fragment/FavoriteEditFragment.kt | 2 +- .../cyxbs/pages/map/viewmodel/MapViewModel.kt | 1 + .../news/ui/activity/NewsItemActivity.kt | 1 + .../todo/ui/activity/TodoDetailActivity.kt | 9 +- .../todo/ui/dialog/SelectRepeatDialog.kt | 4 +- .../widget/widget/normal/NormalWidget.kt | 5 +- gradle.properties | 2 +- gradle/libs.versions.toml | 10 +- .../cyxbs/common/ExampleInstrumentedTest.java | 27 - .../cyxbs/common/component/CyxbsToast.java | 2 +- .../cyxbs/common/ExampleUnitTest.java | 17 - 50 files changed, 3642 insertions(+), 456 deletions(-) rename cyxbs-components/base/src/androidMain/kotlin/com/cyxbs/components/base/ui/{BaseViewModel.kt => BaseViewModel.android.kt} (86%) create mode 100644 cyxbs-components/base/src/commonMain/kotlin/com/cyxbs/components/base/ui/BaseViewModel.kt rename cyxbs-components/base/src/{androidMain => commonMain}/kotlin/com/cyxbs/components/base/utils/ToastUtils.kt (60%) create mode 100644 cyxbs-components/base/src/desktopMain/kotlin/com/cyxbs/components/base/ui/BaseViewModel.desktop.kt create mode 100644 cyxbs-components/base/src/wasmJsMain/kotlin/com/cyxbs/components/base/ui/BaseViewModel.wasmJs.kt create mode 100644 cyxbs-components/config/src/commonMain/kotlin/com/cyxbs/components/config/color/AppColor.kt create mode 100644 cyxbs-components/utils/src/androidMain/kotlin/com/cyxbs/components/utils/compose/Window.android.kt create mode 100644 cyxbs-components/utils/src/androidMain/kotlin/com/cyxbs/components/utils/extensions/Log.android.kt rename cyxbs-components/utils/src/androidMain/kotlin/com/cyxbs/components/utils/extensions/{Toast.kt => Toast.android.kt} (83%) create mode 100644 cyxbs-components/utils/src/commonMain/kotlin/com/cyxbs/components/utils/compose/Window.kt create mode 100644 cyxbs-components/utils/src/commonMain/kotlin/com/cyxbs/components/utils/extensions/Log.kt create mode 100644 cyxbs-components/utils/src/commonMain/kotlin/com/cyxbs/components/utils/extensions/Toast.kt create mode 100644 cyxbs-components/utils/src/desktopMain/kotlin/com/cyxbs/components/utils/compose/Window.desktop.kt create mode 100644 cyxbs-components/utils/src/desktopMain/kotlin/com/cyxbs/components/utils/extensions/Log.desktop.kt create mode 100644 cyxbs-components/utils/src/desktopMain/kotlin/com/cyxbs/components/utils/extensions/Toast.desktop.kt create mode 100644 cyxbs-components/utils/src/wasmJsMain/kotlin/com/cyxbs/components/utils/compose/Window.wasmJs.kt create mode 100644 cyxbs-components/utils/src/wasmJsMain/kotlin/com/cyxbs/components/utils/extensions/Log.wasmJs.kt create mode 100644 cyxbs-components/utils/src/wasmJsMain/kotlin/com/cyxbs/components/utils/extensions/Toast.wasmJs.kt delete mode 100644 cyxbs-pages/login/src/androidMain/kotlin/com/cyxbs/pages/login/login/viewmodel/LoginViewModel.kt create mode 100644 cyxbs-pages/login/src/androidMain/kotlin/com/cyxbs/pages/login/viewmodel/LoginViewModel.android.kt create mode 100644 cyxbs-pages/login/src/commonMain/composeResources/drawable/login_ic_password.xml create mode 100644 cyxbs-pages/login/src/commonMain/composeResources/drawable/login_ic_username.xml create mode 100644 cyxbs-pages/login/src/commonMain/composeResources/files/lottie_check_login.json create mode 100644 cyxbs-pages/login/src/commonMain/composeResources/files/lottie_login_anim.json create mode 100644 cyxbs-pages/login/src/commonMain/kotlin/com/cyxbs/pages/login/ui/LoginCmpose.kt create mode 100644 cyxbs-pages/login/src/commonMain/kotlin/com/cyxbs/pages/login/viewmodel/LoginViewModel.kt create mode 100644 cyxbs-pages/login/src/desktopMain/kotlin/com/cyxbs/pages/login/viewmodel/LoginViewModel.desktop.kt create mode 100644 cyxbs-pages/login/src/wasmJsMain/kotlin/com/cyxbs/pages/login/viewmodel/LoginViewModel.wasmJs.kt delete mode 100644 lib_common/src/androidTest/java/com/mredrock/cyxbs/common/ExampleInstrumentedTest.java delete mode 100644 lib_common/src/test/java/com/mredrock/cyxbs/common/ExampleUnitTest.java diff --git a/build-logic/manager/src/main/kotlin/manager.app.gradle.kts b/build-logic/manager/src/main/kotlin/manager.app.gradle.kts index 3ea2b7c26d..d55781a7a1 100644 --- a/build-logic/manager/src/main/kotlin/manager.app.gradle.kts +++ b/build-logic/manager/src/main/kotlin/manager.app.gradle.kts @@ -1,6 +1,5 @@ import org.jetbrains.compose.desktop.application.dsl.TargetFormat import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl -import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig import rule.ModuleNamespaceCheckRule plugins { diff --git a/build-logic/plugin/kmp/src/main/kotlin/kmp.compose.gradle.kts b/build-logic/plugin/kmp/src/main/kotlin/kmp.compose.gradle.kts index be53b71012..b29354e826 100644 --- a/build-logic/plugin/kmp/src/main/kotlin/kmp.compose.gradle.kts +++ b/build-logic/plugin/kmp/src/main/kotlin/kmp.compose.gradle.kts @@ -18,6 +18,7 @@ kotlin { implementation(compose.materialIconsExtended) implementation(libsEx.`compose-navigation`) implementation(libsEx.`compose-lifecycle`) + implementation(libsEx.`compose-constraintLayout`) } androidMain.dependencies { diff --git a/cyxbs-applications/test/src/desktopMain/kotlin/CyxbsDesktopApp.kt b/cyxbs-applications/test/src/desktopMain/kotlin/CyxbsDesktopApp.kt index 098758c7c1..942552734d 100644 --- a/cyxbs-applications/test/src/desktopMain/kotlin/CyxbsDesktopApp.kt +++ b/cyxbs-applications/test/src/desktopMain/kotlin/CyxbsDesktopApp.kt @@ -1,15 +1,10 @@ -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.material3.Text import androidx.compose.runtime.remember -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp -import androidx.compose.ui.unit.sp import androidx.compose.ui.window.Window import androidx.compose.ui.window.launchApplication import androidx.compose.ui.window.rememberWindowState import com.cyxbs.components.utils.coroutine.runApp +import com.cyxbs.pages.login.ui.LoginCompose import com.g985892345.provider.cyxbsmobile.cyxbsapplications.test.TestKtProviderInitializer /** @@ -22,7 +17,7 @@ import com.g985892345.provider.cyxbsmobile.cyxbsapplications.test.TestKtProvider fun main() = runApp { TestKtProviderInitializer.tryInitKtProvider() launchApplication { - val width = 1000 + val width = 800 val height = 600 Window( onCloseRequest = ::exitApplication, @@ -31,11 +26,9 @@ fun main() = runApp { // resizable = false, ) { remember { -// this.window.minimumSize = java.awt.Dimension(width, height) - } - Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { - Text(text = "桌上重邮", fontSize = 20.sp) + this.window.minimumSize = java.awt.Dimension(300, 600) } + LoginCompose() } } } \ No newline at end of file diff --git a/cyxbs-applications/test/src/wasmJsMain/kotlin/CyxbsWasmJsApp.kt b/cyxbs-applications/test/src/wasmJsMain/kotlin/CyxbsWasmJsApp.kt index 942e82b428..3ecbb2e295 100644 --- a/cyxbs-applications/test/src/wasmJsMain/kotlin/CyxbsWasmJsApp.kt +++ b/cyxbs-applications/test/src/wasmJsMain/kotlin/CyxbsWasmJsApp.kt @@ -1,12 +1,7 @@ -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.material.MaterialTheme -import androidx.compose.material.Text -import androidx.compose.ui.Alignment import androidx.compose.ui.ExperimentalComposeUiApi -import androidx.compose.ui.Modifier -import androidx.compose.ui.unit.sp import androidx.compose.ui.window.ComposeViewport +import com.cyxbs.pages.login.ui.LoginCompose import com.g985892345.provider.cyxbsmobile.cyxbsapplications.test.TestKtProviderInitializer import kotlinx.browser.document @@ -26,9 +21,7 @@ fun main() { MaterialTheme( typography = createTypography(), ) { - Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { - Text(text = "网上重邮", fontSize = 20.sp) - } + LoginCompose() } } } \ No newline at end of file diff --git a/cyxbs-applications/test/src/wasmJsMain/resources/index.html b/cyxbs-applications/test/src/wasmJsMain/resources/index.html index 3cac513ce5..fccd46641c 100644 --- a/cyxbs-applications/test/src/wasmJsMain/resources/index.html +++ b/cyxbs-applications/test/src/wasmJsMain/resources/index.html @@ -14,13 +14,12 @@ \ No newline at end of file diff --git a/cyxbs-components/base/src/androidMain/kotlin/com/cyxbs/components/base/ui/BaseViewModel.kt b/cyxbs-components/base/src/androidMain/kotlin/com/cyxbs/components/base/ui/BaseViewModel.android.kt similarity index 86% rename from cyxbs-components/base/src/androidMain/kotlin/com/cyxbs/components/base/ui/BaseViewModel.kt rename to cyxbs-components/base/src/androidMain/kotlin/com/cyxbs/components/base/ui/BaseViewModel.android.kt index 2475cffb14..fc433d8ab5 100644 --- a/cyxbs-components/base/src/androidMain/kotlin/com/cyxbs/components/base/ui/BaseViewModel.kt +++ b/cyxbs-components/base/src/androidMain/kotlin/com/cyxbs/components/base/ui/BaseViewModel.android.kt @@ -11,18 +11,11 @@ import androidx.lifecycle.viewmodel.initializer import androidx.lifecycle.viewmodel.viewModelFactory import com.cyxbs.components.init.appApplication import com.cyxbs.components.base.utils.RxjavaLifecycle -import com.cyxbs.components.base.utils.ToastUtils import io.reactivex.rxjava3.disposables.CompositeDisposable import io.reactivex.rxjava3.disposables.Disposable -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.CoroutineStart -import kotlinx.coroutines.Job -import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.launch -import kotlin.coroutines.CoroutineContext -import kotlin.coroutines.EmptyCoroutineContext /** * @@ -96,7 +89,7 @@ import kotlin.coroutines.EmptyCoroutineContext * * # 更多封装请往父类和接口查看 */ -abstract class BaseViewModel : ViewModel(), RxjavaLifecycle, ToastUtils { +actual abstract class BaseViewModel : CommonBaseViewModel(), RxjavaLifecycle { val appContext: Context get() = appApplication @@ -108,13 +101,6 @@ abstract class BaseViewModel : ViewModel(), RxjavaLifecycle, ToastUtils { super.onCleared() mDisposables.clear() } - - /** - * 开启协程并收集 Flow - */ - protected fun Flow.collectLaunch(action: suspend (value: T) -> Unit): Job = launch { - collect{ action.invoke(it) } - } /** * 返回一个缓存值为 0 表示事件的 SharedFlow,不会因为 Activity 重建而出现数据倒灌问题 @@ -132,17 +118,6 @@ abstract class BaseViewModel : ViewModel(), RxjavaLifecycle, ToastUtils { } return sharedFlow } - - - protected fun launch( - context: CoroutineContext = EmptyCoroutineContext, - start: CoroutineStart = CoroutineStart.DEFAULT, - block: suspend CoroutineScope.() -> Unit - ): Job = viewModelScope.launch(context, start, block) - - - - /** * 实现 [RxjavaLifecycle] 的方法,用于带有生命周期的调用 diff --git a/cyxbs-components/base/src/commonMain/kotlin/com/cyxbs/components/base/ui/BaseViewModel.kt b/cyxbs-components/base/src/commonMain/kotlin/com/cyxbs/components/base/ui/BaseViewModel.kt new file mode 100644 index 0000000000..678ff5ff37 --- /dev/null +++ b/cyxbs-components/base/src/commonMain/kotlin/com/cyxbs/components/base/ui/BaseViewModel.kt @@ -0,0 +1,39 @@ +package com.cyxbs.components.base.ui + +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import com.cyxbs.components.base.utils.ToastUtils +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.CoroutineStart +import kotlinx.coroutines.Job +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.launch +import kotlin.coroutines.CoroutineContext +import kotlin.coroutines.EmptyCoroutineContext + +/** + * commonMain 下的 ViewModel + * + * @author 985892345 + * @date 2024/12/31 + */ +expect abstract class BaseViewModel() : CommonBaseViewModel + +abstract class CommonBaseViewModel : ViewModel(), ToastUtils { + + /** + * 开启协程并收集 Flow + */ + protected fun Flow.collectLaunch(action: suspend (value: T) -> Unit): Job = launch { + collect{ action.invoke(it) } + } + + /** + * ViewModel 下开启协程 + */ + protected fun launch( + context: CoroutineContext = EmptyCoroutineContext, + start: CoroutineStart = CoroutineStart.DEFAULT, + block: suspend CoroutineScope.() -> Unit + ): Job = viewModelScope.launch(context, start, block) +} \ No newline at end of file diff --git a/cyxbs-components/base/src/androidMain/kotlin/com/cyxbs/components/base/utils/ToastUtils.kt b/cyxbs-components/base/src/commonMain/kotlin/com/cyxbs/components/base/utils/ToastUtils.kt similarity index 60% rename from cyxbs-components/base/src/androidMain/kotlin/com/cyxbs/components/base/utils/ToastUtils.kt rename to cyxbs-components/base/src/commonMain/kotlin/com/cyxbs/components/base/utils/ToastUtils.kt index d70df5b7cf..2f3c535d1b 100644 --- a/cyxbs-components/base/src/androidMain/kotlin/com/cyxbs/components/base/utils/ToastUtils.kt +++ b/cyxbs-components/base/src/commonMain/kotlin/com/cyxbs/components/base/utils/ToastUtils.kt @@ -1,10 +1,5 @@ package com.cyxbs.components.base.utils -import android.widget.Toast -import androidx.annotation.StringRes -import com.cyxbs.components.utils.extensions.CyxbsToast -import com.cyxbs.components.utils.extensions.appContext - /** * Toast 工具类接口 * @@ -18,12 +13,11 @@ interface ToastUtils { * 已自带处于其他线程时自动切换至主线程发送 */ fun toast(s: CharSequence?) { - CyxbsToast.show(appContext, s, Toast.LENGTH_SHORT) + com.cyxbs.components.utils.extensions.toast(s) } fun toastLong(s: CharSequence?) { - CyxbsToast.show(appContext, s, Toast.LENGTH_LONG) + com.cyxbs.components.utils.extensions.toastLong(s) } fun String.toast() = toast(this) fun String.toastLong() = toastLong(this) - fun toast(@StringRes id: Int) = toast(appContext.getString(id)) } \ No newline at end of file diff --git a/cyxbs-components/base/src/desktopMain/kotlin/com/cyxbs/components/base/ui/BaseViewModel.desktop.kt b/cyxbs-components/base/src/desktopMain/kotlin/com/cyxbs/components/base/ui/BaseViewModel.desktop.kt new file mode 100644 index 0000000000..20d702e9cc --- /dev/null +++ b/cyxbs-components/base/src/desktopMain/kotlin/com/cyxbs/components/base/ui/BaseViewModel.desktop.kt @@ -0,0 +1,11 @@ +package com.cyxbs.components.base.ui + +/** + * . + * + * @author 985892345 + * @date 2024/12/31 + */ +actual abstract class BaseViewModel : CommonBaseViewModel() { + +} \ No newline at end of file diff --git a/cyxbs-components/base/src/wasmJsMain/kotlin/com/cyxbs/components/base/ui/BaseViewModel.wasmJs.kt b/cyxbs-components/base/src/wasmJsMain/kotlin/com/cyxbs/components/base/ui/BaseViewModel.wasmJs.kt new file mode 100644 index 0000000000..f48991b664 --- /dev/null +++ b/cyxbs-components/base/src/wasmJsMain/kotlin/com/cyxbs/components/base/ui/BaseViewModel.wasmJs.kt @@ -0,0 +1,9 @@ +package com.cyxbs.components.base.ui + +/** + * commonMain 下的 ViewModel + * + * @author 985892345 + * @date 2024/12/31 + */ +actual abstract class BaseViewModel : CommonBaseViewModel() \ No newline at end of file diff --git a/cyxbs-components/config/build.gradle.kts b/cyxbs-components/config/build.gradle.kts index c139d98cdc..e40ed38d6b 100644 --- a/cyxbs-components/config/build.gradle.kts +++ b/cyxbs-components/config/build.gradle.kts @@ -1,5 +1,6 @@ plugins { id("manager.lib") + id("kmp.compose") } kotlin { diff --git a/cyxbs-components/config/src/commonMain/kotlin/com/cyxbs/components/config/color/AppColor.kt b/cyxbs-components/config/src/commonMain/kotlin/com/cyxbs/components/config/color/AppColor.kt new file mode 100644 index 0000000000..1d19360b81 --- /dev/null +++ b/cyxbs-components/config/src/commonMain/kotlin/com/cyxbs/components/config/color/AppColor.kt @@ -0,0 +1,35 @@ +package com.cyxbs.components.config.color + +import androidx.compose.runtime.ProvidableCompositionLocal +import androidx.compose.runtime.staticCompositionLocalOf +import androidx.compose.ui.graphics.Color + +/** + * 应用级别最常用的颜色 + * + * @author 985892345 + * @date 2024/1/28 11:09 + */ + +val LocalAppColors: ProvidableCompositionLocal = staticCompositionLocalOf { + AppColor() +} + +open class AppColor( + val tvLv1: Color = Color(0xFF112C54), + val tvLv2: Color = Color(0xFF112C57), + val tvLv3: Color = Color(0xFF15315B), + val tvLv4: Color = Color(0xFF2A4E84), + val red: Color = Color(0xFFD50000), + val blue: Color = Color(0xFF1C71FF), + val green: Color = Color(0xFF00C853), + val yellow: Color = Color(0xFFFFAB00), + val orange : Color = Color(0xFFFF6D00), +) + +data object AppDarkColor : AppColor( + tvLv1 = Color(0xFFFFFFFF), + tvLv2 = Color(0xFFFFFFFF), + tvLv3 = Color(0xFFFFFFFF), + tvLv4 = Color(0xFFFFFFFF), +) \ No newline at end of file diff --git a/cyxbs-components/utils/src/androidMain/kotlin/com/cyxbs/components/utils/compose/Window.android.kt b/cyxbs-components/utils/src/androidMain/kotlin/com/cyxbs/components/utils/compose/Window.android.kt new file mode 100644 index 0000000000..55e87f5cf3 --- /dev/null +++ b/cyxbs-components/utils/src/androidMain/kotlin/com/cyxbs/components/utils/compose/Window.android.kt @@ -0,0 +1,20 @@ +package com.cyxbs.components.utils.compose + +import androidx.compose.runtime.Composable +import androidx.compose.ui.platform.LocalConfiguration +import androidx.compose.ui.unit.DpSize +import androidx.compose.ui.unit.dp + +/** + * . + * + * @author 985892345 + * @date 2025/1/1 + */ + +@Composable +actual fun getWindowScreenSize(): DpSize { + return LocalConfiguration.current.let { + DpSize(it.screenWidthDp.dp, it.screenHeightDp.dp) + } +} \ No newline at end of file diff --git a/cyxbs-components/utils/src/androidMain/kotlin/com/cyxbs/components/utils/extensions/Log.android.kt b/cyxbs-components/utils/src/androidMain/kotlin/com/cyxbs/components/utils/extensions/Log.android.kt new file mode 100644 index 0000000000..f165473af7 --- /dev/null +++ b/cyxbs-components/utils/src/androidMain/kotlin/com/cyxbs/components/utils/extensions/Log.android.kt @@ -0,0 +1,13 @@ +package com.cyxbs.components.utils.extensions + +import android.util.Log + +/** + * . + * + * @author 985892345 + * @date 2024/1/23 10:22 + */ +actual fun log(msg: String) { + Log.d("ggg", "(${Exception().stackTrace[2].run { "$fileName:$lineNumber" }}) -> $msg") +} \ No newline at end of file diff --git a/cyxbs-components/utils/src/androidMain/kotlin/com/cyxbs/components/utils/extensions/Toast.kt b/cyxbs-components/utils/src/androidMain/kotlin/com/cyxbs/components/utils/extensions/Toast.android.kt similarity index 83% rename from cyxbs-components/utils/src/androidMain/kotlin/com/cyxbs/components/utils/extensions/Toast.kt rename to cyxbs-components/utils/src/androidMain/kotlin/com/cyxbs/components/utils/extensions/Toast.android.kt index 1f579e64c9..f2b21e934d 100644 --- a/cyxbs-components/utils/src/androidMain/kotlin/com/cyxbs/components/utils/extensions/Toast.kt +++ b/cyxbs-components/utils/src/androidMain/kotlin/com/cyxbs/components/utils/extensions/Toast.android.kt @@ -9,6 +9,7 @@ import android.view.LayoutInflater import android.view.View import android.widget.TextView import android.widget.Toast +import androidx.annotation.StringRes import com.cyxbs.components.utils.BuildConfig import com.cyxbs.components.utils.R @@ -26,23 +27,22 @@ import com.cyxbs.components.utils.R /** * 已自带处于其他线程时自动切换至主线程发送 */ -fun toast(s: CharSequence?) { +actual fun toast(s: CharSequence?) { CyxbsToast.show(appContext, s, Toast.LENGTH_SHORT) } -fun toastWithYOffset(s: CharSequence?, toastY: Int) { - CyxbsToast.show(appContext, s, Toast.LENGTH_SHORT, toastY) -} - -fun toastLong(s: CharSequence?) { +actual fun toastLong(s: CharSequence?) { CyxbsToast.show(appContext, s, Toast.LENGTH_LONG) } -fun String.toast() = toast(this) -fun String.toastWithYOffset(toastY: Int) = toastWithYOffset(this,toastY) -fun String.toastLong() = toastLong(this) +fun toast(@StringRes id: Int) = toast(appContext.getString(id)) + +// 用于特殊场景使用,比如桌面小组件 +fun toast(s: CharSequence?, context: Context) { + CyxbsToast.show(context, s, Toast.LENGTH_SHORT) +} -class CyxbsToast { +private class CyxbsToast { companion object { /** @@ -52,13 +52,12 @@ class CyxbsToast { context: Context, text: CharSequence?, duration: Int, - toastY: Int = 0 ) { if (text == null) return if (Thread.currentThread() !== Looper.getMainLooper().thread) { Handler(Looper.getMainLooper()).post { newInstance(context, text, duration).show() } } else { - newInstance(context, text, duration, toastY).show() + newInstance(context, text, duration).show() } } @@ -66,7 +65,6 @@ class CyxbsToast { context: Context, text: CharSequence, duration: Int, - toastY: Int = 0 ): Toast { if (BuildConfig.DEBUG) { val throwable = Throwable() // 获取堆栈信息 @@ -95,11 +93,7 @@ class CyxbsToast { val v: View = inflate.inflate(R.layout.utils_layout_toast, null) val tv = v.findViewById(R.id.tv_toast) as TextView tv.text = text - val height = if (toastY == 0) { - context.resources.displayMetrics.heightPixels / 8 - } else { - toastY - } + val height = context.resources.displayMetrics.heightPixels / 8 result.view = v result.duration = duration result.setGravity(Gravity.CENTER_HORIZONTAL or Gravity.TOP, 0, height) diff --git a/cyxbs-components/utils/src/commonMain/kotlin/com/cyxbs/components/utils/compose/Color.kt b/cyxbs-components/utils/src/commonMain/kotlin/com/cyxbs/components/utils/compose/Color.kt index 786fafb393..fdeaa4aabd 100644 --- a/cyxbs-components/utils/src/commonMain/kotlin/com/cyxbs/components/utils/compose/Color.kt +++ b/cyxbs-components/utils/src/commonMain/kotlin/com/cyxbs/components/utils/compose/Color.kt @@ -1,7 +1,6 @@ package com.cyxbs.components.utils.compose import androidx.compose.runtime.Composable -import androidx.compose.runtime.staticCompositionLocalOf import androidx.compose.ui.graphics.Color /** @@ -11,10 +10,6 @@ import androidx.compose.ui.graphics.Color * @date 2024/1/23 15:12 */ - -val LocalAppDarkTheme = staticCompositionLocalOf { false } -val LocalAppColors = staticCompositionLocalOf { AppLightColor } - fun Int.color(): Color { return Color(this) } @@ -24,27 +19,25 @@ fun Long.color(): Color { } @Composable -fun Color.dark(darkColor: Color): Color { - return if (LocalAppDarkTheme.current) darkColor else this +fun Int.dark(darkColor: Int): Color { + // todo + return Color(this) +} + +@Composable +fun Int.dark(darkColor: Color): Color { + // todo + return Color(this) } -sealed class AppColor( - val tvLv1: Color = Color(0xFF112C54), - val tvLv2: Color = Color(0xFF112C57), - val tvLv3: Color = Color(0xFF15315B), - val tvLv4: Color = Color(0xFF2A4E84), - val red: Color = Color(0xFFD50000), - val blue: Color = Color(0xFF1C71FF), - val green: Color = Color(0xFF00C853), - val yellow: Color = Color(0xFFFFAB00), - val orange : Color = Color(0xFFFF6D00), -) - -data object AppLightColor : AppColor() - -data object AppDarkColor : AppColor( - tvLv1 = Color(0xFFFFFFFF), - tvLv2 = Color(0xFFFFFFFF), - tvLv3 = Color(0xFFFFFFFF), - tvLv4 = Color(0xFFFFFFFF), -) \ No newline at end of file +@Composable +fun Long.dark(darkColor: Long): Color { + // todo + return Color(this) +} + +@Composable +fun Long.dark(darkColor: Color): Color { + // todo + return Color(this) +} \ No newline at end of file diff --git a/cyxbs-components/utils/src/commonMain/kotlin/com/cyxbs/components/utils/compose/Window.kt b/cyxbs-components/utils/src/commonMain/kotlin/com/cyxbs/components/utils/compose/Window.kt new file mode 100644 index 0000000000..8f85b800fa --- /dev/null +++ b/cyxbs-components/utils/src/commonMain/kotlin/com/cyxbs/components/utils/compose/Window.kt @@ -0,0 +1,14 @@ +package com.cyxbs.components.utils.compose + +import androidx.compose.runtime.Composable +import androidx.compose.ui.unit.DpSize + +/** + * . + * + * @author 985892345 + * @date 2025/1/1 + */ + +@Composable +expect fun getWindowScreenSize(): DpSize diff --git a/cyxbs-components/utils/src/commonMain/kotlin/com/cyxbs/components/utils/extensions/Log.kt b/cyxbs-components/utils/src/commonMain/kotlin/com/cyxbs/components/utils/extensions/Log.kt new file mode 100644 index 0000000000..2b4c24608f --- /dev/null +++ b/cyxbs-components/utils/src/commonMain/kotlin/com/cyxbs/components/utils/extensions/Log.kt @@ -0,0 +1,14 @@ +package com.cyxbs.components.utils.extensions + +/** + * . + * + * @author 985892345 + * @date 2024/1/23 10:22 + */ + +expect fun log(msg: String) + +fun logg(msg: Any?) { + log(msg.toString()) +} \ No newline at end of file diff --git a/cyxbs-components/utils/src/commonMain/kotlin/com/cyxbs/components/utils/extensions/Toast.kt b/cyxbs-components/utils/src/commonMain/kotlin/com/cyxbs/components/utils/extensions/Toast.kt new file mode 100644 index 0000000000..966cf2902d --- /dev/null +++ b/cyxbs-components/utils/src/commonMain/kotlin/com/cyxbs/components/utils/extensions/Toast.kt @@ -0,0 +1,18 @@ +package com.cyxbs.components.utils.extensions + +/** + * ... + * @author 985892345 (Guo Xiangrui) + * @email 2767465918@qq.com + * @date 2022/3/7 17:58 + */ + +/** + * Android:已自带处于其他线程时自动切换至主线程发送 + */ +expect fun toast(s: CharSequence?) + +expect fun toastLong(s: CharSequence?) + +fun String.toast() = toast(this) +fun String.toastLong() = toastLong(this) diff --git a/cyxbs-components/utils/src/desktopMain/kotlin/com/cyxbs/components/utils/compose/Window.desktop.kt b/cyxbs-components/utils/src/desktopMain/kotlin/com/cyxbs/components/utils/compose/Window.desktop.kt new file mode 100644 index 0000000000..9323404339 --- /dev/null +++ b/cyxbs-components/utils/src/desktopMain/kotlin/com/cyxbs/components/utils/compose/Window.desktop.kt @@ -0,0 +1,21 @@ +package com.cyxbs.components.utils.compose + +import androidx.compose.runtime.Composable +import androidx.compose.ui.ExperimentalComposeUiApi +import androidx.compose.ui.platform.LocalWindowInfo +import androidx.compose.ui.unit.DpSize + +/** + * . + * + * @author 985892345 + * @date 2025/1/1 + */ + +@OptIn(ExperimentalComposeUiApi::class) +@Composable +actual fun getWindowScreenSize(): DpSize { + return LocalWindowInfo.current.containerSize.let { + DpSize(it.width.px2dpCompose, it.height.px2dpCompose) + } +} \ No newline at end of file diff --git a/cyxbs-components/utils/src/desktopMain/kotlin/com/cyxbs/components/utils/extensions/Log.desktop.kt b/cyxbs-components/utils/src/desktopMain/kotlin/com/cyxbs/components/utils/extensions/Log.desktop.kt new file mode 100644 index 0000000000..5f408602da --- /dev/null +++ b/cyxbs-components/utils/src/desktopMain/kotlin/com/cyxbs/components/utils/extensions/Log.desktop.kt @@ -0,0 +1,11 @@ +package com.cyxbs.components.utils.extensions + +/** + * . + * + * @author 985892345 + * @date 2024/1/23 10:22 + */ +actual fun log(msg: String) { + println(".(${Exception().stackTrace[2].run { "$fileName:$lineNumber" }}) -> $msg") +} \ No newline at end of file diff --git a/cyxbs-components/utils/src/desktopMain/kotlin/com/cyxbs/components/utils/extensions/Toast.desktop.kt b/cyxbs-components/utils/src/desktopMain/kotlin/com/cyxbs/components/utils/extensions/Toast.desktop.kt new file mode 100644 index 0000000000..45038b68b7 --- /dev/null +++ b/cyxbs-components/utils/src/desktopMain/kotlin/com/cyxbs/components/utils/extensions/Toast.desktop.kt @@ -0,0 +1,8 @@ +package com.cyxbs.components.utils.extensions + + +actual fun toast(s: CharSequence?) { +} + +actual fun toastLong(s: CharSequence?) { +} \ No newline at end of file diff --git a/cyxbs-components/utils/src/wasmJsMain/kotlin/com/cyxbs/components/utils/compose/Window.wasmJs.kt b/cyxbs-components/utils/src/wasmJsMain/kotlin/com/cyxbs/components/utils/compose/Window.wasmJs.kt new file mode 100644 index 0000000000..9323404339 --- /dev/null +++ b/cyxbs-components/utils/src/wasmJsMain/kotlin/com/cyxbs/components/utils/compose/Window.wasmJs.kt @@ -0,0 +1,21 @@ +package com.cyxbs.components.utils.compose + +import androidx.compose.runtime.Composable +import androidx.compose.ui.ExperimentalComposeUiApi +import androidx.compose.ui.platform.LocalWindowInfo +import androidx.compose.ui.unit.DpSize + +/** + * . + * + * @author 985892345 + * @date 2025/1/1 + */ + +@OptIn(ExperimentalComposeUiApi::class) +@Composable +actual fun getWindowScreenSize(): DpSize { + return LocalWindowInfo.current.containerSize.let { + DpSize(it.width.px2dpCompose, it.height.px2dpCompose) + } +} \ No newline at end of file diff --git a/cyxbs-components/utils/src/wasmJsMain/kotlin/com/cyxbs/components/utils/extensions/Log.wasmJs.kt b/cyxbs-components/utils/src/wasmJsMain/kotlin/com/cyxbs/components/utils/extensions/Log.wasmJs.kt new file mode 100644 index 0000000000..dda7c73ca4 --- /dev/null +++ b/cyxbs-components/utils/src/wasmJsMain/kotlin/com/cyxbs/components/utils/extensions/Log.wasmJs.kt @@ -0,0 +1,11 @@ +package com.cyxbs.components.utils.extensions + +/** + * . + * + * @author 985892345 + * @date 2024/1/23 10:22 + */ +actual fun log(msg: String) { + js("console.log(msg)") +} \ No newline at end of file diff --git a/cyxbs-components/utils/src/wasmJsMain/kotlin/com/cyxbs/components/utils/extensions/Toast.wasmJs.kt b/cyxbs-components/utils/src/wasmJsMain/kotlin/com/cyxbs/components/utils/extensions/Toast.wasmJs.kt new file mode 100644 index 0000000000..5c09dadde8 --- /dev/null +++ b/cyxbs-components/utils/src/wasmJsMain/kotlin/com/cyxbs/components/utils/extensions/Toast.wasmJs.kt @@ -0,0 +1,10 @@ +package com.cyxbs.components.utils.extensions + +/** + * Android:已自带处于其他线程时自动切换至主线程发送 + */ +actual fun toast(s: CharSequence?) { +} + +actual fun toastLong(s: CharSequence?) { +} \ No newline at end of file diff --git a/cyxbs-pages/grades/src/androidMain/kotlin/com/cyxbs/pages/grades/ui/viewModel/ContainerViewModel.kt b/cyxbs-pages/grades/src/androidMain/kotlin/com/cyxbs/pages/grades/ui/viewModel/ContainerViewModel.kt index ff82ea64f0..5bfbff9d12 100644 --- a/cyxbs-pages/grades/src/androidMain/kotlin/com/cyxbs/pages/grades/ui/viewModel/ContainerViewModel.kt +++ b/cyxbs-pages/grades/src/androidMain/kotlin/com/cyxbs/pages/grades/ui/viewModel/ContainerViewModel.kt @@ -15,6 +15,7 @@ import com.cyxbs.pages.grades.bean.analyze.isSuccessful import com.cyxbs.pages.grades.network.ApiService import com.cyxbs.components.base.ui.BaseViewModel import com.cyxbs.components.utils.extensions.setSchedulers +import com.cyxbs.components.utils.extensions.toast import com.cyxbs.components.utils.network.ApiGenerator import com.cyxbs.components.utils.network.mapOrInterceptException import io.reactivex.rxjava3.core.Observable diff --git a/cyxbs-pages/login/build.gradle.kts b/cyxbs-pages/login/build.gradle.kts index 78d1945ca9..4c9cf3a2bd 100644 --- a/cyxbs-pages/login/build.gradle.kts +++ b/cyxbs-pages/login/build.gradle.kts @@ -14,6 +14,7 @@ kotlin { implementation(projects.cyxbsComponents.utils) implementation(projects.cyxbsFunctions.update.api) implementation(projects.cyxbsComponents.account.api) + implementation(libs.compose.lottie) } androidMain.dependencies { implementation(libs.bundles.projectBase) diff --git a/cyxbs-pages/login/src/androidMain/kotlin/com/cyxbs/pages/login/login/ui/LoginActivity.kt b/cyxbs-pages/login/src/androidMain/kotlin/com/cyxbs/pages/login/login/ui/LoginActivity.kt index b62b98ea74..ac2afb7228 100644 --- a/cyxbs-pages/login/src/androidMain/kotlin/com/cyxbs/pages/login/login/ui/LoginActivity.kt +++ b/cyxbs-pages/login/src/androidMain/kotlin/com/cyxbs/pages/login/login/ui/LoginActivity.kt @@ -1,30 +1,11 @@ package com.cyxbs.pages.login.login.ui import android.app.Activity -import android.content.Context import android.content.Intent -import android.graphics.Color import android.os.Bundle -import android.text.Spannable -import android.text.SpannableStringBuilder -import android.text.TextPaint -import android.text.method.LinkMovementMethod -import android.text.style.ClickableSpan -import android.text.style.ForegroundColorSpan -import android.transition.Explode -import android.transition.TransitionManager -import android.view.View -import android.view.ViewGroup -import android.view.inputmethod.EditorInfo -import android.view.inputmethod.InputMethodManager -import android.widget.Button -import android.widget.EditText -import android.widget.TextView +import androidx.activity.compose.setContent import androidx.activity.viewModels -import androidx.core.content.ContextCompat import androidx.core.content.edit -import androidx.core.view.get -import com.airbnb.lottie.LottieAnimationView import com.cyxbs.components.account.api.IAccountService import com.cyxbs.components.base.BaseApp import com.cyxbs.components.base.ui.BaseActivity @@ -32,18 +13,23 @@ import com.cyxbs.components.config.route.MINE_FORGET_PASSWORD import com.cyxbs.components.config.sp.SP_PRIVACY_AGREED import com.cyxbs.components.config.sp.defaultSp import com.cyxbs.components.utils.extensions.appContext -import com.cyxbs.components.utils.extensions.launch -import com.cyxbs.components.utils.extensions.setOnSingleClickListener -import com.cyxbs.components.utils.extensions.wrapByNoLeak import com.cyxbs.components.utils.service.impl import com.cyxbs.components.utils.service.startActivity -import com.cyxbs.components.utils.utils.judge.NetworkUtil import com.cyxbs.functions.update.api.IAppUpdateService -import com.cyxbs.pages.login.R import com.cyxbs.pages.login.api.ILegalNoticeService -import com.cyxbs.pages.login.login.viewmodel.LoginViewModel +import com.cyxbs.pages.login.ui.LoginCompose import com.cyxbs.pages.login.ui.UserAgreementDialog - +import com.cyxbs.pages.login.viewmodel.LoginViewModel + +/** + * 登录界面 + * + * 目前登录界面使用了多平台的 compose + * 数据流方向: LoginCompose -> LoginViewModel -> LoginActivity + * 由于 CommonLoginViewModel 抽了一层多平台通用逻辑后,LoginActivity 更多的逻辑是处理跳转,所以感觉有点代码有点少 + * 但如果后续是全界面上 Compose 的话,那个时候跳转就放到 Compose 层,目前因为跳转需要强耦合 activity,所以变成了这样 + * + */ class LoginActivity : BaseActivity() { companion object { fun start(intent: (Intent.() -> Unit)? = null) { @@ -92,119 +78,51 @@ class LoginActivity : BaseActivity() { private val mViewModel by viewModels() - private val mLottieProgress = 0.39f // 点击同意用户协议时的动画的时间 - - private val mEtAccount by R.id.login_et_account.view() - private val mEtPassword by R.id.login_et_password.view() - private val mBtnLogin by R.id.login_btn_login.view