Compare commits

..

1 Commits
lab3 ... main

Author SHA1 Message Date
7cfd496698 Отчет 2023-12-20 12:01:50 +03:00
22 changed files with 219 additions and 935 deletions

View File

@ -1,7 +1,6 @@
plugins { plugins {
id("com.android.application") id("com.android.application")
id("org.jetbrains.kotlin.android") id("org.jetbrains.kotlin.android")
id("kotlin-kapt")
} }
android { android {
@ -31,11 +30,11 @@ android {
} }
} }
compileOptions { compileOptions {
sourceCompatibility = JavaVersion.VERSION_17 sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_1_8
} }
kotlinOptions { kotlinOptions {
jvmTarget = "17" jvmTarget = "1.8"
} }
buildFeatures { buildFeatures {
compose = true compose = true
@ -55,10 +54,6 @@ dependencies {
implementation("androidx.navigation:navigation-compose:2.7.4") implementation("androidx.navigation:navigation-compose:2.7.4")
implementation("androidx.compose.material:material:1.5.4") implementation("androidx.compose.material:material:1.5.4")
implementation("androidx.room:room-ktx:2.6.0")
kapt("androidx.room:room-compiler:2.6.0")
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.6.2")
implementation("androidx.core:core-ktx:1.9.0") implementation("androidx.core:core-ktx:1.9.0")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.1") implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.1")
implementation("androidx.activity:activity-compose:1.7.0") implementation("androidx.activity:activity-compose:1.7.0")

View File

@ -8,22 +8,15 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import com.example.labwork.button_navigation.MainScreen import com.example.labwork.button_navigation.MainScreen
import com.example.labwork.database.AppDatabase
import com.example.labwork.ui.theme.LabWorkTheme import com.example.labwork.ui.theme.LabWorkTheme
class MainActivity : ComponentActivity() { class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
val database = AppDatabase.getInstance(applicationContext)
val bicycleDao = database.bicycleDao()
val userDao = database.userDao()
setContent { setContent {
LabWorkTheme { LabWorkTheme {
MainScreen(bicycleDao,userDao) MainScreen()
} }
} }
} }
} }

View File

@ -5,12 +5,10 @@ import android.annotation.SuppressLint
import androidx.compose.material.Scaffold import androidx.compose.material.Scaffold
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.navigation.compose.rememberNavController import androidx.navigation.compose.rememberNavController
import com.example.labwork.database.DAO.BicycleDao
import com.example.labwork.database.DAO.UserDao
@SuppressLint("UnusedMaterialScaffoldPaddingParameter") @SuppressLint("UnusedMaterialScaffoldPaddingParameter")
@Composable @Composable
fun MainScreen(bicycleDao: BicycleDao, userDao: UserDao) { fun MainScreen() {
val navController = rememberNavController() val navController = rememberNavController()
Scaffold( Scaffold(
bottomBar = { bottomBar = {
@ -18,6 +16,6 @@ fun MainScreen(bicycleDao: BicycleDao, userDao: UserDao) {
} }
) { ) {
SlideGraph(navHostController = navController, bicycleDao = bicycleDao, userDao = userDao) SlideGraph(navHostController = navController)
} }
} }

View File

@ -1,26 +1,16 @@
package com.example.labwork.button_navigation package com.example.labwork.button_navigation
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.itemsIndexed
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.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.navigation.NavHostController import com.example.labwork.models.getItemProducts
import com.example.labwork.database.DAO.BicycleDao
import com.example.labwork.database.DAO.UserDao
import com.example.labwork.models.Bicycle
import com.example.labwork.pages.ListInfo import com.example.labwork.pages.ListInfo
import com.example.labwork.pages.product.FormNewProduct import com.example.labwork.pages.ListProduct
import com.example.labwork.pages.product.ListProduct import com.example.labwork.pages.RegisteryOrLogin
import com.example.labwork.pages.user.RegisteryOrLogin
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
@Composable @Composable
fun ScreenInfo() { fun ScreenInfo() {
@ -28,30 +18,22 @@ fun ScreenInfo() {
} }
@Composable @Composable
fun ScreenProfile(userDao: UserDao, navHostController: NavHostController) { fun ScreenProfile() {
RegisteryOrLogin(userDao, navHostController) RegisteryOrLogin()
} }
@Composable @Composable
fun ScreenListProduct(bicycleDao: BicycleDao, navHostController: NavHostController) { fun ScreenListProduct() {
val bicycles = remember { mutableStateListOf<Bicycle>() } LazyColumn(
LaunchedEffect(Unit) {
val fetchedBicycles = withContext(Dispatchers.IO) {
bicycleDao.getAllBicycles()
}
bicycles.addAll(fetchedBicycles)
}
Column(
modifier = Modifier.fillMaxHeight().padding(bottom = 65.dp) modifier = Modifier.fillMaxHeight().padding(bottom = 65.dp)
) { ) {
FormNewProduct(bicycleDao, navHostController) itemsIndexed(
LazyColumn { getItemProducts()
items(bicycles) { item -> )
ListProduct(item = item, bicycleDao = bicycleDao, navHostController = navHostController) {
} _, item ->
ListProduct(item = item)
} }
} }
} }

View File

@ -5,27 +5,22 @@ import androidx.compose.runtime.Composable
import androidx.navigation.NavHostController import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable import androidx.navigation.compose.composable
import com.example.labwork.database.DAO.BicycleDao
import com.example.labwork.database.DAO.UserDao
@Composable @Composable
fun SlideGraph( fun SlideGraph(
navHostController: NavHostController, navHostController: NavHostController
bicycleDao: BicycleDao,
userDao: UserDao
) { ) {
NavHost(navController = navHostController, startDestination = "Profile"){ NavHost(navController = navHostController, startDestination = "Profile"){
composable("Profile"){ composable("Profile"){
ScreenProfile(userDao, navHostController = navHostController) ScreenProfile()
} }
composable("Info"){ composable("Info"){
ScreenInfo() ScreenInfo()
} }
composable("ListProduct"){ composable("ListProduct"){
ScreenListProduct(bicycleDao, navHostController = navHostController) ScreenListProduct()
} }
} }
} }

View File

@ -1,82 +0,0 @@
package com.example.labwork.database
import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.sqlite.db.SupportSQLiteDatabase
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
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.util.concurrent.Executors
@Database(entities = [User::class, Bicycle::class], version = 1)
abstract class AppDatabase : RoomDatabase() {
abstract fun userDao(): UserDao
abstract fun bicycleDao(): BicycleDao
companion object {
private var instance: AppDatabase? = null
fun getInstance(context: Context): AppDatabase {
if (instance == null) {
synchronized(AppDatabase::class) {
instance = Room.databaseBuilder(
context.applicationContext,
AppDatabase::class.java,
"my-database"
)
.addCallback(object : RoomDatabase.Callback() {
override fun onCreate(db: SupportSQLiteDatabase) {
super.onCreate(db)
Executors.newSingleThreadExecutor().execute {
CoroutineScope(Dispatchers.IO).launch {
populateDatabase(instance!!)
}
}
}
})
.build()
}
}
return instance!!
}
private suspend fun populateDatabase(database: AppDatabase) {
val userDao = database.userDao()
val bicycleDao = database.bicycleDao()
// Создание пользователей
val user1 = User(null, "John Doe", "john.doe@example.com", "password123")
val user2 = User(null, "Jane Smith", "jane.smith@example.com", "password456")
// Вставка пользователей в базу данных
userDao.insertUser(user1)
userDao.insertUser(user2)
// Создание велосипедов
val bicycle1 = Bicycle(brand = "Trek", model = "Велосипед 1", color = "Black", userId = 1, id = null)
val bicycle2 = Bicycle(brand = "Trek", model = "Велосипед 2", color = "Black", userId = null, id = null)
val bicycle3 = Bicycle(brand = "Trek", model = "Велосипед 3", color = "Black", userId = 1, id = null)
val bicycle4 = Bicycle(brand = "Trek", model = "Велосипед 4", color = "Black", userId = null, id = null)
val bicycle5 = Bicycle(brand = "Trek", model = "Велосипед 5", color = "Black", userId = null, id = null)
val bicycle6 = Bicycle(brand = "Trek", model = "Велосипед 6", color = "Black", userId = null, id = null)
// Вставка велосипедов в базу данных
bicycleDao.insertBicycle(bicycle1)
bicycleDao.insertBicycle(bicycle2)
bicycleDao.insertBicycle(bicycle3)
bicycleDao.insertBicycle(bicycle4)
bicycleDao.insertBicycle(bicycle5)
bicycleDao.insertBicycle(bicycle6)
}
}
}

View File

@ -1,29 +0,0 @@
package com.example.labwork.database.DAO
import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.Query
import androidx.room.Update
import com.example.labwork.models.Bicycle
@Dao
interface BicycleDao {
@Insert
suspend fun insertBicycle(bicycle: Bicycle)
@Update
suspend fun updateBicycle(bicycle: Bicycle)
@Delete
suspend fun deleteBicycle(bicycle: Bicycle)
@Query("SELECT * FROM bicycles")
suspend fun getAllBicycles(): List<Bicycle>
@Query("SELECT * FROM bicycles WHERE id = :bicycleId")
suspend fun getBicycleById(bicycleId: Int?): Bicycle
@Query("SELECT * FROM bicycles WHERE userId = :userId")
suspend fun getBicyclesByUserId(userId: Int): List<Bicycle>
}

View File

@ -1,35 +0,0 @@
package com.example.labwork.database.DAO
import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.Query
import androidx.room.Update
import com.example.labwork.models.User
@Dao
interface UserDao {
@Insert
suspend fun insertUser(user: User)
@Update
suspend fun updateUser(user: User)
@Delete
suspend fun deleteUser(user: User)
@Query("SELECT * FROM users")
suspend fun getAllUsers(): List<User>
@Query("SELECT * FROM users WHERE id = :userId")
suspend fun getUserById(userId: Int): User
@Query("SELECT * FROM users WHERE email = :email")
suspend fun getUserByEmail(email: String): User
@Query("SELECT password FROM users WHERE email = :email")
suspend fun getPasswordByEmail(email: String): String
@Query("SELECT * FROM users WHERE email = :email AND password = :password")
suspend fun getUserByEmailAndPassword(email: String, password: String): User?
}

View File

@ -1,19 +0,0 @@
package com.example.labwork.models
import androidx.room.Entity
import androidx.room.ForeignKey
import androidx.room.PrimaryKey
@Entity(tableName = "bicycles",
foreignKeys = [ForeignKey(entity = User::class,
parentColumns = ["id"],
childColumns = ["userId"],
onDelete = ForeignKey.SET_NULL)])
data class Bicycle(
@PrimaryKey(autoGenerate = true)
val id: Int?,
var brand: String,
var model: String,
var color: String,
val userId: Int?
)

View File

@ -0,0 +1,25 @@
package com.example.labwork.models
import com.example.labwork.R
import java.io.Serializable
data class ItemProduct(
val imageId: Int,
val name: String,
val about: String
) : Serializable
fun getItemProducts(): List<ItemProduct> {
return listOf(
ItemProduct(R.drawable.baseline_menu_book,"Золотая рыбка","Старик трудолюбивый (трижды забрасывал невод), добрый (отпустил просящую о пощаде единственную добычу), покорный (не перечит жене). Появление волшебной рыбки проявило алчную натуру женщины: требовательную, грубую, жаждущую от корыта до возможности быть владычицей морскою."),
ItemProduct(R.drawable.baseline_menu_book,"451° по Фаренгейту","Мастер мирового масштаба, совмещающий в литературе несовместимое. Создатель таких ярчайших шедевров, как \"Марсианские хроники\", \"451° по Фаренгейту"),
ItemProduct(R.drawable.baseline_menu_book,"1984","Своеобразный антипод второй великой антиутопии XX века - \"О дивный новый мир\" Олдоса Хаксли. Что, в сущности, страшнее: доведенное до абсурда \"общество потребления\""),
ItemProduct(R.drawable.baseline_menu_book,"Мастер и Маргарита","Один из самых загадочных и удивительных романов XX века. «Мастер и Маргарита» визитная карточка Михаила Булгакова. Более десяти лет он работал над"),
ItemProduct(R.drawable.baseline_menu_book,"Шантарам","Представляем читателю один из самых поразительных романов начала XXI века (в 2015 году получивший долгожданное продолжение «Тень горы»)."),
ItemProduct(R.drawable.baseline_menu_book,"Цветы для Элджернона","Сорок лет назад это считалось фантастикой. Сорок лет назад это читалось как фантастика."),
ItemProduct(R.drawable.baseline_menu_book,"Три товарища","Трое друзей - Робби, отчаянный автогонщик Кестер и \"последний романтик\" Ленц прошли Первую мировую войну."),
ItemProduct(R.drawable.baseline_menu_book,"Портрет Дориана Грея","«Портрет Дориана Грея» одно из величайших произведений последних полутора столетий, роман, который пытались запретить, а автора осуждали"),
ItemProduct(R.drawable.baseline_menu_book,"Маленький принц","«Маленький принц» — аллегорическая повесть, наиболее известное произведение Антуана де Сент-Экзюпери. ")
)
}

View File

@ -1,15 +0,0 @@
package com.example.labwork.models
import androidx.room.Entity
import androidx.room.ForeignKey
import androidx.room.PrimaryKey
@Entity(tableName = "users")
data class User(
@PrimaryKey(autoGenerate = true)
val id: Int?,
var name: String,
var email: String,
var password: String,
)

View File

@ -1,4 +1,4 @@
package com.example.labwork.pages.user package com.example.labwork.pages
import androidx.compose.foundation.Image import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
@ -11,6 +11,7 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.size
import androidx.compose.material.Button import androidx.compose.material.Button
import androidx.compose.material.ButtonDefaults import androidx.compose.material.ButtonDefaults
import androidx.compose.material.IconButton
import androidx.compose.material.Text import androidx.compose.material.Text
import androidx.compose.material.TextField import androidx.compose.material.TextField
import androidx.compose.material.TextFieldDefaults import androidx.compose.material.TextFieldDefaults
@ -25,25 +26,34 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.input.PasswordVisualTransformation import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.text.input.VisualTransformation
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.navigation.NavController import androidx.navigation.NavController
import androidx.navigation.NavHostController import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import com.example.labwork.R 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.models.User
import com.example.labwork.ui.theme.LightBluePolitech import com.example.labwork.ui.theme.LightBluePolitech
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
@Composable @Composable
fun RegisteryPage(navController: NavController, userDao: UserDao, navHostController: NavHostController) { fun RegisteryOrLogin() {
val navController = rememberNavController()
NavHost(navController, startDestination = "login") {
composable("login") {
LoginPage(navController)
}
composable("register") {
RegisteryPage(navController)
}
}
}
@Composable
fun LoginPage(navController: NavController) {
var username by remember { mutableStateOf("") } var username by remember { mutableStateOf("") }
var password by remember { mutableStateOf("") } var password by remember { mutableStateOf("") }
var confirmPassword by remember { mutableStateOf("") } var showPassword by remember { mutableStateOf(false) }
var email by remember { mutableStateOf("") }
Column( Column(
modifier = Modifier modifier = Modifier
@ -81,9 +91,85 @@ fun RegisteryPage(navController: NavController, userDao: UserDao, navHostControl
Spacer(modifier = Modifier.height(8.dp)) Spacer(modifier = Modifier.height(8.dp))
TextField( TextField(
value = email, value = password,
onValueChange = { email = it }, onValueChange = { password = it },
label = { Text("Почта") }, label = { Text("Пароль") },
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp),
textStyle = TextStyle(fontSize = 16.sp),
colors = TextFieldDefaults.textFieldColors(
cursorColor = LightBluePolitech,
backgroundColor = Color.White,
textColor = LightBluePolitech,
unfocusedLabelColor = LightBluePolitech,
focusedIndicatorColor = LightBluePolitech,
unfocusedIndicatorColor = LightBluePolitech,
focusedLabelColor = LightBluePolitech
),
singleLine = true,
visualTransformation = if (showPassword) VisualTransformation.None else PasswordVisualTransformation(),
trailingIcon = {
IconButton(
onClick = { showPassword = !showPassword }
) {
Image(
painter = if(showPassword) painterResource(R.drawable.baseline_visibility) else painterResource(R.drawable.baseline_visibility_off),
contentDescription = "LogoVissable",
modifier = Modifier.size(24.dp)
)
}
}
)
Spacer(modifier = Modifier.height(8.dp))
Button(
onClick = { /* Login logic */ },
colors = ButtonDefaults.buttonColors(backgroundColor = LightBluePolitech, ),
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp)
) {
Text(text = "Авторизоваться", color = Color.White)
}
Spacer(modifier = Modifier.height(8.dp))
Button(
onClick = { navController.navigate("register") },
colors = ButtonDefaults.buttonColors(backgroundColor = LightBluePolitech),
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp)
) {
Text(text = "Регистрация", color = Color.White)
}
}
}
@Composable
fun RegisteryPage(navController: NavController) {
var username by remember { mutableStateOf("") }
var password by remember { mutableStateOf("") }
var confirmPassword by remember { mutableStateOf("") }
Column(
modifier = Modifier
.fillMaxSize()
.padding(16.dp),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Image(
painter = painterResource(R.drawable.logo_ulstu),
contentDescription = "Logo",
modifier = Modifier.size(200.dp)
)
Spacer(modifier = Modifier.height(16.dp))
TextField(
value = username,
onValueChange = { username = it },
label = { Text("Логин") },
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.padding(horizontal = 16.dp), .padding(horizontal = 16.dp),
@ -144,15 +230,7 @@ fun RegisteryPage(navController: NavController, userDao: UserDao, navHostControl
Spacer(modifier = Modifier.height(8.dp)) Spacer(modifier = Modifier.height(8.dp))
Button( Button(
onClick = { onClick = { /* Register logic */ },
if (password == confirmPassword) {
GlobalScope.launch {
val newUser = User(null, name = username, email = email, password = password)
userDao.insertUser(newUser)
}
navController.navigate("login")
}
},
colors = ButtonDefaults.buttonColors(backgroundColor = LightBluePolitech), colors = ButtonDefaults.buttonColors(backgroundColor = LightBluePolitech),
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()

View File

@ -1,6 +1,7 @@
package com.example.labwork.pages package com.example.labwork.pages
import androidx.compose.foundation.Image import androidx.compose.foundation.Image
import androidx.compose.foundation.background
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.PaddingValues import androidx.compose.foundation.layout.PaddingValues
@ -54,7 +55,7 @@ fun ListInfo() {
.shadow(16.dp, shape = RoundedCornerShape(8.dp)) .shadow(16.dp, shape = RoundedCornerShape(8.dp))
) { ) {
Image( Image(
painter = painterResource(id = R.drawable.baseline_directions_bike_24), painter = painterResource(id = R.drawable.logo_ulstu),
contentDescription = "Menu Image", contentDescription = "Menu Image",
Modifier.fillMaxSize() Modifier.fillMaxSize()
) )
@ -89,7 +90,7 @@ fun ListInfo() {
onClick = { selectedTab = 1 } onClick = { selectedTab = 1 }
) { ) {
Text( Text(
text = "Аренда велосипедов", text = "Библиотека",
modifier = Modifier.padding(8.dp), modifier = Modifier.padding(8.dp),
textAlign = TextAlign.Center, textAlign = TextAlign.Center,
) )
@ -109,7 +110,7 @@ fun ListInfo() {
Spacer(modifier = Modifier.height(16.dp)) Spacer(modifier = Modifier.height(16.dp))
when (selectedTab) { when (selectedTab) {
0 -> InfoUniver() 0 -> InfoUniver()
1 -> InfoBike() 1 -> InfoBiblio()
2 -> InfoProgrammer() 2 -> InfoProgrammer()
} }
} }
@ -119,9 +120,7 @@ fun ListInfo() {
@Composable @Composable
fun InfoUniver() { fun InfoUniver() {
LazyColumn( LazyColumn(
modifier = Modifier modifier = Modifier.fillMaxSize().padding(bottom = 65.dp),
.fillMaxSize()
.padding(bottom = 65.dp),
contentPadding = PaddingValues(16.dp) contentPadding = PaddingValues(16.dp)
) { ) {
item { item {
@ -211,11 +210,9 @@ fun InfoUniver() {
} }
@Composable @Composable
fun InfoBike() { fun InfoBiblio() {
LazyColumn( LazyColumn(
modifier = Modifier modifier = Modifier.fillMaxSize().padding(bottom = 65.dp),
.fillMaxSize()
.padding(bottom = 65.dp),
contentPadding = PaddingValues(16.dp) contentPadding = PaddingValues(16.dp)
) { ) {
item { item {
@ -229,26 +226,28 @@ fun InfoBike() {
Text("Технический университет подобным сокровищем обладает!",modifier = Modifier.padding(bottom = 16.dp)) Text("Технический университет подобным сокровищем обладает!",modifier = Modifier.padding(bottom = 16.dp))
Text( Text(
text = "Аренда велосипедов стала популярной и удобной системой передвижения в нашем университете. " + text = "Наша Научная библиотека соответствует всем современным требованиям технического вуза. Постоянно пополняющийся библиотечный фонд составляет более 1100 тыс. единиц хранения, формируется по специальностям (с учетом всех направлений учебного и научного процессов университета) изданиями, отвечающими требованиям программ высшей школы. В фонде имеются зарубежные издания, диссертации, авторефераты, документы на электронных носителях. Пользователям предоставляется доступ к электронным ресурсам удалённого доступа, входящим в состав электронно-библиотечной системы «ЭльбруС» УлГТУ."
"Это новая и интересная инициатива, которая предоставляет возможность студентам и персоналу " +
"университета арендовать велосипеды для своих транспортных нужд."
,modifier = Modifier.padding(bottom = 16.dp) ,modifier = Modifier.padding(bottom = 16.dp)
) )
Text( Text(
text = "Система аренды велосипедов в университете работает через специальное мобильное приложение, " + text = "К услугам читателей: зал каталогов, aвонементы научной и учебной литературы, общий читальный зал, отдел экономической и иностранной литературы. Выдача комплектов учебников первокурсникам, зал для аспирантов и преподавателей, зал периодических изданий, читальный зал машиностроительного факультета, читальный зал электронных ресурсов, отдел художественной литературы, научно-библиографический отдел, библиотека Института авиационных технологий и управления, Барышского колледжа — филиала УлГТУ."
"которое позволяет зарегистрированным пользователям легко и быстро арендовать велосипеды. " +
"Велосипеды предоставляются в зоне университета и пользуются большим спросом среди студентов, " +
"которые хотят быстро и удобно перемещаться по территорий и её окрестности."
,modifier = Modifier.padding(bottom = 16.dp) ,modifier = Modifier.padding(bottom = 16.dp)
) )
Text( Text(
text = "В целом, система аренды велосипедов в университете представляет собой инновационный и удобный способ транспортировки. " + text = "Абонемент учебной литературы обеспечивает студентов и лицеистов учебниками и учебными пособиями в соответствии с учебными программами. Научные, научно-популярные и справочные издания для подготовки рефератов, докладов, курсовых и дипломных работ, а также издания по орган. Располагает богатым фондом справочных и информационных изданий. В отделе художественной литературы собраны книги на любой вкус: есть классическая русская и зарубежная, современная отечественная и иностранная литература; тематика книг - от фантастики, детективов, приключений и женских романов до серьезной, философской литературы. В отделе иностранной литературы хранятся учебные и научные издания на английском, немецком и французском языках. Читальный зал электронных ресурсов (медиатека) НБ УлГТУ располагает фондом CD, DVD по различным отраслям знаний. На территории Научной библиотеки размещены точки доступа в Интернет по технологии Wi-Fi. Право доступа в беспроводную локальной сети предоставляется всем желающим студентам и сотрудникам университета, имеющим учетную запись пользователя корпоративной сети университета."
"Она делает перемещение по университету более доступным, эффективным и приятным. " + ,modifier = Modifier.padding(bottom = 16.dp)
"Кроме того, аренда велосипедов способствует здоровому образу жизни и позволяет студентам" + )
" в полной мере наслаждаться красотами университетского окружения.",
modifier = Modifier.padding(bottom = 16.dp) Text(
text = "События библиотечной жизни оперативно отражаются на нашем сайте (http://lib.ulstu.ru), сайт также обеспечивает круглосуточный доступ пользователей к каталогам и базам данных библиотеки."
,modifier = Modifier.padding(bottom = 16.dp)
)
Text(
text = "Научная библиотека ведёт активную работу в помощь духовно-нравственному, патриотическому и эстетическому воспитанию своих читателей, используя различные формы и методы библиотечного обслуживания, такие как: книжные выставки, тематические обзоры, беседы, творческие встречи с интересными людьми, конкурсы и викторины."
,modifier = Modifier.padding(bottom = 16.dp)
) )
Spacer(modifier = Modifier.height(16.dp)) Spacer(modifier = Modifier.height(16.dp))
@ -256,7 +255,7 @@ fun InfoBike() {
Text("Адреса электронной почты", Text("Адреса электронной почты",
fontSize = 16.sp, fontSize = 16.sp,
fontWeight = FontWeight.Bold) fontWeight = FontWeight.Bold)
Text(text = "arendabike@ulstu.ru") Text(text = "rector@ulstu.ru")
} }
} }
} }
@ -264,9 +263,7 @@ fun InfoBike() {
@Composable @Composable
fun InfoProgrammer() { fun InfoProgrammer() {
LazyColumn( LazyColumn(
modifier = Modifier modifier = Modifier.fillMaxSize().padding(bottom = 65.dp),
.fillMaxSize()
.padding(bottom = 65.dp),
contentPadding = PaddingValues(16.dp) contentPadding = PaddingValues(16.dp)
) { ) {
item { item {

View File

@ -1,4 +1,4 @@
package com.example.labwork.pages.product package com.example.labwork.pages
import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.animateDpAsState import androidx.compose.animation.core.animateDpAsState
@ -35,17 +35,12 @@ import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextAlign
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.navigation.NavHostController import com.example.labwork.models.ItemProduct
import com.example.labwork.R
import com.example.labwork.database.DAO.BicycleDao
import com.example.labwork.models.Bicycle
import com.example.labwork.ui.theme.LightBluePolitech import com.example.labwork.ui.theme.LightBluePolitech
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
@Composable @Composable
fun ListProduct(item: Bicycle, bicycleDao: BicycleDao, navHostController: NavHostController) { fun ListProduct(item: ItemProduct) {
var isFullAbout by remember { mutableStateOf(false) } var isFullAbout by remember { mutableStateOf(false) }
val scale by animateFloatAsState(if (isFullAbout) 1f else 0f) val scale by animateFloatAsState(if (isFullAbout) 1f else 0f)
val textSize by animateDpAsState(if (isFullAbout) 18.dp else 24.dp) val textSize by animateDpAsState(if (isFullAbout) 18.dp else 24.dp)
@ -61,7 +56,7 @@ fun ListProduct(item: Bicycle, bicycleDao: BicycleDao, navHostController: NavHos
Row(verticalAlignment = Alignment.CenterVertically) { Row(verticalAlignment = Alignment.CenterVertically) {
Column { Column {
Image( Image(
painter = painterResource(id = R.drawable.baseline_directions_bike_24), painter = painterResource(id = item.imageId),
contentDescription = "book", contentDescription = "book",
contentScale = ContentScale.Crop, contentScale = ContentScale.Crop,
modifier = Modifier modifier = Modifier
@ -86,24 +81,43 @@ fun ListProduct(item: Bicycle, bicycleDao: BicycleDao, navHostController: NavHos
textAlign = TextAlign.Center, textAlign = TextAlign.Center,
) )
} }
Column { Row {
FormUpdateProduct(item,bicycleDao, navHostController)
Button( Button(
colors = ButtonDefaults.buttonColors(backgroundColor = LightBluePolitech), colors = ButtonDefaults.buttonColors(backgroundColor = LightBluePolitech),
modifier = Modifier modifier = Modifier
.padding(start = 9.dp, bottom = 9.dp) .padding(start = 9.dp, bottom = 9.dp)
.size(height = 32.dp, width = 128.dp), .size(height = 32.dp, width = 40.dp),
onClick = { onClick = {
// СУПЕР ЖОСКИЙ КОСТЫЛЬ ЭТО ВООБЩЕ ТРЕШ /*TODO*/
GlobalScope.launch {
bicycleDao.deleteBicycle(item)
}
navHostController.navigate("ListProduct")
}, },
shape = RoundedCornerShape(15.dp) shape = RoundedCornerShape(15.dp)
) { ) {
Text( Text(
text = "Удалить", text = "+",
color = Color.White,
fontSize = 10.sp,
textAlign = TextAlign.Center,
)
}
Text(
text = "1000",
color = Color.Black,
fontSize = 14.sp,
textAlign = TextAlign.Center,
modifier = Modifier.padding(start = 8.dp, top = 4.dp)
)
Button(
colors = ButtonDefaults.buttonColors(backgroundColor = LightBluePolitech),
modifier = Modifier
.padding(start = 9.dp, bottom = 9.dp)
.size(height = 32.dp, width = 40.dp),
onClick = {
/*TODO*/
},
shape = RoundedCornerShape(15.dp)
) {
Text(
text = "-",
color = Color.White, color = Color.White,
fontSize = 10.sp, fontSize = 10.sp,
textAlign = TextAlign.Center, textAlign = TextAlign.Center,
@ -113,7 +127,7 @@ fun ListProduct(item: Bicycle, bicycleDao: BicycleDao, navHostController: NavHos
} }
Column { Column {
Text( Text(
text = item.model, text = item.name,
color = Color.Black, color = Color.Black,
fontSize = textSize.value.sp, fontSize = textSize.value.sp,
fontWeight = FontWeight.Bold, fontWeight = FontWeight.Bold,
@ -122,51 +136,22 @@ fun ListProduct(item: Bicycle, bicycleDao: BicycleDao, navHostController: NavHos
.fillMaxWidth() .fillMaxWidth()
.padding(top = 8.dp) .padding(top = 8.dp)
) )
AnimatedVisibility( AnimatedVisibility(
visible = isFullAbout, visible = isFullAbout,
enter = fadeIn() + expandIn(), enter = fadeIn() + expandIn(),
exit = fadeOut() + shrinkOut(), exit = fadeOut() + shrinkOut(),
modifier = Modifier.scale(scale) modifier = Modifier.scale(scale)
) { ) {
Column { Text(
Text( color = Color.Black,
color = Color.Black, text = item.about,
text = item.brand, maxLines = 10,
maxLines = 10, fontSize = 14.sp,
fontSize = 14.sp, textAlign = TextAlign.Center,
textAlign = TextAlign.Center, modifier = Modifier
modifier = Modifier .fillMaxWidth()
.fillMaxWidth() .padding(bottom = 8.dp)
) )
Text(
color = Color.Black,
text = item.color,
maxLines = 10,
fontSize = 14.sp,
textAlign = TextAlign.Center,
modifier = Modifier
.fillMaxWidth()
)
Text(
color = Color.Black,
text = item.brand,
maxLines = 10,
fontSize = 14.sp,
textAlign = TextAlign.Center,
modifier = Modifier
.fillMaxWidth()
)
Text(
color = Color.Black,
text = if (item.userId != null) "Занято" else "Свободно",
maxLines = 10,
fontSize = 14.sp,
textAlign = TextAlign.Center,
modifier = Modifier
.fillMaxWidth()
)
}
} }
} }
} }

View File

@ -1,247 +0,0 @@
package com.example.labwork.pages.product
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Button
import androidx.compose.material.ButtonDefaults
import androidx.compose.material.Text
import androidx.compose.material.TextField
import androidx.compose.material.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavHostController
import com.example.labwork.database.DAO.BicycleDao
import com.example.labwork.models.Bicycle
import com.example.labwork.ui.theme.LightBluePolitech
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
@Composable
fun FormNewProduct(bicycleDao: BicycleDao, navHostController: NavHostController) {
val isFormVisible = remember { mutableStateOf(false) }
var brand by remember { mutableStateOf("") }
var model by remember { mutableStateOf("") }
var color by remember { mutableStateOf("") }
Button(
colors = ButtonDefaults.buttonColors(backgroundColor = LightBluePolitech),
modifier = Modifier
.fillMaxWidth()
.padding(9.dp),
onClick = {
// Установите значение состояния открытия формы как true
isFormVisible.value = true
},
shape = RoundedCornerShape(15.dp)
) {
Text(
text = "Добавить",
color = Color.White,
fontSize = 10.sp,
textAlign = TextAlign.Center
)
}
if (isFormVisible.value) {
Column(
modifier = Modifier.fillMaxWidth()
) {
// Поле ввода для бренда
TextField(
value = brand,
onValueChange = { brand = it },
placeholder = { Text("Бренд") },
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 8.dp),
colors = TextFieldDefaults.textFieldColors(backgroundColor = Color.White)
)
// Поле ввода для модели
TextField(
value = model,
onValueChange = { model = it },
placeholder = { Text("Модель") },
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 8.dp),
colors = TextFieldDefaults.textFieldColors(backgroundColor = Color.White)
)
// Поле ввода для цвета
TextField(
value = color,
onValueChange = { color = it },
placeholder = { Text("Цвет") },
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 8.dp),
colors = TextFieldDefaults.textFieldColors(backgroundColor = Color.White)
)
Button(
colors = ButtonDefaults.buttonColors(backgroundColor = LightBluePolitech),
modifier = Modifier
.fillMaxWidth()
.padding(9.dp),
onClick = {
GlobalScope.launch {
val newBicycle = Bicycle(null, brand, model, color, null)
bicycleDao.insertBicycle(newBicycle)
}
isFormVisible.value = false
navHostController.navigate("ListProduct")
},
shape = RoundedCornerShape(15.dp)
) {
Text(
text = "Принять",
color = Color.White,
fontSize = 10.sp,
textAlign = TextAlign.Center
)
}
Button(
colors = ButtonDefaults.buttonColors(backgroundColor = LightBluePolitech),
modifier = Modifier
.fillMaxWidth()
.padding(9.dp),
onClick = {
isFormVisible.value = false
navHostController.navigate("ListProduct")
},
shape = RoundedCornerShape(15.dp)
) {
Text(
text = "Отменить",
color = Color.White,
fontSize = 10.sp,
textAlign = TextAlign.Center
)
}
}
}
}
@Composable
fun FormUpdateProduct(item:Bicycle, bicycleDao: BicycleDao, navHostController: NavHostController) {
val isFormVisible = remember { mutableStateOf(false) }
var brand by remember { mutableStateOf(item.brand) }
var model by remember { mutableStateOf(item.model) }
var color by remember { mutableStateOf(item.color) }
Button(
colors = ButtonDefaults.buttonColors(backgroundColor = LightBluePolitech),
modifier = Modifier
.padding(start = 9.dp, bottom = 9.dp)
.size(height = 32.dp, width = 128.dp),
onClick = {
// Установите значение состояния открытия формы как true
isFormVisible.value = true
},
shape = RoundedCornerShape(15.dp)
) {
Text(
text = "Редактировать",
color = Color.White,
fontSize = 10.sp,
textAlign = TextAlign.Center
)
}
if (isFormVisible.value) {
Column(
modifier = Modifier.fillMaxWidth()
) {
// Поле ввода для бренда
TextField(
value = brand,
onValueChange = { brand = it },
placeholder = { Text("Бренд") },
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 8.dp),
colors = TextFieldDefaults.textFieldColors(backgroundColor = Color.White)
)
// Поле ввода для модели
TextField(
value = model,
onValueChange = { model = it },
placeholder = { Text("Модель") },
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 8.dp),
colors = TextFieldDefaults.textFieldColors(backgroundColor = Color.White)
)
// Поле ввода для цвета
TextField(
value = color,
onValueChange = { color = it },
placeholder = { Text("Цвет") },
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 8.dp),
colors = TextFieldDefaults.textFieldColors(backgroundColor = Color.White)
)
Button(
colors = ButtonDefaults.buttonColors(backgroundColor = LightBluePolitech),
modifier = Modifier
.fillMaxWidth()
.padding(9.dp),
onClick = {
GlobalScope.launch {
val newBicycle = bicycleDao.getBicycleById(item.id)
newBicycle.model = model
newBicycle.color = color
newBicycle.brand = brand
bicycleDao.updateBicycle(newBicycle)
}
isFormVisible.value = false
navHostController.navigate("ListProduct")
},
shape = RoundedCornerShape(15.dp)
) {
Text(
text = "Принять",
color = Color.White,
fontSize = 10.sp,
textAlign = TextAlign.Center
)
}
Button(
colors = ButtonDefaults.buttonColors(backgroundColor = LightBluePolitech),
modifier = Modifier
.fillMaxWidth()
.padding(9.dp),
onClick = {
isFormVisible.value = false
navHostController.navigate("ListProduct")
},
shape = RoundedCornerShape(15.dp)
) {
Text(
text = "Отменить",
color = Color.White,
fontSize = 10.sp,
textAlign = TextAlign.Center
)
}
}
}
}

View File

@ -1,162 +0,0 @@
package com.example.labwork.pages.user
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Button
import androidx.compose.material.ButtonDefaults
import androidx.compose.material.IconButton
import androidx.compose.material.Text
import androidx.compose.material.TextField
import androidx.compose.material.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavController
import androidx.navigation.NavHostController
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.models.User
import com.example.labwork.ui.theme.LightBluePolitech
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
@Composable
fun LoginPage(navController: NavController, userDao: UserDao, navHostController: NavHostController) {
var email by remember { mutableStateOf("") }
var password by remember { mutableStateOf("") }
var userPassword by remember { mutableStateOf("") }
var user by remember { mutableStateOf<User?>(null) }
var showPassword by remember { mutableStateOf(false) }
var acceptLogin by remember { mutableStateOf(false) }
if (acceptLogin == true) {
user?.let { userProfile ->
ProfileForm(item = userProfile, userDao = userDao, navHostController = navHostController)
}
}
else {
Column(
modifier = Modifier
.fillMaxSize()
.padding(16.dp),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Image(
painter = painterResource(R.drawable.logo_ulstu),
contentDescription = "Logo",
modifier = Modifier.size(200.dp)
)
Spacer(modifier = Modifier.height(16.dp))
TextField(
value = email,
onValueChange = { email = it },
label = { Text("Почта") },
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp),
textStyle = TextStyle(fontSize = 16.sp),
colors = TextFieldDefaults.textFieldColors(
cursorColor = LightBluePolitech,
backgroundColor = Color.White,
textColor = LightBluePolitech,
unfocusedLabelColor = LightBluePolitech,
focusedIndicatorColor = LightBluePolitech,
unfocusedIndicatorColor = LightBluePolitech,
focusedLabelColor = LightBluePolitech
),
singleLine = true
)
Spacer(modifier = Modifier.height(8.dp))
TextField(
value = password,
onValueChange = { password = it },
label = { Text("Пароль") },
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp),
textStyle = TextStyle(fontSize = 16.sp),
colors = TextFieldDefaults.textFieldColors(
cursorColor = LightBluePolitech,
backgroundColor = Color.White,
textColor = LightBluePolitech,
unfocusedLabelColor = LightBluePolitech,
focusedIndicatorColor = LightBluePolitech,
unfocusedIndicatorColor = LightBluePolitech,
focusedLabelColor = LightBluePolitech
),
singleLine = true,
visualTransformation = if (showPassword) VisualTransformation.None else PasswordVisualTransformation(),
trailingIcon = {
IconButton(
onClick = { showPassword = !showPassword }
) {
Image(
painter = if (showPassword) painterResource(R.drawable.baseline_visibility) else painterResource(
R.drawable.baseline_visibility_off
),
contentDescription = "LogoVissable",
modifier = Modifier.size(24.dp)
)
}
}
)
Spacer(modifier = Modifier.height(8.dp))
Button(
onClick = {
GlobalScope.launch {
userPassword = userDao.getPasswordByEmail(email)
user = userDao.getUserByEmail(email)
if (userPassword == password) {
acceptLogin = true
//navHostController.navigate("Profile")
}
}
},
colors = ButtonDefaults.buttonColors(backgroundColor = LightBluePolitech,),
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp)
) {
Text(text = "Авторизоваться", color = Color.White)
}
Spacer(modifier = Modifier.height(8.dp))
Button(
onClick = { navController.navigate("register") },
colors = ButtonDefaults.buttonColors(backgroundColor = LightBluePolitech),
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp)
) {
Text(text = "Регистрация", color = Color.White)
}
}
}
}

View File

@ -1,115 +0,0 @@
package com.example.labwork.pages.user
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Button
import androidx.compose.material.ButtonDefaults
import androidx.compose.material.Text
import androidx.compose.material.TextField
import androidx.compose.material.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavHostController
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 com.example.labwork.ui.theme.LightBluePolitech
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
@Composable
fun ProfileForm(item: User, userDao: UserDao, navHostController: NavHostController) {
var email by remember { mutableStateOf(item.email) }
var name by remember { mutableStateOf(item.name) }
var password by remember { mutableStateOf(item.password) }
Column(
modifier = Modifier.fillMaxWidth()
) {
TextField(
value = email,
onValueChange = { email = it },
placeholder = { Text("Почта") },
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 8.dp),
colors = TextFieldDefaults.textFieldColors(backgroundColor = Color.White)
)
TextField(
value = name,
onValueChange = { name = it },
placeholder = { Text("Имя") },
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 8.dp),
colors = TextFieldDefaults.textFieldColors(backgroundColor = Color.White)
)
TextField(
value = password,
onValueChange = { password = it },
placeholder = { Text("Пароль") },
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 8.dp),
colors = TextFieldDefaults.textFieldColors(backgroundColor = Color.White)
)
Button(
colors = ButtonDefaults.buttonColors(backgroundColor = LightBluePolitech),
modifier = Modifier
.fillMaxWidth()
.padding(9.dp),
onClick = {
GlobalScope.launch {
val newUser = userDao.getUserById(item.id!!)
newUser.email = email
newUser.name = name
newUser.password = password
userDao.updateUser(newUser)
}
navHostController.navigate("ListProduct")
},
shape = RoundedCornerShape(15.dp)
) {
Text(
text = "Принять",
color = Color.White,
fontSize = 10.sp,
textAlign = TextAlign.Center
)
}
Button(
colors = ButtonDefaults.buttonColors(backgroundColor = LightBluePolitech),
modifier = Modifier
.fillMaxWidth()
.padding(9.dp),
onClick = {
navHostController.navigate("ListProduct")
},
shape = RoundedCornerShape(15.dp)
) {
Text(
text = "Отменить",
color = Color.White,
fontSize = 10.sp,
textAlign = TextAlign.Center
)
}
}
}

View File

@ -1,55 +0,0 @@
package com.example.labwork.pages.user
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material.Button
import androidx.compose.material.ButtonDefaults
import androidx.compose.material.IconButton
import androidx.compose.material.Text
import androidx.compose.material.TextField
import androidx.compose.material.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavController
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import com.example.labwork.R
import com.example.labwork.database.DAO.BicycleDao
import com.example.labwork.database.DAO.UserDao
import com.example.labwork.ui.theme.LightBluePolitech
@Composable
fun RegisteryOrLogin(userDao: UserDao, navHostController: NavHostController) {
val navController = rememberNavController()
NavHost(navController, startDestination = "login") {
composable("login") {
LoginPage(navController, userDao, navHostController)
}
composable("register") {
RegisteryPage(navController, userDao, navHostController)
}
}
}

View File

@ -1,5 +0,0 @@
<vector android:autoMirrored="true" android:height="24dp"
android:tint="#004890" android:viewportHeight="24"
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M15.5,5.5c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2 -2,0.9 -2,2 0.9,2 2,2zM5,12c-2.8,0 -5,2.2 -5,5s2.2,5 5,5 5,-2.2 5,-5 -2.2,-5 -5,-5zM5,20.5c-1.9,0 -3.5,-1.6 -3.5,-3.5s1.6,-3.5 3.5,-3.5 3.5,1.6 3.5,3.5 -1.6,3.5 -3.5,3.5zM10.8,10.5l2.4,-2.4 0.8,0.8c1.3,1.3 3,2.1 5.1,2.1L19.1,9c-1.5,0 -2.7,-0.6 -3.6,-1.5l-1.9,-1.9c-0.5,-0.4 -1,-0.6 -1.6,-0.6s-1.1,0.2 -1.4,0.6L7.8,8.4c-0.4,0.4 -0.6,0.9 -0.6,1.4 0,0.6 0.2,1.1 0.6,1.4L11,14v5h2v-6.2l-2.2,-2.3zM19,12c-2.8,0 -5,2.2 -5,5s2.2,5 5,5 5,-2.2 5,-5 -2.2,-5 -5,-5zM19,20.5c-1.9,0 -3.5,-1.6 -3.5,-3.5s1.6,-3.5 3.5,-3.5 3.5,1.6 3.5,3.5 -1.6,3.5 -3.5,3.5z"/>
</vector>

View File

@ -4,5 +4,5 @@
# Location of the SDK. This is only used by Gradle. # Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the # For customization when using a Version Control System, please read the
# header note. # header note.
#Sun Nov 19 17:10:30 GMT+04:00 2023 #Fri Oct 27 18:44:58 GMT+04:00 2023
sdk.dir=C\:\\android-sdk sdk.dir=C\:\\Users\\kashi\\AppData\\Local\\Android\\Sdk