From: Caisking <3449750381@qq.com> Date: Sat, 10 Aug 2024 09:41:25 +0000 (+0800) Subject: 实现消息列表自适应大小 X-Git-Tag: release_V1.2.70_20241020_135402~679^2~11 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=cf06555406d44619e22037cba0b2f9c662527489;p=mirrors%2FFD230.git 实现消息列表自适应大小 --- diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/src/MainViewSample.cpp b/code/sdk/application/wearable/fd230app/nativeui/main/src/MainViewSample.cpp index 247c87cd6..a9f1aac9e 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/src/MainViewSample.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/main/src/MainViewSample.cpp @@ -308,10 +308,6 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "messageView new fail"); return; } - if (MessageLable == nullptr) - { - MessageLable = new UILabel(); - } messageView->SetViewId("messageView"); messageView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); messageView->PreLoad(); @@ -392,6 +388,7 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainClockView new fail"); return nullptr; } + /*增加勿扰图标*/ InitImageView(disturbIcon, 213, 0, 40, 40, "disturbIcon", DISTURBICON); /*获取勿扰状态*/ @@ -399,6 +396,7 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "disturb:state[%d]\r\n", state); disturbIcon->SetVisible(state); mainClockView->Add(disturbIcon); + return mainClockView; } // 指南针卡片 diff --git a/code/sdk/application/wearable/fd230app/nativeui/message/include/MessageAdapter.h b/code/sdk/application/wearable/fd230app/nativeui/message/include/MessageAdapter.h index 98a35217a..5ac2f8fa9 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/message/include/MessageAdapter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/message/include/MessageAdapter.h @@ -1,3 +1,9 @@ +/*** + * @Date: 2024-06-28 19:21:39 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-08-09 11:44:39 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/message/include/MessageAdapter.h + */ /*** * @Date: 2024-04-15 10:55:58 * @LastEditors: Caisking 3449750381@qq.com @@ -22,6 +28,7 @@ #include "components/ui_label.h" #include "components/ui_label_ext.h" #include "components/ui_checkbox.h" +#include "components/ui_label_button_ext.h" namespace OHOS { @@ -30,7 +37,7 @@ namespace OHOS { int index; bool read; // 是否未读 - std::string labeltitle; // 来信标签 + std::string labeltitle; // 来信人 std::string labeldetails; // 信息内容 std::string labeltime; // 来信时间 } MessageListItem; @@ -57,6 +64,7 @@ namespace OHOS private: std::list listData; UIView::OnClickListener *itemClickListener{nullptr}; + UILabelButtonExt *DeleteButton{nullptr}; }; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/message/include/MessageCardView.h b/code/sdk/application/wearable/fd230app/nativeui/message/include/MessageCardView.h index 25ca11047..c1737a9f4 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/message/include/MessageCardView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/message/include/MessageCardView.h @@ -65,6 +65,7 @@ namespace OHOS UIList *MessageList = nullptr; UILabelButtonExt *DeleteButton = nullptr; // 删除按键 MessageModel *p_MessageModel{nullptr}; + UIImageView *imageline{nullptr}; }; } #endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/message/include/MessageItemView.h b/code/sdk/application/wearable/fd230app/nativeui/message/include/MessageItemView.h index 50b860357..51330cb59 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/message/include/MessageItemView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/message/include/MessageItemView.h @@ -1,3 +1,9 @@ +/*** + * @Date: 2024-04-15 10:55:58 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-08-09 11:55:24 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/message/include/MessageItemView.h + */ /*** * @Date: 2024-04-15 10:55:58 * @LastEditors: Caisking 3449750381@qq.com @@ -25,6 +31,7 @@ namespace OHOS virtual ~MessageItemView(); virtual void SetItemInfo(const MessageListItem itemInfo); virtual void SetUpChild(); + void TearDownChild(); int GetMessageListIndex(); private: @@ -35,6 +42,7 @@ namespace OHOS UILabel stime; // 时间 UILabelButton sLabelButton; // 按键 MessageListItem sItemInfo = {0, false, nullptr, nullptr, nullptr}; + bool isSetupChild{false}; }; } #endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/message/include/MessageLackView.h b/code/sdk/application/wearable/fd230app/nativeui/message/include/MessageLackView.h index c882fbfdb..a6174653a 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/message/include/MessageLackView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/message/include/MessageLackView.h @@ -1,3 +1,9 @@ +/*** + * @Date: 2024-06-19 17:04:12 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-08-10 16:50:28 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/message/include/MessageLackView.h + */ /*** * @Date: 2024-06-19 17:04:12 * @LastEditors: Caisking 3449750381@qq.com diff --git a/code/sdk/application/wearable/fd230app/nativeui/message/include/MessageView.h b/code/sdk/application/wearable/fd230app/nativeui/message/include/MessageView.h index e9e7385c3..1a56c244d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/message/include/MessageView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/message/include/MessageView.h @@ -1,27 +1,4 @@ -/*** - * @Date: 2024-07-12 11:19:36 - * @LastEditors: Caisking 3449750381@qq.com - * @LastEditTime: 2024-08-10 10:27:24 - * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/message/include/MessageView.h - */ -/*** - * @Date: 2024-04-15 10:55:58 - * @LastEditors: Caisking 3449750381@qq.com - * @LastEditTime: 2024-07-05 18:36:27 - * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/message/include/MessageView.h - */ -/*** - * @Date: 2024-04-15 10:55:58 - * @LastEditors: Caisking 3449750381@qq.com - * @LastEditTime: 2024-06-21 17:13:44 - * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/message/include/MessageView.h - */ -/*** - * @Date: 2024-04-15 10:55:58 - * @LastEditors: Caisking 3449750381@qq.com - * @LastEditTime: 2024-06-19 10:54:53 - * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/message/include/MessageView.h - */ + #ifndef Message_VIEW_H #define Message_VIEW_H 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 9b05ec775..58b017885 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageAdapter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageAdapter.cpp @@ -1,4 +1,4 @@ -/*** +/*** * @Author: Caisking 3449750381@qq.com * @Date: 2024-01-29 19:58:37 * @LastEditors: Caisking 3449750381@qq.com @@ -10,7 +10,10 @@ #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 "uicomponents/UIComponents.h" namespace OHOS { MessageListAdapter::MessageListAdapter() {} @@ -22,7 +25,7 @@ namespace OHOS uint16_t MessageListAdapter::GetCount(void) { - return listData.size(); + return listData.size() + 1; } void MessageListAdapter::SetData(std::list &data) @@ -38,38 +41,56 @@ namespace OHOS } } - /// @brief + /// @brief /// @param inView 一个指向已存在的视图对象的指 /// @param index 要创建的视图在列表中的索引l。 /// @return 返回该视图对象 UIView *MessageListAdapter::GetView(UIView *inView, int16_t index) { - - //1.先检查列表数据是否为空,若为空则返回空指针 + // 1.先检查列表数据是否为空,若为空则返回空指针 if (listData.empty()) { return nullptr; } - //2.接着检查索引是否小于0,若小于0则返回空指针 + // 2.接着检查索引是否小于0,若小于0则返回空指针 if (index < 0) { return nullptr; } - //3.检查是否超出列表数据大小,若超出则返回空指针 + printf("GetView : index %d\r\n", index); + // 3.检查是否超出列表数据大小,若超出则返回空指针 size_t uindex = index; - if (uindex >= listData.size()) - { + 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变量 + // 4.通过迭代器访问列表中指定索引位置的元素,将其赋值给itemData变量 std::list::iterator it = listData.begin(); for (int i = 0; i < index; i++) { it++; } MessageListItem itemData = *it; - MessageItemView *item = nullptr; - //5.根据传入的inView参数是否已经存在一个视图对象,若为空则创建一个新的MessageItemView对象,否则将inView转换成MessageItemView类型的指针 + // 5.根据传入的inView参数是否已经存在一个视图对象,若为空则创建一个新的MessageItemView对象,否则将inView转换成MessageItemView类型的指针 if (inView == nullptr) { item = new MessageItemView(); @@ -77,7 +98,9 @@ namespace OHOS else { item = static_cast(inView); + item->RemoveAll(); } + item->SetUpChild(); item->SetItemInfo(itemData); item->SetViewIndex(index); item->SetOnClickListener(itemClickListener); 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 e4f57fd3b..0df538133 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageCardView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageCardView.cpp @@ -17,12 +17,14 @@ namespace OHOS static MessageCardView *g_pMessageCardView = nullptr; static const uint32_t BACK_GROUND_COLOR = 0xfff6f6f6; static constexpr int16_t MORE_LIST_POSITION_X = 43; - static constexpr int16_t MORE_LIST_POSITION_Y = 120; + static constexpr int16_t MORE_LIST_POSITION_Y = 95; static constexpr int16_t MORE_SCROLLBLANKSIZE = 35; // 设置此滚动视图的空白大小。 static constexpr int16 MAX_SCR_DIS = 1000; static constexpr int16 LIST_POS = 20; static constexpr int16 SNUM_2 = 2; static constexpr uint8_t NUM_2 = 2; + + static constexpr char *lineimagePath = "/user/res/message/Line.bin"; MessageCardView::MessageCardView() { SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); @@ -39,10 +41,10 @@ namespace OHOS void MessageCardView::ClearAll(void) { RemoveAll(); - if (title != nullptr) + if (imageline != nullptr) { - delete title; - title = nullptr; + delete imageline; + imageline = nullptr; } if (MessageList != nullptr) { @@ -64,9 +66,10 @@ namespace OHOS bool MessageCardView::InitPage(void) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "InitPage is begin"); - /*初始化label*/ - InitLabelExt(title, 83, 50, 300, 35, "labletitle", STR_MESSAGE_NOTIFICATION, DEFAULT_VECTOR_FONT_FILENAME, 30); - Add(title); + + /*初始化image*/ + InitImageView(imageline, 193, 30, 365, 35, "image", lineimagePath); + Add(imageline); // UIList 的适配器 p_MessageListAdapter = new MessageListAdapter(); @@ -76,34 +79,24 @@ namespace OHOS MessageList = new UIList(); } MessageList->SetPosition(MORE_LIST_POSITION_X, MORE_LIST_POSITION_Y, 466, 466); - // MessageList->SetScrollStateListener(this); + MessageList->SetScrollBlankSize(35); + MessageList->SetReboundSize(50); MessageList->SetThrowDrag(true); MessageList->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); - // 设置手指抬起屏幕后的最大滚动距离 MessageList->SetMaxScrollDistance(1000); // 1000: max scroll distance - // 设置手指抬起屏幕后的补偿距离 - MessageList->SetSwipeACCLevel(800); // 800: compensation distance - // 设置拖动加速 - MessageList->SetDragACCLevel(5); // 5: drag acceleration - MessageList->SetYScrollBarVisible(true); + MessageList->SetSwipeACCLevel(800); // 800: compensation distance + MessageList->SetDragACCLevel(5); // 5: drag acceleration MessageList->SetViewId(MAINMESSAGEVIEW); - - // SetYScrollBarVisible(true); // 设置滑动滚动条 - UIView::OnClickListener *clickListener = (UIView::OnClickListener *)OHOS::MessageControlPresenter::GetInstance(); - if (clickListener == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AddButton::OnStart clickListener NULL"); - return false; - } - MessageList->SetOnClickListener(clickListener); - UIView::OnDragListener *Messagedraglistener = (UIView::OnDragListener *)(MessageControlPresenter::GetInstance()); + MessageList->SetOnClickListener((UIView::OnClickListener *)OHOS::MessageControlPresenter::GetInstance()); + MessageList->SetIntercept(true); Add(MessageList); MessageList->SetAdapter(p_MessageListAdapter); - MessageList->RefreshList(); - SetDraggable(false); - SetTouchable(false); + // MessageList->RefreshList(); + // SetDraggable(true); + // SetTouchable(true); + initViewStatus = true; WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "InitPage is end"); return true; @@ -150,7 +143,6 @@ namespace OHOS } void MessageCardView::UpdateMessageCard() { - } UIList *MessageCardView::GetList() { diff --git a/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageControlView.cpp b/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageControlView.cpp index e6f4d07b6..d7347151c 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageControlView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageControlView.cpp @@ -1,27 +1,4 @@ -/*** - * @Date: 2024-07-11 14:52:39 - * @LastEditors: Caisking 3449750381@qq.com - * @LastEditTime: 2024-07-25 10:28:36 - * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageControlView.cpp - */ -/*** - * @Date: 2024-07-11 14:52:39 - * @LastEditors: Caisking 3449750381@qq.com - * @LastEditTime: 2024-07-25 09:41:22 - * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageControlView.cpp - */ -/*** - * @Date: 2024-07-11 14:52:39 - * @LastEditors: Caisking 3449750381@qq.com - * @LastEditTime: 2024-07-25 09:32:03 - * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageControlView.cpp - */ -/* - * Copyright (c) CompanyNameMagicTag 2022-2022. All rights reserved. - * Description: MessageControlView.cpp - * Author: - * Create: 2022-04-02 - */ + #include "message/include/MessageControlView.h" #include "message/include/MessageModel.h" #include "message/include/MessageControlPresenter.h" diff --git a/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageItemView.cpp b/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageItemView.cpp index d860e7313..c7b85fd17 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageItemView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageItemView.cpp @@ -4,22 +4,24 @@ namespace OHOS { static constexpr const char *ICON_IMAGE = "user/res/message/Icon.bin"; +#define SELF_ADAPTION 1 + #define RECTANGLE_WIDTH 380 -// 定义不同大小矩形的长度常量 +// 定义不同大小背景矩形的长度常量 #define SMALL_RECTANGLE_LENGTH 180 #define MEDIUM_RECTANGLE_LENGTH 210 #define BIG_RECTANGLE_LENGTH 240 // 定义不同大小标签的长度常量 #define SMALL_LABEL_LENGTH 30 -#define MEDIUM_LABEL_LENGTH 70 -#define BIG_LABEL_LENGTH 105 +#define MEDIUM_LABEL_LENGTH 80 +#define BIG_LABEL_LENGTH 115 // 时间的top -#define SMALL_TIMELABEL_LENGTH 108 -#define MEDIUM_TIMELABEL_LENGTH 139 -#define BIG_LABELTIME_LENGTH 171 +#define SMALL_TIMELABEL_LENGTH 110 +#define MEDIUM_TIMELABEL_LENGTH 141 +#define BIG_LABELTIME_LENGTH 173 // 定义全局变量 static int item_length = BIG_RECTANGLE_LENGTH; @@ -29,66 +31,75 @@ namespace OHOS MessageItemView::MessageItemView() { SetPosition(0, 0, RECTANGLE_WIDTH, item_length); + // SetStyle(STYLE_BACKGROUND_COLOR, 0xff303030); SetStyle(STYLE_BACKGROUND_OPA, 255); SetStyle(STYLE_BORDER_RADIUS, 20); SetTouchable(true); - SetUpChild(); - - Add(&sLabelButton); - Add(&sIcon); - Add(&stitle); - Add(&smessgae); - Add(&stime); } MessageItemView::~MessageItemView() { - Remove(&sIcon); - Remove(&stitle); - Remove(&smessgae); - Remove(&stime); - Remove(&sLabelButton); + RemoveAll(); } void MessageItemView::SetItemInfo(const MessageListItem itemInfo) { sItemInfo = itemInfo; -#if 0 +#if SELF_ADAPTION // 根据 labeldetails 的大小设置矩形和标签的长度 - if (itemInfo.labeldetails.size() <= 10) + printf("itemInfo.labeldetails.size():%d\r\n", itemInfo.labeldetails.size()); + if (itemInfo.labeldetails.size() <= 30) // 一行 { - label_length = SMALL_LABEL_LENGTH; item_length = SMALL_RECTANGLE_LENGTH; + label_length = SMALL_LABEL_LENGTH; time_top = SMALL_TIMELABEL_LENGTH; } - else if (itemInfo.labeldetails.size() > 10 && itemInfo.labeldetails.size() <= 20) + else if (itemInfo.labeldetails.size() > 30 && itemInfo.labeldetails.size() <= 60) // 两行 { - label_length = MEDIUM_LABEL_LENGTH; item_length = MEDIUM_RECTANGLE_LENGTH; + label_length = MEDIUM_LABEL_LENGTH; time_top = MEDIUM_TIMELABEL_LENGTH; } else { - label_length = BIG_LABEL_LENGTH; item_length = BIG_RECTANGLE_LENGTH; + label_length = BIG_LABEL_LENGTH; time_top = BIG_LABELTIME_LENGTH; } - + /* 自适应消息列表配置 测试中 */ SetPosition(0, 0, RECTANGLE_WIDTH, item_length); + smessgae.SetPosition(40, 69, 300, label_length); + stime.SetPosition(40, time_top, 300, 33); + sLabelButton.SetPosition(0, 0, 380, item_length - 20); #endif - if (!itemInfo.read) - { - sIcon.SetSrc(ICON_IMAGE); - } + sIcon.SetSrc(ICON_IMAGE); stitle.SetText(itemInfo.labeltitle.c_str()); smessgae.SetText(itemInfo.labeldetails.c_str()); stime.SetText(itemInfo.labeltime.c_str()); + // 设置图标可见性 + sIcon.SetVisible(!itemInfo.read); - // printf("%d %s %s %s\r\n", itemInfo.read, itemInfo.labeltitle.c_str(), itemInfo.labeldetails.c_str(), itemInfo.labeltime.c_str()); + printf("MessageItemView itemInfo %d %s %s\r\n", itemInfo.read, itemInfo.labeltitle.c_str(), itemInfo.labeldetails.c_str(), itemInfo.labeltime.c_str()); + printf("MessageItemView size %d %d %d\r\n", label_length, item_length, time_top); } + void MessageItemView::TearDownChild() + { + if (!isSetupChild) + return; + Remove(&sIcon); + Remove(&stitle); + Remove(&smessgae); + Remove(&stime); + Remove(&sLabelButton); + + isSetupChild = false; + } void MessageItemView::SetUpChild() { + if (isSetupChild) + return; + sIcon.SetPosition(40, 43); sIcon.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE); @@ -99,12 +110,10 @@ namespace OHOS stitle.SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); stitle.SetRollSpeed(70); - smessgae.SetPosition(40, 69, 300, label_length); smessgae.SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); smessgae.SetTextColor(Color::Gray()); smessgae.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - stime.SetPosition(40, time_top, 300, 33); stime.SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); stime.SetTextColor(Color::Gray()); stime.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 28); @@ -112,9 +121,18 @@ namespace OHOS sLabelButton.SetPosition(0, 0, 380, item_length - 20); sLabelButton.SetStyle(STYLE_BACKGROUND_COLOR, 0xff303030); sLabelButton.SetStyle(STYLE_BORDER_RADIUS, 20); - sLabelButton.SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + sLabelButton.SetStyleForState(STYLE_BORDER_RADIUS, 20, UIButton::PRESSED); + sLabelButton.SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff000000, UIButton::PRESSED); sLabelButton.SetTouchable(true); + + Add(&sLabelButton); + Add(&sIcon); + Add(&stitle); + Add(&smessgae); + Add(&stime); + + isSetupChild = false; } int MessageItemView::GetMessageListIndex() diff --git a/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageShowView.cpp b/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageShowView.cpp index c2bcc40f2..b3c7eb8cc 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageShowView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageShowView.cpp @@ -41,7 +41,6 @@ namespace OHOS std::string timeStr = "2023.12.26 17:23"; std::string messageStr = "【铁路12306】系统已自动为您生成订单EC09828333,04月23日G2231次,深圳北站13:31开。请您在2小时内完成支付。您可通过以下链接进行支付。https://www.12306.cn/index/"; #endif - std::string titleStr, timeStr, messageStr; MessageShowView::MessageShowView() { @@ -159,6 +158,7 @@ namespace OHOS container_->Add(messageButton); container_->Add(deleteButton); /* -------------------------------------------------------------------------- */ + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitView is ok!"); // UpdateMessage(); } @@ -200,7 +200,6 @@ namespace OHOS PreLoad(); - RootView::GetInstance()->Add(container_); SetContainerView(container_); RootView::GetInstance()->SetOnKeyActListener(presenter_); 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 7d9ed0860..9e86c6b53 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageView.cpp @@ -1,4 +1,9 @@ - +/*** + * @Date: 2024-07-12 11:19:45 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-08-09 14:03:51 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageView.cpp + */ #include "message/include/MessageView.h" #include "message/include/MessagePresenter.h" @@ -30,10 +35,13 @@ namespace OHOS MessageView::~MessageView() { - if (viewInitStatus == true) - { - DeInitView(); - } + // if (viewInitStatus == true) + // { + // DeInitView(); + // } + UIViewGroup *tmpGroup = dynamic_cast(container_); + UIViewGroup::RemoveAndDeleteAllRecursively(tmpGroup); + g_pMessageView = nullptr; } @@ -130,7 +138,7 @@ namespace OHOS lackView->Add(labeltitle); lackView->Add(labelmeage); - RootView::GetInstance()->Add(lackView); + container_->Add(lackView); lackView->SetDraggable(true); lackView->SetTouchable(true); @@ -180,16 +188,7 @@ namespace OHOS MessageList->SetOnClickListener(presenter_); messageView->SetOnDragListener(presenter_); -#if 0 - /*删除按键*/ - int top = MessageList->GetHeight(); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "old top %d", top); - top > 466 ? top += 130 : top -= 100; - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new top %d", top); - InitButtonExt(DeleteButton, 43, top, 380, 100, DELETEALLDATA, STR_CLEANALL, 30); - DeleteButton->SetOnClickListener(presenter_); - messageView->Add(DeleteButton); -#endif + messageView->SetVisible(false); // 隐藏界面 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ShowmessageView end"); } @@ -205,27 +204,19 @@ namespace OHOS void MessageView::SetPopupViewStatus(PopupMessage view, bool status) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SetPopupViewStatus %d", view); - UIView *popupView = nullptr; + if (view == PopupMessage::LackPopup) { - MessageModel::GetInstance().SetPopupViewState(false); // 设置状态为无记录 - popupView = lackView; + MessageModel::GetInstance().SetPopupViewState(false); // 设置状态为无消息 + lackView->SetVisible(true); // 隐藏界面 + messageView->SetVisible(false); // 隐藏界面 } else if (view == PopupMessage::MessagePopup) { - MessageModel::GetInstance().SetPopupViewState(true); // 设置状态为有记录 - popupView = messageView; - } - if (popupView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PopupView is NULL"); - return; - } - if (container_ != nullptr) - { - container_->SetVisible(!status); + MessageModel::GetInstance().SetPopupViewState(true); // 设置状态为有消息 + lackView->SetVisible(false); // 隐藏界面 + messageView->SetVisible(true); // 隐藏界面 } - popupView->SetVisible(status); } /// @brief 页面启动时需要执行的代码逻辑 @@ -245,7 +236,6 @@ namespace OHOS ShowMessageView(); PreLoad(); - RootView::GetInstance()->Add(container_); SetContainerView(container_); RootView::GetInstance()->SetOnKeyActListener(presenter_); @@ -266,8 +256,9 @@ namespace OHOS if (MessageModel::GetInstance().HasDataVector()) { messageView->Add(MessageList); + messageView->Add(DeleteButton); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MessageList is add"); - RootView::GetInstance()->Add(messageView); + container_->Add(messageView); MessageList->SetAdapter(p_MessageListAdapter); } Draw();