This commit is contained in:
Ismailov_Rovshan 2023-12-20 11:51:58 +04:00
parent 0d8d318a0c
commit e9bc8e9792
7 changed files with 72 additions and 55 deletions

View File

@ -1,5 +1,7 @@
package com.example.myapplication.components
import ButtonNice
import TextNice
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.ImageDecoder
@ -9,7 +11,9 @@ import android.provider.MediaStore
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
@ -40,6 +44,8 @@ import com.example.myapplication.database.entities.Product
import com.example.myapplication.viewModels.CategoryViewModel
import com.example.myapplication.viewModels.ProductViewModel
import kotlinx.coroutines.launch
import myColor1
import myColor2
@OptIn(ExperimentalMaterial3Api::class)
@Composable
@ -97,8 +103,13 @@ fun AddProduct(
}
}
Column(modifier = Modifier
.padding(start = 30.dp, end = 30.dp, top = 100.dp)
.verticalScroll(rememberScrollState())) {
.fillMaxSize()
.padding(start = 15.dp, end = 10.dp).verticalScroll(rememberScrollState()),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
TextNice("Добавление товара")
myInput("Название", nameState)
myInput("Описание", infoState)
myInput("Цена", priceState)
@ -109,30 +120,39 @@ fun AddProduct(
contentDescription = "editplaceholder",
contentScale = ContentScale.Crop,
modifier = Modifier
.size(384.dp)
.size(350.dp)
.padding(8.dp)
.align(Alignment.CenterHorizontally))
Button(
onClick = {
launcher.launch("image/*")
},
modifier = Modifier
.fillMaxWidth()
.padding(top = 10.dp)) {
Text("Выбрать картинку", fontSize = 20.sp)
// Button(
// onClick = {
// launcher.launch("image/*")
// },
// modifier = Modifier
// .fillMaxWidth()
// .padding(top = 10.dp)) {
// Text("Выбрать картинку", fontSize = 20.sp)
// }
ButtonNice("Выбрать картинку", myColor1){
launcher.launch("image/*")
}
Button(
onClick = {
coroutineScope.launch {
itemViewModel.insert(Product(null, nameState.value,infoState.value, priceState.value.toDouble(), img.value, categoryState.value!!.id!!))
navController.navigate("main/0")
}
},
modifier = Modifier
.fillMaxWidth()
.padding(top = 10.dp)) {
Text("Сохранить", fontSize = 20.sp)
ButtonNice("Сохранить", myColor2){
coroutineScope.launch {
itemViewModel.insert(Product(null, nameState.value,infoState.value, priceState.value.toDouble(), img.value, categoryState.value!!.id!!))
navController.navigate("main/0")
}
}
// Button(
// onClick = {
// coroutineScope.launch {
// itemViewModel.insert(Product(null, nameState.value,infoState.value, priceState.value.toDouble(), img.value, categoryState.value!!.id!!))
// navController.navigate("main/0")
// }
// },
// modifier = Modifier
// .fillMaxWidth()
// .padding(top = 10.dp)) {
// Text("Сохранить", fontSize = 20.sp)
// }
}
}

View File

@ -88,11 +88,11 @@ fun Main(
contentColor = myColor3
),
contentPadding = PaddingValues(0.dp),
modifier = Modifier.size(50.dp).padding(top = 10.dp)
modifier = Modifier.size(30.dp).padding(top = 10.dp)
) {
Image(
painter = painterResource(id = R.drawable.addphoto),
painter = painterResource(id = R.drawable.add),
contentDescription = null,
modifier = Modifier.size(50.dp)
)

View File

@ -1,5 +1,6 @@
package com.example.myapplication.components
import ButtonNice
import Input
import TextNice
import android.widget.Toast
@ -31,6 +32,9 @@ import com.example.myapplication.database.entities.User
import com.example.myapplication.viewModels.UserViewModel
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import myColor1
import myColor2
import myColor3
@Composable
fun Registration(
@ -46,40 +50,32 @@ fun Registration(
val passState = remember { mutableStateOf("") }
val repeatPassState = remember { mutableStateOf("") }
Column(modifier = Modifier.padding(start=30.dp, end=30.dp, top=100.dp)) {
Column(modifier = Modifier
.fillMaxSize()
.padding(start = 10.dp, end = 10.dp),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
TextNice(text = "Регистрация")
myInput("Email", mailState)
myInput("Логин", loginState)
myInput("Пароль", passState)
myInput("Повторите Пароль", repeatPassState)
Button(
onClick = {
coroutineScope.launch {
if(passState.value != repeatPassState.value) {
val toast = Toast.makeText(context, "Пароли не совпадают", Toast.LENGTH_SHORT)
toast.show()
delay(500)
toast.cancel()
return@launch
}
userViewModel.insert(User(null, mailState.value, loginState.value, passState.value))
navController.navigate("authorization")
ButtonNice(text = "Регистрация", color = myColor1){
coroutineScope.launch {
if(passState.value != repeatPassState.value) {
val toast = Toast.makeText(context, "Пароли не совпадают", Toast.LENGTH_SHORT)
toast.show()
delay(500)
toast.cancel()
return@launch
}
},
modifier = Modifier
.fillMaxWidth()
.padding(top = 10.dp)) {
Text("Регистрация", fontSize = 20.sp)
}
Button(
onClick = {navController.navigate("authorization")},
modifier = Modifier.fillMaxWidth(),
border = BorderStroke(1.dp, Color.Black),
colors= ButtonDefaults.buttonColors(
containerColor= Color.White,
contentColor = Color.Gray
)) {
Text("Авторизация", fontSize = 20.sp, color= Color.Black)
userViewModel.insert(User(null, mailState.value, loginState.value, passState.value))
navController.navigate("authorization")
}
}
ButtonNice(text = "Авторизация", color = myColor2, onClickAction = {navController.navigate("authorization")})
}
}

View File

@ -24,6 +24,7 @@ fun ButtonNice(text: String, color: Color, onClickAction: () -> Unit = {}){
shape = RoundedCornerShape(corner = CornerSize(5.dp)),
colors = ButtonDefaults.buttonColors(
containerColor = color,
contentColor = Color.White
)
) {
Text(text, fontSize = 20.sp, color = Color.Black)

View File

@ -33,7 +33,7 @@ fun myInput(label: String, text: MutableState<String>, height: Dp = 50.dp, modif
errorBorderColor = Color.Transparent
),
modifier = Modifier
.border(1.dp, Color.Black, RoundedCornerShape(10.dp))
.border(1.dp, Color.Black, RoundedCornerShape(5.dp))
.fillMaxWidth()
.height(height),
)
@ -55,7 +55,7 @@ fun passwordInput(label: String, text: MutableState<String>, height: Dp = 50.dp,
),
visualTransformation = PasswordVisualTransformation(),
modifier = Modifier
.border(1.dp, Color.Black, RoundedCornerShape(10.dp))
.border(1.dp, Color.Black, RoundedCornerShape(5.dp))
.fillMaxWidth()
.height(height),
)

View File

@ -38,6 +38,7 @@ fun ProductCard(product: ProductOld, onClickAction: () -> Unit) {
ButtonNice(text ="Добавить в корзину" , color = myColor1, onClickAction)
}
}
@Preview(showBackground = true)
@Composable
fun ProductCardPreview() {

View File

@ -13,7 +13,6 @@ interface AppContainer {
val productRepository: ProductRepository
val categoryRepository: CategoryRepository
}
class AppDataContainer(private val context: Context) : AppContainer {
override val userRepository: UserRepository by lazy {
OfflineUserRepository(AppDb.getInstance(context).userDao())