Merge remote-tracking branch 'origin/Lab4' into Lab5

This commit is contained in:
Данила Мочалов 2023-12-19 14:08:16 +04:00
commit ad99fc9748
3 changed files with 11 additions and 7 deletions

View File

@ -14,6 +14,7 @@ import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import java.util.Calendar
import java.util.Date import java.util.Date
import javax.inject.Inject import javax.inject.Inject
@ -36,7 +37,10 @@ class HomeViewModel @Inject constructor(
val product = productRepository.getById(productId).first() val product = productRepository.getById(productId).first()
val order = orderRepository.getUnpaidByUser(userId.toInt()).first() val order = orderRepository.getUnpaidByUser(userId.toInt()).first()
if (order == null) { 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)) orderProductRepository.insert(OrderProductModel(newOrderId.toInt(), productId, 1, product.price))
} }
else { else {

View File

@ -6,7 +6,6 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.example.shawarma.data.models.OrderStatus import com.example.shawarma.data.models.OrderStatus
import com.example.shawarma.data.models.OrderWithProducts import com.example.shawarma.data.models.OrderWithProducts
import com.example.shawarma.data.repos.OrderProductRepository
import com.example.shawarma.data.repos.OrderRepository import com.example.shawarma.data.repos.OrderRepository
import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -14,8 +13,7 @@ import javax.inject.Inject
@HiltViewModel @HiltViewModel
class OrdersViewModel @Inject constructor( class OrdersViewModel @Inject constructor(
private val orderRepository: OrderRepository, private val orderRepository: OrderRepository
private val orderProductRepository: OrderProductRepository
) : ViewModel() { ) : ViewModel() {
private val _preparingOrders = MutableLiveData<List<OrderWithProducts>>() private val _preparingOrders = MutableLiveData<List<OrderWithProducts>>()
private val _preparedOrders = MutableLiveData<List<OrderWithProducts>>() private val _preparedOrders = MutableLiveData<List<OrderWithProducts>>()

View File

@ -52,8 +52,8 @@ class UserViewModel @Inject constructor(
_authorizationState.postValue(null) _authorizationState.postValue(null)
} }
private val _registrationState = MutableLiveData<Boolean?>() private val _registrationState = MutableLiveData<Boolean>()
val registrationState: LiveData<Boolean?> val registrationState: LiveData<Boolean>
get() = _registrationState get() = _registrationState
fun register(login: String, password: String, passwordRepeat: String) { fun register(login: String, password: String, passwordRepeat: String) {
@ -84,12 +84,14 @@ class UserViewModel @Inject constructor(
} }
} }
else { else {
if (registrationState.value != true) {
_registrationState.postValue(false) _registrationState.postValue(false)
} }
} }
} }
} }
} }
}
fun calmRegistrationState() { fun calmRegistrationState() {
_registrationState.postValue(null) _registrationState.postValue(null)