From a0e0f6a30e9beebe657ab02d425949bcf9ce8a45 Mon Sep 17 00:00:00 2001 From: Kyle Corry Date: Wed, 1 Nov 2023 20:01:45 -0400 Subject: [PATCH] Show time of sun / moon in AR view --- .../commands/MeteorShowerAlertCommand.kt | 6 +---- .../trail_sense/shared/FormatService.kt | 24 ++++++++++++++++- .../AugmentedRealityFragment.kt | 26 ++++++++++++++++--- 3 files changed, 47 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/kylecorry/trail_sense/astronomy/infrastructure/commands/MeteorShowerAlertCommand.kt b/app/src/main/java/com/kylecorry/trail_sense/astronomy/infrastructure/commands/MeteorShowerAlertCommand.kt index ec043e479..e1a6b0945 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/astronomy/infrastructure/commands/MeteorShowerAlertCommand.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/astronomy/infrastructure/commands/MeteorShowerAlertCommand.kt @@ -57,11 +57,7 @@ class MeteorShowerAlertCommand(private val context: Context) : Command { strings.getString(R.string.today) } + now.plusDays(1) -> { strings.getString(R.string.tomorrow) } + now.minusDays(1) -> { strings.getString(R.string.yesterday) } + else -> { DateUtils.formatDateTime( context, @@ -252,17 +267,20 @@ class FormatService private constructor(private val context: Context) { R.string.precise_kilometers_format, formatted ) + DistanceUnits.Feet -> strings.getString(R.string.precise_feet_format, formatted) DistanceUnits.Miles -> strings.getString(R.string.precise_miles_format, formatted) DistanceUnits.NauticalMiles -> strings.getString( R.string.precise_nautical_miles_format, formatted ) + DistanceUnits.Inches -> strings.getString(R.string.precise_inches_format, formatted) DistanceUnits.Centimeters -> strings.getString( R.string.precise_centimeters_format, formatted ) + DistanceUnits.Yards -> strings.getString(R.string.yards_format, formatted) } } @@ -300,6 +318,7 @@ class FormatService private constructor(private val context: Context) { R.string.ounces_volume_format, formatted ) + VolumeUnits.ImperialGallons -> strings.getString(R.string.gallon_format, formatted) } } @@ -583,16 +602,19 @@ class FormatService private constructor(private val context: Context) { R.string.precise_kilometers_format, "" ) + DistanceUnits.Feet -> strings.getString(R.string.precise_feet_format, "") DistanceUnits.Miles -> strings.getString(R.string.precise_miles_format, "") DistanceUnits.NauticalMiles -> strings.getString( R.string.precise_nautical_miles_format, "" ) + DistanceUnits.Centimeters -> strings.getString( R.string.precise_centimeters_format, "" ) + DistanceUnits.Inches -> strings.getString(R.string.precise_inches_format, "") DistanceUnits.Yards -> strings.getString(R.string.yards_format, "") }.replace(" ", "") @@ -682,7 +704,7 @@ class FormatService private constructor(private val context: Context) { MapProjectionType.CylindricalEquidistant -> strings.getString(R.string.map_projection_equidistant) } } - + fun formatBooleanYesNo(value: Boolean): String { return if (value) context.getString(R.string.yes) else context.getString(R.string.no) } diff --git a/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/AugmentedRealityFragment.kt b/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/AugmentedRealityFragment.kt index a5d69852e..3d74fc8cb 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/AugmentedRealityFragment.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/AugmentedRealityFragment.kt @@ -122,7 +122,7 @@ class AugmentedRealityFragment : BoundFragment( } } - private fun stopCamera(){ + private fun stopCamera() { binding.cameraToggle.setImageResource(R.drawable.ic_camera_off) isCameraEnabled = false binding.arView.backgroundFillColor = Color.BLACK @@ -206,7 +206,15 @@ class AugmentedRealityFragment : BoundFragment( true ), 1f, - obj + obj, + onFocusedFn = { + binding.arView.focusText = + getString(R.string.moon) + "\n" + formatter.formatRelativeDateTime( + it, + includeSeconds = false + ) + true + } ) }.map { it.value } @@ -226,7 +234,15 @@ class AugmentedRealityFragment : BoundFragment( true ), 1f, - obj + obj, + onFocusedFn = { + binding.arView.focusText = + getString(R.string.sun) + "\n" + formatter.formatRelativeDateTime( + it, + includeSeconds = false + ) + true + } ) }.map { it.value } @@ -243,8 +259,10 @@ class AugmentedRealityFragment : BoundFragment( true ), 2f, + // TODO: Use moon icon CircleCanvasObject(Color.WHITE), onFocusedFn = { + // TODO: Display moon phase binding.arView.focusText = getString(R.string.moon) true } @@ -264,6 +282,8 @@ class AugmentedRealityFragment : BoundFragment( } ) + // TODO: Move current sun / moon to a new layer so they can be focused on separately + // TODO: If two markers overlap, show the one that is in front sunLayer.setMarkers(sunPositions + sun) moonLayer.setMarkers(moonPositions + moon) }