11package com.espressodev.gptmap.feature.screenshot_gallery
22
33import android.util.Log
4+ import androidx.activity.compose.BackHandler
45import androidx.compose.animation.core.FastOutSlowInEasing
56import androidx.compose.animation.core.animateFloatAsState
67import androidx.compose.animation.core.tween
78import androidx.compose.foundation.ExperimentalFoundationApi
89import androidx.compose.foundation.background
910import androidx.compose.foundation.basicMarquee
11+ import androidx.compose.foundation.border
1012import androidx.compose.foundation.combinedClickable
1113import androidx.compose.foundation.layout.Arrangement
1214import androidx.compose.foundation.layout.Box
13- import androidx.compose.foundation.layout.BoxScope
1415import androidx.compose.foundation.layout.Column
1516import androidx.compose.foundation.layout.PaddingValues
1617import androidx.compose.foundation.layout.aspectRatio
@@ -28,10 +29,9 @@ import androidx.compose.foundation.pager.HorizontalPager
2829import androidx.compose.foundation.pager.PagerState
2930import androidx.compose.foundation.pager.rememberPagerState
3031import androidx.compose.foundation.shape.CircleShape
32+ import androidx.compose.foundation.shape.RoundedCornerShape
3133import androidx.compose.material3.Card
32- import androidx.compose.material3.ElevatedCard
3334import androidx.compose.material3.ExperimentalMaterial3Api
34- import androidx.compose.material3.Icon
3535import androidx.compose.material3.MaterialTheme
3636import androidx.compose.material3.Scaffold
3737import androidx.compose.material3.Text
@@ -46,7 +46,9 @@ import androidx.compose.runtime.setValue
4646import androidx.compose.ui.Alignment
4747import androidx.compose.ui.Modifier
4848import androidx.compose.ui.draw.clip
49+ import androidx.compose.ui.draw.shadow
4950import androidx.compose.ui.graphics.Color
51+ import androidx.compose.ui.graphics.Shape
5052import androidx.compose.ui.graphics.graphicsLayer
5153import androidx.compose.ui.platform.LocalDensity
5254import androidx.compose.ui.text.style.TextAlign
@@ -61,6 +63,7 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
6163import com.espressodev.gptmap.core.designsystem.GmIcons
6264import com.espressodev.gptmap.core.designsystem.IconType
6365import com.espressodev.gptmap.core.designsystem.TextType
66+ import com.espressodev.gptmap.core.designsystem.component.GmEditAlertDialog
6467import com.espressodev.gptmap.core.designsystem.component.GmTopAppBar
6568import com.espressodev.gptmap.core.designsystem.component.LottieAnimationPlaceholder
6669import com.espressodev.gptmap.core.designsystem.component.ShimmerImage
@@ -90,9 +93,9 @@ fun ScreenshotGalleryRoute(
9093 onBackClick = popUp,
9194 editText = uiState.selectedImageSummary.title,
9295 isInEditMode = uiState.uiIsInEditMode,
93- onEditClick = viewModel::onEditClick ,
94- onDeleteClick = viewModel::onDeleteClick ,
95- onCancelClick = viewModel::onCancelClick
96+ onEditClick = { viewModel.onEvent( ScreenshotGalleryUiEvent . OnEditClick ) } ,
97+ onDeleteClick = { viewModel.onEvent( ScreenshotGalleryUiEvent . OnDeleteClick ) } ,
98+ onCancelClick = { viewModel.onEvent( ScreenshotGalleryUiEvent . OnCancelClick ) }
9699 )
97100 }
98101 ) {
@@ -103,15 +106,41 @@ fun ScreenshotGalleryRoute(
103106
104107 Response .Loading -> {}
105108 is Response .Success -> {
106- ScreenshotGalleryScreen (
107- modifier = Modifier .padding(it),
108- images = result.data,
109- onLongClick = viewModel::onLongClickToImage,
110- selectedId = uiState.selectedImageSummary.id
111- )
109+ if (result.data.isNotEmpty()) {
110+ ScreenshotGalleryScreen (
111+ modifier = Modifier .padding(it),
112+ images = result.data,
113+ onLongClick = { imageSummary ->
114+ viewModel.onEvent(
115+ ScreenshotGalleryUiEvent .OnLongClickToImage (imageSummary)
116+ )
117+ },
118+ selectedId = uiState.selectedImageSummary.id
119+ )
120+ } else {
121+ LottieAnimationPlaceholder (
122+ modifier = Modifier .padding(it),
123+ rawRes = AppRaw .nothing_here_anim
124+ )
125+ }
112126 }
113127 }
114128 }
129+
130+ BackHandler {
131+ if (uiState.uiIsInEditMode) {
132+ viewModel.onEvent(ScreenshotGalleryUiEvent .Reset )
133+ }
134+ }
135+
136+ if (uiState.editDialogState) {
137+ GmEditAlertDialog (
138+ title = AppText .screenshot_gallery_edit_dialog_title,
139+ textFieldLabel = AppText .screenshot_gallery_edit_dialog_text_field_placeholder,
140+ onConfirm = { viewModel.onEvent(ScreenshotGalleryUiEvent .OnEditDialogConfirm (it)) },
141+ onDismiss = { viewModel.onEvent(ScreenshotGalleryUiEvent .OnEditDialogDismiss ) }
142+ )
143+ }
115144}
116145
117146@OptIn(ExperimentalFoundationApi ::class )
@@ -157,64 +186,48 @@ fun ScreenshotGalleryScreen(
157186fun ImageCard (
158187 imageSummary : ImageSummary ,
159188 modifier : Modifier = Modifier ,
189+ shape : Shape = RoundedCornerShape (16.dp),
160190 isSelected : Boolean = false,
161191 onClick : () -> Unit = {},
162192 onLongClick : () -> Unit = {}
163193) {
164194 var isImageLoaded by remember { mutableStateOf(value = false ) }
195+ val borderStroke = if (isSelected) 3 .dp else 0 .dp
196+ val elevation = if (isSelected) 8 .dp else 0 .dp
165197
166- ElevatedCard (
167- modifier = modifier.combinedClickable(
168- onClick = onClick,
169- onLongClick = onLongClick
170- )
198+ Box (
199+ modifier = modifier
200+ .shadow(elevation, shape)
201+ .clip(shape)
202+ .border(borderStroke, MaterialTheme .colorScheme.primary, shape)
203+ .combinedClickable(
204+ onClick = onClick,
205+ onLongClick = onLongClick
206+ ),
171207 ) {
172- Box {
173- if (isSelected) {
174- SelectedIconView ()
175- }
176- ShimmerImage (
177- imageSummary.imageUrl,
178- modifier = Modifier .aspectRatio(1f ),
179- onSuccess = { isImageLoaded = true }
180- )
181- if (isImageLoaded)
182- Box (
183- modifier = Modifier
184- .matchParentSize()
185- .background(brush = darkBottomOverlayBrush)
186- )
187- Text (
188- text = imageSummary.title,
208+ ShimmerImage (
209+ imageSummary.imageUrl,
210+ modifier = Modifier .aspectRatio(1f ),
211+ onSuccess = { isImageLoaded = true }
212+ )
213+ if (isImageLoaded)
214+ Box (
189215 modifier = Modifier
190- .padding(8 .dp)
191- .fillMaxWidth()
192- .align(Alignment .BottomCenter )
193- .basicMarquee(iterations = Int .MAX_VALUE ),
194- style = MaterialTheme .typography.titleMedium,
195- textAlign = TextAlign .Center ,
196- color = Color .White
216+ .matchParentSize()
217+ .background(brush = darkBottomOverlayBrush)
197218 )
198- }
199- }
200- }
201-
202- @Composable
203- private fun BoxScope.SelectedIconView () {
204- Box (
205- modifier = Modifier .Companion
206- .matchParentSize()
207- .zIndex(1f )
208- ) {
209- Icon (
210- imageVector = GmIcons .ApproveFilled ,
211- contentDescription = null ,
219+ Text (
220+ text = imageSummary.title,
212221 modifier = Modifier
213222 .padding(8 .dp)
214- .size(56 .dp)
215- .align(Alignment .TopEnd ),
216- tint = MaterialTheme .colorScheme.primary
223+ .fillMaxWidth()
224+ .align(Alignment .BottomCenter )
225+ .basicMarquee(iterations = Int .MAX_VALUE ),
226+ style = MaterialTheme .typography.titleMedium,
227+ textAlign = TextAlign .Center ,
228+ color = Color .White
217229 )
230+
218231 }
219232}
220233
@@ -342,12 +355,18 @@ fun DotsIndicator(
342355fun ScreenshotGalleryPreview () {
343356 GptmapTheme {
344357 Box (modifier = Modifier .fillMaxSize(), contentAlignment = Alignment .Center ) {
345- ImageCard (imageSummary = ImageSummary (
346- id = " debet" ,
347- imageUrl = " https://www.google.com/#q=fames" ,
348- title = " himenaeos" ,
349- date = LocalDateTime .now()
350- ), isSelected = true , onClick = {}, onLongClick = {})
358+ ImageCard (
359+ imageSummary = ImageSummary (
360+ id = " debet" ,
361+ imageUrl = " https://www.google.com/#q=fames" ,
362+ title = " himenaeos" ,
363+ date = LocalDateTime .now()
364+ ),
365+ isSelected = true ,
366+ onClick = {},
367+ onLongClick = {},
368+ modifier = Modifier .padding(8 .dp)
369+ )
351370 }
352371 }
353372}
0 commit comments