Skip to content

Commit 24a686b

Browse files
committed
Use TopActionsBar and QuickTooltip in GalleryTopBar
1 parent f88be30 commit 24a686b

File tree

1 file changed

+66
-86
lines changed
  • app/src/main/java/app/grapheneos/camera/ui/composable/components

1 file changed

+66
-86
lines changed

app/src/main/java/app/grapheneos/camera/ui/composable/components/GalleryTopBar.kt

+66-86
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,63 @@ import androidx.compose.animation.core.EaseIn
55
import androidx.compose.animation.core.tween
66
import androidx.compose.animation.slideInVertically
77
import androidx.compose.animation.slideOutVertically
8-
import androidx.compose.foundation.clickable
9-
import androidx.compose.foundation.layout.Box
10-
import androidx.compose.foundation.layout.PaddingValues
11-
import androidx.compose.foundation.layout.absolutePadding
12-
import androidx.compose.foundation.layout.padding
13-
import androidx.compose.foundation.layout.requiredSizeIn
14-
import androidx.compose.foundation.layout.width
8+
import androidx.compose.foundation.layout.fillMaxWidth
9+
1510
import androidx.compose.material.icons.Icons
1611
import androidx.compose.material.icons.automirrored.filled.ArrowBack
1712
import androidx.compose.material.icons.filled.Delete
1813
import androidx.compose.material.icons.filled.Edit
1914
import androidx.compose.material.icons.filled.Info
20-
import androidx.compose.material.icons.filled.MoreVert
2115
import androidx.compose.material.icons.filled.Share
22-
import androidx.compose.material3.DropdownMenu
23-
import androidx.compose.material3.DropdownMenuItem
2416
import androidx.compose.material3.ExperimentalMaterial3Api
2517
import androidx.compose.material3.Icon
2618
import androidx.compose.material3.IconButton
2719
import androidx.compose.material3.MaterialTheme
28-
import androidx.compose.material3.Text
20+
2921
import androidx.compose.material3.TopAppBar
3022
import androidx.compose.material3.TopAppBarColors
3123
import androidx.compose.runtime.Composable
32-
import androidx.compose.runtime.getValue
33-
import androidx.compose.runtime.mutableStateOf
34-
import androidx.compose.runtime.remember
35-
import androidx.compose.runtime.setValue
36-
import androidx.compose.ui.Alignment
24+
3725
import androidx.compose.ui.Modifier
38-
import androidx.compose.ui.graphics.Color
39-
import androidx.compose.ui.text.font.FontWeight
40-
import androidx.compose.ui.unit.dp
41-
import androidx.compose.ui.unit.sp
4226
import app.grapheneos.camera.ui.theme.AppColor
4327

28+
enum class GalleryAction {
29+
EDIT_MEDIA,
30+
DELETE_MEDIA,
31+
SHOW_MEDIA_INFO,
32+
SHARE_MEDIA,
33+
EDIT_MEDIA_WITH_APP,
34+
}
35+
36+
private val GALLERY_ACTIONS = listOf(
37+
TopBarAction(
38+
id = GalleryAction.EDIT_MEDIA,
39+
title = "Edit Media",
40+
icon = Icons.Filled.Edit
41+
),
42+
TopBarAction(
43+
id = GalleryAction.DELETE_MEDIA,
44+
title = "Delete Media",
45+
icon = Icons.Filled.Delete
46+
),
47+
TopBarAction(
48+
id = GalleryAction.SHOW_MEDIA_INFO,
49+
title = "Show media info",
50+
icon = Icons.Filled.Info
51+
),
52+
TopBarAction(
53+
id = GalleryAction.SHARE_MEDIA,
54+
title = "Share Media",
55+
icon = Icons.Filled.Share
56+
),
57+
TopBarAction(
58+
id = GalleryAction.EDIT_MEDIA_WITH_APP,
59+
title = "Edit with",
60+
icon = Icons.Filled.Edit,
61+
alwaysInMoreOptions = true
62+
),
63+
)
64+
4465
@OptIn(ExperimentalMaterial3Api::class)
4566
@Composable
4667
fun GalleryTopBar(
@@ -52,10 +73,6 @@ fun GalleryTopBar(
5273
onShareAction: () -> Unit
5374
) {
5475

55-
var dropDownMenuExpanded by remember {
56-
mutableStateOf(false)
57-
}
58-
5976
AnimatedVisibility(
6077
visible = visible,
6178

@@ -87,70 +104,33 @@ fun GalleryTopBar(
87104
)
88105
}
89106
},
90-
actions = {
91-
IconButton(onClick = {
92-
onEditAction(false)
93-
}) {
94-
Icon(
95-
Icons.Filled.Edit,
96-
"Edit"
97-
)
98-
}
99107

100-
IconButton(onClick = onDeleteAction) {
101-
Icon(Icons.Filled.Delete, null)
102-
}
103-
104-
IconButton(onClick = onInfoAction) {
105-
Icon(Icons.Filled.Info, null)
106-
}
107-
108-
IconButton(onClick = onShareAction) {
109-
Icon(Icons.Filled.Share, null)
110-
}
111-
112-
Box(
113-
contentAlignment = Alignment.TopEnd
114-
) {
115-
IconButton(onClick = {
116-
dropDownMenuExpanded = !dropDownMenuExpanded
117-
}) {
118-
Icon(
119-
Icons.Filled.MoreVert,
120-
"More Options"
121-
)
122-
}
123-
124-
DropdownMenu(
125-
expanded = dropDownMenuExpanded,
126-
onDismissRequest = {
127-
dropDownMenuExpanded = false
128-
},
129-
modifier = Modifier.width(200.dp)
130-
) {
131-
DropdownMenuItem(
132-
contentPadding = PaddingValues(vertical = 0.dp, horizontal = 12.dp),
133-
modifier = Modifier
134-
.requiredSizeIn(maxHeight = 42.dp),
135-
136-
text = {
137-
Text(
138-
text = "Edit With",
139-
color = Color.White,
140-
fontSize = 16.sp,
141-
fontWeight = FontWeight.Normal,
142-
modifier = Modifier
143-
.padding(0.dp)
144-
)
145-
},
146-
147-
onClick = {
108+
actions = {
109+
TopBarActions(
110+
actions = GALLERY_ACTIONS,
111+
onActionClicked = { id ->
112+
when (id) {
113+
GalleryAction.EDIT_MEDIA -> {
114+
onEditAction(false)
115+
}
116+
GalleryAction.DELETE_MEDIA -> {
117+
onDeleteAction()
118+
}
119+
GalleryAction.SHOW_MEDIA_INFO -> {
120+
onInfoAction()
121+
}
122+
GalleryAction.SHARE_MEDIA -> {
123+
onShareAction()
124+
}
125+
GalleryAction.EDIT_MEDIA_WITH_APP -> {
148126
onEditAction(true)
149-
dropDownMenuExpanded = false
150-
},
151-
)
152-
}
153-
}
127+
}
128+
}
129+
},
130+
// To avoid overlapping leading back arrow and some spacing
131+
modifier = Modifier
132+
.fillMaxWidth(0.7f)
133+
)
154134
},
155135
)
156136
}

0 commit comments

Comments
 (0)