-
Notifications
You must be signed in to change notification settings - Fork 3
[UI] 책 검색 페이지 화면 구현 #48
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
Changes from all commits
637f5d6
6032cbe
73d60bb
51e971e
49f63ad
cc0f376
87ad17a
237e036
45e9898
4c414ae
8d24e65
22f1997
0f16607
a8af0d4
d150312
e516df0
fa8cfbb
52e2a9b
63fccf3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| package com.texthip.thip.ui.booksearch.component | ||
|
|
||
| import androidx.compose.foundation.layout.Arrangement | ||
| import androidx.compose.foundation.layout.Column | ||
| import androidx.compose.foundation.layout.Spacer | ||
| import androidx.compose.foundation.layout.fillMaxSize | ||
| import androidx.compose.foundation.layout.height | ||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.foundation.layout.width | ||
| import androidx.compose.material3.Text | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.ui.Alignment | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.res.stringResource | ||
| import androidx.compose.ui.unit.dp | ||
| import com.texthip.thip.R | ||
| import com.texthip.thip.ui.common.buttons.ActionMediumButton | ||
| import com.texthip.thip.ui.theme.ThipTheme.colors | ||
| import com.texthip.thip.ui.theme.ThipTheme.typography | ||
|
|
||
| @Composable | ||
| fun BookEmptyResult( | ||
| mainText: String, | ||
| subText: String, | ||
| onRequestBook: () -> Unit | ||
| ) { | ||
| Column( | ||
| modifier = Modifier.fillMaxSize(), | ||
| verticalArrangement = Arrangement.Center, | ||
| horizontalAlignment = Alignment.CenterHorizontally | ||
| ) { | ||
| Text( | ||
| text = mainText, | ||
| color = colors.White, | ||
| style = typography.smalltitle_sb600_s18_h24 | ||
| ) | ||
| Text( | ||
| text = subText, | ||
| modifier = Modifier.padding(top = 8.dp), | ||
| color = colors.Grey, | ||
| style = typography.copy_r400_s14 | ||
| ) | ||
| Spacer(Modifier.height(20.dp)) | ||
|
|
||
| ActionMediumButton( | ||
| text = stringResource(R.string.group_register_book), | ||
| contentColor = colors.White, | ||
| backgroundColor = colors.Purple, | ||
| modifier = Modifier | ||
| .width(97.dp) | ||
| .height(44.dp), | ||
| onClick = { onRequestBook() }, | ||
| ) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| package com.texthip.thip.ui.booksearch.component | ||
|
|
||
| import androidx.compose.foundation.background | ||
| import androidx.compose.foundation.layout.* | ||
| import androidx.compose.foundation.lazy.LazyColumn | ||
| import androidx.compose.foundation.lazy.itemsIndexed | ||
| import androidx.compose.material3.Text | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.ui.Alignment | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.res.stringResource | ||
| import androidx.compose.ui.tooling.preview.Preview | ||
| import androidx.compose.ui.unit.dp | ||
| import com.texthip.thip.R | ||
| import com.texthip.thip.ui.booksearch.mock.BookData | ||
| import com.texthip.thip.ui.common.cards.CardBookList | ||
| import com.texthip.thip.ui.theme.ThipTheme | ||
| import com.texthip.thip.ui.theme.ThipTheme.colors | ||
| import com.texthip.thip.ui.theme.ThipTheme.typography | ||
|
|
||
| @Composable | ||
| fun BookFilteredSearchResult( | ||
| resultCount: Int, | ||
| bookList: List<BookData> | ||
| ) { | ||
| Column { | ||
| Row( | ||
| modifier = Modifier.fillMaxWidth(), | ||
| verticalAlignment = Alignment.CenterVertically | ||
| ) { | ||
| Text( | ||
| text = stringResource(R.string.group_searched_room_size, resultCount), | ||
| color = colors.Grey, | ||
| style = typography.menu_m500_s14_h24 | ||
| ) | ||
| } | ||
| Spacer( | ||
| modifier = Modifier | ||
| .padding(top = 4.dp, bottom = 20.dp) | ||
| .fillMaxWidth() | ||
| .height(1.dp) | ||
| .background(colors.DarkGrey02) | ||
| ) | ||
|
|
||
| if (bookList.isEmpty()) { | ||
| BookEmptyResult( | ||
| mainText = stringResource(R.string.book_no_search_result1), | ||
| subText = stringResource(R.string.book_no_search_result2), | ||
| onRequestBook = { /*책 요청 처리*/ } | ||
| ) | ||
| } else { | ||
| LazyColumn( | ||
| verticalArrangement = Arrangement.Center | ||
| ) { | ||
| itemsIndexed(bookList) { index, book -> | ||
| CardBookList( | ||
| title = book.title, | ||
| author = book.author, | ||
| publisher = book.publisher, | ||
| imageRes = book.imageRes | ||
| ) | ||
| if (index < bookList.size - 1) { | ||
| Spacer( | ||
| modifier = Modifier | ||
| .padding(top = 12.dp, bottom = 12.dp) | ||
| .fillMaxWidth() | ||
| .height(1.dp) | ||
| .background(colors.DarkGrey02) | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Preview | ||
| @Composable | ||
| fun PreviewBookFilteredSearchResult() { | ||
| ThipTheme { | ||
| BookFilteredSearchResult( | ||
| resultCount = 3, | ||
| bookList = listOf( | ||
| BookData( | ||
| title = "이기적 유전자", | ||
| author = "리처드 도킨스", | ||
| publisher = "을유문화사" | ||
| ), | ||
| BookData( | ||
| title = "총, 균, 쇠", | ||
| author = "재레드 다이아몬드", | ||
| publisher = "문학사상사" | ||
| ), | ||
| BookData( | ||
| title = "코스모스", | ||
| author = "칼 세이건", | ||
| publisher = "사이언스북스" | ||
| ) | ||
| ) | ||
| ) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,43 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||
| package com.texthip.thip.ui.booksearch.component | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.foundation.background | ||||||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.foundation.layout.Arrangement | ||||||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.foundation.layout.Spacer | ||||||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.foundation.layout.fillMaxWidth | ||||||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.foundation.layout.height | ||||||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.foundation.layout.padding | ||||||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.foundation.lazy.LazyColumn | ||||||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.foundation.lazy.itemsIndexed | ||||||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.runtime.Composable | ||||||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.ui.Modifier | ||||||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.ui.unit.dp | ||||||||||||||||||||||||||||||||||||||||||||||||
| import com.texthip.thip.ui.booksearch.mock.BookData | ||||||||||||||||||||||||||||||||||||||||||||||||
| import com.texthip.thip.ui.common.cards.CardBookList | ||||||||||||||||||||||||||||||||||||||||||||||||
| import com.texthip.thip.ui.theme.ThipTheme.colors | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| @Composable | ||||||||||||||||||||||||||||||||||||||||||||||||
| fun BookLiveSearchResult( | ||||||||||||||||||||||||||||||||||||||||||||||||
| bookList: List<BookData> | ||||||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| LazyColumn( | ||||||||||||||||||||||||||||||||||||||||||||||||
| verticalArrangement = Arrangement.Center | ||||||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| itemsIndexed(bookList) { index, book -> | ||||||||||||||||||||||||||||||||||||||||||||||||
| CardBookList( | ||||||||||||||||||||||||||||||||||||||||||||||||
| title = book.title, | ||||||||||||||||||||||||||||||||||||||||||||||||
| author = book.author, | ||||||||||||||||||||||||||||||||||||||||||||||||
| publisher = book.publisher, | ||||||||||||||||||||||||||||||||||||||||||||||||
| imageRes = book.imageRes | ||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||
| if (index < bookList.size - 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+25
to
+32
|
||||||||||||||||||||||||||||||||||||||||||||||||
| itemsIndexed(bookList) { index, book -> | |
| CardBookList( | |
| title = book.title, | |
| author = book.author, | |
| publisher = book.publisher, | |
| imageRes = book.imageRes | |
| ) | |
| if (index < bookList.size - 1) { | |
| items(bookList.flatMapIndexed { index, book -> | |
| if (index < bookList.size - 1) { | |
| listOf(book, null) // Add a null to represent a spacer | |
| } else { | |
| listOf(book) // No spacer after the last item | |
| } | |
| }) { item -> | |
| if (item != null) { | |
| CardBookList( | |
| title = item.title, | |
| author = item.author, | |
| publisher = item.publisher, | |
| imageRes = item.imageRes | |
| ) | |
| } else { |
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.
The spacer logic should be moved outside the itemsIndexed block to avoid conditional rendering inside compose items, which can cause performance issues.