From 41f0be1bb20a17a09ba8d74adcb571cbfe56c3f3 Mon Sep 17 00:00:00 2001 From: woheller69 Date: Tue, 1 Oct 2024 12:54:02 +0200 Subject: [PATCH] V3.2 modify isDay() method to use currentTime instead of timeStamp from last update --- app/build.gradle | 4 +-- .../weather/database/CurrentWeatherData.java | 26 ++++++++++++++----- .../ui/RecycleList/CityWeatherAdapter.java | 7 +++-- .../metadata/android/en-US/changelogs/32.txt | 2 ++ 4 files changed, 26 insertions(+), 13 deletions(-) create mode 100644 fastlane/metadata/android/en-US/changelogs/32.txt diff --git a/app/build.gradle b/app/build.gradle index e10a384..5fd64fe 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,8 +8,8 @@ android { applicationId "org.woheller69.omweather" minSdkVersion 21 targetSdkVersion 34 - versionCode 31 - versionName "3.1" + versionCode 32 + versionName "3.2" buildConfigField "String", "BASE_URL", "\"https://api.open-meteo.com/v1/\"" buildConfigField "String", "GITHUB_URL","\"https://github.com/woheller69/omweather/\"" diff --git a/app/src/main/java/org/woheller69/weather/database/CurrentWeatherData.java b/app/src/main/java/org/woheller69/weather/database/CurrentWeatherData.java index dda1fc6..cdaf88c 100644 --- a/app/src/main/java/org/woheller69/weather/database/CurrentWeatherData.java +++ b/app/src/main/java/org/woheller69/weather/database/CurrentWeatherData.java @@ -114,18 +114,30 @@ public void setCloudiness(float cloudiness) { } public boolean isDay(Context context){ - Calendar timeStamp = Calendar.getInstance(); - timeStamp.setTimeZone(TimeZone.getTimeZone("GMT")); - timeStamp.setTimeInMillis((timestamp+timeZoneSeconds)*1000); + Calendar currentTime = Calendar.getInstance(); + currentTime.setTimeZone(TimeZone.getTimeZone("GMT")); + currentTime.setTimeInMillis(System.currentTimeMillis() + timeZoneSeconds* 1000L); SQLiteHelper dbHelper = SQLiteHelper.getInstance(context); if (timeSunrise==0 || timeSunset==0){ if ((dbHelper.getCityToWatch(city_id).getLatitude())>0){ //northern hemisphere - return timeStamp.get(Calendar.DAY_OF_YEAR) >= 80 && timeStamp.get(Calendar.DAY_OF_YEAR) <= 265; //from March 21 to September 22 (incl) + return currentTime.get(Calendar.DAY_OF_YEAR) >= 80 && currentTime.get(Calendar.DAY_OF_YEAR) <= 265; //from March 21 to September 22 (incl) }else{ //southern hemisphere - return timeStamp.get(Calendar.DAY_OF_YEAR) < 80 || timeStamp.get(Calendar.DAY_OF_YEAR) > 265; + return currentTime.get(Calendar.DAY_OF_YEAR) < 80 || currentTime.get(Calendar.DAY_OF_YEAR) > 265; } - }else { - return timestamp > timeSunrise && timestamp < timeSunset; + } else { + Calendar sunSetTime = Calendar.getInstance(); + sunSetTime.setTimeZone(TimeZone.getTimeZone("GMT")); + sunSetTime.setTimeInMillis(timeSunset * 1000 + timeZoneSeconds * 1000L); + sunSetTime.set(Calendar.DAY_OF_YEAR, currentTime.get(Calendar.DAY_OF_YEAR)); + sunSetTime.set(Calendar.YEAR, currentTime.get(Calendar.YEAR)); + + Calendar sunRiseTime = Calendar.getInstance(); + sunRiseTime.setTimeZone(TimeZone.getTimeZone("GMT")); + sunRiseTime.setTimeInMillis(timeSunrise * 1000 + timeZoneSeconds * 1000L); + sunRiseTime.set(Calendar.DAY_OF_YEAR, currentTime.get(Calendar.DAY_OF_YEAR)); + sunRiseTime.set(Calendar.YEAR, currentTime.get(Calendar.YEAR)); + + return currentTime.after(sunRiseTime) && currentTime.before(sunSetTime); } } diff --git a/app/src/main/java/org/woheller69/weather/ui/RecycleList/CityWeatherAdapter.java b/app/src/main/java/org/woheller69/weather/ui/RecycleList/CityWeatherAdapter.java index abfbce5..283abff 100644 --- a/app/src/main/java/org/woheller69/weather/ui/RecycleList/CityWeatherAdapter.java +++ b/app/src/main/java/org/woheller69/weather/ui/RecycleList/CityWeatherAdapter.java @@ -236,8 +236,7 @@ public void onBindViewHolder(ViewHolder viewHolder, final int position) { int zoneseconds = currentWeatherDataList.getTimeZoneSeconds(); long riseTime = (currentWeatherDataList.getTimeSunrise() + zoneseconds) * 1000; long setTime = (currentWeatherDataList.getTimeSunset() + zoneseconds) * 1000; - long time = currentWeatherDataList.getTimestamp(); - long updateTime = ((time + zoneseconds) * 1000); + long updateTime = ((currentWeatherDataList.getTimestamp() + zoneseconds) * 1000); holder.updatetime.setText("("+StringFormatUtils.formatTimeWithoutZone(context, updateTime)+")"); @@ -252,7 +251,7 @@ public void onBindViewHolder(ViewHolder viewHolder, final int position) { } } if (nowCast!=null) { - if (riseTime==zoneseconds*1000 || setTime==zoneseconds*1000) holder.sun.setText("\u2600\u25b2 --:--" + " \u25bc --:--" ); + if (riseTime == zoneseconds * 1000L || setTime == zoneseconds * 1000L) holder.sun.setText("\u2600\u25b2 --:--" + " \u25bc --:--" ); else { holder.sun.setText("\u2600\u25b2 " + StringFormatUtils.formatTimeWithoutZone(context, riseTime) + " \u25bc " + StringFormatUtils.formatTimeWithoutZone(context, setTime)); } @@ -274,7 +273,7 @@ public void onBindViewHolder(ViewHolder viewHolder, final int position) { holder.precipforecast.setVisibility(View.INVISIBLE); if (next != null){ - if (riseTime==zoneseconds*1000 || setTime==zoneseconds*1000) holder.sun.setText("\u2600\u25b2 --:--" + " \u25bc --:--" ); + if (riseTime==zoneseconds * 1000L || setTime==zoneseconds * 1000L) holder.sun.setText("\u2600\u25b2 --:--" + " \u25bc --:--" ); else { holder.sun.setText("\u2600\u25b2 " + StringFormatUtils.formatTimeWithoutZone(context, riseTime) + " \u25bc " + StringFormatUtils.formatTimeWithoutZone(context, setTime)); } diff --git a/fastlane/metadata/android/en-US/changelogs/32.txt b/fastlane/metadata/android/en-US/changelogs/32.txt new file mode 100644 index 0000000..8261d30 --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/32.txt @@ -0,0 +1,2 @@ +New all-in-one widget +Minor bugfix \ No newline at end of file