Jetpack Paging 3 inside java/kotlin module
Asked Answered
I

1

7

I'm developing an app with clean architecture principles. I've a domain module which is a Java/Kotlin module and it hasn't android dependencies and a domainImpl module which is an Android module and has dependencies to local, remote and domain module. this is a Repository example inside domain module:

interface MovieRepository {
    fun getMovie(id: Long): Flow<Movie>
}

and below code is it's implementation inside domainImpl module:

class MovieRepositoryImpl(
    private val movieApi: MovieApi
) : MovieRepository {

    override fun getMovie(id: Long): Flow<Movie> = flow {
        emit(movieApi.getMovie(id))
    }

}

Everything works fine in this case. But Now I'm trying to add Android Paging 3 for my pagination. So I have to add a method to the MovieRepository interface like:

fun getMovies(): Flow<PagingData<Movie>>

But before this I've to add Paging library to my domain module but unfortunately it is an Android library and I couldn't find a core dependency for it. So What can I do about it? Do I have to change my domain module to an android module because of this? Or is there any other workaround?

Immunize answered 18/2, 2021 at 14:40 Comment(1)
#50548887Doubletree
C
13

The non android components of Paging are in androidx.paging:paging-common - any dependencies on presenter APIs are Android specific by definition so any code related to RecyclerView, LazyColumn, etc will need to be Android specific.

However PagingSource, PagingData, Pager, RemoteMediator are all provided by paging-common, so your implementation of those classes, including your transformation chain and overall output of Flow<PagingData> can be completely android-free.

Corvette answered 19/2, 2021 at 2:54 Comment(4)
Does this dependency work for you? I tried to add it to my pure Kotlin domain module but I receive "Cannot resolve dependency" error. Am I missing something?Mcmullin
What does your gradle file look like? AndroidX artifacts are hosted on Google's maven server here: maven.google.com/web/…Corvette
@Mcmullin please make sure you should have to use Java Version 1.8 instead of 1.7Sasha
thanks man, I resolved my problem by updating the java version to 1.8 on the gradleTenaille

© 2022 - 2024 — McMap. All rights reserved.