Skip to content

Commit

Permalink
Add paging helper (#7)
Browse files Browse the repository at this point in the history
## Description

Add `androidx.paging` [v3
library](https://developer.android.com/topic/libraries/architecture/paging/v3-overview)
helper to handle integration layer content with pagination.

There is two use cases

1. Requesting a amount of content with a list of urns that exceed the
integration layer page limit (50)
2. Requesting a result with a nextUrl

Both are supported with

1. `UrnsPagingSource`
2. `NexturlPagingSource`

### Recommended

We recommend to use `DataProviderPaging` that simplify the usage and
retrieve directly the content needed with `PagingDataAdapter`.

## Usage

```kotlin
val dataProvider = DataProviderPaging(...)
val pagingAdapter = PagingDataAdapter(...)

dataProvider.getMediaRecommendedByUrn(urn, pageSize = 15).collectLatest { pagingData ->
    pagingAdapter.submitData(pagingData)
}
```
  • Loading branch information
StaehliJ authored Jun 21, 2023
1 parent cc51886 commit 301bc0e
Show file tree
Hide file tree
Showing 20 changed files with 619 additions and 9 deletions.
9 changes: 5 additions & 4 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
object Versions {
const val coreKtx = "1.8.0"
const val lifecycle_version = "2.5.1"
const val lifecycle = "2.5.1"
const val dagger = "2.44.2"
const val retrofit_version = "2.9.0"
const val okHttp_version = "4.9.1"
const val gsonVersion = "2.10.1"
const val retrofit = "2.9.0"
const val okHttp = "4.9.1"
const val gson = "2.10.1"
const val detekt = "1.22.0"
const val paging = "3.1.1"
}
2 changes: 1 addition & 1 deletion data/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ android {

dependencies {
implementation("androidx.core:core-ktx:${Versions.coreKtx}")
implementation("com.google.code.gson:gson:${Versions.gsonVersion}")
implementation("com.google.code.gson:gson:${Versions.gson}")

testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
Expand Down
1 change: 1 addition & 0 deletions dataprovider-paging/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
79 changes: 79 additions & 0 deletions dataprovider-paging/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
plugins {
id("com.android.library")
id("org.jetbrains.kotlin.android")
id("org.jetbrains.kotlin.kapt")
`maven-publish`
}

android {
namespace = "ch.srgssr.dataprovider.paging"
compileSdk = Config.compileSdk

defaultConfig {
minSdk = Config.minSdk
targetSdk = Config.targetSdk
group = Config.maven_group
version = Config.versionName
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
lint {
// https://developer.android.com/reference/tools/gradle-api/4.1/com/android/build/api/dsl/LintOptions
abortOnError = false
}
}

dependencies {
api(project(mapOf("path" to ":dataprovider-retrofit")))
implementation("androidx.core:core-ktx:${Versions.coreKtx}")
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:${Versions.lifecycle}")
api("androidx.paging:paging-runtime-ktx:${Versions.paging}")

implementation("com.google.dagger:dagger:${Versions.dagger}")
kapt("com.google.dagger:dagger-compiler:${Versions.dagger}")

testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
}

publishing {
publications {
register<MavenPublication>("gpr") {
afterEvaluate {
from(components["release"])
}
}
}
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/SRGSSR/srgdataprovider-android")
credentials {
username = project.findProperty("gpr.user") as String? ?: System.getenv("USERNAME")
password = project.findProperty("gpr.key") as String? ?: System.getenv("GITHUB_TOKEN")
}
}
maven {
url = uri("https://maven.ecetest.rts.ch/content/repositories/srg-letterbox-releases/")
credentials {
username = project.findProperty("sonatypeUsername") as String? ?: System.getenv("SONATYPE_USERNAME")
password = project.findProperty("sonatypePassword") as String? ?: System.getenv("SONATYPE_PASSWORD")
}
}
}
}
Empty file.
21 changes: 21 additions & 0 deletions dataprovider-paging/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package ch.srgssr.dataprovider.paging

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("ch.srgssr.dataprovider.paging.test", appContext.packageName)
}
}
4 changes: 4 additions & 0 deletions dataprovider-paging/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
Loading

0 comments on commit 301bc0e

Please sign in to comment.