From 1932a82322df80e03cd4d448c90aa9677e81a821 Mon Sep 17 00:00:00 2001 From: Kyle Corry Date: Sat, 18 Nov 2023 07:57:10 -0500 Subject: [PATCH] Add north reference description Closes #1347 --- .../navigation/ui/NavigatorFragment.kt | 1 + .../shared/views/NorthReferenceBadge.kt | 34 +++++++++++++++++++ app/src/main/res/values/strings.xml | 2 ++ 3 files changed, 37 insertions(+) diff --git a/app/src/main/java/com/kylecorry/trail_sense/navigation/ui/NavigatorFragment.kt b/app/src/main/java/com/kylecorry/trail_sense/navigation/ui/NavigatorFragment.kt index fa55a67f1..ec97a5102 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/navigation/ui/NavigatorFragment.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/navigation/ui/NavigatorFragment.kt @@ -509,6 +509,7 @@ class NavigatorFragment : BoundFragment() { // Update the UI updateNavigator() + binding.northReferenceIndicator.showDetailsOnClick = true binding.northReferenceIndicator.useTrueNorth = useTrueNorth binding.northReferenceIndicator.showLabel = true northReferenceHideTimer.once(Duration.ofSeconds(5)) diff --git a/app/src/main/java/com/kylecorry/trail_sense/shared/views/NorthReferenceBadge.kt b/app/src/main/java/com/kylecorry/trail_sense/shared/views/NorthReferenceBadge.kt index 799b3660f..46705f07d 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/shared/views/NorthReferenceBadge.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/shared/views/NorthReferenceBadge.kt @@ -4,6 +4,8 @@ import android.content.Context import android.graphics.Color import android.util.AttributeSet import android.widget.FrameLayout +import androidx.navigation.findNavController +import com.kylecorry.andromeda.alerts.Alerts import com.kylecorry.andromeda.core.system.Resources import com.kylecorry.ceres.badge.CeresBadge import com.kylecorry.trail_sense.R @@ -29,6 +31,18 @@ class NorthReferenceBadge( updateBadge() } + var showDetailsOnClick: Boolean = false + set(value) { + field = value + if (value){ + badge.setOnClickListener { + showDescription() + } + } else { + badge.setOnClickListener(null) + } + } + init { badge.layoutParams = LayoutParams( LayoutParams.WRAP_CONTENT, @@ -50,4 +64,24 @@ class NorthReferenceBadge( badge.setStatusText(text) } + private fun showDescription(){ + val title = if (useTrueNorth){ + context.getString(R.string.true_north) + } else { + context.getString(R.string.magnetic_north) + } + + val message = if (useTrueNorth){ + context.getString(R.string.true_north_description) + } else { + context.getString(R.string.magnetic_north_description) + } + + Alerts.dialog(context, title, message, okText = context.getString(R.string.settings)){ cancelled -> + if (!cancelled){ + findNavController().navigate(R.id.calibrateCompassFragment) + } + } + } + } \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9f6768a81..e70fba718 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1373,6 +1373,8 @@ No, unfortunately this is a hardware feature, so there is nothing that can be done to add it. My device is new/expensive, why is it missing this sensor? Some phone manufacturers choose not to add this sensor, even on new or expensive devices. You can get more information by visiting your device manufacturer\’s website or getting in touch with them. + Points to the geographic North Pole using the declination for your location. This will align with most maps. + Points to the magnetic North Pole. This will align with most compasses. %d map %d maps