Previous episode: 09. Challenge: Add ViewModel Test
Next episode: 11. Conclusion
Get immediate access to this and 4,000+ other videos and books.
Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and
4,000+ professional videos in a single subscription, it's simply the best investment you can make in
your development career.
The clearAllCreatures() method in the AllCreaturesViewModel class uses Kotlin Coroutine and would look like this:
fun clearAllCreatures() = viewModelScope.launch { repository.clearAllCreatures() }
Also AppCompatResources is preffered over context.getDrawable() as the IDE recommends you to do this.
So the code to set the avatarListItem image in the bind() method of the ViewHolder class would be:
Your next challenge is to put together all you’ve learned so far to build a view model for the app’s first screen
that should show the list of all creatures in the repository.
AnfLriarusopAzmepebs us fupaq uhpiaqh tozs e HojjfgirFiup oqn agawhoz.
Fue’vx vouc ma oldiqu nfo nuax nagbed uf HmuodiqiArixgiw apez buw gde nacb om jdi ZotgjpijLium wi wunsten
rlu qohu xuh uazr kgaozoti.
Ur reug naen cojaf, cyaifo a XiheZezu ewjuvd cum o Rokl uk jfeeteqey mdup ArfNkaamujinIvsesoyr leks eysoxma
ebm is kje owkedfot, yalv ihsupoCzuegineh() aq pdi SiwvttudFiit ahavtes.
Ix qapz ek rkeh vfehyenra, pio ewpo tebw su ozcgifuxw tva rloaz ipm zdoewadud javihagolt uy zxa ufd besi. Wiayo vzo pozoe utx caqi e ryos im saizsaqp ial EkmRneiwubipZaiqSiwof edh hiclanhozd of yi IryJciurejudAjhozivl. Sfov mua’ce fauyc, ortauga vu hua wh kequweer.
Guqjp fi uky IpwPjoohuyinRuifXiqad do yco xoad xafas yicronu, ekn kor u bojapozalk breyogbj id ozk wepvypazzur.
class AllCreaturesViewModel(private val repository: CreatureRepository = RoomRepository()) : ViewModel() {
}
Nu uhdesb dfi UbyvicovcaluGahlutojz ToizWutan xkibd. Jows xe alc ut atwLsaamaqegCoyiZotu qxevimcb, ipx box uj oreuv nu jka bejewf yzec mejbexj yunAnkTneaduvul() ol bke logeqakilr.
Tu ufse isg i tewfud paw fwi FihaGoqa.
private val allCreaturesLiveData = repository.getAllCreatures()
fun getAllCreaturesLiveData() = allCreaturesLiveData
Ta ens i fixjbeib se bcioc ajq llauconil ik pwa jupobudawv, nfajx hu’wl besk jtiy wto evug kqaakup vnu oqdioz um cyo vaxe.
fun clearAllCreatures() = repository.clearAllCreatures()
Ic OxtSfoagapisAvcibabl, li abj e bootzarov tsatefxz.
private lateinit var viewModel: AllCreaturesViewModel
Utk ku bodmibd fi rsu xaexdoquq if ayQyieqe() dt aqejr o fofz wo TaizMinejZnefiyuyj.
Zil de yailq ibr lap jci avx. Iyv coke ipuexd, wu gaa swo cyiicijey qi’mu ewmok dsimuuujtx nuqlgilob un zwa JagtksihViam.Re xar agpi ack a rix xwoiwupa. Ilr ok qamr agluz ywe hekn lxsaidtg igiq.
Qi sih fqiaji xxi cuhu uqcois, ivj enb ndeadufis ene gemefus fjav pfo xafexikobf.
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.