Skip to content

Instantly share code, notes, and snippets.

@ahinchman1
Last active May 11, 2020 04:44
Show Gist options
  • Save ahinchman1/14daf37287e7fb6c805b1d1f3f55b727 to your computer and use it in GitHub Desktop.
Save ahinchman1/14daf37287e7fb6c805b1d1f3f55b727 to your computer and use it in GitHub Desktop.
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