Skip to content

Commit

Permalink
Merge pull request #626 from forrestguice/fix623
Browse files Browse the repository at this point in the history
updateIllumination
  • Loading branch information
forrestguice authored Sep 25, 2022
2 parents ce2ec6d + 846ff8f commit ffdb7b9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import com.forrestguice.suntimeswidget.themes.SuntimesTheme;

import java.text.NumberFormat;
import java.util.Calendar;

@SuppressWarnings("Convert2Diamond")
public class MoonPhaseView extends LinearLayout
Expand Down Expand Up @@ -282,18 +283,23 @@ public void updateIllumination(Context context)
illumNote = (context == null ? illum : context.getString(R.string.moon_illumination, illum));

} else {
boolean sharedNoon = (data.getLunarNoonToday().getTimeInMillis() == data.getLunarNoonTomorrow().getTimeInMillis());
Calendar noonToday = data.getLunarNoonToday();
long noonTodayMillis = ((noonToday != null) ? noonToday.getTimeInMillis() : 0);
Calendar noonTomorrow = data.getLunarNoonTomorrow();
long noonTomorrowMillis = ((noonTomorrow != null) ? noonTomorrow.getTimeInMillis() : 0);
boolean sharedNoon = (noonTodayMillis == noonTomorrowMillis);

String illumTime;
if (tomorrowMode)
{
illum = formatter.format(data.getMoonIlluminationTomorrow());
illumTime = utils.calendarTimeShortDisplayString(context, data.getLunarNoonTomorrow()).toString();
illumTime = utils.calendarTimeShortDisplayString(context, noonTomorrow).toString();

} else {
illum = formatter.format(data.getMoonIlluminationToday());
illumTime = (sharedNoon)
? utils.calendarDateTimeDisplayString(context, data.getLunarNoonToday()).toString()
: utils.calendarTimeShortDisplayString(context, data.getLunarNoonToday()).toString();
? utils.calendarDateTimeDisplayString(context, noonToday).toString()
: utils.calendarTimeShortDisplayString(context, noonToday).toString();
}
illumNote = (context == null ? illum : context.getString(sharedNoon ? R.string.moon_illumination : R.string.moon_illumination_at, illum, illumTime));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
Copyright (C) 2018-2019 Forrest Guice
Copyright (C) 2018-2022 Forrest Guice
This file is part of SuntimesWidget.
SuntimesWidget is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -232,7 +232,7 @@ public void calculate()
riseSet[2] = calculator.getMoonTimesForDate(otherCalendar);

ArrayList<Calendar> midnights = findMidnight();
if (midnights.size() >= 1)
if (midnights.size() > 0)
{
midnightToday = midnights.get(midnights.size() - 1);
for (Calendar midnight : midnights)
Expand All @@ -254,7 +254,7 @@ public void calculate()
}

ArrayList<Calendar> noons = findNoon();
if (noons.size() >= 1)
if (noons.size() > 0)
{
noonToday = noons.get(noons.size() - 1);
for (Calendar noon : noons)
Expand All @@ -275,12 +275,12 @@ public void calculate()
//Log.d("DEBUG", "using approximate lunar noon tomorrow");
}

double moonIllumination = ((noonToday != null) ? calculator.getMoonIlluminationForDate(noonToday) : 0);
double moonIllumination = getMoonIllumination(noonToday, todaysCalendar);
if (moonIllumination >= 0) {
this.moonIlluminationToday = moonIllumination;
}

double moonIllumination1 = ((noonTomorrow != null) ? calculator.getMoonIlluminationForDate(noonTomorrow) : 0);
double moonIllumination1 = getMoonIllumination(noonTomorrow, otherCalendar);
if (moonIllumination1 >= 0) {
this.moonIlluminationTomorrow = moonIllumination1;
}
Expand All @@ -296,6 +296,21 @@ public void calculate()
moonPhaseTomorrow = findPhaseOf(midnight1);
}

private double getMoonIllumination(Calendar lunarNoon, Calendar today)
{
if (calculator != null)
{
if (lunarNoon != null) {
return calculator.getMoonIlluminationForDate(lunarNoon);
}
Calendar solarNoon = calculator.getSolarNoonCalendarForDate(today);
if (solarNoon != null) {
return calculator.getMoonIlluminationForDate(solarNoon);
}
}
return 0;
}

/**
* Create a list of lunar noon times by examining the moonrise/moonset times from yesterday, today, and tomorrow.
* @return an ArrayList of Calendar; contains up to 3 items (empty if not found).
Expand Down

0 comments on commit ffdb7b9

Please sign in to comment.