mcu_hi3321_watch/tjd/ui/app/main/TjdUiAppMainPageFavorite.h
2025-05-26 20:15:20 +08:00

468 lines
13 KiB
C++

#ifndef TJD_UI_MAIN_FAVORITE_PAGE_H
#define TJD_UI_MAIN_FAVORITE_PAGE_H
#include "LyricParser.h"
#include "TjdUiAppPlayerModel.h"
#include "View.h"
#include "animator/animator_manager.h"
#include "components/abstract_adapter.h"
#include "components/root_view.h"
#include "components/tjd_ui_radio_button.h"
#include "components/tjd_ui_transform_list_group.h"
#include "components/ui_card_page.h"
#include "components/ui_image_animator.h"
#include "components/ui_label_ext.h"
#include "components/ui_scroll_view.h"
#include "components/ui_slider.h"
#include "components/ui_view_group.h"
#include "gfx_utils/list.h"
#include "graphic_config.h"
#include "graphic_timer.h"
#include <list>
#include <string>
#include <time.h>
namespace TJD {
#define BTN_UP_VIEW_ID "btnUP"
#define BTN_DOWN_VIEW_ID "btnDOWN"
#define BTN_EDIT_VIEW_ID "btnEdit"
#define BTN_SORT_ENTER_VIEW_ID "btnSortEnter"
#define BTN_SORT_CLOSE_VIEW_ID "btnSortClose"
#define BTN_WEATHER_VIEW_ID "btnWeather"
#define BTN_TOP_MODEL_VIEW_ID "TOP_MODEL"
#define BTN_TOP_MODEL_ENTER_VIEW_ID "TOP_MODEL_ENTER"
#define BTN_SAVE_SORT_ENTER_VIEW_ID "SAVE_SORT_ENTER"
#define BTN_SAVE_SORT_CLOSE_VIEW_ID "SAVE_SORT_CLOSE"
#define BTN_PLAYER_LEFT_VIEW_ID "PLAYER_LEFT"
#define BTN_PLAYER_RIGHT_VIEW_ID "PLAYER_RIGHT"
#define BTN_PLAYER_PLAY_VIEW_ID "PLAYER_PLAY"
#define BTN_TIME_OUT_BTN_ID "btnTimeOut"
enum TopModelType
{
TOP_MODEL_DISCONNECTED = 0,
TOP_MODEL_WEATHER,
TOP_MODEL_VOICE,
TOP_MODEL_COUNT
};
enum FavoriteModel
{
MUSIC_MODEL = 0,
HEALTH_MODEL,
SLEEP_MODEL,
MOTION_MODEL,
TIMEKEEPING_MODEL,
MODEL_COUNT
};
enum FavoriteViewIndex
{
MAIN_VIEW_INDEX = 0,
SORT_VIEW_INDEX,
CHOOSE_TOP_MODEL_VIEW_INDEX,
BREAK_VIEW_INDEX,
SETTING_WAIT_VIEW_INDEX,
TIME_OUT_VIEW,
FAVORITE_UNKNOWN
};
class SortItemView : public OHOS::UIViewGroup
{
public:
SortItemView(int16_t y, int16_t index, uint16_t textId, OHOS::UIView::OnClickListener *listener);
~SortItemView() { RemoveAll(); };
void SetItemName(uint16_t textId)
{
textId_ = textId;
name_.SetTextId(textId);
}
uint16_t GetItemName() { return textId_; }
private:
uint16_t textId_{0};
OHOS::UILabelExt name_;
OHOS::UIImageView up_;
OHOS::UIImageView down_;
};
class FavoriteBaseView : public OHOS::UIScrollView
{
public:
FavoriteBaseView() {}
virtual ~FavoriteBaseView() {}
virtual void ShowView() { SetVisible(true); };
virtual void HideView() { SetVisible(false); };
void ScrollBy(int16_t xDistance, int16_t yDistance)
{
SetReboundSize(0);
OHOS::UIScrollView::ScrollBy(0, 1413);
SetReboundSize(GetHeight() / 2);
}
};
// 顶部模组组件
class FavoriteTopModel : public OHOS::UIViewGroup
{
public:
FavoriteTopModel();
~FavoriteTopModel();
void SetType(TopModelType type);
uint16_t GetGreeting(int hour);
private:
void SetDisconnectType(void);
void SetWeatherType(void);
void SetVoiceType(void);
OHOS::UIView::OnClickListener *listener_;
OHOS::UIViewGroup topModel_;
OHOS::UIImageView bg_;
OHOS::UIImageView topModelIcon_;
OHOS::UILabelExt descOne_;
OHOS::UILabelExt descTwo_;
// OHOS::List<TopModelAppItemInfo> topModelAppList_;
// uint16_t topModelAppList_[6]{0};
std::vector<uint16_t> topModelAppList_;
OHOS::UIImageView appIcon_[6];
};
// 音乐模组
class FavoriteMusicModel : public OHOS::UIViewGroup
{
public:
FavoriteMusicModel();
~FavoriteMusicModel()
{
if (lrcParser_) {
delete lrcParser_;
lrcParser_ = nullptr;
}
RemoveAll();
};
OHOS::UICheckBox::UICheckBoxState GetPlayState() { return playIcon_.GetState(); };
void SetPlayState(OHOS::UICheckBox::UICheckBoxState state) { playIcon_.SetState(state, false); };
void UpdateInfo(TjdUiAppPlayerModel *playerModel);
std::string ConvertToTimeFormat(uint64_t Seconds);
void StopAnimator(void);
private:
std::string lrc_{""};
OHOS::UILabel song_;
OHOS::UILabel lyric_;
OHOS::UILabel currentTime_;
OHOS::UILabel totalTime_;
OHOS::UIImageView musicBg_;
OHOS::UIImageView musicIcon_;
OHOS::UICheckBox playIcon_;
OHOS::UIImageView leftIcon_;
OHOS::UIImageView rightIcon_;
OHOS::UISlider progress_;
LrcParser *lrcParser_{nullptr};
OHOS::UIImageAnimatorView imageAnimator_;
};
// 健康模组
class FavoriteHealthModel : public OHOS::UIViewGroup
{
public:
FavoriteHealthModel();
~FavoriteHealthModel()
{
RemoveAll();
healthModel_.RemoveAll();
bloodPressureModel_.RemoveAll();
bloodOxygenModel_.RemoveAll();
};
OHOS::UILabel healthValue_;
OHOS::UILabel spo2Value_;
OHOS::UILabelExt healthLevel_;
OHOS::UILabelExt spo2Level_;
private:
OHOS::UIViewGroup healthModel_;
OHOS::UIImageView healthBg_;
OHOS::UIImageView healthPic_;
OHOS::UIImageView healthIcon_;
OHOS::UILabel healthUnit_;
OHOS::UILabel healthTitle_;
OHOS::UIViewGroup bloodPressureModel_;
OHOS::UIImageView spo2Bg_;
OHOS::UIImageView spo2Icon_;
OHOS::UIImageView spo2Pic_;
OHOS::UILabel spo2Unit_;
OHOS::UILabel spo2Title_;
OHOS::UIViewGroup bloodOxygenModel_;
OHOS::UIImageView bloodOxygenBg_;
OHOS::UILabel bloodOxygenUnit_;
};
// 睡眠模组
class FavoriteSleepModel : public OHOS::UIViewGroup
{
public:
FavoriteSleepModel();
~FavoriteSleepModel() { RemoveAll(); };
OHOS::UILabel sleepHourValue_;
OHOS::UILabel sleepMinValue_;
OHOS::UILabelExt sleepLevel_;
private:
OHOS::UIImageView sleepBg_;
OHOS::UIImageView sleepIcon_;
OHOS::UIImageView sleepPic_;
OHOS::UILabel sleepHourUnit_;
OHOS::UILabel sleepMinUnit_;
OHOS::UILabel sleepTitle_;
};
// 运动模组
class FavoriteMotionModel : public OHOS::UIViewGroup
{
public:
FavoriteMotionModel();
~FavoriteMotionModel()
{
RemoveAll();
motionModel_.RemoveAll();
distanceModel_.RemoveAll();
calorieModel_.RemoveAll();
};
OHOS::UILabel motionStepValue_;
OHOS::UILabel distanceValue_;
OHOS::UILabel calorieValue_;
OHOS::UISlider motionProgress_;
OHOS::UILabel motionProcess_;
private:
OHOS::UIViewGroup motionModel_;
OHOS::UIImageView motionBg_;
OHOS::UIImageView motionIcon_;
OHOS::UIImageView motionProgressBg_;
OHOS::UILabel motionTitle_;
OHOS::UIViewGroup distanceModel_;
OHOS::UIImageView distanceBg_;
OHOS::UIImageView distanceIcon_;
OHOS::UIImageView distancePic_;
OHOS::UILabel distanceTitle_;
OHOS::UILabel distanceUnit_;
OHOS::UIViewGroup calorieModel_;
OHOS::UIImageView calorieBg_;
OHOS::UIImageView calorieIcon_;
OHOS::UIImageView caloriePic_;
OHOS::UILabel calorieTitle_;
OHOS::UILabel calorieUnit_;
OHOS::UILabelExt calorieLevel_;
};
// 秒表模组
class FavoriteTimekeepingModel : public OHOS::UIViewGroup
{
public:
FavoriteTimekeepingModel();
~FavoriteTimekeepingModel() { RemoveAll(); };
void AddTimekeeping();
void StopTimekeeping();
bool OnClickEvent(const OHOS::ClickEvent &event) override;
private:
OHOS::UIImageView stopwatchBg_;
OHOS::UICheckBox startIcon_;
OHOS::UIImageView stopIcon_;
OHOS::UIImageView icon_;
OHOS::UILabel title_;
OHOS::UILabel time_;
OHOS::UILabelExt stopwatchUnit_;
OHOS::UILabel stopwatchTitle_;
std::string timeStr_{""};
};
// 主界面
class FavoriteMainView : public FavoriteBaseView
{
public:
FavoriteMainView();
~FavoriteMainView()
{
RemoveAll();
btnEdit_.RemoveAll();
};
void ShowView();
void HideView();
void SetModelSort(std::list<FavoriteModel> &favoriteModelList);
void UpdateData();
OHOS::UICheckBox::UICheckBoxState GetMusicModelPlayState();
void SetMusicModelPlayState(OHOS::UICheckBox::UICheckBoxState state);
FavoriteTopModel topModel_;
FavoriteMusicModel musicModel_;
FavoriteHealthModel healthModel_;
FavoriteSleepModel sleepModel_;
FavoriteMotionModel motionModel_;
FavoriteTimekeepingModel timekeepingModel_;
OHOS::UILabel time_;
uint32_t startTime_ = 0;
private:
OHOS::UIViewGroup btnEdit_;
OHOS::UILabelExt editDesc_;
OHOS::UIView hide_;
};
// 排序界面
class FavoriteSortModelView : public FavoriteBaseView, public OHOS::UIView::OnClickListener
{
public:
FavoriteSortModelView();
~FavoriteSortModelView();
void ShowView() override;
void HideView() override;
bool OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event) override;
SortItemView *sortItemView_[FavoriteModel::MODEL_COUNT]{nullptr};
OHOS::UILabelExt topModelValue_;
std::list<FavoriteModel> &GetModelSortList() { return modelSortList_; };
private:
std::list<FavoriteModel> modelSortList_;
void SortItem(int index, bool isUp);
OHOS::UILabelExt title_;
OHOS::UIImageView topIcon_;
OHOS::UIViewGroup topModel_;
OHOS::UILabelExt topModelDesc_;
OHOS::UIImageView btnEnter_;
uint16_t itemName_[FavoriteModel::MODEL_COUNT] = {0};
};
struct TopModelItemInfo
{
uint8_t index;
uint16_t name;
};
class TopModelItemView : public ItemConstructor<TopModelItemInfo>
{
public:
TopModelItemView(const TopModelItemInfo &itemInfo);
virtual ~TopModelItemView() { RemoveAll(); }
void RefreshItem(const TopModelItemInfo &itemInfo, int16_t index);
bool OnClickEvent(const OHOS::ClickEvent &event);
private:
OHOS::UILabelExt name_;
OHOS::UIImageView switch_;
OHOS::ImageInfo *selectRes_{nullptr};
OHOS::ImageInfo *unSelectRes_{nullptr};
};
// 顶部模组选择界面
class FavoriteChooseTopModelView : public FavoriteBaseView
{
public:
FavoriteChooseTopModelView();
~FavoriteChooseTopModelView()
{
RemoveAll();
if (adapter_ != nullptr) {
delete adapter_;
adapter_ = nullptr;
}
if (listGroup_ != nullptr) {
delete listGroup_;
listGroup_ = nullptr;
}
};
void ShowView() override;
void HideView() override;
private:
OHOS::UILabelExt title_;
OHOS::UIImageView enterIcon_;
TjdUITransformListGroupAdapter<TopModelItemInfo, TopModelItemView, std::list<TopModelItemInfo>> *adapter_{nullptr};
std::list<TopModelItemInfo> infoList_;
TjdUITransformListGroup *listGroup_{nullptr};
};
// 排序中断界面
class FavoriteBreakView : public FavoriteBaseView
{
public:
FavoriteBreakView();
~FavoriteBreakView() { RemoveAll(); };
private:
OHOS::UILabelExt desc_;
OHOS::UIImageView btnOK_;
OHOS::UIImageView btnCancel_;
};
// 设置中界面
class FavoriteSettingWaitView : public FavoriteBaseView
{
public:
FavoriteSettingWaitView();
~FavoriteSettingWaitView();
void ShowView();
void HideView();
private:
OHOS::UIImageAnimatorView animator_;
OHOS::UILabelExt desc_;
OHOS::ImageAnimatorInfo waitInfo_[11];
};
// 计时结束界面
class TimeOutView : public FavoriteBaseView
{
public:
TimeOutView();
~TimeOutView() { RemoveAll(); };
void ShowView() { SetVisible(true); };
void HideView() { SetVisible(false); };
private:
OHOS::UILabelExt timeOut_;
OHOS::UIImageView enterIcon_;
};
class TjdUiAppMainPageFavorite : public OHOS::UICardPage
{
public:
TjdUiAppMainPageFavorite();
virtual ~TjdUiAppMainPageFavorite();
static TjdUiAppMainPageFavorite *GetInstance(void);
bool OnKeyEvent(const OHOS::KeyEvent &event);
bool InitView(void);
void PreLoad(void) override;
void UnLoad(void) override;
void ScrollBegin(bool isActive) override;
void ScrollEnd(bool isActive) override;
void BackupSortItemView();
void ResetSortItemView();
void InitTargetView(FavoriteViewIndex index);
void ShowView(FavoriteViewIndex showIndex);
void UpdateSortView();
void SetFavoriteModelList(std::list<FavoriteModel> &favoriteModelList);
std::list<FavoriteModel> &GetFavoriteModelList();
std::list<FavoriteModel> &GetFavoriteSortModelViewList();
void SetHorizonalScroll(bool isHorizonal);
void SetVerticalScroll(bool isVertical);
void FavoriteClockTick(void);
void SetViewSetIntercept(bool isIntercept);
OHOS::UICheckBox::UICheckBoxState GetPlayerButtonState();
void BleStateChanged(bool isConnect);
FavoriteViewIndex currentViewIndex_ = FavoriteViewIndex::FAVORITE_UNKNOWN;
private:
bool viewiInitStatus{false};
OHOS::UIScrollView *mainView_{nullptr};
FavoriteBaseView *viewManager_[FavoriteViewIndex::FAVORITE_UNKNOWN]{nullptr};
std::string sortItemViewBackups_[FavoriteModel::MODEL_COUNT];
TopModelType backupTopModelType_{TopModelType::TOP_MODEL_DISCONNECTED};
};
} // namespace TJD
#endif // MAIN_CLOCK_VIEW_H