Skip to content

Commit

Permalink
Show icon for north reference on navigator fragment
Browse files Browse the repository at this point in the history
  • Loading branch information
kylecorry31 committed Nov 7, 2023
1 parent 8dd2e11 commit 9e5957a
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import com.kylecorry.andromeda.core.coroutines.onIO
import com.kylecorry.andromeda.core.system.GeoUri
import com.kylecorry.andromeda.core.system.Resources
import com.kylecorry.andromeda.core.system.Screen
import com.kylecorry.andromeda.core.time.CoroutineTimer
import com.kylecorry.andromeda.core.tryOrNothing
import com.kylecorry.andromeda.core.ui.Colors.withAlpha
import com.kylecorry.andromeda.core.ui.setCompoundDrawables
import com.kylecorry.andromeda.fragments.BoundFragment
import com.kylecorry.andromeda.fragments.inBackground
import com.kylecorry.andromeda.fragments.interval
Expand Down Expand Up @@ -174,6 +177,12 @@ class NavigatorFragment : BoundFragment<ActivityNavigatorBinding>() {
private val styleChooser by lazy { CompassStyleChooser(userPrefs.navigation, hasCompass) }
private val useTrueNorth by lazy { userPrefs.compass.useTrueNorth }

private val northReferenceHideTimer = CoroutineTimer {
if (isBound){
binding.northReferenceIndicator.setStatusText(null)
}
}

override fun onDestroyView() {
super.onDestroyView()
sightingCompass = null
Expand Down Expand Up @@ -499,6 +508,17 @@ class NavigatorFragment : BoundFragment<ActivityNavigatorBinding>() {

// Update the UI
updateNavigator()

binding.northReferenceIndicator.setImageResource(formatService.getCompassReferenceIcon(useTrueNorth))
binding.northReferenceIndicator.setBackgroundTint(Color.TRANSPARENT)
binding.northReferenceIndicator.setForegroundTint(Resources.androidTextColorSecondary(requireContext()))
binding.northReferenceIndicator.setStatusText(if (useTrueNorth){
getString(R.string.true_north)
} else {
getString(R.string.magnetic_north)
})

northReferenceHideTimer.once(Duration.ofSeconds(5))
}

override fun onPause() {
Expand All @@ -508,6 +528,7 @@ class NavigatorFragment : BoundFragment<ActivityNavigatorBinding>() {
errors.reset()
layerManager?.stop()
layerManager = null
northReferenceHideTimer.stop()
}

private fun updateNearbyBeacons() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,15 @@ class FormatService private constructor(private val context: Context) {
return if (value) context.getString(R.string.yes) else context.getString(R.string.no)
}

@DrawableRes
fun getCompassReferenceIcon(isTrueNorth: Boolean = prefs.compass.useTrueNorth): Int {
return if (isTrueNorth) {
R.drawable.ic_star
} else {
R.drawable.ic_tool_metal_detector
}
}

companion object {
@SuppressLint("StaticFieldLeak")
private var instance: FormatService? = null
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_star.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!-- drawable/star.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#ffffff"
android:pathData="M12,17.27L18.18,21L16.54,13.97L22,9.24L14.81,8.62L12,2L9.19,8.62L2,9.24L7.45,13.97L5.82,21L12,17.27Z" />
</vector>
11 changes: 11 additions & 0 deletions app/src/main/res/layout/activity_navigator.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,17 @@
app:layout_constraintTop_toBottomOf="@id/linear_compass"
app:srcCompat="@drawable/ic_camera" />

<com.kylecorry.ceres.badge.CeresBadge
android:id="@+id/north_reference_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/default_bottom_margin"
app:layout_constraintBottom_toTopOf="@id/navigation_sheet"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:foregroundTint="?android:textColorPrimary"
app:icon="@drawable/ic_star" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/beaconBtn"
android:layout_width="wrap_content"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1355,6 +1355,7 @@
<string name="augmented_reality">Augmented Reality</string>
<string name="augmented_reality_description">View nearby beacons and the sun / moon with your camera</string>
<string name="pref_enable_augmented_reality_tool" translatable="false">pref_enable_augmented_reality_tool</string>
<string name="magnetic_north">Magnetic North</string>
<plurals name="map_group_summary">
<item quantity="one">%d map</item>
<item quantity="other">%d maps</item>
Expand Down

0 comments on commit 9e5957a

Please sign in to comment.