forked from boostcampwm-2022/android02-DailyFilm
-
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.
Merge pull request boostcampwm-2022#163 from eoeo0326/feat/search_com…
…pose_paging 검색 Compose Paging 적용
- Loading branch information
Showing
14 changed files
with
398 additions
and
702 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
39 changes: 39 additions & 0 deletions
39
app/src/main/java/com/boostcamp/dailyfilm/data/calendar/CalendarPagingSource.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,39 @@ | ||
package com.boostcamp.dailyfilm.data.calendar | ||
|
||
import androidx.paging.PagingSource | ||
import androidx.paging.PagingState | ||
import com.boostcamp.dailyfilm.data.model.DailyFilmItem | ||
|
||
class CalendarPagingSource( | ||
private val startAt: Int, | ||
private val endAt: Int, | ||
private val calendarDataSource: CalendarDataSource, | ||
) : PagingSource<Int, DailyFilmItem>() { | ||
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, DailyFilmItem> { | ||
runCatching { | ||
val page = params.key ?: 0 | ||
val data = calendarDataSource.loadPagedFilm(startAt, endAt, page).filterNotNull().map { it.mapToDailyFilmItem() } | ||
return LoadResult.Page( | ||
data = data, | ||
prevKey = if (page == 0) null else shouldPositive(page - PAGING_SIZE), | ||
nextKey = if (data.isEmpty()) null else page + data.size, | ||
) | ||
}.onFailure { | ||
return LoadResult.Error(it) | ||
} | ||
return LoadResult.Error(Exception("Unknown Error in CalendarPagingSource")) | ||
} | ||
|
||
override fun getRefreshKey(state: PagingState<Int, DailyFilmItem>): Int? { | ||
return state.anchorPosition?.let { anchorPosition -> | ||
state.closestPageToPosition(anchorPosition)?.prevKey?.plus(PAGING_SIZE) | ||
?: state.closestPageToPosition(anchorPosition)?.nextKey?.minus(PAGING_SIZE) | ||
} | ||
} | ||
|
||
private fun shouldPositive(num: Int) = if (num < 0) 0 else num | ||
|
||
companion object { | ||
const val PAGING_SIZE = 10 | ||
} | ||
} |
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
146 changes: 0 additions & 146 deletions
146
app/src/main/java/com/boostcamp/dailyfilm/presentation/searchfilm/SearchFilmActivity.kt
This file was deleted.
Oops, something went wrong.
42 changes: 0 additions & 42 deletions
42
...src/main/java/com/boostcamp/dailyfilm/presentation/searchfilm/SearchFilmBindingAdapter.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.