-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve decks adapter code #17755
Improve decks adapter code #17755
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All great stuff!
kotlin | ||
.runCatching { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why kotlin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have an extension runCatching in CoroutineHelpers that takes precedence. That method isn't used outside of that file but it felt out of place to make it private so I can access the platform runCatching directly. Made an import alias instead for runCatchingKotlin.
Fixes IDE issues and kotlin cleanups. The setBackgroundAlpha() method was inlined, there was only one usage and this also avoids a warning about one of its parameters having the same value. Used the getDrawableOrThrow ktx extension method to improve the nullability of some of properties. Slightly improves adapter performance by extracting the fetching of some resources values from adapter methods that can be called a lot.
The callbacks and the hasBackground property where only set when the adapter was initialized so it didn't make sense to have setters for them. Also added a bit of documentation. The callbacks were modified to pass the deck id which was previously extracted from the OnClickListener's view that was passed in. LayoutInflater was removed as a constructor property because we pass the context which can be used to obtain it.
DeckPicker was modified to calculate itself the due count because it has the required data, there's no need to go through the adapter. I also refactored a bit the code around setting the subtitle to the due count, I think this looks and reads better.
2c92101
to
e1c40cb
Compare
The suspended code was removed and a similar implementation was done in DeckPicker which will now do the necessary work and then will pass the calculated data to the adapter. The adapter was changed to extend ListAdapter which uses diff-ing to observe changes so we get free animations. The filtering was removed from the adapter, DeckPicker computes the data as it has all info needed, the query and the deck tree. The adapter becomes dumb and just reacts to the changes. A bit wasteful to start a coroutine for each change in the query text, but I wanted to keep the change count small. Note: the methods findDeckPosition() and getNodeByDid() were moved in DeckPicker, they are not needed by the adapter and the DeckPicker already has a reference to the deck tree that it can use in the methods.
e1c40cb
to
e06a890
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy. CI is having general issues
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice set of refactors
Purpose / Description
Refactors the code for DeckAdapter to improve it and fix a kotlin cleanup + rust cleanup. More info on the commits messages. If the last commit seem too bold I can remove it.
How Has This Been Tested?
Ran the tests, manually verified the decks screen.
Checklist