final
This commit is contained in:
parent
534babe2ea
commit
e3e4d1cacb
@ -94,7 +94,7 @@ import java.util.Properties
|
||||
fun CoffeeList(navController: NavController?) {
|
||||
val openDialog = remember { mutableStateOf(false) }
|
||||
val add = remember { mutableStateOf(false) }
|
||||
val coffee = remember { mutableStateOf(Coffee("", 0.0, "", null,0)) }
|
||||
val coffee = remember { mutableStateOf(Coffee("", 0.0, "", null, 0)) }
|
||||
val context = LocalContext.current
|
||||
val itemsList = remember { mutableStateListOf<Coffee>() }
|
||||
|
||||
@ -163,12 +163,15 @@ fun CoffeeList(navController: NavController?) {
|
||||
)
|
||||
}
|
||||
}
|
||||
AppDatabase.getInstance(context).coffeeDao().getAll().collect { data ->
|
||||
itemsList.clear()
|
||||
itemsList.addAll(data)
|
||||
}
|
||||
}
|
||||
},
|
||||
shape = CircleShape,
|
||||
modifier = Modifier.fillMaxWidth(fraction = 0.75f)
|
||||
) {
|
||||
// Inner content including an icon and a text label
|
||||
Icon(
|
||||
imageVector = Icons.Default.Add,
|
||||
contentDescription = "Favorite",
|
||||
@ -177,7 +180,12 @@ fun CoffeeList(navController: NavController?) {
|
||||
Spacer(Modifier.size(ButtonDefaults.IconSpacing))
|
||||
Text(text = "В корзину")
|
||||
}
|
||||
OutlinedIconButton(onClick = { coffee.value = currentCoffee; add.value = false; openDialog.value = true },
|
||||
OutlinedIconButton(
|
||||
onClick = {
|
||||
coffee.value = currentCoffee
|
||||
add.value = false
|
||||
openDialog.value = true
|
||||
},
|
||||
Modifier
|
||||
.padding(start = 10.dp)
|
||||
.clip(CircleShape)) {
|
||||
@ -277,15 +285,13 @@ fun CoffeeList(navController: NavController?) {
|
||||
fos.close()
|
||||
}
|
||||
|
||||
|
||||
copyFileToSftp(f, "/mnt/nextcloud/data/Zyzf/files/Images")
|
||||
|
||||
|
||||
|
||||
AppDatabase.getInstance(context).coffeeDao().getAll().collect { data ->
|
||||
itemsList.clear()
|
||||
itemsList.addAll(data)
|
||||
}
|
||||
openDialog.value = false
|
||||
}
|
||||
}, modifier = Modifier.padding(0.dp, 10.dp, 0.dp, 30.dp)) {
|
||||
Text("Добавить")
|
||||
@ -315,6 +321,7 @@ fun CoffeeList(navController: NavController?) {
|
||||
itemsList.clear()
|
||||
itemsList.addAll(data)
|
||||
}
|
||||
openDialog.value = false
|
||||
}
|
||||
|
||||
}, modifier = Modifier.padding(0.dp, 10.dp, 0.dp, 30.dp)) {
|
||||
@ -327,10 +334,10 @@ fun CoffeeList(navController: NavController?) {
|
||||
}
|
||||
}
|
||||
|
||||
val REMOTE_HOST = "109.197.199.134"
|
||||
val USERNAME = "zyzf"
|
||||
val PASSWORD = "250303Zyzf-d-grad"
|
||||
val REMOTE_PORT = 2223
|
||||
const val REMOTE_HOST = "109.197.199.134"
|
||||
const val USERNAME = "zyzf"
|
||||
const val PASSWORD = "250303Zyzf-d-grad"
|
||||
const val REMOTE_PORT = 2223
|
||||
|
||||
fun copyFileToSftp(srcFile: File, ftpPath: String): Boolean {
|
||||
|
||||
|
@ -1,13 +1,11 @@
|
||||
package com.zyzf.coffeepreorder.composeui
|
||||
|
||||
import android.content.res.Configuration
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxHeight
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
@ -16,6 +14,7 @@ import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Add
|
||||
import androidx.compose.material.icons.filled.Clear
|
||||
@ -30,25 +29,50 @@ import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateListOf
|
||||
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.ImageBitmap
|
||||
import androidx.compose.ui.res.imageResource
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.navigation.NavController
|
||||
import com.zyzf.coffeepreorder.coffee.model.getCoffee
|
||||
import coil.compose.AsyncImage
|
||||
import coil.request.ImageRequest
|
||||
import com.zyzf.coffeepreorder.R
|
||||
import com.zyzf.coffeepreorder.composeui.navigation.Screen
|
||||
import com.zyzf.coffeepreorder.database.AppDatabase
|
||||
import com.zyzf.coffeepreorder.database.model.Coffee
|
||||
import com.zyzf.coffeepreorder.ui.theme.CoffeePreorderTheme
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@OptIn(ExperimentalMaterial3Api::class, DelicateCoroutinesApi::class)
|
||||
@Composable
|
||||
fun Cart(navController: NavController?) {
|
||||
val openDialog = remember { mutableStateOf(false) }
|
||||
val itemsList = getCoffee().toList()
|
||||
var coffee by remember { mutableStateOf(Coffee("", 0.0, "", null, 0)) }
|
||||
val context = LocalContext.current
|
||||
val itemsList = remember { mutableStateListOf<Coffee>() }
|
||||
LaunchedEffect(Unit) {
|
||||
withContext(Dispatchers.IO) {
|
||||
AppDatabase.getInstance(context).coffeeDao().getAllInCart().collect { data ->
|
||||
itemsList.clear()
|
||||
itemsList.addAll(data)
|
||||
}
|
||||
}
|
||||
}
|
||||
LazyColumn(
|
||||
horizontalAlignment = Alignment.CenterHorizontally) {
|
||||
items(itemsList) { currentCoffee ->
|
||||
@ -57,15 +81,27 @@ fun Cart(navController: NavController?) {
|
||||
.heightIn(max = 140.dp)
|
||||
.padding(bottom = 10.dp, top = 10.dp),
|
||||
horizontalArrangement = Arrangement.SpaceAround) {
|
||||
Image(bitmap = ImageBitmap.imageResource(currentCoffee.image),
|
||||
contentDescription = "Кофе", modifier = Modifier
|
||||
.fillMaxHeight()
|
||||
.weight(1f))
|
||||
AsyncImage(
|
||||
model = ImageRequest.Builder(context = LocalContext.current).data("https://zyzf.space/s/zXgFRTmbR4KMxMH/download?path=&files=coffee_image_" + currentCoffee.uid +".png")
|
||||
.crossfade(true).build(),
|
||||
error = painterResource(R.drawable.ic_broken_image),
|
||||
placeholder = painterResource(R.drawable.loading_img),
|
||||
contentDescription = "Кофе",
|
||||
contentScale = ContentScale.Crop,
|
||||
modifier = Modifier
|
||||
.size(100.dp)
|
||||
.clip(RoundedCornerShape(50.dp))
|
||||
)
|
||||
Column(
|
||||
Modifier
|
||||
.weight(2f)
|
||||
.padding(start = 20.dp)) {
|
||||
Text(text = currentCoffee.name, fontSize = 25.sp)
|
||||
val currentCoffeeName: String = if (currentCoffee.count > 1) {
|
||||
currentCoffee.name + " x" + currentCoffee.count.toString()
|
||||
} else {
|
||||
currentCoffee.name
|
||||
}
|
||||
Text(text = currentCoffeeName, fontSize = 25.sp)
|
||||
Text(text = String.format("%.2f", currentCoffee.cost), fontSize = 20.sp)
|
||||
Text(text = currentCoffee.ingredients, fontSize = 15.sp)
|
||||
Row(
|
||||
@ -73,7 +109,7 @@ fun Cart(navController: NavController?) {
|
||||
.fillMaxWidth()
|
||||
.padding(top = 5.dp)) {
|
||||
Button(
|
||||
onClick = { openDialog.value = true },
|
||||
onClick = { coffee = currentCoffee; openDialog.value = true },
|
||||
shape = CircleShape,
|
||||
modifier = Modifier.padding(start = 10.dp, end = 10.dp),
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
@ -81,7 +117,6 @@ fun Cart(navController: NavController?) {
|
||||
contentColor = MaterialTheme.colorScheme.error
|
||||
)
|
||||
) {
|
||||
// Inner content including an icon and a text label
|
||||
Icon(
|
||||
imageVector = Icons.Default.Clear,
|
||||
contentDescription = "Favorite",
|
||||
@ -122,8 +157,13 @@ fun Cart(navController: NavController?) {
|
||||
confirmButton = {
|
||||
TextButton(
|
||||
onClick = {
|
||||
GlobalScope.launch (Dispatchers.Main) {
|
||||
coffee.uid?.let {
|
||||
AppDatabase.getInstance(context).cartDao().deleteCoffee(it, 1)
|
||||
}
|
||||
}
|
||||
|
||||
openDialog.value = false
|
||||
/* TODO */
|
||||
}
|
||||
) {
|
||||
Text("Да")
|
||||
|
@ -67,7 +67,7 @@ fun Login(navController: NavController?) {
|
||||
placeholder = painterResource(R.drawable.loading_img),
|
||||
contentDescription = "Кофе",
|
||||
contentScale = ContentScale.Crop,
|
||||
modifier = Modifier.size(100.dp)
|
||||
modifier = Modifier.size(150.dp)
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.padding(all = 20.dp))
|
||||
@ -93,6 +93,7 @@ fun Login(navController: NavController?) {
|
||||
GlobalScope.launch (Dispatchers.Main) {
|
||||
user = AppDatabase.getInstance(context).userDao().tryLogin(login, password)
|
||||
if (user != null) {
|
||||
AppDatabase.getInstance(context).userDao().logout()
|
||||
AppDatabase.getInstance(context).userDao().setLogined(user!!.uid!!)
|
||||
navController?.navigate(Screen.CoffeeList.route)
|
||||
} else {
|
||||
@ -100,7 +101,6 @@ fun Login(navController: NavController?) {
|
||||
login = "Неверный логин или пароль"
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
shape = CircleShape,
|
||||
modifier = Modifier.fillMaxWidth(fraction = 0.75f),
|
||||
@ -109,7 +109,6 @@ fun Login(navController: NavController?) {
|
||||
contentColor = MaterialTheme.colorScheme.primary
|
||||
)
|
||||
) {
|
||||
// Inner content including an icon and a text label
|
||||
Icon(
|
||||
imageVector = Icons.Default.Check,
|
||||
contentDescription = "Favorite",
|
||||
|
@ -30,17 +30,22 @@ import androidx.compose.material3.TimePicker
|
||||
import androidx.compose.material3.rememberDatePickerState
|
||||
import androidx.compose.material3.rememberTimePickerState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.window.Dialog
|
||||
import androidx.compose.ui.window.DialogProperties
|
||||
import androidx.navigation.NavController
|
||||
import com.zyzf.coffeepreorder.composeui.navigation.Screen
|
||||
import com.zyzf.coffeepreorder.database.AppDatabase
|
||||
import com.zyzf.coffeepreorder.ui.theme.CoffeePreorderTheme
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Calendar
|
||||
import java.util.Date
|
||||
@ -55,6 +60,13 @@ fun Order(navController: NavController?) {
|
||||
val datePickerState = rememberDatePickerState(initialSelectedDateMillis = calendar.timeInMillis)
|
||||
val timePickerState = rememberTimePickerState(is24Hour = true, initialHour = calendar.get(Calendar.HOUR_OF_DAY), initialMinute = calendar.get(Calendar.MINUTE))
|
||||
val formatter = SimpleDateFormat("dd.MM.yyyy", Locale.ROOT)
|
||||
val context = LocalContext.current
|
||||
val sum = remember { mutableStateOf(0.0) }
|
||||
LaunchedEffect(Unit) {
|
||||
withContext(Dispatchers.IO) {
|
||||
sum.value = AppDatabase.getInstance(context).coffeeDao().getSumInCart()
|
||||
}
|
||||
}
|
||||
Column(Modifier.padding(all = 10.dp), horizontalAlignment = Alignment.CenterHorizontally) {
|
||||
Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.Center,
|
||||
verticalAlignment = Alignment.CenterVertically) {
|
||||
@ -91,7 +103,7 @@ fun Order(navController: NavController?) {
|
||||
}
|
||||
}
|
||||
Spacer(modifier = Modifier.padding(all = 20.dp))
|
||||
Text(text = "Сумма: xxx")
|
||||
Text(text = "Сумма: ${sum.value}")
|
||||
}
|
||||
Box(modifier = Modifier.fillMaxSize()) {
|
||||
ExtendedFloatingActionButton(
|
||||
|
@ -26,8 +26,10 @@ import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
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
|
||||
@ -43,41 +45,51 @@ import com.zyzf.coffeepreorder.composeui.navigation.Screen
|
||||
import com.zyzf.coffeepreorder.database.AppDatabase
|
||||
import com.zyzf.coffeepreorder.database.model.User
|
||||
import com.zyzf.coffeepreorder.ui.theme.CoffeePreorderTheme
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
@Composable
|
||||
fun Profile(navController: NavController?) {
|
||||
val openDialogEdit = remember { mutableStateOf(false) }
|
||||
val openDialogExit = remember { mutableStateOf(false) }
|
||||
val openDialogDelete = remember { mutableStateOf(false) }
|
||||
val context = LocalContext.current
|
||||
val user = remember { mutableStateOf<User>(User("", "", "", "")) }
|
||||
var user: User by remember { mutableStateOf(User("", "", "", "")) }
|
||||
var userLogin by remember { mutableStateOf("") }
|
||||
var userFIO by remember { mutableStateOf("") }
|
||||
var userPhone by remember { mutableStateOf("") }
|
||||
val userOldPsswd = remember { mutableStateOf("") }
|
||||
val userNewPsswd = remember { mutableStateOf("") }
|
||||
val userNewPsswdConf = remember { mutableStateOf("") }
|
||||
LaunchedEffect(Unit) {
|
||||
withContext(Dispatchers.IO) {
|
||||
user.value = AppDatabase.getInstance(context).userDao().getLogined()
|
||||
user = AppDatabase.getInstance(context).userDao().getLogined()
|
||||
userLogin = user.login
|
||||
userFIO = user.fio
|
||||
userPhone = user.phone
|
||||
}
|
||||
}
|
||||
Column(Modifier.padding(all = 10.dp), horizontalAlignment = Alignment.CenterHorizontally) {
|
||||
OutlinedTextField(modifier = Modifier.fillMaxWidth(),
|
||||
value = user.value.login, onValueChange = {user.value.login = it},
|
||||
value = userLogin, onValueChange = {userLogin = it},
|
||||
label = {
|
||||
Text(stringResource(id = R.string.profile_login_label))
|
||||
},
|
||||
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text)
|
||||
)
|
||||
OutlinedTextField(modifier = Modifier.fillMaxWidth(),
|
||||
value = user.value.fio, onValueChange = {user.value.fio = it},
|
||||
value = userFIO, onValueChange = {userFIO = it},
|
||||
label = {
|
||||
Text(stringResource(id = R.string.profile_fio_label))
|
||||
},
|
||||
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text)
|
||||
)
|
||||
OutlinedTextField(modifier = Modifier.fillMaxWidth(),
|
||||
value = user.value.phone, onValueChange = {user.value.phone = it},
|
||||
value = userPhone, onValueChange = {userPhone = it},
|
||||
label = {
|
||||
Text(stringResource(id = R.string.profile_phone_label))
|
||||
}
|
||||
@ -180,8 +192,13 @@ fun Profile(navController: NavController?) {
|
||||
confirmButton = {
|
||||
TextButton(
|
||||
onClick = {
|
||||
GlobalScope.launch (Dispatchers.Main) {
|
||||
if (userOldPsswd.value == user.password && userNewPsswd.value == userNewPsswdConf.value) {
|
||||
AppDatabase.getInstance(context).userDao().update(user.uid!!, userLogin, userFIO, userPhone, userNewPsswd.value)
|
||||
user = AppDatabase.getInstance(context).userDao().getLogined()
|
||||
}
|
||||
}
|
||||
openDialogEdit.value = false
|
||||
/* TODO */
|
||||
}
|
||||
) {
|
||||
Text("Да")
|
||||
@ -215,6 +232,9 @@ fun Profile(navController: NavController?) {
|
||||
confirmButton = {
|
||||
TextButton(
|
||||
onClick = {
|
||||
GlobalScope.launch (Dispatchers.Main) {
|
||||
AppDatabase.getInstance(context).userDao().logout()
|
||||
}
|
||||
openDialogExit.value = false
|
||||
navController?.navigate(Screen.Login.route)
|
||||
}
|
||||
@ -250,8 +270,12 @@ fun Profile(navController: NavController?) {
|
||||
confirmButton = {
|
||||
TextButton(
|
||||
onClick = {
|
||||
GlobalScope.launch (Dispatchers.Main) {
|
||||
AppDatabase.getInstance(context).userDao().logout()
|
||||
AppDatabase.getInstance(context).userDao().delete(user.uid!!)
|
||||
}
|
||||
openDialogDelete.value = false
|
||||
/* TODO */
|
||||
navController?.navigate(Screen.Login.route)
|
||||
}
|
||||
) {
|
||||
Text("Да")
|
||||
|
@ -2,13 +2,13 @@ package com.zyzf.coffeepreorder.composeui
|
||||
|
||||
|
||||
import android.content.res.Configuration
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Add
|
||||
import androidx.compose.material3.Button
|
||||
@ -19,65 +19,110 @@ import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
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.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.input.KeyboardType
|
||||
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.navigation.NavController
|
||||
import coil.compose.AsyncImage
|
||||
import coil.request.ImageRequest
|
||||
import com.zyzf.coffeepreorder.R
|
||||
import com.zyzf.coffeepreorder.composeui.navigation.Screen
|
||||
import com.zyzf.coffeepreorder.database.AppDatabase
|
||||
import com.zyzf.coffeepreorder.database.model.User
|
||||
import com.zyzf.coffeepreorder.ui.theme.CoffeePreorderTheme
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
@Composable
|
||||
fun Register(navController: NavController?) {
|
||||
val context = LocalContext.current
|
||||
var login: String by remember { mutableStateOf("") }
|
||||
var fio: String by remember { mutableStateOf("") }
|
||||
var phone: String by remember { mutableStateOf("") }
|
||||
var password: String by remember { mutableStateOf("") }
|
||||
var confPassword: String by remember { mutableStateOf("") }
|
||||
Column(Modifier.padding(all = 10.dp), horizontalAlignment = Alignment.CenterHorizontally) {
|
||||
Image(
|
||||
painter = painterResource(id = R.drawable.coffee_image),
|
||||
contentDescription = "Logo",
|
||||
AsyncImage(
|
||||
model = ImageRequest.Builder(context = LocalContext.current).data("https://zyzf.space/s/YsHjPo3NDmoptSk/download/coffee_image.png")
|
||||
.crossfade(true).build(),
|
||||
error = painterResource(R.drawable.ic_broken_image),
|
||||
placeholder = painterResource(R.drawable.loading_img),
|
||||
contentDescription = "Кофе",
|
||||
contentScale = ContentScale.Crop,
|
||||
modifier = Modifier.size(150.dp)
|
||||
)
|
||||
Spacer(modifier = Modifier.padding(all = 20.dp))
|
||||
OutlinedTextField(modifier = Modifier.fillMaxWidth(),
|
||||
value = "", onValueChange = {}, readOnly = true,
|
||||
value = login, onValueChange = {login = it},
|
||||
label = {
|
||||
Text(stringResource(id = R.string.profile_login_label))
|
||||
}
|
||||
)
|
||||
OutlinedTextField(modifier = Modifier.fillMaxWidth(),
|
||||
value = "", onValueChange = {}, readOnly = true,
|
||||
value = fio, onValueChange = {fio = it},
|
||||
label = {
|
||||
Text(stringResource(id = R.string.profile_fio_label))
|
||||
}
|
||||
)
|
||||
OutlinedTextField(modifier = Modifier.fillMaxWidth(),
|
||||
value = "", onValueChange = {}, readOnly = true,
|
||||
value = phone, onValueChange = {phone = it},
|
||||
label = {
|
||||
Text(stringResource(id = R.string.profile_phone_label))
|
||||
}
|
||||
)
|
||||
OutlinedTextField(modifier = Modifier.fillMaxWidth(),
|
||||
value = "", onValueChange = {}, readOnly = true,
|
||||
value = password, onValueChange = {password = it},
|
||||
label = {
|
||||
Text(stringResource(id = R.string.profile_oldpassw_label))
|
||||
}
|
||||
Text(stringResource(id = R.string.profile_passw_label))
|
||||
},
|
||||
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Password),
|
||||
visualTransformation = PasswordVisualTransformation()
|
||||
)
|
||||
OutlinedTextField(modifier = Modifier.fillMaxWidth(),
|
||||
value = "", onValueChange = {}, readOnly = true,
|
||||
label = {
|
||||
Text(stringResource(id = R.string.profile_newpassw_label))
|
||||
}
|
||||
)
|
||||
OutlinedTextField(modifier = Modifier.fillMaxWidth(),
|
||||
value = "", onValueChange = {}, readOnly = true,
|
||||
value = confPassword, onValueChange = {confPassword = it},
|
||||
label = {
|
||||
Text(stringResource(id = R.string.profile_confpassw_label))
|
||||
}
|
||||
},
|
||||
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Password),
|
||||
visualTransformation = PasswordVisualTransformation()
|
||||
)
|
||||
Spacer(modifier = Modifier.padding(all = 20.dp))
|
||||
Button(
|
||||
onClick = { navController?.navigate(Screen.CoffeeList.route) },
|
||||
onClick = {
|
||||
var user: User?
|
||||
GlobalScope.launch (Dispatchers.Main) {
|
||||
if (password == confPassword) {
|
||||
AppDatabase.getInstance(context).userDao().insert(User(login, fio, phone, password))
|
||||
user = AppDatabase.getInstance(context).userDao().tryLogin(login, password)
|
||||
if (user != null) {
|
||||
AppDatabase.getInstance(context).userDao().logout()
|
||||
AppDatabase.getInstance(context).userDao().setLogined(user!!.uid!!)
|
||||
navController?.navigate(Screen.CoffeeList.route)
|
||||
} else {
|
||||
password = ""
|
||||
login = "Неверный логин или пароль"
|
||||
}
|
||||
} else {
|
||||
password = ""
|
||||
confPassword = ""
|
||||
login = "Пароль не совпадает с подтверждением пароля"
|
||||
}
|
||||
}
|
||||
},
|
||||
shape = CircleShape,
|
||||
modifier = Modifier.fillMaxWidth(fraction = 0.75f),
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
@ -85,7 +130,6 @@ fun Register(navController: NavController?) {
|
||||
contentColor = MaterialTheme.colorScheme.primary
|
||||
)
|
||||
) {
|
||||
// Inner content including an icon and a text label
|
||||
Icon(
|
||||
imageVector = Icons.Default.Add,
|
||||
contentDescription = "Favorite",
|
||||
|
@ -13,6 +13,12 @@ interface CoffeeDao {
|
||||
@Query("select * from coffee order by name collate nocase asc")
|
||||
fun getAll(): Flow<List<Coffee>>
|
||||
|
||||
@Query("select * from coffee where cart_id is not null and count > 0 order by name collate nocase asc")
|
||||
fun getAllInCart(): Flow<List<Coffee>>
|
||||
|
||||
@Query("select sum(cost) from coffee where cart_id is not null and count > 0")
|
||||
fun getSumInCart(): Double
|
||||
|
||||
@Query("select coffee.uid, name, cost, ingredients, cart_id, count, cart.uid as cart_uid from coffee left join cart on coffee.cart_id = cart.uid where coffee.uid = :uid")
|
||||
suspend fun getByUid(uid: Int): CoffeeWithCart
|
||||
|
||||
|
@ -1,10 +1,8 @@
|
||||
package com.zyzf.coffeepreorder.database.dao
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Delete
|
||||
import androidx.room.Insert
|
||||
import androidx.room.Query
|
||||
import androidx.room.Update
|
||||
import com.zyzf.coffeepreorder.database.model.User
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@ -19,7 +17,7 @@ interface UserDao {
|
||||
@Query("select * from user where uid = :uid")
|
||||
suspend fun getByUid(uid: Int): User
|
||||
|
||||
@Query("select * from user left join user_logined on user_logined.user_id = user.uid limit 1")
|
||||
@Query("select user.uid, login, fio, phone, password from user join user_logined on user_logined.user_id = user.uid limit 1")
|
||||
suspend fun getLogined(): User
|
||||
|
||||
@Query("insert into user_logined (user_id) values (:userId)")
|
||||
@ -30,9 +28,9 @@ interface UserDao {
|
||||
@Insert
|
||||
suspend fun insert(user: User)
|
||||
|
||||
@Update
|
||||
suspend fun update(user: User)
|
||||
@Query("update user set login = :login, fio = :fio, phone = :phone, password = :password where uid = :uid")
|
||||
suspend fun update(uid: Int, login: String, fio: String, phone: String, password: String) : Int
|
||||
|
||||
@Delete
|
||||
suspend fun delete(user: User)
|
||||
@Query("delete from user where uid = :uid")
|
||||
suspend fun delete(uid: Int)
|
||||
}
|
@ -7,7 +7,7 @@ import androidx.room.PrimaryKey
|
||||
@Entity(tableName = "cart")
|
||||
data class Cart(
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
val uid: Int?
|
||||
val uid: Int?,
|
||||
) {
|
||||
@Ignore
|
||||
constructor() : this(null)
|
||||
@ -15,7 +15,7 @@ data class Cart(
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
other as User
|
||||
other as Cart
|
||||
if (uid != other.uid) return false
|
||||
return true
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ data class UserLogined(
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
other as User
|
||||
other as UserLogined
|
||||
if (uid != other.uid) return false
|
||||
return true
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
plugins {
|
||||
id("com.android.application") version "8.1.3" apply false
|
||||
id("com.android.application") version "8.1.4" apply false
|
||||
id("org.jetbrains.kotlin.android") version "1.9.10" apply false
|
||||
id("com.google.devtools.ksp") version "1.9.10-1.0.13" apply false
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user