-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOnboardingContentScreen.kt
More file actions
306 lines (286 loc) · 12.2 KB
/
OnboardingContentScreen.kt
File metadata and controls
306 lines (286 loc) · 12.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
package com.flint.presentation.onboarding
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.lazy.LazyRow
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.lazy.grid.itemsIndexed
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
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.graphics.Color
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.flint.core.common.extension.dropShadow
import com.flint.core.common.util.UiState
import com.flint.core.designsystem.component.button.FlintBasicButton
import com.flint.core.designsystem.component.button.FlintButtonState
import com.flint.core.designsystem.component.image.SelectedContentItem
import com.flint.core.designsystem.component.textfield.FlintSearchTextField
import com.flint.core.designsystem.component.topappbar.FlintBackTopAppbar
import com.flint.core.designsystem.component.view.FlintSearchEmptyView
import com.flint.core.designsystem.theme.FlintTheme
import com.flint.domain.model.search.SearchContentItemModel
import com.flint.domain.model.search.SearchContentListModel
import com.flint.presentation.onboarding.component.OnboardingContentItem
import com.flint.presentation.onboarding.component.StepProgressBar
@Composable
fun OnboardingContentRoute(
paddingValues: PaddingValues,
navigateToOnboardingOtt: () -> Unit,
navigateUp: () -> Unit,
viewModel: OnboardingViewModel = hiltViewModel(),
) {
val profileUiState by viewModel.uiState.collectAsStateWithLifecycle()
val contentUiState by viewModel.contentUiState.collectAsStateWithLifecycle()
LaunchedEffect(Unit) {
viewModel.loadInitialContents()
}
OnboardingContentScreen(
nickname = profileUiState.nickname,
contentUiState = contentUiState,
onBackClick = navigateUp,
onNextClick = navigateToOnboardingOtt,
onSearchKeywordChanged = viewModel::updateSearchKeyword,
onSearchAction = viewModel::searchContents,
onClearAction = viewModel::loadInitialContents,
onContentClick = viewModel::toggleContentSelection,
onRemoveContent = viewModel::toggleContentSelection,
modifier = Modifier.padding(paddingValues),
)
}
@Composable
fun OnboardingContentScreen(
nickname: String,
contentUiState: OnboardingContentUiState,
onBackClick: () -> Unit,
onNextClick: () -> Unit,
onSearchKeywordChanged: (String) -> Unit,
onSearchAction: () -> Unit,
onClearAction: () -> Unit,
onContentClick: (SearchContentItemModel) -> Unit,
onRemoveContent: (SearchContentItemModel) -> Unit,
modifier: Modifier = Modifier,
) {
val keyboardController = LocalSoftwareKeyboardController.current
Column(
modifier =
modifier
.fillMaxSize()
.background(color = FlintTheme.colors.background),
) {
FlintBackTopAppbar(
onClick = onBackClick,
)
StepProgressBar(
currentStep = contentUiState.selectedContents.size,
totalSteps = OnboardingContentUiState.REQUIRED_SELECTION_COUNT,
modifier = Modifier.padding(horizontal = 20.dp),
)
Spacer(modifier = Modifier.height(23.dp))
// 전체 콘텐츠를 LazyVerticalGrid로 구성
LazyVerticalGrid(
columns = GridCells.Fixed(3),
modifier = Modifier.weight(1f),
contentPadding = PaddingValues(horizontal = 16.dp),
horizontalArrangement = Arrangement.spacedBy(14.dp),
) {
// 타이틀 영역 - 스크롤됨
item(span = { GridItemSpan(3) }) {
Column {
Text(
text = "${nickname}님이 좋아하는 작품\n7개를 골라주세요",
color = FlintTheme.colors.white,
style = FlintTheme.typography.display2M28,
)
Spacer(modifier = Modifier.height(8.dp))
}
}
// 검색창 - sticky header (상단에 고정)
stickyHeader {
Column(
modifier =
Modifier
.background(FlintTheme.colors.background)
.padding(bottom = 16.dp)
.dropShadow(
shape = RectangleShape,
color = Color.Black.copy(alpha = 0.75f),
blur = 12.dp,
offsetY = 12.dp,
offsetX = 0.dp,
spread = 0.dp
)
) {
Text(
text = contentUiState.currentStepQuestion,
color = FlintTheme.colors.gray300,
style = FlintTheme.typography.body2R14,
)
Spacer(modifier = Modifier.height(24.dp))
FlintSearchTextField(
placeholder = "작품 이름",
value = contentUiState.searchKeyword,
onValueChanged = onSearchKeywordChanged,
onSearchAction = onSearchAction,
onClearAction = onClearAction,
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Search),
keyboardActions = KeyboardActions(
onSearch = {
keyboardController?.hide()
onSearchAction()
}
),
)
// 선택된 영화 가로 스크롤
if (contentUiState.selectedContents.isNotEmpty()) {
val lazyListState = rememberLazyListState()
// 새로운 아이템이 추가될 때 왼쪽 자동 스크롤
LaunchedEffect(contentUiState.selectedContents.size) {
lazyListState.animateScrollToItem(0)
}
Spacer(modifier = Modifier.height(16.dp))
LazyRow(
state = lazyListState,
horizontalArrangement = Arrangement.spacedBy(0.dp),
) {
items(
items = contentUiState.selectedContents,
key = { it.id }
) { content ->
SelectedContentItem(
imageUrl = content.posterUrl,
onRemoveClick = { onRemoveContent(content) },
)
}
}
}
}
}
// 영화 검색 목록
when (val searchResultsState = contentUiState.searchResults) {
is UiState.Empty, is UiState.Failure -> {
item(span = { GridItemSpan(3) }) {
Box(
modifier =
Modifier
.fillMaxWidth()
.height(300.dp),
contentAlignment = Alignment.Center,
) {
FlintSearchEmptyView(
title = "아직 준비 중인 작품이이요"
)
}
}
}
is UiState.Loading -> {
// 로딩
}
is UiState.Success -> {
if (searchResultsState.data.isEmpty()) {
item(span = { GridItemSpan(3) }) {
Box(
modifier =
Modifier
.fillMaxWidth()
.height(300.dp),
contentAlignment = Alignment.Center,
) {
FlintSearchEmptyView(
title = "작품을 찾을 수 없어요"
)
}
}
} else {
// 영화 목록 그리드
itemsIndexed(
items = searchResultsState.data,
key = { _, content -> content.id }
) { index, content ->
val topPadding = if (index >= 3) 20.dp else 0.dp
OnboardingContentItem(
imageUrl = content.posterUrl,
title = content.title,
director = content.author,
releaseYear = content.year.toString(),
isSelected = contentUiState.isContentSelected(content.id),
onClick = { onContentClick(content) },
modifier = Modifier.padding(top = topPadding),
)
}
}
}
}
}
FlintBasicButton(
text = "다음",
state = if (contentUiState.canProceed) FlintButtonState.Able else FlintButtonState.Disable,
onClick = { if (contentUiState.canProceed) { onNextClick() } },
contentPadding = PaddingValues(vertical = 14.dp),
modifier =
Modifier
.fillMaxWidth()
.padding(horizontal = 20.dp, vertical = 20.dp),
)
}
}
@Preview(showBackground = true, name = "기본 목록 상태")
@Composable
private fun OnboardingContentScreenListPreview() {
FlintTheme {
OnboardingContentScreen(
nickname = "안비",
contentUiState = OnboardingContentUiState(
searchResults = UiState.Success(
SearchContentListModel.FakeList
),
),
onBackClick = {},
onNextClick = {},
onSearchKeywordChanged = {},
onSearchAction = {},
onClearAction = {},
onContentClick = {},
onRemoveContent = {},
)
}
}
@Preview(showBackground = true, name = "검색 결과 없음 상태")
@Composable
private fun OnboardingContentScreenEmptyPreview() {
FlintTheme {
OnboardingContentScreen(
nickname = "안비",
contentUiState = OnboardingContentUiState(),
onBackClick = {},
onNextClick = {},
onSearchKeywordChanged = {},
onSearchAction = {},
onClearAction = {},
onContentClick = {},
onRemoveContent = {},
)
}
}