-
-
Save iamriajul/2cdbc15d4fd0e8bad203205c9302a54b to your computer and use it in GitHub Desktop.
getPrayerStatus() returns running & next prayer.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun getPrayerStatus(timeTable: PrayerTimeTable): PrayerStatus? { | |
val running = timeTable.times.firstOrNull { it.isRunning } | |
val next = timeTable.findClosestFutureByStart() | |
return if (running != null && next != null) { | |
PrayerStatus( | |
timeTable.date, | |
running, | |
next | |
) | |
} else if (running == null && next != null) { | |
// The Next Prayer is The First Prayer of The Day. Most Probably Tahajjud. | |
val prayerTimeTableForLastDay = prayerTimeTableService.get( | |
timeTable.latLng, | |
timeTable.date.minusDays(1), | |
timeTable.method, | |
timeTable.timeAdjustments, | |
timeTable.madhab, | |
timeTable.highLatitudeRule | |
) | |
val runningPrayerForLastDay = | |
prayerTimeTableForLastDay.times.firstOrNull { it.isRunning } | |
if (runningPrayerForLastDay != null) { | |
PrayerStatus( | |
timeTable.date, | |
runningPrayerForLastDay, | |
next | |
) | |
} else { | |
null | |
} | |
} else if (next == null && running != null) { | |
// The Running Prayer Is Last Prayer of The Day. Most Probably Isha. | |
val prayerTimeTableForNextDay = prayerTimeTableService.get( | |
timeTable.latLng, | |
timeTable.date.plusDays(1), | |
timeTable.method, | |
timeTable.timeAdjustments, | |
timeTable.madhab, | |
timeTable.highLatitudeRule | |
) | |
val firstPrayerForNextDay = prayerTimeTableForNextDay.findClosestFutureByStart() | |
if (firstPrayerForNextDay != null) { | |
PrayerStatus( | |
timeTable.date, | |
running, | |
firstPrayerForNextDay | |
) | |
} else { | |
null | |
} | |
} else { | |
null | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment