From 97bafd04919c4b2876ec95988d0db3e3500cafdf Mon Sep 17 00:00:00 2001 From: Ismailov_Rovshan Date: Sat, 23 Dec 2023 04:21:36 +0400 Subject: [PATCH] win --- .../example/myapplication/components/Cart.kt | 9 +- .../example/myapplication/database/AppDb.kt | 102 +++++++++--------- 2 files changed, 58 insertions(+), 53 deletions(-) diff --git a/app/src/main/java/com/example/myapplication/components/Cart.kt b/app/src/main/java/com/example/myapplication/components/Cart.kt index 81e8bce..597a8b8 100644 --- a/app/src/main/java/com/example/myapplication/components/Cart.kt +++ b/app/src/main/java/com/example/myapplication/components/Cart.kt @@ -60,11 +60,16 @@ fun Cart(navController: NavController, userViewModel: UserViewModel = viewModel( item{ products.forEach{ - ProductCardInCart(it.name, it.price, it.img,{}) + ProductCardInCart(it.name, it.price, it.img){ + coroutineScope.launch { + userViewModel.deleteCartProduct(userViewModel.getUserId(), it.productId!!) + sumPrice.value -= it.price + products.remove(it) + } + } } } - item { ButtonNice(text = "Оплатить: " + sumPrice.value.toString() + "Р", color = myColor4) } diff --git a/app/src/main/java/com/example/myapplication/database/AppDb.kt b/app/src/main/java/com/example/myapplication/database/AppDb.kt index 7b98fba..f820429 100644 --- a/app/src/main/java/com/example/myapplication/database/AppDb.kt +++ b/app/src/main/java/com/example/myapplication/database/AppDb.kt @@ -43,67 +43,67 @@ abstract class AppDb: RoomDatabase(){ val categoryDao = database.categoryDao() - categoryDao.insert(Category(1, "Видеокарты")) - categoryDao.insert(Category(2, "Процессоры")) - categoryDao.insert(Category(3, "Оперативная память")) - categoryDao.insert(Category(4, "Твердотельные накопители")) +// categoryDao.insert(Category(1, "Видеокарты")) +// categoryDao.insert(Category(2, "Процессоры")) +// categoryDao.insert(Category(3, "Оперативная память")) +// categoryDao.insert(Category(4, "Твердотельные накопители")) val productDao = database.productDao() val img1: Bitmap = BitmapFactory.decodeResource(context.resources, R.drawable.product1) - val img2: Bitmap = BitmapFactory.decodeResource(context.resources, R.drawable.product2) - val img3: Bitmap = BitmapFactory.decodeResource(context.resources, R.drawable.product3) - val img4: Bitmap = BitmapFactory.decodeResource(context.resources, R.drawable.product4) - val img5: Bitmap = BitmapFactory.decodeResource(context.resources, R.drawable.product5) - val img6: Bitmap = BitmapFactory.decodeResource(context.resources, R.drawable.product6) - val img7: Bitmap = BitmapFactory.decodeResource(context.resources, R.drawable.product7) - val img8: Bitmap = BitmapFactory.decodeResource(context.resources, R.drawable.product8) +// val img2: Bitmap = BitmapFactory.decodeResource(context.resources, R.drawable.product2) +// val img3: Bitmap = BitmapFactory.decodeResource(context.resources, R.drawable.product3) +// val img4: Bitmap = BitmapFactory.decodeResource(context.resources, R.drawable.product4) +// val img5: Bitmap = BitmapFactory.decodeResource(context.resources, R.drawable.product5) +// val img6: Bitmap = BitmapFactory.decodeResource(context.resources, R.drawable.product6) +// val img7: Bitmap = BitmapFactory.decodeResource(context.resources, R.drawable.product7) +// val img8: Bitmap = BitmapFactory.decodeResource(context.resources, R.drawable.product8) productDao.insert(Product(1, "MSI GeForce RTX 4090 VENTUS 3X OC", "Информацио о товаре MSI GeForce RTX 4090 VENTUS 3X OC ", 210999.0, img1, 1 )) +// +// productDao.insert(Product(2, "Palit GeForce GTX 1660 SUPER", +// "Информацио о товаре Palit GeForce GTX 1660 SUPER ", +// 25999.0, img2, 1 +// )) +// +// productDao.insert(Product(3, "Intel Celeron G5905 OEM", +// "Информацио о товаре Intel Celeron G5905 OEM ", +// 25999.0, img3, 2 +// )) +// +// +// productDao.insert(Product(4, "AMD Ryzen 5 4500 BOX", +// "Информацио о товаре Intel Celeron G5905 OEM", +// 9799.0, img4, 2 +// )) +// +// productDao.insert(Product(5, "Kingston FURY Beast Black", +// "Информацио о товаре Kingston FURY Beast Black", +// 4499.0, img5, 3 +// )) +// +// productDao.insert(Product(6, "ADATA XPG SPECTRIX D41 RGB", +// "Информацио о товаре ADATA XPG SPECTRIX D41 RGB", +// 4599.0, img6, 3 +// )) +// +// productDao.insert(Product(7, "ADATA SU650", +// "Информацио о товаре ADATA SU650", +// 1550.0, img7, 4 +// )) +// productDao.insert(Product(8, "Smartbuy Revival 3", +// "Информацио о товаре Smartbuy Revival 3", +// 1250.0, img8, 4 +// )) - productDao.insert(Product(2, "Palit GeForce GTX 1660 SUPER", - "Информацио о товаре Palit GeForce GTX 1660 SUPER ", - 25999.0, img2, 1 - )) - - productDao.insert(Product(3, "Intel Celeron G5905 OEM", - "Информацио о товаре Intel Celeron G5905 OEM ", - 25999.0, img3, 2 - )) - - - productDao.insert(Product(4, "AMD Ryzen 5 4500 BOX", - "Информацио о товаре Intel Celeron G5905 OEM", - 9799.0, img4, 2 - )) - - productDao.insert(Product(5, "Kingston FURY Beast Black", - "Информацио о товаре Kingston FURY Beast Black", - 4499.0, img5, 3 - )) - - productDao.insert(Product(6, "ADATA XPG SPECTRIX D41 RGB", - "Информацио о товаре ADATA XPG SPECTRIX D41 RGB", - 4599.0, img6, 3 - )) - - productDao.insert(Product(7, "ADATA SU650", - "Информацио о товаре ADATA SU650", - 1550.0, img7, 4 - )) - productDao.insert(Product(8, "Smartbuy Revival 3", - "Информацио о товаре Smartbuy Revival 3", - 1250.0, img8, 4 - )) - - val userDao = database.userDao() - userDao.insert(User(5, "Иванов И.И", "ivanov","ivanov")) - database.userDao().addProductCart(UserProductCart(1, 1)) - database.userDao().addProductCart(UserProductCart(1, 3)) - //database.userDao().addProductCart(UserProductCart(1, 2)) + val userDao = database.userDao() + userDao.insert(User(5, "Иванов И.И", "ivanov","ivanov")) +// database.userDao().addProductCart(UserProductCart(1, 1)) +// database.userDao().addProductCart(UserProductCart(1, 3)) +// database.userDao().addProductCart(UserProductCart(1, 2)) } } fun getInstance(appContext: Context): AppDb {