Pagination from Remote API & Local Cache Using Paging3, Compose and Clean Architecture

แชร์
ฝัง
  • เผยแพร่เมื่อ 31 ต.ค. 2024

ความคิดเห็น • 112

  • @nijuyonkadesu
    @nijuyonkadesu ปีที่แล้ว +3

    9:15 "Personally I prefer to just have my own solution"
    Yesh!! in a project of mine, I had to fetch new list of url from server on reaching every 30th image (27 actually).
    I implemented my own `paging` by using the `position` value from `onBindView()` of ListAdapter.
    I did that after hearing your words 🥰
    because of you I found out that I don't need Paging library 💯

  • @Rafa-iy2ng
    @Rafa-iy2ng ปีที่แล้ว +10

    In 20:12 I would change endOfPaginationReached logic to 'endOfPaginationReached = beers.size() < pageSize' which will save us one extra refresh at the end of the list

  • @theophilus494
    @theophilus494 ปีที่แล้ว +6

    thank you boss.. I remembered contacting you on your instagram DM on this topic.. and here we are.. God bless you greatly.. really appreciate you...

  • @k40ol
    @k40ol ปีที่แล้ว +3

    Philipp, great course! Thank you for uploading & sharing!
    Wanted to mention, to avoid exposing your BeerEntity to UI layer, consider separating cache/caching to its own db.
    i.e. BeerEntity becomes BeerCatalogItem (this is the cached entity in its own DB). You can always include more extension functions / mappers to get a clean Domain object out to UI layer.
    Pros:
    - simplicity in caching
    - simpler schema migration
    Cons:
    - another DB
    - more space for cached content
    Awesome courses! Thank you again! (Will buy one soon to support you!)

    • @MxMayers
      @MxMayers 11 หลายเดือนก่อน

      I have a problem with the domain layer interface, PagingSource and its data layer implementation because dao in the data layer requires PagingSource. As I know the domain layer should not contain data layer entities, how to implement the domain layer interface in the data layer?

  • @rohitnevse5894
    @rohitnevse5894 ปีที่แล้ว +8

    I was waiting for the exact Tutorial on this channel.... And here it is. Philipp is just amazing

  • @ubersticks
    @ubersticks ปีที่แล้ว +11

    At 21:19 the Paging Library pollutes the ViewModel with Entity. Would the use of a Repository help here? The Repository could expose LazyPagingItems to the ViewModel, and it is ok for Repository to know about Entity.

  • @udioshi7799
    @udioshi7799 ปีที่แล้ว +1

    Thank you Philipp for the tutorial,
    Your mediator loads 4 pages (80 beers) at startup before scrolling

    • @reyjohn88
      @reyjohn88 6 หลายเดือนก่อน

      How did you solve this? It happens in my implementation too?

    • @udioshi7799
      @udioshi7799 6 หลายเดือนก่อน

      @@reyjohn88 didn’t solve yet

  • @formatBCE
    @formatBCE ปีที่แล้ว +8

    If you have page size 10, and already have 2 pages loaded, and there's 29 beers in list, following will happen:
    - paging lib loads page 3
    - entities count is 29
    - next page = 29 / 10 + 1 = 2 + 1 = 3
    - end of pagination not reached
    - paging lib loads page 3
    - upsert updates last 9 items
    - back to start

  • @antonyfilochowski335
    @antonyfilochowski335 ปีที่แล้ว

    thank you
    helped me overcome a couple of obstacles i was encountering

  • @kuana9961
    @kuana9961 ปีที่แล้ว +1

    Thank you very much for the live coding tutorial.🙏 It's simple, easy to understand, and very rewarding.

  • @trocchiettoski
    @trocchiettoski ปีที่แล้ว

    Suggestion, an app with a shared view model for a basket, and some payment method. Philip you rock

  • @mesutemrecelenk5447
    @mesutemrecelenk5447 ปีที่แล้ว +1

    This tutorial is an artwork😊 thanks Phlipp

  • @ezriouil
    @ezriouil ปีที่แล้ว

    the best channel in youtube from morocco

  • @ygorfrazao4420
    @ygorfrazao4420 ปีที่แล้ว +5

    Great tutorial, once again.
    I am wondering if we can wrap the pager inside a repository, or, even, an use case and then inject these in our viewmodel, what do you think?

  • @ngomdecadetkamdaou3464
    @ngomdecadetkamdaou3464 ปีที่แล้ว +4

    I enjoyed the video. But I noticed that in the data package, there is a remote mediator that makes the API call and has some business logic. Does the remote mediator replace the repository and the use case at the same time when referring to clean architecture?

  • @path_ethics
    @path_ethics ปีที่แล้ว +1

    Thanks for the video, you probably got there by now but at 21:27 to solve this (if I understood correctly), instead of having the pager inside your viewModel, you can have another class in between like a dbRepository or a useCase or both. In that repository/usecase you return a Pager(...).flow.map(), and in there you map the PagingData items to your UI model.

  • @renzcarlosalanga6077
    @renzcarlosalanga6077 ปีที่แล้ว +1

    It would be awesome if you can make a CRUD operations with Paging 3

  • @sagarprajapati8769
    @sagarprajapati8769 20 วันที่ผ่านมา

    ​@PhilippLackner please create and add blog about this topic.

  • @algo_chronicles
    @algo_chronicles ปีที่แล้ว +1

    Violation of clean architecture principal but video is good❤

  • @ntikomathaba2662
    @ntikomathaba2662 ปีที่แล้ว +1

    Awesome video Phillip, as always. 👏🏾
    If you wanted to group the data into different sections, how would you go about doing that?

  • @JahangirJadi
    @JahangirJadi 10 หลายเดือนก่อน

    Hi Philipp. First of all, thank you for this amazing tutorial. I have a question. What if I need to update the paging list? For example, update some item at position. How can I achieve this?

  • @smartkidsru
    @smartkidsru ปีที่แล้ว

    Philipp, thanks for your brilliant work! It would be interesting to know how to remove the item from the list by item's id without refreshing the whole list? Looks like it is difficult to implement using compose paging3 library...

  • @entchannel
    @entchannel ปีที่แล้ว

    Thank you so much! It helped me to get the json file. But I’m dealing with json that contain two object first is information about current page, next page url and previous page url and another one is list with the objects that I want to display in recycle view. What should I do? Do I need a data class for each object?

  • @jam4l
    @jam4l ปีที่แล้ว

    Great video, Thanks Philipp 👏

  • @artyommukovozchik7165
    @artyommukovozchik7165 ปีที่แล้ว

    Great as always and so amazing tutorial. Keep doing such useful videos!

  • @pereyrarg11
    @pereyrarg11 ปีที่แล้ว

    Awesome! it was a good introduction to Paging

  • @ericwathome783
    @ericwathome783 ปีที่แล้ว

    you just make everything simple

  • @germenwong
    @germenwong ปีที่แล้ว

    Hi Philip, Can you explain the relationship between PagingSource and RemoteMediator

  • @anorov_hasan
    @anorov_hasan ปีที่แล้ว

    thanks , amazing works great ,
    can you also share your experiences on using markdown in compose

  • @mircodev
    @mircodev ปีที่แล้ว

    Thanks for this perfect explanation!

  • @Rafa-iy2ng
    @Rafa-iy2ng ปีที่แล้ว +2

    I always make mappers as `val` extensions. Are there any disadvantages of this solution?

  • @olegleonov1310
    @olegleonov1310 ปีที่แล้ว

    I think there is one more condition when `endPaginationReached` could be `true`. It's `state.config.pageSize` > beers.size().
    It means that we got fewer items than we should have on the page and it was the last page.

  • @adityarathi8309
    @adityarathi8309 ปีที่แล้ว

    Hi Phillip, Great Tutorial, Learning a lot.
    I had a question, is it possible to get the total item count fetched till the current time in RemoteMediator?
    I wanted to understand a use case when id is not exactly the number of items fetched?

  • @pranavsubramanian2549
    @pranavsubramanian2549 ปีที่แล้ว

    Hi Philipp, I am trying to list out all the items available in Firebase Storage, cache and display it. It doesn't seem to work and I am stuck. What should I do? By the way, your videos are amazing and any video I need on Android Development, I come to this channel first and I mostly get the answers. Great work!

  • @JohanAlbrectsen
    @JohanAlbrectsen ปีที่แล้ว +1

    Good video, but you should also include with cursor pagination logic, as it's the superior pagination type.

  • @seftiannurfaozy2918
    @seftiannurfaozy2918 ปีที่แล้ว

    thank you phillip

  • @nicholasferrara8028
    @nicholasferrara8028 ปีที่แล้ว

    Keep up the great work!

  • @berkc5323
    @berkc5323 ปีที่แล้ว +1

    Hello Philipp, thanks for the amazing videos. I have a question, let's say I'm fetching some data from the api and want to keep it somewhere that multiple viewModels can reach. But I don't want to fetch the data again every time it needs to be used. What is the best way to do it without breaking the clean architecture? Which layer of clean architecture I should keep them? Should I keep the variables in a companion object (I don't want it) or maybe in a repository and inject that repository to the viewModels that need to use it. I don't want to use a BaseViewModel also because I have so many of those variables :) thank you.

  • @bdsnarola
    @bdsnarola ปีที่แล้ว +1

    In this, I notice that the pager calls API for 3-4 pages on app startups. And I also want to include that when the app needs new data on scrolling that time also it calls API for 2 pages at a time. Can we manage it to call API only one time at a time?

  • @DaleHawkins
    @DaleHawkins ปีที่แล้ว

    Nice job. Thank you!

  • @AbdulelahAGR
    @AbdulelahAGR 11 หลายเดือนก่อน

    Thank you for the video

  • @Leon-un2ii
    @Leon-un2ii ปีที่แล้ว

    Thanks for this great tutorial! One question: why you are using retrofit and not ktor?

  • @zynastor1
    @zynastor1 ปีที่แล้ว

    This guy is amazing

  • @hanasakura4541
    @hanasakura4541 ปีที่แล้ว

    Great. Thanks a lot

  • @LEEJIHUN
    @LEEJIHUN ปีที่แล้ว

    Thank you for the great video! If the description of the beer is long, I want to center the beer image on the card, can you tell me how I can center it?

  • @jishnugoyal4397
    @jishnugoyal4397 ปีที่แล้ว +1

    How to cache the images? Do you think you would cover the same?

  • @KunalGoyal
    @KunalGoyal 7 หลายเดือนก่อน +6

    Punk API stopped working, getting 404

    • @icycleragon
      @icycleragon 6 หลายเดือนก่อน +2

      Same here

  • @roshkaalex
    @roshkaalex ปีที่แล้ว

    Thank you. Will be pagination for KMM?

  • @philipjanbaruis7040
    @philipjanbaruis7040 ปีที่แล้ว

    My daily dose of Android Stuffs

  • @mubaraknative
    @mubaraknative ปีที่แล้ว +1

    How Phillip you find these types of algorithms 17:25

  • @TuanPhanVan-s7v
    @TuanPhanVan-s7v ปีที่แล้ว

    Thank you

  • @MatrixAppDev
    @MatrixAppDev ปีที่แล้ว

    hello philip
    always thank you for the video
    Usually, external API and internal room data are often used in the structure of viewmodel - usecase - repository - dao, but why not use that structure when using paging?

  • @AlanBartholomew-h7o
    @AlanBartholomew-h7o ปีที่แล้ว +1

    Philipp, at 31:50 in the video you select "items(items: LazyPagingItems", however it does not appear for me in the list. No matter what I select
    I get an error when hovering over (beers) that states Type Mismatch Required: Int, Found: lazyPagingItems . This also happens if I use the app source code from the Github site. Could the problem be that I am using Android Studio Flamingo | 2022.2.1 Patch 2

    • @limtis
      @limtis ปีที่แล้ว

      You can use any other items()
      items(beers.itemCount) { index ->
      val beer = beers[index]
      ...
      }

    • @germenwong
      @germenwong ปีที่แล้ว

      I also encountered the same problem,
      You can modify according to the pagination library version of the video, and then

  • @NZBurmeseLink
    @NZBurmeseLink ปีที่แล้ว

    Hello Philipp, I would like to know about all of your courses. Is there a discount available if I purchase all of them?

  • @chulgunsirru
    @chulgunsirru ปีที่แล้ว

    thanks for video!

  • @mikelantzelo
    @mikelantzelo ปีที่แล้ว +2

    LazyColumn items not showing LazyPagingItems choice. What am i missing? Can someone help?

    • @symekoo7
      @symekoo7 หลายเดือนก่อน

      I have same issue unfortunatelly. Did you manage to fix it?

  • @freshtechtips
    @freshtechtips ปีที่แล้ว

    Philipp why you still use retrofit? I thought you said you love ktor more and prefer it

  • @siva_subramaniam
    @siva_subramaniam ปีที่แล้ว

    Thank you so much. I have a doubt. Why didn't you include the "androidx.room:room-runtime:$room_version" dependency? Isn't it necessary?

  • @ubersticks
    @ubersticks ปีที่แล้ว

    Hey Phillip - good stuff! You were down on Paging library one year ago and actually had an excellent tutorial video showing how to do it yourself. What changed your mind about Paging Library?

    • @PhilippLackner
      @PhilippLackner  ปีที่แล้ว

      I still use it, but many people wanted a paging tutorial and if you page with a cache it makes things a lot easier

  • @proandroiddevir
    @proandroiddevir ปีที่แล้ว

    Hi Mr lackner . Can you teach crashlytics?

  • @qweqwe2589
    @qweqwe2589 ปีที่แล้ว

    Can you please make a tutorial about how to write back navigation that also supports also api 33? Because after api 33 there is someting new and it's really hard to find on the internet how to implement it perfectly.

  • @vazhakentchiashvili2198
    @vazhakentchiashvili2198 ปีที่แล้ว

    Amazing!❤

  • @zulhijananda5772
    @zulhijananda5772 10 หลายเดือนก่อน

    How to handle query situation? my project works with no query, how to make the paging based on query params?

  • @dmytrodolotov9723
    @dmytrodolotov9723 9 หลายเดือนก่อน

    Hi Philipp, thank you for great tutorial. In the latest version of compose, LazyColumn items() function can no longer accept LazyPagingItems as an argument. What is the best way to solve this issue?

    • @KunalGoyal
      @KunalGoyal 7 หลายเดือนก่อน

      items(beers.itemCount){index - > val beer = beers[index]}..Use this

    • @justmeagain9302
      @justmeagain9302 3 หลายเดือนก่อน

      Or just use itemsIndexed

  • @nurkholiq1931
    @nurkholiq1931 8 หลายเดือนก่อน

    I wonder to imagine what happens to the loaded page if in the middle scroll we change the API query?

  • @AhmedElsayed-ed9ts
    @AhmedElsayed-ed9ts 27 วันที่ผ่านมา

    I can't find the items of lazypagingadapter

  • @John-qt6qk
    @John-qt6qk ปีที่แล้ว

    Can I use it with firestore?

  • @CodingZest
    @CodingZest ปีที่แล้ว

    It might be not the right question, but I really want to know which theme are you using in your Android Studio?

    • @germenwong
      @germenwong ปีที่แล้ว +1

      xcode-dark

    • @CodingZest
      @CodingZest ปีที่แล้ว

      @@germenwongthanks for reply

  • @path_ethics
    @path_ethics ปีที่แล้ว

    If I need to pass more parameters to remote api, like for example, if a user can select a parameter to filter the api responses, where do I pass those filter values for them to get to the api?

    • @MyHobbies-qh8pg
      @MyHobbies-qh8pg 5 หลายเดือนก่อน

      on your repository inside remote mediator pass
      query String
      fun getAllUsers(
      query: String
      ): Flow {
      val pagingSourceFactory = { database.userDao().getAllUsers() }
      return Pager(
      config = PagingConfig(pageSize = ITEMS_PER_PAGE),
      remoteMediator = UsersRemoteMediator(
      api = api,
      usersDatabase = database,
      query = query
      ),
      pagingSourceFactory = pagingSourceFactory
      ).flow
      }
      on your remote mediator
      lass UsersRemoteMediator(
      private val api: HomeScreenApi,
      private val usersDatabase: UserDatabase,
      private val query: String
      ) : RemoteMediator() {
      ******
      }

  • @Shubhammonga242s
    @Shubhammonga242s ปีที่แล้ว

    Amazing

  • @bilmiyorum06
    @bilmiyorum06 ปีที่แล้ว +5

    Using entities instead of UI models in ViewModel is unacceptable. You made it short so that people wouldn't get bored watching the video, but we could have done this in the Repository layer.

  • @voidpointer398
    @voidpointer398 11 หลายเดือนก่อน

    After going through different other articles and codebases, I have found that you cannot abstract out the database details from the ui layer, the pager object tightly couples the ui layer to the paging3 library.
    If anyone else found a solution to this please tell

  • @Adam0001
    @Adam0001 ปีที่แล้ว

    Great 👏

  • @reyjohn88
    @reyjohn88 6 หลายเดือนก่อน

    I implemented this in one of my project, but don't know why it always loads first 4 pages everytime the screen loads. Anyone have any solution for that?

  • @gaoliang1368
    @gaoliang1368 ปีที่แล้ว

    how drag drop resort item

  • @amateur_gamer101
    @amateur_gamer101 ปีที่แล้ว

    i have a question about pagination. Can u use it for all APIs or does the API have to be built in a way that supports it before you can use it?

    • @PhilippLackner
      @PhilippLackner  ปีที่แล้ว +1

      The API needs to support it

    • @amateur_gamer101
      @amateur_gamer101 ปีที่แล้ว

      @@PhilippLackner lets say the API does not support it, saving the unpaginated response to room and paginating from room is the right way to go?

    • @PhilippLackner
      @PhilippLackner  ปีที่แล้ว +1

      @@amateur_gamer101 has a little impact but the longest time is needed to do the network call, not to load from the local db

  • @codeventure23
    @codeventure23 ปีที่แล้ว

    Coupon not working for me

  • @ahmedrashed2587
    @ahmedrashed2587 ปีที่แล้ว

    Will the courses be delivered to me like physically or I'll get them online

  • @AmitKumar-pw1ln
    @AmitKumar-pw1ln 2 หลายเดือนก่อน

    Great

  • @TheZaurHasanov
    @TheZaurHasanov ปีที่แล้ว

  • @aminsakha155
    @aminsakha155 6 หลายเดือนก่อน

    The deployment could not be found on Vercel :)

  • @imamyusupbachtiar5461
    @imamyusupbachtiar5461 ปีที่แล้ว

    Nice,

  • @proandroiddevir
    @proandroiddevir ปีที่แล้ว

    Thanks for this video👏👏👏👏👏👏👏🙏🙏🙏🙏👍👍👍💪💪💪💪💪💪💪

  • @moldovanpeter5123
    @moldovanpeter5123 ปีที่แล้ว

    Nice Vid but in the end it still an overhead to implement pagination and also from Archi perspective, I would not use it, and still not using it because of this.

  • @sijanneupane
    @sijanneupane ปีที่แล้ว

    done an' dusted!

  • @mtanve2319
    @mtanve2319 3 หลายเดือนก่อน

    Anyone trying this in 2024, the PunkAPI has been shut down. Just spent 2 hours on this for it to not work.

  • @Revitalish
    @Revitalish 5 หลายเดือนก่อน

    it's not clear at all why there should be both Beer model and simple Beer data class that looks exactly the same. and what is this beer.tobeerentity and vise versa for? you don't explain crucial things..

  • @gaoliang1368
    @gaoliang1368 ปีที่แล้ว

    It would be awesome if you can make a CRUD operations with Paging 3