Skip to content

Commit

Permalink
MoonPhaseView
Browse files Browse the repository at this point in the history
fixes bug where moon dialog displays the wrong phase label for a given date/time (#843)
  • Loading branch information
forrestguice committed Nov 20, 2024
1 parent 7a9424a commit 2c02773
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,18 @@ protected MoonPhaseDisplay findPhaseOf(Calendar calendar, boolean updateNext)
return (nextPhaseIsToday ? toPhase(nextPhase) : prevMinorPhase(nextPhase));
}

public static MoonPhaseDisplay findCurrentPhaseOf(Calendar calendar, SuntimesMoonData data)
{
SuntimesMoonData data1 = new SuntimesMoonData(data);
data1.setTodayIs(calendar);
data1.calculate();

SuntimesCalculator.MoonPhase nextPhase = data1.nextPhase(calendar);
Calendar nextPhaseDate = data1.moonPhases.get(nextPhase);
boolean nextPhaseIsNow = (nextPhaseDate != null) && (Math.abs(nextPhaseDate.getTimeInMillis() - calendar.getTimeInMillis()) <= (2000 * 60));
return (nextPhaseIsNow ? toPhase(nextPhase) : prevMinorPhase(nextPhase));
}

public CharSequence getMoonPhaseLabel(Context context, SuntimesCalculator.MoonPhase majorPhase) {
return getMoonPhaseLabel(context, majorPhase, moonPhaseCalendar(majorPhase));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,9 @@ public void updateViews(Context context, SuntimesMoonData data, @Nullable Calend
themeIcons(context, themeOverride);
hideIcons();

MoonPhaseDisplay phase = (tomorrowMode ? data.getMoonPhaseTomorrow() : data.getMoonPhaseToday());
MoonPhaseDisplay phase = (dateTime != null) ? SuntimesMoonData.findCurrentPhaseOf(dateTime, data)
: (tomorrowMode ? data.getMoonPhaseTomorrow() : data.getMoonPhaseToday());

if (phase != null)
{
if (phase == MoonPhaseDisplay.FULL || phase == MoonPhaseDisplay.NEW) {
Expand Down

0 comments on commit 2c02773

Please sign in to comment.