Skip to content

Instantly share code, notes, and snippets.

@fvilarino
Last active April 13, 2021 00:21
Show Gist options
  • Save fvilarino/527be47270643429f424eebf34fe58fe to your computer and use it in GitHub Desktop.
Save fvilarino/527be47270643429f424eebf34fe58fe to your computer and use it in GitHub Desktop.
City MVI Fragment
@AndroidEntryPoint
class CityFragment : Fragment() {
private lateinit var binding: FragmentCityBinding
private val viewModel: CityViewModel by viewModels()
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
binding = FragmentCityBinding.inflate(
inflater,
container,
false
)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
viewModel
.state
.onEach { state -> binding.state = state }
.launchIn(lifecycleScope)
binding.cityInput.doAfterTextChanged { prefix ->
viewModel.onIntent(CityMviIntent.PrefixUpdated(prefix.toString()))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment