Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide locations swap icon when fields are empty #895

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() })
Altonss marked this conversation as resolved.
Show resolved Hide resolved
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() {
}

}