实现消息列表自适应大小
authorCaisking <3449750381@qq.com>
Sat, 10 Aug 2024 09:41:25 +0000 (17:41 +0800)
committerCaisking <3449750381@qq.com>
Sat, 10 Aug 2024 09:41:25 +0000 (17:41 +0800)
12 files changed:
code/sdk/application/wearable/fd230app/nativeui/main/src/MainViewSample.cpp
code/sdk/application/wearable/fd230app/nativeui/message/include/MessageAdapter.h
code/sdk/application/wearable/fd230app/nativeui/message/include/MessageCardView.h
code/sdk/application/wearable/fd230app/nativeui/message/include/MessageItemView.h
code/sdk/application/wearable/fd230app/nativeui/message/include/MessageLackView.h
code/sdk/application/wearable/fd230app/nativeui/message/include/MessageView.h
code/sdk/application/wearable/fd230app/nativeui/message/src/MessageAdapter.cpp
code/sdk/application/wearable/fd230app/nativeui/message/src/MessageCardView.cpp
code/sdk/application/wearable/fd230app/nativeui/message/src/MessageControlView.cpp
code/sdk/application/wearable/fd230app/nativeui/message/src/MessageItemView.cpp
code/sdk/application/wearable/fd230app/nativeui/message/src/MessageShowView.cpp
code/sdk/application/wearable/fd230app/nativeui/message/src/MessageView.cpp

index 247c87c..a9f1aac 100644 (file)
@@ -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;
     }
     // 指南针卡片
index 98a3521..5ac2f8f 100644 (file)
@@ -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<MessageListItem> listData;
         UIView::OnClickListener *itemClickListener{nullptr};
+        UILabelButtonExt *DeleteButton{nullptr};
     };
 }
 
index 25ca110..c1737a9 100644 (file)
@@ -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
index 50b8603..51330cb 100644 (file)
@@ -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
index c882fbf..a617465 100644 (file)
@@ -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
index e9e7385..1a56c24 100644 (file)
@@ -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
index 9b05ec7..58b0178 100644 (file)
@@ -1,4 +1,4 @@
-/*** 
+/***
  * @Author: Caisking 3449750381@qq.com
  * @Date: 2024-01-29 19:58:37
  * @LastEditors: Caisking 3449750381@qq.com
 #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<MessageListItem> &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<MessageItemView *>(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<MessageListItem>::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<MessageItemView *>(inView);
+            item->RemoveAll();
         }
+        item->SetUpChild();
         item->SetItemInfo(itemData);
         item->SetViewIndex(index);
         item->SetOnClickListener(itemClickListener);
index e4f57fd..0df5381 100644 (file)
@@ -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()
     {
index e6f4d07..d734715 100644 (file)
@@ -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"
index d860e73..c7b85fd 100644 (file)
@@ -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()
index c2bcc40..b3c7eb8 100644 (file)
@@ -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_);
index 7d9ed08..9e86c6b 100644 (file)
@@ -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<UIViewGroup *>(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();