Абалдеть, я сделал удаление велосипеда, абалдеть....
This commit is contained in:
parent
cf8aefb83d
commit
61b1507973
@ -18,10 +18,11 @@ class MainActivity : ComponentActivity() {
|
||||
|
||||
val database = AppDatabase.getInstance(applicationContext)
|
||||
val bicycleDao = database.bicycleDao()
|
||||
val userDao = database.userDao()
|
||||
|
||||
setContent {
|
||||
LabWorkTheme {
|
||||
MainScreen(bicycleDao)
|
||||
MainScreen(bicycleDao,userDao)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,11 +5,12 @@ import android.annotation.SuppressLint
|
||||
import androidx.compose.material.Scaffold
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
import com.example.labwork.DAO.BicycleDao
|
||||
import com.example.labwork.database.DAO.BicycleDao
|
||||
import com.example.labwork.database.DAO.UserDao
|
||||
|
||||
@SuppressLint("UnusedMaterialScaffoldPaddingParameter")
|
||||
@Composable
|
||||
fun MainScreen(bicycleDao: BicycleDao) {
|
||||
fun MainScreen(bicycleDao: BicycleDao, userDao: UserDao) {
|
||||
val navController = rememberNavController()
|
||||
Scaffold(
|
||||
bottomBar = {
|
||||
@ -17,6 +18,6 @@ fun MainScreen(bicycleDao: BicycleDao) {
|
||||
|
||||
}
|
||||
) {
|
||||
SlideGraph(navHostController = navController, bicycleDao = bicycleDao)
|
||||
SlideGraph(navHostController = navController, bicycleDao = bicycleDao, userDao = userDao)
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ import androidx.compose.runtime.mutableStateListOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.example.labwork.DAO.BicycleDao
|
||||
import com.example.labwork.database.DAO.BicycleDao
|
||||
import com.example.labwork.models.Bicycle
|
||||
import com.example.labwork.pages.ListInfo
|
||||
import com.example.labwork.pages.ListProduct
|
||||
@ -45,7 +45,7 @@ fun ScreenListProduct(bicycleDao: BicycleDao) {
|
||||
modifier = Modifier.fillMaxHeight().padding(bottom = 65.dp)
|
||||
) {
|
||||
items(bicycles) { item ->
|
||||
ListProduct(item = item)
|
||||
ListProduct(item = item, bicycleDao = bicycleDao)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,13 +5,15 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.navigation.NavHostController
|
||||
import androidx.navigation.compose.NavHost
|
||||
import androidx.navigation.compose.composable
|
||||
import com.example.labwork.DAO.BicycleDao
|
||||
import com.example.labwork.database.DAO.BicycleDao
|
||||
import com.example.labwork.database.DAO.UserDao
|
||||
|
||||
|
||||
@Composable
|
||||
fun SlideGraph(
|
||||
navHostController: NavHostController,
|
||||
bicycleDao: BicycleDao
|
||||
bicycleDao: BicycleDao,
|
||||
userDao: UserDao
|
||||
) {
|
||||
NavHost(navController = navHostController, startDestination = "Profile"){
|
||||
|
||||
@ -24,5 +26,6 @@ fun SlideGraph(
|
||||
composable("ListProduct"){
|
||||
ScreenListProduct(bicycleDao)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -5,8 +5,8 @@ import androidx.room.Database
|
||||
import androidx.room.Room
|
||||
import androidx.room.RoomDatabase
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
import com.example.labwork.DAO.BicycleDao
|
||||
import com.example.labwork.DAO.UserDao
|
||||
import com.example.labwork.database.DAO.BicycleDao
|
||||
import com.example.labwork.database.DAO.UserDao
|
||||
import com.example.labwork.models.Bicycle
|
||||
import com.example.labwork.models.User
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
@ -59,12 +59,21 @@ abstract class AppDatabase : RoomDatabase() {
|
||||
userDao.insertUser(user2)
|
||||
|
||||
// Создание велосипедов
|
||||
val bicycle1 = Bicycle(1, "Trek", "FX 2", "Black", 1)
|
||||
val bicycle2 = Bicycle(2, "Giant", "Escape 3", "Blue", 2)
|
||||
val bicycle1 = Bicycle(1, "Trek", "Велосипед 1", "Black", 1)
|
||||
val bicycle2 = Bicycle(2, "Giant", "Велосипед 2", "Blue", 2)
|
||||
val bicycle3 = Bicycle(3, "Trek", "Велосипед 3", "Black", 1)
|
||||
val bicycle4 = Bicycle(4, "Giant", "Велосипед 4", "Blue", 2)
|
||||
val bicycle5 = Bicycle(5, "Trek", "Велосипед 5", "Black", 1)
|
||||
val bicycle6 = Bicycle(6, "Giant", "Велосипед 6", "Blue", 2)
|
||||
|
||||
// Вставка велосипедов в базу данных
|
||||
bicycleDao.insertBicycle(bicycle1)
|
||||
bicycleDao.insertBicycle(bicycle2)
|
||||
bicycleDao.insertBicycle(bicycle3)
|
||||
bicycleDao.insertBicycle(bicycle4)
|
||||
bicycleDao.insertBicycle(bicycle5)
|
||||
bicycleDao.insertBicycle(bicycle6)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.example.labwork.DAO
|
||||
package com.example.labwork.database.DAO
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Delete
|
@ -1,4 +1,4 @@
|
||||
package com.example.labwork.DAO
|
||||
package com.example.labwork.database.DAO
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Delete
|
||||
@ -26,4 +26,7 @@ interface UserDao {
|
||||
|
||||
@Query("SELECT * FROM users WHERE email = :email")
|
||||
suspend fun getUserByEmail(email: String): User
|
||||
|
||||
@Query("SELECT * FROM users WHERE email = :email AND password = :password")
|
||||
suspend fun getUserByEmailAndPassword(email: String, password: String): User?
|
||||
}
|
@ -35,12 +35,17 @@ import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.example.labwork.R
|
||||
import com.example.labwork.database.DAO.BicycleDao
|
||||
import com.example.labwork.database.DAO.UserDao
|
||||
import com.example.labwork.models.Bicycle
|
||||
import com.example.labwork.ui.theme.LightBluePolitech
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
|
||||
@Composable
|
||||
fun ListProduct(item: Bicycle) {
|
||||
fun ListProduct(item: Bicycle, bicycleDao: BicycleDao) {
|
||||
var isFullAbout by remember { mutableStateOf(false) }
|
||||
val scale by animateFloatAsState(if (isFullAbout) 1f else 0f)
|
||||
val textSize by animateDpAsState(if (isFullAbout) 18.dp else 24.dp)
|
||||
@ -55,15 +60,15 @@ fun ListProduct(item: Bicycle) {
|
||||
Box {
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Column {
|
||||
/*Image(
|
||||
painter = painterResource(id = item.imageId),
|
||||
Image(
|
||||
painter = painterResource(id = R.drawable.logo_ulstu),
|
||||
contentDescription = "book",
|
||||
contentScale = ContentScale.Crop,
|
||||
modifier = Modifier
|
||||
.padding(10.dp)
|
||||
.size(128.dp)
|
||||
.shadow(2.dp)
|
||||
)*/
|
||||
)
|
||||
Button(
|
||||
colors = ButtonDefaults.buttonColors(backgroundColor = LightBluePolitech),
|
||||
modifier = Modifier
|
||||
@ -88,7 +93,6 @@ fun ListProduct(item: Bicycle) {
|
||||
.padding(start = 9.dp, bottom = 9.dp)
|
||||
.size(height = 32.dp, width = 40.dp),
|
||||
onClick = {
|
||||
/*TODO*/
|
||||
},
|
||||
shape = RoundedCornerShape(15.dp)
|
||||
) {
|
||||
@ -112,7 +116,10 @@ fun ListProduct(item: Bicycle) {
|
||||
.padding(start = 9.dp, bottom = 9.dp)
|
||||
.size(height = 32.dp, width = 40.dp),
|
||||
onClick = {
|
||||
/*TODO*/
|
||||
// Удаление выбранного велосипеда по нажатию на кнопку
|
||||
GlobalScope.launch {
|
||||
bicycleDao.deleteBicycle(item)
|
||||
}
|
||||
},
|
||||
shape = RoundedCornerShape(15.dp)
|
||||
) {
|
||||
@ -144,7 +151,7 @@ fun ListProduct(item: Bicycle) {
|
||||
) {
|
||||
Text(
|
||||
color = Color.Black,
|
||||
text = item.model,
|
||||
text = item.brand,
|
||||
maxLines = 10,
|
||||
fontSize = 14.sp,
|
||||
textAlign = TextAlign.Center,
|
||||
|
Loading…
x
Reference in New Issue
Block a user