Skip to content

Commit

Permalink
V3.2
Browse files Browse the repository at this point in the history
modify isDay() method to use currentTime instead of timeStamp from last update
  • Loading branch information
woheller69 committed Oct 1, 2024
1 parent 1e5a98d commit 41f0be1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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/\""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)+")");

Expand All @@ -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));
}
Expand All @@ -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));
}
Expand Down
2 changes: 2 additions & 0 deletions fastlane/metadata/android/en-US/changelogs/32.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
New all-in-one widget
Minor bugfix

0 comments on commit 41f0be1

Please sign in to comment.