Skip to content
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 16 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
01ad27f
[add] #228 페이징 관련 라이브러리 추가
Dan2dani Feb 19, 2024
cafe691
[feat] #228 페이지네이션 정보가 포함된 ResponseBakeryListDto 구현
Dan2dani Feb 19, 2024
3fa7e27
[feat] #228 건빵집 리스트 받아오기 서비스에 pageNumber header 값 추가
Dan2dani Feb 19, 2024
8f26fbb
[delete] #228 불필요한 코드 및 파일 삭
Dan2dani Feb 19, 2024
3f512eb
[feat] #228 건빵집 리스트 페이지네이션을 위한 페이징 소스 구현
Dan2dani Feb 19, 2024
636f192
[feat] #228 건빵집 리스트 필터 정보에 대한 data class 구현
Dan2dani Feb 19, 2024
c2e63ff
[feat] #228 건빵집 리스트, paging Data 생성을 위한 페이징 레포지토리 구현
Dan2dani Feb 19, 2024
f317823
[feat] #228 건빵집 리스트 ListAdapter -> PagingDataAdapter로 수정
Dan2dani Feb 19, 2024
6a79fe1
[feat] #228 건빵집 리스트 필터 관련 정보 하나의 flow로 통합
Dan2dani Feb 19, 2024
3da0bdf
[chore] #228 페이징 레포지토리 네이밍 수정
Dan2dani Feb 19, 2024
1e6128c
Merge branch 'develop' into feat-bakery-list-pagination
Dan2dani Feb 20, 2024
e636b11
[feat] #228 breadFilterList 어뎁터에서 람다로 바인딩할 리스트 넘기고, view에서는 inflate만 …
Dan2dani Feb 20, 2024
443a70a
[feat] #228 건빵집 리스트 카테고리 리스트 엠플리튜드 쏘는 부분 수정
Dan2dani Feb 20, 2024
590dcdf
[feat] #228 건빵집 리스트 카테고리 리스트 엠플리튜드 쏘는 부분 수정
Dan2dani Feb 20, 2024
253389c
Merge remote-tracking branch 'origin/feat-bakery-list-pagination' int…
Dan2dani Feb 20, 2024
4380b3f
[chore] #228 ktlint 해결
Dan2dani Feb 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ dependencies {

// kakao
implementation "com.kakao.sdk:v2-all:2.15.0"

// paging
implementation 'androidx.paging:paging-runtime-ktx:3.2.1'
implementation 'androidx.paging:paging-common-android:3.3.0-alpha03'
}

ktlint {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class GPDataSource @Inject constructor(@ApplicationContext context: Context) {
set(value) = dataStore.edit { putBoolean(IS_LOGIN, value) }
get() = dataStore.getBoolean(IS_LOGIN, false)

// TODO: all 앱 내에서의 userRoleType 어떻게 관리할 것인지 논의
var userRoleType: String
set(value) = dataStore.edit { putString(USER_ROLE_TYPE, value) }
get() = dataStore.getString(
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,42 +1,71 @@
package com.sopt.geonppang.data.model.response

import com.sopt.geonppang.domain.model.Bakery
import com.sopt.geonppang.domain.model.BreadType
import com.sopt.geonppang.domain.model.BakeryInformation
import com.sopt.geonppang.presentation.type.BreadFilterType
import kotlinx.serialization.Serializable

@Serializable
data class ResponseBakeryList(
val code: Int,
val data: List<Data>,
val message: String,
val data: Data,
val message: String
) {
@Serializable
data class Data(
val bakeryId: Int,
val bakeryName: String,
val bakeryPicture: String,
val bookMarkCount: Int,
val breadType: BreadType,
val firstNearStation: String,
val isHACCP: Boolean,
val isNonGMO: Boolean,
val isVegan: Boolean,
val reviewCount: Int,
val secondNearStation: String,
val content: List<Content>,
val empty: Boolean,
val first: Boolean,
val last: Boolean,
val number: Int,
val numberOfElements: Int,
val pageable: Pageable,
val size: Int,
val sort: Sort,
val totalElements: Int,
val totalPages: Int
) {
@Serializable
data class BreadType(
val breadTypeId: Int,
val breadTypeName: String,
val isGlutenFree: Boolean,
val isNutFree: Boolean,
val isSugarFree: Boolean,
data class Content(
val bakeryId: Int,
val bakeryName: String,
val bakeryPicture: String,
val bookMarkCount: Int,
val breadTypeList: List<BreadTypeIdDto>,
val firstNearStation: String,
val isHACCP: Boolean,
val isNonGMO: Boolean,
val isVegan: Boolean,
val reviewCount: Int,
val secondNearStation: String
)

@Serializable
data class Pageable(
val offset: Int,
val pageNumber: Int,
val pageSize: Int,
val paged: Boolean,
val sort: Sort,
val unpaged: Boolean
) {
@Serializable
data class Sort(
val empty: Boolean,
val sorted: Boolean,
val unsorted: Boolean
)
}

@Serializable
data class Sort(
val empty: Boolean,
val sorted: Boolean,
val unsorted: Boolean
)
}

fun toBakery() = data.map { bakery ->
Bakery(
fun toBakery() = data.content.map { bakery ->
BakeryInformation(
bakeryId = bakery.bakeryId,
bakeryName = bakery.bakeryName,
bakeryPicture = bakery.bakeryPicture,
Expand All @@ -46,14 +75,11 @@ data class ResponseBakeryList(
isNonGMO = bakery.isNonGMO,
isVegan = bakery.isVegan,
isHACCP = bakery.isHACCP,
breadType = BreadType(
bakery.breadType.breadTypeId,
bakery.breadType.breadTypeName,
bakery.breadType.isGlutenFree,
bakery.breadType.isVegan,
bakery.breadType.isNutFree,
bakery.breadType.isSugarFree,
)
breadTypeList = bakery.breadTypeList.mapNotNull { breadTypeIdDto ->
BreadFilterType.values().find {
it.id == breadTypeIdDto.breadTypeId
}
}
)
}
}
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
Comment on lines +15 to +30
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SO 신기 ~ 페이징은 이렇게 쓰는 거군요

}

companion object {
private const val PAGE_SIZE = 10
}
}
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)
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ interface BakeryService {
@Query("isHard") isHard: Boolean,
@Query("isDessert") isDessert: Boolean,
@Query("isBrunch") isBrunch: Boolean,
@Query("pageNumber") pageNumber: Int
): ResponseBakeryList
}
6 changes: 0 additions & 6 deletions app/src/main/java/com/sopt/geonppang/di/RepositoryModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ interface RepositoryModule {
searchRepositoryImpl: SearchRepositoryImpl,
): SearchRepository

@Binds
@Singleton
fun bindBakeryRepository(
bakeryRepositoryImpl: BakeryRepositoryImpl,
): BakeryRepository

@Binds
@Singleton
fun bindMyPageRepository(
Expand Down
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
)

This file was deleted.

Loading
Loading