feat: remove code
This commit is contained in:
+62
-39
@@ -1,76 +1,99 @@
|
||||
package com.approagency.pharmacy.presentation.components
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
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.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.LocalPharmacy
|
||||
import androidx.compose.material.icons.filled.Medication
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedButton
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.compose.ui.platform.LocalLayoutDirection
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.LayoutDirection
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.approagency.pharmacy.domain.model.DrugSearchResult
|
||||
import com.approagency.pharmacy.presentation.common.CustomBox
|
||||
import com.vada.caller.ui.theme.LocalDime
|
||||
import com.vada.caller.ui.theme.dime
|
||||
|
||||
@Composable
|
||||
fun DaroYabSearchResult(
|
||||
drug: DrugSearchResult,
|
||||
onClickDetail: (DrugSearchResult) -> Unit,
|
||||
onClickDrugStore:(DrugSearchResult) ->Unit,
|
||||
onClickDrugStore: (DrugSearchResult) -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val dime = LocalDime.current
|
||||
|
||||
CustomBox (
|
||||
CustomBox(
|
||||
modifier = modifier
|
||||
.padding(bottom = MaterialTheme.dime.sm)
|
||||
.fillMaxWidth()
|
||||
.clickable { onClickDetail(drug) },
|
||||
|
||||
) {
|
||||
Row (
|
||||
modifier = modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.End
|
||||
) {
|
||||
CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Rtl) {
|
||||
Column(
|
||||
modifier = Modifier.padding(dime.lg),
|
||||
verticalArrangement = Arrangement.Center,
|
||||
horizontalAlignment = Alignment.End
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(MaterialTheme.dime.lg),
|
||||
verticalArrangement = Arrangement.spacedBy(MaterialTheme.dime.xs)
|
||||
) {
|
||||
Text(
|
||||
text = drug.persianName,
|
||||
style = MaterialTheme.typography.labelLarge
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
drug.englishName?.let {
|
||||
drug.englishName?.takeIf { it.isNotBlank() }?.let {
|
||||
Text(
|
||||
text = it,
|
||||
fontSize = 12.sp,
|
||||
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.7f)
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
)
|
||||
}
|
||||
Text(
|
||||
text = "کد: ${drug.genericId}",
|
||||
fontSize = 10.sp,
|
||||
color = MaterialTheme.colorScheme.primary
|
||||
)
|
||||
Row(
|
||||
modifier = modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.SpaceBetween
|
||||
) {
|
||||
TextButton(onClick = {onClickDetail(drug)} , content = {
|
||||
Text("اطلاعات دارویی")
|
||||
})
|
||||
TextButton(onClick = {onClickDrugStore(drug)} , content = {
|
||||
Text("موجودی داروخانه")
|
||||
})
|
||||
}
|
||||
|
||||
Spacer(Modifier.height(MaterialTheme.dime.sm))
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.spacedBy(MaterialTheme.dime.sm)
|
||||
) {
|
||||
Button(
|
||||
onClick = { onClickDrugStore(drug) },
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.height(44.dp)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Filled.LocalPharmacy,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.size(18.dp)
|
||||
)
|
||||
Spacer(Modifier.size(MaterialTheme.dime.xs))
|
||||
Text("موجودی داروخانه", style = MaterialTheme.typography.labelLarge)
|
||||
}
|
||||
OutlinedButton(
|
||||
onClick = { onClickDetail(drug) },
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.height(44.dp)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Filled.Medication,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.size(18.dp)
|
||||
)
|
||||
Spacer(Modifier.size(MaterialTheme.dime.xs))
|
||||
Text("اطلاعات دارویی", style = MaterialTheme.typography.labelLarge)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+119
-128
@@ -3,13 +3,13 @@ package com.approagency.pharmacy.presentation.components
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalConfiguration
|
||||
import androidx.compose.ui.platform.LocalLayoutDirection
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.LayoutDirection
|
||||
@@ -33,161 +33,152 @@ fun PharmacyBottomSheet(
|
||||
) {
|
||||
val scope = rememberCoroutineScope()
|
||||
val sheetState = rememberModalBottomSheetState(
|
||||
skipPartiallyExpanded = false, confirmValueChange = { true })
|
||||
|
||||
skipPartiallyExpanded = true, confirmValueChange = { true }
|
||||
)
|
||||
|
||||
var selectedProvinceId by remember { mutableStateOf("40") } // پیشفرض تهران
|
||||
var showProvinceDropdown by remember { mutableStateOf(false) }
|
||||
|
||||
val pharmacyState by viewModel.state.collectAsState()
|
||||
|
||||
// جستجوی اولیه با استان تهران — با تغییر دارو دوباره اجرا میشود
|
||||
// (در صورت خالی بودن شناسه، ViewModel وضعیت قبلی را پاک و خطا نمایش میدهد)
|
||||
// شیت بلند ثابت میشود تا لیست داخلی بهدرستی اسکرول شود (نه اینکه درگِ شیت
|
||||
// جای اسکرولِ لیست را بگیرد) و حالتهای لودینگ/خالی/خطا وسط دیده شوند.
|
||||
val sheetHeight = (LocalConfiguration.current.screenHeightDp * 0.85f).dp
|
||||
|
||||
LaunchedEffect(genericDrugId, brandIrc) {
|
||||
viewModel.search(genericDrugId, brandIrc, "40")
|
||||
}
|
||||
|
||||
if (isOpen) {
|
||||
CustomModalBottomSheet(
|
||||
sheetState = sheetState, onDismiss = onDismiss, scope = scope
|
||||
) {
|
||||
CustomModalBottomSheet(sheetState = sheetState, onDismiss = onDismiss, scope = scope) {
|
||||
CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Rtl) {
|
||||
LazyColumn(
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxHeight()
|
||||
.fillMaxWidth()
|
||||
.heightIn(min = 400.dp)
|
||||
.padding(MaterialTheme.dime.md),
|
||||
verticalArrangement = Arrangement.spacedBy(MaterialTheme.dime.xl)
|
||||
.height(sheetHeight)
|
||||
.padding(MaterialTheme.dime.lg)
|
||||
) {
|
||||
item {
|
||||
Text(
|
||||
text = "جستجوی دارو در داروخانهها",
|
||||
fontWeight = FontWeight.Bold,
|
||||
fontSize = MaterialTheme.typography.titleMedium.fontSize
|
||||
)
|
||||
}
|
||||
// عنوان
|
||||
// سربرگ ثابت
|
||||
Text(
|
||||
text = "موجودی دارو در داروخانهها",
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
|
||||
item {
|
||||
ExposedDropdownMenuBox(
|
||||
expanded = showProvinceDropdown,
|
||||
onExpandedChange = { showProvinceDropdown = it }) {
|
||||
OutlinedTextField(
|
||||
value = provinces.find { it.id == selectedProvinceId }?.name
|
||||
?: "انتخاب استان",
|
||||
onValueChange = {},
|
||||
readOnly = true,
|
||||
trailingIcon = { ExposedDropdownMenuDefaults.TrailingIcon(expanded = showProvinceDropdown) },
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.menuAnchor(),
|
||||
shape = MaterialTheme.shapes.large
|
||||
Spacer(Modifier.height(MaterialTheme.dime.md))
|
||||
|
||||
ProvinceSelector(
|
||||
selectedProvinceId = selectedProvinceId,
|
||||
expanded = showProvinceDropdown,
|
||||
onExpandedChange = { showProvinceDropdown = it },
|
||||
onProvinceSelected = { id ->
|
||||
selectedProvinceId = id
|
||||
showProvinceDropdown = false
|
||||
viewModel.search(genericDrugId, brandIrc, id)
|
||||
}
|
||||
)
|
||||
|
||||
Spacer(Modifier.height(MaterialTheme.dime.md))
|
||||
|
||||
// ناحیهی محتوا فضای باقیمانده را پر میکند؛ سربرگ بالا ثابت میماند.
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.weight(1f),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
when (val state = pharmacyState) {
|
||||
PharmacyState.Loading -> Loading(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
message = "در حال جستجو..."
|
||||
)
|
||||
|
||||
ExposedDropdownMenu(
|
||||
expanded = showProvinceDropdown,
|
||||
onDismissRequest = { showProvinceDropdown = false }) {
|
||||
provinces.forEach { province ->
|
||||
DropdownMenuItem(text = { Text(province.name) }, onClick = {
|
||||
selectedProvinceId = province.id
|
||||
showProvinceDropdown = false
|
||||
// جستجو با استان جدید
|
||||
viewModel.search(genericDrugId, brandIrc, province.id)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// انتخاب استان
|
||||
|
||||
|
||||
// نمایش نتایج
|
||||
when (val state = pharmacyState) {
|
||||
PharmacyState.Loading -> {
|
||||
item {
|
||||
Loading(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(400.dp),
|
||||
message = "در حال جستجو..."
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
is PharmacyState.Success -> {
|
||||
if (state.items.isEmpty()) {
|
||||
item {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(400.dp),
|
||||
contentAlignment = Alignment.Center
|
||||
is PharmacyState.Success -> {
|
||||
if (state.items.isEmpty()) {
|
||||
EmptyMessage("هیچ داروخانهای یافت نشد")
|
||||
} else {
|
||||
LazyColumn(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
verticalArrangement = Arrangement.spacedBy(MaterialTheme.dime.sm)
|
||||
) {
|
||||
Text(
|
||||
text = "هیچ داروخانهای یافت نشد",
|
||||
fontSize = MaterialTheme.typography.bodyMedium.fontSize,
|
||||
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.6f)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
items(state.items) { pharmacy ->
|
||||
PharmacyResultItem(pharmacy = pharmacy, viewModel)
|
||||
}
|
||||
item {
|
||||
Spacer(modifier = Modifier.height(MaterialTheme.dime.md))
|
||||
Text(
|
||||
text = "تعداد کل: ${state.items.size} داروخانه",
|
||||
fontSize = MaterialTheme.typography.bodySmall.fontSize,
|
||||
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.5f),
|
||||
modifier = Modifier.padding(bottom = MaterialTheme.dime.xs)
|
||||
)
|
||||
}
|
||||
// LazyColumn(
|
||||
// verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||
// modifier = Modifier,
|
||||
// ) {
|
||||
// items(state.items) { pharmacy ->
|
||||
// PharmacyResultItem(pharmacy = pharmacy)
|
||||
// }
|
||||
//
|
||||
//
|
||||
// }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
is PharmacyState.Error -> {
|
||||
item {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(200.dp),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Column(horizontalAlignment = Alignment.CenterHorizontally) {
|
||||
Text(
|
||||
text = state.message,
|
||||
color = MaterialTheme.colorScheme.error,
|
||||
fontSize = MaterialTheme.typography.bodyMedium.fontSize
|
||||
)
|
||||
Spacer(modifier = Modifier.height(MaterialTheme.dime.sm))
|
||||
TextButton(
|
||||
onClick = { viewModel.retry() }) {
|
||||
Text("تلاش مجدد")
|
||||
items(state.items) { pharmacy ->
|
||||
PharmacyResultItem(pharmacy = pharmacy, viewModel)
|
||||
}
|
||||
item {
|
||||
Text(
|
||||
text = "تعداد کل: ${state.items.size} داروخانه",
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
modifier = Modifier.padding(vertical = MaterialTheme.dime.sm)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
is PharmacyState.Error -> Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Text(
|
||||
text = state.message,
|
||||
color = MaterialTheme.colorScheme.error,
|
||||
style = MaterialTheme.typography.bodyMedium
|
||||
)
|
||||
Spacer(Modifier.height(MaterialTheme.dime.sm))
|
||||
TextButton(onClick = { viewModel.retry() }) { Text("تلاش مجدد") }
|
||||
}
|
||||
|
||||
PharmacyState.Idle -> {}
|
||||
PharmacyState.Idle -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
private fun ProvinceSelector(
|
||||
selectedProvinceId: String,
|
||||
expanded: Boolean,
|
||||
onExpandedChange: (Boolean) -> Unit,
|
||||
onProvinceSelected: (String) -> Unit
|
||||
) {
|
||||
ExposedDropdownMenuBox(
|
||||
expanded = expanded,
|
||||
onExpandedChange = onExpandedChange
|
||||
) {
|
||||
OutlinedTextField(
|
||||
value = provinces.find { it.id == selectedProvinceId }?.name ?: "انتخاب استان",
|
||||
onValueChange = {},
|
||||
readOnly = true,
|
||||
label = { Text("استان") },
|
||||
trailingIcon = { ExposedDropdownMenuDefaults.TrailingIcon(expanded = expanded) },
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.menuAnchor(),
|
||||
shape = MaterialTheme.shapes.large
|
||||
)
|
||||
ExposedDropdownMenu(
|
||||
expanded = expanded,
|
||||
onDismissRequest = { onExpandedChange(false) }
|
||||
) {
|
||||
provinces.forEach { province ->
|
||||
DropdownMenuItem(
|
||||
text = { Text(province.name) },
|
||||
onClick = { onProvinceSelected(province.id) }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun EmptyMessage(message: String) {
|
||||
Text(
|
||||
text = message,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user