@@ -9,14 +9,14 @@ import androidx.compose.foundation.layout.Spacer
99import androidx.compose.foundation.layout.WindowInsets
1010import androidx.compose.foundation.layout.fillMaxWidth
1111import androidx.compose.foundation.layout.height
12- import androidx.compose.foundation.layout.padding
1312import androidx.compose.foundation.layout.safeDrawing
1413import androidx.compose.foundation.layout.width
1514import androidx.compose.foundation.layout.windowInsetsBottomHeight
1615import androidx.compose.runtime.Composable
1716import androidx.compose.ui.Alignment
1817import androidx.compose.ui.Modifier
1918import androidx.compose.ui.layout.layout
19+ import androidx.compose.ui.platform.LocalFocusManager
2020import androidx.compose.ui.tooling.preview.PreviewParameter
2121import androidx.compose.ui.unit.dp
2222import androidx.compose.ui.unit.offset
@@ -49,10 +49,10 @@ import com.hedvig.feature.claim.chat.data.StepId
4949import com.hedvig.feature.claim.chat.ui.common.EditButton
5050import com.hedvig.feature.claim.chat.ui.common.FilesRow
5151import com.hedvig.feature.claim.chat.ui.common.SkippedLabel
52- import hedvig.resources.CLAIM_CHAT_FILE_UPLOAD_SEND_BUTTON
5352import hedvig.resources.Res
5453import hedvig.resources.claim_status_detail_add_files
5554import hedvig.resources.claim_status_detail_add_more_files
55+ import hedvig.resources.claims_continue_button
5656import hedvig.resources.claims_skip_button
5757import hedvig.resources.file_upload_choose_files
5858import hedvig.resources.file_upload_photo_library
@@ -69,14 +69,13 @@ internal fun UploadFilesStep(
6969 continueButtonLoading : Boolean ,
7070 skipButtonLoading : Boolean ,
7171 imageLoader : ImageLoader ,
72- localFiles : List <UiFile >,
7372 onEvent : (ClaimChatEvent ) -> Unit ,
7473 onNavigateToImageViewer : (imageUrl: String , cacheKey: String ) -> Unit ,
7574 modifier : Modifier = Modifier ,
7675) {
7776 Box (modifier) {
7877 if (isCurrentStep) {
79- Column (verticalArrangement = Arrangement .spacedBy(16 .dp)) {
78+ Column (verticalArrangement = Arrangement .spacedBy(8 .dp)) {
8079 UploadFilesBubble (
8180 addLocalFile = { uri ->
8281 onEvent(
@@ -95,45 +94,43 @@ internal fun UploadFilesStep(
9594 )
9695 },
9796 appPackageId = appPackageId,
98- localFiles = localFiles,
97+ localFiles = stepContent. localFiles,
9998 imageLoader = imageLoader,
10099 onNavigateToImageViewer = onNavigateToImageViewer,
101100 )
102- Column (verticalArrangement = Arrangement .spacedBy(8 .dp)) {
103- if (stepContent.localFiles.isNotEmpty()) {
104- HedvigButton (
105- text = stringResource(Res .string.CLAIM_CHAT_FILE_UPLOAD_SEND_BUTTON ),
106- enabled = ! continueButtonLoading,
107- onClick = {
108- onEvent(
109- ClaimChatEvent .SubmitFile (
110- itemId,
111- ),
112- )
113- },
114- isLoading = continueButtonLoading,
115- modifier = Modifier .fillMaxWidth(),
116- )
117- }
118- if (stepContent.isSkippable && stepContent.localFiles.isEmpty()) {
119- HedvigButton (
120- text = stringResource(Res .string.claims_skip_button),
121- enabled = ! skipButtonLoading,
122- onClick = {
123- onEvent(ClaimChatEvent .Skip (itemId))
124- },
125- isLoading = skipButtonLoading,
126- modifier = Modifier .fillMaxWidth(),
127- buttonStyle = ButtonDefaults .ButtonStyle .Secondary ,
128- )
129- }
101+ if (stepContent.localFiles.isNotEmpty()) {
102+ HedvigButton (
103+ text = stringResource(Res .string.claims_continue_button),
104+ enabled = ! continueButtonLoading,
105+ onClick = {
106+ onEvent(
107+ ClaimChatEvent .SubmitFile (
108+ itemId,
109+ ),
110+ )
111+ },
112+ isLoading = continueButtonLoading,
113+ modifier = Modifier .fillMaxWidth(),
114+ )
115+ }
116+ if (stepContent.isSkippable && stepContent.localFiles.isEmpty()) {
117+ HedvigButton (
118+ text = stringResource(Res .string.claims_skip_button),
119+ enabled = ! skipButtonLoading,
120+ onClick = {
121+ onEvent(ClaimChatEvent .Skip (itemId))
122+ },
123+ isLoading = skipButtonLoading,
124+ modifier = Modifier .fillMaxWidth(),
125+ buttonStyle = ButtonDefaults .ButtonStyle .Secondary ,
126+ )
130127 }
131128 }
132129 } else {
133130 Column (verticalArrangement = Arrangement .spacedBy(4 .dp)) {
134- if (localFiles.isNotEmpty()) {
131+ if (stepContent. localFiles.isNotEmpty()) {
135132 FilesRow (
136- uiFiles = localFiles,
133+ uiFiles = stepContent. localFiles,
137134 onRemoveFile = null ,
138135 imageLoader = imageLoader,
139136 onNavigateToImageViewer = onNavigateToImageViewer,
@@ -179,6 +176,7 @@ private fun UploadFilesBubble(
179176 ) -> Unit ,
180177 modifier : Modifier = Modifier ,
181178) {
179+ val focusManager = LocalFocusManager .current
182180 val fileTypeSelectBottomSheetState = rememberHedvigBottomSheetState<Unit >()
183181 val photoCaptureState = rememberPhotoCaptureState(appPackageId = appPackageId) { uri ->
184182 addLocalFile(uri)
@@ -210,6 +208,7 @@ private fun UploadFilesBubble(
210208 )
211209 UploadFilesBubbleContent (
212210 onAddFilesButtonClick = {
211+ focusManager.clearFocus()
213212 fileTypeSelectBottomSheetState.show()
214213 },
215214 onRemoveFile = onRemoveFile,
@@ -229,7 +228,7 @@ private fun UploadFilesBubbleContent(
229228 onNavigateToImageViewer : (imageUrl: String , cacheKey: String ) -> Unit ,
230229 modifier : Modifier = Modifier ,
231230) {
232- Column (modifier) {
231+ Column (modifier, verticalArrangement = Arrangement .spacedBy( 16 .dp) ) {
233232 if (localFiles.isNotEmpty()) {
234233 FilesRow (
235234 uiFiles = localFiles,
@@ -249,7 +248,6 @@ private fun UploadFilesBubbleContent(
249248 },
250249 )
251250 }
252- Spacer (Modifier .height(16 .dp))
253251 HedvigButton (
254252 buttonStyle = if (localFiles.isNotEmpty()) {
255253 ButtonDefaults .ButtonStyle .Secondary
@@ -301,27 +299,27 @@ private fun FilePickerBottomSheetContent(
301299 verticalArrangement = Arrangement .spacedBy(4 .dp),
302300 ) {
303301 HedvigButton (
304- onClick = onPickPhoto ,
302+ onClick = onTakePhoto ,
305303 true ,
306304 modifier = Modifier .fillMaxWidth(),
307305 buttonStyle = ButtonDefaults .ButtonStyle .Ghost ,
308306 ) {
309307 Row {
310- Icon (HedvigIcons .Image , null )
308+ Icon (HedvigIcons .Camera , null )
311309 Spacer (Modifier .width(8 .dp))
312- HedvigText (stringResource(Res .string.file_upload_photo_library ))
310+ HedvigText (stringResource(Res .string.file_upload_take_photo ))
313311 }
314312 }
315313 HedvigButton (
316- onClick = onTakePhoto ,
314+ onClick = onPickPhoto ,
317315 true ,
318316 modifier = Modifier .fillMaxWidth(),
319317 buttonStyle = ButtonDefaults .ButtonStyle .Ghost ,
320318 ) {
321319 Row {
322- Icon (HedvigIcons .Camera , null )
320+ Icon (HedvigIcons .Image , null )
323321 Spacer (Modifier .width(8 .dp))
324- HedvigText (stringResource(Res .string.file_upload_take_photo ))
322+ HedvigText (stringResource(Res .string.file_upload_photo_library ))
325323 }
326324 }
327325 HedvigButton (
@@ -344,38 +342,35 @@ private fun FilePickerBottomSheetContent(
344342
345343@HedvigPreview
346344@Composable
347- private fun PreviewUploadFilesBubbleContent (
345+ private fun PreviewUploadFilesStep (
348346 @PreviewParameter(BooleanCollectionPreviewParameterProvider ::class ) hasFiles : Boolean ,
349347) {
350348 HedvigTheme {
351- Surface (
352- color = HedvigTheme .colorScheme.backgroundPrimary,
353- ) {
354- Column (
355- verticalArrangement = Arrangement .spacedBy(16 .dp),
356- modifier = Modifier .padding(horizontal = 16 .dp),
357- ) {
358- UploadFilesBubbleContent (
359- modifier = Modifier .height(400 .dp),
360- onRemoveFile = {},
361- localFiles = if (hasFiles) {
362- listOf (
363- UiFile (
364- name = " file" ,
365- localPath = " path" ,
366- mimeType = " image/jpg" ,
367- url = null ,
368- id = " 1" ,
369- ),
370- )
371- } else {
372- emptyList()
373- },
374- imageLoader = rememberPreviewImageLoader(),
375- onNavigateToImageViewer = { _, _ -> },
376- onAddFilesButtonClick = {},
377- )
378- }
349+ Surface (color = HedvigTheme .colorScheme.backgroundPrimary) {
350+ UploadFilesStep (
351+ itemId = StepId (" " ),
352+ stepContent = StepContent .FileUpload (
353+ " " ,
354+ true ,
355+ listOf (
356+ UiFile (
357+ name = " file" ,
358+ localPath = " path" ,
359+ mimeType = " image/jpg" ,
360+ url = null ,
361+ id = " 1" ,
362+ ),
363+ ).takeIf { hasFiles }.orEmpty(),
364+ ),
365+ appPackageId = " " ,
366+ isCurrentStep = true ,
367+ canEdit = true ,
368+ continueButtonLoading = false ,
369+ skipButtonLoading = false ,
370+ imageLoader = rememberPreviewImageLoader(),
371+ onEvent = {},
372+ onNavigateToImageViewer = { _, _ -> },
373+ )
379374 }
380375 }
381376}
0 commit comments