#661,解决,手表,天气天气图标显示多云,文字显示中雨bug 962/1 962/head
authorluozheng <1732036298@qq.com>
Fri, 13 Sep 2024 02:45:19 +0000 (10:45 +0800)
committerluozheng <1732036298@qq.com>
Fri, 13 Sep 2024 02:45:19 +0000 (10:45 +0800)
code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherModel.h
code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherModel.cpp

index 2d92052..daad9d7 100644 (file)
@@ -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;
index b4bb564..7a5412b 100644 (file)
@@ -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);
         }
-
     }
 
     /*更新天气界面的时间显示*/