From 3f91f1e302c2d7587dc314c13c38f6db57a24d89 Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Fri, 13 Sep 2024 10:45:19 +0800 Subject: [PATCH] =?utf8?q?#661=EF=BC=8C=E8=A7=A3=E5=86=B3,=E6=89=8B?= =?utf8?q?=E8=A1=A8=EF=BC=8C=E5=A4=A9=E6=B0=94=E5=A4=A9=E6=B0=94=E5=9B=BE?= =?utf8?q?=E6=A0=87=E6=98=BE=E7=A4=BA=E5=A4=9A=E4=BA=91=EF=BC=8C=E6=96=87?= =?utf8?q?=E5=AD=97=E6=98=BE=E7=A4=BA=E4=B8=AD=E9=9B=A8bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/weather/include/WeatherModel.h | 4 +- .../nativeui/weather/src/WeatherModel.cpp | 56 ++++++++++++++++--- 2 files changed, 51 insertions(+), 9 deletions(-) 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 2d9205247..daad9d70d 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-07-23 14:41:27 + * @LastEditTime: 2024-09-13 10:25:12 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherModel.h */ #ifndef WEATHER_MODEL_H @@ -111,6 +111,8 @@ namespace OHOS /* -------------------------------------------------------------------------- */ void UpdateMainWeatherData(void); void UpdateWeatherCurTime(void); + /* -------------------------------------------------------------------------- */ + bool IsNightTime(); private: WeatherModel(); WeatherModel(const WeatherModel &) = delete; 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 b4bb5648f..7a5412b0e 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherModel.cpp @@ -1,8 +1,8 @@ /* * @Author: luozheng 1732036298@qq.com * @Date: 2024-04-08 18:40:09 - * @LastEditors: penglei 1624952103@qq.com - * @LastEditTime: 2024-08-28 17:12:21 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-09-13 10:43:56 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherModel.cpp */ #include "weather/include/WeatherModel.h" @@ -10,6 +10,7 @@ #include "weather/include/WeatherControlView.h" #include "DialModelWeather.h" #include "DialModelWeatherStr.h" +#include "ConfigModel.h" namespace OHOS { #if __cplusplus @@ -152,11 +153,33 @@ namespace OHOS return weatherTime; } + //判断当前时间是否在晚上 + bool WeatherModel::IsNightTime() + { + struct tm pTM; + time_t seconds; + time(&seconds); + localtime_r(&seconds, &pTM); + + int hour = pTM.tm_hour; + + // 假设晚上是从 18 点到次日 6 点 + return hour >= 18 || hour < 6; + } + // 获取天气图片 std::string WeatherModel::GetWeatherImage() { // int index = Weather_data_t_now.iconNight;//夜晚天气图标 - int index = Weather_data_seven_data[0].iconDay; // 白天天气图标 + int index; + if (IsNightTime()) + { + index = Weather_data_t_now.iconNight; // 夜晚天气图标 + } + else + { + index = Weather_data_seven_data[0].iconDay; // 白天天气图标 + } return weather65x65[index]; } @@ -170,7 +193,15 @@ namespace OHOS // 获取天气描述 std::string WeatherModel::GetWeatherDescription() { - std::string WeatherDescription = Weather_data_t_now.textNight; + std::string WeatherDescription; + if (IsNightTime()) + { + WeatherDescription = Weather_data_t_now.textNight; + } + else + { + WeatherDescription = Weather_data_seven_data[0].textDay; + } return WeatherDescription; } @@ -187,7 +218,16 @@ namespace OHOS { int maxtemperature = Weather_data_seven_data[0].tempMax; int mintemperature = Weather_data_seven_data[0].tempMin; - std::string MaxandMinTemperature = "最高" + std::to_string(maxtemperature) + "°" + " " + "最低" + std::to_string(mintemperature) + "°"; + int language = ConfigModel::GetInstance()->GetLanguage(); + std::string MaxandMinTemperature; + if (language == 0) // 如果系统语言为中文 + { + MaxandMinTemperature = "最高" + std::to_string(maxtemperature) + "°" + " " + "最低" + std::to_string(mintemperature) + "°"; + } + else + { + MaxandMinTemperature = "Max" + std::to_string(maxtemperature) + "°" + " " + "Min" + std::to_string(mintemperature) + "°"; + } return MaxandMinTemperature; } /* -------------------------------------------------------------------------- */ @@ -303,13 +343,13 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "p_WeatherControlView"); p_WeatherControlView->UpdateWeatherControlViewVisibility(); } - if(DialModelWeather::GetInstance()){ - DialModelWeather::GetInstance()->UpdateWeather(Weather_data_seven_data[0].iconDay); //更新主界面天气图标 + if (DialModelWeather::GetInstance()) + { + DialModelWeather::GetInstance()->UpdateWeather(Weather_data_seven_data[0].iconDay); // 更新主界面天气图标 // const std::string str = GetWeatherTemperature() + " "+GetWeatherDescription(); const std::string str = GetWeatherTemperature(); DialModelWeatherStr::GetInstance()->UpdateWeatherStr(str); } - } /*更新天气界面的时间显示*/ -- 2.17.1