@@ -7,17 +7,23 @@ import androidx.compose.foundation.layout.Row
77import androidx.compose.foundation.layout.Spacer
88import androidx.compose.foundation.layout.fillMaxWidth
99import androidx.compose.foundation.layout.padding
10+ import androidx.compose.foundation.layout.size
1011import androidx.compose.foundation.layout.width
1112import androidx.compose.foundation.text.KeyboardActions
1213import androidx.compose.foundation.text.KeyboardOptions
1314import androidx.compose.material.icons.Icons
15+ import androidx.compose.material.icons.filled.AccountCircle
16+ import androidx.compose.material.icons.filled.Cancel
1417import androidx.compose.material.icons.filled.Close
18+ import androidx.compose.material.icons.filled.Delete
1519import androidx.compose.material.icons.filled.MoreVert
1620import androidx.compose.material.icons.filled.Search
21+ import androidx.compose.material.icons.filled.SelectAll
1722import androidx.compose.material3.CenterAlignedTopAppBar
1823import androidx.compose.material3.DropdownMenu
1924import androidx.compose.material3.DropdownMenuItem
2025import androidx.compose.material3.ExperimentalMaterial3Api
26+ import androidx.compose.material3.HorizontalDivider
2127import androidx.compose.material3.Icon
2228import androidx.compose.material3.IconButton
2329import androidx.compose.material3.MaterialTheme
@@ -39,6 +45,7 @@ import androidx.compose.ui.platform.LocalContext
3945import androidx.compose.ui.platform.LocalFocusManager
4046import androidx.compose.ui.res.stringResource
4147import androidx.compose.ui.text.TextStyle
48+ import androidx.compose.ui.text.font.FontWeight
4249import androidx.compose.ui.text.input.ImeAction
4350import androidx.compose.ui.tooling.preview.Preview
4451import androidx.compose.ui.unit.dp
@@ -47,6 +54,7 @@ import com.example.sw0b_001.R
4754import com.example.sw0b_001.SettingsActivity
4855import com.example.sw0b_001.ui.navigation.AboutScreen
4956import com.example.sw0b_001.ui.theme.AppTheme
57+ import com.example.sw0b_001.utils.getPhoneNumberFromPrefs
5058
5159@Composable
5260@OptIn(ExperimentalMaterial3Api ::class )
@@ -56,7 +64,12 @@ fun RecentAppBar(
5664 searchQuery : String ,
5765 isSearchActive : Boolean ,
5866 onToggleSearch : () -> Unit ,
59- onSearchDone : () -> Unit
67+ onSearchDone : () -> Unit ,
68+ isSelectionMode : Boolean = false,
69+ selectedCount : Int = 0,
70+ onSelectAll : (() -> Unit )? = null,
71+ onDeleteSelected : (() -> Unit )? = null,
72+ onCancelSelection : (() -> Unit )? = null,
6073) {
6174 val context = LocalContext .current
6275 val focusManager = LocalFocusManager .current
@@ -72,58 +85,127 @@ fun RecentAppBar(
7285 }
7386 )
7487 }
88+
89+ val phoneNumber = remember { getPhoneNumberFromPrefs(context) }
90+
7591 Column (modifier = Modifier .fillMaxWidth()) {
76- CenterAlignedTopAppBar (
77- title = {
78- if (! isSearchActive) {
79- Text (stringResource(R .string.app_name))
80- }
81- },
82- actions = {
83- if (! isSearchActive) {
84- 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() }) {
85100 Icon (
86- imageVector = Icons .Filled .Search ,
87- 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)
88111 )
89112 }
90- }
91113
92- IconButton (onClick = { showMenu = ! showMenu }) {
93- Icon (
94- imageVector = Icons .Filled .MoreVert ,
95- contentDescription = stringResource(R .string.menu)
96- )
97- }
98- DropdownMenu (
99- expanded = showMenu,
100- onDismissRequest = { showMenu = false }
101- ) {
102- DropdownMenuItem (
103- text = { Text (stringResource(R .string.settings)) },
104- onClick = {
105- context.startActivity(
106- Intent (context, SettingsActivity ::class .java).apply {
107- flags =
108- Intent .FLAG_ACTIVITY_NEW_TASK or Intent .FLAG_ACTIVITY_TASK_ON_HOME
109- }
114+ IconButton (onClick = { onDeleteSelected?.invoke() }) {
115+ Icon (
116+ imageVector = Icons .Filled .Delete ,
117+ contentDescription = stringResource(R .string.delete)
118+ )
119+ }
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)
110139 )
111- showMenu = false
112140 }
113- )
114- DropdownMenuItem (
115- text = { Text (stringResource(R .string.about)) },
116- onClick = {
117- navController.navigate(AboutScreen )
118- 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))
119182 }
120- )
121- }
122- },
123- colors = TopAppBarDefaults .topAppBarColors(),
124- scrollBehavior = scrollBehavior,
125- modifier = Modifier .nestedScroll(scrollBehavior.nestedScrollConnection)
126- )
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+ }
127209
128210 if (isSearchActive) {
129211 Row (
@@ -183,3 +265,23 @@ fun RecentsAppBarPreview() {
183265 )
184266 }
185267}
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