-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
97141c9
commit 633cd58
Showing
45 changed files
with
229 additions
and
288 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
File renamed without changes.
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
35 changes: 35 additions & 0 deletions
35
app/src/main/java/com/danteandroi/composewall/data/ImageSource.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,35 @@ | ||
package com.danteandroi.composewall.data | ||
|
||
import androidx.paging.PagingSource | ||
import androidx.paging.PagingState | ||
import com.danteandroi.composewall.MenuItem | ||
import com.danteandroi.composewall.net.ImageRepository | ||
|
||
/** | ||
* @author Du Wenyu | ||
* 2022/8/3 | ||
*/ | ||
class ImageSource(private val menuItem: MenuItem, private val repository: ImageRepository) : | ||
PagingSource<Int, Image>() { | ||
|
||
override fun getRefreshKey(state: PagingState<Int, Image>): Int? { | ||
return state.pages[state.anchorPosition?.plus(1) ?: 0].prevKey | ||
} | ||
|
||
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, Image> { | ||
return try { | ||
val nextPage = params.key ?: 1 | ||
val result = repository.fetchImages( | ||
apiClazz = menuItem.apiClazz, | ||
baseUrl = menuItem.baseUrl, | ||
category = menuItem.category[nextPage - 1].first, | ||
page = nextPage | ||
) | ||
LoadResult.Page(result, if (nextPage == 1) null else nextPage, nextPage + 1) | ||
} catch (e: Exception) { | ||
LoadResult.Error(e) | ||
} | ||
} | ||
|
||
|
||
} |
9 changes: 9 additions & 0 deletions
9
app/src/main/java/com/danteandroi/composewall/data/UiEvent.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,9 @@ | ||
package com.danteandroi.composewall.data | ||
|
||
/** | ||
* @author Du Wenyu | ||
* 2022/8/9 | ||
*/ | ||
enum class UiEvent { | ||
ScrollToTop, Refresh | ||
} |
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
Oops, something went wrong.