-
Notifications
You must be signed in to change notification settings - Fork 0
feat: 서재UI/UX 개편 (5) - 타유저 서재 분기처리 #732
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
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f15a74d
refactor: 기존 LibraryRepository 제거 및 추상화
s9hn 0276571
refactor: FilterRepository 추상화 및 구현
s9hn 5419b20
refactor: Datastore My키워드 제거, 기존 LibraryFilterParams -> LibraryFilter…
s9hn aeefb22
refactor: PagingSource 및 RemoteMediator 리팩터링
s9hn cc9bb5c
refactor: 불필요한 파일 제거 및 UI 레이어 연결 리팩터링
s9hn 2ea8683
refactor: LibraryScreen으로 유저 ID 전달되도록 네비게이션 로직 수정
s9hn a075fc5
feat: FilterRepository 생성 및 DI 모듈 등록
s9hn b144eb8
feat: LibraryRepository 생성 및 DI 모듈 등록
s9hn f6fac80
refactor: LibraryFilterViewModel 제거
s9hn f3953c0
refactor: 서재 데이터에 오프셋 추가
s9hn f3b0126
refactor: hilt 스코프 수정
s9hn aade315
refactor: hilt 스코프 롤백
s9hn 78f19d6
refactor: hilt 스코프 롤백
s9hn 900eed7
Merge branch 'feat/699' of https://github.com/Team-WSS/WSS-Android in…
s9hn 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
22 changes: 22 additions & 0 deletions
22
...ain/java/com/into/websoso/core/datastore/datasource/library/mapper/LibraryFilterMapper.kt
This file contains hidden or 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,22 @@ | ||
| package com.into.websoso.core.datastore.datasource.library.mapper | ||
|
|
||
| import com.into.websoso.core.datastore.datasource.library.model.LibraryFilterPreferences | ||
| import com.into.websoso.data.filter.model.LibraryFilter | ||
|
|
||
| internal fun LibraryFilter.toPreferences(): LibraryFilterPreferences = | ||
| LibraryFilterPreferences( | ||
| sortCriteria = sortCriteria, | ||
| isInterested = isInterested, | ||
| readStatuses = readStatuses, | ||
| attractivePoints = attractivePoints, | ||
| novelRating = novelRating, | ||
| ) | ||
|
|
||
| internal fun LibraryFilterPreferences.toData(): LibraryFilter = | ||
| LibraryFilter( | ||
| sortCriteria = sortCriteria, | ||
| isInterested = isInterested, | ||
| readStatuses = readStatuses, | ||
| attractivePoints = attractivePoints, | ||
| novelRating = novelRating, | ||
| ) |
This file contains hidden or 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 hidden or 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 hidden or 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
16 changes: 16 additions & 0 deletions
16
data/library/src/main/java/com/into/websoso/data/filter/FilterRepository.kt
This file contains hidden or 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,16 @@ | ||
| package com.into.websoso.data.filter | ||
|
|
||
| import com.into.websoso.data.filter.model.LibraryFilter | ||
| import kotlinx.coroutines.flow.Flow | ||
|
|
||
| interface FilterRepository { | ||
| val filterFlow: Flow<LibraryFilter> | ||
|
|
||
| suspend fun updateFilter( | ||
| readStatuses: Map<String, Boolean>? = null, | ||
| attractivePoints: Map<String, Boolean>? = null, | ||
| novelRating: Float? = null, | ||
| isInterested: Boolean? = null, | ||
| sortCriteria: String? = null, | ||
| ) | ||
| } |
12 changes: 12 additions & 0 deletions
12
...ary/src/main/java/com/into/websoso/data/filter/datasource/LibraryFilterLocalDataSource.kt
This file contains hidden or 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,12 @@ | ||
| package com.into.websoso.data.filter.datasource | ||
|
|
||
| import com.into.websoso.data.filter.model.LibraryFilter | ||
| import kotlinx.coroutines.flow.Flow | ||
|
|
||
| interface LibraryFilterLocalDataSource { | ||
| val libraryFilterFlow: Flow<LibraryFilter?> | ||
|
|
||
| suspend fun updateLibraryFilter(params: LibraryFilter) | ||
|
|
||
| suspend fun deleteLibraryFilter() | ||
| } |
27 changes: 27 additions & 0 deletions
27
data/library/src/main/java/com/into/websoso/data/filter/di/FilterRepositoryModule.kt
This file contains hidden or 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 @@ | ||
| package com.into.websoso.data.filter.di | ||
|
|
||
| import androidx.lifecycle.SavedStateHandle | ||
| import com.into.websoso.data.filter.FilterRepository | ||
| import com.into.websoso.data.filter.repository.MyLibraryFilterRepository | ||
| import com.into.websoso.data.filter.repository.UserLibraryFilterRepository | ||
| import dagger.Module | ||
| import dagger.Provides | ||
| import dagger.hilt.InstallIn | ||
| import dagger.hilt.android.components.ViewModelComponent | ||
| import dagger.hilt.android.scopes.ViewModelScoped | ||
| import javax.inject.Provider | ||
|
|
||
| @Module | ||
| @InstallIn(ViewModelComponent::class) | ||
| internal object FilterRepositoryModule { | ||
| @Provides | ||
| @ViewModelScoped | ||
| fun provideFilterRepository( | ||
| savedStateHandle: SavedStateHandle, | ||
| myFilterRepository: Provider<MyLibraryFilterRepository>, | ||
| userFilterRepository: Provider<UserLibraryFilterRepository>, | ||
| ): FilterRepository { | ||
| val userId: Long? = savedStateHandle["USER_ID"] | ||
| return if (userId == null) myFilterRepository.get() else userFilterRepository.get() | ||
| } | ||
| } |
24 changes: 24 additions & 0 deletions
24
data/library/src/main/java/com/into/websoso/data/filter/model/LibraryFilter.kt
This file contains hidden or 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 @@ | ||
| package com.into.websoso.data.filter.model | ||
|
|
||
| data class LibraryFilter( | ||
| val sortCriteria: String = DEFAULT_SORT_CRITERIA, | ||
| val isInterested: Boolean = DEFAULT_IS_INTERESTED, | ||
| val novelRating: Float = DEFAULT_NOVEL_RATING, | ||
| val readStatuses: Map<String, Boolean> = emptyMap(), | ||
| val attractivePoints: Map<String, Boolean> = emptyMap(), | ||
| ) { | ||
| val readStatusKeys: List<String> = readStatuses.toSelectedKeyList { it } | ||
| val attractivePointKeys: List<String> = attractivePoints.toSelectedKeyList { it } | ||
|
|
||
| private fun <K> Map<K, Boolean>.toSelectedKeyList(toSelectedKeyName: (K) -> String): List<String> = | ||
| this | ||
| .filterValues { it } | ||
| .keys | ||
| .map { toSelectedKeyName(it) } | ||
|
|
||
| companion object { | ||
| private const val DEFAULT_SORT_CRITERIA = "RECENT" | ||
| private const val DEFAULT_IS_INTERESTED = false | ||
| private const val DEFAULT_NOVEL_RATING = 0.0f | ||
| } | ||
| } |
40 changes: 40 additions & 0 deletions
40
...ibrary/src/main/java/com/into/websoso/data/filter/repository/MyLibraryFilterRepository.kt
This file contains hidden or 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 com.into.websoso.data.filter.repository | ||
|
|
||
| import com.into.websoso.data.filter.FilterRepository | ||
| import com.into.websoso.data.filter.datasource.LibraryFilterLocalDataSource | ||
| import com.into.websoso.data.filter.model.LibraryFilter | ||
| import kotlinx.coroutines.flow.Flow | ||
| import kotlinx.coroutines.flow.distinctUntilChanged | ||
| import kotlinx.coroutines.flow.first | ||
| import kotlinx.coroutines.flow.map | ||
| import javax.inject.Inject | ||
|
|
||
| internal class MyLibraryFilterRepository | ||
| @Inject | ||
| constructor( | ||
| private val myLibraryFilterLocalDataSource: LibraryFilterLocalDataSource, | ||
| ) : FilterRepository { | ||
| override val filterFlow: Flow<LibraryFilter> = | ||
| myLibraryFilterLocalDataSource.libraryFilterFlow | ||
| .map { it ?: LibraryFilter() } | ||
| .distinctUntilChanged() | ||
|
|
||
| override suspend fun updateFilter( | ||
| readStatuses: Map<String, Boolean>?, | ||
| attractivePoints: Map<String, Boolean>?, | ||
| novelRating: Float?, | ||
| isInterested: Boolean?, | ||
| sortCriteria: String?, | ||
| ) { | ||
| val savedFilter = filterFlow.first() | ||
| val updatedFilter = savedFilter.copy( | ||
| sortCriteria = sortCriteria ?: savedFilter.sortCriteria, | ||
| isInterested = isInterested ?: savedFilter.isInterested, | ||
| readStatuses = readStatuses ?: savedFilter.readStatuses, | ||
| attractivePoints = attractivePoints ?: savedFilter.attractivePoints, | ||
| novelRating = novelRating ?: savedFilter.novelRating, | ||
| ) | ||
|
|
||
| myLibraryFilterLocalDataSource.updateLibraryFilter(params = updatedFilter) | ||
| } | ||
| } |
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.
🛠️ Refactor suggestion
JSON 인코딩 및 DataStore 작업에 대한 오류 처리 추가 필요
JSON 인코딩이나 DataStore 쓰기 작업이 실패할 경우를 대비한 try-catch 블록 추가를 고려해보세요.
override suspend fun updateLibraryFilter(params: LibraryFilter) { - val encodedJsonString = withContext(dispatcher) { - Json.encodeToString( - params.toPreferences(), - ) - } - - libraryFilterDataStore.edit { prefs -> - prefs[LIBRARY_FILTER_PARAMS_KEY] = encodedJsonString + try { + val encodedJsonString = withContext(dispatcher) { + Json.encodeToString( + params.toPreferences(), + ) + } + + libraryFilterDataStore.edit { prefs -> + prefs[LIBRARY_FILTER_PARAMS_KEY] = encodedJsonString + } + } catch (e: Exception) { + // 로깅 또는 에러 전파 + throw e } }📝 Committable suggestion
🤖 Prompt for AI Agents