Skip to content

Commit

Permalink
Display message when no astronomy event is found
Browse files Browse the repository at this point in the history
  • Loading branch information
kylecorry31 committed Mar 19, 2023
1 parent 6533196 commit 392f281
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.core.view.isVisible
import androidx.navigation.fragment.findNavController
import com.kylecorry.andromeda.alerts.Alerts
import com.kylecorry.andromeda.alerts.loading.AlertLoadingIndicator
import com.kylecorry.andromeda.alerts.toast
import com.kylecorry.andromeda.core.capitalizeWords
import com.kylecorry.andromeda.core.time.Timer
import com.kylecorry.andromeda.fragments.BoundFragment
Expand Down Expand Up @@ -126,26 +127,30 @@ class AstronomyFragment : BoundFragment<ActivityAstronomyBinding>() {
if (prefs.astronomy.showSolarEclipses) AstronomyEvent.SolarEclipse else null,
AstronomyEvent.Supermoon
)

val optionNames = listOfNotNull(
getString(R.string.full_moon),
getString(R.string.new_moon),
getString(R.string.quarter_moon),
getString(R.string.meteor_shower),
getString(R.string.lunar_eclipse),
if (prefs.astronomy.showSolarEclipses) getString(R.string.solar_eclipse) else null,
getString(R.string.supermoon)
).map { it.capitalizeWords() }

Pickers.item(
requireContext(),
getString(R.string.find_next_occurrence),
listOfNotNull(
getString(R.string.full_moon),
getString(R.string.new_moon),
getString(R.string.quarter_moon),
getString(R.string.meteor_shower),
getString(R.string.lunar_eclipse),
if (prefs.astronomy.showSolarEclipses) getString(R.string.solar_eclipse) else null,
getString(R.string.supermoon)
).map { it.capitalizeWords() },
optionNames,
options.indexOf(lastAstronomyEventSearch)
) {
if (it != null) {
val search = options[it]
lastAstronomyEventSearch = search
val currentDate = binding.displayDate.date
runInBackground {
val loading = AlertLoadingIndicator(requireContext(), getString(R.string.loading))
val loading =
AlertLoadingIndicator(requireContext(), getString(R.string.loading))
loading.show()
val nextEvent = onDefault {
astronomyService.findNextEvent(
Expand All @@ -157,6 +162,16 @@ class AstronomyFragment : BoundFragment<ActivityAstronomyBinding>() {
onMain {
loading.hide()
binding.displayDate.date = nextEvent ?: currentDate

if (nextEvent == null) {
toast(
getString(
R.string.unable_to_find_next_astronomy,
optionNames[it].lowercase()
)
)
}

updateUI()
}
}
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,9 @@
<string name="pref_show_solar_eclipses" translatable="false">pref_show_solar_eclipses</string>
<string name="loading">Loading</string>

<!-- Unable to find the next astronomy event (ex. solar eclipse)-->
<string name="unable_to_find_next_astronomy">Unable to find next %s</string>

<plurals name="map_group_summary">
<item quantity="one">%d map</item>
<item quantity="other">%d maps</item>
Expand Down

0 comments on commit 392f281

Please sign in to comment.