Skip to content
Open

Dev2 #24

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ android {
}

dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1'
def composeBom = platform('androidx.compose:compose-bom:2025.07.00')
implementation composeBom
androidTestImplementation composeBom
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
package ru.yandex.practicum.contacts.data.models

data class Contact(
val id: Long,
val firstName: String,
val lastName: String,
val phoneNumber: String,
val messagingApps: List<MessagingApp> = emptyList()
)

enum class MessagingApp {
TELEGRAM,
WHATS_APP,
Expand All @@ -16,4 +8,6 @@ enum class MessagingApp {
THREEMA,
PHONE,
EMAIL
}
}

annotation class Contact
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package ru.yandex.practicum.contacts.data.models

data class CountryCode(
val code: String,
val country: String
data class CountryCode(
val code: String,
val country: String
) {
companion object {
val COMMON_CODES = listOf(
Expand All @@ -18,4 +18,6 @@ data class CountryCode(
CountryCode("+55", "Brazil")
)
}
}
}

annotation class CountryCode
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package ru.yandex.practicum.contacts.data.models

annotation class MessagingApp {
companion object {
val entries: List<MessagingApp>
get() {
TODO()
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import ru.yandex.practicum.contacts.data.models.MessagingApp
import ru.yandex.practicum.contacts.domain.repository.ContactsRepository

class ContactsRepositoryImpl(private val context: Context) : ContactsRepository {
override fun getContacts(): Flow<List<Contact>> = flow {
fun getContacts(): Flow<List<Contact>> = flow {
val contacts = mutableListOf<Contact>()

context.contentResolver.query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
arrayOf(
Expand All @@ -28,18 +28,18 @@ class ContactsRepositoryImpl(private val context: Context) : ContactsRepository
val idIndex = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.CONTACT_ID)
val nameIndex = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME)
val numberIndex = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)

while (cursor.moveToNext()) {
val id = cursor.getLong(idIndex)
val fullName = cursor.getString(nameIndex)
val phoneNumber = cursor.getString(numberIndex)

val nameParts = fullName.split(" ", limit = 2)
val firstName = nameParts.firstOrNull() ?: ""
val lastName = nameParts.getOrNull(1) ?: ""

val messagingApps = MessagingApp.entries.filter { (0..1).random() == 1 }

contacts.add(
Contact(
id = id,
Expand All @@ -51,7 +51,7 @@ class ContactsRepositoryImpl(private val context: Context) : ContactsRepository
)
}
}

emit(contacts)
}.flowOn(Dispatchers.IO)
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
package ru.yandex.practicum.contacts.domain.repository

import kotlinx.coroutines.flow.Flow
import ru.yandex.practicum.contacts.data.models.Contact

interface ContactsRepository {
fun getContacts(): Flow<List<Contact>>
}
open annotation class ContactsRepository
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
package ru.yandex.practicum.contacts.presentation.country

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Close
import androidx.compose.material3.BottomSheetDefaults
import androidx.compose.material3.Checkbox
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
Expand All @@ -27,6 +17,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
Expand All @@ -35,73 +26,23 @@ fun CountryCodeBottomSheet(
onCodesSelected: (Set<CountryCode>) -> 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,
selectedCodes,
onItemsSelected = onCodesSelected,
onDismiss=onDismiss
) { countryCode, isSelected ->
CountryCodeOption(
isSelected = isSelected,
countryCode = countryCode,
selectedCodes = selectedCodes,
onCodesSelected = onCodesSelected
)
}
}


@Composable
private fun CountryCodeOption(
isSelected: Boolean,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
package ru.yandex.practicum.contacts.presentation.messengers

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Close
import androidx.compose.material3.BottomSheetDefaults
import androidx.compose.material3.Checkbox
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
Expand All @@ -27,6 +15,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
Expand All @@ -35,70 +24,19 @@ fun MessengersBottomSheet(
onAppsSelected: (Set<MessagingApp>) -> 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
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,4 @@ fun <T> CommonBottomSheet(
}
}
}
}
}
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ 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
android.nonTransitiveRClass=true
android.overridePathCheck=true