From 516e30431e9aa57d2d6677e8329bf1aec7dcd127 Mon Sep 17 00:00:00 2001 From: Caisking <3449750381@qq.com> Date: Sat, 5 Oct 2024 17:03:47 +0800 Subject: [PATCH] =?utf8?q?=E6=B6=88=E6=81=AF=EF=BC=9A=E4=BF=AE=E5=A4=8D?= =?utf8?q?=E6=B6=88=E6=81=AF=E5=88=97=E8=A1=A8=E6=98=BE=E7=A4=BA=E4=B8=8D?= =?utf8?q?=E5=AE=8C=E6=88=90=E7=9A=84=E6=8C=89=E9=94=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/message/src/MessageAdapter.cpp | 185 ++++++++---------- .../nativeui/message/src/MessageCardView.cpp | 3 +- .../nativeui/message/src/MessageView.cpp | 10 +- 3 files changed, 91 insertions(+), 107 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageAdapter.cpp b/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageAdapter.cpp index 3e7aceaca..20d01164b 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageAdapter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageAdapter.cpp @@ -3,118 +3,103 @@ * @Date: 2024-01-29 19:58:37 * @LastEditors: Caisking 3449750381@qq.com * @LastEditTime: 2024-06-21 10:35:36 - * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageAdapter.cpp - * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + * @FilePath: + * /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageAdapter.cpp + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 + * 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE */ #include "message/include/MessageAdapter.h" #include "message/include/MessageItemView.h" -#include "wearable_log.h" -#include "message/include/MessagePresenter.h" #include "message/include/MessageModel.h" +#include "message/include/MessagePresenter.h" +#include "wearable_log.h" #include "uicomponents/UIComponents.h" -namespace OHOS -{ - MessageListAdapter::MessageListAdapter() {} +namespace OHOS { +MessageListAdapter::MessageListAdapter() {} - MessageListAdapter::~MessageListAdapter() - { - if(DeleteButton) - { - delete DeleteButton; - DeleteButton = nullptr; - } - listData.clear(); - } +MessageListAdapter::~MessageListAdapter() { + if (DeleteButton) { + delete DeleteButton; + DeleteButton = nullptr; + } + listData.clear(); +} - uint16_t MessageListAdapter::GetCount(void) - { - return listData.size() + 1; - } +uint16_t MessageListAdapter::GetCount(void) { return listData.size() + 1; } - void MessageListAdapter::SetData(std::list &data) - { - if (!listData.empty()) - { - listData.clear(); - } - std::list::iterator it; - for (it = data.begin(); it != data.end(); it++) - { - listData.push_back(*it); - } - } +void MessageListAdapter::SetData(std::list &data) { + if (!listData.empty()) { + listData.clear(); + } + std::list::iterator it; + for (it = data.begin(); it != data.end(); it++) { + listData.push_back(*it); + } +} - /// @brief - /// @param inView 一个指向已存在的视图对象的指 - /// @param index 要创建的视图在列表中的索引l。 - /// @return 返回该视图对象 - UIView *MessageListAdapter::GetView(UIView *inView, int16_t index) - { - // 1.先检查列表数据是否为空,若为空则返回空指针 - if (listData.empty()) - { - return nullptr; - } - // 2.接着检查索引是否小于0,若小于0则返回空指针 - if (index < 0) - { - return nullptr; - } - // printf("GetView : index %d\r\n", index); - // 3.检查是否超出列表数据大小,若超出则返回空指针 - size_t uindex = index; - if (uindex > listData.size()) - return nullptr; +/// @brief +/// @param inView 一个指向已存在的视图对象的指 +/// @param index 要创建的视图在列表中的索引l。 +/// @return 返回该视图对象 +UIView *MessageListAdapter::GetView(UIView *inView, int16_t index) { + // 1.先检查列表数据是否为空,若为空则返回空指针 + if (listData.empty()) { + return nullptr; + } + // 2.接着检查索引是否小于0,若小于0则返回空指针 + if (index < 0) { + return nullptr; + } + // printf("GetView : index %d\r\n", index); + // 3.检查是否超出列表数据大小,若超出则返回空指针 + size_t uindex = index; + if (uindex > listData.size()) + return nullptr; - MessageItemView *item = nullptr; - if (uindex == listData.size()) - { - if (inView == nullptr) - { - item = new MessageItemView(); - } - else - { - item = static_cast(inView); - // item->TearDownChild(); - item->RemoveAll(); - } - InitButtonExt(DeleteButton, 0, 0, 380, 100, DELETEALLDATA, STR_CLEANALL, 30); - DeleteButton->SetOnClickListener(itemClickListener); - item->Add(DeleteButton); - item->SetViewIndex(index); - item->SetOnClickListener(nullptr); - return item; - } - // 4.通过迭代器访问列表中指定索引位置的元素,将其赋值给itemData变量 - std::list::iterator it = listData.begin(); - for (int i = 0; i < index; i++) - { - it++; - } - MessageListItem itemData = *it; - // 5.根据传入的inView参数是否已经存在一个视图对象,若为空则创建一个新的MessageItemView对象,否则将inView转换成MessageItemView类型的指针 - if (inView == nullptr) - { - item = new MessageItemView(); - } - else - { - item = static_cast(inView); - item->TearDownChild(); - item->RemoveAll(); - } - item->SetUpChild(); - item->SetItemInfo(itemData); - item->SetViewIndex(index); - item->SetOnClickListener(itemClickListener); - return item; + MessageItemView *item = nullptr; + if (uindex == listData.size()) { + if (inView == nullptr) { + item = new MessageItemView(); + } else { + item = static_cast(inView); + // item->TearDownChild(); + item->RemoveAll(); } + InitButtonExt(DeleteButton, 0, 0, 380, 100, DELETEALLDATA, STR_CLEANALL, + 30); + DeleteButton->SetOnClickListener(itemClickListener); + item->Add(DeleteButton); + item->SetViewIndex(index); + item->SetOnClickListener(nullptr); + item->SetHeight(300); + // printf("GetView : item GetHeight %d GetWidth %d\r\n", item->GetHeight(), + // item->GetWidth()); + return item; + } + // 4.通过迭代器访问列表中指定索引位置的元素,将其赋值给itemData变量 + std::list::iterator it = listData.begin(); + for (int i = 0; i < index; i++) { + it++; + } + MessageListItem itemData = *it; + // 5.根据传入的inView参数是否已经存在一个视图对象,若为空则创建一个新的MessageItemView对象,否则将inView转换成MessageItemView类型的指针 + if (inView == nullptr) { + item = new MessageItemView(); + } else { + item = static_cast(inView); + item->TearDownChild(); + item->RemoveAll(); + } + item->SetUpChild(); + item->SetItemInfo(itemData); + item->SetViewIndex(index); + item->SetOnClickListener(itemClickListener); + return item; +} - void MessageListAdapter::AddListItem(const MessageListItem &item) - { - listData.push_back(item); - } +void MessageListAdapter::AddListItem(const MessageListItem &item) { + listData.push_back(item); +} } // namespace OHOS diff --git a/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageCardView.cpp b/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageCardView.cpp index 861644ef9..363057b04 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageCardView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageCardView.cpp @@ -85,8 +85,6 @@ namespace OHOS } // MessageList->SetPosition(MORE_LIST_POSITION_X, MORE_LIST_POSITION_Y, 466, 466); MessageList->SetPosition(MORE_LIST_POSITION_X, MORE_LIST_POSITION_Y, 466, 466); - // MessageList->SetScrollBlankSize(35); - // MessageList->SetReboundSize(50); MessageList->SetThrowDrag(true); MessageList->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); MessageList->SetMaxScrollDistance(1000); // 1000: max scroll distance @@ -96,6 +94,7 @@ namespace OHOS MessageList->SetOnClickListener((UIView::OnClickListener *)OHOS::MessageControlPresenter::GetInstance()); MessageList->SetIntercept(true); + Add(MessageList); MessageList->SetAdapter(p_MessageListAdapter); diff --git a/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageView.cpp b/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageView.cpp index f53fb2d90..e0063bedc 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageView.cpp @@ -181,13 +181,8 @@ void MessageView::ShowMessageView() { messageView->Add(MessageList); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MessageList is add"); - container_->Add(messageView); - if (p_MessageListAdapter) { - MessageList->SetAdapter(p_MessageListAdapter); - } - messageView->SetVisible(false); // 隐藏界面 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ShowmessageView end"); } @@ -233,6 +228,11 @@ UIList *MessageView::GetList() { return MessageList; } /// @brief 创建页面的视图 void MessageView::OnSetUpView() { View::OnSetUpView(); + if (MessageModel::GetInstance().HasDataVector()) { + if (p_MessageListAdapter) { + MessageList->SetAdapter(p_MessageListAdapter); + } + } Draw(); } -- 2.17.1