Skip to content

Commit

Permalink
initial migration to Jetpack Paging KMP support
Browse files Browse the repository at this point in the history
  • Loading branch information
joreilly committed May 14, 2024
1 parent fbf7884 commit b920b7c
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@ import dev.johnoreilly.mortycomposekmm.fragment.CharacterDetail
import dev.johnoreilly.mortycomposekmm.fragment.EpisodeDetail
import dev.johnoreilly.mortycomposekmm.fragment.LocationDetail
import dev.johnoreilly.mortycomposekmm.shared.MortyRepository
import dev.johnoreilly.mortycomposekmm.ui.episodes.EpisodesDataSource
import dev.johnoreilly.mortycomposekmm.ui.locations.LocationsDataSource
import dev.johnoreilly.mortycomposekmm.shared.paging.CharactersDataSource
import dev.johnoreilly.mortycomposekmm.shared.paging.EpisodesDataSource
import dev.johnoreilly.mortycomposekmm.shared.paging.LocationsDataSource
import kotlinx.coroutines.flow.Flow


class MainViewModel(private val repository: MortyRepository): ViewModel() {

// currently only using MultiplatformPaging library for character data
val characters = repository.characterPagingData
val characters: Flow<PagingData<CharacterDetail>> = Pager(PagingConfig(pageSize = 20)) {
CharactersDataSource(repository)
}.flow.cachedIn(viewModelScope)


// continuing to use androidx paging library directly (as contrast) for
// episode and location lists
val episodes: Flow<PagingData<EpisodeDetail>> = Pager(PagingConfig(pageSize = 20)) {
EpisodesDataSource(repository)
}.flow.cachedIn(viewModelScope)
Expand Down
5 changes: 3 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ kmpNativeCoroutines = "1.0.0-ALPHA-24-kotlin-2.0.0-Beta3"
androidxActivity = "1.8.2"
androidxComposeCompiler = "1.5.11-dev-k2.0.0-Beta4-21f5e479a96"
androidxComposeBom = "2024.02.01"
androidxPagingCompose = "3.2.1"
androidxPaging = "3.3.0"
androidxNavigationCompose = "2.7.7"
accompanist = "0.30.1"
coilCompose = "2.6.0"
Expand Down Expand Up @@ -43,7 +43,8 @@ androidx-compose-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-
androidx-compose-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }
androidx-compose-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }

androidx-paging-compose = { group = "androidx.paging", name = "paging-compose", version.ref = "androidxPagingCompose" }
androidx-paging-compose = { group = "androidx.paging", name = "paging-compose", version.ref = "androidxPaging" }
androidx-paging-common = { group = "androidx.paging", name = "paging-common", version.ref = "androidxPaging" }
androidx-navigation-compose = { group = "androidx.navigation", name = "navigation-compose", version.ref = "androidxNavigationCompose" }
accompanist-insets = { group = "com.google.accompanist", name = "accompanist-insets", version.ref = "accompanist" }
coilCompose = { group = "io.coil-kt", name = "coil-compose", version.ref = "coilCompose" }
Expand Down
1 change: 1 addition & 0 deletions shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ kotlin {
implementation(libs.apollo.normalized.cache)
implementation(libs.apollo.normalized.cache.sqlite)

api(libs.androidx.paging.common)
api(libs.multiplatformPaging)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.johnoreilly.mortycomposekmm.ui.characters
package dev.johnoreilly.mortycomposekmm.shared.paging

import androidx.paging.PagingSource
import androidx.paging.PagingState
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.johnoreilly.mortycomposekmm.ui.episodes
package dev.johnoreilly.mortycomposekmm.shared.paging

import androidx.paging.PagingSource
import androidx.paging.PagingState
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.johnoreilly.mortycomposekmm.ui.locations
package dev.johnoreilly.mortycomposekmm.shared.paging

import androidx.paging.PagingSource
import androidx.paging.PagingState
Expand Down

0 comments on commit b920b7c

Please sign in to comment.