From dc487aae5662627ff21bb609a8daea3feff7d939 Mon Sep 17 00:00:00 2001 From: Danya_Mochalov Date: Sun, 17 Dec 2023 23:19:04 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9A=D0=B0=D0=BA=D0=BE=D0=B9-=D1=82=D0=BE=20?= =?UTF-8?q?=D0=BC=D0=B8=D0=BD=D0=BE=D1=80=D0=BD=D1=8B=D0=B9=20=D1=84=D0=B8?= =?UTF-8?q?=D0=BA=D1=81=20=D0=B4=D0=B0=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/example/shawarma/viewmodels/HomeViewModel.kt | 6 +++++- .../com/example/shawarma/viewmodels/OrdersViewModel.kt | 4 +--- .../java/com/example/shawarma/viewmodels/UserViewModel.kt | 8 +++++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/example/shawarma/viewmodels/HomeViewModel.kt b/app/src/main/java/com/example/shawarma/viewmodels/HomeViewModel.kt index 0eeff4a..a648f31 100644 --- a/app/src/main/java/com/example/shawarma/viewmodels/HomeViewModel.kt +++ b/app/src/main/java/com/example/shawarma/viewmodels/HomeViewModel.kt @@ -14,6 +14,7 @@ import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.first import kotlinx.coroutines.launch +import java.util.Calendar import java.util.Date import javax.inject.Inject @@ -36,7 +37,10 @@ class HomeViewModel @Inject constructor( val product = productRepository.getById(productId).first() val order = orderRepository.getUnpaidByUser(userId.toInt()).first() if (order == null) { - val newOrderId = orderRepository.insert(OrderModel(null, OrderStatus.Неоплачено.name, userId.toInt(), Date())) + val calendar: Calendar = Calendar.getInstance() + calendar.time = Date() + calendar.add(Calendar.HOUR_OF_DAY, 4) + val newOrderId = orderRepository.insert(OrderModel(null, OrderStatus.Неоплачено.name, userId.toInt(),calendar.time)) orderProductRepository.insert(OrderProductModel(newOrderId.toInt(), productId, 1, product.price)) } else { diff --git a/app/src/main/java/com/example/shawarma/viewmodels/OrdersViewModel.kt b/app/src/main/java/com/example/shawarma/viewmodels/OrdersViewModel.kt index 9f574a6..5a54287 100644 --- a/app/src/main/java/com/example/shawarma/viewmodels/OrdersViewModel.kt +++ b/app/src/main/java/com/example/shawarma/viewmodels/OrdersViewModel.kt @@ -6,7 +6,6 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.example.shawarma.data.models.OrderStatus import com.example.shawarma.data.models.OrderWithProducts -import com.example.shawarma.data.repos.OrderProductRepository import com.example.shawarma.data.repos.OrderRepository import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.launch @@ -14,8 +13,7 @@ import javax.inject.Inject @HiltViewModel class OrdersViewModel @Inject constructor( - private val orderRepository: OrderRepository, - private val orderProductRepository: OrderProductRepository + private val orderRepository: OrderRepository ) : ViewModel() { private val _preparingOrders = MutableLiveData>() private val _preparedOrders = MutableLiveData>() diff --git a/app/src/main/java/com/example/shawarma/viewmodels/UserViewModel.kt b/app/src/main/java/com/example/shawarma/viewmodels/UserViewModel.kt index 0eafd52..31d55c6 100644 --- a/app/src/main/java/com/example/shawarma/viewmodels/UserViewModel.kt +++ b/app/src/main/java/com/example/shawarma/viewmodels/UserViewModel.kt @@ -44,8 +44,8 @@ class UserViewModel @Inject constructor( _authorizationState.postValue(null) } - private val _registrationState = MutableLiveData() - val registrationState: LiveData + private val _registrationState = MutableLiveData() + val registrationState: LiveData get() = _registrationState fun register(login: String, password: String, passwordRepeat: String) { @@ -76,7 +76,9 @@ class UserViewModel @Inject constructor( } } else { - _registrationState.postValue(false) + if (registrationState.value != true) { + _registrationState.postValue(false) + } } } }