From cdf5cc9e8ce591034343f3d133567b70fc1eec53 Mon Sep 17 00:00:00 2001 From: Elizaveta Davydova Date: Tue, 21 Oct 2025 18:52:29 +0500 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=B6=D0=B5=D0=BD=D0=B5=D1=80=D0=B8?= =?UTF-8?q?=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../country/CountryCodeBottomSheet.kt | 78 ++++--------------- .../messengers/MessengersBottomSheet.kt | 77 ++++-------------- gradle.properties | 2 +- 3 files changed, 29 insertions(+), 128 deletions(-) diff --git a/app/src/main/java/ru/yandex/practicum/contacts/presentation/country/CountryCodeBottomSheet.kt b/app/src/main/java/ru/yandex/practicum/contacts/presentation/country/CountryCodeBottomSheet.kt index e74ab23..aa3e880 100644 --- a/app/src/main/java/ru/yandex/practicum/contacts/presentation/country/CountryCodeBottomSheet.kt +++ b/app/src/main/java/ru/yandex/practicum/contacts/presentation/country/CountryCodeBottomSheet.kt @@ -27,6 +27,7 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import ru.yandex.practicum.contacts.R import ru.yandex.practicum.contacts.data.models.CountryCode +import ru.yandex.practicum.contacts.presentation.ui.components.CommonBottomSheet @OptIn(ExperimentalMaterial3Api::class) @Composable @@ -35,70 +36,19 @@ fun CountryCodeBottomSheet( onCodesSelected: (Set) -> Unit, onDismiss: () -> Unit ) { - ModalBottomSheet( - onDismissRequest = onDismiss, - dragHandle = { BottomSheetDefaults.DragHandle() } - ) { - Column( - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 16.dp) - ) { - Row( - modifier = Modifier - .fillMaxWidth() - .padding(bottom = 16.dp), - horizontalArrangement = Arrangement.SpaceBetween, - verticalAlignment = Alignment.CenterVertically - ) { - Text( - text = stringResource(R.string.filter_by_country_code), - style = MaterialTheme.typography.titleLarge - ) - IconButton(onClick = onDismiss) { - Icon( - imageVector = Icons.Default.Close, - contentDescription = stringResource(R.string.close) - ) - } - } - - LazyColumn( - modifier = Modifier - .fillMaxWidth() - .padding(bottom = 16.dp) - ) { - items(CountryCode.COMMON_CODES) { countryCode -> - val isSelected = selectedCodes.contains(countryCode) - Surface( - modifier = Modifier - .fillMaxWidth() - .padding(vertical = 4.dp), - onClick = { - val newSelection = selectedCodes.toMutableSet() - if (isSelected) { - newSelection.remove(countryCode) - } else { - newSelection.add(countryCode) - } - onCodesSelected(newSelection) - }, - color = if (isSelected) { - MaterialTheme.colorScheme.primaryContainer - } else { - MaterialTheme.colorScheme.surface - } - ) { - CountryCodeOption( - isSelected = isSelected, - countryCode = countryCode, - selectedCodes = selectedCodes, - onCodesSelected = onCodesSelected - ) - } - } - } - } + CommonBottomSheet( + title = stringResource(R.string.filter_by_country_code), + items = CountryCode.COMMON_CODES, + selectedItems = selectedCodes, + onItemsSelected = onCodesSelected, + onDismiss = onDismiss + ) { countryCode, isSelected -> + CountryCodeOption( + isSelected = isSelected, + countryCode = countryCode, + selectedCodes = selectedCodes, + onCodesSelected = onCodesSelected + ) } } diff --git a/app/src/main/java/ru/yandex/practicum/contacts/presentation/messengers/MessengersBottomSheet.kt b/app/src/main/java/ru/yandex/practicum/contacts/presentation/messengers/MessengersBottomSheet.kt index dcddf8d..2562ee3 100644 --- a/app/src/main/java/ru/yandex/practicum/contacts/presentation/messengers/MessengersBottomSheet.kt +++ b/app/src/main/java/ru/yandex/practicum/contacts/presentation/messengers/MessengersBottomSheet.kt @@ -27,6 +27,7 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import ru.yandex.practicum.contacts.R import ru.yandex.practicum.contacts.data.models.MessagingApp +import ru.yandex.practicum.contacts.presentation.ui.components.CommonBottomSheet @OptIn(ExperimentalMaterial3Api::class) @Composable @@ -35,70 +36,20 @@ fun MessengersBottomSheet( onAppsSelected: (Set) -> Unit, onDismiss: () -> Unit ) { - ModalBottomSheet( - onDismissRequest = onDismiss, - dragHandle = { BottomSheetDefaults.DragHandle() } - ) { - Column( - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 16.dp) - ) { - Row( - modifier = Modifier - .fillMaxWidth() - .padding(bottom = 16.dp), - horizontalArrangement = Arrangement.SpaceBetween, - verticalAlignment = Alignment.CenterVertically - ) { - Text( - text = stringResource(R.string.filter_by_messaging_app), - style = MaterialTheme.typography.titleLarge - ) - IconButton(onClick = onDismiss) { - Icon( - imageVector = Icons.Default.Close, - contentDescription = stringResource(R.string.close) - ) - } - } - LazyColumn( - modifier = Modifier - .fillMaxWidth() - .padding(bottom = 16.dp) - ) { - items(MessagingApp.entries) { app -> - val isSelected = selectedApps.contains(app) - Surface( - modifier = Modifier - .fillMaxWidth() - .padding(vertical = 4.dp), - onClick = { - val newSelection = selectedApps.toMutableSet() - if (isSelected) { - newSelection.remove(app) - } else { - newSelection.add(app) - } - onAppsSelected(newSelection) - }, - color = if (isSelected) { - MaterialTheme.colorScheme.primaryContainer - } else { - MaterialTheme.colorScheme.surface - } - ) { - MessengerOption( - isSelected = isSelected, - app = app, - selectedApps = selectedApps, - onAppsSelected = onAppsSelected - ) - } - } - } - } + CommonBottomSheet( + title = stringResource(R.string.filter_by_messaging_app), + items = MessagingApp.entries, + selectedItems = selectedApps, + onItemsSelected = onAppsSelected, + onDismiss = onDismiss + ) { app, isSelected -> + MessengerOption( + isSelected = isSelected, + app = app, + selectedApps = selectedApps, + onAppsSelected = onAppsSelected + ) } } diff --git a/gradle.properties b/gradle.properties index dab7c28..d5e8af3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,4 +18,4 @@ android.useAndroidX=true # Enables namespacing of each library's R class so that its R class includes only the # resources declared in the library itself and none from the library's dependencies, # thereby reducing the size of the R class for that library -android.nonTransitiveRClass=true \ No newline at end of file +android.nonTransitiveRClass=true