Last active
May 11, 2020 04:44
-
-
Save ahinchman1/14daf37287e7fb6c805b1d1f3f55b727 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class InvasiveSpeciesMapFragment: Fragment() { | |
private val navigator by lazy { (requireActivity() as MainActivity).navigator } | |
private val viewModel by viewModels<InvasiveSpeciesMapViewModel>() | |
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? = | |
inflater.inflate(R.layout.fragment_invasive_species_map, container, false) | |
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | |
super.onViewCreated(view, savedInstanceState) | |
viewModel.viewState.observeForever { viewState -> | |
viewState?.let { render(it) } | |
} | |
} | |
private fun render(viewState: InvasiveSpeciesMapViewState) { | |
when (viewState) { | |
is InvasiveSpeciesMapViewState.Loading -> { | |
invasive_species_map_loader.visibility = setVisibleOrGone(true) | |
map.visibility = setVisibleOrGone(false) | |
} | |
is InvasiveSpeciesMapViewState.Content -> { | |
invasive_species_map_loader.visibility = setVisibleOrGone(false) | |
map.visibility = setVisibleOrGone(true) | |
} | |
is InvasiveSpeciesMapViewState.Error -> | |
navigator.navigateToError(from = Screen.INVASIVE_SPECIES_MAP) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment