forked from Olympic/NTO-2025-Android-TeamTask
bugfix
This commit is contained in:
@@ -45,6 +45,8 @@ class AuthRepository private constructor(context: Context) {
|
||||
if (codeCache != null && name != null) {
|
||||
userCache = UserCache(name, photo)
|
||||
_isAuthorized.value = true
|
||||
} else {
|
||||
clear()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -158,7 +158,7 @@ fun BookScreen(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(paddingValues)
|
||||
.padding(16.dp)
|
||||
.padding(horizontal = 16.dp, vertical = 8.dp)
|
||||
) {
|
||||
Content(
|
||||
state = currentState,
|
||||
@@ -185,7 +185,6 @@ private fun Content(
|
||||
.fillMaxSize()
|
||||
.verticalScroll(rememberScrollState())
|
||||
) {
|
||||
|
||||
ScrollableTabRow(
|
||||
selectedTabIndex = state.selectedDateIndex,
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
@@ -211,7 +210,8 @@ private fun Content(
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
val selectedDate = state.dates[state.selectedDateIndex]
|
||||
val selectedDate = state.dates.getOrNull(state.selectedDateIndex)
|
||||
if (selectedDate != null) {
|
||||
Column {
|
||||
selectedDate.places.forEachIndexed { index, placeItem ->
|
||||
Row(
|
||||
@@ -238,6 +238,7 @@ private fun Content(
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(32.dp))
|
||||
|
||||
|
||||
@@ -99,9 +99,10 @@ fun MainScreen(
|
||||
Text(
|
||||
text = currentState.error,
|
||||
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(
|
||||
onClick = { viewModel.onIntent(MainIntent.Refresh) },
|
||||
modifier = Modifier.testTag(TestIds.Main.REFRESH_BUTTON)
|
||||
@@ -111,20 +112,14 @@ fun MainScreen(
|
||||
}
|
||||
} else {
|
||||
Column(
|
||||
modifier = Modifier.fillMaxSize()
|
||||
) {
|
||||
Text(
|
||||
text = "",
|
||||
color = Color.Red,
|
||||
modifier = Modifier
|
||||
.testTag(TestIds.Main.ERROR)
|
||||
.height(0.dp)
|
||||
)
|
||||
|
||||
.fillMaxSize()
|
||||
.padding(horizontal = 16.dp)
|
||||
) {
|
||||
Card(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(16.dp),
|
||||
.padding(vertical = 16.dp),
|
||||
elevation = CardDefaults.cardElevation(defaultElevation = 4.dp)
|
||||
) {
|
||||
Row(
|
||||
@@ -179,7 +174,7 @@ fun MainScreen(
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp),
|
||||
.padding(bottom = 16.dp),
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
||||
) {
|
||||
Button(
|
||||
@@ -210,41 +205,39 @@ fun MainScreen(
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
if (currentState.bookings.isNotEmpty()) {
|
||||
Text(
|
||||
text = "Мои бронирования:",
|
||||
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(
|
||||
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)
|
||||
modifier = Modifier
|
||||
.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,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Card(
|
||||
Box(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.padding(vertical = 4.dp),
|
||||
) {
|
||||
Card(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
elevation = CardDefaults.cardElevation(defaultElevation = 2.dp)
|
||||
) {
|
||||
Column(
|
||||
@@ -283,3 +277,4 @@ private fun BookingItem(
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,10 +35,6 @@ class MainViewModel(
|
||||
fun onIntent(intent: MainIntent) {
|
||||
when (intent) {
|
||||
MainIntent.Logout -> {
|
||||
val currentState = _uiState.value
|
||||
if (currentState is MainState.Data) {
|
||||
authRepo.saveUserInfo(currentState.userName, currentState.userPhotoUrl)
|
||||
}
|
||||
authRepo.clear()
|
||||
viewModelScope.launch {
|
||||
_actionFlow.emit(MainAction.NavigateToAuth)
|
||||
@@ -89,7 +85,7 @@ class MainViewModel(
|
||||
MainState.Data(
|
||||
userName = authRepo.getUserInfo()?.name ?: "",
|
||||
userPhotoUrl = authRepo.getUserInfo()?.photo,
|
||||
error = error.message ?: "data load error"
|
||||
error = error.message ?: "Ошибка загрузки данных"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user