-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from onseok/feature/optimize-gallery-paging3-a…
…ndroid [feature/optimize-gallery-paging3-android] Integrate Paging3 for PeekabooGallery in Android
- Loading branch information
Showing
11 changed files
with
365 additions
and
133 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
97 changes: 0 additions & 97 deletions
97
peekaboo-ui/src/androidMain/kotlin/com/preat/peekaboo/ui/gallery/MediaPhoto.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
45 changes: 45 additions & 0 deletions
45
.../androidMain/kotlin/com/preat/peekaboo/ui/gallery/datasource/PeekabooGalleryDataSource.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,45 @@ | ||
/* | ||
* Copyright 2024 onseok | ||
* | ||
* 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 | ||
* | ||
* http://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.preat.peekaboo.ui.gallery.datasource | ||
|
||
import app.cash.paging.PagingSource | ||
import app.cash.paging.PagingState | ||
import com.preat.peekaboo.ui.gallery.model.PeekabooMediaImage | ||
|
||
internal class PeekabooGalleryDataSource( | ||
private val onFetch: (limit: Int, offset: Int) -> List<PeekabooMediaImage>, | ||
) : PagingSource<Int, PeekabooMediaImage>() { | ||
override fun getRefreshKey(state: PagingState<Int, PeekabooMediaImage>): Int? { | ||
return state.anchorPosition?.let { | ||
state.closestPageToPosition(it)?.prevKey?.plus(1) | ||
?: state.closestPageToPosition(it)?.nextKey?.minus(1) | ||
} | ||
} | ||
|
||
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, PeekabooMediaImage> { | ||
val pageNumber = params.key ?: 0 | ||
val pageSize = params.loadSize | ||
val pictures = onFetch.invoke(pageSize, pageNumber * pageSize) | ||
val prevKey = if (pageNumber > 0) pageNumber.minus(1) else null | ||
val nextKey = if (pictures.isNotEmpty()) pageNumber.plus(1) else null | ||
|
||
return LoadResult.Page( | ||
data = pictures, | ||
prevKey = prevKey, | ||
nextKey = nextKey, | ||
) | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
peekaboo-ui/src/androidMain/kotlin/com/preat/peekaboo/ui/gallery/model/PeekabooMediaImage.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,24 @@ | ||
/* | ||
* Copyright 2024 onseok | ||
* | ||
* 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 | ||
* | ||
* http://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.preat.peekaboo.ui.gallery.model | ||
|
||
import android.net.Uri | ||
|
||
internal data class PeekabooMediaImage( | ||
val id: Long, | ||
val uri: Uri, | ||
val name: String?, | ||
) |
27 changes: 27 additions & 0 deletions
27
.../androidMain/kotlin/com/preat/peekaboo/ui/gallery/repository/PeekabooGalleryRepository.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,27 @@ | ||
/* | ||
* Copyright 2024 onseok | ||
* | ||
* 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 | ||
* | ||
* http://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.preat.peekaboo.ui.gallery.repository | ||
|
||
import app.cash.paging.PagingSource | ||
import com.preat.peekaboo.ui.gallery.model.PeekabooMediaImage | ||
|
||
internal interface PeekabooGalleryRepository { | ||
suspend fun getCount(): Int | ||
|
||
suspend fun getByOffset(offset: Int): PeekabooMediaImage? | ||
|
||
fun getPicturePagingSource(): PagingSource<Int, PeekabooMediaImage> | ||
} |
Oops, something went wrong.