forked from android/sunflower
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Paging 3.0 for gallery screen (android#629)
* Add Paging dependency Also updates RecyclerView version and update ShareCompat API call * Update UnsplashService param order Move client_id to the last param * Implement Paging 3.0 Also remove default values for UnsplashService#searchPhotos * Remove unused method * Update paging version Co-authored-by: Florina Muntenescu <[email protected]> * Update recyclerview version Co-authored-by: Florina Muntenescu <[email protected]> * Address PR comments - catch Exception instead of IO/HttpException - disable Paging placeholders - remove unneeded local variable in searchPictures Co-authored-by: Florina Muntenescu <[email protected]>
- Loading branch information
1 parent
4ea76fb
commit a4e9eac
Showing
11 changed files
with
93 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
app/src/main/java/com/google/samples/apps/sunflower/data/UnsplashPagingSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright 2020 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.samples.apps.sunflower.data | ||
|
||
import androidx.paging.PagingSource | ||
import com.google.samples.apps.sunflower.api.UnsplashService | ||
|
||
private const val UNSPLASH_STARTING_PAGE_INDEX = 1 | ||
|
||
class UnsplashPagingSource ( | ||
private val service: UnsplashService, | ||
private val query: String | ||
) : PagingSource<Int, UnsplashPhoto>() { | ||
|
||
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, UnsplashPhoto> { | ||
val page = params.key ?: UNSPLASH_STARTING_PAGE_INDEX | ||
return try { | ||
val response = service.searchPhotos(query, page, params.loadSize) | ||
val photos = response.results | ||
LoadResult.Page( | ||
data = photos, | ||
prevKey = if (page == UNSPLASH_STARTING_PAGE_INDEX) null else page - 1, | ||
nextKey = if (page == response.totalPages) null else page + 1 | ||
) | ||
} catch (exception: Exception) { | ||
LoadResult.Error(exception) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 0 additions & 22 deletions
22
app/src/main/java/com/google/samples/apps/sunflower/data/UnsplashSearchResult.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters