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 2336ca0..095580a 100644 --- a/app/src/main/java/com/example/shawarma/viewmodels/UserViewModel.kt +++ b/app/src/main/java/com/example/shawarma/viewmodels/UserViewModel.kt @@ -52,8 +52,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) { @@ -84,7 +84,9 @@ class UserViewModel @Inject constructor( } } else { - _registrationState.postValue(false) + if (registrationState.value != true) { + _registrationState.postValue(false) + } } } }