📗 Read the written tutorial with all the code 👇👇
https://resocoder.com/mvvm-android-kotlin-crash-course
Start saving time now by planning weekly with Week Sweep: http://bit.ly/2Jf3QA0
Model – View – ViewModel is an architectural pattern which will empower you to write manageable, maintainable, cleaner and testable code. MVVM is also supported and encouraged by Google itself. There are many first-party libraries like lifecycle-aware components, LiveData, ViewModel and many more.
In this tutorial you are going to put MVVM pattern into practice. You will build a simple, yet real-enough app which will make you understand MVVM on a deeper level. It will be an app displaying quotes which you put in. This quote app will have a ViewModel, Repository, fake database and a simple dependency injection. This will give you a strong foundation to build on.
Go to my website for more information, code examples and articles:
● http://resocoder.com
Follow me on social media:
● https://www.facebook.com/resocoder
● https://twitter.com/resocoder
source
nice video.
I am from java background. what the hell🤯 is going on with Syntax.
You sir are a legend (y)
Brilliant thank you
Best video about the argument!!!
I followed the tutorial and getting an error while accessing quoteDao in the "InjectorUtils" file. Unresolved reference: quoteDao.
Memory LEAK.
As for me it's not a good idea to receive LiveData from repository directly (through ViewModel) to Layout / Activvity / Fragment. Because you don't know how much time it will take to the DataBase to execute your query. It should be asynchronous task. That's why you should wait in ViewModel the answer from the Repository DB and then using switchMap replace the answer (LiveData ) from Repository to LiveData that is intended for your Layout.
Summary: Get data from DB to ViewModel and if Activity / Fragment AND put the answer to the new LiveData that will be received in Activity / Frament.
Why? Because user can run some task that needs DB data (REST API for example), and without waiting for the end of execution exit from Application or switched to another Activity / Fragment.
Incredible tutorial!! Thank you so much for making this, you are an amazing teacher! I am currently making an app that handles the shopping in a retail store (for the people who physically shop or "pick" the items that are delivered to your house). I made a basic desktop version using java and MVC, but after seeing how well you put this together I am definitely going to use Kotlin and the MVVM techniques you have shown here. Much appreciated! Subscribed 😀
MVVM in kotlin https://www.youtube.com/watch?v=NAYll0w4rxU
Thanks! That was really helpful to me
Awesome tutorial!! Thank u!
Hi Reso Coder. I was following your example. I check there are some depreceated library and some code is not valid anymore. Do you want I send you the proyect updated so you can upload to GitHub?.
I dont understand why at 16:58 the FakeDatabase object is no inheriting FakeDatabaseDao, but rather is creating FakeDatabaseDao as a new object?
Do you have tutorials for MVVM when using Firebase?
23:10 if your QuoteViewModel is only passing along the repos's method, it is an useless intermediate. In this case, you can work on the repo directly instead of adding complexity for the sake of it.
Lower the bass from your voice ☹️
I honestly don't think MVVM requires this many code and classes to be made. Like MVP, all you really need is a model class, view class, and a presenter class. DI can be done manually or with Dagger. That's it. With this, the codebase would clutter up as it scales making everything hard to maintain and unreadable.
how did he set listener to the button with just id?? i mean without findViewById()…. and also accessed other ui elements with just id.. how??
Tanx so much Reso coder…. I have a better understanding of Live data and MVVM now…
Amazing ! It's so helpful
Great Video (cheers)
Thanks for the tutorial. 😀
Really awesome video! It would be nice to provide an advanced implementation like this, combining mvvm with services, where data are driven from services to a database
thanks for being so considerate and 'apologising' for bad sound in the start. I hardly noticed it 🙂
thanks for this wonderful video – should the repo be init with the db and not the dao ? why repo is with constructor with dao?
It's really good tutorial for learning thanks bro
Thank you!!!
Thank you, you are really simple explained the difference module: dao, repos, vm, vmf, and use that in Activity ))
That's not simple to understand that when you are reading the manual by himself. Three time "addQuote" 🙈👋
ViewModelProviders is Depreciated
This is how I did it
val viewModel = ViewModelProvider(
this@QuotesActivity,
factory
).get(QuotesViewModel::class.java)
Thanks!! Your tutorial was realy helpful <3