diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml
index 5c591b0..7c452ed 100644
--- a/.idea/deploymentTargetDropDown.xml
+++ b/.idea/deploymentTargetDropDown.xml
@@ -1,17 +1,17 @@
-
+
-
+
-
+
-
-
+
+
\ No newline at end of file
diff --git a/app/src/main/java/com/example/shawarma/data/api/MyServerService.kt b/app/src/main/java/com/example/shawarma/data/api/MyServerService.kt
index 152a9e4..75bf813 100644
--- a/app/src/main/java/com/example/shawarma/data/api/MyServerService.kt
+++ b/app/src/main/java/com/example/shawarma/data/api/MyServerService.kt
@@ -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)
diff --git a/app/src/main/java/com/example/shawarma/data/api/UnsafeOkHttpClient.java b/app/src/main/java/com/example/shawarma/data/api/OkHttpClientSettings.java
similarity index 98%
rename from app/src/main/java/com/example/shawarma/data/api/UnsafeOkHttpClient.java
rename to app/src/main/java/com/example/shawarma/data/api/OkHttpClientSettings.java
index 3694fdf..e4353b2 100644
--- a/app/src/main/java/com/example/shawarma/data/api/UnsafeOkHttpClient.java
+++ b/app/src/main/java/com/example/shawarma/data/api/OkHttpClientSettings.java
@@ -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
diff --git a/app/src/main/java/com/example/shawarma/screens/products/ProductsScreen.kt b/app/src/main/java/com/example/shawarma/screens/products/ProductsScreen.kt
index 088426e..519280e 100644
--- a/app/src/main/java/com/example/shawarma/screens/products/ProductsScreen.kt
+++ b/app/src/main/java/com/example/shawarma/screens/products/ProductsScreen.kt
@@ -50,10 +50,11 @@ import com.example.shawarma.widgets.ShawarmaLogo2
@Composable
fun ProductsScreen(navHostController: NavHostController) {
+ val productsViewModel: ProductsViewModel = hiltViewModel()
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()
-
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()
+fun ProductItem(product: ProductModel, navHostController: NavHostController, token: String, productsViewModel: ProductsViewModel){
Card(
border = BorderStroke(width = 2.dp, color = MyOrange),
shape = RoundedCornerShape(size = 20.dp),
diff --git a/app/src/main/java/com/example/shawarma/viewmodels/ProductsViewModel.kt b/app/src/main/java/com/example/shawarma/viewmodels/ProductsViewModel.kt
index 2233b3c..8b13c1e 100644
--- a/app/src/main/java/com/example/shawarma/viewmodels/ProductsViewModel.kt
+++ b/app/src/main/java/com/example/shawarma/viewmodels/ProductsViewModel.kt
@@ -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> {
- return productRepository.getAllItemsPaged(token).cachedIn(viewModelScope)
+ return productRepository.getAllItemsPaged(token)
}
fun deleteProduct(product: ProductModel, token: String) {