230 lines
9.5 KiB
C++
230 lines
9.5 KiB
C++
/*----------------------------------------------------------------------------
|
|
* Copyright (c) TJD Technologies Co., Ltd. 2024. All rights reserved.
|
|
*
|
|
* Description:
|
|
*
|
|
* Author: wuchangxin
|
|
*
|
|
* Create: 2024-7-3
|
|
*--------------------------------------------------------------------------*/
|
|
#include "TjdUiAppLuckyCloverPresenter.h"
|
|
#include "NativeAbility.h"
|
|
#include "TjdUiAppIds.h"
|
|
#include "TjdUiAppLuckyCloverModel.h"
|
|
#include "TjdUiAppLuckyCloverView.h"
|
|
#include "TjdUiMsgCenter.h"
|
|
#include "ble_api.h"
|
|
#include "dock/input_device.h"
|
|
#include "graphic_service.h"
|
|
#include "notification_manager.h"
|
|
#include "service_lucky_clover.h"
|
|
#include <stdio.h>
|
|
#include "TjdUiRegisterManager.h"
|
|
|
|
using namespace OHOS;
|
|
|
|
#define LUCKY_CLOVER_SWIPEVIEW_ID "allContainer_"
|
|
namespace TJD {
|
|
|
|
TJD_REGIST_NATIVE_MENU(TJD_APP_VIEW_LUCKY_CLOVER, TjdUiAppLuckyCloverView, TjdUiAppLuckyCloverPresenter, IMG_MENU_LIST_MENU_LEFUN, STR_ID_29);
|
|
|
|
static TjdUiAppLuckyCloverPresenter *g_pv_AppLuckyCloverPresenter = nullptr;
|
|
static UIScrollView *g_messageLuckyCloverView = nullptr;
|
|
static OHOS::RootView::OnKeyActListener *tmpLuckyCloverOnKeyListener = nullptr;
|
|
|
|
TjdUiAppLuckyCloverPresenter::TjdUiAppLuckyCloverPresenter() { g_pv_AppLuckyCloverPresenter = this; }
|
|
|
|
TjdUiAppLuckyCloverPresenter::~TjdUiAppLuckyCloverPresenter() { g_pv_AppLuckyCloverPresenter = nullptr; }
|
|
|
|
TjdUiAppLuckyCloverPresenter *TjdUiAppLuckyCloverPresenter::GetInstance(void) { return g_pv_AppLuckyCloverPresenter; }
|
|
|
|
void TjdUiAppLuckyCloverPresenter::OnStart()
|
|
{
|
|
TjdUiCommonOnKeyListener::GetInstance()->SetOnKeyActListener(this, KeyModelType::APP_KEY_TYPE);
|
|
}
|
|
|
|
void TjdUiAppLuckyCloverPresenter::OnPause() { Presenter::OnPause(); }
|
|
|
|
void TjdUiAppLuckyCloverPresenter::OnResume() { Presenter::OnResume(); }
|
|
|
|
void TjdUiAppLuckyCloverPresenter::OnStop()
|
|
{
|
|
TjdUiCommonOnKeyListener::GetInstance()->ClearOnKeyActListener(KeyModelType::APP_KEY_TYPE);
|
|
}
|
|
|
|
void TjdUiAppLuckyCloverPresenter::OnSwipe(OHOS::UISwipeView &view) {}
|
|
|
|
bool TjdUiAppLuckyCloverPresenter::OnClick(UIView &view, const ClickEvent &event) { return false; }
|
|
|
|
void TjdUiAppLuckyCloverPresenter::ViewExitEvent(OHOS::UIView &view)
|
|
{
|
|
ExitLuckyCloverView();
|
|
}
|
|
|
|
bool TjdUiAppLuckyCloverPresenter::OnKeyAct(OHOS::UIView &view, const OHOS::KeyEvent &event)
|
|
{
|
|
if (!TjdUiCommonOnKeyListener::GetInstance()->CheckIsExitEvent(event)) {
|
|
return true;
|
|
}
|
|
ExitLuckyCloverView();
|
|
|
|
return false;
|
|
}
|
|
|
|
bool TjdUiAppLuckyCloverPresenter::OnDrag(OHOS::UIView &view, const OHOS::DragEvent &event)
|
|
{
|
|
printf("TjdUiAppLuckyCloverPresenter ondragend\r\n");
|
|
TjdUiAppLuckyCloverView *luckyCloverView = TjdUiAppLuckyCloverView::GetInstance();
|
|
|
|
if (event.GetDragDirection() == OHOS::DragEvent::DIRECTION_BOTTOM_TO_TOP) {
|
|
if (view.GetViewId() == "mainPage_") {
|
|
view.SetVisible(false);
|
|
luckyCloverView->dataPage_->SetVisible(true);
|
|
return true;
|
|
}
|
|
}
|
|
if (event.GetDragDirection() == OHOS::DragEvent::DIRECTION_TOP_TO_BOTTOM) {
|
|
if (view.GetViewId() == "dataPage_" && (luckyCloverView->dataPage_->GetRect().GetTop() >= 0)) {
|
|
view.SetVisible(false);
|
|
luckyCloverView->mainPage_->SetVisible(true);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return TjdUiScreenDragListener::OnDrag(view, event);
|
|
}
|
|
|
|
void TjdUiAppLuckyCloverPresenter::ExitLuckyCloverView(void)
|
|
{
|
|
OHOS::NativeAbility::GetInstance().ChangePreSlice();
|
|
printf("TjdUiAppLuckyCloverPresenter::ExitLuckyCloverView");
|
|
}
|
|
|
|
void TjdUiAppLuckyCloverPresenter::StartJumpTimer(void)
|
|
{
|
|
if (jumpTimerId_ == nullptr) {
|
|
jumpTimerId_ = osTimerNew(
|
|
[](void *arg) {
|
|
GraphicService::GetInstance()->PostGraphicEvent([]() {
|
|
TjdUiAppLuckyCloverPresenter *luckyCloverPresenter = TjdUiAppLuckyCloverPresenter::GetInstance();
|
|
if (luckyCloverPresenter == nullptr) {
|
|
return;
|
|
}
|
|
printf("TjdUiAppLuckyCloverPresenter::StartJumpTimer Jump to Home\n");
|
|
luckyCloverPresenter->ExitLuckyCloverView();
|
|
});
|
|
},
|
|
osTimerOnce, nullptr, nullptr);
|
|
if (jumpTimerId_ == nullptr) {
|
|
printf("TjdUiAppLuckyCloverPresenter::StartJumpTimer Create timer fail.\n");
|
|
return;
|
|
}
|
|
}
|
|
|
|
int ret = osTimerStart(jumpTimerId_, 3000);
|
|
|
|
if (ret != 0) {
|
|
printf("TjdUiAppAlipayModel::AlipayStartBind Start timer fail\n");
|
|
return;
|
|
}
|
|
}
|
|
|
|
void TjdUiLuckyCloverMessageProc(const Topic topic, Request *req)
|
|
{
|
|
printf("TjdUiLuckyCloverMessageProc 133\n");
|
|
lucky_clover_msg_t msgData = *(lucky_clover_msg_t *)(req->data);
|
|
|
|
OHOS::NotificationManager::GetInstance()->SetNotifyPriority(TjdUiMsgCenterGetPriority(topic));
|
|
OHOS::NotificationManager::GetInstance()->ShowNotify(
|
|
[msgData]() -> OHOS::UIScrollView * {
|
|
if (g_messageLuckyCloverView == nullptr) {
|
|
printf("TjdUiLuckyCloverMessageProc");
|
|
std::string popupText;
|
|
g_pv_AppLuckyCloverPresenter = new TjdUiAppLuckyCloverPresenter();
|
|
switch (msgData.msg_type) {
|
|
case 0:
|
|
popupText = "站立活动";
|
|
g_messageLuckyCloverView =
|
|
new LuckyCloverRemindWindow(msgData.lucky_clover_data.currentStandNum,
|
|
msgData.lucky_clover_data.goalStandNum, (char *)popupText.c_str());
|
|
break;
|
|
case 1:
|
|
popupText = "活动热量";
|
|
g_messageLuckyCloverView = new LuckyCloverRemindWindow(msgData.lucky_clover_data.currentCalorieNum,
|
|
msgData.lucky_clover_data.goalCalorieNum,
|
|
(char *)popupText.c_str());
|
|
break;
|
|
case 2:
|
|
popupText = "中高强度";
|
|
g_messageLuckyCloverView = new LuckyCloverRemindWindow(
|
|
msgData.lucky_clover_data.currentStrengthTime, msgData.lucky_clover_data.goalStrengthTime,
|
|
(char *)popupText.c_str());
|
|
break;
|
|
case 3:
|
|
popupText = "步数";
|
|
g_messageLuckyCloverView =
|
|
new LuckyCloverRemindWindow(msgData.lucky_clover_data.currentStepNum,
|
|
msgData.lucky_clover_data.goalStepNum, (char *)popupText.c_str());
|
|
break;
|
|
case 4:
|
|
popupText = "每日喝水";
|
|
g_messageLuckyCloverView =
|
|
new LuckyCloverRemindWindow(msgData.lucky_clover_data.currentDrinkNum,
|
|
msgData.lucky_clover_data.goalDrinkNum, (char *)popupText.c_str());
|
|
break;
|
|
case 5:
|
|
popupText = "早睡";
|
|
g_messageLuckyCloverView =
|
|
new LuckyCloverRemindWindow(msgData.lucky_clover_data.currentDrinkNum,
|
|
msgData.lucky_clover_data.goalDrinkNum, (char *)popupText.c_str());
|
|
break;
|
|
case 6:
|
|
popupText = "睡眠时长";
|
|
g_messageLuckyCloverView =
|
|
new LuckyCloverRemindWindow(msgData.lucky_clover_data.currentDrinkNum,
|
|
msgData.lucky_clover_data.goalDrinkNum, (char *)popupText.c_str());
|
|
break;
|
|
case 7:
|
|
popupText = "血压测量";
|
|
g_messageLuckyCloverView =
|
|
new LuckyCloverRemindWindow(msgData.lucky_clover_data.currentDrinkNum,
|
|
msgData.lucky_clover_data.goalDrinkNum, (char *)popupText.c_str());
|
|
break;
|
|
case 8:
|
|
popupText = "自定义";
|
|
g_messageLuckyCloverView =
|
|
new LuckyCloverRemindWindow(msgData.lucky_clover_data.currentDrinkNum,
|
|
msgData.lucky_clover_data.goalDrinkNum, (char *)popupText.c_str());
|
|
break;
|
|
case 9:
|
|
g_messageLuckyCloverView = new LuckyCloverPopupWindow(POPUP_WINDOW_ENERGETIC_CLOVER);
|
|
break;
|
|
case 10:
|
|
g_messageLuckyCloverView = new LuckyCloverPopupWindow(POPUP_WINDOW_PERFECT_CLOVER);
|
|
break;
|
|
case 11:
|
|
g_messageLuckyCloverView =
|
|
new GSensor_RemindWindow(TjdUiAppLuckyCloverModel::GetInstance()->get_lucky_clover_info());
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
OHOS::NotificationManager::GetInstance()->RegisterNotifyCleanupFunction([]() {
|
|
printf("TjdUiShutdownMsgCenterMessageProc RegisterNotifyCleanupFunction");
|
|
OHOS::NotificationManager::GetInstance()->SetNotifyPriority(TJD_UI_PRIO_LOWEST);
|
|
delete g_messageLuckyCloverView;
|
|
delete g_pv_AppLuckyCloverPresenter;
|
|
g_messageLuckyCloverView = nullptr;
|
|
g_pv_AppLuckyCloverPresenter = nullptr;
|
|
RunPopOutPageCallback();
|
|
});
|
|
return g_messageLuckyCloverView;
|
|
},
|
|
static_cast<uint16_t>(topic), true
|
|
|
|
);
|
|
}
|
|
|
|
} // namespace TJD
|