【训练记录】UI
authorCaisking <Casiking@zhihuishixun.com>
Fri, 25 Apr 2025 10:14:06 +0000 (18:14 +0800)
committerCaisking <Casiking@zhihuishixun.com>
Fri, 25 Apr 2025 10:14:06 +0000 (18:14 +0800)
code/sdk/application/wearable/fd230/nativeapp/nativeui/traingrecord/include/TraingRecordAdapter.h [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/traingrecord/include/TraingRecordItemView.h [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/traingrecord/include/TraingRecordModel.h [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/traingrecord/include/TraingRecordPresenter.h [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/traingrecord/include/TraingRecordView.h [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/traingrecord/src/TraingRecordAdapter.cpp [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/traingrecord/src/TraingRecordItemView.cpp [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/traingrecord/src/TraingRecordModel.cpp [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/traingrecord/src/TraingRecordPresenter.cpp [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/traingrecord/src/TraingRecordView.cpp [new file with mode: 0644]

diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/traingrecord/include/TraingRecordAdapter.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/traingrecord/include/TraingRecordAdapter.h
new file mode 100644 (file)
index 0000000..ef595fa
--- /dev/null
@@ -0,0 +1,58 @@
+/*** 
+ * @Date: 2024-05-20 19:40:41
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-06-07 20:24:32
+ * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/traingrecord/include/TraingRecordAdapter.h
+ */
+
+#ifndef TraingRecord_ADAPTER_H
+#define TraingRecord_ADAPTER_H
+#include <list>
+#include <string>
+#include "components/ui_list.h"
+#include "components/abstract_adapter.h"
+#include "components/ui_label.h"
+#include "components/ui_label_ext.h"
+#include "components/ui_checkbox.h"
+#include "AppViewIDs.h"
+#include "components/ui_label_ext.h"
+#include "ui_resource_string.h"
+
+// 列表的适配器
+namespace OHOS
+{
+
+    typedef struct
+    {
+        int index;         // 下标
+        std::string image; // 训练类icon
+        std::string data;  // 日期
+        std::string time;  // 时间
+    } TraingRecordItem;
+
+    class TraingRecordAdapter : public AbstractAdapter
+    {
+    public:
+        explicit TraingRecordAdapter();
+        virtual ~TraingRecordAdapter();
+
+        void SetData(std::list<TraingRecordItem> &data);
+
+        virtual uint16_t GetCount(void) override;
+
+        virtual UIView *GetView(UIView *inView, int16_t index) override;
+
+        virtual void AddItem(const TraingRecordItem &item);
+
+        void SetItemClickListener(UIView::OnClickListener *itemclicklistener)
+        {
+            itemClickListener = itemclicklistener;
+        }
+
+    private:
+        std::list<TraingRecordItem> listData;
+        UIView::OnClickListener *itemClickListener{nullptr};
+    };
+}
+
+#endif
\ No newline at end of file
diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/traingrecord/include/TraingRecordItemView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/traingrecord/include/TraingRecordItemView.h
new file mode 100644 (file)
index 0000000..93d2bb3
--- /dev/null
@@ -0,0 +1,55 @@
+/***
+ * @Date: 2024-05-20 19:40:41
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-06-08 11:27:43
+ * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/traingrecord/include/TraingRecordItemView.h
+ */
+/***
+ * @Author: Caisking 3449750381@qq.com
+ * @Date: 2024-03-27 11:12:32
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-03-30 11:05:58
+ * @FilePath: /sdk/application/wearable/fd230app/nativeui/traing/training_list_Record/include/TraingRecordItemView.h
+ * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
+ */
+
+#ifndef TraingRecord_ITEM_VIEW_H
+#define TraingRecord_ITEM_VIEW_H
+
+#include "components/ui_label.h"
+#include "components/ui_label_ext.h"
+#include "components/ui_view_group.h"
+#include "components/ui_checkbox.h"
+#include "components/ui_image_view.h"
+#include "traingrecord/include/TraingRecordAdapter.h"
+#include "components/ui_label_button.h"
+#include "AppViewIDs.h"
+#include "components/ui_label_ext.h"
+#include "ui_resource_string.h"
+#include "ohos_types.h"
+
+namespace OHOS
+{
+    class TraingRecordItemView : public UIViewGroup
+    {
+    public:
+        explicit TraingRecordItemView();
+        virtual ~TraingRecordItemView();
+        static TraingRecordItemView &GetInstance(void);
+
+        virtual void SetItemInfo(const TraingRecordItem itemInfo);
+        virtual void SetUpChild();
+        int GetTraingRecordIndex();
+
+    private:
+        TraingRecordItemView(const TraingRecordItemView &);
+        UIImageView sbackground; // 背景
+        UIImageView sicon;       // 箭头
+        UILabelExt sLabeldata;   // 标签
+        UILabelExt sLabeltime;   // 标签
+        UIImageView slogo;       // 图标
+        TraingRecordItem sItemInfo = {0, nullptr, nullptr, nullptr};
+    };
+
+}
+#endif
\ No newline at end of file
diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/traingrecord/include/TraingRecordModel.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/traingrecord/include/TraingRecordModel.h
new file mode 100644 (file)
index 0000000..d43e22f
--- /dev/null
@@ -0,0 +1,62 @@
+/***
+ * @Date: 2024-05-20 19:40:41
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-06-11 09:42:02
+ * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/traingrecord/include/TraingRecordModel.h
+ */
+/***
+ * @Date: 2024-05-20 19:40:41
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-06-07 18:46:11
+ * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/traingrecord/include/TraingRecordModel.h
+ */
+
+#ifndef TraingRecord_MODEL_H
+#define TraingRecord_MODEL_H
+
+#include <cstdint>
+#include <map>
+#include "AppViewIDs.h"
+#include "components/ui_label_ext.h"
+#include "ui_resource_string.h"
+#include "components/ui_label_ext.h"
+#include "ui_resource_string.h"
+#include "UiConfig.h"
+#include "TraingRecordPresenter.h"
+#include "traingrecord/include/TraingRecordAdapter.h"
+
+namespace OHOS
+{
+    class TraingRecordModel
+    {
+    public:
+        static TraingRecordModel &GetInstance(void);
+        void InitTraingRecordListItem();
+        const TraingRecordItem *GetTraingRecordlistItems() const;
+        uint8_t GetTraingRecordListNum();
+
+        // 设置当前界面
+        void SetPopupView(bool state);
+        // 获取当前界面
+        bool GetPopupView();
+
+        // 设置json状态
+        void SetJsonStatus(bool status);
+        // 获取json状态
+        bool GetJsonStatus();
+
+    private:
+        TraingRecordModel();
+        TraingRecordModel(const TraingRecordModel &);
+        TraingRecordModel &operator=(const TraingRecordModel &);
+        virtual ~TraingRecordModel();
+        static const uint16_t TraingRecordListMaxNum = 10;
+        uint8_t ArrayNum;
+        TraingRecordItem TraingRecords[TraingRecordListMaxNum] = {0, nullptr, nullptr, nullptr};
+        // std::map<int, AppViewId> TraingRecordIdToViewId;
+        bool jsonStatus{false}; // json文件存在标志位
+        bool popupStatus{false};
+    };
+}
+
+#endif
\ No newline at end of file
diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/traingrecord/include/TraingRecordPresenter.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/traingrecord/include/TraingRecordPresenter.h
new file mode 100644 (file)
index 0000000..f084c08
--- /dev/null
@@ -0,0 +1,40 @@
+
+#ifndef _TraingRecord_PRESENTER_H
+#define _TraingRecord_PRESENTER_H
+
+#include "Presenter.h"
+#include "TraingRecordView.h"
+
+namespace OHOS
+{
+    class TraingRecordView;
+    class TraingRecordModel;
+
+    class TraingRecordPresenter : public Presenter<TraingRecordView>,
+                                  public UIView::OnClickListener,
+                                  public UIView::OnDragListener,
+                                  public RootView::OnKeyActListener
+    {
+    public:
+        TraingRecordPresenter();
+        virtual ~TraingRecordPresenter();
+
+        void OnStart() override;
+        void OnPause() override;
+        void OnResume() override;
+        void OnStop() override;
+        static TraingRecordPresenter *GetInstance();
+        void NavigateBack();
+
+    private:
+        // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承;
+        bool OnClick(UIView &view, const ClickEvent &event) override;
+        bool OnDrag(UIView &view, const DragEvent &event) override;
+        bool OnDragEnd(UIView &view, const DragEvent &event) override;
+        bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件
+
+        TraingRecordModel *p_TraingRecordModel{nullptr};
+    };
+} // namespace OHOS
+
+#endif // SLEEPDETAIL_PRESENTER_H
\ No newline at end of file
diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/traingrecord/include/TraingRecordView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/traingrecord/include/TraingRecordView.h
new file mode 100644 (file)
index 0000000..b9620f2
--- /dev/null
@@ -0,0 +1,91 @@
+/*** 
+ * @Date: 2024-05-20 19:40:41
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-07-27 17:47:13
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/traingrecord/include/TraingRecordView.h
+ */
+/***
+ * @Date: 2024-05-20 19:40:41
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-06-11 09:40:10
+ * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/traingrecord/include/TraingRecordView.h
+ */
+#ifndef _TraingRecord_VIEW_H
+#define _TraingRecord_VIEW_H
+
+
+#include "View.h"
+#include <ui_scroll_view.h>
+#include "components/ui_view_group.h"
+#include "components/ui_label.h"
+#include "components/ui_label_ext.h"
+#include "components/ui_image_view.h"
+#include "components/ui_button.h"
+#include "components/ui_image_animator.h"
+#include "components/ui_label_button_ext.h"
+#include "components/ui_chart.h"
+#include "components/ui_list.h"
+#include "components/icon_adapter.h"
+#include "wearable_log.h"
+#include "ohos_types.h"
+#include "components/ui_card_page.h"
+
+#include "traing/include/TraingModel.h"
+#include "uicomponents/UIComponents.h"
+#include "traing/Training_UiConfig.h"
+#include "TraingRecordPresenter.h"
+
+#include "traingrecord/include/TraingRecordItemView.h"
+namespace OHOS
+{
+#define BUTTONGO "button_go"
+
+    enum class PopupRecord
+    {
+        LackPopup,
+        RecordPopup
+    };
+
+    class TraingRecordPresenter;
+    class TraingRecordView : public View<TraingRecordPresenter>, public ListScrollListener
+    {
+    public:
+        TraingRecordView();
+        virtual ~TraingRecordView();
+        static TraingRecordView *GetInstance(void);
+
+        void OnStart() override;
+      
+        void InitView();
+        void DeInit();
+        void PreLoad(void);
+
+        void ShowLackView();
+        void ShowRecordView();
+        void SetPopupViewStatus(PopupRecord view, bool status);
+        int GetPopupRecordView();
+        void AddToTraingRecordList(const TraingRecordItem &item);
+
+    private:
+        UIView::OnDragListener *draglistener{nullptr};
+        TraingRecordView(TraingRecordView &&) = delete;
+        TraingRecordView &operator=(TraingRecordView &&) = delete;
+        UIScrollView *scrollview = nullptr;
+
+        /*无训练记录界面*/
+        UIScrollView *lackView{nullptr};
+        UILabelExt *labeltitle_ = nullptr;
+        UILabelExt *labelrecord_ = nullptr;
+        UILabelButtonExt *buttongo = nullptr;
+        UIImageView *imagerecord = nullptr;
+
+        /*训练列表界面*/
+        UIScrollView *recordView{nullptr};
+        UILabelExt *labelercord_ = nullptr;
+        TraingRecordAdapter *p_TraingRecordAdapter{nullptr};
+        UIList *TraingRecordList = nullptr;
+
+        bool viewiInitStatus{false};
+    };
+} // namespace OHOS
+#endif // TraingRecord_PRESENTER_H
diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/traingrecord/src/TraingRecordAdapter.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/traingrecord/src/TraingRecordAdapter.cpp
new file mode 100644 (file)
index 0000000..77ef5db
--- /dev/null
@@ -0,0 +1,100 @@
+/***
+ * @Author: Caisking 3449750381@qq.com
+ * @Date: 2024-03-27 11:12:53
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-03-27 15:27:45
+ * @FilePath: /sdk/application/wearable/fd230app/nativeui/traing/training_list_Record/src/TraingRecordAdapter.cpp
+ * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
+ */
+#include "traingrecord/include/TraingRecordAdapter.h"
+#include "traingrecord/include/TraingRecordModel.h"
+#include "traingrecord/include/TraingRecordItemView.h"
+
+#include "wearable_log.h"
+
+namespace OHOS
+{
+    TraingRecordAdapter::TraingRecordAdapter() {}
+
+    TraingRecordAdapter::~TraingRecordAdapter()
+    {
+        listData.clear();
+        if(itemClickListener)
+        {
+            delete itemClickListener;
+            itemClickListener = nullptr;
+        }
+    }
+
+    uint16_t TraingRecordAdapter::GetCount(void)
+    {
+        return listData.size();
+    }
+
+    void TraingRecordAdapter::SetData(std::list<TraingRecordItem> &data)
+    {
+        if (!listData.empty())
+        {
+            listData.clear();
+        }
+        std::list<TraingRecordItem>::iterator it;
+        for (it = data.begin(); it != data.end(); it++)
+        {
+            listData.push_back(*it);
+        }
+    }
+
+    /// @brief 为列表的每一项创建一个视图
+    /// @param inView 一个指向已存在的视图对象的指
+    /// @param index 要创建的视图在列表中的索引l。
+    /// @return 返回该视图对象
+    UIView *TraingRecordAdapter::GetView(UIView *inView, int16_t index)
+    {
+
+        // 1.先检查列表数据是否为空,若为空则返回空指针
+        if (listData.empty())
+        {
+            return nullptr;
+        }
+        // 2.接着检查索引是否小于0,若小于0则返回空指针
+        if (index < 0)
+        {
+            return nullptr;
+        }
+        // 3.检查是否超出列表数据大小,若超出则返回空指针
+        size_t uindex = index;
+        if (uindex >= listData.size())
+        {
+            return nullptr;
+        }
+        // 4.通过迭代器访问列表中指定索引位置的元素,将其赋值给itemData变量
+        std::list<TraingRecordItem>::iterator it = listData.begin();
+        for (int i = 0; i < index; i++)
+        {
+            it++;
+        }
+        TraingRecordItem itemData = *it;
+        TraingRecordItemView *item = nullptr;
+        /*
+            5.根据传入的inView参数是否已经存在一个视图对象,
+            若为空则创建一个新的MessageItemView对象,
+           否则将inView转换成MessageItemView类型的指针
+        */
+        if (inView == nullptr)
+        {
+            item = new TraingRecordItemView();
+        }
+        else
+        {
+            item = static_cast<TraingRecordItemView *>(inView);
+        }
+        item->SetItemInfo(itemData);
+        item->SetOnClickListener(itemClickListener);
+        return item;
+    }
+
+    void TraingRecordAdapter::AddItem(const TraingRecordItem &item)
+    {
+        listData.push_back(item);
+    }
+} // namespace OHOS
diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/traingrecord/src/TraingRecordItemView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/traingrecord/src/TraingRecordItemView.cpp
new file mode 100644 (file)
index 0000000..4f2fb3b
--- /dev/null
@@ -0,0 +1,93 @@
+/***
+ * @Author: Caisking 3449750381@qq.com
+ * @Date: 2024-03-27 11:13:16
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-03-29 11:47:02
+ * @FilePath: /sdk/application/wearable/fd230app/nativeui/traing/training_list_Record/src/TraingRecordItemView.cpp
+ * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
+ */
+
+#include "traingrecord/include/TraingRecordItemView.h"
+#include "traing/include/TraingModel.h"
+#include "uicomponents/UIComponents.h"
+#include "traing/Training_UiConfig.h"
+#include "components/ui_label_ext.h"
+#include "ui_resource_string.h"
+#include "UiConfig.h"
+namespace OHOS
+{
+
+    TraingRecordItemView::TraingRecordItemView()
+    {
+        SetPosition(0, 0, 380, 120); // 每一个itemview宽高要配置好,因为加到list都是以这个视图为基准
+        SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
+        SetStyle(STYLE_BACKGROUND_OPA, 255);
+        SetTouchable(true);
+        SetUpChild();
+        
+        Add(&sbackground);
+        Add(&sicon);
+        Add(&sLabeldata);
+        Add(&sLabeltime);
+        Add(&slogo);
+    }
+
+    TraingRecordItemView::~TraingRecordItemView()
+    {
+        Remove(&sbackground);
+        Remove(&sLabeldata);
+        Remove(&sLabeltime);
+        Remove(&slogo);
+        Remove(&sicon);
+    }
+
+    TraingRecordItemView &TraingRecordItemView::GetInstance()
+    {
+        static TraingRecordItemView instance;
+        return instance;
+    }
+
+    /// @brief 设置item的信息
+    /// @param itemInfo
+    void TraingRecordItemView::SetItemInfo(const TraingRecordItem itemInfo)
+    {
+        sItemInfo = itemInfo;
+        //printf("iamge--%s data--%s time--%s\r\n", (itemInfo.image).c_str(), (itemInfo.data).c_str(), (itemInfo.time).c_str());
+        sLabeldata.SetText((itemInfo.data).c_str());
+        sLabeltime.SetText((itemInfo.time).c_str());
+        slogo.SetSrc((itemInfo.image).c_str());
+    }
+
+    /// @brief 设置每一个itemview上的组件
+    void TraingRecordItemView::SetUpChild()
+    {
+        sbackground.SetSrc(PNG_SETTING_BACKGROUND_IMAGE);
+
+        slogo.SetPosition(60, 35);
+        slogo.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE);
+
+        sicon.SetPosition(330, 40);
+        sicon.SetSrc(ICON_IMAGE);
+        sicon.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE);
+
+        sLabeldata.SetPosition(50, 5, 300, 80);
+        sLabeldata.SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS);
+        sLabeldata.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+        sLabeldata.SetRollSpeed(0);
+        sLabeldata.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 28);
+
+        sLabeltime.SetPosition(52, 40, 300, 80);
+        sLabeltime.SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS);
+        sLabeltime.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+        sLabeltime.SetRollSpeed(0);
+        sLabeltime.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 23);
+        sLabeltime.SetTextColor(Color::Gray()); // 设置文本颜色
+    }
+
+    /// @brief 获取list的中每个组件的在list的下标
+    /// @return 返回下标
+    int TraingRecordItemView::GetTraingRecordIndex()
+    {
+        return sItemInfo.index;
+    }
+}
\ No newline at end of file
diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/traingrecord/src/TraingRecordModel.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/traingrecord/src/TraingRecordModel.cpp
new file mode 100644 (file)
index 0000000..cb7f785
--- /dev/null
@@ -0,0 +1,105 @@
+/***
+ * @Date: 2024-05-20 19:40:41
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-07-16 18:05:51
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/traingrecord/src/TraingRecordModel.cpp
+ */
+/***
+ * @Date: 2024-05-20 19:40:41
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-06-11 09:41:20
+ * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/traingrecord/src/TraingRecordModel.cpp
+ */
+/***
+ * @Date: 2024-05-20 19:40:41
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-06-07 17:41:18
+ * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/traingrecord/src/TraingRecordModel.cpp
+ */
+
+#include "traingrecord/include/TraingRecordModel.h"
+#include "traing/Training_UiConfig.h"
+#include "common/image_cache_manager.h"
+#include "components/ui_label_ext.h"
+#include "ui_resource_string.h"
+#include "UiConfig.h"
+#include "ui_resource_image.h"
+#include "AppViewIDs.h"
+#include "components/ui_label_ext.h"
+#include "ui_resource_string.h"
+#include "traing/include/TraingModel.h"
+#include <vector>
+
+namespace OHOS
+{
+
+    TraingRecordModel::TraingRecordModel()
+    {
+        jsonStatus = TraingModel::GetInstance()->CheckDataJson();
+    }
+
+    TraingRecordModel::~TraingRecordModel() {}
+
+    TraingRecordModel &TraingRecordModel::GetInstance()
+    {
+        static TraingRecordModel instance;
+        return instance;
+    }
+
+    // 获取状态
+    bool TraingRecordModel::GetJsonStatus()
+    {
+        return jsonStatus;
+    }
+    // 设置状态
+    void TraingRecordModel::SetJsonStatus(bool status)
+    {
+        jsonStatus = status;
+    }
+
+    void TraingRecordModel::InitTraingRecordListItem()
+    {
+        // 1.读取json数据
+        std::vector<SportData> sportDataVector;
+        if (!TraingModel::GetInstance()->LoadDataFormJson(sportDataVector))
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadDataFormJson failed");
+            return;
+        }
+        if (!sportDataVector.empty())
+        {
+            ArrayNum = sportDataVector.size();
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "the ArrayNum is %d", ArrayNum);
+            for (int i = ArrayNum - 1, count = 0; i >= 0 && count < TraingRecordListMaxNum; i--, count++)
+            {
+                SportData sportData = sportDataVector[i];
+                // 获取训练类图标
+                std::string imageicon = TraingModel::GetInstance()->GetSportIcon(sportData.sportType,sportData.sportId,1);
+                // 获取日期
+                // 获取时间
+                std::string Time = sportData.start_time + std::string("-") + sportData.end_time;
+                TraingRecords[count] = {count, imageicon.c_str(), sportData.start_date, Time};
+            }
+        }
+    }
+
+    const TraingRecordItem *TraingRecordModel::GetTraingRecordlistItems() const
+    {
+        return TraingRecords;
+    }
+    uint8_t TraingRecordModel::GetTraingRecordListNum()
+    {
+        return ArrayNum;
+    }
+
+    // 设置当前界面
+    void TraingRecordModel::SetPopupView(bool state)
+    {
+        popupStatus = state;
+    }
+    // 获取当前界面 0:没有训练记录 | 1:有训练记录
+    bool TraingRecordModel::GetPopupView()
+    {
+        return popupStatus;
+    }
+}
\ No newline at end of file
diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/traingrecord/src/TraingRecordPresenter.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/traingrecord/src/TraingRecordPresenter.cpp
new file mode 100644 (file)
index 0000000..80c6091
--- /dev/null
@@ -0,0 +1,174 @@
+/***
+ * @Date: 2024-05-20 19:40:41
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-06-08 10:11:18
+ * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/traingrecord/src/TraingRecordPresenter.cpp
+ */
+#include "AppViewIDs.h"
+#include "components/ui_label_ext.h"
+#include "ui_resource_string.h"
+#include "NativeAbility.h"
+
+#include <iostream>
+#include <chrono>
+#include <thread>
+#include "traingrecord/include/TraingRecordPresenter.h"
+#include "traingrecord/include/TraingRecordModel.h"
+#include "traing/include/TraingEnddataView.h"
+#include "traing/include/TraingModel.h"
+
+#include "KeyInputListener.h"
+#include "custom_utils.h"
+#include "common/key_code.h"
+// #include "TraingRecordView.h"
+#include "gfx_utils/mem_check.h"
+
+#include "NativeRegisterManager.h"
+#include "uicomponents/UIComponents.h"
+namespace OHOS
+{
+    REGIST_MENU_PRO(VIEW_TRAINING_RECORD, TraingRecordView, TraingRecordPresenter,
+        PNG_APPLIST_TRAINING_RECORD_IMAGE_BIG, PNG_APPLIST_TRAINING_RECORD_IMAGE_BIG, PNG_APPLIST_TRAINING_RECORD_IMAGE, "训练记录", STR_TRAINING_RECORD);
+
+
+    // 当前Presenter属性实例化的内存指针
+    static TraingRecordPresenter *g_pTraingRecordPresenter = nullptr;
+
+    TraingRecordPresenter::TraingRecordPresenter()
+    {
+        p_TraingRecordModel = &TraingRecordModel::GetInstance();
+        g_pTraingRecordPresenter = this;
+#ifdef MEM_CHECK
+        MemCheck::GetInstance()->EnableLeakCheck(true);
+#endif
+    }
+
+    TraingRecordPresenter::~TraingRecordPresenter()
+    {
+        g_pTraingRecordPresenter = nullptr;
+        p_TraingRecordModel = nullptr;
+#ifdef MEM_CHECK
+        MemCheck::GetInstance()->EnableLeakCheck(false);
+#endif
+    }
+
+    TraingRecordPresenter *TraingRecordPresenter::GetInstance()
+    {
+        return g_pTraingRecordPresenter;
+    }
+
+    void TraingRecordPresenter::OnStart()
+    {
+        p_TraingRecordModel->InitTraingRecordListItem();
+        Presenter<TraingRecordView>::OnStart();
+    }
+
+    void TraingRecordPresenter::OnPause(void)
+    {
+        Presenter<TraingRecordView>::OnPause();
+    }
+
+    void TraingRecordPresenter::OnResume(void)
+    {
+        if (view_ == nullptr)
+        {
+            return;
+        }
+        if (p_TraingRecordModel->GetJsonStatus())
+        {
+            const TraingRecordItem *itemInfo = p_TraingRecordModel->GetTraingRecordlistItems();
+            for (int i = 0; i < p_TraingRecordModel->GetTraingRecordListNum(); i++)
+            {
+                view_->AddToTraingRecordList(itemInfo[i]);
+            }
+        }
+        Presenter<TraingRecordView>::OnResume();
+    }
+
+    void TraingRecordPresenter::OnStop(void)
+    {
+        Presenter<TraingRecordView>::OnStop();
+    }
+    void TraingRecordPresenter::NavigateBack()
+    {
+        uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId();
+        // 根据前一界面切换 {训练结束失败}
+        if (preSlice == VIEW_TRAININGCRAD)
+        {
+            if (TraingModel::GetInstance()->GetEntryType() == APPLIST_ENTER)
+                NativeAbility::GetInstance().ChangeSlice(VIEW_TRAINING, TransitionType::TRANSITION_BACK_TO_HEXAGONS);
+            else
+            {
+                NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN, TransitionType::TRANSITION_BACK_TO_HEXAGONS);
+                NativeAbility::GetInstance().ClearSliceIdStack(); // 清空所有SLiceId栈元素
+            }
+        }
+        else
+        {
+            NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS);
+        }
+    }
+    bool TraingRecordPresenter::OnDrag(UIView &view, const DragEvent &event)
+    {
+        return true;
+    }
+    bool TraingRecordPresenter::OnDragEnd(UIView &view, const DragEvent &event)
+    {
+        if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT)
+        {
+            NavigateBack();
+        }
+        return true;
+    }
+
+    bool TraingRecordPresenter::OnClick(UIView &view, const ClickEvent &event)
+    {
+        // 返回按键
+        std::string viewId = view.GetViewId();
+        if (TraingRecordModel::GetInstance().GetPopupView() == false)
+        {
+            if (viewId == BUTTONGO)
+            {
+                NativeAbility::GetInstance().EnterSlice(VIEW_TRAININGMORE);
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "go to training");
+                return true;
+            }
+        }
+        else
+        {
+            TraingRecordItemView *p_TraingRecordItemView = static_cast<TraingRecordItemView *>(&view);
+            int index = p_TraingRecordItemView->GetTraingRecordIndex();
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "the index is %d", index);
+            // 读取json数据
+            std::vector<SportData> sportDataVector;
+            if (!TraingModel::GetInstance()->LoadDataFormJson(sportDataVector))
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadDataFormJson failed");
+                return false;
+            }
+            if (!sportDataVector.empty())
+            {
+                // 选择点击按键的历史数据
+                int arraynum = sportDataVector.size() - 1;
+                SportData sportData = sportDataVector[arraynum - index]; // 显示是倒序 id同理
+                NativeAbility::GetInstance().EnterSlice(VIEW_TRAININGENDDATA);
+                TraingModel::GetInstance()->SetSportdata(&sportData);
+                return true;
+            }
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "the sportDataVector is error");
+        }
+        return false;
+    }
+    // 增加按键事件
+    bool TraingRecordPresenter::OnKeyAct(UIView &view, const KeyEvent &event)
+    {
+        unsigned short keyID = event.GetKeyId();
+        unsigned short keyState = event.GetState();
+        // 如果是power键,且是亮屏状态,按键释放就返回上一级
+        if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0)
+        {
+            NavigateBack();
+        }
+        return true;
+    }
+}
diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/traingrecord/src/TraingRecordView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/traingrecord/src/TraingRecordView.cpp
new file mode 100644 (file)
index 0000000..b810c02
--- /dev/null
@@ -0,0 +1,288 @@
+
+#include "traingrecord/include/TraingRecordView.h"
+#include "traingrecord/include/TraingRecordAdapter.h"
+#include "traingrecord/include/TraingRecordModel.h"
+
+#include "UiConfig.h"
+#include "common/image_cache_manager.h"
+#include "components/ui_button.h"
+#include "ui_resource_image.h"
+#include "uicomponents/UIComponents.h"
+#include <ui_scroll_view.h>
+namespace OHOS {
+static const uint32_t BACK_GROUND_COLOR = 0xfff6f6f6;
+static TraingRecordView *g_pTraingRecordView{nullptr};
+static constexpr uint8_t NUM_2 = 2;
+// static TraingMOREView *g_pTraingMOREView{nullptr};
+static constexpr int16_t MORE_LIST_POSITION_X = 43;
+static constexpr int16_t MORE_LIST_POSITION_Y = 120;
+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;
+
+TraingRecordView::TraingRecordView() { g_pTraingRecordView = this; }
+
+TraingRecordView::~TraingRecordView() {
+  DeInit();
+  //   lackView->RemoveAll();
+  //   recordView->RemoveAll();
+
+  //   UIViewGroup *tmpGroup = dynamic_cast<UIViewGroup *>(scrollview);
+  //   UIViewGroup::RemoveAndDeleteAllRecursively(tmpGroup);
+
+  g_pTraingRecordView = nullptr;
+}
+
+TraingRecordView *TraingRecordView::GetInstance() {
+  return g_pTraingRecordView;
+}
+
+/* InitView:初始化界面*/
+void TraingRecordView ::InitView() {
+  if (scrollview == nullptr) {
+    scrollview = new UIScrollView();
+    scrollview->SetPosition(0, 0, 466, 466);
+    scrollview->SetStyle(STYLE_BACKGROUND_OPA, 0);
+  }
+  // 展示界面
+  if (TraingRecordModel::GetInstance().GetJsonStatus()) {
+    // printf("存在训练数据!\r\n");
+    SetPopupViewStatus(PopupRecord::RecordPopup, true);
+  } else {
+    // printf("不存在训练数据!\r\n");
+    SetPopupViewStatus(PopupRecord::LackPopup, true);
+  }
+}
+
+/* DeInit:删除组件 */
+void TraingRecordView::DeInit() {
+  if (scrollview != nullptr) {
+    scrollview->RemoveAll();
+   
+  if (scrollview) {
+    scrollview->RemoveAll();
+  }
+  if (lackView) {
+    lackView->RemoveAll();
+  }
+
+  if (recordView) {
+    recordView->RemoveAll();
+  }
+
+  if (labeltitle_) {
+    delete labeltitle_;
+    labeltitle_ = nullptr;
+  }
+
+  if (labelrecord_) {
+    delete labelrecord_;
+    labelrecord_ = nullptr;
+  }
+
+  if (buttongo) {
+    delete buttongo;
+    buttongo = nullptr;
+  }
+
+  if (imagerecord) {
+    delete imagerecord;
+    imagerecord = nullptr;
+  }
+
+  if (lackView) {
+    delete lackView;
+    lackView = nullptr;
+  }
+
+  if (TraingRecordList) {
+    delete TraingRecordList;
+    TraingRecordList = nullptr;
+  }
+
+  if (p_TraingRecordAdapter) {
+    delete p_TraingRecordAdapter;
+    p_TraingRecordAdapter = nullptr;
+  }
+
+  if (labelercord_) {
+    delete labelercord_;
+    labelercord_ = nullptr;
+  }
+
+  if (recordView) {
+    delete recordView;
+    recordView = nullptr;
+  }
+
+  delete scrollview;
+  scrollview = nullptr;
+}
+}
+void TraingRecordView::PreLoad(void) {
+  if (!viewiInitStatus) {
+    InitView();
+    viewiInitStatus = true;
+  }
+}
+/*显示无记录界面*/
+void TraingRecordView::ShowLackView() {
+  WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ShowLackView start");
+  if (lackView == nullptr) {
+    lackView = new UIScrollView();
+    if (lackView == nullptr) {
+      return;
+    }
+    lackView->SetPosition(0, 0);
+    lackView->Resize(VERTICAL_RESOLUTION, HORIZONTAL_RESOLUTION);
+    lackView->SetScrollBlankSize(20);
+    lackView->SetReboundSize(50);
+    lackView->SetDirection(1);
+  }
+
+  /*初始化label*/
+  InitLabelExt(labeltitle_, 83, 50, 300, 35, "labletitle", STR_TRAINING_RECORD,
+               DEFAULT_VECTOR_FONT_FILENAME, 30);
+  InitLabelExt(labelrecord_, 53, 260, 360, 40, "labelrecord", STR_TRAINGNO,
+               DEFAULT_VECTOR_FONT_FILENAME, 30);
+  /*初始化image*/
+  InitImageView(imagerecord, 174, 120, 118, 120, "image", RECOED_IMAGE);
+  /*初始化按键*/
+  InitButtonExt(buttongo, 93, 330, 280, 90, BUTTONGO, STR_TRAINGGO, 30);
+  buttongo->SetStyle(STYLE_BACKGROUND_COLOR, 0xff4fc34c); // 设置按键颜色
+  buttongo->SetOnClickListener(static_cast<UIView::OnClickListener *>(
+      TraingRecordPresenter::GetInstance()));
+
+  lackView->Add(labeltitle_);
+  lackView->Add(labelrecord_);
+  lackView->Add(imagerecord);
+  lackView->Add(buttongo);
+
+  // RootView::GetInstance()->lackView
+  scrollview->Add(lackView);
+  // printf("lackView Add\r\n");
+
+  lackView->SetDraggable(true);
+  lackView->SetTouchable(true);
+
+  UIView::OnDragListener *draglistener = static_cast<UIView::OnDragListener *>(
+      TraingRecordPresenter::GetInstance());
+  if (draglistener == nullptr) {
+    return;
+  }
+  lackView->SetOnDragListener(draglistener);
+  lackView->SetVisible(false); // 界面隐藏
+  WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ShowLackView end");
+}
+/*记录列表界面*/
+void TraingRecordView::ShowRecordView() {
+  WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ShowRecordView start");
+  if (recordView == nullptr) {
+    recordView = new UIScrollView();
+    if (recordView == nullptr) {
+      return;
+    }
+    recordView->SetPosition(0, 0);
+    recordView->Resize(466, 466);
+    recordView->SetScrollBlankSize(50);
+    recordView->SetDirection(1);
+  }
+
+  /*初始化label*/
+  InitLabelExt(labelercord_, 83, 50, 300, 35, "labletitle", STR_TRAINING_RECORD,
+               DEFAULT_VECTOR_FONT_FILENAME, 30);
+  recordView->Add(labelercord_);
+
+  // UIList 的适配器
+  if(p_TraingRecordAdapter == nullptr)
+  {
+    p_TraingRecordAdapter = new TraingRecordAdapter();
+  }
+  p_TraingRecordAdapter->SetItemClickListener(presenter_);
+  if (TraingRecordList == nullptr) {
+    TraingRecordList = new UIList();
+  }
+  TraingRecordList->SetPosition(MORE_LIST_POSITION_X, MORE_LIST_POSITION_Y, 466,
+                                466);
+  TraingRecordList->SetScrollStateListener(this);
+  TraingRecordList->SetThrowDrag(true);
+  TraingRecordList->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT);
+  // 设置手指抬起屏幕后的最大滚动距离
+  TraingRecordList->SetMaxScrollDistance(1000);
+  // 设置手指抬起屏幕后的补偿距离
+  TraingRecordList->SetSwipeACCLevel(200);
+  // 设置拖动加速
+  TraingRecordList->SetDragACCLevel(5);
+  TraingRecordList->SetYScrollBarVisible(true);
+  recordView->SetVisible(false); // 隐藏界面
+  TraingRecordList->SetOnClickListener(static_cast<UIView::OnClickListener *>(
+      TraingRecordPresenter::GetInstance()));
+
+  UIView::OnDragListener *recorddraglistener =
+      static_cast<UIView::OnDragListener *>(
+          TraingRecordPresenter::GetInstance());
+  if (recorddraglistener == nullptr) {
+    return;
+  }
+  recordView->SetOnDragListener(recorddraglistener);
+  WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ShowRecordView end");
+}
+/*控制显示界面*/
+void TraingRecordView::SetPopupViewStatus(PopupRecord view, bool status) {
+  WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SetPopupViewStatus %d", view);
+
+  if (view == PopupRecord::LackPopup) {
+    TraingRecordModel::GetInstance().SetPopupView(
+        false);                    // 设置状态为无训练记录
+    lackView->SetVisible(true);    // 隐藏界面
+    recordView->SetVisible(false); // 隐藏界面
+  } else if (view == PopupRecord::RecordPopup) {
+    TraingRecordModel::GetInstance().SetPopupView(true); // 设置状态为有训练记录
+    lackView->SetVisible(false);                         // 隐藏界面
+    recordView->SetVisible(true);                        // 隐藏界面
+  }
+}
+// 获取目前的view
+void TraingRecordView::OnStart() {
+  View<TraingRecordPresenter>::OnStart();
+
+  scrollview = new UIScrollView();
+  if (scrollview == nullptr) {
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "scrollview new fail");
+    return;
+  }
+  scrollview->SetPosition(0, 0, Screen::GetInstance().GetWidth(),
+                          Screen::GetInstance().GetHeight());
+
+  scrollview->SetOnDragListener(presenter_);
+  scrollview->SetTouchable(true);
+  scrollview->SetDraggable(true);
+  scrollview->SetStyle(STYLE_BACKGROUND_COLOR, BACK_GROUND_COLOR);
+  scrollview->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
+
+  ShowLackView();
+  ShowRecordView();
+  PreLoad();
+
+  AddViewToRootContainer(scrollview);
+
+  // 增加按键监听
+  RootView::OnKeyActListener *keyactListener =
+      (RootView::OnKeyActListener *)OHOS::TraingRecordPresenter::GetInstance();
+  RootView::GetInstance()->SetOnKeyActListener(keyactListener);
+
+  if (TraingRecordModel::GetInstance().GetJsonStatus()) {
+    recordView->Add(TraingRecordList);
+    recordView->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT);
+    scrollview->Add(recordView);
+    // printf("recordView Add\r\n");
+    TraingRecordList->SetAdapter(p_TraingRecordAdapter);
+  }
+}
+void TraingRecordView::AddToTraingRecordList(const TraingRecordItem &item) {
+  p_TraingRecordAdapter->AddItem(item);
+}
+
+} // namespace OHOS