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,7 +210,8 @@ 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)
if (selectedDate != null) {
Column { Column {
selectedDate.places.forEachIndexed { index, placeItem -> selectedDate.places.forEachIndexed { index, placeItem ->
Row( Row(
@@ -238,6 +238,7 @@ private fun Content(
} }
} }
} }
}
Spacer(modifier = Modifier.height(32.dp)) Spacer(modifier = Modifier.height(32.dp))

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()
) {
Text(
text = "",
color = Color.Red,
modifier = Modifier modifier = Modifier
.testTag(TestIds.Main.ERROR) .fillMaxSize()
.height(0.dp) .padding(horizontal = 16.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,41 +205,39 @@ 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)
) )
} else {
Box(
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
contentAlignment = Alignment.Center
) {
Text(
text = "У вас нет активных бронирований",
color = MaterialTheme.colorScheme.onSurfaceVariant
)
}
}
LazyColumn( LazyColumn(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.weight(1f) .weight(1f)
.padding(horizontal = 16.dp, vertical = 8.dp)
) { ) {
itemsIndexed(currentState.bookings) { index, booking -> itemsIndexed(currentState.bookings) { index, booking ->
BookingItem( BookingItem(
booking = booking, booking = booking,
position = index, position = index,
modifier = Modifier.testTag( modifier = Modifier
TestIds.Main.getIdItemByPosition(index) .fillMaxWidth()
.padding(vertical = 4.dp)
.testTag(TestIds.Main.getIdItemByPosition(index))
) )
}
}
} else {
Box(
modifier = Modifier
.fillMaxWidth()
.weight(1f),
contentAlignment = Alignment.Center
) {
Text(
text = "У вас нет активных бронирований",
color = MaterialTheme.colorScheme.onSurfaceVariant
) )
} }
} }
@@ -261,10 +254,11 @@ private fun BookingItem(
position: Int, position: Int,
modifier: Modifier = Modifier modifier: Modifier = Modifier
) { ) {
Card( Box(
modifier = modifier modifier = modifier
.fillMaxWidth() ) {
.padding(vertical = 4.dp), Card(
modifier = Modifier.fillMaxWidth(),
elevation = CardDefaults.cardElevation(defaultElevation = 2.dp) elevation = CardDefaults.cardElevation(defaultElevation = 2.dp)
) { ) {
Column( Column(
@@ -283,3 +277,4 @@ private fun BookingItem(
} }
} }
} }
}

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 ?: "Ошибка загрузки данных"
) )
} }
} }