修复主界面上拉消息item的index获取异常
authorCaisking <3449750381@qq.com>
Mon, 15 Jul 2024 09:11:45 +0000 (17:11 +0800)
committerCaisking <3449750381@qq.com>
Mon, 15 Jul 2024 09:11:45 +0000 (17:11 +0800)
code/sdk/application/wearable/fd230app/nativeui/message/src/MessageControlPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/message/src/MessageModel.cpp
code/sdk/application/wearable/fd230app/nativeui/message/src/MessagePresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/message/src/MessageShowPresenter.cpp

index f2b1c55..494fd2b 100644 (file)
@@ -1,3 +1,9 @@
+/***
+ * @Date: 2024-06-22 11:36:16
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-07-15 16:53:35
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageControlPresenter.cpp
+ */
 /***
  * @Date: 2024-06-22 11:36:16
  * @LastEditors: Caisking 3449750381@qq.com
@@ -44,11 +50,6 @@ namespace OHOS
     {
         UNUSED(event);
         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MessageControlView::OnClick %s", view.GetViewId());
-        if (strcmp(view.GetViewId(), MAINMESSAGEVIEW) != 0)
-        {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error: View is not List");
-            return false;
-        }
 
         if (!MessageModel::GetInstance().HasDataVector())
         {
@@ -69,18 +70,13 @@ namespace OHOS
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error: Invalid view type.");
             return false;
         }
-        
-        int index1 = MessageCardView::GetInstance()->GetList()->GetViewIndex();
-        int index2 = p_MessageItemView->GetMessageListIndex();
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "index1 is %d, index2 is %d", index1, index2);
 
-        if (index2 > -1 && index2 < 11)
-        {
-            MessageModel::GetInstance().SetCurrentIndex(index2);
-            // 切换到详情界面
-            NativeAbility::GetInstance().ChangeSlice(VIEW_MESSAGE_SHOW);
-        }
+        int index = p_MessageItemView->GetMessageListIndex();
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "index is %d", index);
 
-        return true; // 返回 true 表示点击事件处理成功
+        MessageModel::GetInstance().SetCurrentIndex(index);
+        MessageModel::GetInstance().SetMessageAsRead();
+        NativeAbility::GetInstance().ChangeSlice(VIEW_MESSAGE_SHOW); // 切换到详情界面
+        return true;
     }
 } // namespace OHOS
\ No newline at end of file
index f417b0b..8f4c1a8 100644 (file)
@@ -209,7 +209,7 @@ namespace OHOS
             data.labelDetails = labelDetails->valuestring;
             data.labelTitle = labelTitle->valuestring;
             data.timestamp = timestamp->valuedouble;
-            
+
             char labelTime[20];
             if (uapi_get_TIME_STR(data.timestamp, labelTime, '.', ':', DATE_Y_M_D_H_M) != ERRCODE_SUCC)
             {
@@ -304,6 +304,8 @@ namespace OHOS
     // 设置当前项[数组下标]
     void MessageModel::SetCurrentIndex(uint8_t index)
     {
+        if (index < 0 || index > MaxMessageListCount)
+            return;
         numberOfItems = MessageVector.size();
         currentIndex_ = numberOfItems - index - 1;
     }
index 0de31f8..51924c7 100644 (file)
@@ -1,21 +1,4 @@
-/***
- * @Date: 2024-04-15 10:55:58
- * @LastEditors: Caisking 3449750381@qq.com
- * @LastEditTime: 2024-06-18 17:26:05
- * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/message/src/MessagePresenter.cpp
- */
-/***
- * @Date: 2024-04-15 10:55:58
- * @LastEditors: Caisking 3449750381@qq.com
- * @LastEditTime: 2024-06-15 15:56:50
- * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/message/src/MessagePresenter.cpp
- */
-/***
- * @Date: 2024-04-15 10:55:58
- * @LastEditors: Caisking 3449750381@qq.com
- * @LastEditTime: 2024-04-23 15:38:33
- * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/message/src/MessagePresenter.cpp
- */
+
 
 #include "AppViewIDs.h"
 #include "components/ui_label_ext.h"
@@ -94,14 +77,12 @@ namespace OHOS
         {
             NativeAbility::GetInstance().Back();
         }
-        if (!MessageModel::GetInstance().GetPopupViewState())
+        // 向下回到主界面
+        if (event.GetDragDirection() == DragEvent::DIRECTION_TOP_TO_BOTTOM)
         {
-            // 向下回到主界面
-            if (event.GetDragDirection() == DragEvent::DIRECTION_TOP_TO_BOTTOM)
-            {
-                NativeAbility::GetInstance().EnterSlice(VIEW_MAIN);
-            }
+            NativeAbility::GetInstance().EnterSlice(VIEW_MAIN);
         }
+
         return true;
     }
 
index 692688c..25860de 100644 (file)
@@ -1,3 +1,9 @@
+/*** 
+ * @Date: 2024-06-17 19:39:36
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-07-15 17:05:36
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageShowPresenter.cpp
+ */
 /***
  * @Date: 2024-06-17 19:39:36
  * @LastEditors: Caisking 3449750381@qq.com
@@ -80,7 +86,6 @@ namespace OHOS
         {
             NativeAbility::GetInstance().ChangeSlice(VIEW_MESSAGE);
         }
-
         return true;
     }