Сдал
This commit is contained in:
parent
0d8d318a0c
commit
e9bc8e9792
@ -1,5 +1,7 @@
|
|||||||
package com.example.myapplication.components
|
package com.example.myapplication.components
|
||||||
|
|
||||||
|
import ButtonNice
|
||||||
|
import TextNice
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.graphics.BitmapFactory
|
import android.graphics.BitmapFactory
|
||||||
import android.graphics.ImageDecoder
|
import android.graphics.ImageDecoder
|
||||||
@ -9,7 +11,9 @@ import android.provider.MediaStore
|
|||||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.compose.foundation.Image
|
import androidx.compose.foundation.Image
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.size
|
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.CategoryViewModel
|
||||||
import com.example.myapplication.viewModels.ProductViewModel
|
import com.example.myapplication.viewModels.ProductViewModel
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import myColor1
|
||||||
|
import myColor2
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
@ -97,8 +103,13 @@ fun AddProduct(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Column(modifier = Modifier
|
Column(modifier = Modifier
|
||||||
.padding(start = 30.dp, end = 30.dp, top = 100.dp)
|
.fillMaxSize()
|
||||||
.verticalScroll(rememberScrollState())) {
|
.padding(start = 15.dp, end = 10.dp).verticalScroll(rememberScrollState()),
|
||||||
|
verticalArrangement = Arrangement.Center,
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally
|
||||||
|
|
||||||
|
) {
|
||||||
|
TextNice("Добавление товара")
|
||||||
myInput("Название", nameState)
|
myInput("Название", nameState)
|
||||||
myInput("Описание", infoState)
|
myInput("Описание", infoState)
|
||||||
myInput("Цена", priceState)
|
myInput("Цена", priceState)
|
||||||
@ -109,30 +120,39 @@ fun AddProduct(
|
|||||||
contentDescription = "editplaceholder",
|
contentDescription = "editplaceholder",
|
||||||
contentScale = ContentScale.Crop,
|
contentScale = ContentScale.Crop,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.size(384.dp)
|
.size(350.dp)
|
||||||
.padding(8.dp)
|
.padding(8.dp)
|
||||||
.align(Alignment.CenterHorizontally))
|
.align(Alignment.CenterHorizontally))
|
||||||
Button(
|
// Button(
|
||||||
onClick = {
|
// onClick = {
|
||||||
|
// launcher.launch("image/*")
|
||||||
|
// },
|
||||||
|
// modifier = Modifier
|
||||||
|
// .fillMaxWidth()
|
||||||
|
// .padding(top = 10.dp)) {
|
||||||
|
// Text("Выбрать картинку", fontSize = 20.sp)
|
||||||
|
// }
|
||||||
|
ButtonNice("Выбрать картинку", myColor1){
|
||||||
launcher.launch("image/*")
|
launcher.launch("image/*")
|
||||||
},
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(top = 10.dp)) {
|
|
||||||
Text("Выбрать картинку", fontSize = 20.sp)
|
|
||||||
}
|
}
|
||||||
Button(
|
ButtonNice("Сохранить", myColor2){
|
||||||
onClick = {
|
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
itemViewModel.insert(Product(null, nameState.value,infoState.value, priceState.value.toDouble(), img.value, categoryState.value!!.id!!))
|
itemViewModel.insert(Product(null, nameState.value,infoState.value, priceState.value.toDouble(), img.value, categoryState.value!!.id!!))
|
||||||
navController.navigate("main/0")
|
navController.navigate("main/0")
|
||||||
}
|
}
|
||||||
},
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(top = 10.dp)) {
|
|
||||||
Text("Сохранить", fontSize = 20.sp)
|
|
||||||
}
|
}
|
||||||
|
// 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)
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,11 +88,11 @@ fun Main(
|
|||||||
contentColor = myColor3
|
contentColor = myColor3
|
||||||
),
|
),
|
||||||
contentPadding = PaddingValues(0.dp),
|
contentPadding = PaddingValues(0.dp),
|
||||||
modifier = Modifier.size(50.dp).padding(top = 10.dp)
|
modifier = Modifier.size(30.dp).padding(top = 10.dp)
|
||||||
|
|
||||||
) {
|
) {
|
||||||
Image(
|
Image(
|
||||||
painter = painterResource(id = R.drawable.addphoto),
|
painter = painterResource(id = R.drawable.add),
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
modifier = Modifier.size(50.dp)
|
modifier = Modifier.size(50.dp)
|
||||||
)
|
)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.example.myapplication.components
|
package com.example.myapplication.components
|
||||||
|
|
||||||
|
import ButtonNice
|
||||||
import Input
|
import Input
|
||||||
import TextNice
|
import TextNice
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
@ -31,6 +32,9 @@ import com.example.myapplication.database.entities.User
|
|||||||
import com.example.myapplication.viewModels.UserViewModel
|
import com.example.myapplication.viewModels.UserViewModel
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import myColor1
|
||||||
|
import myColor2
|
||||||
|
import myColor3
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun Registration(
|
fun Registration(
|
||||||
@ -46,13 +50,19 @@ fun Registration(
|
|||||||
val passState = remember { mutableStateOf("") }
|
val passState = remember { mutableStateOf("") }
|
||||||
val repeatPassState = 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("Email", mailState)
|
||||||
myInput("Логин", loginState)
|
myInput("Логин", loginState)
|
||||||
myInput("Пароль", passState)
|
myInput("Пароль", passState)
|
||||||
myInput("Повторите Пароль", repeatPassState)
|
myInput("Повторите Пароль", repeatPassState)
|
||||||
Button(
|
|
||||||
onClick = {
|
ButtonNice(text = "Регистрация", color = myColor1){
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
if(passState.value != repeatPassState.value) {
|
if(passState.value != repeatPassState.value) {
|
||||||
val toast = Toast.makeText(context, "Пароли не совпадают", Toast.LENGTH_SHORT)
|
val toast = Toast.makeText(context, "Пароли не совпадают", Toast.LENGTH_SHORT)
|
||||||
@ -65,21 +75,7 @@ fun Registration(
|
|||||||
userViewModel.insert(User(null, mailState.value, loginState.value, passState.value))
|
userViewModel.insert(User(null, mailState.value, loginState.value, passState.value))
|
||||||
navController.navigate("authorization")
|
navController.navigate("authorization")
|
||||||
}
|
}
|
||||||
},
|
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
ButtonNice(text = "Авторизация", color = myColor2, onClickAction = {navController.navigate("authorization")})
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -24,6 +24,7 @@ fun ButtonNice(text: String, color: Color, onClickAction: () -> Unit = {}){
|
|||||||
shape = RoundedCornerShape(corner = CornerSize(5.dp)),
|
shape = RoundedCornerShape(corner = CornerSize(5.dp)),
|
||||||
colors = ButtonDefaults.buttonColors(
|
colors = ButtonDefaults.buttonColors(
|
||||||
containerColor = color,
|
containerColor = color,
|
||||||
|
contentColor = Color.White
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
Text(text, fontSize = 20.sp, color = Color.Black)
|
Text(text, fontSize = 20.sp, color = Color.Black)
|
||||||
|
@ -33,7 +33,7 @@ fun myInput(label: String, text: MutableState<String>, height: Dp = 50.dp, modif
|
|||||||
errorBorderColor = Color.Transparent
|
errorBorderColor = Color.Transparent
|
||||||
),
|
),
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.border(1.dp, Color.Black, RoundedCornerShape(10.dp))
|
.border(1.dp, Color.Black, RoundedCornerShape(5.dp))
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.height(height),
|
.height(height),
|
||||||
)
|
)
|
||||||
@ -55,7 +55,7 @@ fun passwordInput(label: String, text: MutableState<String>, height: Dp = 50.dp,
|
|||||||
),
|
),
|
||||||
visualTransformation = PasswordVisualTransformation(),
|
visualTransformation = PasswordVisualTransformation(),
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.border(1.dp, Color.Black, RoundedCornerShape(10.dp))
|
.border(1.dp, Color.Black, RoundedCornerShape(5.dp))
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.height(height),
|
.height(height),
|
||||||
)
|
)
|
||||||
|
@ -38,6 +38,7 @@ fun ProductCard(product: ProductOld, onClickAction: () -> Unit) {
|
|||||||
ButtonNice(text ="Добавить в корзину" , color = myColor1, onClickAction)
|
ButtonNice(text ="Добавить в корзину" , color = myColor1, onClickAction)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Preview(showBackground = true)
|
@Preview(showBackground = true)
|
||||||
@Composable
|
@Composable
|
||||||
fun ProductCardPreview() {
|
fun ProductCardPreview() {
|
||||||
|
@ -13,7 +13,6 @@ interface AppContainer {
|
|||||||
val productRepository: ProductRepository
|
val productRepository: ProductRepository
|
||||||
val categoryRepository: CategoryRepository
|
val categoryRepository: CategoryRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
class AppDataContainer(private val context: Context) : AppContainer {
|
class AppDataContainer(private val context: Context) : AppContainer {
|
||||||
override val userRepository: UserRepository by lazy {
|
override val userRepository: UserRepository by lazy {
|
||||||
OfflineUserRepository(AppDb.getInstance(context).userDao())
|
OfflineUserRepository(AppDb.getInstance(context).userDao())
|
||||||
|
Loading…
Reference in New Issue
Block a user