11package com.espressodev.gptmap.feature.map
22
33import android.annotation.SuppressLint
4- import android.util.Log
54import androidx.activity.compose.BackHandler
65import androidx.compose.animation.AnimatedVisibility
76import androidx.compose.animation.core.LinearEasing
@@ -29,20 +28,22 @@ import androidx.compose.foundation.pager.HorizontalPager
2928import androidx.compose.foundation.pager.rememberPagerState
3029import androidx.compose.foundation.shape.RoundedCornerShape
3130import androidx.compose.material3.BottomAppBar
32- import androidx.compose.material3.FloatingActionButton
31+ import androidx.compose.material3.CenterAlignedTopAppBar
32+ import androidx.compose.material3.ExperimentalMaterial3Api
3333import androidx.compose.material3.Icon
34+ import androidx.compose.material3.IconButton
3435import androidx.compose.material3.MaterialTheme
3536import androidx.compose.material3.OutlinedButton
3637import androidx.compose.material3.Scaffold
3738import androidx.compose.material3.Surface
3839import androidx.compose.material3.Text
40+ import androidx.compose.material3.TopAppBarDefaults
3941import androidx.compose.runtime.Composable
4042import androidx.compose.runtime.LaunchedEffect
4143import androidx.compose.runtime.derivedStateOf
4244import androidx.compose.runtime.getValue
4345import androidx.compose.runtime.mutableStateOf
4446import androidx.compose.runtime.remember
45- import androidx.compose.runtime.saveable.rememberSaveable
4647import androidx.compose.runtime.setValue
4748import androidx.compose.ui.Alignment
4849import androidx.compose.ui.Modifier
@@ -67,7 +68,6 @@ import com.airbnb.lottie.compose.LottieAnimation
6768import com.airbnb.lottie.compose.LottieCompositionSpec
6869import com.airbnb.lottie.compose.animateLottieCompositionAsState
6970import com.airbnb.lottie.compose.rememberLottieComposition
70- import com.espressodev.gptmap.core.common.splash_navigation.SplashNavigationManager
7171import com.espressodev.gptmap.core.designsystem.Constants.HIGH_PADDING
7272import com.espressodev.gptmap.core.designsystem.Constants.MAX_PADDING
7373import com.espressodev.gptmap.core.designsystem.Constants.MEDIUM_PADDING
@@ -82,7 +82,6 @@ import com.espressodev.gptmap.core.designsystem.component.SquareButton
8282import com.espressodev.gptmap.core.designsystem.theme.GptmapTheme
8383import com.espressodev.gptmap.core.model.Location
8484import com.espressodev.gptmap.core.model.chatgpt.Content
85- import com.espressodev.gptmap.core.model.chatgpt.Coordinates
8685import com.espressodev.gptmap.core.model.unsplash.LocationImage
8786import com.espressodev.gptmap.core.save_screenshot.composable.SaveScreenshot
8887import com.espressodev.gptmap.feature.map.ComponentLoadingState.MAP
@@ -129,13 +128,18 @@ fun MapRoute(
129128 )
130129 }
131130 },
131+ topBar = {
132+ MapTopButtons (
133+ onFavouriteClick = navigateToFavourite,
134+ onScreenshotGalleryClick = navigateToScreenshotGallery,
135+ onAccountClick = navigateToProfile,
136+ modifier = modifier
137+ )
138+ },
132139 modifier = modifier
133140 ) {
134141 MapScreen (
135142 uiState = uiState,
136- onFavouriteClick = navigateToFavourite,
137- onScreenshotGalleryClick = navigateToScreenshotGallery,
138- onProfileClick = navigateToProfile,
139143 onEvent = { event ->
140144 viewModel.onEvent(
141145 event = event,
@@ -144,7 +148,7 @@ fun MapRoute(
144148 }
145149 )
146150 },
147- modifier = Modifier .statusBarsPadding( )
151+ modifier = Modifier .padding(top = it.calculateTopPadding() )
148152 )
149153 }
150154 SaveScreenshot (
@@ -166,9 +170,6 @@ fun MapRoute(
166170@Composable
167171private fun MapScreen (
168172 uiState : MapUiState ,
169- onFavouriteClick : () -> Unit ,
170- onScreenshotGalleryClick : () -> Unit ,
171- onProfileClick : () -> Unit ,
172173 onEvent : (MapUiEvent ) -> Unit ,
173174 modifier : Modifier = Modifier ,
174175) {
@@ -186,13 +187,6 @@ private fun MapScreen(
186187 location = uiState.location,
187188 onDismiss = { onEvent(MapUiEvent .OnImageDismiss ) }
188189 )
189- MapTopButtons (
190- isVisible = uiState.isTopButtonsVisible,
191- onFavouriteClick = onFavouriteClick,
192- onScreenshotGalleryClick = onScreenshotGalleryClick,
193- onAccountClick = onProfileClick,
194- modifier = modifier
195- )
196190 Box (modifier = modifier.fillMaxSize()) {
197191 LoadingDialog (uiState.componentLoadingState)
198192 MapSection (
@@ -203,64 +197,62 @@ private fun MapScreen(
203197 }
204198}
205199
200+ @OptIn(ExperimentalMaterial3Api ::class )
206201@Composable
207202fun MapTopButtons (
208- isVisible : Boolean ,
209203 onFavouriteClick : () -> Unit ,
210204 onScreenshotGalleryClick : () -> Unit ,
211205 onAccountClick : () -> Unit ,
212206 modifier : Modifier = Modifier
213207) {
214- Box (
215- modifier = modifier
216- .fillMaxSize()
217- .zIndex(1f )
218- .padding(8 .dp)
219- ) {
220- AnimatedVisibility (
221- visible = isVisible,
222- modifier = Modifier .align(Alignment .TopEnd )
223- ) {
224- Column (
225- verticalArrangement = Arrangement .spacedBy(8 .dp)
226- ) {
227- GmFloatingButton (onFavouriteClick, IconType .Vector (GmIcons .GalleryDefault ))
228- GmFloatingButton (
229- onScreenshotGalleryClick,
230- IconType .Vector (GmIcons .ScreenshotDefault )
231- )
232- }
233- }
234- AnimatedVisibility (visible = isVisible) {
235- GmFloatingButton (
208+ CenterAlignedTopAppBar (
209+ title = { Text (text = " Gptmap" , fontWeight = FontWeight .Medium ) },
210+ navigationIcon = {
211+ GmIconButtonWithText (
236212 onClick = onAccountClick,
237213 icon = IconType .Vector (GmIcons .PersonDefault ),
238- containerColor = MaterialTheme .colorScheme.secondaryContainer,
239214 )
240- }
241- }
215+ },
216+ actions = {
217+ GmIconButtonWithText (
218+ onClick = onFavouriteClick,
219+ icon = IconType .Vector (GmIcons .GalleryDefault ),
220+ )
221+ GmIconButtonWithText (
222+ onClick = onScreenshotGalleryClick,
223+ icon = IconType .Vector (GmIcons .ScreenshotDefault ),
224+ )
225+ },
226+ modifier = modifier,
227+ colors = TopAppBarDefaults .centerAlignedTopAppBarColors(
228+ containerColor = Color .Transparent
229+ )
230+ )
242231}
243232
244233@Composable
245- fun GmFloatingButton (
234+ fun GmIconButtonWithText (
246235 onClick : () -> Unit ,
247236 icon : IconType ,
248237 modifier : Modifier = Modifier ,
249- containerColor : Color = MaterialTheme .colorScheme.secondaryContainer,
250- contentColor : Color = MaterialTheme .colorScheme.onSecondaryContainer
238+ color : Color = MaterialTheme .colorScheme.onSurface
251239) {
252- FloatingActionButton (
240+ IconButton (
253241 onClick = onClick,
254- containerColor = containerColor,
255- contentColor = contentColor,
256- modifier = modifier
242+ modifier = modifier.size(48 .dp)
257243 ) {
258244 when (icon) {
259- is IconType .Vector -> Icon (icon.imageVector, null , modifier = Modifier .size(36 .dp))
245+ is IconType .Vector -> Icon (
246+ imageVector = icon.imageVector,
247+ contentDescription = null ,
248+ modifier = Modifier .size(32 .dp),
249+ tint = color
250+ )
251+
260252 is IconType .Bitmap -> Image (
261253 painterResource(id = icon.painterId),
262254 null ,
263- modifier = Modifier .size(36 .dp)
255+ modifier = Modifier .size(32 .dp),
264256 )
265257 }
266258 }
@@ -364,10 +356,11 @@ private fun MapBottomBar(
364356 onValueChange : (String ) -> Unit ,
365357 onSearchClick : () -> Unit ,
366358) {
367- BottomAppBar (
359+ Surface (
368360 modifier = Modifier
361+ .height(80 .dp)
369362 .imePadding()
370- .navigationBarsPadding()
363+ .navigationBarsPadding(),
371364 ) {
372365 Row (
373366 modifier = Modifier
@@ -596,42 +589,14 @@ fun BoxScope.SmallInformationCard(
596589 }
597590}
598591
599-
600592@Preview(showBackground = true )
601593@Composable
602594fun MapPreview () {
603595 GptmapTheme {
604- MapScreen (
605- uiState = MapUiState (
606- searchValue = " " ,
607- location = Location (
608- id = " " , content = Content (
609- coordinates = Coordinates (
610- latitude = 0.0 ,
611- longitude = 0.0
612- ),
613- city = " " ,
614- district = null ,
615- country = " " ,
616- poeticDescription = " " ,
617- normalDescription = " "
618- ), locationImages = listOf (), addToFavouriteButtonState = false
619- ),
620- componentLoadingState = MAP ,
621- bottomSheetState = SMALL_INFORMATION_CARD ,
622- searchButtonEnabledState = false ,
623- searchTextFieldEnabledState = false ,
624- bottomSearchState = false ,
625- isTopButtonsVisible = true ,
626- isFavouriteButtonPlaying = false ,
627- isLocationPinVisible = false ,
628- takeScreenshotState = false ,
629- imageGalleryState = Pair (0 , false )
630- ),
631- {},
632- {},
633- {},
634- onEvent = {}
596+ MapTopButtons (
597+ onFavouriteClick = {},
598+ onScreenshotGalleryClick = {},
599+ onAccountClick = {},
635600 )
636601 }
637602}
0 commit comments