Skip to content

Commit

Permalink
Show time of sun / moon in AR view
Browse files Browse the repository at this point in the history
  • Loading branch information
kylecorry31 committed Nov 2, 2023
1 parent 9fee153 commit a0e0f6a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ class MeteorShowerAlertCommand(private val context: Context) : Command<Coordinat
private fun getShowerDescription(context: Context, shower: MeteorShowerPeak): String {
val formatService = FormatService.getInstance(context)

val peak =
formatService.formatRelativeDate(shower.peak.toLocalDate()) + " " + formatService.formatTime(
shower.peak.toLocalTime(),
false
)
val peak = formatService.formatRelativeDateTime(shower.peak, includeSeconds = false)

val rate = context.getString(R.string.meteors_per_hour, shower.shower.rate)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,34 @@ class FormatService private constructor(private val context: Context) {
}
}

fun formatRelativeDateTime(
time: ZonedDateTime,
abbreviateMonth: Boolean = false,
includeSeconds: Boolean = true,
includeMinutes: Boolean = true
): String {
return formatRelativeDate(
time.toLocalDate(),
abbreviateMonth
) + " " + formatTime(time.toLocalTime(), includeSeconds, includeMinutes)
}

fun formatRelativeDate(date: LocalDate, abbreviateMonth: Boolean = false): String {
val now = LocalDate.now()

return when (date) {
now -> {
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,
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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(" ", "")
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class AugmentedRealityFragment : BoundFragment<FragmentAugmentedRealityBinding>(
}
}

private fun stopCamera(){
private fun stopCamera() {
binding.cameraToggle.setImageResource(R.drawable.ic_camera_off)
isCameraEnabled = false
binding.arView.backgroundFillColor = Color.BLACK
Expand Down Expand Up @@ -206,7 +206,15 @@ class AugmentedRealityFragment : BoundFragment<FragmentAugmentedRealityBinding>(
true
),
1f,
obj
obj,
onFocusedFn = {
binding.arView.focusText =
getString(R.string.moon) + "\n" + formatter.formatRelativeDateTime(
it,
includeSeconds = false
)
true
}
)
}.map { it.value }

Expand All @@ -226,7 +234,15 @@ class AugmentedRealityFragment : BoundFragment<FragmentAugmentedRealityBinding>(
true
),
1f,
obj
obj,
onFocusedFn = {
binding.arView.focusText =
getString(R.string.sun) + "\n" + formatter.formatRelativeDateTime(
it,
includeSeconds = false
)
true
}
)
}.map { it.value }

Expand All @@ -243,8 +259,10 @@ class AugmentedRealityFragment : BoundFragment<FragmentAugmentedRealityBinding>(
true
),
2f,
// TODO: Use moon icon
CircleCanvasObject(Color.WHITE),
onFocusedFn = {
// TODO: Display moon phase
binding.arView.focusText = getString(R.string.moon)
true
}
Expand All @@ -264,6 +282,8 @@ class AugmentedRealityFragment : BoundFragment<FragmentAugmentedRealityBinding>(
}
)

// 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)
}
Expand Down

0 comments on commit a0e0f6a

Please sign in to comment.