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"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="deploymentTargetDropDown"> <component name="deploymentTargetDropDown">
<targetSelectedWithDropDown> <runningDeviceTargetSelectedWithDropDown>
<Target> <Target>
<type value="QUICK_BOOT_TARGET" /> <type value="RUNNING_DEVICE_TARGET" />
<deviceKey> <deviceKey>
<Key> <Key>
<type value="VIRTUAL_DEVICE_PATH" /> <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> </Key>
</deviceKey> </deviceKey>
</Target> </Target>
</targetSelectedWithDropDown> </runningDeviceTargetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2023-10-09T12:44:34.176701300Z" /> <timeTargetWasSelectedWithDropDown value="2023-12-25T13:14:56.067510100Z" />
</component> </component>
</project> </project>

View File

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

View File

@ -11,7 +11,7 @@ import javax.net.ssl.X509TrustManager;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
public class UnsafeOkHttpClient { public class OkHttpClientSettings {
public static OkHttpClient getUnsafeOkHttpClient() { public static OkHttpClient getUnsafeOkHttpClient() {
try { try {
// Create a trust manager that does not validate certificate chains // 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.api.models.toProductModel
import com.example.shawarma.data.db.AppDatabase import com.example.shawarma.data.db.AppDatabase
import com.example.shawarma.data.models.ProductModel import com.example.shawarma.data.models.ProductModel
import kotlinx.coroutines.flow.first
import java.io.IOException import java.io.IOException
@OptIn(ExperimentalPagingApi::class) @OptIn(ExperimentalPagingApi::class)
@ -50,14 +51,25 @@ class ProductRemoteMediator (
"items" -> { "items" -> {
serverService.getItemsList(after = loadKey, token = token) serverService.getItemsList(after = loadKey, token = token)
} }
else -> {ProductListResponse()} else -> {ProductListResponse()}
} }
database.withTransaction { database.withTransaction {
if (loadType == LoadType.REFRESH) { if (loadType == LoadType.REFRESH) {
if (query != "items") {
productDao.deleteByQuery(query) 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>() val products = mutableListOf<ProductModel>()
for (prod in response.products) { for (prod in response.products) {

View File

@ -9,6 +9,7 @@ import androidx.room.Query
import androidx.room.Update import androidx.room.Update
import com.example.shawarma.data.models.ProductModel import com.example.shawarma.data.models.ProductModel
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
@Dao @Dao
interface ProductDao { interface ProductDao {
@Insert(onConflict = REPLACE) @Insert(onConflict = REPLACE)
@ -47,6 +48,9 @@ interface ProductDao {
@Query("select * from products") @Query("select * from products")
fun getPagedItems(): PagingSource<Int, ProductModel> 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") @Query("delete from products where products.product_old_price is null")
fun deleteAllProducts() fun deleteAllProducts()

View File

@ -19,12 +19,4 @@ data class OrderModel(
val date: String 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) return restRepository.update(product, token)
} }
suspend fun delete(product: ProductModel, token: String) { suspend fun delete(product: ProductModel, token: String) {
//orderProductDao.deleteByProductId(product.id!!)
productDao.delete(product) productDao.delete(product)
return restRepository.delete(product.id!!, token) return restRepository.delete(product.id!!, token)
} }

View File

@ -17,9 +17,6 @@ class UserRepository @Inject constructor(
suspend fun delete (user: UserModel) { suspend fun delete (user: UserModel) {
return userDao.delete(user) return userDao.delete(user)
} }
fun getAll(): Flow<List<UserModel>> {
return userDao.getAll()
}
fun getById(id: Int): Flow<UserModel> { fun getById(id: Int): Flow<UserModel> {
return userDao.getById(id) 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.platform.LocalContext
import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight 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.input.TextFieldValue
import androidx.compose.ui.text.style.TextDecoration import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
@ -155,7 +156,8 @@ fun AuthorizationCard(navHostController: NavHostController) {
) )
.size(208.dp, (50).dp), .size(208.dp, (50).dp),
placeholder = "Пароль", placeholder = "Пароль",
singleLine = true singleLine = true,
visualTransformation = PasswordVisualTransformation('*')
) )
Button( Button(
onClick = { onClick = {

View File

@ -32,6 +32,7 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.font.FontWeight 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.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import androidx.compose.ui.zIndex import androidx.compose.ui.zIndex
@ -186,14 +187,20 @@ fun PaidItem(order : OrderWithProducts) {
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.padding(horizontal = 20.dp) .padding(horizontal = 20.dp)
) {
Column(
modifier = Modifier.fillMaxWidth(0.5f)
) { ) {
Text( Text(
text = order.orderWithProducts[index].product!!.title, text = order.orderWithProducts[index].product!!.title,
fontFamily = NunitoFamily, fontFamily = NunitoFamily,
fontSize = 20.sp, fontSize = 20.sp,
modifier = Modifier.padding(top = 15.dp), modifier = Modifier.padding(top = 15.dp),
fontWeight = FontWeight.Bold fontWeight = FontWeight.Bold,
maxLines = 1,
overflow = TextOverflow.Ellipsis
) )
}
Text( Text(
text = "x" + order.orderWithProducts[index].orderProductModel.quantity, text = "x" + order.orderWithProducts[index].orderProductModel.quantity,
fontFamily = NunitoFamily, fontFamily = NunitoFamily,
@ -251,13 +258,19 @@ fun CartItem(order : OrderWithProducts) {
Row( Row(
horizontalArrangement = Arrangement.SpaceBetween, horizontalArrangement = Arrangement.SpaceBetween,
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()
) {
Column(
modifier = Modifier.fillMaxWidth(0.5f)
) { ) {
Text( Text(
text = order.orderWithProducts[index].product!!.title, text = order.orderWithProducts[index].product!!.title,
fontFamily = NunitoFamily, fontFamily = NunitoFamily,
fontSize = 20.sp, fontSize = 20.sp,
fontWeight = FontWeight.Bold fontWeight = FontWeight.Bold,
maxLines = 1,
overflow = TextOverflow.Ellipsis
) )
}
Text( Text(
text = (order.orderWithProducts[index].orderProductModel.quantity * order.orderWithProducts[index].product!!.price).toString() + " руб.", text = (order.orderWithProducts[index].orderProductModel.quantity * order.orderWithProducts[index].product!!.price).toString() + " руб.",
fontFamily = NunitoFamily, fontFamily = NunitoFamily,

View File

@ -28,6 +28,7 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextDecoration 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.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import androidx.compose.ui.zIndex import androidx.compose.ui.zIndex
@ -137,7 +138,10 @@ fun DiscountCard(product : ProductModel){
fontFamily = NunitoFamily, fontFamily = NunitoFamily,
fontSize = 20.sp, fontSize = 20.sp,
fontWeight = FontWeight.Bold, fontWeight = FontWeight.Bold,
modifier = Modifier.padding(top = 10.dp) modifier = Modifier.padding(top = 10.dp),
maxLines = 1,
softWrap = true,
overflow = TextOverflow.Ellipsis
) )
Image( Image(
painter = painterResource(id = R.drawable.shawarma2), 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.platform.LocalContext
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight 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.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import androidx.compose.ui.zIndex import androidx.compose.ui.zIndex
@ -140,7 +141,10 @@ fun ProductCard(product: ProductModel){
fontFamily = NunitoFamily, fontFamily = NunitoFamily,
fontSize = 20.sp, fontSize = 20.sp,
fontWeight = FontWeight.Bold, fontWeight = FontWeight.Bold,
modifier = Modifier.padding(top = 10.dp) modifier = Modifier.padding(top = 10.dp),
maxLines = 1,
softWrap = true,
overflow = TextOverflow.Ellipsis
) )
Image( Image(
painter = painterResource(id = R.drawable.shawarma2), 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.platform.LocalContext
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight 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.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import androidx.compose.ui.zIndex import androidx.compose.ui.zIndex
@ -49,10 +50,11 @@ import com.example.shawarma.widgets.ShawarmaLogo2
@Composable @Composable
fun ProductsScreen(navHostController: NavHostController) { fun ProductsScreen(navHostController: NavHostController) {
val productsViewModel: ProductsViewModel = hiltViewModel<ProductsViewModel>()
Box( Box(
contentAlignment = Alignment.TopCenter contentAlignment = Alignment.TopCenter
) { ) {
ProductsList(navHostController) ProductsList(navHostController, productsViewModel)
ShawarmaLogo2() ShawarmaLogo2()
} }
} }
@ -60,12 +62,9 @@ fun ProductsScreen(navHostController: NavHostController) {
@Composable @Composable
fun ProductsList(navHostController: NavHostController){ fun ProductsList(navHostController: NavHostController, productsViewModel: ProductsViewModel){
val preferencesManager = PreferencesManager(LocalContext.current) val preferencesManager = PreferencesManager(LocalContext.current)
val searchToken = preferencesManager.getData("token", "") val searchToken = preferencesManager.getData("token", "")
val productsViewModel: ProductsViewModel = hiltViewModel<ProductsViewModel>()
val products = productsViewModel.getItemsList(searchToken).collectAsLazyPagingItems() val products = productsViewModel.getItemsList(searchToken).collectAsLazyPagingItems()
Box( Box(
@ -113,7 +112,7 @@ fun ProductsList(navHostController: NavHostController){
products.itemCount, products.itemCount,
key = products.itemKey() key = products.itemKey()
) { index -> ) { index ->
ProductItem(products[index]!!, navHostController, productsViewModel, searchToken) ProductItem(products[index]!!, navHostController, searchToken, productsViewModel)
Spacer(modifier = Modifier.height(20.dp)) Spacer(modifier = Modifier.height(20.dp))
if (index == products.itemCount - 1) { if (index == products.itemCount - 1) {
Spacer(modifier = Modifier.height(70.dp)) Spacer(modifier = Modifier.height(70.dp))
@ -125,7 +124,7 @@ fun ProductsList(navHostController: NavHostController){
} }
@Composable @Composable
fun ProductItem(product: ProductModel, navHostController: NavHostController, productsViewModel: ProductsViewModel, token: String){ fun ProductItem(product: ProductModel, navHostController: NavHostController, token: String, productsViewModel: ProductsViewModel){
Card( Card(
border = BorderStroke(width = 2.dp, color = MyOrange), border = BorderStroke(width = 2.dp, color = MyOrange),
shape = RoundedCornerShape(size = 20.dp), shape = RoundedCornerShape(size = 20.dp),
@ -145,7 +144,9 @@ fun ProductItem(product: ProductModel, navHostController: NavHostController, pro
text = product.title, text = product.title,
fontFamily = NunitoFamily, fontFamily = NunitoFamily,
fontSize = 20.sp, fontSize = 20.sp,
fontWeight = FontWeight.Bold fontWeight = FontWeight.Bold,
maxLines = 1,
overflow = TextOverflow.Ellipsis
) )
if (product.oldPrice != null) { if (product.oldPrice != null) {
Text( Text(

View File

@ -24,6 +24,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight 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.input.TextFieldValue
import androidx.compose.ui.text.style.TextDecoration import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
@ -145,7 +146,8 @@ fun RegistrationCard(navHostController: NavHostController){
) )
.size(208.dp, (50).dp), .size(208.dp, (50).dp),
placeholder = "Пароль", placeholder = "Пароль",
singleLine = true singleLine = true,
visualTransformation = PasswordVisualTransformation('*')
) )
MyTextField( MyTextField(
text = passwordRepeat, text = passwordRepeat,
@ -156,7 +158,8 @@ fun RegistrationCard(navHostController: NavHostController){
) )
.size(208.dp, (50).dp), .size(208.dp, (50).dp),
placeholder = "Повторите пароль", placeholder = "Повторите пароль",
singleLine = true singleLine = true,
visualTransformation = PasswordVisualTransformation('*')
) )
Button( Button(
onClick = { onClick = {

View File

@ -1,7 +1,5 @@
package com.example.shawarma.widgets 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.foundation.shape.RoundedCornerShape
import androidx.compose.material.Text import androidx.compose.material.Text
import androidx.compose.material.TextField import androidx.compose.material.TextField
@ -10,9 +8,9 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState import androidx.compose.runtime.MutableState
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.Placeholder
import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.input.TextFieldValue 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.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import com.example.shawarma.ui.theme.JejuFamily import com.example.shawarma.ui.theme.JejuFamily
@ -24,7 +22,8 @@ fun MyTextField(
onTextChanged: (TextFieldValue) -> Unit, onTextChanged: (TextFieldValue) -> Unit,
modifier: Modifier, modifier: Modifier,
placeholder: String, placeholder: String,
singleLine: Boolean singleLine: Boolean,
visualTransformation: VisualTransformation = VisualTransformation.None
) { ) {
return TextField( return TextField(
value = text.value, value = text.value,
@ -52,6 +51,7 @@ fun MyTextField(
unfocusedIndicatorColor = Color.Transparent, unfocusedIndicatorColor = Color.Transparent,
disabledIndicatorColor = Color.Transparent disabledIndicatorColor = Color.Transparent
), ),
visualTransformation = visualTransformation,
modifier = modifier modifier = modifier
) )
} }