Skip to content

Commit

Permalink
Use play bar for backtrack
Browse files Browse the repository at this point in the history
  • Loading branch information
kylecorry31 committed Mar 9, 2022
1 parent 2a48064 commit 9702476
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import android.view.View
import android.view.ViewGroup
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import com.kylecorry.andromeda.alerts.Alerts
import com.kylecorry.andromeda.alerts.toast
import com.kylecorry.andromeda.fragments.BoundFragment
import com.kylecorry.andromeda.list.ListView
import com.kylecorry.andromeda.pickers.Pickers
Expand Down Expand Up @@ -39,8 +39,6 @@ class PathsFragment : BoundFragment<FragmentPathsBinding>() {
IOFactory().createGpxService(this)
}

private var wasEnabled = false

private var paths = emptyList<Path>()
private var sort = PathSortMethod.MostRecent

Expand Down Expand Up @@ -79,41 +77,33 @@ class PathsFragment : BoundFragment<FragmentPathsBinding>() {
}
}

wasEnabled = prefs.backtrackEnabled
if (wasEnabled && !(prefs.isLowPowerModeOn && prefs.lowPowerModeDisablesBacktrack)) {
binding.startBtn.setImageResource(R.drawable.ic_baseline_stop_24)
} else {
binding.startBtn.setImageResource(R.drawable.ic_baseline_play_arrow_24)
}
binding.backtrackPlayBar.setState(isBacktrackRunning)

binding.startBtn.setOnClickListener {
binding.backtrackPlayBar.setOnPlayButtonClickListener {
if (prefs.isLowPowerModeOn && prefs.lowPowerModeDisablesBacktrack) {
Alerts.toast(
requireContext(),
getString(R.string.backtrack_disabled_low_power_toast)
)
toast(getString(R.string.backtrack_disabled_low_power_toast))
} else {
prefs.backtrackEnabled = !wasEnabled
if (!wasEnabled) {
binding.startBtn.setImageResource(R.drawable.ic_baseline_stop_24)
val isOn = isBacktrackRunning
prefs.backtrackEnabled = !isOn
if (!isOn) {
BacktrackScheduler.start(requireContext(), true)
} else {
binding.startBtn.setImageResource(R.drawable.ic_baseline_play_arrow_24)
BacktrackScheduler.stop(requireContext())
}
wasEnabled = !wasEnabled
}
onUpdate()
}

scheduleUpdates(INTERVAL_1_FPS)
}

override fun onUpdate() {
wasEnabled = BacktrackScheduler.isOn(requireContext())
if (wasEnabled && !(prefs.isLowPowerModeOn && prefs.lowPowerModeDisablesBacktrack)) {
binding.startBtn.setImageResource(R.drawable.ic_baseline_stop_24)
val backtrackEnabled = isBacktrackRunning
binding.backtrackPlayBar.setState(backtrackEnabled)
binding.backtrackPlayBar.subtitle = if (backtrackEnabled) {
getString(R.string.on)
} else {
binding.startBtn.setImageResource(R.drawable.ic_baseline_play_arrow_24)
getString(R.string.off)
}
}

Expand All @@ -124,6 +114,9 @@ class PathsFragment : BoundFragment<FragmentPathsBinding>() {
return FragmentPathsBinding.inflate(layoutInflater, container, false)
}

private val isBacktrackRunning: Boolean
get() = BacktrackScheduler.isOn(requireContext())

private fun onPathsChanged(paths: List<Path>) {
this.paths = sortPaths(paths)
listView.setData(this.paths)
Expand Down
24 changes: 11 additions & 13 deletions app/src/main/res/layout/fragment_paths.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
android:id="@+id/paths_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:flattenQuickActions="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:rightQuickActionIcon="@drawable/ic_menu_dots"
app:showSubtitle="false"
app:flattenQuickActions="true"
app:title="@string/paths" />

<androidx.recyclerview.widget.RecyclerView
Expand All @@ -28,18 +28,6 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/paths_title" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/start_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginBottom="24dp"
android:clickable="true"
android:focusable="true"
android:src="@drawable/ic_baseline_play_arrow_24"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

<TextView
android:id="@+id/waypoints_empty_text"
android:layout_width="wrap_content"
Expand All @@ -54,4 +42,14 @@
app:layout_constraintTop_toTopOf="@+id/waypoints_list"
tools:visibility="visible" />

<com.kylecorry.trail_sense.shared.views.PlayBarView
android:id="@+id/backtrack_play_bar"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:playBarIcon="@drawable/ic_tool_backtrack"
app:playBarTitle="@string/backtrack" />

</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit 9702476

Please sign in to comment.