Skip to content

Commit

Permalink
Extract north reference badge
Browse files Browse the repository at this point in the history
  • Loading branch information
kylecorry31 committed Nov 18, 2023
1 parent 51a4c66 commit bca8df6
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class NavigatorFragment : BoundFragment<ActivityNavigatorBinding>() {

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

Expand Down Expand Up @@ -509,15 +509,8 @@ 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)
})

binding.northReferenceIndicator.useTrueNorth = useTrueNorth
binding.northReferenceIndicator.showLabel = true
northReferenceHideTimer.once(Duration.ofSeconds(5))
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.kylecorry.trail_sense.shared.views

import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
import android.widget.FrameLayout
import com.kylecorry.andromeda.core.system.Resources
import com.kylecorry.ceres.badge.CeresBadge
import com.kylecorry.trail_sense.R
import com.kylecorry.trail_sense.shared.FormatService

class NorthReferenceBadge(
context: Context,
attrs: AttributeSet? = null
) : FrameLayout(context, attrs) {

private val badge = CeresBadge(context, attrs)
private val formatter = FormatService.getInstance(context)

var useTrueNorth: Boolean = false
set(value) {
field = value
updateBadge()
}

var showLabel: Boolean = true
set(value) {
field = value
updateBadge()
}

init {
badge.layoutParams = LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT
)
badge.setBackgroundTint(Color.TRANSPARENT)
badge.setForegroundTint(Resources.androidTextColorSecondary(context))
useTrueNorth = false
addView(badge)
}

private fun updateBadge() {
badge.setImageResource(formatter.getCompassReferenceIcon(useTrueNorth))
val text = when {
!showLabel -> null
useTrueNorth -> context.getString(R.string.true_north)
else -> context.getString(R.string.magnetic_north)
}
badge.setStatusText(text)
}

}
6 changes: 2 additions & 4 deletions app/src/main/res/layout/activity_navigator.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,14 @@
app:layout_constraintTop_toBottomOf="@id/linear_compass"
app:srcCompat="@drawable/ic_camera" />

<com.kylecorry.ceres.badge.CeresBadge
<com.kylecorry.trail_sense.shared.views.NorthReferenceBadge
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" />
app:layout_constraintStart_toStartOf="parent" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/beaconBtn"
Expand Down

0 comments on commit bca8df6

Please sign in to comment.