-
Notifications
You must be signed in to change notification settings - Fork 1
feat : 서재에서 컬렉션 작품을 선택하는 기능 구현 #946
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
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
cf66bbb
feat: 컬렉션 내 서재 작품 선택 화면 추가 및 검색 화면 연동
devfeijoa 8611773
feat: 필터 없는 서재 작품 조회 추가
devfeijoa 40495c7
feat: 컬렉션 서재 작품 항목 추가
devfeijoa 103e3d3
feat: 서재 작품 컬렉션 모델 변환 추가
devfeijoa fe6c6d7
feat: feature/collection 모듈 내 Navigation 및 Paging Compose 의존성 추가
devfeijoa c151f1a
feat: 컬렉션 생성 내 서재 작품 선택 기능 구현
devfeijoa 6800b0d
feat: 컬렉션 서재 소설 선택 화면 내 로딩 인디케이터 추가
devfeijoa 47ecaa8
feat: 컬렉션 서재 내 작품 선택 화면 하단 로딩 인디케이터 추가
devfeijoa f1c82ce
refactor: 서재 관련 레포지토리 내 함수 코드 포맷팅 수정
devfeijoa 6f1ab63
feat: 서재 작품 선택 화면 내 데이터 로드 실패 대응 UI 추가
devfeijoa 3f3190c
fix: 서재 작품 선택 화면 내 에러 상태 처리 로직 개선
devfeijoa e9b7e31
refactor: feat/936 변경 사항을 feat/937에 동기화
devfeijoa 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
Some comments aren't visible on the classic Files Changed page.
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
202 changes: 202 additions & 0 deletions
202
...rc/main/java/com/into/websoso/feature/collection/CollectionLibraryNovelSelectionScreen.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,202 @@ | ||
| package com.into.websoso.feature.collection | ||
|
|
||
| import androidx.compose.foundation.Image | ||
| import androidx.compose.foundation.background | ||
| import androidx.compose.foundation.layout.Arrangement | ||
| import androidx.compose.foundation.layout.Box | ||
| import androidx.compose.foundation.layout.Column | ||
| import androidx.compose.foundation.layout.PaddingValues | ||
| import androidx.compose.foundation.layout.Spacer | ||
| import androidx.compose.foundation.layout.fillMaxSize | ||
| import androidx.compose.foundation.layout.fillMaxWidth | ||
| import androidx.compose.foundation.layout.height | ||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.foundation.layout.size | ||
| import androidx.compose.foundation.layout.statusBarsPadding | ||
| import androidx.compose.foundation.lazy.grid.GridCells | ||
| import androidx.compose.foundation.lazy.grid.GridItemSpan | ||
| import androidx.compose.foundation.lazy.grid.LazyVerticalGrid | ||
| import androidx.compose.foundation.shape.RoundedCornerShape | ||
| import androidx.compose.material3.Button | ||
| import androidx.compose.material3.ButtonDefaults | ||
| import androidx.compose.material3.CircularProgressIndicator | ||
| import androidx.compose.material3.Text | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.LaunchedEffect | ||
| import androidx.compose.runtime.getValue | ||
| import androidx.compose.ui.Alignment | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.res.painterResource | ||
| import androidx.compose.ui.res.stringResource | ||
| import androidx.compose.ui.text.style.TextAlign | ||
| import androidx.compose.ui.tooling.preview.Preview | ||
| import androidx.compose.ui.unit.dp | ||
| import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel | ||
| import androidx.lifecycle.compose.collectAsStateWithLifecycle | ||
| import androidx.paging.LoadState | ||
| import androidx.paging.PagingData | ||
| import androidx.paging.compose.LazyPagingItems | ||
| import androidx.paging.compose.collectAsLazyPagingItems | ||
| import com.into.websoso.core.designsystem.theme.Black | ||
| import com.into.websoso.core.designsystem.theme.Gray300 | ||
| import com.into.websoso.core.designsystem.theme.Primary100 | ||
| import com.into.websoso.core.designsystem.theme.WebsosoTheme | ||
| import com.into.websoso.core.designsystem.theme.White | ||
| import com.into.websoso.core.resource.R.drawable.img_load_fail | ||
| import com.into.websoso.core.resource.R.string.load_fail_description | ||
| import com.into.websoso.core.resource.R.string.load_fail_reload | ||
| import com.into.websoso.core.resource.R.string.load_fail_title | ||
| import com.into.websoso.feature.collection.component.CollectionAppBar | ||
| import com.into.websoso.feature.collection.component.CollectionLibraryNovelItem | ||
| import com.into.websoso.feature.collection.model.CollectionLibraryNovelUiModel | ||
| import kotlinx.coroutines.flow.flowOf | ||
|
|
||
| @Composable | ||
| internal fun CollectionLibraryNovelSelectionRoute( | ||
| initialSelectedNovelIds: Set<Long>, | ||
| onAddClick: (Set<Long>) -> Unit, | ||
| onNavigateBack: () -> Unit, | ||
| viewModel: CollectionLibraryNovelSelectionViewModel = hiltViewModel(), | ||
| ) { | ||
| val novels = viewModel.novels.collectAsLazyPagingItems() | ||
| val selectedNovelIds by viewModel.selectedNovelIds.collectAsStateWithLifecycle() | ||
|
|
||
| LaunchedEffect(initialSelectedNovelIds) { | ||
| viewModel.setSelectedNovelIds(initialSelectedNovelIds) | ||
| } | ||
|
|
||
| CollectionLibraryNovelSelectionScreen( | ||
| novels = novels, | ||
| selectedNovelIds = selectedNovelIds, | ||
| onNovelSelectionChange = viewModel::toggleNovelSelection, | ||
| onAddClick = { onAddClick(selectedNovelIds) }, | ||
| onNavigateBack = onNavigateBack, | ||
| ) | ||
| } | ||
|
|
||
| @Composable | ||
| internal fun CollectionLibraryNovelSelectionScreen( | ||
| novels: LazyPagingItems<CollectionLibraryNovelUiModel>, | ||
| selectedNovelIds: Set<Long>, | ||
| onNovelSelectionChange: (Long) -> Unit, | ||
| onAddClick: () -> Unit, | ||
| onNavigateBack: () -> Unit, | ||
| modifier: Modifier = Modifier, | ||
| ) { | ||
| Column( | ||
| modifier = modifier | ||
| .fillMaxSize() | ||
| .background(White) | ||
| .statusBarsPadding(), | ||
| ) { | ||
| CollectionAppBar( | ||
| title = "서재", | ||
| actionLabel = "추가", | ||
| onNavigateBack = onNavigateBack, | ||
| onActionClick = onAddClick, | ||
| isActionEnabled = selectedNovelIds.isNotEmpty(), | ||
| ) | ||
| Box( | ||
| modifier = Modifier | ||
| .fillMaxWidth() | ||
| .weight(1f), | ||
| ) { | ||
| when { | ||
| novels.itemCount == 0 && novels.loadState.refresh is LoadState.Loading -> { | ||
| CircularProgressIndicator(modifier = Modifier.align(Alignment.Center)) | ||
| } | ||
|
|
||
| (novels.itemCount == 0 && novels.loadState.refresh is LoadState.Error) || | ||
| novels.loadState.append is LoadState.Error -> { | ||
| Column( | ||
| modifier = Modifier.align(Alignment.Center), | ||
| horizontalAlignment = Alignment.CenterHorizontally, | ||
| ) { | ||
| Image( | ||
| painter = painterResource(img_load_fail), | ||
| contentDescription = null, | ||
| modifier = Modifier.size(width = 166.dp, height = 160.dp), | ||
| ) | ||
| Spacer(modifier = Modifier.height(40.dp)) | ||
| Text( | ||
| text = stringResource(load_fail_title), | ||
| color = Black, | ||
| style = WebsosoTheme.typography.title1, | ||
| textAlign = TextAlign.Center, | ||
| ) | ||
| Spacer(modifier = Modifier.height(10.dp)) | ||
| Text( | ||
| text = stringResource(load_fail_description), | ||
| color = Gray300, | ||
| style = WebsosoTheme.typography.body2, | ||
| textAlign = TextAlign.Center, | ||
| ) | ||
| Spacer(modifier = Modifier.height(40.dp)) | ||
| Button( | ||
| onClick = novels::retry, | ||
| shape = RoundedCornerShape(8.dp), | ||
| colors = ButtonDefaults.buttonColors(containerColor = Primary100), | ||
| contentPadding = PaddingValues(horizontal = 38.dp, vertical = 14.dp), | ||
| elevation = null, | ||
| ) { | ||
| Text( | ||
| text = stringResource(load_fail_reload), | ||
| color = White, | ||
| style = WebsosoTheme.typography.label1, | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| else -> { | ||
| LazyVerticalGrid( | ||
| columns = GridCells.Fixed(3), | ||
| modifier = Modifier.fillMaxSize(), | ||
| contentPadding = PaddingValues( | ||
| start = 20.dp, | ||
| top = 11.dp, | ||
| end = 20.dp, | ||
| ), | ||
| horizontalArrangement = Arrangement.spacedBy(6.dp), | ||
| verticalArrangement = Arrangement.spacedBy(18.dp), | ||
| ) { | ||
| items(novels.itemCount) { index -> | ||
| novels[index]?.let { novel -> | ||
| CollectionLibraryNovelItem( | ||
| novel = novel, | ||
| isSelected = novel.novelId in selectedNovelIds, | ||
| onSelectionChange = { onNovelSelectionChange(novel.novelId) }, | ||
| ) | ||
| } | ||
| } | ||
| if (novels.loadState.append is LoadState.Loading) { | ||
| item(span = { GridItemSpan(maxLineSpan) }) { | ||
| Box( | ||
| modifier = Modifier.fillMaxWidth(), | ||
| contentAlignment = Alignment.Center, | ||
| ) { | ||
| CircularProgressIndicator(modifier = Modifier.padding(16.dp)) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Preview(showBackground = true) | ||
| @Composable | ||
| private fun CollectionLibraryNovelSelectionScreenPreview() { | ||
| WebsosoTheme { | ||
| CollectionLibraryNovelSelectionScreen( | ||
| novels = flowOf(PagingData.empty<CollectionLibraryNovelUiModel>()) | ||
| .collectAsLazyPagingItems(), | ||
| selectedNovelIds = emptySet(), | ||
| onNovelSelectionChange = {}, | ||
| onAddClick = {}, | ||
| onNavigateBack = {}, | ||
| ) | ||
| } | ||
| } |
49 changes: 49 additions & 0 deletions
49
...main/java/com/into/websoso/feature/collection/CollectionLibraryNovelSelectionViewModel.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,49 @@ | ||
| package com.into.websoso.feature.collection | ||
|
|
||
| import androidx.lifecycle.ViewModel | ||
| import androidx.lifecycle.viewModelScope | ||
| import androidx.paging.PagingData | ||
| import androidx.paging.cachedIn | ||
| import androidx.paging.map | ||
| import com.into.websoso.data.library.LibraryRepository | ||
| import com.into.websoso.data.library.model.NovelEntity | ||
| import com.into.websoso.feature.collection.mapper.toUiModel | ||
| import com.into.websoso.feature.collection.model.CollectionLibraryNovelUiModel | ||
| import dagger.hilt.android.lifecycle.HiltViewModel | ||
| import kotlinx.coroutines.flow.Flow | ||
| import kotlinx.coroutines.flow.MutableStateFlow | ||
| import kotlinx.coroutines.flow.StateFlow | ||
| import kotlinx.coroutines.flow.asStateFlow | ||
| import kotlinx.coroutines.flow.map | ||
| import kotlinx.coroutines.flow.update | ||
| import javax.inject.Inject | ||
|
|
||
| @HiltViewModel | ||
| internal class CollectionLibraryNovelSelectionViewModel | ||
| @Inject | ||
| constructor( | ||
| libraryRepository: LibraryRepository, | ||
| ) : ViewModel() { | ||
| private val _selectedNovelIds = MutableStateFlow<Set<Long>>(emptySet()) | ||
| val selectedNovelIds: StateFlow<Set<Long>> = _selectedNovelIds.asStateFlow() | ||
|
|
||
| val novels: Flow<PagingData<CollectionLibraryNovelUiModel>> = | ||
| libraryRepository | ||
| .getUnfilteredLibraryFlow() | ||
| .map { pagingData -> pagingData.map(NovelEntity::toUiModel) } | ||
| .cachedIn(viewModelScope) | ||
|
|
||
| fun toggleNovelSelection(novelId: Long) { | ||
| _selectedNovelIds.update { selectedNovelIds -> | ||
| if (novelId in selectedNovelIds) { | ||
| selectedNovelIds - novelId | ||
| } else { | ||
| selectedNovelIds + novelId | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fun setSelectedNovelIds(novelIds: Set<Long>) { | ||
| _selectedNovelIds.value = novelIds | ||
| } | ||
| } |
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.
createLibraryFlow가 중복 함수같아 이를 통일하면 좋을 것 같습니다