Compare commits
No commits in common. "470c66a61256e94049425fc0c6749b82d6eb53d0" and "b9cd46db5e1a16904f16bc130a45c928b43e41dd" have entirely different histories.
470c66a612
...
b9cd46db5e
|
@ -1,8 +0,0 @@
|
|||
{
|
||||
"color": [
|
||||
{
|
||||
"name": "bg_01",
|
||||
"value": "#F2F3F5"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,19 +1,6 @@
|
|||
{
|
||||
"app": {
|
||||
"signingConfigs": [
|
||||
{
|
||||
"name": "default",
|
||||
"type": "HarmonyOS",
|
||||
"material": {
|
||||
"certpath": "C:\\Users\\wps\\.ohos\\config\\default_himi_ZikZBgBxljB_K_Bxk-D2cAAnn7PtvbqmLsGmCt8Tywc=.cer",
|
||||
"storePassword": "0000001B9A5987C8C2ED4361B7927D584652F717FF7936EC3310D0B9BCEEA9B1E3485C8480FF92C40CA86E",
|
||||
"keyAlias": "debugKey",
|
||||
"keyPassword": "0000001BC10C705923EBF5BFF9E770159DFBE2DD5E92BD7DCC5F78CCF2629A20BA2BD3177C275B83ADB93F",
|
||||
"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": [
|
||||
{
|
||||
|
|
|
@ -6,28 +6,18 @@ package ohos_app_cangjie_entry.components.chat
|
|||
internal import ohos.component.*
|
||||
internal import ohos.state_manage.*
|
||||
internal import ohos.base.*
|
||||
import std.collection.*
|
||||
import ohos.state_macro_manage.*
|
||||
import ohos_app_cangjie_entry.mock.*
|
||||
import ohos_app_cangjie_entry.types.ChatData
|
||||
import ohos_app_cangjie_entry.utils.Logger
|
||||
import ohos_app_cangjie_entry.view_model.ChatListControl
|
||||
|
||||
@Component
|
||||
public class ChatList {
|
||||
let TAG: String = "ChatList"
|
||||
@Prop
|
||||
var datasource: ArrayList<ChatData>
|
||||
let scrollerForList = Scroller()
|
||||
|
||||
protected func aboutToAppear() {
|
||||
Logger(TAG).info("About to Appear")
|
||||
ChatListControl().setScrollerForList(this.scrollerForList)
|
||||
}
|
||||
var datasource: ObservedArray<ChatData>
|
||||
|
||||
func build() {
|
||||
Column {
|
||||
List(space: 20, initialIndex: Int32(this.datasource.size - 1), scroller: this.scrollerForList) {
|
||||
List(space: 20, initialIndex: 0) {
|
||||
ForEach(
|
||||
this.datasource,
|
||||
itemGeneratorFunc: {
|
||||
|
@ -37,7 +27,7 @@ public class ChatList {
|
|||
source: item.source,
|
||||
)
|
||||
}
|
||||
},
|
||||
}
|
||||
)
|
||||
}
|
||||
}.height(100.percent).width(100.percent).padding(top: 5.vp)
|
||||
|
|
|
@ -19,9 +19,6 @@ public enum EChatSource {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 只限定UI
|
||||
**/
|
||||
@Component
|
||||
public class ChatMessage {
|
||||
@Prop
|
||||
|
|
|
@ -7,60 +7,12 @@ internal import ohos.base.*
|
|||
internal import ohos.component.*
|
||||
internal import ohos.state_manage.*
|
||||
import ohos.state_macro_manage.*
|
||||
import ohos_app_cangjie_entry.utils.Logger
|
||||
import ohos_app_cangjie_entry.store.ChatStore
|
||||
import ohos_app_cangjie_entry.types.ChatData
|
||||
import ohos_app_cangjie_entry.view_model.ChatListControl
|
||||
|
||||
@Component
|
||||
public class HomeBottom {
|
||||
let TAG: String = "HomeBottom"
|
||||
|
||||
@State
|
||||
var isPedding: Bool = false
|
||||
@State
|
||||
var inputText: String = ""
|
||||
let inputPlaceHolder: String = "有什么问题尽管问我"
|
||||
let inputController = TextInputController()
|
||||
|
||||
protected func aboutToAppear() {
|
||||
Logger(TAG).info("About to appear.")
|
||||
}
|
||||
|
||||
func submitInput() {
|
||||
if (this.inputText == "") {
|
||||
return
|
||||
}
|
||||
|
||||
if (this.isPedding) {
|
||||
// 处理正在等待的情况
|
||||
return
|
||||
}
|
||||
|
||||
this.isPedding = true
|
||||
ChatStore().add(
|
||||
ChatData(
|
||||
id: ChatStore().genID(),
|
||||
message: this.inputText,
|
||||
source: 'ME',
|
||||
)
|
||||
)
|
||||
this.inputText = ""
|
||||
this.isPedding = false
|
||||
ChatListControl().toBottom()
|
||||
}
|
||||
|
||||
func build() {
|
||||
Row {
|
||||
TextInput(
|
||||
text: this.inputText,
|
||||
placeholder: this.inputPlaceHolder,
|
||||
controller: this.inputController,
|
||||
).onChange {
|
||||
value => this.inputText = value
|
||||
}.onSubmit {
|
||||
_ => this.submitInput()
|
||||
}
|
||||
Text("HomeBottom")
|
||||
}.width(100.percent)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,28 +6,15 @@ package ohos_app_cangjie_entry.components.home
|
|||
internal import ohos.base.*
|
||||
internal import ohos.component.*
|
||||
internal import ohos.state_manage.*
|
||||
import ohos_app_cangjie_entry.utils.Logger
|
||||
import ohos.state_macro_manage.*
|
||||
import ohos_app_cangjie_entry.components.chat.ChatList
|
||||
import ohos_app_cangjie_entry.mock.*
|
||||
import ohos_app_cangjie_entry.types.ChatData
|
||||
import std.collection.*
|
||||
import ohos_app_cangjie_entry.store.ChatStore
|
||||
import ohos_app_cangjie_entry.view_model.ChatListControl
|
||||
|
||||
@Component
|
||||
public class HomeMain {
|
||||
let TAG: String = "HomeMain"
|
||||
@State
|
||||
var mockData: ArrayList<ChatData> = ChatStore().use()
|
||||
let chatListController = ChatListControl()
|
||||
|
||||
protected func aboutToAppear(): Unit {
|
||||
Logger(TAG).info("About to appear.")
|
||||
ChatStore().register(this.TAG) {
|
||||
this.mockData = ChatStore().use()
|
||||
}
|
||||
}
|
||||
var mockData: ObservedArray<ChatData> = ObservedArray<ChatData>(genMockData())
|
||||
|
||||
func build() {
|
||||
Column {
|
||||
|
|
|
@ -19,6 +19,6 @@ class MyView {
|
|||
func build() {
|
||||
Row {
|
||||
HomePage()
|
||||
}.height(100.percent).width(100.percent).backgroundColor(@r(app.color.bg_01))
|
||||
}.height(100.percent).width(100.percent)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ public func genMockData() {
|
|||
20,
|
||||
{
|
||||
index: Int => ChatData(
|
||||
id: index.toString(),
|
||||
message: "teststesstasdasdasdadasdasdsaesrfsfdfsfdsf",
|
||||
source: getSource(index)
|
||||
)
|
||||
|
|
|
@ -9,20 +9,16 @@ import ohos.state_macro_manage.*
|
|||
internal import ohos.component.*
|
||||
internal import ohos.state_manage.*
|
||||
internal import ohos.base.*
|
||||
import ohos_app_cangjie_entry.store.ChatStore
|
||||
|
||||
@Component
|
||||
public class HomePage {
|
||||
private let TAG = "HomePage"
|
||||
protected func aboutToAppear() {
|
||||
ChatStore().initStore()
|
||||
}
|
||||
func build() {
|
||||
Column(10) {
|
||||
HomeTitle()
|
||||
Column {
|
||||
HomeMain()
|
||||
}.layoutWeight(1)
|
||||
HomeBottom()
|
||||
}.width(100.percent).height(100.percent)
|
||||
}
|
||||
|
|
|
@ -8,62 +8,17 @@ internal import ohos.base.*
|
|||
import ohos.state_macro_manage.*
|
||||
import ohos_app_cangjie_entry.types.ChatData
|
||||
import ohos_app_cangjie_entry.mock.genMockData
|
||||
import std.collection.*
|
||||
import ohos_app_cangjie_entry.utils.Logger
|
||||
|
||||
@Observed
|
||||
public class ChatStore {
|
||||
private let TAG: String = "ChatStore"
|
||||
private static let chatDataList: ArrayList<ChatData> = ArrayList<ChatData>()
|
||||
private static let observers: HashMap<String, () -> Unit> = HashMap<String, () -> Unit>()
|
||||
@Publish
|
||||
private var chatDataList: ObservedArray<ChatData> = ObservedArray<ChatData>()
|
||||
|
||||
public func initStore() {
|
||||
ChatStore.chatDataList.appendAll(genMockData())
|
||||
func initChatStore() {
|
||||
this.chatDataList = ObservedArray<ChatData>(genMockData())
|
||||
}
|
||||
|
||||
public func genID() {
|
||||
return chatDataList.size.toString()
|
||||
}
|
||||
|
||||
public func len() {
|
||||
return chatDataList.size
|
||||
}
|
||||
|
||||
public func use() {
|
||||
return ChatStore.chatDataList.clone()
|
||||
}
|
||||
|
||||
public func resetStore() {
|
||||
ChatStore.chatDataList.clear()
|
||||
}
|
||||
|
||||
public func register(id: String, action: () -> Unit) {
|
||||
if (observers.contains(id)) {
|
||||
Logger(TAG).warn("this id: ${id} is existed.")
|
||||
}
|
||||
ChatStore.observers[id] = action
|
||||
return this
|
||||
}
|
||||
|
||||
public func unregister(id: String) {
|
||||
ChatStore.observers.remove(id)
|
||||
return this
|
||||
}
|
||||
|
||||
public func add(chatData: ChatData) {
|
||||
chatDataList.append(chatData)
|
||||
this.onUpdate()
|
||||
return this
|
||||
}
|
||||
|
||||
public func remove(chatData: ChatData) {
|
||||
chatDataList.removeIf {item => item == chatData}
|
||||
this.onUpdate()
|
||||
return this
|
||||
}
|
||||
|
||||
private func onUpdate() {
|
||||
ChatStore.observers.values().iterator().forEach {
|
||||
action => action()
|
||||
}
|
||||
func getChatDataList() {
|
||||
return this.chatDataList
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
/**
|
||||
* Created on 2024/9/19
|
||||
*/
|
||||
package ohos_app_cangjie_entry.support.support_database
|
||||
|
||||
import ohos.preferences.*
|
||||
internal import ohos.ability.*
|
||||
internal import ohos.window.*
|
||||
import ohos.base.*
|
||||
|
||||
public class PreferencesStore {
|
||||
private let context: AbilityContext
|
||||
public init(context: AbilityContext) {
|
||||
this.context = context
|
||||
|
||||
}
|
||||
}
|
|
@ -3,48 +3,6 @@
|
|||
*/
|
||||
package ohos_app_cangjie_entry.types
|
||||
|
||||
import serialization.serialization.*
|
||||
import std.math.*
|
||||
import encoding.json.*
|
||||
|
||||
public class ChatData <: Serializable<ChatData> {
|
||||
public ChatData(public let id!: String, public let message!: String, public let source!: String) {}
|
||||
|
||||
public operator func ==(right: ChatData) {
|
||||
return (
|
||||
this.id == right.id
|
||||
&& this.message == right.message
|
||||
&& this.source == right.source
|
||||
)
|
||||
}
|
||||
|
||||
public func serialize(): DataModel {
|
||||
return (
|
||||
DataModelStruct()
|
||||
.add(field<String>('id', id))
|
||||
.add(field<String>('message', message))
|
||||
.add(field<String>('source', source))
|
||||
)
|
||||
}
|
||||
|
||||
public static func deserialize(dm: DataModel): ChatData {
|
||||
let dms = match (dm) {
|
||||
case data: DataModelStruct => data
|
||||
case _ => throw Exception("this data is not DataModelStruct")
|
||||
}
|
||||
ChatData(
|
||||
id: String.deserialize(dms.get('id')),
|
||||
message: String.deserialize(dms.get('message')),
|
||||
source: String.deserialize(dms.get('source')),
|
||||
)
|
||||
}
|
||||
|
||||
public func toString(): String {
|
||||
this.serialize().toJson().toString()
|
||||
}
|
||||
|
||||
public static func fromString(s: String): ChatData {
|
||||
let jsonObj = JsonValue.fromStr(s)
|
||||
ChatData.deserialize(DataModel.fromJson(jsonObj))
|
||||
}
|
||||
public struct ChatData {
|
||||
public ChatData(public let message!: String, public let source!: String) {}
|
||||
}
|
||||
|
|
|
@ -3,26 +3,16 @@
|
|||
*/
|
||||
package ohos_app_cangjie_entry.utils
|
||||
|
||||
internal import ohos.base.*
|
||||
|
||||
public class Logger {
|
||||
private let TAG: String
|
||||
public init(TAG: String) {
|
||||
this.TAG = TAG + ": "
|
||||
}
|
||||
public func debug(msg: String) {
|
||||
AppLog.debug(this.TAG + msg)
|
||||
}
|
||||
public func debug(msg: String) {}
|
||||
|
||||
public func error(msg: String) {
|
||||
AppLog.error(this.TAG + msg)
|
||||
}
|
||||
public func error(msg: String) {}
|
||||
|
||||
public func info(msg: String) {
|
||||
AppLog.info(this.TAG + msg)
|
||||
}
|
||||
public func info(msg: String) {}
|
||||
|
||||
public func warn(msg: String) {
|
||||
AppLog.warn(this.TAG + msg)
|
||||
}
|
||||
public func warn(msg: String) {}
|
||||
}
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
/**
|
||||
* Created on 2024/9/18
|
||||
*/
|
||||
package ohos_app_cangjie_entry.view_model
|
||||
|
||||
internal import ohos.component.Scroller
|
||||
import ohos_app_cangjie_entry.store.ChatStore
|
||||
import ohos_app_cangjie_entry.utils.Logger
|
||||
|
||||
public class ChatListControl {
|
||||
private let TAG: String = "ChatListControl"
|
||||
private static var scrollerForList: ?Scroller = None
|
||||
private let chatStore = ChatStore()
|
||||
|
||||
public func setScrollerForList(scroller: Scroller) {
|
||||
scrollerForList = scroller
|
||||
}
|
||||
|
||||
public func toBottom(smooth!: Bool = false): Unit {
|
||||
Logger(TAG).info("toBottom")
|
||||
scrollerForList?.scrollToIndex(Int32(this.chatStore.len() - 1), smooth: smooth)
|
||||
}
|
||||
|
||||
public func toTop(smooth!: Bool = false): Unit {
|
||||
Logger(TAG).info("toTop")
|
||||
scrollerForList?.scrollToIndex(0, smooth: smooth)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user