Android MVVM Kotlin Tutorial - LiveData + ViewModel (Android Architecture Components)

แชร์
ฝัง
  • เผยแพร่เมื่อ 18 ก.ย. 2024

ความคิดเห็น • 151

  • @DivyangM
    @DivyangM 2 ปีที่แล้ว +2

    The BEST MVVM TUTORIAL on the planet for beginners. I wish I had a teacher like you when I was in college. Thank you, sir.

  • @henriquedesouza412
    @henriquedesouza412 5 ปีที่แล้ว +17

    Just amazing, I was looking for something like this a long time ago !
    Greetings from Brazil

  • @verryondrums
    @verryondrums 4 ปีที่แล้ว +6

    I wish I had discovered this tutorial 2 weeks ago. Would have saved me a lot of time...! Thanks anyway, really good explanations and examples !

  • @tonyblack1981
    @tonyblack1981 3 ปีที่แล้ว +2

    I absolutely love way you explain the purpose for everything you are doing throughout your tutorial. I'm subscribing. I don't want to speak too soon, but maybe you're the tutor I've been looking for to help me make sense of android dev. Thumbs up.

  • @mitchellthornton1223
    @mitchellthornton1223 6 ปีที่แล้ว +6

    You're the best. I'd love to see you do a design pattern series. I have trouble understanding how to link everything together and the reasons behind design patterns

    • @ResoCoder
      @ResoCoder  6 ปีที่แล้ว +4

      Thank you! I will make a full Android app series using MVVM pattern. I might do a comparison between different architectural patterns but I don't promise anything 😄

  • @mohsenss8791
    @mohsenss8791 5 ปีที่แล้ว +8

    I've seen twice but still some interesting points to learn.

  • @hellespont5072
    @hellespont5072 3 ปีที่แล้ว +2

    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 :D

  • @AdilKhalil
    @AdilKhalil 4 ปีที่แล้ว

    thanks for being so considerate and 'apologising' for bad sound in the start. I hardly noticed it :)

  • @davidmfra
    @davidmfra 6 ปีที่แล้ว +9

    Hey. @14:00 on your database singleton you could have used the lazy delegate, like this:
    val instance = lazy{ FakeDatabase()}
    also it's a good practice to not use this for the lock, use a private object for locking,so people cannot have access to your lock outside.

    • @dragossusi
      @dragossusi 5 ปีที่แล้ว +2

      or you can use object instead of class

    • @davidmfra
      @davidmfra 5 ปีที่แล้ว

      @@dragossusi yes, you would keep the Singleton logic, but loose the lazyness

  • @alextroy605
    @alextroy605 4 ปีที่แล้ว +1

    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" 🙈👋

  • @matt-g-recovers
    @matt-g-recovers 3 ปีที่แล้ว

    I have used this as reference last couple years when I forget this or that.
    It's a great crash course and quick reference.
    I love the DI from scratch @27:20

  • @ryanbennett6801
    @ryanbennett6801 4 ปีที่แล้ว

    Best Android explanation channel on TH-cam.

  • @remali26
    @remali26 3 ปีที่แล้ว +1

    Everyone if you want to rename something press the word you want to rename and then press shift+F6 and then enter. Or press right click refactor -> rename.

  • @patrickstens2779
    @patrickstens2779 6 ปีที่แล้ว +45

    Great video!
    What colour scheme/font are you using? Really like the colours.
    Edit: It's the Material UI Theme Plugin with color scheme set to Material Darker

    • @michaelgidron
      @michaelgidron 4 ปีที่แล้ว

      Sweet .. thanks :-)

    • @berkc5323
      @berkc5323 4 ปีที่แล้ว

      and which font is it?

  • @michalrv3066
    @michalrv3066 5 ปีที่แล้ว +4

    great tutorial, best android tutorial quality I've seen on youtube so far

  • @dival9963
    @dival9963 4 ปีที่แล้ว +2

    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

  • @BinaryBenevolence
    @BinaryBenevolence 2 ปีที่แล้ว

    this is great tutorial ! learning how to use mvvm in android app. glad that I found it early

  • @TheAiSaEr
    @TheAiSaEr 5 ปีที่แล้ว +2

    Thank you! :) Great explanation! And your voice is so nice!

  • @moritziseke9658
    @moritziseke9658 5 ปีที่แล้ว +2

    13:24 you can simply use "object FakeDatabase {...}" to create a singleton

    • @amrh4259
      @amrh4259 5 ปีที่แล้ว

      the same question

  • @dhivabanyuwigara7406
    @dhivabanyuwigara7406 5 ปีที่แล้ว +2

    Nice tutorial, hope you do LiveData + ViewModel + DataBinding on later video, and thanks!

  • @anthonyporter7390
    @anthonyporter7390 5 ปีที่แล้ว

    Third video i've watched today. Amazing work!

  • @LoldemortII
    @LoldemortII 3 ปีที่แล้ว

    I love you!! This is just what I needed to progress!

  • @Enshaedn
    @Enshaedn 5 ปีที่แล้ว +3

    Thank you for the video. It has helped me understand MVVM better though I still feel like I need more practice with it. Specifically related to actually connecting with a database.
    I was wondering if any of your other videos/tutorials explain connecting with Firestore. Would it be made via calls / queries in the Repository class or would you still have a Database class which instantiates the DB connection and makes the queries? Firestore also allows listeners for data changes so I don't understand if LiveData should be used as well or if it matters. Using Firestore also seems like Room wouldn't need to be used. Is that correct?

  • @nandomkumchi4377
    @nandomkumchi4377 4 ปีที่แล้ว

    Tanx so much Reso coder.... I have a better understanding of Live data and MVVM now...

  • @savaramkiran
    @savaramkiran 6 ปีที่แล้ว

    Excellent tutor, required full tutorial explaining hitting REST API, Local Storage, Repository, ViewModel, View

  • @ralphordanza3487
    @ralphordanza3487 5 ปีที่แล้ว

    You earned a new subscriber! Thank you so much man!

  • @cs-ope
    @cs-ope ปีที่แล้ว

    You are an awesome guy my friend!

  • @kingmarwat
    @kingmarwat 2 ปีที่แล้ว

    amaaaaaazing. teaching method. well done, awesome

  • @heavysoccer7862
    @heavysoccer7862 6 ปีที่แล้ว

    Your tutorials are really very helpful. Thanks man.

  • @asadmukhtar1
    @asadmukhtar1 5 ปีที่แล้ว +1

    Great video!
    What colour scheme/font are you using? Really like the colours?

  • @raghav_achari
    @raghav_achari 4 ปีที่แล้ว +1

    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??

    • @bsrafael
      @bsrafael 4 ปีที่แล้ว

      Synthetic binding. Requires installing kotlin android extensions. Check this out: medium.com/coding-blocks/goodbye-findviewbyid-say-hello-to-synthetic-binding-in-kotlin-d3727bd8438e

  • @dreb.7760
    @dreb.7760 2 ปีที่แล้ว

    Great tutorial, many thanks

  • @shrikantdevarmani9473
    @shrikantdevarmani9473 5 ปีที่แล้ว

    Understandable content with easy explanation. Ty

  • @elpirato5428
    @elpirato5428 3 ปีที่แล้ว

    thx, best short tutorial

  • @SabbathJoe89v2
    @SabbathJoe89v2 3 ปีที่แล้ว

    Best video about the argument!!!

  • @MateusMeurer
    @MateusMeurer 3 ปีที่แล้ว

    Oh fuck me twice, seriously? I know the good practices are here to better our lives but damn, he already have like 4 packages and 6 classes and I'm halfway through the tutorial and this is a simple quote app.
    Thank you for the tutorial btw very clear =)

  • @voicheci007
    @voicheci007 6 ปีที่แล้ว +3

    Great video! Can you also make a video on Dependency injection for beginners?

    • @ResoCoder
      @ResoCoder  6 ปีที่แล้ว +4

      Yes! I will publish it this Friday 😉

    • @voicheci007
      @voicheci007 6 ปีที่แล้ว

      @@ResoCoder Great! Thanks a lot! Looking forward to the video

    • @jktan5793
      @jktan5793 6 ปีที่แล้ว +1

      yes dagger2!!!

  • @user-gz7mr2zk8s
    @user-gz7mr2zk8s 11 หลายเดือนก่อน

    Thank you very much Sir, Great tutorial ...

  • @khanhsb15
    @khanhsb15 ปีที่แล้ว

    Thanks so much, it's helpful !

  • @roasters943
    @roasters943 ปีที่แล้ว

    Wonderful tutorial

  • @danildv2001
    @danildv2001 4 ปีที่แล้ว

    Awesome tutorial!! Thank u!

  • @soulduse
    @soulduse 6 ปีที่แล้ว

    Thank you so much. Your explain is so nice and helpful for me !

  • @samha1513
    @samha1513 5 ปีที่แล้ว +7

    I am completely lost in these classes and repository and fakedatabase. What's the best way to learn mvvm?

    • @ResoCoder
      @ResoCoder  5 ปีที่แล้ว +2

      Maybe you'd benefit from my tutorial series where we build a real MVVM app for weather forecasts.

    • @samha1513
      @samha1513 5 ปีที่แล้ว

      @@ResoCoder thanks I am following those and it's good so far.

    • @ralphGabbbbbb
      @ralphGabbbbbb 5 ปีที่แล้ว

      @@ResoCoder What is that series ? I want to check that

  • @CiaphasCain21
    @CiaphasCain21 4 ปีที่แล้ว

    Thanks! That was really helpful to me

  • @gerardpalma8006
    @gerardpalma8006 3 ปีที่แล้ว

    I think that you can use the DI to create the Singleton instance for some of your classes

  • @md.naimurrahman2466
    @md.naimurrahman2466 2 ปีที่แล้ว

    Just amazing!

  • @mohsenss8791
    @mohsenss8791 5 ปีที่แล้ว

    Thanks. I've learned so much.

  • @MultiBuzzTube
    @MultiBuzzTube 4 ปีที่แล้ว

    thanks for this wonderful video - should the repo be init with the db and not the dao ? why repo is with constructor with dao?

  • @ashiqurrahmantahmid9634
    @ashiqurrahmantahmid9634 4 ปีที่แล้ว

    Amazing ! It's so helpful

  • @amrh4259
    @amrh4259 5 ปีที่แล้ว

    Great tutorial, I prefer if you can draw a sample flow graph just to make it easier for you and for us too
    many thanks

  • @nsansa9234
    @nsansa9234 2 ปีที่แล้ว +2

    I think not using Room DB and making it fake DB made it more confusing

  • @CiaphasCain21
    @CiaphasCain21 4 ปีที่แล้ว

    Thanks!! Your tutorial was realy helpful

  • @Since1059
    @Since1059 4 ปีที่แล้ว

    It's really good tutorial for learning thanks bro

  • @mankesh_mishra
    @mankesh_mishra 4 ปีที่แล้ว

    Great Video (cheers)
    Thanks for the tutorial. :D

  • @VinayKumar-mb3ge
    @VinayKumar-mb3ge 5 ปีที่แล้ว

    keep adding more videos.Thanks

  • @holofox66
    @holofox66 6 ปีที่แล้ว

    Thanks you. I wait this tutorial.

  • @LordOfTheBing
    @LordOfTheBing 4 ปีที่แล้ว

    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.

  • @DjangoMx
    @DjangoMx 5 ปีที่แล้ว

    Great video but i have a question, for each view model i have to create a viewmodel factory? because in the video you only create one for the only one viewmodel you have

  • @navdeepbrar3526
    @navdeepbrar3526 2 ปีที่แล้ว +1

    How did the code recognize textview, edittext, and button's XML ids without databinding or findviewbyid in QuotesAcitvity?

    • @adravel
      @adravel 2 ปีที่แล้ว +1

      It's possible using Kotlin synthetics, but the plugin (Kotlin Android Extensions) is now deprecated

  • @pd6732
    @pd6732 6 ปีที่แล้ว

    Thanks for the video. Have been doing android stuff for quite some time now, but never follwed any particular design patters because the apps were for personal use only. Btw. what color scheme/font are you using? Kinda reminds me of default atom colors. cheers

    • @ResoCoder
      @ResoCoder  6 ปีที่แล้ว

      Yes, the need for patterns comes after a few finished projects :D I'm using "Material Darker" theme. It's a plugin for Android Studio. The font is Consolas.

  • @joshthiele8416
    @joshthiele8416 4 ปีที่แล้ว

    Excellent video. I'm new to development, so i could be totally wrong, but shouldn't the business logic be in the ViewModel, and not in the View?
    :)

  • @abdulhakeemmahmood5463
    @abdulhakeemmahmood5463 5 ปีที่แล้ว +1

    hey @6:50 , why override the toString method in kotlin data class? data class does that by default, right?

  • @nkheart4
    @nkheart4 5 ปีที่แล้ว

    If who want to run the code but don't want to write by your self.
    This is the code that I write from this tutorial. Some command I change it to the latest Kotlin version.
    github.com/heart/Android-MVVM-Kotlin

  • @user-fb7do4nc6r
    @user-fb7do4nc6r 4 ปีที่แล้ว

    Thank you!!!

  • @EL-cb1nu
    @EL-cb1nu 4 ปีที่แล้ว

    I dont understand why at 16:58 the FakeDatabase object is no inheriting FakeDatabaseDao, but rather is creating FakeDatabaseDao as a new object?

  • @OurPastSecrets
    @OurPastSecrets 5 ปีที่แล้ว

    I'm confused at the distinction of DAO and Repository - I always thought of them as the same thing. Your implementation of Respository just calls the DAO.getQuotes() or DAO.addQuote() so why the extra layer

  • @adibazhar1115
    @adibazhar1115 4 ปีที่แล้ว

    Hi, I familiar with android studio in Java but new in Kotlin...what is the basic things u can suggest before I start to learn about MVVM ? like coroutines, room, etc ?

  • @ziweiguo7821
    @ziweiguo7821 6 ปีที่แล้ว

    Thinks for your video, but I have a question: how to initialize view without invoking "findViewById" method?

  • @jollibeecheese
    @jollibeecheese 4 ปีที่แล้ว

    I suppose Quote should not be initialized on QuoteActivity cause it directly uses a model. If I'm wrong, please let me know.

  • @fabrizziocht
    @fabrizziocht 5 ปีที่แล้ว

    When I have many entities, should I create a repository for each one? For example, if I have the Post and Blog entities, each with its own DAO, I could implement a repository for each one, but in a real application I may need both at the same time in a synchronizeAll () method. How can I solve this?

  • @OmerFarukUcer
    @OmerFarukUcer 2 ปีที่แล้ว

    I still can't understand the topic.I try to learn MVVM architecture using in an app but still can't understand why we use this kind of different usages.I mean it's like there is no logic.How can I learn it easily?I tried my best but still can't understand the liveData or MVVM architechture :(

  • @mohsenss8791
    @mohsenss8791 5 ปีที่แล้ว

    In case of a chat app that we have two models, if we have just one repository which gives data to all view models, it does not make sense. Because all the functions we have in the repository is accessible in any view models. For example, we can get a list of groups in user viewmodel. So what can we do for this problem?

  • @cwssoftware3588
    @cwssoftware3588 5 ปีที่แล้ว

    Please create videos on testing

  • @kamala132
    @kamala132 5 ปีที่แล้ว

    Amazing tutorial mate, thanks a lot for it! Could you please explain how do I plug a real db in this pattern? I m using normal sqlite with Anko library

    • @ResoCoder
      @ResoCoder  5 ปีที่แล้ว

      Thanks! Have you considered using the Room library? Even if not, watch my newest tutorial series. The last part is about creating a database.

  • @edwinfcapidos
    @edwinfcapidos 4 ปีที่แล้ว

    Do you have tutorials for MVVM when using Firebase?

  • @witoldsienski1709
    @witoldsienski1709 5 ปีที่แล้ว

    Very good video

  • @jktan5793
    @jktan5793 6 ปีที่แล้ว

    Hi, very nice and updated tutorial.
    Can you add dagger2 and retrofit (web service) in this project tutorial too ?

    • @ResoCoder
      @ResoCoder  6 ปีที่แล้ว +2

      Thanks. I will publish a tutorial on MVVM and Kodein which is a dependency injection framework built for Kotlin.
      I'm also currently preparing a whole tutorial series where we'll be using Retrofit2, Room and more. Stay tuned 😃

    • @jktan5793
      @jktan5793 6 ปีที่แล้ว

      Thank you so much.
      Love the way you teaching, and also your sound is really clear and good =)
      Can't wait for them haha.
      Thank you once again !!!

  • @blackkingblackjack3325
    @blackkingblackjack3325 2 ปีที่แล้ว

    I encounter an unsresolved reference issue in the QuotesActivity when I reference the textView or editText, any idea why? I get unrseolved reference and variable expected

  • @voicheci007
    @voicheci007 5 ปีที่แล้ว

    Hi Matej! Can you do another tutorial like this but with a real DAO (Room library) and a real web service you can call? This is a bit confusing. Thank you for understanding

    • @ResoCoder
      @ResoCoder  5 ปีที่แล้ว

      Sure! Check out my new videos. I'm doing a tutorial series where we're building a real world forecast mvvm app.

  • @dogukangoktas693
    @dogukangoktas693 2 ปีที่แล้ว

    09:00 I can't use mutableListOf() What can ı do?

  • @ProGaming-kb9io
    @ProGaming-kb9io 3 ปีที่แล้ว +2

    ViewModelProvider(this, factory)

  • @vankans2267
    @vankans2267 5 ปีที่แล้ว

    great!!

  • @cwssoftware3588
    @cwssoftware3588 5 ปีที่แล้ว

    can you make a video on testing

  • @mohammadamirkanjoori138
    @mohammadamirkanjoori138 3 ปีที่แล้ว

    nice

  • @ProjectNullTheGame
    @ProjectNullTheGame 5 ปีที่แล้ว

    I think this volitale and sync is unneccessary because we have lazy pattern for kotlin...

  • @pembatamang8233
    @pembatamang8233 4 ปีที่แล้ว

    is a singleton class needed for the repository even in real apps?

  • @tejasjani2544
    @tejasjani2544 3 ปีที่แล้ว +1

    nice video.
    I am from java background. what the hell🤯 is going on with Syntax.

    • @hamzamateen7827
      @hamzamateen7827 3 ปีที่แล้ว

      I swear i had the same reaction :( I used Java more than a year ago

  • @TikTokTrendsCompilation
    @TikTokTrendsCompilation 6 ปีที่แล้ว

    how do you have that dark theme of AS?

  • @sadzolot2
    @sadzolot2 5 ปีที่แล้ว

    Nice fonts in Android Studio , what`s name?

  • @krishnachinya
    @krishnachinya 6 ปีที่แล้ว

    very helpful. can you do the same tutorial using Java

    • @ResoCoder
      @ResoCoder  6 ปีที่แล้ว

      I technically could but Kotlin is the way to go 😉

    • @krishnachinya
      @krishnachinya 6 ปีที่แล้ว

      Yeah, but most companies don't switch to kotlin from java. its rework and there is not much advantage in switching in terms of performance or support. at the end of the day both codes are converted into bytecode.

  • @sanaebadi97
    @sanaebadi97 5 ปีที่แล้ว

    do u have mvvm tutorial with java ?

  • @pembatamang8233
    @pembatamang8233 4 ปีที่แล้ว

    your Android Studio looks like Visual Studio

  • @tigranbabajanyan842
    @tigranbabajanyan842 5 ปีที่แล้ว

    Why not used ROOM annotations?

  • @mohsenmirtalebi2170
    @mohsenmirtalebi2170 5 ปีที่แล้ว

    tnx

  • @tubebility
    @tubebility 5 ปีที่แล้ว

    This line is failing > implementation "androidx.lifecycle:lifecycle-extensions:2.0.0-rc01"
    Android Studio 3.2.1

    • @tubebility
      @tubebility 5 ปีที่แล้ว

      After researching the components website, I learn that you now have to specify the viewmodel and livedata extensions separately.
      _implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.0.0'_
      _implementation 'androidx.lifecycle:lifecycle-livedata:2.0.0'_

  • @MinhTran-xn3kk
    @MinhTran-xn3kk 5 ปีที่แล้ว +1

    hello.
    how to make code beautiful like this :))

  • @this-is-bioman
    @this-is-bioman 3 ปีที่แล้ว

    The actual content of wiring-up the view with the model begins at 30:00.
    I find the FakeQuoteDao is overengineered not only for this example but in general. There should be only a repository exposing an interface so that you can exchange the repository. The way you did it creates unnecessary repetitions where you end up with three (!) methods named getQuotes.
    This tutorial is also too long. Mixing dependency injection and all the factories etc here makes it difficult to follow. The focus should have been just to wire-up the model with the view which could have been done in less than 8 minutes :-\

  • @dentor2005
    @dentor2005 3 ปีที่แล้ว

    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.

  • @eesaaphilips9271
    @eesaaphilips9271 5 ปีที่แล้ว

    What theme are you using for the android studio ide?

  • @shaikhaaves6645
    @shaikhaaves6645 6 ปีที่แล้ว +1

    which version of android studio are you using?

    • @ResoCoder
      @ResoCoder  6 ปีที่แล้ว +1

      I'm currently using version 3.3 Canary 6.

    • @shaikhaaves6645
      @shaikhaaves6645 6 ปีที่แล้ว

      Thanks!

    • @shaikhaaves6645
      @shaikhaaves6645 6 ปีที่แล้ว

      Thanks!
      My android studio does not support android jetpack navigation!
      Please give me suggestion

    • @ResoCoder
      @ResoCoder  6 ปีที่แล้ว +1

      Well, if you install the latest 3.3 canary version, it will work.

    • @shaikhaaves6645
      @shaikhaaves6645 6 ปีที่แล้ว +3

      Thanks for your suggestion, i just did it and it actually worked!
      Thanks!
      Can you please make a video on Repository + Navigation + Retrofit + ViewModel + RecyclerView!!!!!
      Please do make one!