Skip to content

Commit

Permalink
Update DirectionsFragment.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
Altonss authored Dec 6, 2023
1 parent 088cf3f commit 41cdcd2
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,10 @@ class DirectionsFragment : TransportrFragment() {
fromLocation.setLocation(it)
if (it != null) toLocation.requestFocus()
})
viewModel.fromLocation.observe(viewLifecycleOwner, { onLocationsChanged() })
viewModel.viaLocation.observe(viewLifecycleOwner, { viaLocation.setLocation(it) })
viewModel.toLocation.observe(viewLifecycleOwner, { toLocation.setLocation(it) })
viewModel.toLocation.observe(viewLifecycleOwner, { 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 +150,12 @@ 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.visibility = if (fromNotEmpty || toNotEmpty) VISIBLE else GONE
}

override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
outState.putSerializable(DATE, viewModel.lastQueryCalendar.value)
Expand Down Expand Up @@ -272,3 +280,4 @@ class DirectionsFragment : TransportrFragment() {
}

}

0 comments on commit 41cdcd2

Please sign in to comment.