Compare commits

...

2 Commits

Author SHA1 Message Date
c1b7f45b2c minor fixes 2023-12-26 13:31:53 +04:00
07b8aea79f minor fixes 2023-12-25 16:41:38 +04:00
16 changed files with 82 additions and 58 deletions

View File

@ -1,17 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetDropDown">
<targetSelectedWithDropDown>
<runningDeviceTargetSelectedWithDropDown>
<Target>
<type value="QUICK_BOOT_TARGET" />
<type value="RUNNING_DEVICE_TARGET" />
<deviceKey>
<Key>
<type value="VIRTUAL_DEVICE_PATH" />
<value value="C:\Users\Danya\.android\avd\Pixel_2_API_34_2.avd" />
<value value="C:\Users\Danya\.android\avd\Nexus_5X_API_34_3.avd" />
</Key>
</deviceKey>
</Target>
</targetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2023-10-09T12:44:34.176701300Z" />
</runningDeviceTargetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2023-12-25T13:14:56.067510100Z" />
</component>
</project>

View File

@ -40,8 +40,6 @@ interface MyServerService {
@Body user: UserModelRemote
) :UserModelRemote?
@GET("user")
suspend fun getUser(@Header("Authorization") token: String) : UserModelRemote?
//
// PRODUCTS
@ -122,7 +120,7 @@ interface MyServerService {
return INSTANCE ?: synchronized(this) {
val logger = HttpLoggingInterceptor()
logger.level = HttpLoggingInterceptor.Level.BASIC
val client = UnsafeOkHttpClient.getUnsafeOkHttpClient()
val client = OkHttpClientSettings.getUnsafeOkHttpClient()
return Retrofit.Builder()
.baseUrl(BASE_URL)
.client(client)

View File

@ -11,7 +11,7 @@ import javax.net.ssl.X509TrustManager;
import okhttp3.OkHttpClient;
public class UnsafeOkHttpClient {
public class OkHttpClientSettings {
public static OkHttpClient getUnsafeOkHttpClient() {
try {
// Create a trust manager that does not validate certificate chains

View File

@ -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>()

View File

@ -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()

View File

@ -19,12 +19,4 @@ data class OrderModel(
val date: String
)
fun getOrdersByUserId() : List<OrderModel> {
return listOf(
)
}
fun getAllOrders() : List<OrderModel> {
return listOf(
)
}

View File

@ -29,8 +29,3 @@ data class ProductModel(
}
}
fun getProducts() :List<ProductModel> {
return listOf(
)
}

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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 = {

View File

@ -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,

View File

@ -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),

View File

@ -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),

View File

@ -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
@ -49,10 +50,11 @@ import com.example.shawarma.widgets.ShawarmaLogo2
@Composable
fun ProductsScreen(navHostController: NavHostController) {
val productsViewModel: ProductsViewModel = hiltViewModel<ProductsViewModel>()
Box(
contentAlignment = Alignment.TopCenter
) {
ProductsList(navHostController)
ProductsList(navHostController, productsViewModel)
ShawarmaLogo2()
}
}
@ -60,12 +62,9 @@ fun ProductsScreen(navHostController: NavHostController) {
@Composable
fun ProductsList(navHostController: NavHostController){
fun ProductsList(navHostController: NavHostController, productsViewModel: ProductsViewModel){
val preferencesManager = PreferencesManager(LocalContext.current)
val searchToken = preferencesManager.getData("token", "")
val productsViewModel: ProductsViewModel = hiltViewModel<ProductsViewModel>()
val products = productsViewModel.getItemsList(searchToken).collectAsLazyPagingItems()
Box(
@ -113,7 +112,7 @@ fun ProductsList(navHostController: NavHostController){
products.itemCount,
key = products.itemKey()
) { index ->
ProductItem(products[index]!!, navHostController, productsViewModel, searchToken)
ProductItem(products[index]!!, navHostController, searchToken, productsViewModel)
Spacer(modifier = Modifier.height(20.dp))
if (index == products.itemCount - 1) {
Spacer(modifier = Modifier.height(70.dp))
@ -125,7 +124,7 @@ fun ProductsList(navHostController: NavHostController){
}
@Composable
fun ProductItem(product: ProductModel, navHostController: NavHostController, productsViewModel: ProductsViewModel, token: String){
fun ProductItem(product: ProductModel, navHostController: NavHostController, token: String, productsViewModel: ProductsViewModel){
Card(
border = BorderStroke(width = 2.dp, color = MyOrange),
shape = RoundedCornerShape(size = 20.dp),
@ -145,7 +144,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(

View File

@ -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 = {

View File

@ -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
)
}