This commit is contained in:
solovushka56
2025-12-12 02:20:05 +03:00
parent cd70c1cd20
commit 011e169f96
4 changed files with 73 additions and 79 deletions

View File

@@ -45,6 +45,8 @@ class AuthRepository private constructor(context: Context) {
if (codeCache != null && name != null) { if (codeCache != null && name != null) {
userCache = UserCache(name, photo) userCache = UserCache(name, photo)
_isAuthorized.value = true _isAuthorized.value = true
} else {
clear()
} }
} }

View File

@@ -158,7 +158,7 @@ fun BookScreen(
modifier = Modifier modifier = Modifier
.fillMaxSize() .fillMaxSize()
.padding(paddingValues) .padding(paddingValues)
.padding(16.dp) .padding(horizontal = 16.dp, vertical = 8.dp)
) { ) {
Content( Content(
state = currentState, state = currentState,
@@ -185,7 +185,6 @@ private fun Content(
.fillMaxSize() .fillMaxSize()
.verticalScroll(rememberScrollState()) .verticalScroll(rememberScrollState())
) { ) {
ScrollableTabRow( ScrollableTabRow(
selectedTabIndex = state.selectedDateIndex, selectedTabIndex = state.selectedDateIndex,
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
@@ -211,30 +210,32 @@ private fun Content(
Spacer(modifier = Modifier.height(16.dp)) Spacer(modifier = Modifier.height(16.dp))
val selectedDate = state.dates[state.selectedDateIndex] val selectedDate = state.dates.getOrNull(state.selectedDateIndex)
Column { if (selectedDate != null) {
selectedDate.places.forEachIndexed { index, placeItem -> Column {
Row( selectedDate.places.forEachIndexed { index, placeItem ->
modifier = Modifier Row(
.fillMaxWidth() modifier = Modifier
.selectable( .fillMaxWidth()
.selectable(
selected = state.selectedPlaceIndex == index,
onClick = { onPlaceSelect(index) }
)
.padding(vertical = 8.dp, horizontal = 16.dp)
.testTag(TestIds.Book.getIdPlaceItemByPosition(index))
) {
RadioButton(
selected = state.selectedPlaceIndex == index, selected = state.selectedPlaceIndex == index,
onClick = { onPlaceSelect(index) } onClick = { onPlaceSelect(index) },
modifier = Modifier.testTag(TestIds.Book.ITEM_PLACE_SELECTOR)
) )
.padding(vertical = 8.dp, horizontal = 16.dp) Spacer(modifier = Modifier.width(16.dp))
.testTag(TestIds.Book.getIdPlaceItemByPosition(index)) Text(
) { text = placeItem.name,
RadioButton( modifier = Modifier.testTag(TestIds.Book.ITEM_PLACE_TEXT),
selected = state.selectedPlaceIndex == index, style = MaterialTheme.typography.bodyLarge
onClick = { onPlaceSelect(index) }, )
modifier = Modifier.testTag(TestIds.Book.ITEM_PLACE_SELECTOR) }
)
Spacer(modifier = Modifier.width(16.dp))
Text(
text = placeItem.name,
modifier = Modifier.testTag(TestIds.Book.ITEM_PLACE_TEXT),
style = MaterialTheme.typography.bodyLarge
)
} }
} }
} }

View File

@@ -99,9 +99,10 @@ fun MainScreen(
Text( Text(
text = currentState.error, text = currentState.error,
color = Color.Red, color = Color.Red,
modifier = Modifier.testTag(TestIds.Main.ERROR) modifier = Modifier
.testTag(TestIds.Main.ERROR)
.padding(bottom = 16.dp)
) )
Spacer(modifier = Modifier.height(16.dp))
Button( Button(
onClick = { viewModel.onIntent(MainIntent.Refresh) }, onClick = { viewModel.onIntent(MainIntent.Refresh) },
modifier = Modifier.testTag(TestIds.Main.REFRESH_BUTTON) modifier = Modifier.testTag(TestIds.Main.REFRESH_BUTTON)
@@ -111,20 +112,14 @@ fun MainScreen(
} }
} else { } else {
Column( Column(
modifier = Modifier.fillMaxSize() modifier = Modifier
.fillMaxSize()
.padding(horizontal = 16.dp)
) { ) {
Text(
text = "",
color = Color.Red,
modifier = Modifier
.testTag(TestIds.Main.ERROR)
.height(0.dp)
)
Card( Card(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.padding(16.dp), .padding(vertical = 16.dp),
elevation = CardDefaults.cardElevation(defaultElevation = 4.dp) elevation = CardDefaults.cardElevation(defaultElevation = 4.dp)
) { ) {
Row( Row(
@@ -179,7 +174,7 @@ fun MainScreen(
Row( Row(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.padding(horizontal = 16.dp), .padding(bottom = 16.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp) horizontalArrangement = Arrangement.spacedBy(8.dp)
) { ) {
Button( Button(
@@ -210,19 +205,34 @@ fun MainScreen(
} }
} }
Spacer(modifier = Modifier.height(8.dp))
if (currentState.bookings.isNotEmpty()) { if (currentState.bookings.isNotEmpty()) {
Text( Text(
text = "Мои бронирования:", text = "Мои бронирования:",
style = MaterialTheme.typography.titleMedium, style = MaterialTheme.typography.titleMedium,
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp) modifier = Modifier.padding(bottom = 8.dp)
) )
LazyColumn(
modifier = Modifier
.fillMaxWidth()
.weight(1f)
) {
itemsIndexed(currentState.bookings) { index, booking ->
BookingItem(
booking = booking,
position = index,
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 4.dp)
.testTag(TestIds.Main.getIdItemByPosition(index))
)
}
}
} else { } else {
Box( Box(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.padding(16.dp), .weight(1f),
contentAlignment = Alignment.Center contentAlignment = Alignment.Center
) { ) {
Text( Text(
@@ -231,23 +241,6 @@ fun MainScreen(
) )
} }
} }
LazyColumn(
modifier = Modifier
.fillMaxWidth()
.weight(1f)
.padding(horizontal = 16.dp, vertical = 8.dp)
) {
itemsIndexed(currentState.bookings) { index, booking ->
BookingItem(
booking = booking,
position = index,
modifier = Modifier.testTag(
TestIds.Main.getIdItemByPosition(index)
)
)
}
}
} }
} }
} }
@@ -261,25 +254,27 @@ private fun BookingItem(
position: Int, position: Int,
modifier: Modifier = Modifier modifier: Modifier = Modifier
) { ) {
Card( Box(
modifier = modifier modifier = modifier
.fillMaxWidth()
.padding(vertical = 4.dp),
elevation = CardDefaults.cardElevation(defaultElevation = 2.dp)
) { ) {
Column( Card(
modifier = Modifier.padding(16.dp) modifier = Modifier.fillMaxWidth(),
elevation = CardDefaults.cardElevation(defaultElevation = 2.dp)
) { ) {
Text( Column(
text = booking.place, modifier = Modifier.padding(16.dp)
style = MaterialTheme.typography.titleMedium, ) {
modifier = Modifier.testTag(TestIds.Main.ITEM_PLACE) Text(
) text = booking.place,
Text( style = MaterialTheme.typography.titleMedium,
text = booking.getFormattedDate(), modifier = Modifier.testTag(TestIds.Main.ITEM_PLACE)
style = MaterialTheme.typography.bodyMedium, )
modifier = Modifier.testTag(TestIds.Main.ITEM_DATE) Text(
) text = booking.getFormattedDate(),
style = MaterialTheme.typography.bodyMedium,
modifier = Modifier.testTag(TestIds.Main.ITEM_DATE)
)
}
} }
} }
} }

View File

@@ -35,10 +35,6 @@ class MainViewModel(
fun onIntent(intent: MainIntent) { fun onIntent(intent: MainIntent) {
when (intent) { when (intent) {
MainIntent.Logout -> { MainIntent.Logout -> {
val currentState = _uiState.value
if (currentState is MainState.Data) {
authRepo.saveUserInfo(currentState.userName, currentState.userPhotoUrl)
}
authRepo.clear() authRepo.clear()
viewModelScope.launch { viewModelScope.launch {
_actionFlow.emit(MainAction.NavigateToAuth) _actionFlow.emit(MainAction.NavigateToAuth)
@@ -89,7 +85,7 @@ class MainViewModel(
MainState.Data( MainState.Data(
userName = authRepo.getUserInfo()?.name ?: "", userName = authRepo.getUserInfo()?.name ?: "",
userPhotoUrl = authRepo.getUserInfo()?.photo, userPhotoUrl = authRepo.getUserInfo()?.photo,
error = error.message ?: "data load error" error = error.message ?: "Ошибка загрузки данных"
) )
} }
} }