From: Caisking <3449750381@qq.com> Date: Thu, 16 May 2024 16:45:24 +0000 (+0800) Subject: 通过json数据适配训练记录 X-Git-Tag: release_V1.2.70_20241020_135402~1116 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=80d98e95abedcb6c9888b8cef1ef79bc029b4a59;p=mirrors%2FFD230.git 通过json数据适配训练记录 --- diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingModel.h b/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingModel.h index fe8691c3a..ab8a35832 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingModel.h @@ -224,7 +224,8 @@ namespace OHOS /*设置运动类型*/ void SetSportType(Exercisetype type); /*获取运动类型图片*/ - std::string GetSportType(); + std::string GetSportType(Exercisetype sporttype); + std::string GetSportIcon(Exercisetype sporttype); /*设置运动项目*/ void SetSportEvent(UIResourceTextId id); /*获取运动项目*/ @@ -283,6 +284,7 @@ namespace OHOS int CalculateAverageHeartRate(int newHeartRate); /*保存训练记录到json文件*/ + bool CheckDataJson(); bool SaveDataToJson(SportData *data); SportData *LoadDateFeomJson(); diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingEnddataView.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingEnddataView.cpp index 55a0a676b..436a907a3 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingEnddataView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingEnddataView.cpp @@ -80,11 +80,11 @@ namespace OHOS InitLabel(labeltype, 188, 52, 90, 35, "label1", "健身类", DEFAULT_VECTOR_FONT_FILENAME, 30); InitLabel(labelsport, 147, 140, 240, 35, "label6", "健走", DEFAULT_VECTOR_FONT_FILENAME, 30); InitLabel(labelduration, 146, 179, 240, 40, "label7", "13:00:22-15:00:12", DEFAULT_VECTOR_FONT_FILENAME, 28); - InitLabelExt(labelutag, 146, 252, 240, 40, "label8",STR_GOAL_ACCOMPLISHMENT_DEGREE, DEFAULT_VECTOR_FONT_FILENAME, 30); + InitLabelExt(labelutag, 146, 252, 240, 40, "label8", STR_GOAL_ACCOMPLISHMENT_DEGREE, DEFAULT_VECTOR_FONT_FILENAME, 30); InitLabelExt(labelutime, 146, 382, 240, 40, "label9", STR_TRAINING_DURATION, DEFAULT_VECTOR_FONT_FILENAME, 30); InitLabelExt(labelumile, 146, 512, 240, 40, "label10", STR_RANGE_MILE, DEFAULT_VECTOR_FONT_FILENAME, 30); - InitLabelExt(labeluheart, 146, 642, 240, 40, "label11",STR_MEAN_HEART_RATE_MIN, DEFAULT_VECTOR_FONT_FILENAME, 30); - InitLabelExt(labelusteps, 146, 772, 240, 40, "label12",STR_STEP_NUMBER, DEFAULT_VECTOR_FONT_FILENAME, 30); + InitLabelExt(labeluheart, 146, 642, 240, 40, "label11", STR_MEAN_HEART_RATE_MIN, DEFAULT_VECTOR_FONT_FILENAME, 30); + InitLabelExt(labelusteps, 146, 772, 240, 40, "label12", STR_STEP_NUMBER, DEFAULT_VECTOR_FONT_FILENAME, 30); InitLabelExt(labelustrong, 146, 902, 240, 40, "label2", STR_TRAINING_INTENSITY, DEFAULT_VECTOR_FONT_FILENAME, 30); InitLabelExt(labelnote, 80, 1024, 300, 40, "label8", STR_MORE_APP, DEFAULT_VECTOR_FONT_FILENAME, 30); @@ -280,12 +280,11 @@ namespace OHOS SportData *enddata = TraingModel::GetInstance()->GetSportdata(); if (enddata == nullptr) { - return; } // 训练图标Icon - std::string imageStr = TraingModel::GetInstance()->GetSportType(); + std::string imageStr = TraingModel::GetInstance()->GetSportType(enddata->sportType); imageIcon->SetSrc(imageStr.c_str()); // 运动项目 diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp index a57bd359f..93f71dc38 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp @@ -221,10 +221,26 @@ namespace OHOS LIMIT_54_IMAGE, OTHER_54_IMAGE, }; + /*训练记录Icon*/ + std::string sportIcons[8] = { + FITNESS_IMAGE, + DANCE_IMAGE, + REST_IMAGE, + BALL_IMAGE, + SWIMMING_IMAGE, + ICE_IMAGE, + LIMIT_IMAGE, + OTHER_IMAGE, + }; /*获取运动类型图片*/ - std::string TraingModel::GetSportType() + std::string TraingModel::GetSportType(Exercisetype sporttype) + { + return sportImages[static_cast(sporttype)]; + } + /*获取运动类型icon*/ + std::string TraingModel::GetSportIcon(Exercisetype sporttype) { - return sportImages[static_cast(sportType_)]; + return sportIcons[static_cast(sporttype)]; } /*设置运动Id*/ void TraingModel::SetSportEvent(UIResourceTextId id) @@ -1067,6 +1083,34 @@ namespace OHOS #endif /* -------------------------------------------------------------------------- */ + /*检查是否存在数据*/ + bool TraingModel::CheckDataJson() + { + // 读取record.json文件 + std::ifstream file(TRAINING_RECORD_FILE); + + // 检查文件是否打开成功 + if (!file.is_open()) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Unable to open file"); + return false; + } + + // 检查文件是否为空 + file.seekg(0, std::ios::end); + if (file.tellg() == 0) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "File is empty"); + file.close(); + return false; + } + + // 关闭文件 + file.close(); + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CheckDataJson is ok"); + return true; + } /* 保存训练数据到 json 文件 */ bool TraingModel::SaveDataToJson(SportData *data) @@ -1142,7 +1186,7 @@ namespace OHOS fclose(fp); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SaveDataToJson is succeed"); + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SaveDataToJson is succeed"); return true; } /* 加载训练数据函数 */ diff --git a/code/sdk/application/wearable/fd230app/nativeui/traingrecord/include/TraingRecordAdapter.h b/code/sdk/application/wearable/fd230app/nativeui/traingrecord/include/TraingRecordAdapter.h index bcff41779..cc17ffb0b 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traingrecord/include/TraingRecordAdapter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/traingrecord/include/TraingRecordAdapter.h @@ -18,9 +18,10 @@ namespace OHOS typedef struct { - AppViewId id; - UIResourceTextId labelid; // 标签 - const char *logo; + int index; //下标 + const char *image; //训练类icon + std::string data; //日期 + std::string time; //时间 } TraingRecordItem; class TraingRecordAdapter : public AbstractAdapter diff --git a/code/sdk/application/wearable/fd230app/nativeui/traingrecord/include/TraingRecordItemView.h b/code/sdk/application/wearable/fd230app/nativeui/traingrecord/include/TraingRecordItemView.h index e69de29bb..6d28a4c83 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traingrecord/include/TraingRecordItemView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/traingrecord/include/TraingRecordItemView.h @@ -0,0 +1,47 @@ +/*** + * @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 "language/font/ui_resource_string.h" +#include "ohos_types.h" + +namespace OHOS +{ + class TraingRecordItemView : public UIViewGroup + { + public: + explicit TraingRecordItemView(); + virtual ~TraingRecordItemView(); + 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/fd230app/nativeui/traingrecord/include/TraingRecordModel.h b/code/sdk/application/wearable/fd230app/nativeui/traingrecord/include/TraingRecordModel.h index e69de29bb..d9268502b 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traingrecord/include/TraingRecordModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/traingrecord/include/TraingRecordModel.h @@ -0,0 +1,40 @@ + +#ifndef TraingRecord_MODEL_H +#define TraingRecord_MODEL_H + +#include +#include +#include "AppViewIDs.h" +#include "components/ui_label_ext.h" +#include "language/font/ui_resource_string.h" +#include "components/ui_label_ext.h" +#include "language/font/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() const; + //设置标志位 + bool GetJsonStatus(); + + private: + TraingRecordModel(); + TraingRecordModel(const TraingRecordModel &); + TraingRecordModel &operator=(const TraingRecordModel &); + virtual ~TraingRecordModel(); + static const uint16_t TraingRecordListMaxNum = 10; + TraingRecordItem TraingRecords[TraingRecordListMaxNum] = {0, nullptr, nullptr, nullptr}; + // std::map TraingRecordIdToViewId; + bool jsonStatus{false}; // json文件存在标志位 + }; +} + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/traingrecord/include/TraingRecordPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/traingrecord/include/TraingRecordPresenter.h index 1c5a0758b..3933d19ac 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traingrecord/include/TraingRecordPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/traingrecord/include/TraingRecordPresenter.h @@ -7,10 +7,11 @@ namespace OHOS { class TraingRecordView; + class TraingRecordModel; class TraingRecordPresenter : public Presenter, - public UIView::OnClickListener, - public UIView::OnDragListener + public UIView::OnClickListener, + public UIView::OnDragListener { public: TraingRecordPresenter(); @@ -26,6 +27,8 @@ namespace OHOS // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; bool OnClick(UIView &view, const ClickEvent &event) override; bool OnDrag(UIView &view, const DragEvent &event) override; + + TraingRecordModel *p_TraingRecordModel{nullptr}; }; } // namespace OHOS diff --git a/code/sdk/application/wearable/fd230app/nativeui/traingrecord/include/TraingRecordView.h b/code/sdk/application/wearable/fd230app/nativeui/traingrecord/include/TraingRecordView.h index 41600ba2d..b5e592df5 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traingrecord/include/TraingRecordView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/traingrecord/include/TraingRecordView.h @@ -22,6 +22,8 @@ #include "uicomponents/UIComponents.h" #include "traing/Training_UiConfig.h" #include "TraingRecordPresenter.h" + +#include "traingrecord/include/TraingRecordItemView.h" namespace OHOS { #define BUTTONGO "button_go" @@ -51,6 +53,7 @@ namespace OHOS void ShowLackView(); void ShowRecordView(); void SetPopupViewStatus(PopupRecord view, bool status); + void AddToTraingRecordList(const TraingRecordItem &item); private: UIView::OnDragListener *draglistener{nullptr}; @@ -67,6 +70,9 @@ namespace OHOS /*训练列表界面*/ UIScrollView *recordView{nullptr}; + UILabelExt *labelercord_ = nullptr; + TraingRecordAdapter *p_TraingRecordAdapter{nullptr}; + UIList *TraingRecordList = nullptr; bool viewiInitStatus{false}; }; diff --git a/code/sdk/application/wearable/fd230app/nativeui/traingrecord/src/TraingRecordAdapter.cpp b/code/sdk/application/wearable/fd230app/nativeui/traingrecord/src/TraingRecordAdapter.cpp index e69de29bb..5bb2f0f57 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traingrecord/src/TraingRecordAdapter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traingrecord/src/TraingRecordAdapter.cpp @@ -0,0 +1,95 @@ +/*** + * @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(); + } + + uint16_t TraingRecordAdapter::GetCount(void) + { + return listData.size(); + } + + void TraingRecordAdapter::SetData(std::list &data) + { + if (!listData.empty()) + { + listData.clear(); + } + std::list::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::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(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/fd230app/nativeui/traingrecord/src/TraingRecordItemView.cpp b/code/sdk/application/wearable/fd230app/nativeui/traingrecord/src/TraingRecordItemView.cpp index e69de29bb..cde58933b 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traingrecord/src/TraingRecordItemView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traingrecord/src/TraingRecordItemView.cpp @@ -0,0 +1,83 @@ +/*** + * @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 "language/font/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); + } + + /// @brief 设置item的信息 + /// @param itemInfo + void TraingRecordItemView::SetItemInfo(const TraingRecordItem itemInfo) + { + sItemInfo = itemInfo; + sLabeldata.SetText((itemInfo.data).c_str()); + sLabeltime.SetText((itemInfo.time).c_str()); + slogo.SetSrc(itemInfo.image); + } + + /// @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, 0, 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, 20); + + sLabeltime.SetPosition(50, 50, 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, 20); + } + + /// @brief 获取list的中每个组件的在list的下标 + /// @return 返回下标 + int TraingRecordItemView::GetTraingRecordIndex() + { + return sItemInfo.index; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/traingrecord/src/TraingRecordModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/traingrecord/src/TraingRecordModel.cpp index e69de29bb..fe082a913 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traingrecord/src/TraingRecordModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traingrecord/src/TraingRecordModel.cpp @@ -0,0 +1,76 @@ +/*** + * @Author: Caisking 3449750381@qq.com + * @Date: 2024-03-26 18:34:15 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-03-26 18:36:25 + * @FilePath: /sdk/application/wearable/fd230app/nativeui/traing/training_list_Record/src/TraingRecordModel.cpp + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + */ + +#include "traingrecord/include/TraingRecordModel.h" +#include "traing/Training_UiConfig.h" +#include "common/image_cache_manager.h" +#include "components/ui_label_ext.h" +#include "language/font/ui_resource_string.h" +#include "UiConfig.h" +#include "ui_resource_image.h" +#include "AppViewIDs.h" +#include "components/ui_label_ext.h" +#include "language/font/ui_resource_string.h" +#include "traing/include/TraingModel.h" + +namespace OHOS +{ + + TraingRecordModel::TraingRecordModel() {} + + TraingRecordModel::~TraingRecordModel() {} + + TraingRecordModel &TraingRecordModel::GetInstance() + { + static TraingRecordModel instance; + return instance; + } + + //设置标志位 + bool TraingRecordModel::GetJsonStatus() + { + jsonStatus = TraingModel::GetInstance()->CheckDataJson(); + return jsonStatus; + } + + void TraingRecordModel::InitTraingRecordListItem() + { + // 1.读取json数据 + SportData *sportDataArray = TraingModel::GetInstance()->LoadDateFeomJson(); + if (sportDataArray != nullptr) + { + int dataCount = 0; + for (int i = 0; i < TraingRecordListMaxNum; i++) // 最多只有10条数据 + { + SportData sportData = sportDataArray[i]; + // 2.获取训练类 + std::string imageicon = TraingModel::GetInstance()->GetSportIcon(sportData.sportType); + // 3.获取日期 + // 4.获取时间 + TraingRecords[i] = {i, imageicon.c_str(), sportData.start_date, sportData.start_time}; +#if 0 + // 使用 printf 输出每条训练记录的信息 [测试] + printf("Training Record %d:\n", i + 1); + printf("Sport Type: %s\n", imageicon.c_str()); + printf("Start Date: %s\n", sportData.start_date.c_str()); + printf("Start Time: %s\n", sportData.start_time.c_str()); +#endif + } + } + } + + const TraingRecordItem *TraingRecordModel::GetTraingRecordlistItems() const + { + return TraingRecords; + } + uint8_t TraingRecordModel::GetTraingRecordListNum() const + { + return TraingRecordListMaxNum; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/traingrecord/src/TraingRecordPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/traingrecord/src/TraingRecordPresenter.cpp index 61de10292..b62523d58 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traingrecord/src/TraingRecordPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traingrecord/src/TraingRecordPresenter.cpp @@ -7,6 +7,7 @@ #include #include #include "traingrecord/include/TraingRecordPresenter.h" +#include "traingrecord/include/TraingRecordModel.h" // #include "TraingRecordView.h" namespace OHOS @@ -16,6 +17,7 @@ namespace OHOS TraingRecordPresenter::TraingRecordPresenter() { + p_TraingRecordModel = &TraingRecordModel::GetInstance(); g_pTraingRecordPresenter = this; } @@ -31,6 +33,7 @@ namespace OHOS void TraingRecordPresenter::OnStart() { + p_TraingRecordModel->InitTraingRecordListItem(); Presenter::OnStart(); } @@ -41,6 +44,18 @@ namespace OHOS 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::OnResume(); } diff --git a/code/sdk/application/wearable/fd230app/nativeui/traingrecord/src/TraingRecordView.cpp b/code/sdk/application/wearable/fd230app/nativeui/traingrecord/src/TraingRecordView.cpp index e9150c16a..bfa38000f 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traingrecord/src/TraingRecordView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traingrecord/src/TraingRecordView.cpp @@ -1,5 +1,7 @@ #include "traingrecord/include/TraingRecordView.h" +#include "traingrecord/include/TraingRecordAdapter.h" +#include "traingrecord/include/TraingRecordModel.h" #include "common/image_cache_manager.h" #include "UiConfig.h" @@ -10,8 +12,15 @@ 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() { @@ -38,8 +47,17 @@ namespace OHOS container_->SetPosition(0, 0, 466, 466); container_->SetStyle(STYLE_BACKGROUND_OPA, 0); } - // 展示无记录界面。后续需要加入函数判断 - SetPopupViewStatus(PopupRecord::LackPopup, true); + // 展示界面 + if (TraingRecordModel::GetInstance().GetJsonStatus()) + { + printf("存在训练数据!\r\n"); + SetPopupViewStatus(PopupRecord::RecordPopup, true); + } + else + { + printf("不存在训练数据!\r\n"); + SetPopupViewStatus(PopupRecord::LackPopup, true); + } } /* DeInit:删除组件 */ @@ -70,13 +88,25 @@ namespace OHOS delete imagerecord; imagerecord = nullptr; } - if (lackView != nullptr) { lackView->RemoveAll(); delete lackView; lackView = nullptr; } + + if (TraingRecordList != nullptr) + { + recordView->Remove(TraingRecordList); + delete TraingRecordList; + TraingRecordList = nullptr; + } + if (labelercord_ != nullptr) + { + recordView->Remove(labelercord_); + delete labelercord_; + labelercord_ = nullptr; + } if (recordView != nullptr) { recordView->RemoveAll(); @@ -145,7 +175,54 @@ namespace OHOS /*记录列表界面*/ void TraingRecordView::ShowRecordView() { - + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ShowRecordView start"); + recordView = new UIScrollView(); + if (recordView == nullptr) + { + return; + } + recordView->SetPosition(0, 0); + recordView->Resize(VERTICAL_RESOLUTION, HORIZONTAL_RESOLUTION); + recordView->SetScrollBlankSize(20); + recordView->SetReboundSize(50); + recordView->SetDirection(1); + + /*初始化label*/ + InitLabelExt(labelercord_, 83, 50, 300, 35, "labletitle", STR_TRAINING_RECORD, DEFAULT_VECTOR_FONT_FILENAME, 30); + recordView->Add(labelercord_); + + // UIList 的适配器 + p_TraingRecordAdapter = new TraingRecordAdapter(); + p_TraingRecordAdapter->SetItemClickListener(presenter_); + if (TraingRecordList == nullptr) + { + TraingRecordList = new UIList(); + } + TraingRecordList->SetPosition(More_LIST_POSITION_X, More_LIST_POSITION_Y); + TraingRecordList->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + TraingRecordList->SetScrollBlankSize(More_SCROLLBLANKSIZE); + TraingRecordList->SetReboundSize(50); + TraingRecordList->SetSelectPosition(HORIZONTAL_RESOLUTION / SNUM_2); // middle position + TraingRecordList->SetDraggable(true); + TraingRecordList->SetThrowDrag(true); + TraingRecordList->EnableAutoAlign(true); + TraingRecordList->SetElastic(true); // 设置回弹效果 + TraingRecordList->SetMaxScrollDistance(MAX_SCR_DIS); + + recordView->SetYScrollBarVisible(true); // 设置滑动滚动条 + + // 增加表冠控制 + TraingRecordList->SetRotateFactor(2); + TraingRecordList->RequestFocus(); + + UIView::OnDragListener *recorddraglistener = static_cast(TraingRecordPresenter::GetInstance()); + if (recorddraglistener == nullptr) + { + return; + } + recordView->SetOnDragListener(recorddraglistener); + recordView->SetVisible(false); //隐藏界面 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ShowRecordView end"); } /*控制显示界面*/ void TraingRecordView::SetPopupViewStatus(PopupRecord view, bool status) @@ -197,14 +274,24 @@ namespace OHOS container_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); ShowLackView(); + ShowRecordView(); PreLoad(); RootView::GetInstance()->Add(container_); } - + void TraingRecordView::AddToTraingRecordList(const TraingRecordItem &item) + { + p_TraingRecordAdapter->AddItem(item); + } void TraingRecordView::OnSetUpView() { - View::OnSetUpView(); + if (TraingRecordModel::GetInstance().GetJsonStatus()) + { + recordView->Add(TraingRecordList); + recordView->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + RootView::GetInstance()->Add(recordView); + TraingRecordList->SetAdapter(p_TraingRecordAdapter); + } Draw(); } @@ -219,6 +306,8 @@ namespace OHOS { View::OnStop(); RootView::GetInstance()->RemoveAll(); + if (TraingRecordModel::GetInstance().GetJsonStatus()) + RootView::GetInstance()->ClearFocus(); return; } }