Skip to content

Commit b836eb2

Browse files
committed
Refactor UI components in SaveScreenshot and DetailSheet
1 parent 647cb77 commit b836eb2

File tree

2 files changed

+18
-33
lines changed
  • core/save-screenshot/src/main/kotlin/com/espressodev/gptmap/core/save_screenshot/composable
  • feature/map/src/main/kotlin/com/espressodev/gptmap/feature/map

2 files changed

+18
-33
lines changed

core/save-screenshot/src/main/kotlin/com/espressodev/gptmap/core/save_screenshot/composable/SaveScreenshot.kt

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import android.media.projection.MediaProjectionManager
66
import android.util.Log
77
import androidx.activity.compose.rememberLauncherForActivityResult
88
import androidx.activity.result.contract.ActivityResultContracts
9-
import androidx.compose.foundation.layout.Box
10-
import androidx.compose.foundation.layout.fillMaxSize
119
import androidx.compose.runtime.Composable
1210
import androidx.compose.runtime.LaunchedEffect
1311
import androidx.compose.runtime.getValue
@@ -34,9 +32,11 @@ fun SaveScreenshot(
3432
onSuccess()
3533
viewModel.resetScreenState()
3634
}
35+
3736
ScreenState.Started -> {
3837
onConfirm()
3938
}
39+
4040
ScreenState.Idle -> {}
4141
}
4242
}
@@ -61,13 +61,12 @@ fun SaveScreenshot(
6161
}
6262
}
6363

64-
Box(modifier = modifier.fillMaxSize()) {
65-
if (uiState.isButtonVisible)
66-
GmDraggableButton(
67-
icon = GmIcons.CameraFilled,
68-
onClick = {
69-
screenCaptureLauncher.launch(screenCaptureIntent)
70-
}
71-
)
72-
}
64+
if (uiState.isButtonVisible)
65+
GmDraggableButton(
66+
icon = GmIcons.CameraFilled,
67+
onClick = {
68+
screenCaptureLauncher.launch(screenCaptureIntent)
69+
},
70+
modifier = modifier
71+
)
7372
}

feature/map/src/main/kotlin/com/espressodev/gptmap/feature/map/DetailSheet.kt

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import androidx.compose.foundation.layout.Arrangement
77
import androidx.compose.foundation.layout.Box
88
import androidx.compose.foundation.layout.BoxScope
99
import androidx.compose.foundation.layout.Column
10-
import androidx.compose.foundation.layout.Row
1110
import androidx.compose.foundation.layout.Spacer
1211
import androidx.compose.foundation.layout.fillMaxWidth
1312
import androidx.compose.foundation.layout.height
@@ -40,14 +39,12 @@ import com.espressodev.gptmap.core.designsystem.component.ShimmerImage
4039
import com.espressodev.gptmap.core.designsystem.component.SquareButton
4140
import com.espressodev.gptmap.core.model.Location
4241
import com.espressodev.gptmap.core.model.unsplash.LocationImage
43-
import com.espressodev.gptmap.core.designsystem.R.drawable as AppDrawable
4442
import com.espressodev.gptmap.core.designsystem.R.string as AppText
4543

4644
@Composable
4745
internal fun BoxScope.DetailSheet(
4846
location: Location,
4947
onEvent: (MapUiEvent) -> Unit,
50-
onStreetViewClick: () -> Unit,
5148
) {
5249
BackHandler { onEvent(MapUiEvent.OnDetailSheetBackClick) }
5350
Box(
@@ -78,9 +75,8 @@ internal fun BoxScope.DetailSheet(
7875
overflow = TextOverflow.Ellipsis
7976
)
8077
Spacer(modifier = Modifier.height(MEDIUM_PADDING))
81-
DetailButtons(
78+
DetailButton(
8279
addToFavouriteButtonState = location.addToFavouriteButtonState,
83-
onStreetViewClick = onStreetViewClick,
8480
onFavouriteClick = { onEvent(MapUiEvent.OnFavouriteClick) }
8581
)
8682
Text(
@@ -149,30 +145,20 @@ fun BoxScope.UnsplashBanner(name: String, modifier: Modifier = Modifier) {
149145
}
150146

151147
@Composable
152-
private fun DetailButtons(
148+
private fun DetailButton(
153149
addToFavouriteButtonState: Boolean,
154-
onStreetViewClick: () -> Unit,
155150
onFavouriteClick: () -> Unit,
156151
modifier: Modifier = Modifier
157152
) {
158-
Row(
159-
horizontalArrangement = Arrangement.spacedBy(HIGH_PADDING),
153+
AnimatedVisibility(
154+
addToFavouriteButtonState,
155+
exit = slideOutVertically(targetOffsetY = { fullHeight: Int -> -fullHeight }),
160156
modifier = modifier.padding(bottom = HIGH_PADDING)
161157
) {
162158
SquareButton(
163-
icon = IconType.Bitmap(AppDrawable.street_view),
164-
contentDesc = AppText.street_view,
165-
onClick = onStreetViewClick
159+
icon = IconType.Vector(GmIcons.FavouriteOutlined),
160+
contentDesc = AppText.add_favourite,
161+
onClick = onFavouriteClick
166162
)
167-
AnimatedVisibility(
168-
addToFavouriteButtonState,
169-
exit = slideOutVertically(targetOffsetY = { fullHeight: Int -> -fullHeight })
170-
) {
171-
SquareButton(
172-
icon = IconType.Vector(GmIcons.FavouriteOutlined),
173-
contentDesc = AppText.add_favourite,
174-
onClick = onFavouriteClick
175-
)
176-
}
177163
}
178164
}

0 commit comments

Comments
 (0)