mcu_hi3321_watch/tjd/ui/app/startup/TjdUiAppStartUpPresenter.cpp
2025-05-26 20:15:20 +08:00

176 lines
5.6 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "TjdUiAppStartUpPresenter.h"
#include "NativeAbility.h"
#include "TjdUiAppIds.h"
#include "TjdUiAppStartUpItemView.h"
#include "TjdUiAppStartUpModel.h"
#include "TjdUiAppStartUpView.h"
#include "TjdUiImageIds.h"
#include "TjdUiRegisterManager.h"
#include "TjdUiScreenManage.h"
#include "ability_manager.h"
#include "common/image_cache_manager.h"
#include "graphic_service.h"
#include "securec.h"
#include "service_startup.h"
#include "sys_config.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
// clang-format off
#define STARTUP_IMAGE_BIN_PATH TJD_IMAGE_PATH"/img_startup.bin"
#define DRAG_EXIT_DISTANCE 170
// clang-format on
namespace TJD {
TJD_REGIST_SLICE(TJD_APP_VIEW_STARTUP, TjdStartUpView, TjdStartUpPresenter);
static TjdStartUpPresenter *g_startUpPresenter = nullptr;
TjdStartUpPresenter::TjdStartUpPresenter()
{
g_startUpPresenter = this;
SetPeriod(2000); // 定时通知触发notify
}
TjdStartUpPresenter::~TjdStartUpPresenter() { g_startUpPresenter = nullptr; }
TjdStartUpPresenter *TjdStartUpPresenter::GetInstance(void) { return g_startUpPresenter; }
void TjdStartUpPresenter::OnStart()
{
TjdUiScreenManage::DisableBackHomeInterval();
TjdUiCommonOnKeyListener::GetInstance()->SetOnKeyActListener(this, KeyModelType::APP_KEY_TYPE);
TjdStartUpModel::GetInstance().LoadMacAddr();
view_->InitViewData();
static_print_info("mac addr: %s", TjdStartUpModel::GetInstance().GetMacAddr().c_str());
}
void TjdStartUpPresenter::OnStop(void)
{
tjd_service_startup_task_ui_update(true);
TjdUiScreenManage::ResetBackHomeInterval();
TjdUiScreenManage::SetScreenKeepOnTimeout();
TjdUiCommonOnKeyListener::GetInstance()->ClearOnKeyActListener(KeyModelType::APP_KEY_TYPE);
}
bool TjdStartUpPresenter::OnClick(UIView &view, const ClickEvent &event)
{
if (view.GetViewId() == std::string("StartUpQrcode")) {
click_count++;
if (click_count >= 7) {
click_count = 0;
ChangeToFactory();
}
return true;
}
return false;
}
void TjdStartUpPresenter::ViewExitEvent()
{
if (view_->currentPage == DETAIL_VIEW) {
view_->ChangedView(SELECT_VIEW, DETAIL_VIEW);
click_count = 0;
return;
}
}
bool TjdStartUpPresenter::OnKeyAct(UIView &view, const KeyEvent &event)
{
if (!TjdUiCommonOnKeyListener::CheckIsExitEvent(event)) {
return true;
}
if (view_->currentPage == SELECT_VIEW) {
TjdStartUpModel::GetInstance().SetLanguage(LANGUAGE_CHINESE);
view_->ChangedView(DETAIL_VIEW, SELECT_VIEW);
return true;
} else if (view_->currentPage == DETAIL_VIEW) {
ChangeToMainview();
return true;
}
return false;
}
void TjdStartUpPresenter::Notify(void)
{
if (TjdStartUpModel::GetInstance().GetBtLinkStatus() == true && view_->currentPage == DETAIL_VIEW) {
view_->ChangedView(LINKOK_VIEW, DETAIL_VIEW);
}
if (view_->currentPage == LINKOK_VIEW) {
if (skipMainWaitCount--) {
ChangeToMainview();
}
}
}
void TjdStartUpPresenter::OnSwipe(UISwipeView &view)
{
static_print_info("swipeView page:%d", view.GetCurrentPage());
if (view.GetCurrentPage() != 0) {
click_count = 0;
}
}
const std::string &TjdStartUpPresenter::GetMacAddr(void) { return TjdStartUpModel::GetInstance().GetMacAddr(); }
void TjdStartUpPresenter::StartJumpTimer(StartUpView jumpView)
{
if (jumpTimerId_ == nullptr) {
jumpTimerId_ = osTimerNew(
[](void *arg) {
StartUpView jumpView = static_cast<StartUpView>(reinterpret_cast<intptr_t>(arg));
GraphicService::GetInstance()->PostGraphicEvent([jumpView]() {
TjdStartUpView *view = TjdStartUpView::GetInstance();
TjdStartUpPresenter *presenter = TjdStartUpPresenter::GetInstance();
if (view == nullptr) {
return;
}
view->ChangedView(jumpView, view->currentPage);
presenter->DeleteJumpTimer();
});
},
osTimerOnce, reinterpret_cast<void *>(static_cast<intptr_t>(jumpView)), nullptr);
if (jumpTimerId_ == nullptr) {
static_print_error("TjdUiAppAlipayPresenter::StartJumpTimer Create timer fail.");
return;
}
}
int32_t ret = osTimerStart(jumpTimerId_, 300);
if (ret != 0) {
static_print_error("TjdUiAppAlipayPresenter::StartJumpTimer Start timer fail");
return;
}
}
void TjdStartUpPresenter::DeleteJumpTimer()
{
if (jumpTimerId_ != nullptr) {
osTimerDelete(jumpTimerId_);
jumpTimerId_ = nullptr;
}
}
void TjdStartUpPresenter::ShowQrcodeViewEvent() { TjdUiScreenManage::SetScreenKeepOnTimeout(1000 * 60 * 60); }
void TjdStartUpPresenter::HideQrcodeViewEvent() { TjdUiScreenManage::SetScreenKeepOnTimeout(0); }
void TjdStartUpPresenter::ChangeToFactory(void) { NativeAbility::GetInstance().ChangeSlice(TJD_APP_VIEW_PRODUCTION); }
void TjdStartUpPresenter::ChangeToMainview() { NativeAbility::GetInstance().ChangeSlice(TJD_APP_VIEW_MAIN); }
} // namespace TJD