applist的样式保存改用ConfigModel 628/2 628/head 629/target/1
authorluozheng <1732036298@qq.com>
Fri, 2 Aug 2024 01:58:50 +0000 (09:58 +0800)
committerluozheng <1732036298@qq.com>
Fri, 2 Aug 2024 01:58:50 +0000 (09:58 +0800)
code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistView.cpp
code/sdk/application/wearable/fd230app/nativeui/themestyle/src/ThemeStyleModel.cpp
code/sdk/drivers/peripheral/config/include/ConfigModel.h

index fcb583b..6d24541 100644 (file)
@@ -101,23 +101,24 @@ void ApplistView::FootballStyleOnStart()
 void ApplistView::HexagonsStyleOnStart()
 {
     WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::HexagonsStyleOnStart start...");
-    if (hexagonsList_ == nullptr) {
+    if (hexagonsList_ == nullptr) 
+    {
         hexagonsList_ = new UICustomHexagonsList();
+        hexagonsList_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
+        imgDistance_ = hexagonsList_->GetWidth() * 0.25991; // 0.25991, empirical coefficient
+        imgSize_ = hexagonsList_->GetWidth() * 0.23348; // 0.23348, empirical coefficient
+        hexagonsList_->SetImageDistance(imgDistance_);
+        hexagonsList_->SetImageSizeInCenter(imgSize_);
+        int16_t blankSize = hexagonsList_->GetRelativeRect().GetWidth() > hexagonsList_->GetRelativeRect().GetHeight() ?
+            hexagonsList_->GetRelativeRect().GetWidth() / 2 : hexagonsList_->GetRelativeRect().GetHeight() / 2; // 2, half
+        hexagonsList_->SetScrollBlankSize(blankSize);
+        hexagonsList_->SetReboundSize(blankSize);
+        hexagonsList_->SetThrowDrag(true);
+        hexagonsList_->SetOnRotateListener(presenter_);
+        hexagonsList_->RequestFocus();
+        SetContainerView(hexagonsList_);
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::HexagonsStyleOnStart start...");
     }
-    hexagonsList_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
-    imgDistance_ = hexagonsList_->GetWidth() * 0.25991; // 0.25991, empirical coefficient
-    imgSize_ = hexagonsList_->GetWidth() * 0.23348; // 0.23348, empirical coefficient
-    hexagonsList_->SetImageDistance(imgDistance_);
-    hexagonsList_->SetImageSizeInCenter(imgSize_);
-    int16_t blankSize = hexagonsList_->GetRelativeRect().GetWidth() > hexagonsList_->GetRelativeRect().GetHeight() ?
-        hexagonsList_->GetRelativeRect().GetWidth() / 2 : hexagonsList_->GetRelativeRect().GetHeight() / 2; // 2, half
-    hexagonsList_->SetScrollBlankSize(blankSize);
-    hexagonsList_->SetReboundSize(blankSize);
-    hexagonsList_->SetThrowDrag(true);
-    hexagonsList_->SetOnRotateListener(presenter_);
-    hexagonsList_->RequestFocus();
-    SetContainerView(hexagonsList_);
-    WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::HexagonsStyleOnStart start...");
 }
 
 //列表OnStart
@@ -129,47 +130,51 @@ void ApplistView::ListStyleOnStart()
         if (listGroup == nullptr){
             return;
         }
+        SetContainerView(listGroup);
+        container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
     }
-    SetContainerView(listGroup);
-    container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
+    /* ------------------------------ listAdapter_ ------------------------------ */
     if(listAdapter_== nullptr) {
         listAdapter_ = new ApplistAdapter();
         if (listAdapter_ == nullptr){
             return;
         }
+        listAdapter_->SetItemClickListener(presenter_);
     }
-    listAdapter_->SetItemClickListener(presenter_);
+    /* ------------------------------ contentList_ ------------------------------ */
     if(contentList_ == nullptr) {
         contentList_ = new UIList(UIList::VERTICAL);
         if (contentList_ == nullptr){
             return;
         }
+        contentList_->SetPosition(0, 0);
+        contentList_->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);
+        contentList_->SetScrollBlankSize(VERTICAL_RESOLUTION / NUM_2);
+        contentList_->SetSelectPosition(VERTICAL_RESOLUTION / NUM_2); // middle position
+        contentList_->SetDraggable(true);
+        contentList_->SetThrowDrag(true);
+        contentList_->EnableAutoAlign(true);
+        contentList_->SetScrollStateListener(presenter_);
+        contentList_->SetMaxScrollDistance(MAX_SCROLL_DIS);
+        contentList_->SetYScrollBarVisible(true);
+        contentList_->SetRotateFactor(ROTATE_FACTOR_2); // 增加表冠控制
+        contentList_->RequestFocus();
+        container_->Add(contentList_);
+        /* ------------------------------ dragListener ------------------------------ */
+        if(dragListener == nullptr){
+            dragListener = new AppListOnDragListener();
+            if (dragListener == nullptr) {
+                return;
+            }
+        }
+        contentList_->SetOnDragListener(dragListener);
     }
-    contentList_->SetPosition(0, 0);
-    contentList_->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);
-    contentList_->SetScrollBlankSize(VERTICAL_RESOLUTION / NUM_2);
-    contentList_->SetSelectPosition(VERTICAL_RESOLUTION / NUM_2); // middle position
-    contentList_->SetDraggable(true);
-    contentList_->SetThrowDrag(true);
-    contentList_->EnableAutoAlign(true);
-    contentList_->SetScrollStateListener(presenter_);
-    contentList_->SetMaxScrollDistance(MAX_SCROLL_DIS);
-    contentList_->SetYScrollBarVisible(true);
-    contentList_->SetRotateFactor(ROTATE_FACTOR_2); // 增加表冠控制
-    contentList_->RequestFocus();
-    container_->Add(contentList_);
-
-    dragListener = new AppListOnDragListener();
-    if (dragListener == nullptr) {
-        return;
-    }
-    contentList_->SetOnDragListener(dragListener);
     WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::ListStyleOnStart end...");
 }
 
 void ApplistView::OnSetUpView()
 {
-    WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::OnSetUpView");
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ApplistView::OnSetUpView");
     View<ApplistPresenter>::OnSetUpView();
     AppListStyle style = presenter_->GetCurrentStyle();
     if (style == AppListStyle::FOOTBALL_STYLE) {
index 7ae3c11..25a5c07 100644 (file)
@@ -8,7 +8,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-06-07 09:21:47
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-07-17 15:35:23
+ * @LastEditTime: 2024-08-02 09:55:52
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/set_desktop/src/ThemeStyleModel.cpp
  */
 
@@ -17,6 +17,7 @@
 #include "securec.h"
 #include "wearable_log.h"
 #include <ohos_errno.h>
+#include "ConfigModel.h"
 namespace OHOS
 {
     static const int STYLE_VALUE_LEN = 32;
@@ -36,17 +37,8 @@ namespace OHOS
     {
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ThemeStyleModel::GetAppListDisplayStyle");
 
-        char temp[STYLE_VALUE_LEN] = {0};
-        int ret = UtilsGetValue(THEMESTYLE_KEY, temp, STYLE_VALUE_LEN); // 从文件系统或缓存中获取与指定键匹配的值。
-        if (ret < 0)
-        {
-            UtilsSetValue(THEMESTYLE_KEY, THEMESTYLE_VALUE_LIST); // 设置默认值
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UtilsGetValue error,temp:%s,ret = %d", temp, ret);
-            return ThemeStyle::APPLIST_STYLE;
-        }
-
         // 检查是否存在对应的样式选项
-        auto it = ReverseThemeStyleMap.find(std::string(temp));
+        auto it = ReverseThemeStyleMap.find(OHOS::ConfigModel::GetInstance()->get_configData_string(OHOS::ConfigModel::CONFIGMODEL_ITEM_APPLIST_STYLE));
         if (it != ReverseThemeStyleMap.end())
         {
             return it->second;
@@ -67,16 +59,10 @@ namespace OHOS
         // 检查是否存在对应的样式选项
         if (ThemeStyleMap.find(style) != ThemeStyleMap.end())
         {
-            const char *value = THEMESTYLE_KEY;
-            const char *key = ThemeStyleMap.at(style).c_str();
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "value:%s,key:%s", value, key);
+            const char *value = ThemeStyleMap.at(style).c_str();
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "value:%s", value);
             // 根据映射设置显示样式值
-            int ret = UtilsSetValue(value, key);
-            if (ret != EC_SUCCESS)
-            {
-                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UtilsSetValue error,ret = %d", ret);
-                return;
-            }
+            OHOS::ConfigModel::GetInstance()->set_condigData_String(OHOS::ConfigModel::CONFIGMODEL_ITEM_APPLIST_STYLE, value);
         }
         else
         {
index e0281d1..7414d00 100644 (file)
@@ -128,6 +128,7 @@ namespace OHOS
             CONFIGMODEL_ITEM_SELECT_AIMODEL,//ai模型
             CONFIGMODEL_ITEM_FIRSTTIMESTART,//手表是否是第一次启动
             CONFIGMODEL_ITEM_OPEN_AI_API_KEYS,//API Keys
+            CONFIGMODEL_ITEM_APPLIST_STYLE,//applist的显示样式
             CONFIGMODEL_ITEM_MAX,
         } ;
 
@@ -377,6 +378,7 @@ namespace OHOS
             {ConfigDataType::DATATYPE_INT,     "select_aimodel",       "0"          },//CONFIGMODEL_ITEM_SELECT_AIMODEL
             {ConfigDataType::DATATYPE_BOOL,     "is_first_time_start",       "true"    }, //CONFIGMODEL_ITEM_FIRSTTIMESTART true :手表第一次启动,否则不是
             {ConfigDataType::DATATYPE_STRING,     "open_ai_api_keys",       "-1"    }, //CONFIGMODEL_ITEM_OPEN_AI_API_KEYS 
+            {ConfigDataType::DATATYPE_STRING,     "applist_style",       "list"    }, //CONFIGMODEL_ITEM_APPLIST_STYLE 
         };
         ConfigModel();                                        // 私有构造函数,确保无法在外部实例化
         ConfigModel(const ConfigModel &) = delete;            // 禁止拷贝构造