From e60c6e388de0fc1d4c0d5103d816ea963acedca3 Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Tue, 23 Jul 2024 15:13:08 +0800 Subject: [PATCH] =?utf8?q?=E8=A7=A3=E5=86=B3=E5=A4=A9=E6=B0=94=E7=95=8C?= =?utf8?q?=E9=9D=A2=E6=B2=A1=E6=9C=89=E6=97=B6=E9=97=B4=E6=98=BE=E7=A4=BA?= =?utf8?q?=E7=9A=84bug=EF=BC=8C=E5=B9=B6=E4=BC=98=E5=8C=96=E6=97=B6?= =?utf8?q?=E9=97=B4=E5=88=B7=E6=96=B0=201.=E7=9B=AE=E5=89=8D=E4=B8=BB?= =?utf8?q?=E7=95=8C=E9=9D=A2=E5=A4=A9=E6=B0=94=E5=88=B7=E6=96=B0=EF=BC=9A?= =?utf8?q?=E5=A6=82=E6=9E=9C=E5=9C=A8=E5=A4=A9=E6=B0=94=E5=8D=A1=E7=89=87?= =?utf8?q?=EF=BC=8C=E5=A4=A9=E6=B0=94=E6=95=B0=E6=8D=AE=E6=9C=89=E6=95=88?= =?utf8?q?=EF=BC=8C=E5=B0=B1=E5=88=B7=E6=96=B0=E6=97=B6=E9=97=B4=202.?= =?utf8?q?=E5=A6=82=E6=9E=9C=E6=98=AFSlice=E5=A4=A9=E6=B0=94=EF=BC=9A?= =?utf8?q?=E6=BB=91=E5=88=B0=E7=AC=AC=E4=B8=80=E4=B8=AA=E7=95=8C=E9=9D=A2?= =?utf8?q?=EF=BC=8C=E6=97=B6=E9=97=B4=E5=B0=B1=E4=BC=9A=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/main/src/MainPresenterSample.cpp | 6 ++++ .../nativeui/weather/include/WeatherModel.h | 4 ++- .../nativeui/weather/include/WeatherView.h | 4 +-- .../weather/src/MainWeatherPresenter.cpp | 4 +-- .../nativeui/weather/src/WeatherModel.cpp | 31 +++++++++++++++++-- .../nativeui/weather/src/WeatherView.cpp | 15 +++------ 6 files changed, 46 insertions(+), 18 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/src/MainPresenterSample.cpp b/code/sdk/application/wearable/fd230app/nativeui/main/src/MainPresenterSample.cpp index 8cb7d95ef..6698e3683 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/src/MainPresenterSample.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/main/src/MainPresenterSample.cpp @@ -29,6 +29,7 @@ #include "custom_utils.h" #include "traing/training_card/include/Training_CardView.h" #include "dnotdisturb/include/DnotDisturbModel.h" +#include "weather/include/WeatherModel.h" #if USE_OFFLINE_DIAL #include "DialViewGroup.h" #endif @@ -392,6 +393,11 @@ namespace OHOS } } break; + case WEATHER: + if(WeatherModel::GetInstance().GetWeatherDataIsValid()) { + WeatherModel::GetInstance().UpdateWeatherCurTime(); + } + break; } } diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherModel.h b/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherModel.h index 669210b24..2d9205247 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherModel.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-04-08 18:40:20 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-06-19 10:24:03 + * @LastEditTime: 2024-07-23 14:41:27 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherModel.h */ #ifndef WEATHER_MODEL_H @@ -88,6 +88,7 @@ namespace OHOS static WeatherModel &GetInstance(void); void InitFutureWeatherItem(); void TimestampToMonthDayString(time_t timestamp, char *buffer); + std::string GetWeatherCurTime(); std::string GetWeatherImage(); std::string GetWeatherTemperature(); std::string GetWeatherDescription(); @@ -109,6 +110,7 @@ namespace OHOS void SetWeatherDataIsValid(bool value); /* -------------------------------------------------------------------------- */ void UpdateMainWeatherData(void); + void UpdateWeatherCurTime(void); private: WeatherModel(); WeatherModel(const WeatherModel &) = delete; diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherView.h b/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherView.h index 3c93ddf58..618c91589 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherView.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-03-30 09:14:38 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-06-15 16:31:50 + * @LastEditTime: 2024-07-23 14:51:03 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherView.h */ #ifndef WEATHER_VIEW_H @@ -35,6 +35,7 @@ namespace OHOS virtual bool InitView(void *caller) override; void ClearAll(); bool UpdateWeatherViewData(void); + bool UpdateWeatherTime(void); private: UILabelExt *InitLabelExt(int x, int y, int w, int h, const char *text, int textfont, int lineheight); @@ -45,7 +46,6 @@ namespace OHOS void DumpWeatherInfo(); bool SetImageSource(UIImageView *image, const std::string &source); bool SetTextLabel(UILabel *label, const std::string &text); - bool UpdateWeatherTime(void); bool UpdateWeatherImag(void); bool UpdateWeatherTemperature(void); bool UpdateWeatherWeatherDescription(void); diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/src/MainWeatherPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/weather/src/MainWeatherPresenter.cpp index daaba8b2c..edeae73b5 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/src/MainWeatherPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/src/MainWeatherPresenter.cpp @@ -101,9 +101,9 @@ namespace OHOS { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainWeatherPresenter::OnSwipe,current tab index = %d", view.GetCurrentPage()); // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "the view index = %d,dragging direction = %d,current tab index = %d", view.GetViewIndex(), view.GetDirection(), view.GetCurrentPage()); - if (view.GetCurrentPage() == WEATHERREPORTVIEW) + if (view.GetCurrentPage() == MAINWEATHERVIEW) { - //MainWeatherView::GetInstance()->GetFutureWeatherView()->GetFutureWeatherList()->RefreshList(); + WeatherModel::GetInstance().UpdateWeatherCurTime(); } } diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherModel.cpp index 7002393f8..eb23d0194 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherModel.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-04-08 18:40:09 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-06-19 10:24:12 + * @LastEditTime: 2024-07-23 14:54:46 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherModel.cpp */ #include "weather/include/WeatherModel.h" @@ -135,6 +135,22 @@ namespace OHOS sprintf(buffer, "%02d.%02d", timeinfo.tm_mon + 1, timeinfo.tm_mday); } + /*获取天气界面的当前时间*/ + std::string WeatherModel::GetWeatherCurTime() + { + struct tm pTM; + time_t seconds; + time(&seconds); + localtime_r(&seconds, &pTM); + + int hour = pTM.tm_hour; + int minute = pTM.tm_min; + + std::string weatherTime = (hour < 10 ? "0" : "") + std::to_string(hour) + ":" + (minute < 10 ? "0" : "") + std::to_string(minute); + + return weatherTime; + } + // 获取天气图片 std::string WeatherModel::GetWeatherImage() { @@ -267,7 +283,7 @@ namespace OHOS /* 更新所有天气数据 */ void WeatherModel::UpdateMainWeatherData(void) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UpdateMainWeatherData"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "UpdateMainWeatherData"); MainWeatherView *p_MainWeatherView = MainWeatherView::GetInstance(); if (p_MainWeatherView != nullptr) @@ -287,4 +303,15 @@ namespace OHOS p_WeatherControlView->UpdateWeatherControlViewVisibility(); } } + + /*更新天气界面的时间显示*/ + void WeatherModel::UpdateWeatherCurTime(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "UpdateWeatherCurTime"); + MainWeatherView *p_MainWeatherView = MainWeatherView::GetInstance(); + if (p_MainWeatherView != nullptr) + { + p_MainWeatherView->GetWeatherView()->UpdateWeatherTime(); + } + } } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherView.cpp b/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherView.cpp index 7e79b1afb..d4c105770 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherView.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-06-12 11:44:04 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-06-19 10:51:02 + * @LastEditTime: 2024-07-23 14:44:07 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherView.cpp */ #include "weather/include/WeatherView.h" @@ -87,6 +87,7 @@ namespace OHOS SetViewIndex(0); // 视图索引 WeatherModel *p_WeatherModel = &WeatherModel::GetInstance(); + WeatherTime = p_WeatherModel->GetWeatherCurTime(); WeatherImag = p_WeatherModel->GetWeatherImage(); Temperature = p_WeatherModel->GetWeatherTemperature(); WeatherDescription = p_WeatherModel->GetWeatherDescription(); @@ -200,7 +201,7 @@ namespace OHOS showWeatherImage->SetResizeMode(UIImageView::CONTAIN); showWeatherImage->SetSrc(WeatherImag.c_str()); /* -------------------------------------------------------------------------- */ - showCurrentTimeLabel = InitLabelExt(CURRENT_TIME_LABEL_X, CURRENT_TIME_LABEL_Y, CURRENT_TIME_LABEL_W, CURRENT_TIME_LABEL_H, "", + showCurrentTimeLabel = InitLabelExt(CURRENT_TIME_LABEL_X, CURRENT_TIME_LABEL_Y, CURRENT_TIME_LABEL_W, CURRENT_TIME_LABEL_H, WeatherTime.c_str(), CURRENT_TIME_LABEL_TEXT_FONT, CURRENT_TIME_LABEL_LINE_HEIGHT); if (showCurrentTimeLabel == nullptr) { @@ -362,15 +363,7 @@ namespace OHOS { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherView::UpdateWeatherTime"); - struct tm pTM; - time_t seconds; - time(&seconds); - localtime_r(&seconds, &pTM); - - int hour = pTM.tm_hour; - int minute = pTM.tm_min; - - std::string weatherTime = (hour < 10 ? "0" : "") + std::to_string(hour) + ":" + (minute < 10 ? "0" : "") + std::to_string(minute); + std::string weatherTime = WeatherModel::GetInstance().GetWeatherCurTime(); return SetTextLabel(showCurrentTimeLabel, weatherTime); } -- 2.17.1