diff --git a/build-profile.json5 b/build-profile.json5 index 1e69556..24a4284 100644 --- a/build-profile.json5 +++ b/build-profile.json5 @@ -1,6 +1,20 @@ { "app": { - "signingConfigs": [], + "signingConfigs": [ + { + "name": "default", + "type": "HarmonyOS", + "material": { + "certpath": "C:\\Users\\wps\\.ohos\\config\\default_himi_ZikZBgBxljB_K_Bxk-D2cAAnn7PtvbqmLsGmCt8Tywc=.cer", + "storePassword": "0000001A324907DCD55F55682629687D2AECF782CD5EE7AFB5FD4E1CE3F410EBB601D67AC641B4072B46", + "keyAlias": "debugKey", + "keyPassword": "0000001A8EDEBEC4585D89D8F1A91107E51ECAE951E2849CB803CBA06C9E49A8A59CCB6CECAF7EA5DADA", + "profile": "C:\\Users\\wps\\.ohos\\config\\default_himi_ZikZBgBxljB_K_Bxk-D2cAAnn7PtvbqmLsGmCt8Tywc=.p7b", + "signAlg": "SHA256withECDSA", + "storeFile": "C:\\Users\\wps\\.ohos\\config\\default_himi_ZikZBgBxljB_K_Bxk-D2cAAnn7PtvbqmLsGmCt8Tywc=.p12" + } + } + ], "products": [ { "name": "default", diff --git a/entry/src/main/cangjie/src/components/Chat/ChatMessage.cj b/entry/src/main/cangjie/src/components/Chat/ChatMessage.cj new file mode 100644 index 0000000..aedb237 --- /dev/null +++ b/entry/src/main/cangjie/src/components/Chat/ChatMessage.cj @@ -0,0 +1,93 @@ +/** + * Created on 2024/9/10 + */ +package ohos_app_cangjie_entry.components.Chat + +import std.collection.* +import ohos.component.* +import ohos.state_macro_manage.* +import ohos.state_manage.* +import ohos.base.* + +public enum EChatSource { + | ME + | YOU +} + +@Component +public class ChatMessage { + @Prop + var message: String + @Prop + var source: EChatSource + + @State + var radiusMap: HashMap = HashMap() + + protected func aboutToAppear() { + this.radiusMap = this.messageRadius() + } + + func fontColor() { + match (this.source) { + case EChatSource.ME => Color.WHITE + case EChatSource.YOU => Color.BLACK + } + } + + func bgColor() { + match (this.source) { + case EChatSource.YOU => Color.WHITE + case EChatSource.ME => Color.BLUE + } + } + + func orient() { + match (this.source) { + case EChatSource.YOU => FlexAlign.Start + case EChatSource.ME => FlexAlign.End + } + } + + func messageRadius(): HashMap { + match (this.source) { + case EChatSource.YOU => HashMap( + [ + ("topLeft", 12.vp), + ("topRight", 12.vp), + ("bottomLeft", 0.vp), + ("bottomRight", 12.vp) + ] + ) + case EChatSource.ME => HashMap( + [ + ("topLeft", 12.vp), + ("topRight", 12.vp), + ("bottomLeft", 12.vp), + ("bottomRight", 0.vp) + ] + ) + } + } + + func build() { + Row() { + Row() { + Text(message) + .fontColor(this.fontColor()) + .backgroundColor(this.bgColor()) + .padding(top: 8, right: 16,bottom: 8, left: 16) + .borderRadius( + topLeft: this.radiusMap['topLeft'], + topRight: this.radiusMap['topRight'], + bottomLeft: this.radiusMap['bottomLeft'], + bottomRight: this.radiusMap['bottomRight'], + ) + } + .width(60.percent) + .justifyContent(this.orient()) + } + .width(100.percent) + .justifyContent(this.orient()) + } +} diff --git a/entry/src/main/cangjie/src/components/ChatList.cj b/entry/src/main/cangjie/src/components/ChatList.cj new file mode 100644 index 0000000..ad03ece --- /dev/null +++ b/entry/src/main/cangjie/src/components/ChatList.cj @@ -0,0 +1,36 @@ +/** + * Created on 2024/9/10 + */ +package ohos_app_cangjie_entry.components + +internal import ohos.component.* +internal import ohos.state_manage.* +internal import ohos.base.* +import ohos.state_macro_manage.* +import ohos_app_cangjie_entry.components.Chat.* + +@Component +public class ChatList { + let array: Array = Array(20, item: "teststesstasdasdasdadasdasdsaesrfsfdfsfdsf") + func build() { + Column { + List(space: 20, initialIndex: 0) { + ForEach( + this.array, + itemGeneratorFunc: { + item: String, index: Int64 => ListItem { + ChatMessage( + message: item, + source: if (index % 2 == 0) { + EChatSource.ME + } else { + EChatSource.YOU + } + ) + } + } + ) + } + }.height(100.percent).width(100.percent).padding(top: 5.vp) + } +} diff --git a/entry/src/main/cangjie/src/index.cj b/entry/src/main/cangjie/src/index.cj index b4aaad6..e8d4590 100644 --- a/entry/src/main/cangjie/src/index.cj +++ b/entry/src/main/cangjie/src/index.cj @@ -9,9 +9,13 @@ import ohos_app_cangjie_entry.pages.* @Entry @Component class MyView { + let TAG = "MyView" @State var message: String = "Hello Cangjie" + protected func aboutToAppear() { + } + func build() { Row { HomePage() diff --git a/entry/src/main/cangjie/src/utils/Logger.cj b/entry/src/main/cangjie/src/utils/Logger.cj new file mode 100644 index 0000000..08b87b6 --- /dev/null +++ b/entry/src/main/cangjie/src/utils/Logger.cj @@ -0,0 +1,35 @@ +/** + * Created on 2024/9/7 + */ +package ohos_app_cangjie_entry.utils + +import std.log.* +import log.* +import std.console.* + +public class Logger { + private let TAG: String + private static let logger = SimpleLogger() + private static let isOutputFile: Bool = false + private static let outputFilePath: String = './logger.log' + public init(TAG: String) { + logger.setOutput(Console.stdOut) + this.TAG = TAG + ": " + } + + public func debug(message: String) { + logger.debug(this.TAG + message) + logger.flush() + } + + public func info(msg: String) { + logger.info(this.TAG + msg) + logger.flush() + } + public func warn(msg: String) { + logger.warn(this.TAG + msg) + } + public func error(msg: String) { + logger.error(this.TAG + msg) + } +}