Kotlin Sealed Classes & Custom State Managment (VLog)

Поділитися
Вставка
  • Опубліковано 15 жов 2024

КОМЕНТАРІ • 126

  • @brandon_iceberg
    @brandon_iceberg 4 роки тому +31

    Would love to see more more on Sealed Classes, keep up the good work!

  • @karthikss6501
    @karthikss6501 4 роки тому +6

    More than a sealed class explanation, man I liked the way you used lifecycle owner in adapter viewholder...great work...keep it up🔥🔥🔥

  • @DaroltiDan
    @DaroltiDan 4 роки тому

    got to say, i was a bit confused by your implementation of selected items, but after i tried it (tweaked it a bit for my benefits) I can say it works really well. thank you!

  • @gurupreetsingh6751
    @gurupreetsingh6751 4 роки тому +5

    Man I am fan of Sealed classes. Using it for all kind of Result handling.

    • @goobar
      @goobar 4 роки тому

      Same here. They're one of my favorite Kotlin features

  • @adil_k
    @adil_k 4 роки тому +1

    Would love to see in-depth tutorial on Sealed Classes because nobody can do it better than you. Eagerly waiting!

  • @muhammadomersaleem4919
    @muhammadomersaleem4919 2 роки тому

    Awesome man. I liked the way you manage states using and selection using lifecycle owner and LiveData. I would like to see videos on how you try to break your code. Please make a video on this topic as well.

  • @foreverrafs
    @foreverrafs 4 роки тому

    I love this approach so much that, I decided to make my listinteraction a generic class so that I can pass any Model to it and also added selectAll() to it. I love you Mitch ❤️

  • @smithshelke2036
    @smithshelke2036 4 роки тому +2

    If you observe selectedNotes in the bind method then it will be called several number of times each time you scroll. So the better practice would be to observe it in the constructor of the viewholder class. Then it will only be called when the onCreateViewHolder method is called.

  • @TheSaver23
    @TheSaver23 4 роки тому +1

    mitch your videos/vlogs are becoming really really good, well done, keep em coming :D

  • @GakisStylianos
    @GakisStylianos 4 роки тому +14

    This darn CodingInFlow guy can not keep getting away with this!

  • @ChrisAthanas
    @ChrisAthanas 3 роки тому

    This is even better the second time

  • @niazsagor
    @niazsagor 3 роки тому

    this is pure gem mitch!

  • @cdmunoz
    @cdmunoz 4 роки тому +1

    Hi Mitch, congrats for all the stuff and effort sharing knowledge and ty very much. One question regarding passing lifeCycleOwner and the list to the adapter and view holder: I think that this violates the principle of single responsibility of RV's adapter (to create and binding data), but it's just a thought, what do you think about it? ... anyway it's a clever way to solve a problem

  • @Since1059
    @Since1059 4 роки тому +4

    Would like to see some more videos and realtime examples on sealed classes

  • @arunkumarka1809
    @arunkumarka1809 3 роки тому

    Great work buddy. Go ahead. It helped us a lot to learn all the Kotlin stuff.

  • @Forke13
    @Forke13 4 роки тому

    Hey Mitch, I like the style of this vlog series a lot. Following the process of someone figuring out stuff is nice :)
    I've got a comment on the recycler view stuff: Did you play around with ListAdapter yet? It comes with some convenience funcitons like updating the current data set and a DiffUtil, which checks for which rows are now abesnt, new or just have changed their content and only refreshes them.
    That in conjuction with not the raw data "note", but more like state objects as list items for the adapter containing properties for "selected" streamlined things up for me in the past.
    If using that you would provide a LiveData Object with a list of NoteItems, which hold the note and the state.

    • @codingwithmitch
      @codingwithmitch  4 роки тому +1

      Yes I have. I prefer to setup diffutil myself like I have here. Listadapter does the same thing but I think it looks more complex

  • @matthewnelson1862
    @matthewnelson1862 4 роки тому +2

    Sealed classes are wonderful! My only issue with them (enums suffer from this as well) are that they dramatically increase the apk size. I much prefer to use custom @IntDef or @StringDef if all you're trying to do is distinguish between states; the compiled code is MUCH smaller, while readability does not suffer.

  • @ozgurtas4508
    @ozgurtas4508 4 роки тому

    i super liked your logic in the viewholder :D and im also a big fan of the livedata :)

  •  4 роки тому +1

    Hey Mitch your explanations are awesome! I really like this channel. Thanks for your work

  • @ronaldosanches1605
    @ronaldosanches1605 4 роки тому +1

    dude your content is really good, I learn so much from you

  • @Tech-To-Logic
    @Tech-To-Logic 4 роки тому +1

    Thanks, Mitch for this video... I didn't watch yet. I feel to say thanks to you before I watch it. I really like your presentation style. Whatever you said in your video, I understand very clearly.

  • @BapeRuLLZ
    @BapeRuLLZ 2 роки тому +1

    Hey Mitch, great video! I was wondering whether it would be better to pass the viewmodel to the adapter as a constructor argument, because that way the adapter could directly call the viewmodel without going through the fragment with the interaction interface. It would also mean one less constructor argument for the adapter. The other thing I'm wondering is whether it would be better to observe the selectedNotes livedata separatly from the viewholder and somehow change the adapter items from there? In your implementation there is an observer for every single item and all of them get called on any selection change and all of them have to iterate through the entire list of selected items. If you have a recyclerview with for example 200 items and you have 100 of them selected and you select another, then the code would iterate through a 100 item list 200 times (= 20.000) which doesn't seem ideal. This might still be the cleanest solution, just a tought.

  • @buzzminkyunghoon3856
    @buzzminkyunghoon3856 4 роки тому +2

    This vlog was great. Easy to understand.
    Did you really inserted 1000 items, is there a way to insert it in bulk?

    • @codingwithmitch
      @codingwithmitch  4 роки тому +3

      Just made a loop that ran 1000 times. Then removed it

  • @starlite5097
    @starlite5097 4 роки тому +2

    I actually discovered you from the Coding in Flow channel, so he also helps you :D

  • @faisalnaseer798
    @faisalnaseer798 3 роки тому

    ahan I was thinking what I should write as you asked for comment... so Love you Mitch .. I have learned a lot from you bro

  • @ЛёхаБодунов-б7ж
    @ЛёхаБодунов-б7ж 3 роки тому

    You can also replace when statement with a polymorphism and incapsulate your logic inside of the state to implement state pattern. In your app those sealed classes are just like enums.

  • @tomvarga982
    @tomvarga982 4 роки тому +1

    Top channel for android

  • @jjhoninatan55sabadi
    @jjhoninatan55sabadi 4 роки тому +1

    I liked to use sealed class to pass firebase data state to activity. I used Google pattern with Resource class and Success, Loading and Failure sub classes, it worked well

  • @erlanamanatov2962
    @erlanamanatov2962 4 роки тому +1

    This kind of videos are very useful. Thanks for sharing knowledge

  • @armandoavila4615
    @armandoavila4615 4 роки тому +1

    Great video, Mitch! Keep them coming. I like your content far better than CodingInFlow 💪. Oh, also I think you can use "object" insted of "class" on the sub classes of your sealed class if they're not holding any state.

    • @codinginflow
      @codinginflow 4 роки тому +7

      wow

    • @armandoavila4615
      @armandoavila4615 4 роки тому

      @@codinginflow Hahaha, I also watch and like your content, but don't tell Mitch 👀. Your last two building your app with Clean Architecture are really cool, keep them coming too.

    • @goobar
      @goobar 4 роки тому +2

      I wasn't planning on pointing it out since it wasn't really the point of the video, but I second this comment about using an object declaration if the sealed class type doesn't take any unique data. It basically becomes an enum type at that point which makes referencing it slightly easier and overall more memory efficient I think (though that's quite minor)

  • @johnnybegood8669
    @johnnybegood8669 4 роки тому

    Cool design! But is there really a reason to create sealed classes in this particular case? I mean you could've just used two int constants to keep track of the current state and change UI accordingly. Sealed classes are great when you need to delegate some functionality to the state classes with the same interface.

  • @pascallopez6771
    @pascallopez6771 3 роки тому

    So yes Mitch, please talk us about sealed classes :0D

  • @kumarshubham2812
    @kumarshubham2812 4 роки тому +1

    Don't worry sir!! You are the best!

  • @kravets_coding
    @kravets_coding 3 роки тому

    13:06 Hi. Grateful for videos and I'm curious about this observe-in-adapter approach. Is there a problem or I miss something.
    In short, each time when "selectedNotes.observe" is called new instance of Observer is created and will be destroyed only when lifecycleOwner is Destroyed. Plus, Observer (as an instance of anonymous class under the hood) keeps reference to the "note" and "itemView". This can cause tricky behavior in the future when the ViewHolders are being reused.
    =======
    In Details.
    1. Too many useless object are allocated (new Observer for each ViewHolder.bind)
    Let`s say user have 100 items. When user open the screen, only 10 are visible, so 10 ViewHolders are created and each observes LiveData with new Observer instance.
    Then user scrolls 10 elements more, so these 10 ViewHolders were reused and liveData gets new Observer instances.
    As a result the liveData has 20 observers, even though you have only 10 visible ViewHolders. Because old Observers will be removed only when livecycleOwner is Destroyed.
    2. Each Observer instance keeps the "note" and "itemView" reference inside which can cause tricky behavior
    If point 1 is correct and there are much more Observer instances in memory than visible ViewHolders - then it can be the following case:
    ViewHolder1 instance were used to present Note1. After awhile user scroll down and eventually returns to the Note1 again. So another instance, lets say, ViewHolder 6 now presents Note1. Note: now we have in memory two Observers instances and both keep references to the same "note" but different "itemView". Note1 is selected so LiveData notifies its observers. Current ViewHolder Observer is invoked and make the itemView color to Grey - which is ok. And old Observer instance also gets notified, it has a reference to the Note1 so it change color of its current "itemView" to grey - which is now correct. Because this "itemView" is used now to present, for example, Note 3.

  • @smithshelke2036
    @smithshelke2036 4 роки тому +2

    If you pass in the viewLifecycleOwner into your adapter, wouldn't it cause a memory leak ?? Because if you use a method in viewLifecycleOwner, and before that method returns the device is rotated and the activity is destroyed but not the viewLifecycleOwner so that method will still be able to return causing a memory leak. Please correct me if i'm wrong

  • @hosseinmirzazadeh290
    @hosseinmirzazadeh290 4 роки тому

    Hey Mitch. We would love to see a tutorial on Kotlin Sealed Classes. We'd be grateful.

  • @jensbeyer951
    @jensbeyer951 3 роки тому

    @CodingWithMitch you should draw on your desktop while explaining code, it' more simple to follow. I mean something like a small overview what you're doing and where the glue is between those. I always try to comprehend with drawing after a video like this. I'm not a professional tuber but I use this too simple tool called "NittiTre WhiteBoard". Hopefully you will find a better one for windows. I'm a programmer and have learned to think with a whiteboard, when the problem and information overwhelmes me. Though I think the best skill to have a vision is to draw as less as possible to get an overview about relation, which is not taught in general.

  • @watdehan
    @watdehan 4 роки тому +2

    Hey mitch, just recently found your channel and I'm loving how easily it is for me to understand your explanation. And especially loving all these vlog series!

  • @kaustubhpatange
    @kaustubhpatange 4 роки тому +1

    Dude that's just amazing!

  • @mdad2947
    @mdad2947 4 роки тому +1

    Thanks for such a great video 👍🏻👍🏻👍🏻

  • @leonardosibela
    @leonardosibela 4 роки тому

    I see in many videos a "when statement" being used inside the view, but I'm not sure if it's just normal or something that I should avoid (alongside ifs, fors, etc) because they should be on the ViewModel. Any thoughts on that?

  • @mahdim4383
    @mahdim4383 4 роки тому

    Hi. I have a question. Do you recommend using databinding with MVVM at all?

  • @kmkole86
    @kmkole86 4 роки тому

    is there any reason why you havent done it with diff util and the onBindViewHolder(ViewHolder, int, List) that caries the payload (List), so you do not have to rebind whole view holder just its small part, like a background color, like button etc.

  • @charlien759
    @charlien759 4 роки тому +1

    Any advantage of having that extra manager class and not having that logic in your ViewModel?

  • @sanaebadi97
    @sanaebadi97 4 роки тому +1

    was nice , if u can create more about kotlin

  • @AhmedSamir-bu2in
    @AhmedSamir-bu2in 4 роки тому +1

    Please make more videos about it

  • @mdjahidulislam9205
    @mdjahidulislam9205 4 роки тому

    Please do make video on sealed class . How to manage state

  • @hellosagar
    @hellosagar 4 роки тому

    Love to see examples on this

  • @ashishkmr
    @ashishkmr 4 роки тому +1

    Loved your video ♥️

  • @ashtadirani3120
    @ashtadirani3120 4 роки тому

    i would love to hear the sealed classes video from you sir

  • @rajdeepgoswami744
    @rajdeepgoswami744 4 роки тому +1

    Please make a video on Sealed class and create a sample app

  • @andrefilgueiras
    @andrefilgueiras 4 роки тому

    Awesome video!

  • @stachulec
    @stachulec 4 роки тому

    why not coop with CodingInFlow? it's UA-cam, not console exclusives, you can enjoy both rather than fanboy one

  • @BelokonRoman
    @BelokonRoman 4 роки тому

    Hi Mitch,
    Advice how to improve your adapter:
    selectedNotes.observe(... { notes ->
    val isNoteSelected = notes?.contains(note) == true
    itemView.changeClor(
    newColor = if (isNoteSelected) COLOR_GRAY else COLOR_PRIMARY
    )
    }
    In my opinion it is much more readable
    Also I will explain why this approach is not good(i would even say bad approach):
    on each bind you create a new Observer, which will actively listen to the LiveData until the view will not be destroyed. Le's say you have 100 Notes in the list. If you scroll to the bottom of the list - you will have 100 Observerds, then if you scroll back to the top - you will have 200 Observers, and so on. And now on each item select\unselect the LiveData will trigger all this observers to work, and each of them will try to find a Note in the list of 100 Notes... and all this on the UI thread. Here your solution may start to lag

    • @codingwithmitch
      @codingwithmitch  4 роки тому

      I thought that too. But like I said I inserted 1000. Scrolled up and down. Selected, unselected, basically did a bunch of interaction. And no lag. Worked perfectly 🤷‍♂️

    • @BelokonRoman
      @BelokonRoman 4 роки тому +1

      ​@@codingwithmitch Yes, maybe it works. But it also may be that it will start to lag on some low-end devices. You should understand that you create hundreds or thousands of unneeded subscriptions so this approach is not good. And there is an easy way how to avoid it and improve performance

  • @starlite5097
    @starlite5097 4 роки тому

    Nice video, I would like to learn how to use sealed classes in my project.

  • @orwakassab8326
    @orwakassab8326 3 роки тому

    Great work, thanks

  • @loklok2003
    @loklok2003 4 роки тому +1

    thx for sharing, I like your video

  • @foreverrafs
    @foreverrafs 4 роки тому +2

    Codinginflow crisis part 2😵😵😵😵😵

  • @vishalg0210
    @vishalg0210 4 роки тому

    Hi can you give me a suggestion, a friend of mine asked me to create an e commerce app for android they dont have any setup.I am thinking of using firebase as backend and develop the app .what is your take on this. Open to all suggestions

    • @codingwithmitch
      @codingwithmitch  4 роки тому +1

      Firebase is great if you don't have any web dev or server backend experience. But I always prefer a using a server that your actually own.

  • @onwukadaniel3387
    @onwukadaniel3387 2 роки тому

    You are the real gee.

  • @pawemuniak634
    @pawemuniak634 4 роки тому

    Hello, cool videos there :)
    Have you tried setting view state in xml file via custom parameter with data binding? You keep state as a single livedata in your vm, lets u clean fragment class off a lot of code :)

    • @codingwithmitch
      @codingwithmitch  4 роки тому +1

      Not a fan of data binding

    • @pawemuniak634
      @pawemuniak634 4 роки тому

      @@codingwithmitch Why is that? Are there some big cons or you just didnt dive into it deep enough yet?

    • @codingwithmitch
      @codingwithmitch  4 роки тому +2

      @@pawemuniak634 I don't think the added complexity is worth what it does. View binding is great. But other than that having to make all these adapters and put logic in the XML is not my favorite thing.

  • @aabhishek4911
    @aabhishek4911 4 роки тому

    Hi Mitch ,
    Will you create a course for this application in your website ?

  • @ahmedhegazy8452
    @ahmedhegazy8452 4 роки тому

    Please, Give more samples for sealed

  • @warm-sweater-123
    @warm-sweater-123 4 роки тому

    Is there a specific reason you chose to use a sealed class over an enum for your use case?

    • @codingwithmitch
      @codingwithmitch  4 роки тому +1

      Could have used enum in this case. Would have been the same.

    • @revm4942
      @revm4942 4 роки тому

      When statement haha

  • @sagarock1012
    @sagarock1012 4 роки тому +1

    Awesome

  • @jagadhisshdeveloper1689
    @jagadhisshdeveloper1689 4 роки тому

    sir please do course project kotlin mvvm hilt retrofit compleate token based authentication sir

  • @pembatamang8233
    @pembatamang8233 4 роки тому

    florian is getting ready to show his face

  • @mkroven
    @mkroven 4 роки тому +1

    Coding in flow is at Instagram too. U may consider opening an account there. Many people including me see his inst posts and forwarded to his channel. Of course ur vids deserves better and a bit advanced compared to his topics.

  • @AntonioGonzalezsanchez
    @AntonioGonzalezsanchez 4 роки тому

    I gave that video a comment, youtube algorithm loves comments.

  • @ianmubangizi6721
    @ianmubangizi6721 4 роки тому +4

    Mitch you're great, but CodingInFlow has that accent 😂

  • @abhinavkumar17
    @abhinavkumar17 4 роки тому

    You are awesome!!

  • @realityandtruth9662
    @realityandtruth9662 3 роки тому

    sir please about class delegation

  • @sidique5269
    @sidique5269 4 роки тому +1

    Mitch when you type for search ..I saw wtf😁

  • @jagadhisshdeveloper1689
    @jagadhisshdeveloper1689 4 роки тому

    super and thanks sir

  • @abhinavchauhangujjar6456
    @abhinavchauhangujjar6456 4 роки тому

    *Can anyone tell* can i just keep going with java for android, it took my too much time and effort to learn core java, collections, streams, functional programming in java, and other java stuff, and now there is new language called kotlin which people recommends for android development but if i go with it my java knowledge if i am not wrong will be wasted and i will be like *"why did i learn java? if i knew kotlin is better i would have never learn that much java stuff i would have started with kotlin only"* or maybe flutter, is kotlin rendering java useless for new android developers and in future is flutter going to render kotlin useless.

    • @Forke13
      @Forke13 4 роки тому +1

      Your Java knowledge will actually help you. Kotlin fastens up development though. Learning more than one language is inevitable for a developer in the end anyways. And it will give you more thinking perspectives, which enhances your problem solving abilities. Go for it!

    • @abhinavchauhangujjar6456
      @abhinavchauhangujjar6456 4 роки тому

      @@Forke13 thanks for your valueable answer, i was also worried about , the time by which i will get a grip of kotlin the flutter /reactnative etc will take over the development and then i will have to learn dart/Javascript

    • @codingwithmitch
      @codingwithmitch  4 роки тому +1

      Kotlin is basically the same as java. Your knowledge of Java is a good thing to have

    • @abhinavchauhangujjar6456
      @abhinavchauhangujjar6456 4 роки тому

      @@codingwithmitch thanks for the answer mitch, will you please aslo reply for my comments above, one that was for Forke K

    • @pxnx
      @pxnx 4 роки тому +1

      @@codingwithmitch Kotlin is Java in Mobile-optimized and with a bit of Steroids

  • @ericgacoki2225
    @ericgacoki2225 3 роки тому

    😊 16:17 Yeah, I see W at the top (wtf)

  • @savin1999
    @savin1999 4 роки тому +2

    So less code to do so much stuff 😬

  • @HienNguyen-xn7tr
    @HienNguyen-xn7tr 4 роки тому

    oh wow

  • @hasanzolfagharipour
    @hasanzolfagharipour 3 роки тому

    very nice

  • @lovishjain5002
    @lovishjain5002 4 роки тому

    Better use data binding

  • @karanvs4298
    @karanvs4298 4 роки тому

    Hey Mitch, very informative tutorial. Keep it up with the videos. Just want to mention that the real advantage of sealed classes in your code would be when you add another view state and compiler automatically detects that there is type case missing in when statement. For that to happen you will need to use extension function in your when statement just like mentioned here, ua-cam.com/video/OyIRuxjBORY/v-deo.html. For your use case, you could have used enum class as well since there is no additional information you need in viewstate except the type.

  • @Zeeshan-Syed
    @Zeeshan-Syed 4 роки тому

    Coding in Flow be like: Hahahaha (Evil laugh) 😈👹

  • @codingwithsam4992
    @codingwithsam4992 2 роки тому

    Sad to see his subscribers now reaching 2 lack 🤣🤣, well thanks not just for tutorials, but also for Coding in Flow 😂

  • @RookSoto
    @RookSoto 4 роки тому +1

    We open-sourced our in-house MVI implementation. It plays really nicely with sealed classes. If interested, Google: WW Roxie

  • @ChrisAthanas
    @ChrisAthanas 3 роки тому

    Engagement

  • @magicvide0
    @magicvide0 Рік тому +1

    Down voted. Title was “sealed classses” but didn’t get to it until 8 mins in. Then proceeds to read and show the kotlin documentation.

  • @bryanneuberger5886
    @bryanneuberger5886 3 роки тому

    engagement

  • @zayphyo1367
    @zayphyo1367 4 роки тому

    sealed class ..

  • @Shad0wB0X3r
    @Shad0wB0X3r 4 роки тому

    real men wear pink.....and uses sealed classes

  • @Tech-To-Logic
    @Tech-To-Logic 4 роки тому

    Mitch, quite disappointed with this video. You are focus on other staff other than the sealed class.

  • @gofudgeyourselves9024
    @gofudgeyourselves9024 4 роки тому

    We need sealed classes demo video

  • @freedomchuks
    @freedomchuks 4 роки тому +1

    Would love to see more more on Sealed Classes, keep up the good work!