Skip to content

Commit

Permalink
Show moon phase in AR
Browse files Browse the repository at this point in the history
  • Loading branch information
kylecorry31 committed Dec 29, 2023
1 parent 0e2d827 commit ac1323a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import com.kylecorry.andromeda.canvas.ICanvasDrawer
import com.kylecorry.andromeda.core.ui.Colors.withAlpha
import com.kylecorry.andromeda.core.units.PixelCoordinate
import com.kylecorry.luna.coroutines.CoroutineQueueRunner
import com.kylecorry.sol.science.astronomy.Astronomy
import com.kylecorry.sol.science.astronomy.moon.MoonPhase
import com.kylecorry.sol.time.Time
import com.kylecorry.sol.units.Coordinate
import com.kylecorry.trail_sense.astronomy.domain.AstronomyService
Expand All @@ -22,7 +24,7 @@ class ARAstronomyLayer(
private val drawLines: Boolean,
private val drawBelowHorizon: Boolean,
private val onSunFocus: (time: ZonedDateTime) -> Boolean,
private val onMoonFocus: (time: ZonedDateTime) -> Boolean
private val onMoonFocus: (time: ZonedDateTime, phase: MoonPhase) -> Boolean
) : ARLayer {

private val scope = CoroutineScope(Dispatchers.Default)
Expand Down Expand Up @@ -152,6 +154,8 @@ class ARAstronomyLayer(
moonAfterPathObject
}

val phase = Astronomy.getMoonPhase(it)

ARMarker(
SphericalARPoint(
astro.getMoonAzimuth(location, it).value,
Expand All @@ -161,7 +165,7 @@ class ARAstronomyLayer(
),
canvasObject = obj,
onFocusedFn = {
onMoonFocus(it)
onMoonFocus(it, phase)
}
)
}.map { it.value }
Expand Down Expand Up @@ -198,7 +202,7 @@ class ARAstronomyLayer(
val sunAltitude = astro.getSunAltitude(location)
val sunAzimuth = astro.getSunAzimuth(location).value

val phase = astro.getMoonPhase(time.toLocalDate())
val phase = Astronomy.getMoonPhase(time)
val moonIconId = MoonPhaseImageMapper().getPhaseImage(phase.phase)
val moonImageSize = drawer.dp(24f).toInt()
val moonBitmap = bitmapLoader?.load(moonIconId, moonImageSize)
Expand All @@ -213,7 +217,7 @@ class ARAstronomyLayer(
canvasObject = moonBitmap?.let { CanvasBitmap(moonBitmap) }
?: CanvasCircle(Color.WHITE),
onFocusedFn = {
onMoonFocus(time)
onMoonFocus(time, phase)
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import com.kylecorry.andromeda.core.system.Resources
import com.kylecorry.andromeda.core.ui.Colors.withAlpha
import com.kylecorry.andromeda.fragments.BoundFragment
import com.kylecorry.andromeda.fragments.observeFlow
import com.kylecorry.sol.science.astronomy.Astronomy
import com.kylecorry.sol.science.astronomy.moon.MoonPhase
import com.kylecorry.sol.units.Distance
import com.kylecorry.trail_sense.R
import com.kylecorry.trail_sense.databinding.FragmentAugmentedRealityBinding
Expand Down Expand Up @@ -169,12 +171,14 @@ class AugmentedRealityFragment : BoundFragment<FragmentAugmentedRealityBinding>(
return true
}

private fun onMoonFocused(time: ZonedDateTime): Boolean {
private fun onMoonFocused(time: ZonedDateTime, phase: MoonPhase): Boolean {
binding.arView.focusText =
getString(R.string.moon) + "\n" + formatter.formatRelativeDateTime(
time,
includeSeconds = false
)
) + "\n${formatter.formatMoonPhase(phase.phase)} (${formatter.formatPercentage(
phase.illumination
)})"
return true
}

Expand Down

0 comments on commit ac1323a

Please sign in to comment.