#include "TjdUiAppAlbumPresenter.h" #include "NativeAbility.h" #include "TjdUiAppAlbumModel.h" #include "TjdUiAppAlbumView.h" #include "common/image_cache_manager.h" #include "dock/input_device.h" #include "sys_config.h" #include "TjdUiRegisterManager.h" #define ENABLE_PRINT_INFO 1 #define ENABLE_DEBUG 0 #if ENABLE_PRINT_INFO #define static_print_info(...) sys_ui_log_i(__VA_ARGS__) // 一般信息打印宏控制 #define static_print_warn(...) sys_ui_log_w(__VA_ARGS__) // 警告信息打印一般常开 #define static_print_error(...) sys_ui_log_e(__VA_ARGS__) // 错误信息打印一般常开 #if ENABLE_PRINT_INFO #define static_print_debug(...) sys_ui_log_d(__VA_ARGS__) // 调试信息打印 #else #define static_print_debug(...) #endif #else #define static_print_info(...) #define static_print_warn(...) #define static_print_error(...) #define static_print_debug(...) #endif using namespace OHOS; namespace TJD { TJD_REGIST_NATIVE_MENU(TJD_APP_VIEW_ALBUM, TjdUiAppAlbumView, TjdUiAppAlbumPresenter, IMG_MENU_LIST_MENU_PHOTO, STR_ID_20); // clang-format off #define DRAG_EXIT_DISTANCE 170 // clang-format on static void *g_task_ui_album_handle; static bool g_pv_isExit_{true}; static TjdUiAppAlbumPresenter *g_pv_UiAppAlbumPresenter = nullptr; static ImageAnimatorInfo g_imageAnimatorInfo[11] = { {nullptr, {104, 40}, 71, 71, IMG_SRC_IMAGE_INFO}, {nullptr, {104, 40}, 71, 71, IMG_SRC_IMAGE_INFO}, {nullptr, {104, 40}, 71, 71, IMG_SRC_IMAGE_INFO}, }; TjdUiAppAlbumPresenter::TjdUiAppAlbumPresenter() { g_pv_UiAppAlbumPresenter = this; model = &TjdUiAppAlbumModel::GetInstance(); ImageCacheManager::GetInstance().LoadAllInMultiRes(ALBUM_IMAGE_BIN_PATH); LoadIconRes(); } TjdUiAppAlbumPresenter::~TjdUiAppAlbumPresenter() { g_pv_UiAppAlbumPresenter = nullptr; ImageCacheManager::GetInstance().UnloadAllInMultiRes(ALBUM_IMAGE_BIN_PATH); } TjdUiAppAlbumPresenter *TjdUiAppAlbumPresenter::GetInstance(void) { return g_pv_UiAppAlbumPresenter; } void TjdUiAppAlbumPresenter::OnStart() { static_print_info("TjdUiAppAlbumPresenter::%s", __func__); TjdUiCommonOnKeyListener::GetInstance()->SetOnKeyActListener(this, KeyModelType::APP_KEY_TYPE); view_->GetUIList()->SetAdapter(view_->GetAdapter()); view_->GetUIList()->ScrollBy((VERTICAL_RESOLUTION - ALBUM_ITEM_H) / 2); } void TjdUiAppAlbumPresenter::OnResume(void) { static_print_info("TjdUiAppAlbumPresenter::%s", __func__); firstEnter_ = true; if (view_->GetUIList()) { view_->GetUIList()->RequestFocus(); view_->GetUIList()->SetRotateFactor(1.0); } Presenter::OnResume(); } void TjdUiAppAlbumPresenter::OnPause(void) { static_print_info("TjdUiAppAlbumPresenter::%s", __func__); if (view_->GetUIList()) { view_->GetUIList()->ClearFocus(); } Presenter::OnPause(); } void TjdUiAppAlbumPresenter::OnStop(void) { static_print_info("TjdUiAppAlbumPresenter::%s", __func__); if (view_->GetUIList()) view_->GetUIList()->ClearFocus(); Presenter::OnStop(); TjdUiCommonOnKeyListener::GetInstance()->ClearOnKeyActListener(KeyModelType::APP_KEY_TYPE); } bool TjdUiAppAlbumPresenter::OnClick(UIView &view, const ClickEvent &event) { std::string viewId = view.GetViewId(); if (viewId == SET_WALLPAPER_BUTTON) { view_->EnterWallPaperSet(true); return true; } else if (viewId == SET_CANCEL_BUTTON) { view_->EnterWallPaperSet(false); return true; } else if (viewId == SET_CONFIRM_BUTTON) { view_->EnterWallPaperSet(false); view_->ChangeView(ALBUM_SETTING_VIEW, ALBUM_PHOTO_VIEW); currentView = ALBUM_SETTING_VIEW; return true; } else if (viewId == SET_RESET_BUTTON) { view_->EnterSetFail(false); } return false; } bool TjdUiAppAlbumPresenter::OnKeyAct(UIView &view, const KeyEvent &event) { if(!TjdUiCommonOnKeyListener::CheckIsExitEvent(event)) { return true; } if (currentView == ALBUM_SETTING_VIEW && !view_->isSetWallPaperFail_) { return true; // 非设置失败页面,不设置退出事件 } ExitCurrentView(); return false; } void TjdUiAppAlbumPresenter::OnItemSelected(int16_t index, OHOS::UIView *view) { static_print_info("TjdUiAppAlbumPresenter::%s index:%d", __func__, index); UNUSED(index); if (view != nullptr) { itemViewSele = static_cast(view); itemViewSele->SelectedChange(); if (preItemViewSele != nullptr && preItemViewSele != itemViewSele) { preItemViewSele->Reset(); } preItemViewSele = itemViewSele; } } void TjdUiAppAlbumPresenter::LoadIconRes(void) { for (int i = 0; i < ALBUM_ICON_MAX; i++) { AlbumIconArray[i] = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_ALBUM_BACKWARD + i, ALBUM_IMAGE_BIN_PATH); if (AlbumIconArray[i] == nullptr) static_print_error("TjdUiAppAlbumPresenter::%s: AlbumIconArray[%d] is nullptr", i); } } void TjdUiAppAlbumPresenter::ExitAlbumView(void) { static_print_info("TjdUiAppAlbumPresenter::%s", __func__); OHOS::NativeAbility::GetInstance().ChangePreSlice(); } void TjdUiAppAlbumPresenter::ExitCurrentView(void) { // 判断当前处于几级页面并返回,若在顶层则退出 if (view_->viewHierarchy.find(currentView) != view_->viewHierarchy.end()) { if (currentView == ALBUM_PHOTO_VIEW && view_->isEnterWallPaperSet_) { view_->EnterWallPaperSet(false); return; } else if (currentView == ALBUM_PHOTO_VIEW && !view_->isEnterWallPaperSet_ && view_->isEnterFromVideo_) { view_->isEnterFromVideo_ = false; view_->ChangeView(ALBUM_VIDEO_VIEW, currentView); return; } else if (currentView == ALBUM_SETTING_VIEW) { view_->SettingViewInit(); } view_->ChangeView(view_->viewHierarchy.at(currentView), currentView); } else { ExitAlbumView(); } } void TjdUiAppAlbumPresenter::TaskProcess(AlbumItem *item) { #define APP_MAIN_STACK_SIZE 0x1c00 #define TASK_PRIORITY_APP (osPriority_t)(16) osThreadAttr_t task_attr = { "tjd_t_ui_album_update_wfjson", 0, NULL, 0, NULL, APP_MAIN_STACK_SIZE, TASK_PRIORITY_APP, 0, 0}; g_task_ui_album_handle = osThreadNew( [](void *param) { AlbumItem *item = static_cast(param); TjdUiAppAlbumModel::GetInstance().UpdateWfJson(item->type, item->path); TjdUiAppAlbumPresenter::GetInstance()->isSetSucc = true; }, item, &task_attr); osThreadDetach(g_task_ui_album_handle); } } // namespace TJD