RecyclerView with DiffUtil - MVVM News App

  Рет қаралды 37,527

Philipp Lackner

Philipp Lackner

Күн бұрын

Пікірлер: 76
@Traffic_Pro
@Traffic_Pro 6 ай бұрын
Hey Philipp brother you helped me a lot by showing how to use DiffUtil. Thank you so much🙌
@matt-g-recovers
@matt-g-recovers 3 жыл бұрын
I Gotta say I love this part, such a good optimization.
@BaljeetSingh-ib1pf
@BaljeetSingh-ib1pf 3 жыл бұрын
Hey Philipp, Thanks for this amazing lesson over diffUtil. Could you explain how to assign items list to this adapter. Thanks
@bharathpediredla549
@bharathpediredla549 4 жыл бұрын
You explained it better man. 👌🏼
@PhilippLackner
@PhilippLackner 4 жыл бұрын
better than what? :D
@bharathpediredla549
@bharathpediredla549 4 жыл бұрын
@@PhilippLackner Than the stupid Documentation 😂😂.
@PhilippLackner
@PhilippLackner 4 жыл бұрын
@@bharathpediredla549 thanks 😂👍
@mhmitsray
@mhmitsray 6 ай бұрын
hey :) just a few questions (all towards the end of the video): 1. Wouldn't it be better to make the setOnItemClickListener function private? or is it for external use? 2. I'm getting an error when add '.name' to: tvSource.text = article.source.name
@rodneyperello
@rodneyperello 3 жыл бұрын
Everything is in good programming style.
@tiagosutter8821
@tiagosutter8821 3 жыл бұрын
First of all, thanks for the course. I have a question related to big android projects in general What are the advantage of having all the 'adapters' in one top level package in big projects? I see this often, the same for ViewModels. When we get to a point of having 50+ adapters (my case) it gets kind of messy, and most adapters are used in one single place in my application. The same happens to viewmodels folder. For example in an app we have some screen related to payment, to get better separation i put everything related to payment screens in the ui.payment package Then i have packages like ui.payment.viewmodels, ui.payment.fragments, ui.payment.adapters, etc The adapters related to payment are used only for the screens related to payment, so i see no reason to put them in a top level 'adapters' package, same thing with the ViewModels. Is there some big disadvantage of working with this structure that I described that i'm just not seeing? Thanks again for the awesome content.
@PhilippLackner
@PhilippLackner 3 жыл бұрын
You're totally right with that, this is not the structure I would use for big scale apps. I think for this simple app and tutorial here it's not a big issue though :)
@felipepereira3061
@felipepereira3061 4 жыл бұрын
I still got confused about the line 58, with the : ((Article) -> Unit)? it is an Article object?Why all the Unit? declarations?
@ubersticks
@ubersticks 3 жыл бұрын
"Unit" in Kotlin is just like "void" in Java -- "-> Unit" means this function that accepts "Article" as a parameter does not return anything.
@egementt245
@egementt245 3 жыл бұрын
@@ubersticks Great explanation! Thanks a lot.
@yootewb
@yootewb 2 жыл бұрын
It is not an Article object. It is actually a nullable function that takes an Article as an argument and returns Unit (the equivalent of void in Java). We are simply assigning a variable to represent a function that we can choose to either implement or leave null.
@j2ck1e
@j2ck1e Жыл бұрын
Is the setOnClickListener attribute of item layout?
@johntotetwoo
@johntotetwoo 4 жыл бұрын
Hello, how do you add a button click listener inside the recyclerview and notify it when that item's property has been changed?
@brucebane7401
@brucebane7401 3 жыл бұрын
what does listener mean ???
@fu7ur3gh057
@fu7ur3gh057 3 жыл бұрын
Hello Phill,can you show us how to filter recycler view with DiffUtil?for example at SavedNewsFragments?
@firantemilan
@firantemilan 4 жыл бұрын
Thank you very much. How many videos are there in total?
@PhilippLackner
@PhilippLackner 4 жыл бұрын
In total 12 videos. You're welcome 👍
@testapp616
@testapp616 3 жыл бұрын
Thank you for everything :)
@matt-g-recovers
@matt-g-recovers 3 жыл бұрын
Perfect! Thanks so much!
@ackerman6992
@ackerman6992 2 жыл бұрын
Can anyone explain me about that onitemclicklistener and all? It is bad practice to call setonclicklistener in bind viewholder right? Then why he used it there?
@himanshujain718
@himanshujain718 4 жыл бұрын
Please upload video on how to implement seach saved news in saved news fragment.
@iam-learning6374
@iam-learning6374 4 жыл бұрын
Hi @Philipp Lacker.... may I know what is the difference between ListAdapter and AsyncListDiffer? and which one to use ? Great tutorial as always! thanks.
@yootewb
@yootewb 2 жыл бұрын
Not much of a difference. ListAdapter is just an extension of RecyclerView.Adapter that uses AsyncListDiffer to calculate the differences on a background thread. If your list is dynamic (like in this video), it would be better to opt for ListAdapter because the constructor requires you to specify a Diff checker and therefore prevent you from forgetting to do so.
@muthami_duncan
@muthami_duncan 2 жыл бұрын
Hi Phil, How can I use view binding here?
@jayceeddeyro1406
@jayceeddeyro1406 4 жыл бұрын
Do you have a video where you use diffUtil and with databinding?
@Omsamara6
@Omsamara6 4 жыл бұрын
When you're setting all of those textviews (tvSource, tvTitle, etc) do they have to be inside of the apply block? None of those reference "this" (the view) so I'm not sure why it's in the apply block. Same applies to the setOnClickListener. Great tutorial as always, thank you
@PhilippLackner
@PhilippLackner 4 жыл бұрын
They do reference the view (itemView). Otherwise you would have to write holder.itemView.* for every view you reference. Same counts for onclicklistener
@albertocastro5496
@albertocastro5496 2 жыл бұрын
How would you set up a listener to handle clicks on a view that is inside of a list item, for example if you wanted to execute some code after clicking on your tvTitle view
@chuka_obi5167
@chuka_obi5167 4 жыл бұрын
Hey Phillip this is a really great tutorial! Thank you for sharing. Can you create a tutorial in future that uses data binding and ListAdapter for recyclerview? I currently use ListAdapter for my recyclerview but I can't tell which one is better, using a Recyclerview.Adapter or ListAdapter
@yootewb
@yootewb 2 жыл бұрын
Not much of a difference. ListAdapter is just an extension of RecyclerView.Adapter that uses AsyncListDiffer to calculate the differences on a background thread. If your list is dynamic (like in this video), it would be better to opt for ListAdapter because the constructor requires you to specify a Diff checker and therefore prevent you from forgetting to do so.
@sohilupadhyay4804
@sohilupadhyay4804 3 жыл бұрын
Why do you use Diff utils in RecyclerView? You can also create seperate adapter class different Fragments ?
@joywanjiku2317
@joywanjiku2317 3 жыл бұрын
1:18-2:15 DiffUtil is more efficient & runs in the background thread compared to NotifyDataSetChanged
@shyngyskhann
@shyngyskhann 2 жыл бұрын
AMAZING!
@ajaygalagali5963
@ajaygalagali5963 4 жыл бұрын
It would be helpful to beginners, if you explain in more details
@PhilippLackner
@PhilippLackner 4 жыл бұрын
This is not a beginner tutorial though. Don't skip the basics
@DriveWithHamza
@DriveWithHamza 3 жыл бұрын
Thumbs up Philipp
@FelixEsUnDios
@FelixEsUnDios 2 жыл бұрын
I'm here October 2022
@dennisgonzales9521
@dennisgonzales9521 4 жыл бұрын
Thanks bro! You're awesome 👌👍
@PhilippLackner
@PhilippLackner 4 жыл бұрын
You're welcome!
@chuka_obi5167
@chuka_obi5167 4 жыл бұрын
Also, for my ListAdapter, I don't know why it will only work if I write my code like this val itemToRemove = ToDoItem(toDoText, isCompleted) viewModel.removeFromToDoList(itemToRemove) toDoAdapter.submitList(null) toDoAdapter.submitList(viewModel.toDoList.value!!) toDoAdapter.notifyDataSetChanged() Isn't the point of a DiffUtil so that you dont need to call notifyDataSetChanged()
@osmanmusse9432
@osmanmusse9432 3 жыл бұрын
Great video
@hasanal-qaisi8712
@hasanal-qaisi8712 4 жыл бұрын
Thank you for this valuable information. I have a question, what if my adapter receive data of type (any) and i cast the data in the adapter. How can I implement DiffUtil in this case (Of having multiple data types) ?
@PhilippLackner
@PhilippLackner 4 жыл бұрын
check with a when-expression what type of data you're dealing with
@hasanal-qaisi8712
@hasanal-qaisi8712 4 жыл бұрын
@@PhilippLackner I tried to make differItemCallback of type Any and checked the type of data by using when expression I faced two problems: 1- Suspicious equality check: equals() is not implemented in Object DiffUtilEquals I solved this first problem by making the data class implement an interface that override equals function and make the differItemCallback type of this interface. 2- The second problem is that neither areItemsTheSame() nor areContentsTheSame() working.. I logged them and found out that they're not getting called. I don't know why.
@PhilippLackner
@PhilippLackner 4 жыл бұрын
@@hasanal-qaisi8712 you can also compare the hashcodes of 2 items to check if the contents are the same
@SudhanshuKumar-xy6xv
@SudhanshuKumar-xy6xv 3 жыл бұрын
Now how do I access imageview with view binding as this method is deprecated plz help
@tjgolder99
@tjgolder99 3 жыл бұрын
First write --> private lateinit var binding: ItemArticlePreviewBinding inside the class NewsAdapter and then in onBindViewHolder write this ---> val ivArticleImage = binding.ivArticleImage and then use ivArticleImage in into(ivArticleImage) . Hope you understand .. If you feel any difficulty contact me.
@IlyaTihii
@IlyaTihii 2 жыл бұрын
Phillip, you can help me. How do I change Bindviewholder so that tv.Source, tv.Title and so on are not highlighted in red.
@i5470
@i5470 2 жыл бұрын
lateinit var binding: ItemArticlePreviewBinding ... override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ArticleViewHolder { binding = ItemArticlePreviewBinding.inflate(LayoutInflater.from(parent.context), parent, false) return ArticleViewHolder(binding) }
@akshaykalola
@akshaykalola 4 жыл бұрын
I have one recyclerview with nestedscrollview. That's works perfectly as normal. But, when I tried to improve it with diffutil it don't appear. So, what is the issue I don't know?? Please, help me.
@amineayachi335
@amineayachi335 3 жыл бұрын
Thanks
@amateur_gamer101
@amateur_gamer101 2 жыл бұрын
when setting up the glide, i cant find the ".urlToImage" to call. what's the problem?
@9769ug
@9769ug Жыл бұрын
the NewsAPi no longer has a field for urlToImage, does anyone know a workaround to get the images?
@praystation0409
@praystation0409 2 жыл бұрын
I am here January 2022
@mex5341
@mex5341 2 жыл бұрын
it's better to implement ListAdapter to Adapter Class
@tabrezlj7057
@tabrezlj7057 4 жыл бұрын
Why do you have the setOnItemClickListener function when you didn’t even call it ?
@ackerman6992
@ackerman6992 2 жыл бұрын
Did you got any answer?
@brucebane7401
@brucebane7401 3 жыл бұрын
isnt onitemclicklistener a keyword how can we name a variable like that ????
@mubaraknative
@mubaraknative Жыл бұрын
phillip get 123K subscriber's at 02/08/2023 at 11:09 AM
@yasminedwedar8651
@yasminedwedar8651 4 жыл бұрын
A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution i got this error helpppp
@mikec4220
@mikec4220 4 жыл бұрын
Hi Yasmine, had the same issue... In Article class replace "val author : Any" with "val author : String" .. it worked on my end but I don't know if I messed it up in the long run.. although it should not be a big issue.
@nirajmalpani9589
@nirajmalpani9589 4 жыл бұрын
@@mikec4220 Thanks buddy... I had the same error it worked👍
@roopkishore785
@roopkishore785 3 жыл бұрын
This tutorial series is not for beginners, I am beginner and I am totally confused.
@pembatamang8233
@pembatamang8233 3 жыл бұрын
who the heck hit dislike. Must be high haha
@aakashroushann1602
@aakashroushann1602 4 жыл бұрын
tried your way but unfortunately the list disappers after using diffutil...hope you can help here's the link to my adapter class: pastebin.com/v4jshBgZ
@Sk-gb2hx
@Sk-gb2hx 3 жыл бұрын
+
@innocentkumwenda8139
@innocentkumwenda8139 2 жыл бұрын
sir I cant get my view in my layout file in the overrided function "onBindViewHolder" this part : holder.itemView.apply { }
@vikramshah-01
@vikramshah-01 Жыл бұрын
hey !! did you able get the solution ?
Architectural Skeleton - MVVM News App
11:34
Philipp Lackner
Рет қаралды 32 М.
Handling Pagination with Retrofit - MVVM News App
21:05
Philipp Lackner
Рет қаралды 33 М.
風船をキャッチしろ!🎈 Balloon catch Challenges
00:57
はじめしゃちょー(hajime)
Рет қаралды 35 МЛН
Trapped by the Machine, Saved by Kind Strangers! #shorts
00:21
Fabiosa Best Lifehacks
Рет қаралды 26 МЛН
Osman Kalyoncu Sonu Üzücü Saddest Videos Dream Engine 275 #shorts
00:29
RecyclerView | Everything You Need to Know
25:07
Practical Coding
Рет қаралды 142 М.
RecyclerView Performance with DiffUtil (Kotlin)
15:43
CodingWithMitch
Рет қаралды 23 М.
Kotlin RecyclerView Template (DiffUtil and AsyncListDiffer)
26:34
CodingWithMitch
Рет қаралды 16 М.
Database and Room TypeConverter - MVVM News App
9:43
Philipp Lackner
Рет қаралды 35 М.
Retrofit Setup - MVVM News App
14:35
Philipp Lackner
Рет қаралды 45 М.
How does RecyclerView work internally?
28:39
Native Mobile Bits
Рет қаралды 2,3 М.
5 Tips To Organize Python Code
12:16
Tech With Tim
Рет қаралды 243 М.