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

Поделиться
HTML-код
  • Опубликовано: 4 ноя 2024

Комментарии • 152

  • @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.

  • @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.

  • @AdilKhalil
    @AdilKhalil 4 года назад

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

  • @henriquedesouza412
    @henriquedesouza412 5 лет назад +17

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

  • @ryanbennett6801
    @ryanbennett6801 4 года назад

    Best Android explanation channel on RUclips.

  • @verryondrums
    @verryondrums 5 лет назад +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 !

  • @BinaryBenevolence
    @BinaryBenevolence 2 года назад

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

  • @hellespont5072
    @hellespont5072 4 года назад +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

  • @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.

  • @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

  • @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 6 лет назад +2

      or you can use object instead of class

    • @davidmfra
      @davidmfra 6 лет назад

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

  • @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.

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

  • @nandomkumchi4377
    @nandomkumchi4377 4 года назад

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

  • @kingmarwat
    @kingmarwat 3 года назад

    amaaaaaazing. teaching method. well done, awesome

  • @michalrv3066
    @michalrv3066 5 лет назад +4

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

  • @nsansa9234
    @nsansa9234 2 года назад +2

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

  • @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

  • @TheAiSaEr
    @TheAiSaEr 6 лет назад +2

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

  • @moritziseke9658
    @moritziseke9658 6 лет назад +2

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

    • @amrh4259
      @amrh4259 5 лет назад

      the same question

  • @LoldemortII
    @LoldemortII 3 года назад

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

  • @anthonyporter7390
    @anthonyporter7390 5 лет назад

    Third video i've watched today. Amazing work!

  • @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

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

  • @cs-ope
    @cs-ope Год назад

    You are an awesome guy my friend!

  • @JessintaFernandes
    @JessintaFernandes Год назад

    Thank you very much Sir, Great tutorial ...

  • @SabbathJoe89v2
    @SabbathJoe89v2 4 года назад

    Best video about the argument!!!

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

  • @ralphordanza3487
    @ralphordanza3487 5 лет назад

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

  • @dreb.7760
    @dreb.7760 2 года назад

    Great tutorial, many thanks

  • @asadmukhtar1
    @asadmukhtar1 5 лет назад +1

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

  • @heavysoccer7862
    @heavysoccer7862 6 лет назад

    Your tutorials are really very helpful. Thanks man.

  • @shrikantdevarmani9473
    @shrikantdevarmani9473 5 лет назад

    Understandable content with easy explanation. Ty

  • @savaramkiran
    @savaramkiran 6 лет назад

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

  • @roasters943
    @roasters943 Год назад

    Wonderful tutorial

  • @khanhsb15
    @khanhsb15 Год назад

    Thanks so much, it's helpful !

  • @dhivabanyuwigara7406
    @dhivabanyuwigara7406 5 лет назад +2

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

  • @gerardpalma8006
    @gerardpalma8006 3 года назад

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

  • @adibazhar1115
    @adibazhar1115 5 лет назад

    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 ?

  • @joshthiele8416
    @joshthiele8416 5 лет назад

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

  • @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

  • @Since1059
    @Since1059 4 года назад

    It's really good tutorial for learning thanks bro

  • @danildv2001
    @danildv2001 4 года назад

    Awesome tutorial!! Thank u!

  • @CiaphasCain21
    @CiaphasCain21 4 года назад

    Thanks! That was really helpful to me

  • @elpirato5428
    @elpirato5428 3 года назад

    thx, best short tutorial

  • @ashiqurrahmantahmid9634
    @ashiqurrahmantahmid9634 4 года назад

    Amazing ! It's so helpful

  • @samha1513
    @samha1513 6 лет назад +7

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

    • @ResoCoder
      @ResoCoder  6 лет назад +2

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

    • @samha1513
      @samha1513 6 лет назад

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

  • @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.

  • @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.

  • @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

  • @ezscootrr
    @ezscootrr 4 года назад

    Do you have tutorials for MVVM when using Firebase?

  • @soulduse
    @soulduse 6 лет назад

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

  • @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

  • @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

  • @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!!!

  • @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.

  • @md.naimurrahman2466
    @md.naimurrahman2466 2 года назад

    Just amazing!

  • @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

  • @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 :(

  • @VinayKumar-mb3ge
    @VinayKumar-mb3ge 5 лет назад

    keep adding more videos.Thanks

  • @cwssoftware3588
    @cwssoftware3588 5 лет назад

    Please create videos on testing

  • @CiaphasCain21
    @CiaphasCain21 4 года назад

    Thanks!! Your tutorial was realy helpful

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

  • @mohsenss8791
    @mohsenss8791 5 лет назад

    Thanks. I've learned so much.

  • @ziweiguo7821
    @ziweiguo7821 6 лет назад

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

  • @mankesh_mishra
    @mankesh_mishra 4 года назад

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

  • @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 =)

  • @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

  • @ProGaming-kb9io
    @ProGaming-kb9io 3 года назад +2

    ViewModelProvider(this, factory)

  • @voicheci007
    @voicheci007 6 лет назад

    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  6 лет назад

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

  • @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 !!!

  • @fabrizziocht
    @fabrizziocht 6 лет назад

    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?

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

  • @bricktop5403
    @bricktop5403 3 дня назад

    Using Fake database was a pretty bad idea here. Makes it so much confusing with terms QuoteDao, FakeDatabase, FakeQuoteDao

  • @kamala132
    @kamala132 6 лет назад

    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  6 лет назад

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

  • @sadzolot2
    @sadzolot2 5 лет назад

    Nice fonts in Android Studio , what`s name?

  • @sanaebadi97
    @sanaebadi97 5 лет назад

    do u have mvvm tutorial with java ?

  • @abdulhakeemmahmood5463
    @abdulhakeemmahmood5463 5 лет назад +1

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

  • @witoldsienski1709
    @witoldsienski1709 6 лет назад

    Very good video

  • @holofox66
    @holofox66 6 лет назад

    Thanks you. I wait this tutorial.

  • @cwssoftware3588
    @cwssoftware3588 5 лет назад

    can you make a video on testing

  • @ProjectNullTheGame
    @ProjectNullTheGame 5 лет назад

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

  • @pembatamang8233
    @pembatamang8233 5 лет назад

    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

  • @dogukangoktas693
    @dogukangoktas693 3 года назад

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

  • @АкимДанилов-к2е
    @АкимДанилов-к2е 4 года назад

    Thank you!!!

  • @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 :-\

  • @tigranbabajanyan842
    @tigranbabajanyan842 5 лет назад

    Why not used ROOM annotations?

  • @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.

  • @pembatamang8233
    @pembatamang8233 5 лет назад

    your Android Studio looks like Visual Studio

  • @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

  • @dentor2005
    @dentor2005 4 года назад

    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.

  • @tubebility
    @tubebility 6 лет назад

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

    • @tubebility
      @tubebility 6 лет назад

      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'_

  • @mohammadamirkanjoori138
    @mohammadamirkanjoori138 3 года назад

    nice

  • @vankans2267
    @vankans2267 5 лет назад

    great!!

  • @MinhTran-xn3kk
    @MinhTran-xn3kk 5 лет назад +1

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

  • @eesaaphilips9271
    @eesaaphilips9271 6 лет назад

    What theme are you using for the android studio ide?

  • @TikTokTrendsCompilation
    @TikTokTrendsCompilation 6 лет назад

    how do you have that dark theme of AS?

  • @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!