From 2e79a12fb7bf2306fddb6decad821ed693c8e1be Mon Sep 17 00:00:00 2001 From: Brad Date: Fri, 24 Nov 2023 22:28:24 -0600 Subject: [PATCH] Added map type toggle to current recording screen. Resolves #44 --- .../gpxrecorder/recording/RecorderFragment.kt | 30 ++++++++++++++----- .../layout/fragment_active_route_details.xml | 15 ++++++++++ 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/iboism/gpxrecorder/recording/RecorderFragment.kt b/app/src/main/java/com/iboism/gpxrecorder/recording/RecorderFragment.kt index bab0b72..535dc38 100644 --- a/app/src/main/java/com/iboism/gpxrecorder/recording/RecorderFragment.kt +++ b/app/src/main/java/com/iboism/gpxrecorder/recording/RecorderFragment.kt @@ -4,8 +4,10 @@ import android.content.Context import android.content.Intent import android.os.Bundle import android.view.LayoutInflater +import android.view.MenuItem import android.view.View import android.view.ViewGroup +import android.widget.PopupMenu import androidx.fragment.app.Fragment import androidx.lifecycle.lifecycleScope import com.iboism.gpxrecorder.Events @@ -52,6 +54,20 @@ class RecorderFragment : Fragment(), RecorderServiceConnection.OnServiceConnecte binding.playpauseBtn.setOnClickListener(this::playPauseButtonClicked) binding.stopBtn.setOnClickListener(this::stopButtonClicked) + val moreMenu = PopupMenu(binding.root.context, binding.moreBtn) + val mapToggleMenuItem: MenuItem = moreMenu.menu.add("Toggle map type") + + moreMenu.setOnMenuItemClickListener { menuItem -> + when (menuItem) { + mapToggleMenuItem -> mapController?.toggleMapType() + else -> return@setOnMenuItemClickListener false + } + + return@setOnMenuItemClickListener true + } + + binding.moreBtn.setOnClickListener { moreMenu.show() } + updateUI(gpxId) binding.mapView.let { @@ -141,13 +157,13 @@ class RecorderFragment : Fragment(), RecorderServiceConnection.OnServiceConnecte } val update = Single.just(Pair(gpxContent.title, isPaused)) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe { pair -> - binding.routeTitleTv.text = pair.first - val pauseResumeString = if (pair.second) R.string.resume_recording else R.string.pause_recording - binding.playpauseBtn.setText(pauseResumeString) - mapController?.redraw() - } + .observeOn(AndroidSchedulers.mainThread()) + .subscribe { pair -> + binding.routeTitleTv.text = pair.first + val pauseResumeString = if (pair.second) R.string.resume_recording else R.string.pause_recording + binding.playpauseBtn.setText(pauseResumeString) + mapController?.redraw() + } realm.close() } diff --git a/app/src/main/res/layout/fragment_active_route_details.xml b/app/src/main/res/layout/fragment_active_route_details.xml index ccacff5..d4c5d36 100644 --- a/app/src/main/res/layout/fragment_active_route_details.xml +++ b/app/src/main/res/layout/fragment_active_route_details.xml @@ -46,6 +46,21 @@ app:layout_constraintStart_toStartOf="@id/current_rec_header" app:layout_constraintTop_toBottomOf="@id/current_rec_header" /> + +