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

137 lines
4.4 KiB
C++

#ifndef TJDUIAPP_ALBUM_MODEL
#define TJDUIAPP_ALBUM_MODEL
#include "TjdUiImageIds.h"
#include "ui_view.h"
#include "audio_manager.h"
#include "audio_base_type.h"
#include "player.h"
#include "list"
#include "media_thread_adapt.h"
#include "components/ui_button.h"
#include "components/ui_lite_surface_view.h"
#include "video_play_wrapper.h"
namespace TJD {
#define ALBUM_IMAGE_BIN_PATH TJD_IMAGE_PATH"/img_album.bin"
#define ALBUM_NUM_MAX 10
#define ALBUM_BUTTON_NUM 4
#define FORWARD_BUTTON "forward_button"
#define BACKWARD_BUTTON "backward_button"
#define PAUSE_RESUME_BUTTON "pause_resume_button"
#define WALLPAPER_BUTTON "wallpaper_button"
#define SET_WALLPAPER_BUTTON "set_wallpaper_button"
#define SET_CONFIRM_BUTTON "set_confirm_button"
#define SET_CANCEL_BUTTON "set_cancel_button"
#define SET_RESET_BUTTON "set_reset_button"
#define NONE_ALBUM_LABEL "none_album_label"
#define SET_WALLPAPER_LABEL "set_wallpaper_label"
#define SET_SUCC_LABEL "set_succ_label"
#define SET_FAIL_LABEL "set_fail_label"
#define SELECTED_PHOTO_IMAGE "selected_photo_image"
#define SET_SUCC_IMAGE "set_succ_image"
#define SET_FAIL_IMAGE "set_fail_image"
#define ALBUM_ITEM_H 300
#define ALBUM_ITEM_W 380
#define DELECT_ICON_INTERVAL 30
#define DELECT_ICON_H 106
#define DELECT_ICON_W 105
enum Album_type{
ALBUM_PHOTO,
ALBUM_VIDEO
};
enum AlbumView{
ALBUM_LIST_VIEW,
ALBUM_PHOTO_VIEW,
ALBUM_VIDEO_VIEW,
ALBUM_SETTING_VIEW,
ALBUM_VIEW_MAX
};
enum AlbumIconType{
ALBUM_BACKWARD,
ALBUM_CANCEL,
ALBUM_CONFIRM,
ALBUM_DELETE,
ALBUM_FORWARD,
ALBUM_PAUSE,
ALBUM_RESET,
ALBUM_RESUME,
ALBUM_RETURN,
ALBUM_SET_FALSE,
ALBUM_SET_SUCC,
ALBUM_WALLPAPER,
ALBUM_ICON_MAX
};
struct AlbumItem{
uint8_t index = 0;
Album_type type = ALBUM_PHOTO;
char path[256] = {0};
AlbumItem() = default;
AlbumItem(uint8_t index, Album_type type, const char *path)
: index(index), type(type) {
if (path != nullptr) {
std::strncpy(this->path, path, sizeof(this->path) - 1);
this->path[sizeof(this->path) - 1] = '\0';
}
}
// 辅助函数,用于获取文件名(包括扩展名)
const char* getFileName() const {
const char* lastSlash = std::strrchr(path, '/');
if (lastSlash) {
return lastSlash + 1;
}
return path;
}
// 辅助函数,用于比较文件名(忽略扩展名)
bool hasSameBaseName(const AlbumItem& other) const {
const char* myFileName = getFileName();
const char* otherFileName = other.getFileName();
// 找到各自的扩展名开始位置
const char* myExt = std::strrchr(myFileName, '.');
const char* otherExt = std::strrchr(otherFileName, '.');
// 如果任一文件没有扩展名,则直接比较整个文件名
if (!myExt || !otherExt) return std::strcmp(myFileName, otherFileName) == 0;
// 比较扩展名之前的部分
return std::strncmp(myFileName, otherFileName, myExt - myFileName) == 0;
}
};
class TjdUiAppAlbumModel {
public:
static TjdUiAppAlbumModel &GetInstance(void);
int GetAllFiles(std::list<AlbumItem> *playersCaseList);
bool DeleteFile(Album_type type, const char *filePath);
void UpdateWfJson(Album_type type, const std::string& filename);
uint8_t valid_num{0};
private:
};
class AlbumVideoPlayer : public OHOS::MediaVideoPlay {
public:
AlbumVideoPlayer(OHOS::Surface *surface, OHOS::UIButton **buttonArray,
std::string uri, bool isPureVideo);
~AlbumVideoPlayer();
int64_t GetDurationTime(void);
void SetUri(std::string uri);
OHOS::UIButton *buttonArray_[ALBUM_BUTTON_NUM]{nullptr};
};
} //namespace TJD
#endif