From: luozheng <1732036298@qq.com> Date: Tue, 23 Jul 2024 07:13:08 +0000 (+0800) Subject: 解决天气界面没有时间显示的bug,并优化时间刷新 X-Git-Tag: release_V1.2.70_20241020_135402~764 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=e60c6e388de0fc1d4c0d5103d816ea963acedca3;p=mirrors%2FFD230.git 解决天气界面没有时间显示的bug,并优化时间刷新 1.目前主界面天气刷新:如果在天气卡片,天气数据有效,就刷新时间 2.如果是Slice天气:滑到第一个界面,时间就会更新 --- 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); }