minor fixes

This commit is contained in:
Данила Мочалов 2023-12-26 13:31:53 +04:00
parent 07b8aea79f
commit c1b7f45b2c
5 changed files with 13 additions and 17 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

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

@ -50,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()
}
}
@ -61,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(
@ -114,7 +112,7 @@ fun ProductsList(navHostController: NavHostController){
products.itemCount,
key = products.itemKey()
) { index ->
ProductItem(products[index]!!, navHostController, searchToken)
ProductItem(products[index]!!, navHostController, searchToken, productsViewModel)
Spacer(modifier = Modifier.height(20.dp))
if (index == products.itemCount - 1) {
Spacer(modifier = Modifier.height(70.dp))
@ -126,8 +124,7 @@ fun ProductsList(navHostController: NavHostController){
}
@Composable
fun ProductItem(product: ProductModel, navHostController: NavHostController, token: String){
val productsViewModel: ProductsViewModel = hiltViewModel<ProductsViewModel>()
fun ProductItem(product: ProductModel, navHostController: NavHostController, token: String, productsViewModel: ProductsViewModel){
Card(
border = BorderStroke(width = 2.dp, color = MyOrange),
shape = RoundedCornerShape(size = 20.dp),

View File

@ -3,7 +3,6 @@ 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
@ -17,7 +16,7 @@ class ProductsViewModel @Inject constructor(
) : ViewModel() {
fun getItemsList(token:String): Flow<PagingData<ProductModel>> {
return productRepository.getAllItemsPaged(token).cachedIn(viewModelScope)
return productRepository.getAllItemsPaged(token)
}
fun deleteProduct(product: ProductModel, token: String) {