Sign in Go Pro

Android MvRx Fundamentals

Introduction to MvRx

 
Autoplay

Up next

About

MvRx is an Android architecture built on top of Android Jetpack that is designed to make practical Android development easier, faster, and more fun. This lesson will walk through the creation of a simple hello world screen and will introduce you to some common pitfalls and challenges that are involved with Android development that MvRx helps with.

Instructor

Links

Comments

Will you please share the GitHub link of this project?

Thank you, Mr. Peal. https://github.com/airbnb/MvRx/tree/master/todomvrx

Using mvrx what is the recommended approach for use cases such as "autocomplete edittext" where you want to connect your ui text rx stream with the viewmodel's methods (i.e. taking the advantages of rx operations like debounce etc)

I would recommend just having a text watcher that calls a function on your ViewModel that sets a state property to the CharSequence it emitted. What rx operations would you do on it?

Thanks for the reply, I was thinking to do something like that in the "view" in order to take advantage of Rx's debounce operator that I will make less requests when my autocomplete edittext queries the api
RxTextView.textChanges(searchInput).skipInitialValue()
.debounce(500, TimeUnit.MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread())
.subscribe { viewModel.getAddressByPostCode(it.toString()) }

Obviously I need to do write some disposable cancel logic inside fetchAddressByPostCode method in order to cancel earlier api calls
i.e fetchAddressByPostCode logic has
withState {
if (postCode != it.queryText) {

setState {
copy(queryText = postCode)
}
disposable?.let {it.dispose()}
disposable = repository.getAddress(postCode)
.subscribeOn(Schedulers.io())
.execute {
copy(addressResults = it)
}
}
}
I hope that is clear. Any thoughts?

>
You need to go PRO to post comments.

Lessons in Android MvRx Fundamentals