minor fixes
This commit is contained in:
parent
85bb4ebf41
commit
07b8aea79f
@ -40,8 +40,6 @@ interface MyServerService {
|
||||
@Body user: UserModelRemote
|
||||
) :UserModelRemote?
|
||||
|
||||
@GET("user")
|
||||
suspend fun getUser(@Header("Authorization") token: String) : UserModelRemote?
|
||||
|
||||
//
|
||||
// PRODUCTS
|
||||
|
@ -10,6 +10,7 @@ import com.example.shawarma.data.api.models.ProductListResponse
|
||||
import com.example.shawarma.data.api.models.toProductModel
|
||||
import com.example.shawarma.data.db.AppDatabase
|
||||
import com.example.shawarma.data.models.ProductModel
|
||||
import kotlinx.coroutines.flow.first
|
||||
import java.io.IOException
|
||||
|
||||
@OptIn(ExperimentalPagingApi::class)
|
||||
@ -50,13 +51,24 @@ class ProductRemoteMediator (
|
||||
"items" -> {
|
||||
serverService.getItemsList(after = loadKey, token = token)
|
||||
}
|
||||
|
||||
else -> {ProductListResponse()}
|
||||
}
|
||||
|
||||
database.withTransaction {
|
||||
|
||||
if (loadType == LoadType.REFRESH) {
|
||||
productDao.deleteByQuery(query)
|
||||
if (query != "items") {
|
||||
productDao.deleteByQuery(query)
|
||||
}
|
||||
else {
|
||||
val present = productDao.getItemsByLoadKey(loadKey).first()
|
||||
val responseProducts = response.products.map { it -> it.toProductModel() }
|
||||
for (product in present) {
|
||||
if (product !in responseProducts ) {
|
||||
productDao.delete(product)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val products = mutableListOf<ProductModel>()
|
||||
|
@ -9,6 +9,7 @@ import androidx.room.Query
|
||||
import androidx.room.Update
|
||||
import com.example.shawarma.data.models.ProductModel
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@Dao
|
||||
interface ProductDao {
|
||||
@Insert(onConflict = REPLACE)
|
||||
@ -47,6 +48,9 @@ interface ProductDao {
|
||||
@Query("select * from products")
|
||||
fun getPagedItems(): PagingSource<Int, ProductModel>
|
||||
|
||||
@Query("select * from products where products.id > :loadKey limit 20")
|
||||
fun getItemsByLoadKey(loadKey: Int): Flow<List<ProductModel>>
|
||||
|
||||
@Query("delete from products where products.product_old_price is null")
|
||||
fun deleteAllProducts()
|
||||
|
||||
|
@ -19,12 +19,4 @@ data class OrderModel(
|
||||
val date: String
|
||||
)
|
||||
|
||||
fun getOrdersByUserId() : List<OrderModel> {
|
||||
return listOf(
|
||||
)
|
||||
}
|
||||
|
||||
fun getAllOrders() : List<OrderModel> {
|
||||
return listOf(
|
||||
)
|
||||
}
|
||||
|
@ -29,8 +29,3 @@ data class ProductModel(
|
||||
}
|
||||
}
|
||||
|
||||
fun getProducts() :List<ProductModel> {
|
||||
return listOf(
|
||||
)
|
||||
|
||||
}
|
||||
|
@ -27,7 +27,6 @@ class ProductRepository @Inject constructor(
|
||||
return restRepository.update(product, token)
|
||||
}
|
||||
suspend fun delete(product: ProductModel, token: String) {
|
||||
//orderProductDao.deleteByProductId(product.id!!)
|
||||
productDao.delete(product)
|
||||
return restRepository.delete(product.id!!, token)
|
||||
}
|
||||
|
@ -17,9 +17,6 @@ class UserRepository @Inject constructor(
|
||||
suspend fun delete (user: UserModel) {
|
||||
return userDao.delete(user)
|
||||
}
|
||||
fun getAll(): Flow<List<UserModel>> {
|
||||
return userDao.getAll()
|
||||
}
|
||||
fun getById(id: Int): Flow<UserModel> {
|
||||
return userDao.getById(id)
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
||||
import androidx.compose.ui.text.input.TextFieldValue
|
||||
import androidx.compose.ui.text.style.TextDecoration
|
||||
import androidx.compose.ui.unit.dp
|
||||
@ -155,7 +156,8 @@ fun AuthorizationCard(navHostController: NavHostController) {
|
||||
)
|
||||
.size(208.dp, (50).dp),
|
||||
placeholder = "Пароль",
|
||||
singleLine = true
|
||||
singleLine = true,
|
||||
visualTransformation = PasswordVisualTransformation('*')
|
||||
)
|
||||
Button(
|
||||
onClick = {
|
||||
|
@ -32,6 +32,7 @@ import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.compose.ui.zIndex
|
||||
@ -187,13 +188,19 @@ fun PaidItem(order : OrderWithProducts) {
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 20.dp)
|
||||
) {
|
||||
Text(
|
||||
text = order.orderWithProducts[index].product!!.title,
|
||||
fontFamily = NunitoFamily,
|
||||
fontSize = 20.sp,
|
||||
modifier = Modifier.padding(top = 15.dp),
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth(0.5f)
|
||||
) {
|
||||
Text(
|
||||
text = order.orderWithProducts[index].product!!.title,
|
||||
fontFamily = NunitoFamily,
|
||||
fontSize = 20.sp,
|
||||
modifier = Modifier.padding(top = 15.dp),
|
||||
fontWeight = FontWeight.Bold,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
}
|
||||
Text(
|
||||
text = "x" + order.orderWithProducts[index].orderProductModel.quantity,
|
||||
fontFamily = NunitoFamily,
|
||||
@ -252,12 +259,18 @@ fun CartItem(order : OrderWithProducts) {
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
Text(
|
||||
text = order.orderWithProducts[index].product!!.title,
|
||||
fontFamily = NunitoFamily,
|
||||
fontSize = 20.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth(0.5f)
|
||||
) {
|
||||
Text(
|
||||
text = order.orderWithProducts[index].product!!.title,
|
||||
fontFamily = NunitoFamily,
|
||||
fontSize = 20.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
}
|
||||
Text(
|
||||
text = (order.orderWithProducts[index].orderProductModel.quantity * order.orderWithProducts[index].product!!.price).toString() + " руб.",
|
||||
fontFamily = NunitoFamily,
|
||||
|
@ -28,6 +28,7 @@ import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextDecoration
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.compose.ui.zIndex
|
||||
@ -137,7 +138,10 @@ fun DiscountCard(product : ProductModel){
|
||||
fontFamily = NunitoFamily,
|
||||
fontSize = 20.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
modifier = Modifier.padding(top = 10.dp)
|
||||
modifier = Modifier.padding(top = 10.dp),
|
||||
maxLines = 1,
|
||||
softWrap = true,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
Image(
|
||||
painter = painterResource(id = R.drawable.shawarma2),
|
||||
|
@ -27,6 +27,7 @@ import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.compose.ui.zIndex
|
||||
@ -140,7 +141,10 @@ fun ProductCard(product: ProductModel){
|
||||
fontFamily = NunitoFamily,
|
||||
fontSize = 20.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
modifier = Modifier.padding(top = 10.dp)
|
||||
modifier = Modifier.padding(top = 10.dp),
|
||||
maxLines = 1,
|
||||
softWrap = true,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
Image(
|
||||
painter = painterResource(id = R.drawable.shawarma2),
|
||||
|
@ -27,6 +27,7 @@ import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.compose.ui.zIndex
|
||||
@ -113,7 +114,7 @@ fun ProductsList(navHostController: NavHostController){
|
||||
products.itemCount,
|
||||
key = products.itemKey()
|
||||
) { index ->
|
||||
ProductItem(products[index]!!, navHostController, productsViewModel, searchToken)
|
||||
ProductItem(products[index]!!, navHostController, searchToken)
|
||||
Spacer(modifier = Modifier.height(20.dp))
|
||||
if (index == products.itemCount - 1) {
|
||||
Spacer(modifier = Modifier.height(70.dp))
|
||||
@ -125,7 +126,8 @@ fun ProductsList(navHostController: NavHostController){
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun ProductItem(product: ProductModel, navHostController: NavHostController, productsViewModel: ProductsViewModel, token: String){
|
||||
fun ProductItem(product: ProductModel, navHostController: NavHostController, token: String){
|
||||
val productsViewModel: ProductsViewModel = hiltViewModel<ProductsViewModel>()
|
||||
Card(
|
||||
border = BorderStroke(width = 2.dp, color = MyOrange),
|
||||
shape = RoundedCornerShape(size = 20.dp),
|
||||
@ -145,7 +147,9 @@ fun ProductItem(product: ProductModel, navHostController: NavHostController, pro
|
||||
text = product.title,
|
||||
fontFamily = NunitoFamily,
|
||||
fontSize = 20.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
fontWeight = FontWeight.Bold,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
if (product.oldPrice != null) {
|
||||
Text(
|
||||
|
@ -24,6 +24,7 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
||||
import androidx.compose.ui.text.input.TextFieldValue
|
||||
import androidx.compose.ui.text.style.TextDecoration
|
||||
import androidx.compose.ui.unit.dp
|
||||
@ -145,7 +146,8 @@ fun RegistrationCard(navHostController: NavHostController){
|
||||
)
|
||||
.size(208.dp, (50).dp),
|
||||
placeholder = "Пароль",
|
||||
singleLine = true
|
||||
singleLine = true,
|
||||
visualTransformation = PasswordVisualTransformation('*')
|
||||
)
|
||||
MyTextField(
|
||||
text = passwordRepeat,
|
||||
@ -156,7 +158,8 @@ fun RegistrationCard(navHostController: NavHostController){
|
||||
)
|
||||
.size(208.dp, (50).dp),
|
||||
placeholder = "Повторите пароль",
|
||||
singleLine = true
|
||||
singleLine = true,
|
||||
visualTransformation = PasswordVisualTransformation('*')
|
||||
)
|
||||
Button(
|
||||
onClick = {
|
||||
|
@ -3,6 +3,7 @@ package com.example.shawarma.viewmodels
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import androidx.paging.PagingData
|
||||
import androidx.paging.cachedIn
|
||||
import com.example.shawarma.data.models.ProductModel
|
||||
import com.example.shawarma.data.repos.ProductRepository
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
@ -16,7 +17,7 @@ class ProductsViewModel @Inject constructor(
|
||||
) : ViewModel() {
|
||||
|
||||
fun getItemsList(token:String): Flow<PagingData<ProductModel>> {
|
||||
return productRepository.getAllItemsPaged(token)
|
||||
return productRepository.getAllItemsPaged(token).cachedIn(viewModelScope)
|
||||
}
|
||||
|
||||
fun deleteProduct(product: ProductModel, token: String) {
|
||||
|
@ -1,7 +1,5 @@
|
||||
package com.example.shawarma.widgets
|
||||
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.material.TextField
|
||||
@ -10,9 +8,9 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.MutableState
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.text.Placeholder
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.input.TextFieldValue
|
||||
import androidx.compose.ui.text.input.VisualTransformation
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.example.shawarma.ui.theme.JejuFamily
|
||||
@ -24,7 +22,8 @@ fun MyTextField(
|
||||
onTextChanged: (TextFieldValue) -> Unit,
|
||||
modifier: Modifier,
|
||||
placeholder: String,
|
||||
singleLine: Boolean
|
||||
singleLine: Boolean,
|
||||
visualTransformation: VisualTransformation = VisualTransformation.None
|
||||
) {
|
||||
return TextField(
|
||||
value = text.value,
|
||||
@ -52,6 +51,7 @@ fun MyTextField(
|
||||
unfocusedIndicatorColor = Color.Transparent,
|
||||
disabledIndicatorColor = Color.Transparent
|
||||
),
|
||||
visualTransformation = visualTransformation,
|
||||
modifier = modifier
|
||||
)
|
||||
}
|
Loading…
Reference in New Issue
Block a user