Jetpack DataStore is Google's newer recommended solution for key-value storage. If you're developing a new Android app, you should consider using it instead of SharedPreferences: developer.android.com/topic/libraries/architecture/datastore
somehow youtube recommended me this video which is awesome. i'm looking forward to see more videos from you, but in the meantime you got me as a subscriber.
Nice video! When i have to do a comparison of the sort you did between the Boolean and Float delegates, I'll copy one version into the clipboard, select the other version, and then use Compare Clipboard to Selection (I think thats the name, I'm on my phone away from my laptop!)
Thanks Sky Tech! Just to clarify - are you asking about using delegated properties with SQLite, or are you just asking for an explainer video about SQLite in general?
I've heard of Multiplatform Settings (github.com/russhwolf/multiplatform-settings), but I don't have any experience with it myself. It supports Android, iOS, macOS, watchOS, tvOS, JavaScript, JVM, and Windows - and looks like its API supports delegates. Might be worth checking out!
That can work in certain cases, like when you've got a generic with a type argument as a function parameter (or as a receiver on an extension function). In the example in this video, there just aren't any parameters that can be used to distinguish between the functions. In other words, the clash isn't just for the JVM platform; it's a clash in Kotlin, regardless of the platform you're targeting. It was a good thought, though!
Hey, Deepak, thanks for the suggestion! Just to clarify, are you looking for videos that explain the trade-offs between different design decisions? (e.g., "when should I use an extension function, and when should I use a delegate?")
Thanks for the information. How can I make my list automatically save to the shared preferences again when an item is removed or added to it? I have been struggling to find a solution for this problem. Thanks.
Hey, LG, thanks for asking! Is this a list of strings, where you're saving the whole list to SharedPreferences (e.g., using putStringSet()), or are you trying to save individual items of the list as individual values, or something else...? Creating your own implementation of `MutableList` is a likely option, but it might help to see some example code to understand your particular situation better.
@@typealias I would like to store a list of strings/ids (10-12 character long ones). dynamically add and remove from the list, search in the list for matching ID, and want them to be stored in the shared prefs all the time, as it is quite an important data I need during runtime. I was able to create the one you have, but this way I have to create and copy all existing items into a new list and assign it to my variable.
Okay, thanks. You could consider extending AbstractMutableSet with your own class, e.g., named SharedPreferencesSet. Its constructor could accept an instance of SharedPreferences and the key. It would also hold a private instance of an underlying mutable set. Then, the modification functions (e.g., add/remove/etc.) would be overridden to call the same function on the private instance _and also_ save the set to shared preferences. Would definitely need some good testing to make sure it works as expected. Hopefully the description above is enough to give you the idea, but if you need more info, just send me a direct message on X, LinkedIn, or Kotlin Slack.
Excellent explanation of delegates. However this is not really "easy" once you get past the initial version. SharedPrefs are quite easy to use--I fail to see the need for all this complicated code to do something that already works well and is straight-forward.
a good example of delegation in the very beginning of this video! but what goes after - is a sample of over-engineering, to my mind. I'm sorry for that, but this wrapping of SP leads only to useless complications of code with no real benefits. again - thanks for the video, this one, and for the content on this channel! you give really great lessons about Kotlin mastery! the line above concerns only the given approach to SP.
Hey Igor, I'm glad you've been enjoying the videos! I can certainly respect your conclusion that the first, simpler approach is adequate. It's fun to explore the possibilities, and getting to full type-safety is a nice idea, but not always worth the cost at the usage site. Got diminishing returns trying to get the last little bit of type safety on this one, for sure!
Thanks Dmytro! I was using the "Add Selection for Next Occurrence" keyboard shortcut for multiple cursors. Here's the documentation about it: www.jetbrains.com/help/idea/multicursor.html?#multiple_words
That's amazing Thank you Can we use delegation with Flow? (Kotlin Coroutines) Instead of return Flow we return the value Like the way collectAsState() works with in JetpackCompose I hope you understood me Keep going 👏
Hey, thanks Adam! If I understand right, you're looking for a way to use a delegated property to connect a Flow so that it always gives you the latest value when you evaluate it. If that's what you're looking for, I slapped together an example of that here: gist.github.com/djleeds/716f3acbd94b8e4367ab66ba403778d7 Keep in mind that I only have limited experience with Flow so far... so someone else might be able to comment on a better way to achieve this... or maybe the coroutines core library might even give us something similar to this out of the box... ?
Jetpack DataStore is Google's newer recommended solution for key-value storage. If you're developing a new Android app, you should consider using it instead of SharedPreferences: developer.android.com/topic/libraries/architecture/datastore
So much of in depth industry level knowledge in one video 🙌🏻 please continue uploading such videos
Thanks so much, Akash! I'll keep at it! 🙂
UA-cam lacks advance android knowledge like the one shown in your video. All the best :)
This was a great way to see delegates in action and also an interesting example of working with generics + reified. Thanks for putting it together!
You're most welcome, Jesse! I'm glad you liked it!
You are doing a great job, Dave! Bravo!
Thanks for the detailed explanation of different approaches. Expecting more videos from you on Kotlin programming.
You're most welcome! And yes, more videos coming!
best content on kotlin I've ever found, congrats! Please more!
Wow, thanks so much for the kind words!
great Explanation, just found your channel and subscribed immediately.
Hey, that's fantastic! Thank you so much!
I really liked the type video, nice work, going to check more!
Thanks Carlos! I've only created a handful of videos so far, but I'm glad to hear that you enjoyed this one!
Great video. Thanks for this! It would be interesting to see how you would unit test this code.
somehow youtube recommended me this video which is awesome. i'm looking forward to see more videos from you, but in the meantime you got me as a subscriber.
Sounds great, Andrei! Thanks for subscribing! 🙂
amazing video! You explained it concise and step by step, from easy to hard. Thanks a lot bro you inspired me a lot
Thanks so much Jack! 🙂
Nice video! When i have to do a comparison of the sort you did between the Boolean and Float delegates, I'll copy one version into the clipboard, select the other version, and then use Compare Clipboard to Selection (I think thats the name, I'm on my phone away from my laptop!)
Thanks Pete! Yeah, that's a handy feature! I love using it when I'm developing but it didn't occur to me to use it for the video! 😅
This is really great content! I already learned so much. I wish you all the best and hope you will make more videos 🙂
Thank you so much. I'm glad to hear! And yes, more videos will be coming!
Very interesting and good presentation of the material. Keep up the good work. Good luck! subscription
Many thanks, Мaikl!
As usual, a great video 👍
Thanks so much! Glad you enjoyed it! 🙂
This is incredible. Thank you!
You're most welcome, Derek! Thanks for your kind words!
So insightful!
That was super informative, Thank you!
You're most welcome! Glad you enjoyed it!
One of the best explainer videos! something like this for a Sqlite Database !?
Thanks Sky Tech! Just to clarify - are you asking about using delegated properties with SQLite, or are you just asking for an explainer video about SQLite in general?
Love your videos ❤
Thanks so much, Rajesh! 🙂
Amazing video as always. I was wondering if there is something similar that is not specific to Android?
I've heard of Multiplatform Settings (github.com/russhwolf/multiplatform-settings), but I don't have any experience with it myself. It supports Android, iOS, macOS, watchOS, tvOS, JavaScript, JVM, and Windows - and looks like its API supports delegates. Might be worth checking out!
Just awesome 🎉
Hey, thanks so much, Muhammad! I appreciate that!
Really nice and helpful idea
Thanks so much! I'm glad you like it!
Great video, please make more video
Thanks so much! More videos are on the way!
For the overloading of getters problem, would @JvmName be an appropriate solution?
That can work in certain cases, like when you've got a generic with a type argument as a function parameter (or as a receiver on an extension function). In the example in this video, there just aren't any parameters that can be used to distinguish between the functions. In other words, the clash isn't just for the JVM platform; it's a clash in Kotlin, regardless of the platform you're targeting. It was a good thought, though!
Could you make videos on Difference between videos like -> Extension fun vs Delegates
Hey, Deepak, thanks for the suggestion! Just to clarify, are you looking for videos that explain the trade-offs between different design decisions? (e.g., "when should I use an extension function, and when should I use a delegate?")
@@typealias Yes, it will help us to get deeper knowledge(may be for interview purpose)
Great, thanks again! 👍
Thanks for the information. How can I make my list automatically save to the shared preferences again when an item is removed or added to it? I have been struggling to find a solution for this problem. Thanks.
Hey, LG, thanks for asking! Is this a list of strings, where you're saving the whole list to SharedPreferences (e.g., using putStringSet()), or are you trying to save individual items of the list as individual values, or something else...? Creating your own implementation of `MutableList` is a likely option, but it might help to see some example code to understand your particular situation better.
@@typealias I would like to store a list of strings/ids (10-12 character long ones). dynamically add and remove from the list, search in the list for matching ID, and want them to be stored in the shared prefs all the time, as it is quite an important data I need during runtime. I was able to create the one you have, but this way I have to create and copy all existing items into a new list and assign it to my variable.
Okay, thanks. You could consider extending AbstractMutableSet with your own class, e.g., named SharedPreferencesSet. Its constructor could accept an instance of SharedPreferences and the key. It would also hold a private instance of an underlying mutable set. Then, the modification functions (e.g., add/remove/etc.) would be overridden to call the same function on the private instance _and also_ save the set to shared preferences. Would definitely need some good testing to make sure it works as expected.
Hopefully the description above is enough to give you the idea, but if you need more info, just send me a direct message on X, LinkedIn, or Kotlin Slack.
make one video with sharefPreferences in fragment without to user Activity.
Amazing!
nice!!!
Forgive me are u somehow related to sheldon cooper? P/s great vid thanks
Haha, I'm tall and slender, but not nearly smart enough to be related to Sheldon! Glad you enjoyed the video!
Excellent explanation of delegates. However this is not really "easy" once you get past the initial version. SharedPrefs are quite easy to use--I fail to see the need for all this complicated code to do something that already works well and is straight-forward.
🔥
whoa
a good example of delegation in the very beginning of this video!
but what goes after - is a sample of over-engineering, to my mind. I'm sorry for that, but this wrapping of SP leads only to useless complications of code with no real benefits.
again - thanks for the video, this one, and for the content on this channel! you give really great lessons about Kotlin mastery! the line above concerns only the given approach to SP.
Hey Igor, I'm glad you've been enjoying the videos! I can certainly respect your conclusion that the first, simpler approach is adequate. It's fun to explore the possibilities, and getting to full type-safety is a nice idea, but not always worth the cost at the usage site. Got diminishing returns trying to get the last little bit of type safety on this one, for sure!
Man, you are a wizard! How to do that? ua-cam.com/video/KFgb6l1PUJI/v-deo.html
Thanks Dmytro! I was using the "Add Selection for Next Occurrence" keyboard shortcut for multiple cursors. Here's the documentation about it: www.jetbrains.com/help/idea/multicursor.html?#multiple_words
That's amazing
Thank you
Can we use delegation with Flow? (Kotlin Coroutines)
Instead of return Flow we return the value
Like the way collectAsState() works with in JetpackCompose
I hope you understood me
Keep going 👏
Hey, thanks Adam! If I understand right, you're looking for a way to use a delegated property to connect a Flow so that it always gives you the latest value when you evaluate it. If that's what you're looking for, I slapped together an example of that here: gist.github.com/djleeds/716f3acbd94b8e4367ab66ba403778d7
Keep in mind that I only have limited experience with Flow so far... so someone else might be able to comment on a better way to achieve this... or maybe the coroutines core library might even give us something similar to this out of the box... ?
if I am not mistaken Mutablestateflow.collectAsState() does that