minor fixes
This commit is contained in:
parent
07b8aea79f
commit
c1b7f45b2c
@ -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>
|
@ -120,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)
|
||||||
|
@ -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
|
@ -50,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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -61,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(
|
||||||
@ -114,7 +112,7 @@ fun ProductsList(navHostController: NavHostController){
|
|||||||
products.itemCount,
|
products.itemCount,
|
||||||
key = products.itemKey()
|
key = products.itemKey()
|
||||||
) { index ->
|
) { index ->
|
||||||
ProductItem(products[index]!!, navHostController, 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))
|
||||||
@ -126,8 +124,7 @@ fun ProductsList(navHostController: NavHostController){
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ProductItem(product: ProductModel, navHostController: NavHostController, token: String){
|
fun ProductItem(product: ProductModel, navHostController: NavHostController, token: String, productsViewModel: ProductsViewModel){
|
||||||
val productsViewModel: ProductsViewModel = hiltViewModel<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),
|
||||||
|
@ -3,7 +3,6 @@ package com.example.shawarma.viewmodels
|
|||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import androidx.paging.PagingData
|
import androidx.paging.PagingData
|
||||||
import androidx.paging.cachedIn
|
|
||||||
import com.example.shawarma.data.models.ProductModel
|
import com.example.shawarma.data.models.ProductModel
|
||||||
import com.example.shawarma.data.repos.ProductRepository
|
import com.example.shawarma.data.repos.ProductRepository
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
@ -17,7 +16,7 @@ class ProductsViewModel @Inject constructor(
|
|||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
|
|
||||||
fun getItemsList(token:String): Flow<PagingData<ProductModel>> {
|
fun getItemsList(token:String): Flow<PagingData<ProductModel>> {
|
||||||
return productRepository.getAllItemsPaged(token).cachedIn(viewModelScope)
|
return productRepository.getAllItemsPaged(token)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deleteProduct(product: ProductModel, token: String) {
|
fun deleteProduct(product: ProductModel, token: String) {
|
||||||
|
Loading…
Reference in New Issue
Block a user