Easy SharedPreferences with Delegated Properties in Kotlin

  Рет қаралды 8,595

Dave Leeds

Dave Leeds

Күн бұрын

Пікірлер: 70
@typealias
@typealias 6 ай бұрын
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
@akashkhatkale1149
@akashkhatkale1149 2 жыл бұрын
So much of in depth industry level knowledge in one video 🙌🏻 please continue uploading such videos
@typealias
@typealias Жыл бұрын
Thanks so much, Akash! I'll keep at it! 🙂
@akashkhatkale1149
@akashkhatkale1149 Жыл бұрын
KZbin lacks advance android knowledge like the one shown in your video. All the best :)
@shubhamnanche
@shubhamnanche 2 ай бұрын
You are doing a great job, Dave! Bravo!
@jessehill4658
@jessehill4658 2 жыл бұрын
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!
@typealias
@typealias 2 жыл бұрын
You're most welcome, Jesse! I'm glad you liked it!
@wagnerarcieri
@wagnerarcieri Жыл бұрын
best content on kotlin I've ever found, congrats! Please more!
@typealias
@typealias Жыл бұрын
Wow, thanks so much for the kind words!
@vengateshm2122
@vengateshm2122 Жыл бұрын
Thanks for the detailed explanation of different approaches. Expecting more videos from you on Kotlin programming.
@typealias
@typealias Жыл бұрын
You're most welcome! And yes, more videos coming!
@Carlos-xz9zq
@Carlos-xz9zq 2 жыл бұрын
I really liked the type video, nice work, going to check more!
@typealias
@typealias 2 жыл бұрын
Thanks Carlos! I've only created a handful of videos so far, but I'm glad to hear that you enjoyed this one!
@behnamahmadi2834
@behnamahmadi2834 7 ай бұрын
great Explanation, just found your channel and subscribed immediately.
@typealias
@typealias 7 ай бұрын
Hey, that's fantastic! Thank you so much!
@AndreiBacalu
@AndreiBacalu Жыл бұрын
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.
@typealias
@typealias Жыл бұрын
Sounds great, Andrei! Thanks for subscribing! 🙂
@Namesake..
@Namesake.. 20 күн бұрын
Great video. Thanks for this! It would be interesting to see how you would unit test this code.
@jackli1924
@jackli1924 Жыл бұрын
amazing video! You explained it concise and step by step, from easy to hard. Thanks a lot bro you inspired me a lot
@typealias
@typealias Жыл бұрын
Thanks so much Jack! 🙂
@h4m74ro
@h4m74ro Жыл бұрын
This is really great content! I already learned so much. I wish you all the best and hope you will make more videos 🙂
@typealias
@typealias Жыл бұрын
Thank you so much. I'm glad to hear! And yes, more videos will be coming!
@waelalghamdi5298
@waelalghamdi5298 2 жыл бұрын
As usual, a great video 👍
@typealias
@typealias 2 жыл бұрын
Thanks so much! Glad you enjoyed it! 🙂
@aiklklivlind9451
@aiklklivlind9451 Жыл бұрын
Very interesting and good presentation of the material. Keep up the good work. Good luck! subscription
@typealias
@typealias Жыл бұрын
Many thanks, Мaikl!
@PeteC62
@PeteC62 5 ай бұрын
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!)
@typealias
@typealias 5 ай бұрын
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! 😅
@derekdevs
@derekdevs Жыл бұрын
This is incredible. Thank you!
@typealias
@typealias Жыл бұрын
You're most welcome, Derek! Thanks for your kind words!
@aungkhanthtoo7678
@aungkhanthtoo7678 7 ай бұрын
So insightful!
@BewareOfStinger
@BewareOfStinger 5 ай бұрын
Amazing video as always. I was wondering if there is something similar that is not specific to Android?
@typealias
@typealias 5 ай бұрын
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!
@etherxi
@etherxi 11 ай бұрын
Really nice and helpful idea
@typealias
@typealias 11 ай бұрын
Thanks so much! I'm glad you like it!
@skytech2501
@skytech2501 2 жыл бұрын
One of the best explainer videos! something like this for a Sqlite Database !?
@typealias
@typealias 2 жыл бұрын
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?
@MuhammadAwais-hc6ry
@MuhammadAwais-hc6ry 2 ай бұрын
Just awesome 🎉
@typealias
@typealias 2 ай бұрын
Hey, thanks so much, Muhammad! I appreciate that!
@rajeshpattanaik6597
@rajeshpattanaik6597 Жыл бұрын
Love your videos ❤
@typealias
@typealias Жыл бұрын
Thanks so much, Rajesh! 🙂
@mdisi5967
@mdisi5967 Жыл бұрын
That was super informative, Thank you!
@typealias
@typealias Жыл бұрын
You're most welcome! Glad you enjoyed it!
@ztao3907
@ztao3907 8 ай бұрын
nice!!!
@safionweb
@safionweb Жыл бұрын
Amazing!
@rohitjakhar6672
@rohitjakhar6672 Жыл бұрын
Great video, please make more video
@typealias
@typealias Жыл бұрын
Thanks so much! More videos are on the way!
@lg.studio
@lg.studio 9 ай бұрын
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.
@typealias
@typealias 9 ай бұрын
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.
@lg.studio
@lg.studio 9 ай бұрын
@@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.
@typealias
@typealias 8 ай бұрын
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.
@cal1314
@cal1314 6 ай бұрын
For the overloading of getters problem, would @JvmName be an appropriate solution?
@typealias
@typealias 6 ай бұрын
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!
@deepakshah3108
@deepakshah3108 Жыл бұрын
Could you make videos on Difference between videos like -> Extension fun vs Delegates
@typealias
@typealias Жыл бұрын
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?")
@deepakshah3108
@deepakshah3108 Жыл бұрын
@@typealias Yes, it will help us to get deeper knowledge(may be for interview purpose)
@typealias
@typealias Жыл бұрын
Great, thanks again! 👍
@lglf77
@lglf77 Жыл бұрын
make one video with sharefPreferences in fragment without to user Activity.
@roman3249
@roman3249 Жыл бұрын
🔥
@scottbiggs8894
@scottbiggs8894 5 ай бұрын
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.
@TerryQuiet
@TerryQuiet Жыл бұрын
whoa
@mohamednizam5298
@mohamednizam5298 Жыл бұрын
Forgive me are u somehow related to sheldon cooper? P/s great vid thanks
@typealias
@typealias Жыл бұрын
Haha, I'm tall and slender, but not nearly smart enough to be related to Sheldon! Glad you enjoyed the video!
@igorshaula9097
@igorshaula9097 5 ай бұрын
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.
@typealias
@typealias 5 ай бұрын
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!
@dmytroberezhnyi717
@dmytroberezhnyi717 Жыл бұрын
Man, you are a wizard! How to do that? kzbin.info/www/bejne/gXfKk2miZrWIgKs
@typealias
@typealias Жыл бұрын
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
@Adam0001
@Adam0001 2 жыл бұрын
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 👏
@typealias
@typealias 2 жыл бұрын
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... ?
@ahmedel-hady3249
@ahmedel-hady3249 7 ай бұрын
if I am not mistaken Mutablestateflow.collectAsState() does that
5 Fun Ways to Use Extension Functions in Kotlin
18:46
Dave Leeds
Рет қаралды 12 М.
Kotlin Code Reuse: Composing like you're Inheriting
14:42
Dave Leeds
Рет қаралды 10 М.
Try Not To Laugh 😅 the Best of BoxtoxTv 👌
00:18
boxtoxtv
Рет қаралды 7 МЛН
бабл ти гель для душа // Eva mash
01:00
EVA mash
Рет қаралды 6 МЛН
Wait for the last one 🤣🤣 #shorts #minecraft
00:28
Cosmo Guy
Рет қаралды 22 МЛН
Applying the State Pattern in Kotlin
12:55
Dave Leeds
Рет қаралды 6 М.
Kotlin Multiplatform vs Flutter: Which should we use?
4:42
Kei Fujikawa
Рет қаралды 25 М.
95% Don't Understand THIS About Coroutines (Main-Safety)
9:38
Philipp Lackner
Рет қаралды 30 М.
Coroutines: Concurrency in Kotlin
30:22
Dave Leeds
Рет қаралды 14 М.
The Flaws of Inheritance
10:01
CodeAesthetic
Рет қаралды 963 М.
Learn .NET MAUI - Full Course for Beginners | Build cross-platform apps in C#
4:08:53
Data Analysis with Python for Excel Users - Full Course
3:57:46
freeCodeCamp.org
Рет қаралды 2,9 МЛН
Three Simple Rules for Subtypes
13:52
Dave Leeds
Рет қаралды 2,7 М.
Fundamentals of Compose Layouts and Modifiers - MAD Skills
11:56
Android Developers
Рет қаралды 99 М.