All Projects → MobileUpLLC → RxPagingLoading

MobileUpLLC / RxPagingLoading

Licence: MIT license
Easy handling of the Paging or Loading screens states

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to RxPagingLoading

easy-css-layout
Easy css layout
Stars: ✭ 117 (+160%)
Mutual labels:  pagination, loading
mongoose-aggregate-paginate-v2
A cursor based custom aggregate pagination library for Mongoose with customizable labels.
Stars: ✭ 103 (+128.89%)
Mutual labels:  pagination, paging
Dotnetpaging
Data paging with ASP.NET and ASP.NET Core
Stars: ✭ 70 (+55.56%)
Mutual labels:  pagination, paging
Movies-PagingLibrary-Arch-Components
Sample to practice PagingLibrary & RX
Stars: ✭ 92 (+104.44%)
Mutual labels:  paging-library, paging-library-in-android
uni-z-paging
【uni-app自动分页器】超简单!仅需两步轻松完成完整分页逻辑(下拉刷新、上拉加载更多),分页全自动处理。支持自定义加载更多的文字或整个view,自定义下拉刷新样式,自动管理空数据view等。
Stars: ✭ 91 (+102.22%)
Mutual labels:  pagination, paging
Mongoose Paginate V2
A cursor based custom pagination library for Mongoose with customizable labels.
Stars: ✭ 283 (+528.89%)
Mutual labels:  pagination, paging
Combine Pagination
A JavaScript library for paginating data from multiple sources 🦑
Stars: ✭ 157 (+248.89%)
Mutual labels:  pagination, paging
paginated
⚛️ React render props component & custom hook for pagination.
Stars: ✭ 20 (-55.56%)
Mutual labels:  pagination
TipDialog
flutter tip dialog
Stars: ✭ 78 (+73.33%)
Mutual labels:  loading
theleakycauldronblog
My Personal Blog. Powered by Gatsby and Netlify CMS
Stars: ✭ 33 (-26.67%)
Mutual labels:  pagination
GradientLoading
No description or website provided.
Stars: ✭ 12 (-73.33%)
Mutual labels:  loading
shitload
The appropriate bullgit loading animation
Stars: ✭ 15 (-66.67%)
Mutual labels:  loading
dlib
Dynamic loading library for C/C++
Stars: ✭ 19 (-57.78%)
Mutual labels:  loading
PetkoparaCrudGeneratorBundle
Symfony3 CRUD generator bundle with pagination, filter, bulk actions and Twitter bootstrap 3.3.6 features.
Stars: ✭ 69 (+53.33%)
Mutual labels:  pagination
vue3-table-lite
A simple and lightweight data table component for Vue.js 3. Features sorting, paging, row check, dynamic data rendering, supported TypeScript, and more.
Stars: ✭ 148 (+228.89%)
Mutual labels:  pagination
Pagination-and-Search-Laravel
Example of pagination and search functionality combined in Laravel Framework
Stars: ✭ 19 (-57.78%)
Mutual labels:  pagination
CustomProgress
一款常见的进度条加载框架
Stars: ✭ 32 (-28.89%)
Mutual labels:  loading
loopback-row-count-mixin
A loopback mixin to get total count of a model
Stars: ✭ 13 (-71.11%)
Mutual labels:  pagination
PagingSampleCodelab v1.x
[DEPRECATED] Android App done as part of the Google Codelab "Android Paging v1.x". This repository is no longer maintained.
Stars: ✭ 22 (-51.11%)
Mutual labels:  paging-library
ResDelivery-Hilt-Coroutines-Mvvm-Single-Activity
This is a Sample Single Activity App (Multi Fragments) that uses Dagger-Hilt, Coroutines Flows, Paging 3 & Mvvm Clean Architecture
Stars: ✭ 28 (-37.78%)
Mutual labels:  paging

Reactive Paging and Loading

Maven Central Android Arsenal License: MIT

This library implements reactive paging and loading.

It helps to handle the states of loading a simple data (LCE - loading/content/error) or the complex states of lists with pagination (PLCE - paging/loading/content/error).

The solution is based on the usage of Unidirectional Data Flow pattern.

The library depends on RxJava, so you will find familiar interfaces in it's API.

Dependency

Add the dependency to your build.gradle:

dependencies {
    implementation 'ru.mobileup:rxpagingloading:1.0.1'
}

Loading a simple data

Loading interface looks as follows:

interface Loading<T> {

    enum class Action { REFRESH, FORCE_REFRESH }

    val state: Observable<State<T>>

    val actions: Consumer<Action>

    data class State<T>(
        val content: T? = null,
        val loading: Boolean = false,
        val error: Throwable? = null
    )
}

It includes:

  • State class — represents LCE state.
  • Action enum - the possible actions.
  • state: Observable - observes changes of the LCE state.
  • actions: Consumer - receives performed Action.

There are two implementations of this interface:

LoadingOrdinary

This class is for simple case when at first load or after refresh content comes from Single data source, passed into the constructor:

LoadingOrdinary(
    source = Single.just("Content string")
)

LoadingAssembled

This implementation is for case when there is a separate Сompletable to refresh the content and an Observable stream for receiving this content updates:

LoadingAssembled(
    refresh = repository.refreshDataCompletable(),
    updates = repository.dataChangesObservable()
)

Paging

The Paging interface looks a bit more complicated. In addition to the LCE, it has the paging states:

interface Paging<T> {

    enum class Action { REFRESH, FORCE_REFRESH, LOAD_NEXT_PAGE }

    val state: Observable<State<T>>

    val actions: Consumer<Action>

    data class State<T>(
        val content: List<T>? = null,
        val loading: Boolean = false,
        val error: Throwable? = null,
        val pageLoading: Boolean = false,
        val pageError: Throwable? = null,
        val lastPage: Page<T>? = null
    ) {
        val isEndReached: Boolean get() = lastPage?.isEndReached ?: false
    }

    interface Page<T> {
        val items: List<T>
        val lastItem: T? get() = items.lastOrNull()
        val isEndReached: Boolean
    }
}

Note, the State also stores the last loaded page. It is used to download the following page, as well as to determine the end of the list.

Page is an interface made for flexibility. Your data source can map a page data to it's own class. For example, you can store an identifier of the last entity, or a link to the next page, or any data depending on your back-end requirements. The last page will be passed to a lambda pageSource from the constructor of the PagingImpl:

class PageInfo(
    override val items: List<Item>,
    override val isEndReached: Boolean
    lastItemId: Int
) : Paging.Page<Item>

PagingImpl(
    pageSource = { offset, lastPage ->
        repository
            .loadPage(lastItemId = lastPage?.lastItemId)
            .map {
                PageInfo(
                    items = it.list,
                    isEndReached = (offset + it.list.size) == it.totalCount
                    it.lastItemId
                )
            }
    }
)

Display the state

You can just use the resulting PLCE or LCE state to render your screen UI. Or you can use extensions from LoadingExtensions.kt and PagingExtensions.kt to observe individual state parts changes. It's helpful when you don't need all of the states or use with MVVM-like pattern.

In the sample we use the RxPM library and extensions to split resulting state to the Presentation Model states.

License

MIT License

Copyright (c) 2019 MobileUp

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].