@@ -13,9 +13,12 @@ import androidx.compose.foundation.text.KeyboardActions
1313import androidx.compose.foundation.text.KeyboardOptions
1414import androidx.compose.material.icons.Icons
1515import androidx.compose.material.icons.filled.AccountCircle
16+ import androidx.compose.material.icons.filled.Cancel
1617import androidx.compose.material.icons.filled.Close
18+ import androidx.compose.material.icons.filled.Delete
1719import androidx.compose.material.icons.filled.MoreVert
1820import androidx.compose.material.icons.filled.Search
21+ import androidx.compose.material.icons.filled.SelectAll
1922import androidx.compose.material3.CenterAlignedTopAppBar
2023import androidx.compose.material3.DropdownMenu
2124import androidx.compose.material3.DropdownMenuItem
@@ -62,6 +65,11 @@ fun RecentAppBar(
6265 isSearchActive : Boolean ,
6366 onToggleSearch : () -> Unit ,
6467 onSearchDone : () -> Unit ,
68+ isSelectionMode : Boolean = false,
69+ selectedCount : Int = 0,
70+ onSelectAll : (() -> Unit )? = null,
71+ onDeleteSelected : (() -> Unit )? = null,
72+ onCancelSelection : (() -> Unit )? = null,
6573) {
6674 val context = LocalContext .current
6775 val focusManager = LocalFocusManager .current
@@ -81,87 +89,123 @@ fun RecentAppBar(
8189 val phoneNumber = remember { getPhoneNumberFromPrefs(context) }
8290
8391 Column (modifier = Modifier .fillMaxWidth()) {
84- CenterAlignedTopAppBar (
85- title = {
86- if (! isSearchActive) {
87- Text (stringResource(R .string.app_name))
88- }
89- },
90- actions = {
91- if (! isSearchActive) {
92- IconButton (onClick = onToggleSearch) {
92+ if (isSelectionMode) {
93+ // Selection mode app bar
94+ CenterAlignedTopAppBar (
95+ title = {
96+ Text (stringResource(R .string.selected_messages, selectedCount))
97+ },
98+ navigationIcon = {
99+ IconButton (onClick = { onCancelSelection?.invoke() }) {
93100 Icon (
94- imageVector = Icons .Filled .Search ,
95- contentDescription = stringResource(R .string.search)
101+ imageVector = Icons .Filled .Cancel ,
102+ contentDescription = stringResource(R .string.cancel)
103+ )
104+ }
105+ },
106+ actions = {
107+ IconButton (onClick = { onSelectAll?.invoke() }) {
108+ Icon (
109+ imageVector = Icons .Filled .SelectAll ,
110+ contentDescription = stringResource(R .string.select_all)
96111 )
97112 }
98- }
99113
100- IconButton (onClick = { showMenu = ! showMenu }) {
101- Icon (
102- imageVector = Icons .Filled .MoreVert ,
103- contentDescription = stringResource(R .string.menu)
104- )
105- }
106- DropdownMenu (
107- expanded = showMenu,
108- onDismissRequest = { showMenu = false }
109- ) {
110- if (! phoneNumber.isNullOrBlank()) {
111- DropdownMenuItem (
112- text = {
113- Row (verticalAlignment = Alignment .CenterVertically ) {
114- Icon (
115- imageVector = Icons .Default .AccountCircle ,
116- contentDescription = stringResource(R .string.your_account),
117- modifier = Modifier .size(40 .dp),
118- tint = MaterialTheme .colorScheme.onSurfaceVariant
119- )
120- Spacer (modifier = Modifier .width(16 .dp))
121- Column {
122- Text (
123- text = stringResource(R .string.your_account),
124- fontWeight = FontWeight .SemiBold ,
125- style = MaterialTheme .typography.bodyMedium
126- )
127- Text (
128- text = phoneNumber,
129- style = MaterialTheme .typography.bodySmall,
130- color = MaterialTheme .colorScheme.onSurfaceVariant
131- )
132- }
133- }
134- },
135- onClick = { },
136- enabled = false
114+ IconButton (onClick = { onDeleteSelected?.invoke() }) {
115+ Icon (
116+ imageVector = Icons .Filled .Delete ,
117+ contentDescription = stringResource(R .string.delete)
137118 )
138- HorizontalDivider (modifier = Modifier .padding(vertical = 8 .dp))
139119 }
140- DropdownMenuItem (
141- text = { Text (stringResource(R .string.settings)) },
142- onClick = {
143- context.startActivity(
144- Intent (context, SettingsActivity ::class .java).apply {
145- flags =
146- Intent .FLAG_ACTIVITY_NEW_TASK or Intent .FLAG_ACTIVITY_TASK_ON_HOME
147- }
120+ },
121+ colors = TopAppBarDefaults .topAppBarColors(),
122+ scrollBehavior = scrollBehavior,
123+ modifier = Modifier .nestedScroll(scrollBehavior.nestedScrollConnection)
124+ )
125+ } else {
126+ // Normal mode app bar
127+ CenterAlignedTopAppBar (
128+ title = {
129+ if (! isSearchActive) {
130+ Text (stringResource(R .string.app_name))
131+ }
132+ },
133+ actions = {
134+ if (! isSearchActive) {
135+ IconButton (onClick = onToggleSearch) {
136+ Icon (
137+ imageVector = Icons .Filled .Search ,
138+ contentDescription = stringResource(R .string.search)
148139 )
149- showMenu = false
150140 }
151- )
152- DropdownMenuItem (
153- text = { Text (stringResource(R .string.about)) },
154- onClick = {
155- navController.navigate(AboutScreen )
156- showMenu = false
141+ }
142+
143+ IconButton (onClick = { showMenu = ! showMenu }) {
144+ Icon (
145+ imageVector = Icons .Filled .MoreVert ,
146+ contentDescription = stringResource(R .string.menu)
147+ )
148+ }
149+ DropdownMenu (
150+ expanded = showMenu,
151+ onDismissRequest = { showMenu = false }
152+ ) {
153+ if (! phoneNumber.isNullOrBlank()) {
154+ DropdownMenuItem (
155+ text = {
156+ Row (verticalAlignment = Alignment .CenterVertically ) {
157+ Icon (
158+ imageVector = Icons .Default .AccountCircle ,
159+ contentDescription = stringResource(R .string.your_account),
160+ modifier = Modifier .size(40 .dp),
161+ tint = MaterialTheme .colorScheme.onSurfaceVariant
162+ )
163+ Spacer (modifier = Modifier .width(16 .dp))
164+ Column {
165+ Text (
166+ text = stringResource(R .string.your_account),
167+ fontWeight = FontWeight .SemiBold ,
168+ style = MaterialTheme .typography.bodyMedium
169+ )
170+ Text (
171+ text = phoneNumber,
172+ style = MaterialTheme .typography.bodySmall,
173+ color = MaterialTheme .colorScheme.onSurfaceVariant
174+ )
175+ }
176+ }
177+ },
178+ onClick = { },
179+ enabled = false
180+ )
181+ HorizontalDivider (modifier = Modifier .padding(vertical = 8 .dp))
157182 }
158- )
159- }
160- },
161- colors = TopAppBarDefaults .topAppBarColors(),
162- scrollBehavior = scrollBehavior,
163- modifier = Modifier .nestedScroll(scrollBehavior.nestedScrollConnection)
164- )
183+ DropdownMenuItem (
184+ text = { Text (stringResource(R .string.settings)) },
185+ onClick = {
186+ context.startActivity(
187+ Intent (context, SettingsActivity ::class .java).apply {
188+ flags =
189+ Intent .FLAG_ACTIVITY_NEW_TASK or Intent .FLAG_ACTIVITY_TASK_ON_HOME
190+ }
191+ )
192+ showMenu = false
193+ }
194+ )
195+ DropdownMenuItem (
196+ text = { Text (stringResource(R .string.about)) },
197+ onClick = {
198+ navController.navigate(AboutScreen )
199+ showMenu = false
200+ }
201+ )
202+ }
203+ },
204+ colors = TopAppBarDefaults .topAppBarColors(),
205+ scrollBehavior = scrollBehavior,
206+ modifier = Modifier .nestedScroll(scrollBehavior.nestedScrollConnection)
207+ )
208+ }
165209
166210 if (isSearchActive) {
167211 Row (
@@ -221,3 +265,23 @@ fun RecentsAppBarPreview() {
221265 )
222266 }
223267}
268+
269+ @Preview(showBackground = true )
270+ @Composable
271+ fun RecentsAppBarSelectionModePreview () {
272+ AppTheme (darkTheme = false ) {
273+ RecentAppBar (
274+ navController = NavController (context = LocalContext .current),
275+ onSearchQueryChanged = { },
276+ searchQuery = " " ,
277+ isSearchActive = false ,
278+ onToggleSearch = { },
279+ onSearchDone = {},
280+ isSelectionMode = true ,
281+ selectedCount = 3 ,
282+ onSelectAll = { },
283+ onDeleteSelected = { },
284+ onCancelSelection = { }
285+ )
286+ }
287+ }
0 commit comments