From a6ee7972d148f61abc30c286ed16000b4c5d07f9 Mon Sep 17 00:00:00 2001 From: Altonss <66519591+Altonss@users.noreply.github.com> Date: Sat, 2 Nov 2024 13:29:15 +0100 Subject: [PATCH] Hide locations swap icon when fields are empty (#895) --- .../transportr/trips/search/DirectionsFragment.kt | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/de/grobox/transportr/trips/search/DirectionsFragment.kt b/app/src/main/java/de/grobox/transportr/trips/search/DirectionsFragment.kt index e5c50f545..3ee22c175 100644 --- a/app/src/main/java/de/grobox/transportr/trips/search/DirectionsFragment.kt +++ b/app/src/main/java/de/grobox/transportr/trips/search/DirectionsFragment.kt @@ -110,9 +110,13 @@ class DirectionsFragment : TransportrFragment() { viewModel.fromLocation.observe(viewLifecycleOwner, { fromLocation.setLocation(it) if (it != null) toLocation.requestFocus() + onLocationsChanged() }) viewModel.viaLocation.observe(viewLifecycleOwner, { viaLocation.setLocation(it) }) - viewModel.toLocation.observe(viewLifecycleOwner, { toLocation.setLocation(it) }) + viewModel.toLocation.observe(viewLifecycleOwner, { + toLocation.setLocation(it) + onLocationsChanged() + }) viewModel.viaSupported.observe(viewLifecycleOwner, { viaIcon.visibility = if (it) VISIBLE else GONE }) viewModel.isDeparture.observe(viewLifecycleOwner, { onIsDepartureChanged(it) }) viewModel.isExpanded.observe(viewLifecycleOwner, { onViaVisibleChanged(it) }) @@ -148,6 +152,14 @@ class DirectionsFragment : TransportrFragment() { TooltipCompat.setTooltipText(viaIcon, getString(R.string.action_navigation_expand)) } + private fun onLocationsChanged() { + val fromNotEmpty = this.viewModel.fromLocation.value != null + val toNotEmpty = this.viewModel.toLocation.value != null + swapIcon.isEnabled = fromNotEmpty || toNotEmpty + // If icon disabled, grey it out + swapIcon.alpha = if (swapIcon.isEnabled) 1.0f else 0.5f + } + override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) outState.putSerializable(DATE, viewModel.lastQueryCalendar.value) @@ -272,3 +284,4 @@ class DirectionsFragment : TransportrFragment() { } } +