#include "TjdUiAppAlarmPresenter.h" #include "NativeAbility.h" #include "TjdUiAppAlarmAdapter.h" #include "TjdUiAppAlarmModel.h" #include "TjdUiAppAlarmView.h" #include "TjdUiImageIds.h" #include "TjdUiOnKeyListener.h" #include "TjdUiUtils.h" #include "common/image_cache_manager.h" #include "common/key_code.h" #include "dock/input_device.h" #include "fs_user_common.h" #include "sys_config.h" #include #include "TjdUiRegisterManager.h" #include "TjdUiMultiLanguageExt.h" using namespace OHOS; #define ENABLE_PRINT_INFO 1 #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__) // 错误信息打印一般常开 #define static_print_debug(...) sys_ui_log_d(__VA_ARGS__) // 调试信息打印 #else #define static_print_info(...) #define static_print_warn(...) #define static_print_error(...) #define static_print_debug(...) #endif namespace TJD { TJD_REGIST_NATIVE_MENU(TJD_APP_VIEW_ALARM, TjdUiAppAlarmView, TjdUiAppAlarmPresenter, IMG_MENU_LIST_MENU_CLOCK, STR_ID_14); // clang-format off #define DRAG_EXIT_DISTANCE 170 // clang-format on std::string buildCycleString(uint8_t cycle_mode) { std::array modes = {STR_ID_292, STR_ID_293, STR_ID_294, STR_ID_295, STR_ID_296, STR_ID_297, STR_ID_298}; std::string str; std::array temp = {0, 0, 0, 0, 0, 0, 0}; if (cycle_mode == 0x7f) { // str = "每日"; str = FontGlobalManager::GetInstance()->GetText(STR_ID_301); } else if (cycle_mode == 0x00) { // str = "仅一次"; str = FontGlobalManager::GetInstance()->GetText(STR_ID_304); } else { for (size_t i = 0; i < modes.size(); ++i) { if (cycle_mode & (1 << i)) { temp[i] = 1; str += std::string(FontGlobalManager::GetInstance()->GetText(modes[i])) + std::string("、"); } } std::string substr = "、"; size_t pos = str.rfind(substr); if (pos != std::string::npos) { str.erase(pos, substr.length()); } } if (temp[0] && temp[1] && temp[2] && temp[3] && temp[4]) // str = "工作日"; str = FontGlobalManager::GetInstance()->GetText(STR_ID_302); else if (temp[5] && temp[6]) // str = "休息日"; str = FontGlobalManager::GetInstance()->GetText(STR_ID_303); return str; } std::string CheckTimeIsNeedFillZero(uint8_t value) { std::string str; if (value < 10) { str = "0" + std::to_string(value); } else { str = std::to_string(value); } return str; } uint16_t convertDay(uint8_t dayNum) { switch (dayNum) { case 1: return STR_ID_292; case 2: return STR_ID_293; case 3: return STR_ID_294; case 4: return STR_ID_295; case 5: return STR_ID_296; case 6: return STR_ID_297; case 7: return STR_ID_298; default: return 0; } } static TjdUiAppAlarmPresenter *g_pv_UiAppAlarmPresenter = nullptr; TjdUiAppAlarmPresenter::TjdUiAppAlarmPresenter() { g_pv_UiAppAlarmPresenter = this; model = &TjdUiAppAlarmModel::GetInstance(); } TjdUiAppAlarmPresenter::~TjdUiAppAlarmPresenter() { g_pv_UiAppAlarmPresenter = nullptr; model = nullptr; ImageCacheManager::GetInstance().UnloadAllInMultiRes(ALARM_BIN_PATH); } TjdUiAppAlarmPresenter *TjdUiAppAlarmPresenter::GetInstance(void) { return g_pv_UiAppAlarmPresenter; } void TjdUiAppAlarmPresenter::OnStart() { static_print_info("TjdUiAppAlarmPresenter::%s", __func__); TjdUiCommonOnKeyListener::GetInstance()->SetOnKeyActListener(this, KeyModelType::APP_KEY_TYPE); } void TjdUiAppAlarmPresenter::OnResume() { static_print_info("TjdUiAppAlarmPresenter::%s", __func__); Presenter::OnResume(); } void TjdUiAppAlarmPresenter::OnPause() { static_print_info("TjdUiAppAlarmPresenter::%s", __func__); Presenter::OnPause(); } void TjdUiAppAlarmPresenter::OnStop() { static_print_info("TjdUiAppAlarmPresenter::%s", __func__); TjdUiCommonOnKeyListener::GetInstance()->ClearOnKeyActListener(KeyModelType::APP_KEY_TYPE); } bool TjdUiAppAlarmPresenter::OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event) { static_print_info("TjdUiAppAlarmPresenter::%s", __func__); if (&view == &(view_->homeContainer_->add_) || &view == &(view_->homeContainer_->firstAdd_)) { TjdUiAppAlarmView::GetInstance()->ShowView(ALARM_TIME_SET_VIEW); view_->setTimeContainer_->enterView_ = ALARM_HOME_VIEW; return true; } else if (&view == &(view_->editContainer_->delete_)) { TjdUiAppAlarmView::GetInstance()->ShowView(ALARM_DEL_REMIND_VIEW); return true; } else if (&view == &(view_->setCycleContainer_->confirm_)) { view_->setCycleContainer_->ConfirmCallback(); return true; } else if (&view == &(view_->deleteRemindContainer_->imgCancel_)) { TjdUiAppAlarmView::GetInstance()->ShowView(ALARM_EDIT_VIEW); return true; } else if (&view == &(view_->deleteRemindContainer_->imgConfirm_)) { model->DeleteAlarmFromSQL(view_->editContainer_->selectedItemInfo_.index); TjdUiAppAlarmView::GetInstance()->ShowView(ALARM_HOME_VIEW); return true; } return false; } bool TjdUiAppAlarmPresenter::OnKeyAct(OHOS::UIView &view, const OHOS::KeyEvent &event) { if (!TjdUiCommonOnKeyListener::CheckIsExitEvent(event)) { return true; } ExitCurrentView(); return false; } void TjdUiAppAlarmPresenter::OnSelectTimePicker(OHOS::UIPicker &picker) { TjdUiUtils::ViewRequestFocus(picker); } void TjdUiAppAlarmPresenter::OnEnter(int32_t hour, int32_t minute) { TjdUiAppAlarmView *alarmView = TjdUiAppAlarmView::GetInstance(); if (alarmView == nullptr) { return; } if (alarmView->setTimeContainer_->enterView_ == ALARM_HOME_VIEW) { alarmView->setTimeContainer_->hour_ = hour; alarmView->setTimeContainer_->minute_ = minute; TjdUiAppAlarmView::GetInstance()->ShowView(ALARM_CYCLE_SET_VIEW); alarmView->setCycleContainer_->enterView_ = ALARM_TIME_SET_VIEW; } else if (alarmView->setTimeContainer_->enterView_ == ALARM_EDIT_VIEW) { uint8_t index = alarmView->editContainer_->selectedItemInfo_.index; static_print_debug("AlarmTimeSetting::EnterCallback index:%d, hour:%d, minute:%d", index, hour, minute); TjdUiAppAlarmModel::GetInstance().EditAlarmTimeToSQL(index, hour, minute); alarmView->ShowView(ALARM_EDIT_VIEW); AlarmItem item = alarmView->editContainer_->selectedItemInfo_; item.hour = hour; item.minute = minute; alarmView->editContainer_->SelectedCallback(item); } } void TjdUiAppAlarmPresenter::ExitAlarmSlice(void) { static_print_info("TjdUiAppAlarmPresenter::%s", __func__); OHOS::NativeAbility::GetInstance().ChangePreSlice(); } void TjdUiAppAlarmPresenter::ExitCurrentView(void) { static_print_info("TjdUiAppAlarmPresenter::%s", __func__); // 判断当前处于几级页面并返回,若在顶层则退出 switch (currentView_) { case ALARM_HOME_VIEW: ExitAlarmSlice(); break; case ALARM_EDIT_VIEW: view_->ShowView(ALARM_HOME_VIEW); break; case ALARM_TIME_SET_VIEW: view_->ShowView(view_->setTimeContainer_->enterView_); break; case ALARM_CYCLE_SET_VIEW: view_->ShowView(view_->setCycleContainer_->enterView_); break; case ALARM_DEL_REMIND_VIEW: view_->ShowView(ALARM_EDIT_VIEW); break; default: break; } } } // namespace TJD