Saturday, 13 September, 2025г.
russian english deutsch french spanish portuguese czech greek georgian chinese japanese korean indonesian turkish thai uzbek

пример: покупка автомобиля в Запорожье

 

Android Tutorial 2019 #7: Implementing ViewModel w/ MutableLiveData, Kotlin Coroutines, MVVM

Android Tutorial 2019 #7: Implementing ViewModel w/ MutableLiveData, Kotlin Coroutines, MVVMУ вашего броузера проблема в совместимости с HTML5
Enjoy my teaching style? Looking for a comprehensive introduction to Kotlin, Android, and Programming in general? If so, consider picking up my introductory course to Programming Fundamentals with Kotlin and Android on Udemy; I don't think you'll be disappointed: https://www.udemy.com/application-programming-fundamentals-with-kotlin/ In This part of the tutorial, we build the ViewModel portion of our Model-View-ViewModel architecture. As discussed in other episodes, we use a particular style of MVVM in this feature, where the View is kept very simple, but at the cost of losing reusability of a given ViewModel. I will be going in to more detail about Coroutines in a separate video in this series, but I also talk about setting up a CoroutineScope so that we can launch coroutines and call suspending functions from the ViewModel. There's a shit ton of information in this video, so I've provided timestamps below: 2:00 A quick look at our BaseViewModel Abstract class, including how it helps us reduce repetitious code, and launch our coroutines from the Dispatchers.mainThread (this is important if you plan on using Coroutines) 4:42 Tip from Al Warren on hiding MutableLiveData objects behind immutable LiveData references Al's blog: https://ntxdroid.com/ 6:35 Quick note on two functions in the ViewModel which we won't be coding today, but I will demonstrate it in another video 7:35 How to simplify interactions between the View and the ViewModel using Sealed Classes an Generics **PRO TIP** 8:54 Writing the constructor of our ViewModel 9:47 By applying simple dependency injection, for our ViewModel and BaseViewModel, we can provide Dispatchers.unconfined when we want to run tests on these classes in a JVM sandbox environment. 10:47 Adding the Repository to our ViewModel's Constructor. 11:10 Adding our MutableLiveData objects to the ViewModel 11:56 A very brief explanation of LiveData and MutableLiveData, and the differences between them 13:28 Representing on screen widgets and control logic using MutableLiveData 14:29 How to publish events to the View which do not require actually passing any data using Kotlin's Unit function 16:10 Adding a MutableLiveData object for each on-screen widget 18:20 Implementing our handleEvent Function with Sealed Class events 22:11 Implementing our Coroutine launch getUser() function (this is how we talk to the back end of the app using coroutines) 23:47 What is a Result Wrapper and why are we returning it from the backend? 25:21 Getting our User object out of the Result Wrapper, and assigning it to the MutableLiveData object 27:45 Implementing onAuthButtonClick Coroutine function 31:10 Implementing our Presentation Logic Functions (different states of the View) with const val String resources Repository link: https://github.com/BracketCove/JetpackNotesMvvmKotlin MVVM Article: https://medium.com/@rkay301/mvvm-on-android-kinda-awkward-tbh-8db78a88f056 Follow the wiseAss Community: https://www.instagram.com/wiseassbrand/ https://www.facebook.com/wiseassblog/ https://twitter.com/wiseass301 http://wiseassblog.com/ https://www.linkedin.com/in/ryan-kay-808388114 Support wiseAss here: https://www.paypal.me/ryanmkay
Мой аккаунт