Last active
April 13, 2021 00:21
-
-
Save fvilarino/527be47270643429f424eebf34fe58fe to your computer and use it in GitHub Desktop.
City MVI Fragment
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
@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