Custom Pagination Tutorial with Jetpack Compose | Android 2024

  Рет қаралды 1,252

The Android Factory

The Android Factory

Күн бұрын

Have you ever worked with a paginated endpoint? Do you know how "infinite scrolling" works under the hood? Take a dozen minutes or so to learn something new with this simple and elegant tutorial to paginating with Jetpack Compose!
Don't forget to subscribe and enable notifications to stay up-to-date!
Full playlist here: • Season 15: Multi-modul...
Source code here: github.com/the-android-factor...
0:00 Intro
0:30 Update navigation
2:42 Pagination intro & implementation
7:10 Network implementation & state updates
11:40 Minor bug fix
=========== Popular Series ===========
Redux e-commerce app: • Season 10: E-commerce ...
Rick and Morty app: • Season 6: Rick & Morty...
=========== Connect with me ===========
LinkedIn: / domenic-polidoro-802b72b4
Instagram: / dom_polidoro
Twitter: / developer_dom
Tiktok: / building_android

Пікірлер: 26
@niko_ferrey9118
@niko_ferrey9118 3 ай бұрын
NAH THIS IS CRAZY, i was EXACTLY looking for this to implement it on a Compose Multiplatform project, you save me with the idea of using an array of Pages instead of Items. thank you so much!
@TheAndroidFactory
@TheAndroidFactory 3 ай бұрын
Hell yeah!! Hahaha what a day for you to find these videos huh 😉
@heyyounotyouyou3761
@heyyounotyouyou3761 3 ай бұрын
I just started leaning android, fisished some basic amd intermediate courses offered by google. Now really exiced to follow along this playlist. Please continue. Subbed❤
@TheAndroidFactory
@TheAndroidFactory 3 ай бұрын
Welcome to the channel and excited to have you learn :)
@neyasbit
@neyasbit 21 күн бұрын
What about error handling. For example, when in the middle of the list, that is, for an unsuccessful loading of one item. Also, what happens if the list ends? You can also find various subtleties that are not being talked about.
@TheAndroidFactory
@TheAndroidFactory 21 күн бұрын
When the list ends, there is nothing more to page so the job is "done" so to speak. This can also be detected when the meta.next value is equal to null. Regarding error handling, you can implement a auto-retry feature to attempt the call that failed 1-3 times (or however many times you want) or you can add something to the UI that mentions a failure in loading and the user can click a button or something to trigger the request. The tutorial was meant to be a simpler and mostly working approach as opposed to a fully bulletproof mechanic. The content is more consumable that way, but some bits of what you mentioned are correct. If you'd like to open a pull request enhancing the functionality, I would review it and make content about me reviewing it!
@neyasbit
@neyasbit 21 күн бұрын
Perhaps you're right, I just want to see the subtleties of use
@TheAndroidFactory
@TheAndroidFactory 21 күн бұрын
@neyasbit I could enhance this over time
@nastenkaoo
@nastenkaoo 4 ай бұрын
actually, I need it on my project and can't apply with custom pagination tutorials and paging3. I will look at this amd hope that it will help me
@TheAndroidFactory
@TheAndroidFactory 4 ай бұрын
The pagination libraries are nice, but limiting at times. If you can roll your own custom implementation for things, I would recommend it! Hope this helps
@nastenkaoo
@nastenkaoo 4 ай бұрын
@@TheAndroidFactory yeap, btw, if api supports offset instead of page, these codes also can work or not? I don't have time now, but I will try to implement later, just wanna ask to be ensure
@TheAndroidFactory
@TheAndroidFactory 4 ай бұрын
Yeah absolutely! It would need to change a little bit, but instead of calculating page number, you would just look up how many characters there are, and that is your offset key
@nastenkaoo
@nastenkaoo 4 ай бұрын
@@TheAndroidFactory okay, thanks. I will try
@RageNagatoTV
@RageNagatoTV 2 ай бұрын
Im first time seeing this like wrapping whole screen into a state ? is this actually better than regular screens ( dont know how to explain to you like most of tutorials and repository code i found) and inside that screen i call collectAsState from viewModel and then i add items from that state to list etc.. hope you can understand what i mean :D
@TheAndroidFactory
@TheAndroidFactory 2 ай бұрын
I believe I understand. And the answer likely is: "it depends". When you have a screen that should react "as a whole" I like this pattern, but if you had a screen that held many different data points and ways for the user to interact, it may be better to separate them out. Then again, you could have all of those elements of state in a single data class that has everything you need, and at that point it would boil down to listening for N different pieces of state or having one piece of state that contains N elements. In most cases it may not matter which approach you go with, but sometimes this way or the way you're asking about is better for the use case. Good to be aware of all the options so you can make the best decision when the time comes! Hope that helps haha
@RageNagatoTV
@RageNagatoTV 2 ай бұрын
@@TheAndroidFactory Im way less expirienced than you(2 years but 1 year work expirience with old old android 13y old code in that company, i started learning jetpack compose 1 year ago) so now i have one more thing to keep in mind i think i understand you a little because in my case i have a screen where ill have a list with some clients info and after i click on it i will have more of clients details so this is all about the screen i guess your way with state is great then ? and i actually wanted to implement some paginating (also custom i didnt want to rely on library i wanted to expand my understanding of android etc). And i managed to get to your video so im thinking to redo my whole screen , i managed to implement some pagination by having lastLoadedId variable in my repository then i gave it value lastLoadedClientId = clientList.last().clientId , so i have two functions one for initialLoading with limit of 7 and the other is loadMore with limit of 4 with .startAfter(lastLoadedClientId) ( im using firebase for this app) , so i made it work somehow and i didnt know if its a good way of doing(i think it is not thats why im trying to find some other solutions). Im talking too much haha , thank you for your response anyway :D
@RageNagatoTV
@RageNagatoTV 2 ай бұрын
@@TheAndroidFactory if i understood good in my case this will be good since i also have screen with a list of clients( 3 fields displaying on a card) after i click im opening clients info screen where i can see more fields about him and a picture. i wanted to implement a custom pagination because i didnt want to rely on library , so i found you at the right time :D also i did some i think bad way of paginating and thats why i want to find more solutions private var lastLoadedClientId: String? = null in my repository than i have initialLoad fun where i limit 7 items to load and give the lastLoadedClientId = clientList.last().clientId and i have another function which will be called multiple times as long i have items to load loadMore with limit of 4 items and .startAfter(lastLoadedClientId) and giving also value lastLoadedClientId = clientList.last().clientId . Im using firebase , and from my ui i had some similar logic to your to detect when to call loadMore function . Hope i explained well to you :D thanks for any answers
@RageNagatoTV
@RageNagatoTV 2 ай бұрын
@@TheAndroidFactory i tried few times to reply and is my comment too long? and cant be posted ( it is posted but then dissapears hmm)
@RageNagatoTV
@RageNagatoTV 2 ай бұрын
if i understood good in my case this will be good since i also have screen with a list of clients( 3 fields displaying on a card) after i click im opening clients info screen where i can see more fields about him and a picture. i wanted to implement a custom pagination because, also i did some i think bad way of paginating and thats why i want to find more solutions private var lastLoadedClientId: String? = null in my repository than i have initialLoad fun where i limit 7 items to load and give the lastLoadedClientId = clientList.last().clientId and i have another function which will be called multiple times as long i have items to load loadMore with limit of 4 items and .startAfter(lastLoadedClientId) and giving also value lastLoadedClientId = clientList.last().clientId . Im using firebase , and from my ui i had some similar logic to your to detect when to call loadMore function . Hope i explained well to you :D thanks for any answers
@frankyjunior6005
@frankyjunior6005 4 ай бұрын
Any reason why you are not using paging3?
@TheAndroidFactory
@TheAndroidFactory 4 ай бұрын
Yeah I prefer to not use libraries if you don't need to. There's a bunch of fluff by incorporating the library to your project and this was just a simple example of a "custom" solution. The library works, but I've run into limitations with it before that were super annoying to "hack" around, so having full control is sometimes easier. Nothing wrong with using the lib though!
@vengateshm2122
@vengateshm2122 4 ай бұрын
Why - 10 being used?
@TheAndroidFactory
@TheAndroidFactory 4 ай бұрын
Just a random number I selected. We want to fetch the next page when the user is 10 items away from the bottom. If we chose a smaller number like 5 or 3, the users may hit the bottom of the current page before the next page has been loaded from the internet. Google's recommended approach under the hood is much larger than just 10! It's mostly a best guess to try and keep the "infinite scroll" feeling truly infinite
@sw_a_ppy
@sw_a_ppy 2 ай бұрын
Can we deep dive more into this...?
@TheAndroidFactory
@TheAndroidFactory 2 ай бұрын
Sure, how so?
Jetpack Compose Custom Toolbar
12:04
The Android Factory
Рет қаралды 412
Compose UI work: List items vs. Grid items
19:51
The Android Factory
Рет қаралды 493
Я обещал подарить ему самокат!
01:00
Vlad Samokatchik
Рет қаралды 9 МЛН
ПРОВЕРИЛ АРБУЗЫ #shorts
00:34
Паша Осадчий
Рет қаралды 7 МЛН
Practical API mapping Android example
11:14
The Android Factory
Рет қаралды 1,6 М.
Multi-module Android App Tutorial
17:04
The Android Factory
Рет қаралды 8 М.
Don't Do THIS Jetpack Compose Mistake
8:12
Philipp Lackner
Рет қаралды 20 М.
KMP vs. Flutter - Who Will Win The Cross-Platform Battle?
16:19
Philipp Lackner
Рет қаралды 40 М.
How to handle network errors with Ktor
10:37
The Android Factory
Рет қаралды 1,3 М.
Multiple Screen Size Support in Android Jetpack Compose.
11:42
Pagination with Jetpack Compose
23:15
CodingWithMitch
Рет қаралды 15 М.
Custom layouts and graphics in Compose
20:25
Android Developers
Рет қаралды 51 М.
Я обещал подарить ему самокат!
01:00
Vlad Samokatchik
Рет қаралды 9 МЛН