-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feat] 건빵집 리스트 페이징 구현 및 리팩토링 #230
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
01ad27f
[add] #228 페이징 관련 라이브러리 추가
Dan2dani cafe691
[feat] #228 페이지네이션 정보가 포함된 ResponseBakeryListDto 구현
Dan2dani 3fa7e27
[feat] #228 건빵집 리스트 받아오기 서비스에 pageNumber header 값 추가
Dan2dani 8f26fbb
[delete] #228 불필요한 코드 및 파일 삭
Dan2dani 3f512eb
[feat] #228 건빵집 리스트 페이지네이션을 위한 페이징 소스 구현
Dan2dani 636f192
[feat] #228 건빵집 리스트 필터 정보에 대한 data class 구현
Dan2dani c2e63ff
[feat] #228 건빵집 리스트, paging Data 생성을 위한 페이징 레포지토리 구현
Dan2dani f317823
[feat] #228 건빵집 리스트 ListAdapter -> PagingDataAdapter로 수정
Dan2dani 6a79fe1
[feat] #228 건빵집 리스트 필터 관련 정보 하나의 flow로 통합
Dan2dani 3da0bdf
[chore] #228 페이징 레포지토리 네이밍 수정
Dan2dani 1e6128c
Merge branch 'develop' into feat-bakery-list-pagination
Dan2dani e636b11
[feat] #228 breadFilterList 어뎁터에서 람다로 바인딩할 리스트 넘기고, view에서는 inflate만 …
Dan2dani 443a70a
[feat] #228 건빵집 리스트 카테고리 리스트 엠플리튜드 쏘는 부분 수정
Dan2dani 590dcdf
[feat] #228 건빵집 리스트 카테고리 리스트 엠플리튜드 쏘는 부분 수정
Dan2dani 253389c
Merge remote-tracking branch 'origin/feat-bakery-list-pagination' int…
Dan2dani 4380b3f
[chore] #228 ktlint 해결
Dan2dani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
18 changes: 0 additions & 18 deletions
18
app/src/main/java/com/sopt/geonppang/data/datasource/remote/BakeryDataSource.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
36 changes: 36 additions & 0 deletions
36
app/src/main/java/com/sopt/geonppang/data/repository/BakeryListPagingRepository.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,36 @@ | ||
package com.sopt.geonppang.data.repository | ||
|
||
import androidx.paging.Pager | ||
import androidx.paging.PagingConfig | ||
import com.sopt.geonppang.data.service.BakeryService | ||
import com.sopt.geonppang.domain.model.BakeryListFilterType | ||
import javax.inject.Inject | ||
|
||
class BakeryListPagingRepository @Inject constructor( | ||
private val bakeryService: BakeryService, | ||
) { | ||
fun fetchBakeryList( | ||
bakeryListFilterType: BakeryListFilterType | ||
) = run { | ||
Pager( | ||
config = PagingConfig( | ||
pageSize = PAGE_SIZE, | ||
enablePlaceholders = false, | ||
), | ||
pagingSourceFactory = { | ||
BakeryListPagingSource( | ||
bakeryService = bakeryService, | ||
sort = bakeryListFilterType.sortType.sortName, | ||
personal = bakeryListFilterType.isPersonalFilterApplied == true, | ||
isHard = bakeryListFilterType.isHard, | ||
isBrunch = bakeryListFilterType.isBrunch, | ||
isDessert = bakeryListFilterType.isDessert | ||
) | ||
} | ||
).flow | ||
} | ||
|
||
companion object { | ||
private const val PAGE_SIZE = 10 | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
app/src/main/java/com/sopt/geonppang/data/repository/BakeryListPagingSource.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,52 @@ | ||
package com.sopt.geonppang.data.repository | ||
|
||
import android.os.Build | ||
import androidx.annotation.RequiresExtension | ||
import androidx.paging.PagingSource | ||
import androidx.paging.PagingState | ||
import com.sopt.geonppang.data.service.BakeryService | ||
import com.sopt.geonppang.domain.model.BakeryInformation | ||
import retrofit2.HttpException | ||
import java.io.IOException | ||
|
||
class BakeryListPagingSource( | ||
private val bakeryService: BakeryService, | ||
private val sort: String, | ||
private val personal: Boolean, | ||
private val isHard: Boolean, | ||
private val isBrunch: Boolean, | ||
private val isDessert: Boolean, | ||
) : PagingSource<Int, BakeryInformation>() { | ||
override fun getRefreshKey(state: PagingState<Int, BakeryInformation>): Int? { | ||
return state.anchorPosition?.let { anchorPosition -> | ||
state.closestPageToPosition(anchorPosition)?.prevKey | ||
} | ||
} | ||
|
||
@RequiresExtension(extension = Build.VERSION_CODES.S, version = 7) | ||
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, BakeryInformation> { | ||
return try { | ||
val position = params.key ?: 1 | ||
val response = bakeryService.fetchBakeryList( | ||
sort = sort, | ||
personal = personal, | ||
isHard = isHard, | ||
isBrunch = isBrunch, | ||
isDessert = isDessert, | ||
pageNumber = position | ||
) | ||
|
||
val bakeryList = response.toBakery() | ||
|
||
LoadResult.Page( | ||
data = bakeryList, | ||
prevKey = if (position == 1) null else position - 1, | ||
nextKey = if (bakeryList.isNotEmpty()) position + 1 else null | ||
) | ||
} catch (exception: IOException) { | ||
return LoadResult.Error(exception) | ||
} catch (exception: HttpException) { | ||
return LoadResult.Error(exception) | ||
} | ||
} | ||
} |
21 changes: 0 additions & 21 deletions
21
app/src/main/java/com/sopt/geonppang/data/repository/BakeryRepositoryImpl.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
11 changes: 11 additions & 0 deletions
11
app/src/main/java/com/sopt/geonppang/domain/model/BakeryListFilterType.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,11 @@ | ||
package com.sopt.geonppang.domain.model | ||
|
||
import com.sopt.geonppang.presentation.type.BakerySortType | ||
|
||
data class BakeryListFilterType( | ||
val sortType: BakerySortType = BakerySortType.DEFAULT, | ||
val isPersonalFilterApplied: Boolean? = null, | ||
val isHard: Boolean = false, | ||
val isDessert: Boolean = false, | ||
val isBrunch: Boolean = false | ||
) |
13 changes: 0 additions & 13 deletions
13
app/src/main/java/com/sopt/geonppang/domain/repository/BakeryRepository.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SO 신기 ~ 페이징은 이렇게 쓰는 거군요