Skip to content
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

#39 add test, flow, core modules + up version #60

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .idea/copyright/IceRock.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/copyright/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 34 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ This is a Kotlin MultiPlatform library that contains pagination logic for kotlin
- **Pagination** implements pagination logic for the data from abstract `PagedListDataSource`.
- Managing a data loading process using **Pagination** asynchronous functions: `loadFirstPage`, `loadNextPage`,
`refresh` or their duplicates with `suspend` modifier.
- Observing states of **Pagination** using `LiveData` from **moko-mvvm**.
- Observing states of **Pagination** using `LiveData` from **moko-mvvm** or `Flow` from **kotlinx.coroutines**.

## Requirements
- Gradle version 6.8+
Expand All @@ -38,12 +38,18 @@ allprojects {
project build.gradle
```groovy
dependencies {
commonMainApi("dev.icerock.moko:paging:0.7.1")
commonMainApi("dev.icerock.moko:paging-core:0.8.0")
commonMainApi("dev.icerock.moko:paging-livedata:0.8.0")
commonMainApi("dev.icerock.moko:paging-flow:0.8.0")
commonMainApi("dev.icerock.moko:paging-state:0.8.0")
commonMainApi("dev.icerock.moko:paging-test:0.8.0")
}
```

## Usage

### LiveData

You can use **Pagination** in `commonMain` sourceset.

**Pagination** creation:
Expand Down Expand Up @@ -110,11 +116,35 @@ pagination.refreshLoading.addObserver { isRefreshing: Boolean ->
}
```

### Flow

```kotlin
// Observing the state of the pagination
pagination.state
.onEach { /* ... */ }
.launchIn(coroutineScope)

// Observing the next page loading process
pagination.nextPageLoading
.onEach { /* ... */ }
.launchIn(coroutineScope)

// Observing the refresh process
pagination.refreshLoading
.onEach { /* ... */ }
.launchIn(coroutineScope)
```


## Samples
Please see more examples in the [sample directory](sample).
Please see more examples in the [sample directory](sample) or [sample-declarative-ui](sample-declarative-ui)

## Set Up Locally
- The [paging directory](paging) contains the `paging` library;
- The [paging-core directory](paging-core) contains the core - pagination logic & data sources;
- The [paging-livedata directory](paging-livedata) contains implementation of the Pagination using `moko-mvvv-livedata`;
- The [paging-flow directory](paging-flow) contains implementation of the Pagination using `kotlinx.coroutines`;
- The [paging-state directory](paging-state) contains a set of code for working with the state of resources;
- The [paging-test directory](paging-test) contains a set of tests for pagination;
- The [sample directory](sample) contains sample apps for Android and iOS; plus the mpp-library connected to the apps.

## Contributing
Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ buildscript {
classpath(libs.mobileMultiplatformGradlePlugin)
classpath(libs.kotlinSerializationGradlePlugin)
classpath(libs.mokoUnitsGeneratorGradlePlugin)
classpath(libs.mokoKSwiftGradle)
}
}

Expand Down
12 changes: 9 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ recyclerViewVersion = "1.1.0"
swipeRefreshLayoutVersion = "1.1.0"
ktorClientVersion = "2.0.0"
coroutinesVersion = "1.6.0-native-mt"
mokoMvvmVersion = "0.12.0"
mokoResourcesVersion = "0.18.0"
mokoMvvmVersion = "0.13.0"
mokoResourcesVersion = "0.20.1"
mokoUnitsVersion = "0.8.0"
mokoPagingVersion = "0.7.1"
mokoKSwiftVersion = "0.5.0"
mokoPagingVersion = "0.8.0"

[libraries]
appCompat = { module = "androidx.appcompat:appcompat", version.ref = "androidAppCompatVersion" }
Expand All @@ -24,6 +25,9 @@ mokoUnits = { module = "dev.icerock.moko:units", version.ref = "mokoUnitsVersion
mokoUnitsDataBinding = { module = "dev.icerock.moko:units-databinding", version.ref = "mokoUnitsVersion" }
mokoMvvmLiveData = { module = "dev.icerock.moko:mvvm-livedata", version.ref = "mokoMvvmVersion" }
mokoMvvmState = { module = "dev.icerock.moko:mvvm-state", version.ref = "mokoMvvmVersion" }
mokoMvvmFlow = { module = "dev.icerock.moko:mvvm-flow", version.ref = "mokoMvvmVersion" }
mokoMvvmCore = { module = "dev.icerock.moko:mvvm-core", version.ref = "mokoMvvmVersion" }
mokoMvvmFlowCompose = { module = "dev.icerock.moko:mvvm-flow-compose", version.ref = "mokoMvvmVersion" }
kotlinTestJUnit = { module = "org.jetbrains.kotlin:kotlin-test-junit", version.ref = "kotlinVersion" }
androidCoreTesting = { module = "androidx.arch.core:core-testing", version.ref = "androidCoreTestingVersion" }
ktorClientMock = { module = "io.ktor:ktor-client-mock", version.ref = "ktorClientVersion" }
Expand All @@ -36,3 +40,5 @@ mokoGradlePlugin = { module = "dev.icerock.moko:moko-gradle-plugin", version = "
mobileMultiplatformGradlePlugin = { module = "dev.icerock:mobile-multiplatform", version = "0.14.1" }
kotlinSerializationGradlePlugin = { module = "org.jetbrains.kotlin:kotlin-serialization", version.ref = "kotlinVersion" }
mokoUnitsGeneratorGradlePlugin = { module = "dev.icerock.moko:units-generator", version.ref = "mokoUnitsVersion" }

mokoKSwiftGradle = { module = "dev.icerock.moko:kswift-gradle-plugin", version.ref = "mokoKSwiftVersion" }
14 changes: 14 additions & 0 deletions paging-core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
*/

plugins {
id("dev.icerock.moko.gradle.multiplatform.mobile")
id("dev.icerock.moko.gradle.publication")
id("dev.icerock.moko.gradle.stub.javadoc")
id("dev.icerock.moko.gradle.detekt")
}

dependencies {
commonMainApi(libs.coroutines)
}
2 changes: 2 additions & 0 deletions paging-core/src/androidMain/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="dev.icerock.moko.paging.core" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
*/

package dev.icerock.moko.paging

@Deprecated(
message = "deprecated due to package renaming",
replaceWith = ReplaceWith("IdEntity", "dev.icerock.moko.paging.core"),
level = DeprecationLevel.WARNING
)
typealias IdEntity = dev.icerock.moko.paging.core.IdEntity

@Deprecated(
message = "deprecated due to package renaming",
replaceWith = ReplaceWith("IdComparator", "dev.icerock.moko.paging.core"),
level = DeprecationLevel.WARNING
)
typealias IdComparator<T> = dev.icerock.moko.paging.core.IdComparator<T>

@Deprecated(
message = "deprecated due to package renaming",
replaceWith = ReplaceWith("LambdaPagedListDataSource", "dev.icerock.moko.paging.core"),
level = DeprecationLevel.WARNING
)
typealias LambdaPagedListDataSource<T> = dev.icerock.moko.paging.core.LambdaPagedListDataSource<T>

@Deprecated(
message = "deprecated due to package renaming",
replaceWith = ReplaceWith("PagedListDataSource", "dev.icerock.moko.paging.core"),
level = DeprecationLevel.WARNING
)
typealias PagedListDataSource<T> = dev.icerock.moko.paging.core.PagedListDataSource<T>

@Deprecated(
message = "deprecated due to package renaming",
replaceWith = ReplaceWith("ReachEndNotifierList", "dev.icerock.moko.paging.core"),
level = DeprecationLevel.WARNING
)
typealias ReachEndNotifierList<T> = dev.icerock.moko.paging.core.ReachEndNotifierList<T>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
*/

package dev.icerock.moko.paging.core

interface IdEntity {
val id: Long
}

class IdComparator<T : IdEntity> : Comparator<T> {
override fun compare(a: T, b: T): Int {
return if (a.id == b.id) 0 else 1
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
*/

package dev.icerock.moko.paging
package dev.icerock.moko.paging.core

class LambdaPagedListDataSource<T>(
private val loadPageLambda: suspend (List<T>?) -> List<T>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
*/

package dev.icerock.moko.paging
package dev.icerock.moko.paging.core

interface PagedListDataSource<T> {
suspend fun loadPage(currentList: List<T>?): List<T>
Expand Down
Loading