Skip to content

Commit

Permalink
Hide locations swap icon when fields are empty (grote#895)
Browse files Browse the repository at this point in the history
  • Loading branch information
Altonss authored Nov 2, 2024
1 parent 16d92d1 commit a6ee797
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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) })
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -272,3 +284,4 @@ class DirectionsFragment : TransportrFragment() {
}

}

0 comments on commit a6ee797

Please sign in to comment.