Compare commits
No commits in common. "761d76d4aacc07a2276fa6f678c6aab9a378202f" and "57d4d6b0c8dbf77e242320357839af64f14d42bf" have entirely different histories.
761d76d4aa
...
57d4d6b0c8
@ -1,8 +1,6 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id 'com.android.application'
|
id 'com.android.application'
|
||||||
id 'org.jetbrains.kotlin.android'
|
id 'org.jetbrains.kotlin.android'
|
||||||
//lab 3
|
|
||||||
id 'kotlin-kapt'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
@ -20,10 +18,6 @@ android {
|
|||||||
vectorDrawables {
|
vectorDrawables {
|
||||||
useSupportLibrary true
|
useSupportLibrary true
|
||||||
}
|
}
|
||||||
|
|
||||||
kapt {
|
|
||||||
arguments {arg("room.schemaLocation", "$projectDir/schemas")}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
@ -68,9 +62,4 @@ dependencies {
|
|||||||
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_ui_version"
|
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_ui_version"
|
||||||
debugImplementation "androidx.compose.ui:ui-tooling:$compose_ui_version"
|
debugImplementation "androidx.compose.ui:ui-tooling:$compose_ui_version"
|
||||||
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_ui_version"
|
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_ui_version"
|
||||||
|
|
||||||
// lab 3
|
|
||||||
implementation 'androidx.room:room-runtime:2.5.0' // Библиотека "Room"
|
|
||||||
kapt "androidx.room:room-compiler:2.5.0" // Кодогенератор
|
|
||||||
implementation 'androidx.room:room-ktx:2.5.0' // Дополнительно для Kotlin Coroutines, Kotlin Flows
|
|
||||||
}
|
}
|
@ -1,30 +0,0 @@
|
|||||||
package com.example.shawarma.data.dao
|
|
||||||
|
|
||||||
import androidx.room.Dao
|
|
||||||
import androidx.room.Delete
|
|
||||||
import androidx.room.Insert
|
|
||||||
import androidx.room.Query
|
|
||||||
import androidx.room.Update
|
|
||||||
import com.example.shawarma.data.models.OrderModel
|
|
||||||
import com.example.shawarma.data.models.OrderWithProducts
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
|
||||||
|
|
||||||
@Dao
|
|
||||||
interface OrderDao {
|
|
||||||
@Insert
|
|
||||||
suspend fun insert(order: OrderModel)
|
|
||||||
|
|
||||||
@Update
|
|
||||||
suspend fun update(order: OrderModel)
|
|
||||||
|
|
||||||
@Delete
|
|
||||||
suspend fun delete(order: OrderModel)
|
|
||||||
|
|
||||||
@Query("select * from orders where orders.user_id is not null")
|
|
||||||
fun getAll() : Flow<List<OrderWithProducts>>
|
|
||||||
@Query("select * from orders where orders.id =:id")
|
|
||||||
fun getById(id: Int): Flow<List<OrderWithProducts>>
|
|
||||||
@Query("select * from orders where orders.user_id =:userId")
|
|
||||||
fun getByUserId(userId: Int): Flow<List<OrderWithProducts>>
|
|
||||||
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
package com.example.shawarma.data.dao
|
|
||||||
|
|
||||||
import androidx.room.Dao
|
|
||||||
import androidx.room.Insert
|
|
||||||
import com.example.shawarma.data.models.OrderProductModel
|
|
||||||
|
|
||||||
@Dao
|
|
||||||
interface OrderProductDao {
|
|
||||||
@Insert
|
|
||||||
suspend fun insert(order: OrderProductModel)
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
package com.example.shawarma.data.dao
|
|
||||||
|
|
||||||
import androidx.room.Dao
|
|
||||||
import androidx.room.Delete
|
|
||||||
import androidx.room.Insert
|
|
||||||
import androidx.room.Query
|
|
||||||
import androidx.room.Update
|
|
||||||
import com.example.shawarma.data.models.ProductModel
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
|
||||||
|
|
||||||
@Dao
|
|
||||||
interface ProductDao {
|
|
||||||
@Insert
|
|
||||||
suspend fun insert(product: ProductModel)
|
|
||||||
|
|
||||||
@Update
|
|
||||||
suspend fun update(product: ProductModel)
|
|
||||||
|
|
||||||
@Delete
|
|
||||||
suspend fun delete(product: ProductModel)
|
|
||||||
|
|
||||||
@Query("select * from products where products.product_old_price is null")
|
|
||||||
fun getAll() : Flow<List<ProductModel>>
|
|
||||||
|
|
||||||
@Query("select * from products where products.product_old_price is not null")
|
|
||||||
fun getDiscounts() : Flow<List<ProductModel>>
|
|
||||||
|
|
||||||
@Query("select * from products where products.id = :id")
|
|
||||||
fun getById(id: Int): ProductModel
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
package com.example.shawarma.data.dao
|
|
||||||
|
|
||||||
import androidx.room.Dao
|
|
||||||
import androidx.room.Delete
|
|
||||||
import androidx.room.Insert
|
|
||||||
import androidx.room.Query
|
|
||||||
import androidx.room.Update
|
|
||||||
import com.example.shawarma.data.models.UserModel
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
|
||||||
|
|
||||||
@Dao
|
|
||||||
interface UserDao {
|
|
||||||
@Insert
|
|
||||||
suspend fun insert(user: UserModel)
|
|
||||||
|
|
||||||
@Update
|
|
||||||
suspend fun update(user: UserModel)
|
|
||||||
|
|
||||||
@Delete
|
|
||||||
suspend fun delete(user: UserModel)
|
|
||||||
|
|
||||||
@Query("select * from users order by user_login collate nocase asc")
|
|
||||||
fun getAll() : Flow<List<UserModel>>
|
|
||||||
|
|
||||||
@Query("select * from users where users.id = :id")
|
|
||||||
fun getById(id: Int): UserModel
|
|
||||||
}
|
|
@ -1,107 +0,0 @@
|
|||||||
package com.example.shawarma.data.db
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import androidx.room.Database
|
|
||||||
import androidx.room.Room
|
|
||||||
import androidx.room.RoomDatabase
|
|
||||||
import androidx.room.TypeConverters
|
|
||||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
|
||||||
import com.example.shawarma.data.dao.OrderDao
|
|
||||||
import com.example.shawarma.data.dao.OrderProductDao
|
|
||||||
import com.example.shawarma.data.dao.ProductDao
|
|
||||||
import com.example.shawarma.data.dao.UserDao
|
|
||||||
import com.example.shawarma.data.models.OrderModel
|
|
||||||
import com.example.shawarma.data.models.OrderProductModel
|
|
||||||
import com.example.shawarma.data.models.OrderStatus
|
|
||||||
import com.example.shawarma.data.models.ProductModel
|
|
||||||
import com.example.shawarma.data.models.UserModel
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import java.util.Date
|
|
||||||
|
|
||||||
@Database(
|
|
||||||
entities =
|
|
||||||
[
|
|
||||||
UserModel::class,
|
|
||||||
OrderModel::class,
|
|
||||||
ProductModel::class,
|
|
||||||
OrderProductModel::class,
|
|
||||||
],
|
|
||||||
version = 1,
|
|
||||||
exportSchema = false
|
|
||||||
)
|
|
||||||
@TypeConverters(Converter::class)
|
|
||||||
abstract class AppDatabase : RoomDatabase() {
|
|
||||||
abstract fun userDao() : UserDao
|
|
||||||
abstract fun productDao() : ProductDao
|
|
||||||
abstract fun orderDao() : OrderDao
|
|
||||||
abstract fun orderProductDao() : OrderProductDao
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
private const val DB_NAME: String = "shawarma-db"
|
|
||||||
|
|
||||||
@Volatile
|
|
||||||
private var INSTANCE: AppDatabase? = null
|
|
||||||
|
|
||||||
private suspend fun populateDatabase() {
|
|
||||||
INSTANCE?.let { database ->
|
|
||||||
// Users
|
|
||||||
val userDao = database.userDao()
|
|
||||||
val user1 = UserModel(1, "danya", "password", "ADMIN")
|
|
||||||
userDao.insert(user1)
|
|
||||||
// Products
|
|
||||||
val productDao = database.productDao()
|
|
||||||
val product1 = ProductModel(1, "Классик", 100, null)
|
|
||||||
val product2 = ProductModel(2, "Сырная", 120, null)
|
|
||||||
val discount1 = ProductModel(3, "Выгода", 80, 100)
|
|
||||||
val discount2 = ProductModel(4, "Кола", 50, 75)
|
|
||||||
productDao.insert(product1)
|
|
||||||
productDao.insert(product2)
|
|
||||||
productDao.insert(discount1)
|
|
||||||
productDao.insert(discount2)
|
|
||||||
// Orders
|
|
||||||
val orderDao = database.orderDao()
|
|
||||||
val order1 = OrderModel(1, OrderStatus.Готовится.toString(), 1, Date())
|
|
||||||
val order2 = OrderModel(2, OrderStatus.Неоплачено.toString(), 1, Date())
|
|
||||||
val order3 = OrderModel(3, OrderStatus.Готово.toString(), 1, Date())
|
|
||||||
val order4 = OrderModel(4, OrderStatus.Выдано.toString(), 1, Date())
|
|
||||||
orderDao.insert(order1)
|
|
||||||
orderDao.insert(order2)
|
|
||||||
orderDao.insert(order3)
|
|
||||||
orderDao.insert(order4)
|
|
||||||
// OrderProducts
|
|
||||||
val orderProductDao = database.orderProductDao()
|
|
||||||
val op1 = OrderProductModel(1, 1, 2, 200)
|
|
||||||
val op2 = OrderProductModel(2, 4, 3, 150)
|
|
||||||
val op3 = OrderProductModel(3, 3, 1, 80)
|
|
||||||
val op4 = OrderProductModel(4, 2, 1, 120)
|
|
||||||
orderProductDao.insert(op1)
|
|
||||||
orderProductDao.insert(op2)
|
|
||||||
orderProductDao.insert(op3)
|
|
||||||
orderProductDao.insert(op4)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getInstance(appContext: Context): AppDatabase {
|
|
||||||
return INSTANCE ?: synchronized(this) {
|
|
||||||
Room.databaseBuilder(
|
|
||||||
appContext,
|
|
||||||
AppDatabase::class.java,
|
|
||||||
DB_NAME
|
|
||||||
)
|
|
||||||
.addCallback(object : Callback() {
|
|
||||||
override fun onCreate(db: SupportSQLiteDatabase) {
|
|
||||||
super.onCreate(db)
|
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
|
||||||
populateDatabase()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.build()
|
|
||||||
.also { INSTANCE = it }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
package com.example.shawarma.data.db
|
|
||||||
|
|
||||||
import androidx.room.TypeConverter
|
|
||||||
import java.util.Date
|
|
||||||
|
|
||||||
class Converter {
|
|
||||||
@TypeConverter
|
|
||||||
fun fromTimestamp(value: Long?): Date? {
|
|
||||||
return value?.let { Date(it) }
|
|
||||||
}
|
|
||||||
|
|
||||||
@TypeConverter
|
|
||||||
fun dateToTimestamp(date: Date?): Long? {
|
|
||||||
return date?.time?.toLong()
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,39 +0,0 @@
|
|||||||
package com.example.shawarma.data.models
|
|
||||||
|
|
||||||
import androidx.room.ColumnInfo
|
|
||||||
import androidx.room.Entity
|
|
||||||
import androidx.room.ForeignKey
|
|
||||||
import androidx.room.PrimaryKey
|
|
||||||
import java.util.Date
|
|
||||||
|
|
||||||
@Entity(
|
|
||||||
tableName = "orders",
|
|
||||||
foreignKeys = [
|
|
||||||
ForeignKey(
|
|
||||||
entity = UserModel::class,
|
|
||||||
parentColumns = ["id"],
|
|
||||||
childColumns = ["user_id"],
|
|
||||||
)
|
|
||||||
]
|
|
||||||
)
|
|
||||||
data class OrderModel(
|
|
||||||
@PrimaryKey(autoGenerate = true)
|
|
||||||
@ColumnInfo(name = "id")
|
|
||||||
val id: Int?,
|
|
||||||
@ColumnInfo(name = "order_status")
|
|
||||||
val status: String,
|
|
||||||
@ColumnInfo(name = "user_id", index = true)
|
|
||||||
val userId: Int?,
|
|
||||||
@ColumnInfo(name = "date")
|
|
||||||
val date: Date
|
|
||||||
)
|
|
||||||
|
|
||||||
fun getOrdersByUserId() : List<OrderModel> {
|
|
||||||
return listOf(
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getAllOrders() : List<OrderModel> {
|
|
||||||
return listOf(
|
|
||||||
)
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
package com.example.shawarma.data.models
|
|
||||||
|
|
||||||
import androidx.room.ColumnInfo
|
|
||||||
import androidx.room.Entity
|
|
||||||
|
|
||||||
@Entity(tableName = "order_product", primaryKeys = ["order_id", "product_id"])
|
|
||||||
data class OrderProductModel(
|
|
||||||
@ColumnInfo(name = "order_id", index = true)
|
|
||||||
var orderId: Int,
|
|
||||||
@ColumnInfo(name = "product_id", index = true)
|
|
||||||
var productId: Int,
|
|
||||||
@ColumnInfo(name = "quantity")
|
|
||||||
val quantity: Int,
|
|
||||||
@ColumnInfo(name = "total_price")
|
|
||||||
val totalPrice: Int
|
|
||||||
)
|
|
@ -1,11 +0,0 @@
|
|||||||
package com.example.shawarma.data.models
|
|
||||||
|
|
||||||
import androidx.room.Embedded
|
|
||||||
import androidx.room.Relation
|
|
||||||
|
|
||||||
data class OrderProductModelWithProduct(
|
|
||||||
@Embedded
|
|
||||||
val orderProductModel: OrderProductModel,
|
|
||||||
@Relation(entity = ProductModel::class, parentColumn = "product_id", entityColumn = "id")
|
|
||||||
val productList: List<ProductModel>
|
|
||||||
)
|
|
@ -1,11 +0,0 @@
|
|||||||
package com.example.shawarma.data.models
|
|
||||||
|
|
||||||
import androidx.room.Embedded
|
|
||||||
import androidx.room.Relation
|
|
||||||
|
|
||||||
data class OrderWithProducts(
|
|
||||||
@Embedded
|
|
||||||
val order: OrderModel,
|
|
||||||
@Relation(entity = OrderProductModel::class, parentColumn = "id", entityColumn = "order_id")
|
|
||||||
val orderWithProducts: List<OrderProductModelWithProduct>
|
|
||||||
)
|
|
@ -1,36 +0,0 @@
|
|||||||
package com.example.shawarma.data.models
|
|
||||||
|
|
||||||
import androidx.room.ColumnInfo
|
|
||||||
import androidx.room.Entity
|
|
||||||
import androidx.room.PrimaryKey
|
|
||||||
|
|
||||||
@Entity(tableName = "products")
|
|
||||||
data class ProductModel(
|
|
||||||
@PrimaryKey(autoGenerate = true)
|
|
||||||
@ColumnInfo(name = "id")
|
|
||||||
val id: Int?,
|
|
||||||
@ColumnInfo(name = "product_title")
|
|
||||||
val title: String,
|
|
||||||
@ColumnInfo(name = "product_price")
|
|
||||||
val price: Int,
|
|
||||||
@ColumnInfo(name = "product_old_price")
|
|
||||||
val oldPrice: Int?,
|
|
||||||
) {
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
if (this === other) return true
|
|
||||||
if (javaClass != other?.javaClass) return false
|
|
||||||
other as ProductModel
|
|
||||||
if (id != other.id) return false
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
|
||||||
return id ?: -1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getProducts() :List<ProductModel> {
|
|
||||||
return listOf(
|
|
||||||
)
|
|
||||||
|
|
||||||
}
|
|
@ -1,5 +0,0 @@
|
|||||||
package com.example.shawarma.data.models
|
|
||||||
|
|
||||||
enum class OrderStatus {
|
|
||||||
Неоплачено, Готовится, Готово, Выдано
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
package com.example.shawarma.data.models
|
|
||||||
|
|
||||||
import androidx.room.ColumnInfo
|
|
||||||
import androidx.room.Entity
|
|
||||||
import androidx.room.PrimaryKey
|
|
||||||
|
|
||||||
@Entity(tableName = "users")
|
|
||||||
data class UserModel(
|
|
||||||
@PrimaryKey(autoGenerate = true)
|
|
||||||
@ColumnInfo(name = "id")
|
|
||||||
val id: Int?,
|
|
||||||
@ColumnInfo(name = "user_login")
|
|
||||||
val login: String,
|
|
||||||
@ColumnInfo(name = "user_password")
|
|
||||||
val password: String,
|
|
||||||
@ColumnInfo(name = "user_role")
|
|
||||||
val role: String
|
|
||||||
) {
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
if (this === other) return true
|
|
||||||
if (javaClass != other?.javaClass) return false
|
|
||||||
other as UserModel
|
|
||||||
if (id != other.id) return false
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
|
||||||
return id ?: -1
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,15 @@
|
|||||||
|
package com.example.shawarma.models
|
||||||
|
|
||||||
|
data class DiscountProductModel(
|
||||||
|
val id: Int,
|
||||||
|
val title: String,
|
||||||
|
val oldPrice: Int,
|
||||||
|
val newPrice: Int
|
||||||
|
)
|
||||||
|
|
||||||
|
fun getAllDiscountProducts() : List<DiscountProductModel> {
|
||||||
|
return listOf(
|
||||||
|
DiscountProductModel(1, "Шаурма", 150, 120),
|
||||||
|
DiscountProductModel(1, "Шаурма", 150, 120)
|
||||||
|
)
|
||||||
|
}
|
34
app/src/main/java/com/example/shawarma/models/OrderModel.kt
Normal file
34
app/src/main/java/com/example/shawarma/models/OrderModel.kt
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
package com.example.shawarma.models
|
||||||
|
|
||||||
|
import java.util.Date
|
||||||
|
|
||||||
|
|
||||||
|
data class OrderModel(
|
||||||
|
val id: Int,
|
||||||
|
val status: OrderStatus,
|
||||||
|
val productsId: HashMap<Int, Int>,
|
||||||
|
val userId: Int,
|
||||||
|
val date: Date
|
||||||
|
)
|
||||||
|
|
||||||
|
fun getOrdersByUserId() : List<OrderModel> {
|
||||||
|
val map1 = HashMap<Int, Int>()
|
||||||
|
map1[1] = 2
|
||||||
|
|
||||||
|
val map2 = HashMap<Int, Int>()
|
||||||
|
map2[1] = 2
|
||||||
|
return listOf(
|
||||||
|
OrderModel(1, OrderStatus.Unpaid, map1, 1, Date()),
|
||||||
|
OrderModel(2, OrderStatus.Preparing, map2 , 1, Date())
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getAllOrders() : List<OrderModel> {
|
||||||
|
val map1 = HashMap<Int, Int>()
|
||||||
|
map1[1] = 2
|
||||||
|
return listOf(
|
||||||
|
OrderModel(1, OrderStatus.Prepared, map1, 1, Date()),
|
||||||
|
OrderModel(2, OrderStatus.Preparing, map1 , 1, Date()),
|
||||||
|
OrderModel(3, OrderStatus.Processed, map1 , 1, Date())
|
||||||
|
)
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package com.example.shawarma.models
|
||||||
|
|
||||||
|
data class ProductModel(
|
||||||
|
val id: Int,
|
||||||
|
val title: String,
|
||||||
|
val price: Int
|
||||||
|
)
|
||||||
|
|
||||||
|
fun getProducts() :List<ProductModel> {
|
||||||
|
return listOf(
|
||||||
|
ProductModel(1, "Классика", 150),
|
||||||
|
ProductModel(1, "Классика", 150),
|
||||||
|
ProductModel(1, "Классика", 150),
|
||||||
|
ProductModel(1, "Классика", 150),
|
||||||
|
ProductModel(1, "Классика", 150),
|
||||||
|
ProductModel(1, "Классика", 150),
|
||||||
|
)
|
||||||
|
|
||||||
|
}
|
5
app/src/main/java/com/example/shawarma/models/Status.kt
Normal file
5
app/src/main/java/com/example/shawarma/models/Status.kt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package com.example.shawarma.models
|
||||||
|
|
||||||
|
enum class OrderStatus {
|
||||||
|
Unpaid, Preparing, Prepared, Processed
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
package com.example.shawarma.models
|
||||||
|
|
||||||
|
data class UserModel(
|
||||||
|
val id: Int,
|
||||||
|
val login: String,
|
||||||
|
val password: String,
|
||||||
|
val role: String
|
||||||
|
)
|
@ -2,11 +2,14 @@ package com.example.shawarma.screens.cart
|
|||||||
|
|
||||||
import androidx.compose.foundation.BorderStroke
|
import androidx.compose.foundation.BorderStroke
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.gestures.Orientation
|
||||||
|
import androidx.compose.foundation.gestures.scrollable
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.fillMaxHeight
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
@ -23,31 +26,27 @@ import androidx.compose.material.Card
|
|||||||
import androidx.compose.material.Icon
|
import androidx.compose.material.Icon
|
||||||
import androidx.compose.material.Text
|
import androidx.compose.material.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
|
||||||
import androidx.compose.runtime.mutableStateListOf
|
|
||||||
import androidx.compose.runtime.remember
|
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.platform.LocalContext
|
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
|
import androidx.compose.ui.text.font.Font
|
||||||
|
import androidx.compose.ui.text.font.FontFamily
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import androidx.compose.ui.zIndex
|
import androidx.compose.ui.zIndex
|
||||||
import com.example.shawarma.R
|
import com.example.shawarma.R
|
||||||
import com.example.shawarma.data.db.AppDatabase
|
import com.example.shawarma.models.OrderModel
|
||||||
import com.example.shawarma.data.models.OrderStatus
|
import com.example.shawarma.models.OrderStatus
|
||||||
import com.example.shawarma.data.models.OrderWithProducts
|
import com.example.shawarma.models.getOrdersByUserId
|
||||||
import com.example.shawarma.ui.theme.MarckFamily
|
import com.example.shawarma.ui.theme.MarckFamily
|
||||||
import com.example.shawarma.ui.theme.MyLightRed
|
import com.example.shawarma.ui.theme.MyLightRed
|
||||||
import com.example.shawarma.ui.theme.MyMainBackground
|
import com.example.shawarma.ui.theme.MyMainBackground
|
||||||
import com.example.shawarma.ui.theme.MyOrange
|
import com.example.shawarma.ui.theme.MyOrange
|
||||||
import com.example.shawarma.ui.theme.NunitoFamily
|
import com.example.shawarma.ui.theme.NunitoFamily
|
||||||
import com.example.shawarma.widgets.ShawarmaLogo2
|
import com.example.shawarma.widgets.ShawarmaLogo2
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.withContext
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun CartScreen() {
|
fun CartScreen() {
|
||||||
@ -62,25 +61,15 @@ fun CartScreen() {
|
|||||||
@Composable
|
@Composable
|
||||||
fun CartWidget(){
|
fun CartWidget(){
|
||||||
|
|
||||||
val context = LocalContext.current
|
val orders = getOrdersByUserId()
|
||||||
val orders = remember { mutableStateListOf<OrderWithProducts>() }
|
val unpaidOrders = mutableListOf<OrderModel>()
|
||||||
LaunchedEffect(Unit) {
|
val preparingOrders = mutableListOf<OrderModel>()
|
||||||
withContext(Dispatchers.IO) {
|
|
||||||
AppDatabase.getInstance(context).orderDao().getByUserId(1).collect { data ->
|
|
||||||
orders.clear()
|
|
||||||
orders.addAll(data)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val unpaidOrders = mutableListOf<OrderWithProducts>()
|
|
||||||
val preparingOrders = mutableListOf<OrderWithProducts>()
|
|
||||||
|
|
||||||
for(order in orders) {
|
for(order in orders) {
|
||||||
if (order.order.status == OrderStatus.Неоплачено.toString()) {
|
if (order.status == OrderStatus.Unpaid) {
|
||||||
unpaidOrders.add(order)
|
unpaidOrders.add(order)
|
||||||
}
|
}
|
||||||
if (order.order.status == OrderStatus.Готовится.toString() || order.order.status == OrderStatus.Готово.toString()) {
|
if (order.status == OrderStatus.Preparing) {
|
||||||
preparingOrders.add(order)
|
preparingOrders.add(order)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -121,8 +110,8 @@ fun CartWidget(){
|
|||||||
.width(340.dp)
|
.width(340.dp)
|
||||||
.height(200.dp)
|
.height(200.dp)
|
||||||
) {
|
) {
|
||||||
items(preparingOrders.size) { index ->
|
items(preparingOrders.size * 2) {
|
||||||
PaidItem(preparingOrders[index])
|
PaidItem(preparingOrders[0])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Text(
|
Text(
|
||||||
@ -137,8 +126,8 @@ fun CartWidget(){
|
|||||||
.width(340.dp)
|
.width(340.dp)
|
||||||
.height(200.dp)
|
.height(200.dp)
|
||||||
) {
|
) {
|
||||||
items(unpaidOrders.size) {index ->
|
items(unpaidOrders.size * 2) {
|
||||||
CartItem(unpaidOrders[index])
|
PaidItem(unpaidOrders[0])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,7 +158,7 @@ fun CartWidget(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun PaidItem(order : OrderWithProducts) {
|
fun PaidItem(order : OrderModel) {
|
||||||
Card(
|
Card(
|
||||||
border = BorderStroke(width = 2.dp, color = MyOrange),
|
border = BorderStroke(width = 2.dp, color = MyOrange),
|
||||||
shape = RoundedCornerShape(size = 20.dp),
|
shape = RoundedCornerShape(size = 20.dp),
|
||||||
@ -184,21 +173,21 @@ fun PaidItem(order : OrderWithProducts) {
|
|||||||
.padding(horizontal = 20.dp)
|
.padding(horizontal = 20.dp)
|
||||||
){
|
){
|
||||||
Text(
|
Text(
|
||||||
text = order.orderWithProducts[0].productList[0].title,
|
text = "Классика",
|
||||||
fontFamily = NunitoFamily,
|
fontFamily = NunitoFamily,
|
||||||
fontSize = 20.sp,
|
fontSize = 20.sp,
|
||||||
modifier = Modifier.padding(top = 15.dp),
|
modifier = Modifier.padding(top = 15.dp),
|
||||||
fontWeight = FontWeight.Bold
|
fontWeight = FontWeight.Bold
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
text = "x" + order.orderWithProducts[0].orderProductModel.quantity,
|
text = "x" + order.productsId.values.first().toString(),
|
||||||
fontFamily = NunitoFamily,
|
fontFamily = NunitoFamily,
|
||||||
fontSize = 20.sp,
|
fontSize = 20.sp,
|
||||||
modifier = Modifier.padding(top = 15.dp),
|
modifier = Modifier.padding(top = 15.dp),
|
||||||
fontWeight = FontWeight.Bold
|
fontWeight = FontWeight.Bold
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
text = order.orderWithProducts[0].orderProductModel.totalPrice.toString() + " руб.",
|
text = "150 руб.",
|
||||||
fontFamily = NunitoFamily,
|
fontFamily = NunitoFamily,
|
||||||
fontSize = 20.sp,
|
fontSize = 20.sp,
|
||||||
modifier = Modifier.padding(top = 15.dp),
|
modifier = Modifier.padding(top = 15.dp),
|
||||||
@ -221,7 +210,7 @@ fun PaidItem(order : OrderWithProducts) {
|
|||||||
color = Color.Gray
|
color = Color.Gray
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
text = order.order.status,
|
text = "Готовится",
|
||||||
fontFamily = NunitoFamily,
|
fontFamily = NunitoFamily,
|
||||||
fontSize = 20.sp,
|
fontSize = 20.sp,
|
||||||
modifier = Modifier.padding(top = 15.dp),
|
modifier = Modifier.padding(top = 15.dp),
|
||||||
@ -235,7 +224,7 @@ fun PaidItem(order : OrderWithProducts) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun CartItem(order : OrderWithProducts) {
|
fun CartItem(order : OrderModel) {
|
||||||
Card(
|
Card(
|
||||||
border = BorderStroke(width = 2.dp, color = MyOrange),
|
border = BorderStroke(width = 2.dp, color = MyOrange),
|
||||||
shape = RoundedCornerShape(size = 20.dp),
|
shape = RoundedCornerShape(size = 20.dp),
|
||||||
@ -256,20 +245,20 @@ fun CartItem(order : OrderWithProducts) {
|
|||||||
modifier = Modifier.fillMaxWidth()
|
modifier = Modifier.fillMaxWidth()
|
||||||
){
|
){
|
||||||
Text(
|
Text(
|
||||||
text = order.orderWithProducts[0].productList[0].title,
|
text = "Классика",
|
||||||
fontFamily = NunitoFamily,
|
fontFamily = NunitoFamily,
|
||||||
fontSize = 20.sp,
|
fontSize = 20.sp,
|
||||||
fontWeight = FontWeight.Bold
|
fontWeight = FontWeight.Bold
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
text = "x" + order.orderWithProducts[0].orderProductModel.quantity,
|
text = "x" + order.productsId.values.first().toString(),
|
||||||
fontFamily = NunitoFamily,
|
fontFamily = NunitoFamily,
|
||||||
fontSize = 20.sp,
|
fontSize = 20.sp,
|
||||||
fontWeight = FontWeight.Bold
|
fontWeight = FontWeight.Bold
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Text(
|
Text(
|
||||||
text = order.orderWithProducts[0].orderProductModel.totalPrice.toString() + " руб.",
|
text = "150 руб.",
|
||||||
fontFamily = NunitoFamily,
|
fontFamily = NunitoFamily,
|
||||||
fontSize = 20.sp,
|
fontSize = 20.sp,
|
||||||
fontWeight = FontWeight.Bold
|
fontWeight = FontWeight.Bold
|
||||||
|
@ -20,14 +20,10 @@ import androidx.compose.material.ButtonDefaults
|
|||||||
import androidx.compose.material.Card
|
import androidx.compose.material.Card
|
||||||
import androidx.compose.material.Text
|
import androidx.compose.material.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
|
||||||
import androidx.compose.runtime.mutableStateListOf
|
|
||||||
import androidx.compose.runtime.remember
|
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.platform.LocalContext
|
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.text.style.TextDecoration
|
import androidx.compose.ui.text.style.TextDecoration
|
||||||
@ -35,10 +31,8 @@ import androidx.compose.ui.unit.dp
|
|||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import androidx.compose.ui.zIndex
|
import androidx.compose.ui.zIndex
|
||||||
import com.example.shawarma.R
|
import com.example.shawarma.R
|
||||||
import com.example.shawarma.data.db.AppDatabase
|
import com.example.shawarma.models.DiscountProductModel
|
||||||
import com.example.shawarma.data.models.DiscountProductModel
|
import com.example.shawarma.models.getAllDiscountProducts
|
||||||
import com.example.shawarma.data.models.ProductModel
|
|
||||||
import com.example.shawarma.data.models.getAllDiscountProducts
|
|
||||||
import com.example.shawarma.screens.home.HomeList
|
import com.example.shawarma.screens.home.HomeList
|
||||||
import com.example.shawarma.ui.theme.MarckFamily
|
import com.example.shawarma.ui.theme.MarckFamily
|
||||||
import com.example.shawarma.ui.theme.MyLightYellow
|
import com.example.shawarma.ui.theme.MyLightYellow
|
||||||
@ -47,8 +41,6 @@ import com.example.shawarma.ui.theme.MyOrange
|
|||||||
import com.example.shawarma.ui.theme.MyPriceBackground
|
import com.example.shawarma.ui.theme.MyPriceBackground
|
||||||
import com.example.shawarma.ui.theme.NunitoFamily
|
import com.example.shawarma.ui.theme.NunitoFamily
|
||||||
import com.example.shawarma.widgets.ShawarmaLogo2
|
import com.example.shawarma.widgets.ShawarmaLogo2
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.withContext
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun DiscountScreen() {
|
fun DiscountScreen() {
|
||||||
@ -64,16 +56,7 @@ fun DiscountScreen() {
|
|||||||
@Composable
|
@Composable
|
||||||
fun DiscountList(){
|
fun DiscountList(){
|
||||||
|
|
||||||
val context = LocalContext.current
|
val products = getAllDiscountProducts()
|
||||||
val products = remember { mutableStateListOf<ProductModel>() }
|
|
||||||
LaunchedEffect(Unit) {
|
|
||||||
withContext(Dispatchers.IO) {
|
|
||||||
AppDatabase.getInstance(context).productDao().getDiscounts().collect { data ->
|
|
||||||
products.clear()
|
|
||||||
products.addAll(data)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
@ -117,7 +100,7 @@ fun DiscountList(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun DiscountCard(product : ProductModel){
|
fun DiscountCard(product : DiscountProductModel){
|
||||||
Card(
|
Card(
|
||||||
shape = RoundedCornerShape(20.dp),
|
shape = RoundedCornerShape(20.dp),
|
||||||
backgroundColor = Color.White,
|
backgroundColor = Color.White,
|
||||||
@ -161,7 +144,7 @@ fun DiscountCard(product : ProductModel){
|
|||||||
textDecoration = TextDecoration.LineThrough
|
textDecoration = TextDecoration.LineThrough
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
text = product.price.toString() + "руб. ",
|
text = product.newPrice.toString() + "руб. ",
|
||||||
fontFamily = NunitoFamily,
|
fontFamily = NunitoFamily,
|
||||||
fontSize = 16.sp,
|
fontSize = 16.sp,
|
||||||
fontWeight = FontWeight.ExtraBold,
|
fontWeight = FontWeight.ExtraBold,
|
||||||
|
@ -21,23 +21,18 @@ import androidx.compose.material.ButtonDefaults
|
|||||||
import androidx.compose.material.Card
|
import androidx.compose.material.Card
|
||||||
import androidx.compose.material.Text
|
import androidx.compose.material.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
|
||||||
import androidx.compose.runtime.mutableStateListOf
|
|
||||||
import androidx.compose.runtime.remember
|
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.platform.LocalContext
|
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import androidx.compose.ui.zIndex
|
import androidx.compose.ui.zIndex
|
||||||
import com.example.shawarma.R
|
import com.example.shawarma.R
|
||||||
import com.example.shawarma.data.db.AppDatabase
|
import com.example.shawarma.models.ProductModel
|
||||||
import com.example.shawarma.data.models.ProductModel
|
import com.example.shawarma.models.getProducts
|
||||||
import com.example.shawarma.data.models.getProducts
|
|
||||||
import com.example.shawarma.ui.theme.MarckFamily
|
import com.example.shawarma.ui.theme.MarckFamily
|
||||||
import com.example.shawarma.ui.theme.MyLightYellow
|
import com.example.shawarma.ui.theme.MyLightYellow
|
||||||
import com.example.shawarma.ui.theme.MyMainBackground
|
import com.example.shawarma.ui.theme.MyMainBackground
|
||||||
@ -45,8 +40,6 @@ import com.example.shawarma.ui.theme.MyOrange
|
|||||||
import com.example.shawarma.ui.theme.MyPriceBackground
|
import com.example.shawarma.ui.theme.MyPriceBackground
|
||||||
import com.example.shawarma.ui.theme.NunitoFamily
|
import com.example.shawarma.ui.theme.NunitoFamily
|
||||||
import com.example.shawarma.widgets.ShawarmaLogo2
|
import com.example.shawarma.widgets.ShawarmaLogo2
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.withContext
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun HomeScreen() {
|
fun HomeScreen() {
|
||||||
@ -60,16 +53,8 @@ fun HomeScreen() {
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun HomeList(){
|
fun HomeList(){
|
||||||
val context = LocalContext.current
|
|
||||||
val products = remember { mutableStateListOf<ProductModel>() }
|
val products = getProducts()
|
||||||
LaunchedEffect(Unit) {
|
|
||||||
withContext(Dispatchers.IO) {
|
|
||||||
AppDatabase.getInstance(context).productDao().getAll().collect { data ->
|
|
||||||
products.clear()
|
|
||||||
products.addAll(data)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
|
@ -22,29 +22,23 @@ import androidx.compose.material.ButtonDefaults
|
|||||||
import androidx.compose.material.Card
|
import androidx.compose.material.Card
|
||||||
import androidx.compose.material.Text
|
import androidx.compose.material.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
|
||||||
import androidx.compose.runtime.mutableStateListOf
|
|
||||||
import androidx.compose.runtime.remember
|
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.platform.LocalContext
|
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import androidx.compose.ui.zIndex
|
import androidx.compose.ui.zIndex
|
||||||
import com.example.shawarma.data.db.AppDatabase
|
import com.example.shawarma.models.OrderModel
|
||||||
import com.example.shawarma.data.models.OrderStatus
|
import com.example.shawarma.models.OrderStatus
|
||||||
import com.example.shawarma.data.models.OrderWithProducts
|
import com.example.shawarma.models.getAllOrders
|
||||||
import com.example.shawarma.ui.theme.MarckFamily
|
import com.example.shawarma.ui.theme.MarckFamily
|
||||||
import com.example.shawarma.ui.theme.MyLightYellow
|
import com.example.shawarma.ui.theme.MyLightYellow
|
||||||
import com.example.shawarma.ui.theme.MyMainBackground
|
import com.example.shawarma.ui.theme.MyMainBackground
|
||||||
import com.example.shawarma.ui.theme.MyOrange
|
import com.example.shawarma.ui.theme.MyOrange
|
||||||
import com.example.shawarma.ui.theme.NunitoFamily
|
import com.example.shawarma.ui.theme.NunitoFamily
|
||||||
import com.example.shawarma.widgets.ShawarmaLogo2
|
import com.example.shawarma.widgets.ShawarmaLogo2
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.withContext
|
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@ -59,29 +53,20 @@ fun OrdersScreen() {
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun OrdersList(){
|
fun OrdersList(){
|
||||||
val context = LocalContext.current
|
|
||||||
val allOrders = remember { mutableStateListOf<OrderWithProducts>() }
|
|
||||||
LaunchedEffect(Unit) {
|
|
||||||
withContext(Dispatchers.IO) {
|
|
||||||
AppDatabase.getInstance(context).orderDao().getAll().collect { data ->
|
|
||||||
allOrders.clear()
|
|
||||||
allOrders.addAll(data)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val preparingOrders = mutableListOf<OrderWithProducts>()
|
val allOrders = getAllOrders()
|
||||||
val preparedOrders = mutableListOf<OrderWithProducts>()
|
val preparingOrders = mutableListOf<OrderModel>()
|
||||||
val processedOrders = mutableListOf<OrderWithProducts>()
|
val preparedOrders = mutableListOf<OrderModel>()
|
||||||
|
val processedOrders = mutableListOf<OrderModel>()
|
||||||
|
|
||||||
for (order in allOrders){
|
for (order in allOrders){
|
||||||
if (order.order.status == OrderStatus.Готовится.toString()) {
|
if (order.status == OrderStatus.Preparing) {
|
||||||
preparingOrders.add(order)
|
preparingOrders.add(order)
|
||||||
}
|
}
|
||||||
if (order.order.status == OrderStatus.Готово.toString()) {
|
if (order.status == OrderStatus.Prepared) {
|
||||||
preparedOrders.add(order)
|
preparedOrders.add(order)
|
||||||
}
|
}
|
||||||
if (order.order.status == OrderStatus.Выдано.toString()) {
|
if (order.status == OrderStatus.Processed) {
|
||||||
processedOrders.add(order)
|
processedOrders.add(order)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -123,11 +108,9 @@ fun OrdersList(){
|
|||||||
.width(340.dp)
|
.width(340.dp)
|
||||||
.height(250.dp)
|
.height(250.dp)
|
||||||
) {
|
) {
|
||||||
if (preparingOrders.size != 0) {
|
items(preparingOrders.size) {
|
||||||
items(preparingOrders.size) {
|
index ->
|
||||||
index ->
|
PreparingItem(preparedOrders[index])
|
||||||
PreparingItem(preparingOrders[index])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Text(
|
Text(
|
||||||
@ -142,11 +125,9 @@ fun OrdersList(){
|
|||||||
.width(340.dp)
|
.width(340.dp)
|
||||||
.height(250.dp)
|
.height(250.dp)
|
||||||
) {
|
) {
|
||||||
if (preparedOrders.size != 0) {
|
items(preparedOrders.size) {
|
||||||
items(preparedOrders.size) {
|
index ->
|
||||||
index ->
|
PreparedItem(preparedOrders[index])
|
||||||
PreparedItem(preparedOrders[index])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Text(
|
Text(
|
||||||
@ -161,10 +142,8 @@ fun OrdersList(){
|
|||||||
.width(340.dp)
|
.width(340.dp)
|
||||||
.height(250.dp)
|
.height(250.dp)
|
||||||
) {
|
) {
|
||||||
if (processedOrders.size != 0) {
|
items(2) {
|
||||||
items(processedOrders.size) {index ->
|
ProcessedItem()
|
||||||
ProcessedItem(processedOrders[index])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Spacer(modifier = Modifier.height(70.dp))
|
Spacer(modifier = Modifier.height(70.dp))
|
||||||
@ -175,7 +154,7 @@ fun OrdersList(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun PreparingItem(order : OrderWithProducts){
|
fun PreparingItem(order : OrderModel){
|
||||||
Card(
|
Card(
|
||||||
border = BorderStroke(width = 2.dp, color = MyOrange),
|
border = BorderStroke(width = 2.dp, color = MyOrange),
|
||||||
shape = RoundedCornerShape(size = 20.dp),
|
shape = RoundedCornerShape(size = 20.dp),
|
||||||
@ -192,7 +171,7 @@ fun PreparingItem(order : OrderWithProducts){
|
|||||||
modifier = Modifier.fillMaxWidth(0.5f)
|
modifier = Modifier.fillMaxWidth(0.5f)
|
||||||
){
|
){
|
||||||
val localDateFormat = SimpleDateFormat("HH:mm")
|
val localDateFormat = SimpleDateFormat("HH:mm")
|
||||||
val time = localDateFormat.format(order.order.date)
|
val time = localDateFormat.format(order.date)
|
||||||
Text(
|
Text(
|
||||||
text = time,
|
text = time,
|
||||||
fontFamily = NunitoFamily,
|
fontFamily = NunitoFamily,
|
||||||
@ -204,13 +183,13 @@ fun PreparingItem(order : OrderWithProducts){
|
|||||||
modifier = Modifier.fillMaxWidth()
|
modifier = Modifier.fillMaxWidth()
|
||||||
){
|
){
|
||||||
Text(
|
Text(
|
||||||
text = order.orderWithProducts[0].productList[0].title,
|
text = "Классика",
|
||||||
fontFamily = NunitoFamily,
|
fontFamily = NunitoFamily,
|
||||||
fontSize = 20.sp,
|
fontSize = 20.sp,
|
||||||
fontWeight = FontWeight.Bold
|
fontWeight = FontWeight.Bold
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
text = "x" + order.orderWithProducts[0].orderProductModel.quantity,
|
text = "x" + order.productsId.values.first().toString(),
|
||||||
fontFamily = NunitoFamily,
|
fontFamily = NunitoFamily,
|
||||||
fontSize = 20.sp,
|
fontSize = 20.sp,
|
||||||
fontWeight = FontWeight.Bold
|
fontWeight = FontWeight.Bold
|
||||||
@ -243,7 +222,7 @@ fun PreparingItem(order : OrderWithProducts){
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun PreparedItem(order : OrderWithProducts){
|
fun PreparedItem(order : OrderModel){
|
||||||
Card(
|
Card(
|
||||||
border = BorderStroke(width = 2.dp, color = MyOrange),
|
border = BorderStroke(width = 2.dp, color = MyOrange),
|
||||||
shape = RoundedCornerShape(size = 20.dp),
|
shape = RoundedCornerShape(size = 20.dp),
|
||||||
@ -260,7 +239,7 @@ fun PreparedItem(order : OrderWithProducts){
|
|||||||
modifier = Modifier.fillMaxWidth(0.5f)
|
modifier = Modifier.fillMaxWidth(0.5f)
|
||||||
){
|
){
|
||||||
val localDateFormat = SimpleDateFormat("HH:mm")
|
val localDateFormat = SimpleDateFormat("HH:mm")
|
||||||
val time = localDateFormat.format(order.order.date)
|
val time = localDateFormat.format(order.date)
|
||||||
Text(
|
Text(
|
||||||
text = time,
|
text = time,
|
||||||
fontFamily = NunitoFamily,
|
fontFamily = NunitoFamily,
|
||||||
@ -272,13 +251,13 @@ fun PreparedItem(order : OrderWithProducts){
|
|||||||
modifier = Modifier.fillMaxWidth()
|
modifier = Modifier.fillMaxWidth()
|
||||||
){
|
){
|
||||||
Text(
|
Text(
|
||||||
text = order.orderWithProducts[0].productList[0].title,
|
text = "Классика",
|
||||||
fontFamily = NunitoFamily,
|
fontFamily = NunitoFamily,
|
||||||
fontSize = 20.sp,
|
fontSize = 20.sp,
|
||||||
fontWeight = FontWeight.Bold
|
fontWeight = FontWeight.Bold
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
text = "x" + order.orderWithProducts[0].orderProductModel.quantity,
|
text = "x" + order.productsId.values.first().toString(),
|
||||||
fontFamily = NunitoFamily,
|
fontFamily = NunitoFamily,
|
||||||
fontSize = 20.sp,
|
fontSize = 20.sp,
|
||||||
fontWeight = FontWeight.Bold
|
fontWeight = FontWeight.Bold
|
||||||
@ -311,7 +290,7 @@ fun PreparedItem(order : OrderWithProducts){
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ProcessedItem(order : OrderWithProducts){
|
fun ProcessedItem(){
|
||||||
Card(
|
Card(
|
||||||
border = BorderStroke(width = 2.dp, color = MyOrange),
|
border = BorderStroke(width = 2.dp, color = MyOrange),
|
||||||
shape = RoundedCornerShape(size = 20.dp),
|
shape = RoundedCornerShape(size = 20.dp),
|
||||||
@ -327,10 +306,8 @@ fun ProcessedItem(order : OrderWithProducts){
|
|||||||
|
|
||||||
modifier = Modifier.fillMaxWidth(0.5f)
|
modifier = Modifier.fillMaxWidth(0.5f)
|
||||||
){
|
){
|
||||||
val localDateFormat = SimpleDateFormat("HH:mm")
|
|
||||||
val time = localDateFormat.format(order.order.date)
|
|
||||||
Text(
|
Text(
|
||||||
text = time,
|
text = "16:24",
|
||||||
fontFamily = NunitoFamily,
|
fontFamily = NunitoFamily,
|
||||||
fontSize = 20.sp,
|
fontSize = 20.sp,
|
||||||
fontWeight = FontWeight.Bold
|
fontWeight = FontWeight.Bold
|
||||||
@ -340,13 +317,13 @@ fun ProcessedItem(order : OrderWithProducts){
|
|||||||
modifier = Modifier.fillMaxWidth()
|
modifier = Modifier.fillMaxWidth()
|
||||||
){
|
){
|
||||||
Text(
|
Text(
|
||||||
text = order.orderWithProducts[0].productList[0].title,
|
text = "Классика",
|
||||||
fontFamily = NunitoFamily,
|
fontFamily = NunitoFamily,
|
||||||
fontSize = 20.sp,
|
fontSize = 20.sp,
|
||||||
fontWeight = FontWeight.Bold
|
fontWeight = FontWeight.Bold
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
text = "x" + order.orderWithProducts[0].orderProductModel.quantity,
|
text = "x2",
|
||||||
fontFamily = NunitoFamily,
|
fontFamily = NunitoFamily,
|
||||||
fontSize = 20.sp,
|
fontSize = 20.sp,
|
||||||
fontWeight = FontWeight.Bold
|
fontWeight = FontWeight.Bold
|
||||||
@ -360,13 +337,13 @@ fun ProcessedItem(order : OrderWithProducts){
|
|||||||
modifier = Modifier.fillMaxWidth(0.5f)
|
modifier = Modifier.fillMaxWidth(0.5f)
|
||||||
){
|
){
|
||||||
Text(
|
Text(
|
||||||
text = order.orderWithProducts[0].orderProductModel.totalPrice.toString(),
|
text = "300 руб.",
|
||||||
fontFamily = NunitoFamily,
|
fontFamily = NunitoFamily,
|
||||||
fontSize = 14.sp,
|
fontSize = 14.sp,
|
||||||
fontWeight = FontWeight.Bold
|
fontWeight = FontWeight.Bold
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
text = order.order.date.toString(),
|
text = "20.03.2012",
|
||||||
fontFamily = NunitoFamily,
|
fontFamily = NunitoFamily,
|
||||||
fontSize = 14.sp,
|
fontSize = 14.sp,
|
||||||
fontWeight = FontWeight.Bold
|
fontWeight = FontWeight.Bold
|
||||||
|
Loading…
x
Reference in New Issue
Block a user