forked from student-18211/NTO-2025-Android-TeamTask
Compare commits
2 Commits
to-book
...
47e9018b67
| Author | SHA1 | Date | |
|---|---|---|---|
| 47e9018b67 | |||
| abc0f81356 |
@@ -1,7 +1,7 @@
|
|||||||
package ru.myitschool.work.core
|
package ru.myitschool.work.core
|
||||||
|
|
||||||
object Constants {
|
object Constants {
|
||||||
const val HOST = "http://127.0.0.1:8080"
|
const val HOST = "http://10.0.2.2:8080"
|
||||||
const val AUTH_URL = "/auth"
|
const val AUTH_URL = "/auth"
|
||||||
const val INFO_URL = "/info"
|
const val INFO_URL = "/info"
|
||||||
const val BOOKING_URL = "/booking"
|
const val BOOKING_URL = "/booking"
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
package ru.myitschool.work.data.repo
|
|
||||||
|
|
||||||
import ru.myitschool.work.data.source.NetworkDataSource
|
|
||||||
import ru.myitschool.work.ui.screen.Booking
|
|
||||||
import ru.myitschool.work.ui.screen.UserInfo
|
|
||||||
|
|
||||||
object BookRepository {
|
|
||||||
suspend fun loadBooks(code: String): Result<List<Booking>> {
|
|
||||||
return NetworkDataSource.getFreeBooking(code)
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun sendData(code: String, booking: Booking) : Result<Boolean> {
|
|
||||||
return NetworkDataSource.createNewBooking(code, booking)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,23 +1,16 @@
|
|||||||
package ru.myitschool.work.data.source
|
package ru.myitschool.work.data.source
|
||||||
|
|
||||||
import io.ktor.client.HttpClient
|
import io.ktor.client.HttpClient
|
||||||
import io.ktor.client.call.body
|
|
||||||
import io.ktor.client.engine.cio.CIO
|
import io.ktor.client.engine.cio.CIO
|
||||||
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
|
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
|
||||||
import io.ktor.client.request.get
|
import io.ktor.client.request.get
|
||||||
import io.ktor.client.request.post
|
|
||||||
import io.ktor.client.statement.bodyAsText
|
import io.ktor.client.statement.bodyAsText
|
||||||
import io.ktor.http.ContentType
|
|
||||||
import io.ktor.http.HttpStatusCode
|
import io.ktor.http.HttpStatusCode
|
||||||
import io.ktor.http.contentType
|
|
||||||
import io.ktor.serialization.kotlinx.json.json
|
import io.ktor.serialization.kotlinx.json.json
|
||||||
import io.ktor.utils.io.InternalAPI
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import ru.myitschool.work.core.Constants
|
import ru.myitschool.work.core.Constants
|
||||||
import ru.myitschool.work.ui.screen.Booking
|
|
||||||
import ru.myitschool.work.ui.screen.UserInfo
|
|
||||||
|
|
||||||
object NetworkDataSource {
|
object NetworkDataSource {
|
||||||
private val client by lazy {
|
private val client by lazy {
|
||||||
@@ -38,40 +31,6 @@ object NetworkDataSource {
|
|||||||
suspend fun checkAuth(code: String): Result<Boolean> = withContext(Dispatchers.IO) {
|
suspend fun checkAuth(code: String): Result<Boolean> = withContext(Dispatchers.IO) {
|
||||||
return@withContext runCatching {
|
return@withContext runCatching {
|
||||||
val response = client.get(getUrl(code, Constants.AUTH_URL))
|
val response = client.get(getUrl(code, Constants.AUTH_URL))
|
||||||
when (response.status) {
|
|
||||||
HttpStatusCode.OK -> true
|
|
||||||
else -> error("Неверный код для авторизации")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun getInfo(code: String): Result<UserInfo> = withContext(Dispatchers.IO){
|
|
||||||
return@withContext runCatching {
|
|
||||||
val response = client.get(getUrl(code, Constants.INFO_URL))
|
|
||||||
when(response.status){
|
|
||||||
HttpStatusCode.OK -> response.body()
|
|
||||||
else -> error("Ошибка получения данных")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun getFreeBooking(code: String) : Result<List<Booking>> = withContext(Dispatchers.IO) {
|
|
||||||
return@withContext runCatching {
|
|
||||||
val response = client.get(getUrl(code, Constants.BOOKING_URL))
|
|
||||||
when (response.status) {
|
|
||||||
HttpStatusCode.OK -> response.body()
|
|
||||||
else -> error(response.bodyAsText())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@OptIn(InternalAPI::class)
|
|
||||||
suspend fun createNewBooking(code: String, booking: Booking) : Result<Boolean> = withContext(Dispatchers.IO) {
|
|
||||||
return@withContext runCatching {
|
|
||||||
val response = client.post(getUrl(code, Constants.BOOK_URL)) {
|
|
||||||
contentType(ContentType.Application.Json)
|
|
||||||
body = booking
|
|
||||||
}
|
|
||||||
when (response.status) {
|
when (response.status) {
|
||||||
HttpStatusCode.OK -> true
|
HttpStatusCode.OK -> true
|
||||||
else -> error(response.bodyAsText())
|
else -> error(response.bodyAsText())
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
package ru.myitschool.work.ui.screen
|
|
||||||
|
|
||||||
import kotlinx.serialization.Serializable
|
|
||||||
|
|
||||||
@Serializable
|
|
||||||
data class UserInfo(
|
|
||||||
val name: String,
|
|
||||||
val photo: String? = null,
|
|
||||||
val bookings: List<Booking>
|
|
||||||
)
|
|
||||||
|
|
||||||
@Serializable
|
|
||||||
data class Booking(
|
|
||||||
val date: String,
|
|
||||||
val place: String
|
|
||||||
)
|
|
||||||
@@ -7,7 +7,6 @@ import androidx.compose.material3.Text
|
|||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
|
||||||
import androidx.navigation.NavHostController
|
import androidx.navigation.NavHostController
|
||||||
import androidx.navigation.compose.NavHost
|
import androidx.navigation.compose.NavHost
|
||||||
import androidx.navigation.compose.composable
|
import androidx.navigation.compose.composable
|
||||||
@@ -16,8 +15,6 @@ import ru.myitschool.work.ui.nav.AuthScreenDestination
|
|||||||
import ru.myitschool.work.ui.nav.BookScreenDestination
|
import ru.myitschool.work.ui.nav.BookScreenDestination
|
||||||
import ru.myitschool.work.ui.nav.MainScreenDestination
|
import ru.myitschool.work.ui.nav.MainScreenDestination
|
||||||
import ru.myitschool.work.ui.screen.auth.AuthScreen
|
import ru.myitschool.work.ui.screen.auth.AuthScreen
|
||||||
import ru.myitschool.work.ui.screen.book.BookScreen
|
|
||||||
import ru.myitschool.work.ui.screen.book.BookViewModel
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun AppNavHost(
|
fun AppNavHost(
|
||||||
@@ -42,10 +39,11 @@ fun AppNavHost(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
composable<BookScreenDestination> {
|
composable<BookScreenDestination> {
|
||||||
BookScreen(
|
Box(
|
||||||
viewModel = BookViewModel(),
|
contentAlignment = Alignment.Center
|
||||||
navController = navController
|
) {
|
||||||
)
|
Text(text = "Hello")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
package ru.myitschool.work.ui.screen.book
|
|
||||||
|
|
||||||
import ru.myitschool.work.ui.screen.Booking
|
|
||||||
|
|
||||||
sealed interface BookIntent {
|
|
||||||
data class Send(val code : String, val booking: Booking) : BookIntent
|
|
||||||
data object BackToMainScreen : BookIntent
|
|
||||||
data object ToAuthScreen : BookIntent
|
|
||||||
data object LoadData : BookIntent
|
|
||||||
}
|
|
||||||
@@ -1,209 +0,0 @@
|
|||||||
package ru.myitschool.work.ui.screen.book;
|
|
||||||
|
|
||||||
import android.util.Log
|
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
|
||||||
import androidx.compose.foundation.layout.Column
|
|
||||||
import androidx.compose.foundation.layout.Row
|
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
|
||||||
import androidx.compose.foundation.layout.size
|
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
|
||||||
import androidx.compose.foundation.selection.selectableGroup
|
|
||||||
import androidx.compose.material3.Button
|
|
||||||
import androidx.compose.material3.CircularProgressIndicator
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
|
||||||
import androidx.compose.material3.NavigationBar
|
|
||||||
import androidx.compose.material3.NavigationBarItem
|
|
||||||
import androidx.compose.material3.RadioButton
|
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
|
||||||
import androidx.compose.runtime.MutableState
|
|
||||||
import androidx.compose.runtime.collectAsState
|
|
||||||
import androidx.compose.runtime.getValue
|
|
||||||
import androidx.compose.runtime.mutableStateOf
|
|
||||||
import androidx.compose.ui.Alignment
|
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.platform.testTag
|
|
||||||
import androidx.compose.ui.res.stringResource
|
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
|
||||||
import androidx.navigation.NavController
|
|
||||||
import ru.myitschool.work.R
|
|
||||||
import ru.myitschool.work.core.TestIds
|
|
||||||
import ru.myitschool.work.data.repo.AuthRepository
|
|
||||||
import ru.myitschool.work.ui.nav.AuthScreenDestination
|
|
||||||
import ru.myitschool.work.ui.nav.MainScreenDestination
|
|
||||||
import ru.myitschool.work.ui.screen.Booking
|
|
||||||
|
|
||||||
var selectedTime: MutableState<String?> = mutableStateOf(null)
|
|
||||||
var selectedBooking: MutableState<Booking?> = mutableStateOf(null)
|
|
||||||
var currentTime: MutableState<String?> = mutableStateOf(null)
|
|
||||||
@Composable
|
|
||||||
fun BookScreen(
|
|
||||||
viewModel: BookViewModel = viewModel(),
|
|
||||||
navController: NavController,
|
|
||||||
modifier: Modifier = Modifier
|
|
||||||
) {
|
|
||||||
val state by viewModel.uiState.collectAsState()
|
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
|
||||||
Log.d("BookScreen", "1")
|
|
||||||
viewModel.navigationFlow.collect {
|
|
||||||
// TODO настроить наконец это переход между экранами
|
|
||||||
// Log.d("BookScreen", "2")
|
|
||||||
when (it) {
|
|
||||||
BookNavigationEvent.NavigateToMain -> {
|
|
||||||
Log.d("BookScreen", "3")
|
|
||||||
navController.navigate(MainScreenDestination)
|
|
||||||
}
|
|
||||||
BookNavigationEvent.NavigateToAuth -> {
|
|
||||||
Log.d("BookScreen", "4")
|
|
||||||
navController.navigate(AuthScreenDestination) {
|
|
||||||
Log.d("BookScreen", "5")
|
|
||||||
popUpTo(navController.graph.startDestinationId) {
|
|
||||||
Log.d("BookScreen", "6")
|
|
||||||
inclusive = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Column(
|
|
||||||
modifier = modifier.fillMaxSize()
|
|
||||||
) {
|
|
||||||
// Text("" + selectedTime.value + "," + currentTime.value + "," + selectedBooking.value)
|
|
||||||
when (state) {
|
|
||||||
is BookState.Data -> {
|
|
||||||
val options = (state as BookState.Data).booking
|
|
||||||
if (currentTime.value == null)
|
|
||||||
for (el in options) {
|
|
||||||
currentTime.value = el.key
|
|
||||||
break
|
|
||||||
}
|
|
||||||
TabGroup(options.keys)
|
|
||||||
options[currentTime.value]?.let { SelectBooking(it) }
|
|
||||||
|
|
||||||
Button(
|
|
||||||
onClick = {
|
|
||||||
viewModel.onIntent(BookIntent.Send(AuthRepository.getSavedCode()!!, selectedBooking.value!!))
|
|
||||||
},
|
|
||||||
modifier = Modifier
|
|
||||||
.testTag(TestIds.Book.BOOK_BUTTON),
|
|
||||||
enabled = selectedBooking.value != null
|
|
||||||
) {
|
|
||||||
Text(stringResource(R.string.to_book))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
is BookState.Error -> {
|
|
||||||
Text(
|
|
||||||
text = (state as BookState.Error).error,
|
|
||||||
color = MaterialTheme.colorScheme.error,
|
|
||||||
modifier = Modifier
|
|
||||||
.testTag(TestIds.Book.ERROR)
|
|
||||||
)
|
|
||||||
|
|
||||||
Button(
|
|
||||||
onClick = {
|
|
||||||
viewModel.onIntent(BookIntent.LoadData)
|
|
||||||
},
|
|
||||||
modifier = Modifier
|
|
||||||
.testTag(TestIds.Book.REFRESH_BUTTON)
|
|
||||||
) {
|
|
||||||
Text(stringResource(R.string.upadate)) // А что сюда писать?
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
BookState.Loading -> {
|
|
||||||
CircularProgressIndicator(
|
|
||||||
modifier = Modifier
|
|
||||||
.align(Alignment.CenterHorizontally)
|
|
||||||
.size(64.dp)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
BookState.NotData -> {
|
|
||||||
Text(
|
|
||||||
text = stringResource(R.string.not_book),
|
|
||||||
modifier = Modifier
|
|
||||||
.testTag(TestIds.Book.EMPTY)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Button(
|
|
||||||
onClick = {
|
|
||||||
viewModel.onIntent(BookIntent.BackToMainScreen)
|
|
||||||
},
|
|
||||||
modifier = Modifier
|
|
||||||
.testTag(TestIds.Book.BACK_BUTTON)
|
|
||||||
) {
|
|
||||||
Text(stringResource(R.string.back))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun TabGroup(options: Set<String>) {
|
|
||||||
NavigationBar(
|
|
||||||
Modifier.fillMaxWidth()
|
|
||||||
) {
|
|
||||||
options.forEachIndexed { index, label ->
|
|
||||||
NavigationBarItem(
|
|
||||||
selected = currentTime.value == label,
|
|
||||||
onClick = {
|
|
||||||
currentTime.value = label
|
|
||||||
},
|
|
||||||
icon = {
|
|
||||||
Text(
|
|
||||||
text = label,
|
|
||||||
modifier = Modifier
|
|
||||||
.testTag(TestIds.Book.ITEM_DATE)
|
|
||||||
)
|
|
||||||
},
|
|
||||||
modifier = Modifier
|
|
||||||
.testTag(TestIds.Book.getIdDateItemByPosition(index))
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun SelectBooking(options: List<Booking>) {
|
|
||||||
LazyColumn(
|
|
||||||
Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
) {
|
|
||||||
options.forEachIndexed { index, book ->
|
|
||||||
item {
|
|
||||||
Row(
|
|
||||||
Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.selectableGroup()
|
|
||||||
.testTag(TestIds.Book.getIdPlaceItemByPosition(index)),
|
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
text = book.place,
|
|
||||||
modifier = Modifier
|
|
||||||
.testTag(TestIds.Book.ITEM_PLACE_TEXT)
|
|
||||||
)
|
|
||||||
RadioButton(
|
|
||||||
selected = book == selectedBooking.value && currentTime.value == selectedTime.value,
|
|
||||||
onClick = {
|
|
||||||
selectedBooking.value = book
|
|
||||||
selectedTime.value = currentTime.value
|
|
||||||
},
|
|
||||||
modifier = Modifier
|
|
||||||
.testTag(TestIds.Book.ITEM_PLACE_SELECTOR)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
package ru.myitschool.work.ui.screen.book
|
|
||||||
|
|
||||||
import ru.myitschool.work.ui.screen.Booking
|
|
||||||
|
|
||||||
sealed interface BookState {
|
|
||||||
object Loading: BookState
|
|
||||||
data class Data(
|
|
||||||
val booking : Map<String, List<Booking>> = mapOf()
|
|
||||||
): BookState
|
|
||||||
data class Error(
|
|
||||||
val error : String
|
|
||||||
): BookState
|
|
||||||
object NotData : BookState
|
|
||||||
}
|
|
||||||
@@ -1,125 +0,0 @@
|
|||||||
package ru.myitschool.work.ui.screen.book
|
|
||||||
|
|
||||||
import android.util.Log
|
|
||||||
import androidx.lifecycle.ViewModel
|
|
||||||
import androidx.lifecycle.viewModelScope
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
|
||||||
import kotlinx.coroutines.flow.SharedFlow
|
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
|
||||||
import kotlinx.coroutines.flow.update
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import ru.myitschool.work.data.repo.AuthRepository
|
|
||||||
import ru.myitschool.work.data.repo.BookRepository
|
|
||||||
import ru.myitschool.work.ui.screen.Booking
|
|
||||||
|
|
||||||
class BookViewModel : ViewModel() {
|
|
||||||
private val _uiState = MutableStateFlow<BookState>(BookState.Loading)
|
|
||||||
val uiState: StateFlow<BookState> = _uiState.asStateFlow();
|
|
||||||
|
|
||||||
private val _actionFlow: MutableSharedFlow<Unit> = MutableSharedFlow()
|
|
||||||
val actionFlow: SharedFlow<Unit> = _actionFlow
|
|
||||||
private val _navigationFlow = MutableSharedFlow<BookNavigationEvent>()
|
|
||||||
val navigationFlow: SharedFlow<BookNavigationEvent> = _navigationFlow
|
|
||||||
|
|
||||||
init {
|
|
||||||
loadData()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun loadData() {
|
|
||||||
_uiState.update { BookState.Loading }
|
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
|
||||||
val code = AuthRepository.getSavedCode() ?: run {
|
|
||||||
onIntent(BookIntent.ToAuthScreen)
|
|
||||||
Log.d("", "Go to AuthScreen")
|
|
||||||
return@launch
|
|
||||||
}
|
|
||||||
Log.d("", "Проверка")
|
|
||||||
// _uiState.update {
|
|
||||||
// BookState.Data(
|
|
||||||
// listOf(
|
|
||||||
// Booking(
|
|
||||||
// "19.04",
|
|
||||||
// "Рабочее место у окна"
|
|
||||||
// ),
|
|
||||||
// Booking(
|
|
||||||
// "19.04",
|
|
||||||
// "Переговорная комната № 1"
|
|
||||||
// ),
|
|
||||||
// Booking(
|
|
||||||
// "19.04",
|
|
||||||
// "Коворкинг А"
|
|
||||||
// ),
|
|
||||||
// Booking(
|
|
||||||
// "20.04",
|
|
||||||
// "Кабинет № 33"
|
|
||||||
// ),
|
|
||||||
// ).toMap()
|
|
||||||
// )
|
|
||||||
// }
|
|
||||||
BookRepository.loadBooks(code).fold(
|
|
||||||
onSuccess = {
|
|
||||||
it.let { bookings ->
|
|
||||||
_uiState.update {
|
|
||||||
when (bookings.isEmpty()) {
|
|
||||||
true -> BookState.Data(
|
|
||||||
booking = bookings.toMap()
|
|
||||||
)
|
|
||||||
false -> BookState.NotData
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onFailure = { error ->
|
|
||||||
_uiState.update {
|
|
||||||
BookState.Error(
|
|
||||||
error = error.message ?: "Не удалось загрузить данные"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun onIntent(intent: BookIntent) {
|
|
||||||
when (intent) {
|
|
||||||
is BookIntent.Send -> {
|
|
||||||
viewModelScope.launch(Dispatchers.Default) {
|
|
||||||
_uiState.update { BookState.Loading }
|
|
||||||
BookRepository.sendData(intent.code, intent.booking).fold(
|
|
||||||
onSuccess = {
|
|
||||||
_actionFlow.emit(Unit)
|
|
||||||
},
|
|
||||||
onFailure = { error ->
|
|
||||||
BookState.Error(error.message ?: "Неизвестная ошибка")
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
BookIntent.BackToMainScreen -> {
|
|
||||||
_navigationFlow.tryEmit(BookNavigationEvent.NavigateToMain)
|
|
||||||
}
|
|
||||||
BookIntent.LoadData -> loadData()
|
|
||||||
BookIntent.ToAuthScreen -> {
|
|
||||||
_navigationFlow.tryEmit(BookNavigationEvent.NavigateToAuth)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun List<Booking>.toMap() : Map<String, List<Booking>> {
|
|
||||||
val options = this
|
|
||||||
val map : MutableMap<String, MutableList<Booking>> = mutableMapOf()
|
|
||||||
options.forEach {
|
|
||||||
if (map[it.date] == null) map[it.date] = mutableListOf(it)
|
|
||||||
else map[it.date]?.add(it)
|
|
||||||
}
|
|
||||||
return map
|
|
||||||
}
|
|
||||||
|
|
||||||
sealed interface BookNavigationEvent {
|
|
||||||
object NavigateToAuth : BookNavigationEvent
|
|
||||||
object NavigateToMain : BookNavigationEvent
|
|
||||||
}
|
|
||||||
@@ -4,8 +4,4 @@
|
|||||||
<string name="auth_title">Привет! Введи код для авторизации</string>
|
<string name="auth_title">Привет! Введи код для авторизации</string>
|
||||||
<string name="auth_label">Код</string>
|
<string name="auth_label">Код</string>
|
||||||
<string name="auth_sign_in">Войти</string>
|
<string name="auth_sign_in">Войти</string>
|
||||||
<string name="to_book">забронировать</string>
|
|
||||||
<string name="back">Назад</string>
|
|
||||||
<string name="not_book">Всё забранировано</string>
|
|
||||||
<string name="upadate">Обновить</string>
|
|
||||||
</resources>
|
</resources>
|
||||||
Reference in New Issue
Block a user