@@ -5,42 +5,63 @@ import androidx.compose.animation.core.EaseIn
5
5
import androidx.compose.animation.core.tween
6
6
import androidx.compose.animation.slideInVertically
7
7
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
+
15
10
import androidx.compose.material.icons.Icons
16
11
import androidx.compose.material.icons.automirrored.filled.ArrowBack
17
12
import androidx.compose.material.icons.filled.Delete
18
13
import androidx.compose.material.icons.filled.Edit
19
14
import androidx.compose.material.icons.filled.Info
20
- import androidx.compose.material.icons.filled.MoreVert
21
15
import androidx.compose.material.icons.filled.Share
22
- import androidx.compose.material3.DropdownMenu
23
- import androidx.compose.material3.DropdownMenuItem
24
16
import androidx.compose.material3.ExperimentalMaterial3Api
25
17
import androidx.compose.material3.Icon
26
18
import androidx.compose.material3.IconButton
27
19
import androidx.compose.material3.MaterialTheme
28
- import androidx.compose.material3.Text
20
+
29
21
import androidx.compose.material3.TopAppBar
30
22
import androidx.compose.material3.TopAppBarColors
31
23
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
+
37
25
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
42
26
import app.grapheneos.camera.ui.theme.AppColor
43
27
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
+
44
65
@OptIn(ExperimentalMaterial3Api ::class )
45
66
@Composable
46
67
fun GalleryTopBar (
@@ -52,10 +73,6 @@ fun GalleryTopBar(
52
73
onShareAction : () -> Unit
53
74
) {
54
75
55
- var dropDownMenuExpanded by remember {
56
- mutableStateOf(false )
57
- }
58
-
59
76
AnimatedVisibility (
60
77
visible = visible,
61
78
@@ -87,70 +104,33 @@ fun GalleryTopBar(
87
104
)
88
105
}
89
106
},
90
- actions = {
91
- IconButton (onClick = {
92
- onEditAction(false )
93
- }) {
94
- Icon (
95
- Icons .Filled .Edit ,
96
- " Edit"
97
- )
98
- }
99
107
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 -> {
148
126
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
+ )
154
134
},
155
135
)
156
136
}
0 commit comments