android-paging | Jetpack Paging codelab | Model View Controller library

 by   googlecodelabs Kotlin Version: Current License: Apache-2.0

kandi X-RAY | android-paging Summary

kandi X-RAY | android-paging Summary

android-paging is a Kotlin library typically used in Architecture, Model View Controller applications.,roid-paging has no bugs, it has no vulnerabilities, it has a Permissive License and it has low support. You can download it from GitHub.

Jetpack Paging codelab
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              android-paging has a low active ecosystem.
              It has 456 star(s) with 255 fork(s). There are 24 watchers for this library.
              OutlinedDot
              It had no major release in the last 6 months.
              There are 25 open issues and 126 have been closed. On average issues are closed in 96 days. There are 5 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of android-paging is current.

            kandi-Quality Quality

              android-paging has no bugs reported.

            kandi-Security Security

              android-paging has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.

            kandi-License License

              android-paging is licensed under the Apache-2.0 License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              android-paging releases are not available. You will need to build from source code and install.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of android-paging
            Get all kandi verified functions for this library.

            android-paging Key Features

            No Key Features are available at this moment for android-paging.

            android-paging Examples and Code Snippets

            No Code Snippets are available at this moment for android-paging.

            Community Discussions

            QUESTION

            Android Paging 3 - experiencing flickers, glitches or jumps in position when scrolling & loading new pages
            Asked 2021-Mar-19 at 18:15

            Hello Guys im using Android Jetpack Paging library 3, I'm creating a news app that implements network + database scenario, and im following the codelab by google https://codelabs.developers.google.com/codelabs/android-paging , im doing it almost like in the codelab i almost matched all the operations shown in the examples https://github.com/android/architecture-components-samples/tree/main/PagingWithNetworkSample.

            It works almost as it should...but my backend response is page keyed, i mean response comes with the list of news and the next page url, remote mediator fetches the data, populates the database, repository is set, viewmodel is set...

            The problem is : when recyclerview loads the data , following happens:recyclerview flickers, items jump, are removed , added again and so on. I dont know why recyclerview or its itemanimator behaves like that , that looks so ugly and glitchy. More than that, when i scroll to the end of the list new items are fetched and that glitchy and jumping effect is happening again.

            I would be very grateful if you could help me, im sitting on it for three days , thank you very much in advance.Here are my code snippets:

            ...

            ANSWER

            Answered 2021-Mar-19 at 18:15

            Just following up here from comments:

            Setting pageSize = 10 fixes the issue.

            The issue was with pageSize being too small, resulting in PagingSource refreshes loading pages that did not cover the viewport. Since source refresh replaces the list and goes through DiffUtil, you need to provide an initialLoadSize that is large enough so that there is some overlap (otherwise scroll position will be lost).

            BTW - Paging loads additional data automatically based on PagingConfig.prefetchDistance. If RecyclerView binds items close enough to the edge of the list, it will automatically trigger APPEND / PREPEND loads. This is why the default of initialLoadSize is 3 * pageSize, but if you're still experiencing additional loads, I would suggest either adjusting prefetchDistance, or increasing initialLoadSize further.

            Source https://stackoverflow.com/questions/66627912

            QUESTION

            How to handle many Api requests using Paging 3
            Asked 2020-Dec-17 at 10:27

            Following this codelab I have implemented pagination and caching using RemoteMediator (I am calling a simple API that returns a list of news). I am injecting this RemoteMediator to Repository which has method getResultStream() that returns Flow>. In ViewModel is function getNews() : Flow> and in Fragment I am calling this function and submitting list to RecyclerAdapter.

            Now I want to add a new API call that returns news but with search keyword. What is the proper way to do it? Do I have to write all this code again and create a new RemoteMediator? The logic will be the same but now I have to pass a string argument to the Retrofit get function. The result of this call will replace items in RecyclerView, so I will have two sources of data but one Recycler, do I have to create also a MediatorLiveData? (I don't add any code but if it help I can do it)

            One person asked how exactly I did it (Question posted as answer so it is deleted now but maybe it will help someone in future). So, in ViewModel I have this:

            ...

            ANSWER

            Answered 2020-Nov-15 at 19:24

            Assuming you still have one recyclerview, you can do something like:

            Source https://stackoverflow.com/questions/64817701

            QUESTION

            Paging 3 - IllegalArgumentException: Additional prepend event after prepend state is done
            Asked 2020-Nov-16 at 19:18

            After making a simple app with Paging 3 (based on this Google GitHub codelab) my app crashes. When I scroll down, at some point (probably when the new GET function is called). Logcat looks like this:

            ...

            ANSWER

            Answered 2020-Nov-16 at 19:18

            I am not sure but I think it was just a bug in the library. I was using 3.0.0-alpha08 but after updating to 3.0.0-alpha09 I don't get any errors. I tested it in my app and in Google sample project after updating the version and it is working.

            Fix for IllegalArgumentException being throw when using separators with RemoteMediator and an invalidate is triggered while a remote load that would return endOfPagination is still running (I3a260)

            Source https://stackoverflow.com/questions/64861346

            QUESTION

            Convert Kotlin class to Java
            Asked 2020-Oct-27 at 02:34

            How to convert this Kotlin class to Java

            ...

            ANSWER

            Answered 2020-Oct-27 at 02:34

            Decompiling that class to Java with IntelliJ produces this. I changed Repo to String so that it would compile locally without dependencies.

            Source https://stackoverflow.com/questions/64544981

            QUESTION

            Set span size in Paging Library with GridLayoutManager
            Asked 2020-Oct-18 at 14:33

            set span size to 1 in GridLayoutManager when LoadState is Loading in Paging Library. I have tried this solution but it's not working.

            For replicate issue: clone this official repo and set GridLayoutManager in SearchRepositoriesActivity

            My code is here

            MovieListFragment

            ...

            ANSWER

            Answered 2020-Jun-21 at 09:44

            I solved it. this is my code

            In your Activity

            Source https://stackoverflow.com/questions/62358002

            QUESTION

            Does PagingData Run on a Background Thread by Default in Paging 3 Library?
            Asked 2020-Sep-21 at 04:40

            Is background threading managed automatically with PagingData as it is with PagedList, and then returned on the main thread?

            From the logs below, it appears PagingData is not run on the backgroud thread in the Paging 3 library compared to PagedList in Paging 2's library.

            Expect (Based on the Paging Codelab sample)

            • GithubPagingSource override suspend fun load(...) to run on an IO thread.
            • SearchRepositoriesActivity viewModel.searchRepo(query).collectLatest { ... } to run on the main thread.

            Observe

            • Both GithubPagingSource override suspend fun load(...) and SearchRepositoriesActivity viewModel.searchRepo(query).collectLatest { ... } run on the main thread.
            Paging 2

            Threading is handled on the background by PagedList with toLiveData according to the documentation.

            If you use LivePagedListBuilder to get a LiveData, it will initialize PagedLists on a background thread for you.

            Paging 3

            The Paging 3 documentation does not mention how threading is managed. However, from the logs, PagingSource appears to be running the network request on a main thread and returning the PagingData on a main thread.

            My Sample Code

            I've recreated the Codelab pattern in the CryptoTweets sample app app-simple module.

            FeedPagingSource.kt

            ...

            ANSWER

            Answered 2020-Sep-21 at 04:26
            Kotlin Coroutines

            When implementing PagingData and PagingSource with Kotlin Coroutines and making a Retrofit network request, as in the sample code above, Retrofit handles the background threading by default and returns on the main thread.

            See StackOverflow: Does Retrofit make network calls on main thread?

            RxJava

            When using RxJava with Retrofit as the network source, the threading needs to be explicitly specified as shown in the Android documentation sample.

            See Android documentation: Page from network and database > Implement a RemoteMediator

            Source https://stackoverflow.com/questions/63985284

            QUESTION

            Display empty state when using Google's Paging3 library
            Asked 2020-Sep-18 at 06:35

            I'm currently using Google's Paging3 library for the first time. I'm basing my code on their Codelab at https://codelabs.developers.google.com/codelabs/android-paging/#0.

            The flow of my app adheres to the following rules:

            1. display empty state
            2. let users search for something
            3. display results
            4. when user presses back button on searchbar -> display empty state again

            The codelab unfortunately does not deal with empty states :( I'm using the following addLoadStateListener to deal with the search results:

            ...

            ANSWER

            Answered 2020-Sep-18 at 06:35

            Here are a couple APIs you might find helpful:

            You can use PagingData.empty() to create an empty PagingData you can submit to "clear" the previous PagingData, until you call adapter.submitData again. This is useful if you want to show empty state between searches or before searching. You can also use PagingData.from(list) if you want to show some static content.

            To get the presented item count you can use adapter.itemCount

            If you need to check specifically what items are loaded after refresh finishes, you can use adapter.peek(index) or adapter.snapshot() to get all the items at once (but is more expensive).

            Source https://stackoverflow.com/questions/63941762

            QUESTION

            Paging3: "Not sure how to convert a Cursor to this method's return type" when using PagingSource as return type in Room DAO
            Asked 2020-Aug-13 at 10:24

            I was trying to imitate Google's codelab for the new Paging 3 library, and I encountered the following error when I tried to have a Room DAO method return a PagingSource:

            ...

            ANSWER

            Answered 2020-Aug-13 at 10:10

            It turns out that you need to increase the Room version to 2.3.0-alpha02 or above:

            Source https://stackoverflow.com/questions/63373069

            QUESTION

            Creating another PagingSource for a different API resource?
            Asked 2020-Aug-06 at 04:30

            Suppose I have a API resource that displays a list of animals, let's call it /animals, and I have another that is used to search the list of animals using their species, /animals/{species}, if I were to use Android's new Paging3 library, would I have to create two separate PagingSourceobjects for them? The Codelab for paging has one class that extends PagingSource called GithubPagingSource, but it is only for one endpoint. I was wondering what the correct approach would be.

            ...

            ANSWER

            Answered 2020-Aug-06 at 04:30

            A single instance of PagingSource is supposed to represent a snapshot of the backing dataset, which basically means that if a page is dropped and reloaded by the same instance, the same page should be output.

            However, you can have one implementation and create multiple instances of it, so something like this would probably be recommendable:

            Source https://stackoverflow.com/questions/63275353

            QUESTION

            Why does ViewModelProvider creates new instance of view model on screen rotation?
            Asked 2020-Jun-06 at 05:49

            Im trying to implement Paging but every time i rotate a screen constructor of view model gets called, thus triggering loadInitial to fetch new data from network in my DataSource class.Help appreciated

            ...

            ANSWER

            Answered 2020-Jun-06 at 04:49

            You should never be calling through to the factory's create() method yourself.

            Instead, you should be following the documentation and using ViewModelProvider:

            Source https://stackoverflow.com/questions/62227321

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install android-paging

            You can download it from GitHub.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/googlecodelabs/android-paging.git

          • CLI

            gh repo clone googlecodelabs/android-paging

          • sshUrl

            git@github.com:googlecodelabs/android-paging.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link