diff --git a/app/build.gradle b/app/build.gradle index e0ae51bf..e1c60a52 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -96,32 +96,32 @@ dependencies { implementation 'androidx.core:core-ktx:1.3.2' implementation 'androidx.preference:preference-ktx:1.1.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' - implementation 'androidx.navigation:navigation-fragment-ktx:2.3.3' - implementation 'androidx.navigation:navigation-ui-ktx:2.3.3' + implementation 'androidx.navigation:navigation-fragment-ktx:2.3.4' + implementation 'androidx.navigation:navigation-ui-ktx:2.3.4' implementation "androidx.browser:browser:1.3.0" implementation 'androidx.recyclerview:recyclerview:1.1.0' implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0" - implementation 'androidx.navigation:navigation-fragment-ktx:2.3.3' - implementation 'androidx.navigation:navigation-ui-ktx:2.3.3' - implementation 'androidx.paging:paging-runtime-ktx:3.0.0-alpha12' - implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.2.0' - implementation 'androidx.lifecycle:lifecycle-viewmodel-savedstate:2.2.0' - implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.2.0" - implementation "androidx.lifecycle:lifecycle-common-java8:2.2.0" + implementation 'androidx.navigation:navigation-fragment-ktx:2.3.4' + implementation 'androidx.navigation:navigation-ui-ktx:2.3.4' + implementation 'androidx.paging:paging-runtime-ktx:3.0.0-beta02' + implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.0' + implementation 'androidx.lifecycle:lifecycle-viewmodel-savedstate:2.3.0' + implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.3.0" + implementation "androidx.lifecycle:lifecycle-common-java8:2.3.0" implementation "androidx.annotation:annotation:1.1.0" implementation 'androidx.gridlayout:gridlayout:1.0.0' // Use the most recent version of CameraX - def cameraX_version = '1.0.0-rc02' + def cameraX_version = '1.0.0-rc03' implementation "androidx.camera:camera-core:${cameraX_version}" implementation "androidx.camera:camera-camera2:${cameraX_version}" // CameraX Lifecycle library implementation "androidx.camera:camera-lifecycle:$cameraX_version" // CameraX View class - implementation 'androidx.camera:camera-view:1.0.0-alpha21' + implementation 'androidx.camera:camera-view:1.0.0-alpha22' - def room_version = "2.3.0-beta01" + def room_version = "2.3.0-beta03" implementation "androidx.room:room-runtime:$room_version" kapt "androidx.room:room-compiler:$room_version" implementation "androidx.room:room-ktx:$room_version" @@ -190,7 +190,7 @@ dependencies { // debugImplementation required vs testImplementation: https://issuetracker.google.com/issues/128612536 //noinspection FragmentGradleConfiguration - stagingImplementation("androidx.fragment:fragment-testing:1.3.0") { + stagingImplementation("androidx.fragment:fragment-testing:1.3.1") { exclude group:'androidx.test', module:'monitor' } diff --git a/app/src/main/java/com/h/pixeldroid/posts/feeds/uncachedFeeds/accountLists/FollowersPagingSource.kt b/app/src/main/java/com/h/pixeldroid/posts/feeds/uncachedFeeds/accountLists/FollowersPagingSource.kt index d219da09..d1eb8d8b 100644 --- a/app/src/main/java/com/h/pixeldroid/posts/feeds/uncachedFeeds/accountLists/FollowersPagingSource.kt +++ b/app/src/main/java/com/h/pixeldroid/posts/feeds/uncachedFeeds/accountLists/FollowersPagingSource.kt @@ -6,14 +6,15 @@ import com.h.pixeldroid.utils.api.PixelfedAPI import com.h.pixeldroid.utils.api.objects.Account import retrofit2.HttpException import java.io.IOException +import java.math.BigInteger class FollowersPagingSource( private val api: PixelfedAPI, private val accessToken: String, private val accountId: String, private val following: Boolean -) : PagingSource() { - override suspend fun load(params: LoadParams): LoadResult { +) : PagingSource() { + override suspend fun load(params: LoadParams): LoadResult { val position = params.key return try { val response = @@ -24,14 +25,14 @@ class FollowersPagingSource( api.followers(account_id = accountId, authorization = "Bearer $accessToken", limit = params.loadSize, - page = position?.toString(), - max_id = position?.toString()) + page = position, + max_id = position) } else { api.following(account_id = accountId, authorization = "Bearer $accessToken", limit = params.loadSize, - page = position?.toString(), - max_id = position?.toString()) + page = position, + max_id = position) } val accounts = if(response.isSuccessful){ @@ -40,19 +41,19 @@ class FollowersPagingSource( throw HttpException(response) } - val nextPosition = if(response.headers()["Link"] != null){ + val nextPosition: String = if(response.headers()["Link"] != null){ //Header is of the form: // Link: ; rel="next", ; rel="prev" // So we want the first max_id value. In case there are arguments after // the max_id in the URL, we make sure to stop at the first '?' response.headers()["Link"] .orEmpty() - .substringAfter("max_id=") - .substringBefore('?') - .substringBefore('>') - .toIntOrNull() ?: 0 + .substringAfter("max_id=", "") + .substringBefore('?', "") + .substringBefore('>', "") } else { - params.key?.plus(1) ?: 2 + // No Link header, so we just increment the position value + (position?.toBigIntegerOrNull() ?: 1.toBigInteger()).inc().toString() } LoadResult.Page( @@ -66,4 +67,9 @@ class FollowersPagingSource( LoadResult.Error(exception) } } + + override fun getRefreshKey(state: PagingState): String? = + state.anchorPosition?.run { + state.closestItemToPosition(this)?.id + } } \ No newline at end of file diff --git a/app/src/main/java/com/h/pixeldroid/posts/feeds/uncachedFeeds/search/SearchPagingSource.kt b/app/src/main/java/com/h/pixeldroid/posts/feeds/uncachedFeeds/search/SearchPagingSource.kt index 1d62aba3..63c4f87f 100644 --- a/app/src/main/java/com/h/pixeldroid/posts/feeds/uncachedFeeds/search/SearchPagingSource.kt +++ b/app/src/main/java/com/h/pixeldroid/posts/feeds/uncachedFeeds/search/SearchPagingSource.kt @@ -1,6 +1,7 @@ package com.h.pixeldroid.posts.feeds.uncachedFeeds.search import androidx.paging.PagingSource +import androidx.paging.PagingState import com.h.pixeldroid.utils.api.PixelfedAPI import com.h.pixeldroid.utils.api.objects.FeedContent import com.h.pixeldroid.utils.api.objects.Results @@ -44,4 +45,9 @@ class SearchPagingSource( LoadResult.Error(exception) } } + + override fun getRefreshKey(state: PagingState): Int? = + state.anchorPosition?.run { + state.closestItemToPosition(this)?.id?.toIntOrNull() + } } \ No newline at end of file