Какой-то минорный фикс даты

This commit is contained in:
Данила Мочалов 2023-12-17 23:19:04 +04:00
parent dc290f19d3
commit dc487aae56
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.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 {

View File

@ -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<List<OrderWithProducts>>()
private val _preparedOrders = MutableLiveData<List<OrderWithProducts>>()

View File

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