-
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
[#15] 검색화면 (SearchScreen) 구현 #16
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
41560c1
feat: add SearchKeyword service, repository, usecase
ksw4015 6d3cd32
feat: add SeachScreen
ksw4015 c806540
feat: add Loading progress
ksw4015 ec13457
style: change fun name
ksw4015 89e88b1
feat: keyboard hide after search query submit (SearchScreen)
ksw4015 4b89eae
design: change FestivalCard design
ksw4015 13476ee
Merge branch 'feature/searchscreen-21' into feature/15
ksw4015 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
40 changes: 40 additions & 0 deletions
40
app/src/main/java/kr/ksw/visitkorea/data/paging/source/SearchKeyWordPagingSource.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,40 @@ | ||
package kr.ksw.visitkorea.data.paging.source | ||
|
||
import androidx.paging.PagingSource | ||
import androidx.paging.PagingState | ||
import kr.ksw.visitkorea.data.mapper.toItems | ||
import kr.ksw.visitkorea.data.remote.api.SearchKeywordApi | ||
import kr.ksw.visitkorea.data.remote.dto.LocationBasedDTO | ||
|
||
class SearchKeyWordPagingSource( | ||
private val searchKeywordApi: SearchKeywordApi, | ||
private val keyword: String | ||
) : PagingSource<Int, LocationBasedDTO>(){ | ||
|
||
override fun getRefreshKey(state: PagingState<Int, LocationBasedDTO>): Int? { | ||
return state.anchorPosition?.let { anchor -> | ||
val anchorPage = state.closestPageToPosition(anchor) | ||
anchorPage?.prevKey?.plus(1) ?: anchorPage?.nextKey?.minus(1) | ||
} | ||
} | ||
|
||
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, LocationBasedDTO> { | ||
val page = params.key ?: 1 | ||
val loadSize = params.loadSize | ||
val data = try { | ||
searchKeywordApi.searchListByKeyword( | ||
numOfRows = loadSize, | ||
pageNo = page, | ||
keyword = keyword | ||
).toItems() | ||
} catch (e: Exception) { | ||
emptyList() | ||
} | ||
return LoadResult.Page( | ||
data = data, | ||
prevKey = if(page == 1 || data.isEmpty()) null else page - 1, | ||
nextKey = if(data.size == loadSize && data.isNotEmpty()) page + 1 else null | ||
) | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
app/src/main/java/kr/ksw/visitkorea/data/remote/api/SearchKeywordApi.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,17 @@ | ||
package kr.ksw.visitkorea.data.remote.api | ||
|
||
import kr.ksw.visitkorea.data.remote.dto.LocationBasedDTO | ||
import kr.ksw.visitkorea.data.remote.model.ApiResponse | ||
import retrofit2.http.GET | ||
import retrofit2.http.Query | ||
|
||
interface SearchKeywordApi { | ||
@GET("searchKeyword1") | ||
suspend fun searchListByKeyword( | ||
@Query("arrange") arrange: String = "Q", | ||
@Query("numOfRows") numOfRows: Int, | ||
@Query("pageNo") pageNo: Int, | ||
@Query("keyword") keyword: String, | ||
@Query("contentTypeId") contentTypeId: String? = null | ||
): ApiResponse<LocationBasedDTO> | ||
} |
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/kr/ksw/visitkorea/data/repository/SearchKeywordRepository.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 kr.ksw.visitkorea.data.repository | ||
|
||
import androidx.paging.PagingData | ||
import kotlinx.coroutines.flow.Flow | ||
import kr.ksw.visitkorea.data.remote.dto.LocationBasedDTO | ||
|
||
interface SearchKeywordRepository { | ||
suspend fun getListByKeyword( | ||
keyword: String | ||
): Result<Flow<PagingData<LocationBasedDTO>>> | ||
} |
41 changes: 41 additions & 0 deletions
41
app/src/main/java/kr/ksw/visitkorea/data/repository/SearchKeywordRepositoryImpl.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,41 @@ | ||
package kr.ksw.visitkorea.data.repository | ||
|
||
import androidx.paging.Pager | ||
import androidx.paging.PagingConfig | ||
import androidx.paging.PagingData | ||
import androidx.paging.PagingSource | ||
import kotlinx.coroutines.flow.Flow | ||
import kr.ksw.visitkorea.data.paging.source.SearchKeyWordPagingSource | ||
import kr.ksw.visitkorea.data.remote.api.SearchKeywordApi | ||
import kr.ksw.visitkorea.data.remote.dto.LocationBasedDTO | ||
import javax.inject.Inject | ||
|
||
class SearchKeywordRepositoryImpl @Inject constructor( | ||
private val searchKeywordApi: SearchKeywordApi | ||
) : SearchKeywordRepository { | ||
private var pagingSource: PagingSource<Int, LocationBasedDTO>? = null | ||
|
||
override suspend fun getListByKeyword( | ||
keyword: String | ||
): Result<Flow<PagingData<LocationBasedDTO>>> = runCatching { | ||
pagingSource?.run { | ||
if(!invalid) { | ||
invalidate() | ||
} | ||
} | ||
Pager( | ||
config = PagingConfig( | ||
pageSize = 30, | ||
initialLoadSize = 30 | ||
), | ||
pagingSourceFactory = { | ||
SearchKeyWordPagingSource( | ||
searchKeywordApi, | ||
keyword, | ||
).also { | ||
pagingSource = it | ||
} | ||
} | ||
).flow | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
app/src/main/java/kr/ksw/visitkorea/domain/di/SearchModule.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,17 @@ | ||
package kr.ksw.visitkorea.domain.di | ||
|
||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.android.components.ActivityRetainedComponent | ||
import kr.ksw.visitkorea.domain.usecase.search.GetListByKeywordUseCase | ||
import kr.ksw.visitkorea.domain.usecase.search.GetListByKeywordUseCaseImpl | ||
|
||
@Module | ||
@InstallIn(ActivityRetainedComponent::class) | ||
abstract class SearchModule { | ||
@Binds | ||
abstract fun bindGetListByKeywordUseCase( | ||
getListByKeywordUseCase: GetListByKeywordUseCaseImpl | ||
): GetListByKeywordUseCase | ||
} |
11 changes: 11 additions & 0 deletions
11
app/src/main/java/kr/ksw/visitkorea/domain/usecase/search/GetListByKeywordUseCase.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 kr.ksw.visitkorea.domain.usecase.search | ||
|
||
import androidx.paging.PagingData | ||
import kotlinx.coroutines.flow.Flow | ||
import kr.ksw.visitkorea.data.remote.dto.LocationBasedDTO | ||
|
||
interface GetListByKeywordUseCase { | ||
suspend operator fun invoke( | ||
keyword: String | ||
): Result<Flow<PagingData<LocationBasedDTO>>> | ||
} |
15 changes: 15 additions & 0 deletions
15
app/src/main/java/kr/ksw/visitkorea/domain/usecase/search/GetListByKeywordUseCaseImpl.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,15 @@ | ||
package kr.ksw.visitkorea.domain.usecase.search | ||
|
||
import androidx.paging.PagingData | ||
import kotlinx.coroutines.flow.Flow | ||
import kr.ksw.visitkorea.data.remote.dto.LocationBasedDTO | ||
import kr.ksw.visitkorea.data.repository.SearchKeywordRepository | ||
import javax.inject.Inject | ||
|
||
class GetListByKeywordUseCaseImpl @Inject constructor( | ||
private val searchKeywordRepository: SearchKeywordRepository | ||
): GetListByKeywordUseCase { | ||
override suspend fun invoke(keyword: String): Result<Flow<PagingData<LocationBasedDTO>>> { | ||
return searchKeywordRepository.getListByKeyword(keyword) | ||
} | ||
} |
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.
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.
방금 든 생각인데,
@QueryMap
을 사용하면 여러 개의 쿼리를 맵 하나에 넣어서 좀더 간편하게 할 수 있을 거 같아요.https://futurestud.io/tutorials/retrofit-2-add-multiple-query-parameter-with-querymap
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.
@QueryMap
을 쓰기에는 좀 애매하다고 생각했었는데, 한 번 적용해 보도록 하겠습니다.