#include "TjdUiAppLefunAiPresenter.h" #include "NativeAbility.h" #include "TjdUiAppLefunAiModel.h" #include "TjdUiAppLefunAiView.h" #include "ble_api.h" #include "dock/input_device.h" #include "graphic_service.h" #include "sys_config.h" #include #include "TjdUiRegisterManager.h" namespace TJD { TJD_REGIST_NATIVE_MENU(TJD_APP_VIEW_LEFUN_AI, TjdUiAppLefunAiView, TjdUiAppLefunAiPresenter, IMG_MENU_LIST_MENU_LEFUNAI, STR_ID_30); #define LefunAi_GET_PAY_STR_MAX_LENGTH 20 #define ENABLE_PRINT_INFO 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__) // 错误信息打印一般常开 #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 struct LefunAiOnClickMapper { const char *id; void (TjdUiAppLefunAiPresenter::*func)(); }; static TjdUiAppLefunAiPresenter *g_pv_AppLefunAiPresenter = nullptr; TjdUiAppLefunAiPresenter::TjdUiAppLefunAiPresenter() { extern void lefun_ai_data_callback(struct data_flow * data); extern void lefun_ai_data_end_callback(struct data_flow * data); TjdUiAppLefunAiModel::GetInstance().RegisterLefunAiDataCallback(lefun_ai_data_callback); TjdUiAppLefunAiModel::GetInstance().RegisterLefunAiDataEndCallback(lefun_ai_data_end_callback); g_pv_AppLefunAiPresenter = this; } TjdUiAppLefunAiPresenter::~TjdUiAppLefunAiPresenter() { TjdUiAppLefunAiModel::GetInstance().UnregisterLefunAiDataCallback(); TjdUiAppLefunAiModel::GetInstance().UnregisterLefunAiDataEndCallback(); g_pv_AppLefunAiPresenter = nullptr; } TjdUiAppLefunAiPresenter *TjdUiAppLefunAiPresenter::GetInstance(void) { return g_pv_AppLefunAiPresenter; } void TjdUiAppLefunAiPresenter::OnStart() { printf("=======TjdUiAppLefunAiPresenter::%s\n", __func__); TjdUiCommonOnKeyListener::GetInstance()->SetOnKeyActListener(this, KeyModelType::APP_KEY_TYPE); } void TjdUiAppLefunAiPresenter::OnStop() { TjdUiCommonOnKeyListener::GetInstance()->ClearOnKeyActListener(KeyModelType::APP_KEY_TYPE); } void TjdUiAppLefunAiPresenter::OnPause() { Presenter::OnPause(); } void TjdUiAppLefunAiPresenter::OnResume() { Presenter::OnResume(); } bool TjdUiAppLefunAiPresenter::OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event) { printf("=======TjdUiAppLefunAiPresenter::%s\n", __func__); if (view.GetViewId() == TIMEOUT_VIEW_RETRY_ID) { TjdUiAppLefunAiView *view = TjdUiAppLefunAiView::GetInstance(); if (view == nullptr) { return false; } view->ShowView(LefunAiView::LEFUN_AI_VIEW_ANALYSIS_VIEW); } OnClickedEventDistribute(view.GetViewId()); return true; } bool TjdUiAppLefunAiPresenter::OnKeyAct(OHOS::UIView &view, const OHOS::KeyEvent &event) { if(!TjdUiCommonOnKeyListener::CheckIsExitEvent(event)) { return true; } ViewExitEvent(view); return true; } void TjdUiAppLefunAiPresenter::ViewExitEvent(OHOS::UIView &view) { printf("TjdUiAppLefunAiPresenter::[%s][%s]\n", __func__, view.GetViewId()); switch (TjdUiAppLefunAiView::currentViewIndex_) { case LefunAiView::LEFUN_AI_VIEW_MAIN: OHOS::NativeAbility::GetInstance().ChangePreSlice(); break; case LefunAiView::LEFUN_AI_VIEW_RECORDING_VIEW: case LefunAiView::LEFUN_AI_VIEW_TIME_OUT_VIEW: case LefunAiView::LEFUN_AI_VIEW_HISTORY_VIEW: TjdUiAppLefunAiView::GetInstance()->ShowView(LefunAiView::LEFUN_AI_VIEW_MAIN); break; case LefunAiView::LEFUN_AI_VIEW_ANALYSIS_VIEW: LefunAiAnalysisView::GetInstance()->ViewExitEvent(); TjdUiAppLefunAiView::GetInstance()->ShowView(LefunAiView::LEFUN_AI_VIEW_MAIN); break; default: break; } } void TjdUiAppLefunAiPresenter::MainViewHistoryBtnClick() { TjdUiAppLefunAiView *view = TjdUiAppLefunAiView::GetInstance(); if (view == nullptr) { return; } view->ShowView(LefunAiView::LEFUN_AI_VIEW_HISTORY_VIEW); } void TjdUiAppLefunAiPresenter::MainViewConfirmBtnClick() { TjdUiAppLefunAiView *view = TjdUiAppLefunAiView::GetInstance(); if (view == nullptr) { return; } if (tjd_get_ble_is_connect()) { TjdUiAppLefunAiModel::GetInstance().LefunAiRequestIntoAudioTransmit(); TjdUiAppLefunAiModel::GetInstance().LefunAiRequestStartAudioTransmit(); view->ShowView(LefunAiView::LEFUN_AI_VIEW_RECORDING_VIEW); } else { view->ShowView(LefunAiView::LEFUN_AI_VIEW_NO_CONNECT_VIEW); StartJumpTimer(LefunAiView::LEFUN_AI_VIEW_MAIN); } } void TjdUiAppLefunAiPresenter::RecordingViewBtnClick() { TjdUiAppLefunAiView *view = TjdUiAppLefunAiView::GetInstance(); if (view == nullptr) { return; } view->ShowView(LefunAiView::LEFUN_AI_VIEW_ANALYSIS_VIEW); } void TjdUiAppLefunAiPresenter::TimeoutViewRetryBtnClick() { TjdUiAppLefunAiModel::GetInstance().LefunAiRequestIntoAudioTransmit(); TjdUiAppLefunAiModel::GetInstance().LefunAiRequestStartAudioTransmit(); TjdUiAppLefunAiModel::GetInstance().ResendAudioData(); } void TjdUiAppLefunAiPresenter::TimeoutViewCancelBtnClick() { TjdUiAppLefunAiView *view = TjdUiAppLefunAiView::GetInstance(); if (view == nullptr) { return; } view->ShowView(LefunAiView::LEFUN_AI_VIEW_MAIN); } void TjdUiAppLefunAiPresenter::AnswerViewBtnClick() { TjdUiAppLefunAiView *view = TjdUiAppLefunAiView::GetInstance(); if (view == nullptr) { return; } TjdUiAppLefunAiModel::GetInstance().DeleDataFlow(); view->ShowView(LefunAiView::LEFUN_AI_VIEW_MAIN); LefunAiAnswerView::GetInstance()->answerView_.ScrollBy( 0, LefunAiAnswerView::GetInstance()->answerView_.GetRect().GetBottom()); } void TjdUiAppLefunAiPresenter::NoContentViewBtnClick() { TjdUiAppLefunAiView *view = TjdUiAppLefunAiView::GetInstance(); if (view == nullptr) { return; } view->ShowView(LefunAiView::LEFUN_AI_VIEW_MAIN); } void TjdUiAppLefunAiPresenter::HistoryViewBtnClick() { TjdUiAppLefunAiView *view = TjdUiAppLefunAiView::GetInstance(); if (view == nullptr) { return; } view->ShowView(LefunAiView::LEFUN_AI_VIEW_MAIN); } static const LefunAiOnClickMapper g_LefunAi_OnClickMapper[] = { {MAIN_VIEW_ID, &TjdUiAppLefunAiPresenter::MainViewConfirmBtnClick}, {MAIN_VIEW_HISTORY_BTN_ID, &TjdUiAppLefunAiPresenter::MainViewHistoryBtnClick}, {RECORDING_VIEW_ID, &TjdUiAppLefunAiPresenter::RecordingViewBtnClick}, {TIMEOUT_VIEW_RETRY_ID, &TjdUiAppLefunAiPresenter::TimeoutViewRetryBtnClick}, {TIMEOUT_VIEW_CANCEL_ID, &TjdUiAppLefunAiPresenter::TimeoutViewCancelBtnClick}, {ANSWER_VIEW_ID, &TjdUiAppLefunAiPresenter::AnswerViewBtnClick}, {NO_CONTENT_VIEW_ID, &TjdUiAppLefunAiPresenter::NoContentViewBtnClick}, {HISTORT_VIEW_ID, &TjdUiAppLefunAiPresenter::HistoryViewBtnClick}, }; void TjdUiAppLefunAiPresenter::OnClickedEventDistribute(const char *viewId) { for (const auto &view : g_LefunAi_OnClickMapper) { if (strcmp(viewId, view.id) == 0) { (GetInstance()->*view.func)(); } } } void TjdUiAppLefunAiPresenter::StartJumpTimer(LefunAiView jumpView) { if (jumpTimerId_ == nullptr) { jumpTimerId_ = osTimerNew( [](void *arg) { LefunAiView jumpView = static_cast(reinterpret_cast(arg)); GraphicService::GetInstance()->PostGraphicEvent([jumpView]() { TjdUiAppLefunAiView *view = TjdUiAppLefunAiView::GetInstance(); if (view == nullptr) { return; } view->ShowView(jumpView); TjdUiAppLefunAiPresenter::GetInstance()->DeleteJumpTimer(); }); }, osTimerOnce, reinterpret_cast(static_cast(jumpView)), nullptr); if (jumpTimerId_ == nullptr) { printf("TjdUiAppAlipayModel::AlipayStartBind Create timer fail."); return; } } int ret = 0; if (jumpView == LefunAiView::LEFUN_AI_VIEW_MAIN) ret = osTimerStart(jumpTimerId_, 2000); else if (jumpView == LefunAiView::LEFUN_AI_VIEW_TIME_OUT_VIEW) ret = osTimerStart(jumpTimerId_, 30000); if (ret != 0) { printf("TjdUiAppAlipayModel::AlipayStartBind Start timer fail"); return; } } void TjdUiAppLefunAiPresenter::DeleteJumpTimer() { if (jumpTimerId_ != nullptr) { osTimerDelete(jumpTimerId_); jumpTimerId_ = nullptr; } } void LefunAiInterruptListener::OnInterrupt(int32_t type, int32_t hint) { static_print_info("LefunAi CaptureInterruptListener OnInterrupt, type:%d, hint:%d", type, hint); if (type == INTERRUPT_TYPE_BEGIN && hint == INTERRUPT_HINT_PAUSE) { static_print_info("LefunAi OnInterrupt pause not supported"); } if (type == INTERRUPT_TYPE_END && hint == INTERRUPT_HINT_RESUME) { static_print_info("LefunAi OnInterrupt resume not supported"); } if (type == INTERRUPT_TYPE_BEGIN && hint == INTERRUPT_HINT_STOP) { } if (type == INTERRUPT_TYPE_END && hint == INTERRUPT_HINT_STOP) { static_print_info("LefunAi OnInterrupt stop not supported"); } } } // namespace TJD