diff --git a/buildSrc/src/main/kotlin/ProjectInfo.kt b/buildSrc/src/main/kotlin/ProjectInfo.kt index dddce19..77d56ef 100644 --- a/buildSrc/src/main/kotlin/ProjectInfo.kt +++ b/buildSrc/src/main/kotlin/ProjectInfo.kt @@ -1,5 +1,5 @@ object P { - const val projectVersion = "3.1.0" + const val projectVersion = "3.1.1" const val projectGroupId = "com.kroegerama.android-kaiteki" diff --git a/retrofit/src/main/java/com/kroegerama/kaiteki/retrofit/Listing.kt b/retrofit/src/main/java/com/kroegerama/kaiteki/retrofit/Listing.kt index ffed178..2649798 100644 --- a/retrofit/src/main/java/com/kroegerama/kaiteki/retrofit/Listing.kt +++ b/retrofit/src/main/java/com/kroegerama/kaiteki/retrofit/Listing.kt @@ -17,7 +17,12 @@ class Listing( fun cancel() = cancelFun.invoke() } -fun LiveData>.result() = switchMap { it.result } -fun LiveData>.isRunning() = switchMap { it.state }.map { it.isRunning } -fun LiveData>.update() = value?.update() -fun LiveData>.cancel() = value?.cancel() \ No newline at end of file +fun LiveData>.result() = switchMap { it.result } +fun LiveData>.isRunning() = switchMap { it.state }.map { it.isRunning } +fun LiveData>.update() { + value?.update() +} + +fun LiveData>.cancel() { + value?.cancel() +} \ No newline at end of file diff --git a/retrofit/src/main/java/com/kroegerama/kaiteki/retrofit/PageKeyedPagination.kt b/retrofit/src/main/java/com/kroegerama/kaiteki/retrofit/PageKeyedPagination.kt index 543985a..5a8988c 100644 --- a/retrofit/src/main/java/com/kroegerama/kaiteki/retrofit/PageKeyedPagination.kt +++ b/retrofit/src/main/java/com/kroegerama/kaiteki/retrofit/PageKeyedPagination.kt @@ -66,7 +66,7 @@ class RetrofitPageKeyedDataSource( val page = pageProvider.firstPage val size = params.requestedLoadSize makeLoadRequest(true, page, size) { data -> - callback.onResult(data, pageProvider.getPreviousPage(page), pageProvider.getNextPage(page)) + callback.onResult(data, pageProvider.getPreviousPage(page, data.size, size), pageProvider.getNextPage(page, data.size, size)) } } @@ -74,7 +74,7 @@ class RetrofitPageKeyedDataSource( val page = params.key val size = params.requestedLoadSize makeLoadRequest(false, page, size) { data -> - callback.onResult(data, pageProvider.getNextPage(page)) + callback.onResult(data, pageProvider.getNextPage(page, data.size, size)) } } @@ -82,7 +82,7 @@ class RetrofitPageKeyedDataSource( val page = params.key val size = params.requestedLoadSize makeLoadRequest(false, page, size) { data -> - callback.onResult(data, pageProvider.getPreviousPage(page)) + callback.onResult(data, pageProvider.getPreviousPage(page, data.size, size)) } } diff --git a/retrofit/src/main/java/com/kroegerama/kaiteki/retrofit/PaginationHelper.kt b/retrofit/src/main/java/com/kroegerama/kaiteki/retrofit/PaginationHelper.kt index ec069a7..64d0d2d 100644 --- a/retrofit/src/main/java/com/kroegerama/kaiteki/retrofit/PaginationHelper.kt +++ b/retrofit/src/main/java/com/kroegerama/kaiteki/retrofit/PaginationHelper.kt @@ -10,14 +10,17 @@ internal typealias RetryFun = () -> Unit interface PageProvider { val firstPage: Int - fun getNextPage(currentPage: Int): Int? - fun getPreviousPage(currentPage: Int): Int? + fun getNextPage(currentPage: Int, currentSize: Int, requestedSize: Int): Int? + fun getPreviousPage(currentPage: Int, currentSize: Int, requestedSize: Int): Int? } object DefaultPageProvider : PageProvider { override val firstPage = 0 - override fun getNextPage(currentPage: Int) = currentPage + 1 - override fun getPreviousPage(currentPage: Int): Int? = null + + override fun getNextPage(currentPage: Int, currentSize: Int, requestedSize: Int) = + if (currentSize < requestedSize) null else currentPage + 1 + + override fun getPreviousPage(currentPage: Int, currentSize: Int, requestedSize: Int): Int? = null } val DefaultPageConfig by lazy { PagedList.Config.Builder().setPageSize(10).setPrefetchDistance(20).build() } @@ -45,12 +48,23 @@ class PagedListing( } } -fun LiveData>.pagedList() = switchMap { it.pagedList } -fun LiveData>.initialRunning() = switchMap { it.initialState }.map { it.isRunning } -fun LiveData>.loadRunning() = switchMap { it.loadState }.map { it.isRunning } -fun LiveData>.initialResult() = switchMap { it.initialResponse } -fun LiveData>.loadResult() = switchMap { it.loadResponse } -fun LiveData>.refresh() = value?.refresh() -fun LiveData>.retryInitial() = value?.retryInitial() -fun LiveData>.retryLoad() = value?.retryLoad() -fun LiveData>.cancel() = value?.cancel() \ No newline at end of file +fun LiveData>.pagedList() = switchMap { it.pagedList } +fun LiveData>.initialRunning() = switchMap { it.initialState }.map { it.isRunning } +fun LiveData>.loadRunning() = switchMap { it.loadState }.map { it.isRunning } +fun LiveData>.initialResult() = switchMap { it.initialResponse } +fun LiveData>.loadResult() = switchMap { it.loadResponse } +fun LiveData>.refresh() { + value?.refresh() +} + +fun LiveData>.retryInitial() { + value?.retryInitial() +} + +fun LiveData>.retryLoad() { + value?.retryLoad() +} + +fun LiveData>.cancel() { + value?.cancel() +} \ No newline at end of file