Commit 129a9baa authored by Daniel Cesanelli's avatar Daniel Cesanelli
Browse files

Agregado a productlist el total del cart

parent 702a1f58
package com.cesanelli.lajusta.ui;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Base64;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.recyclerview.widget.RecyclerView;
import com.cesanelli.lajusta.R;
import com.cesanelli.lajusta.databinding.FragmentCartBinding;
import com.cesanelli.lajusta.databinding.FragmentProductsBinding;
import com.cesanelli.lajusta.io.models.Cart;
import com.cesanelli.lajusta.io.models.CartItem;
import com.cesanelli.lajusta.io.models.Product;
import java.util.ArrayList;
public class CartRecyclerViewAdapter extends RecyclerView.Adapter<CartRecyclerViewAdapter.ViewHolder> {
......
package com.cesanelli.lajusta.ui;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
......@@ -16,7 +15,7 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.cesanelli.lajusta.R;
import com.cesanelli.lajusta.io.ApiAdapter;
import com.cesanelli.lajusta.databinding.FragmentProductsListBinding;
import com.cesanelli.lajusta.io.models.Product;
import com.cesanelli.lajusta.ui.viewmodel.CartViewModel;
import com.cesanelli.lajusta.ui.viewmodel.ProductListViewModel;
......@@ -24,14 +23,11 @@ import com.cesanelli.lajusta.ui.viewmodel.ProductViewModel;
import java.util.ArrayList;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class ProductsFragment extends Fragment implements ProductsRecyclerViewAdapter.OnProductListener {
private ProductViewModel productViewModel;
private ProductListViewModel productListViewModel;
private CartViewModel cartViewModel;
private FragmentProductsListBinding fragmentProductsListBinding;
public ProductsFragment() {
}
......@@ -49,8 +45,9 @@ public class ProductsFragment extends Fragment implements ProductsRecyclerViewAd
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_products_list, container, false);
return view;
LayoutInflater layoutInflater = LayoutInflater.from(getContext());
fragmentProductsListBinding = FragmentProductsListBinding.inflate(layoutInflater, container, false);
return fragmentProductsListBinding.getRoot();
}
@Override
......@@ -58,10 +55,15 @@ public class ProductsFragment extends Fragment implements ProductsRecyclerViewAd
super.onViewCreated(view, savedInstanceState);
productViewModel = new ViewModelProvider(getActivity()).get(ProductViewModel.class);
cartViewModel = new ViewModelProvider(getActivity()).get(CartViewModel.class);
cartViewModel.getCart().observe(getViewLifecycleOwner(), cart -> {
if (cart != null) {
fragmentProductsListBinding.setCart(cart);
}
});
productListViewModel = new ViewModelProvider(getActivity()).get(ProductListViewModel.class);
productListViewModel.getProductList().observe(getViewLifecycleOwner(), list -> {
if (list != null) {
RecyclerView recyclerView = (RecyclerView) view;
RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.listProducts);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerView.setAdapter(new ProductsRecyclerViewAdapter((ArrayList<Product>) list, this));
}
......
<?xml version="1.0" encoding="utf-8"?>
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/listProducts"
android:name="com.cesanelli.lajusta.ProductsFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
app:layoutManager="LinearLayoutManager"
tools:context=".ui.ProductsFragment"
tools:listitem="@layout/fragment_products" />
\ No newline at end of file
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="cart"
type="com.cesanelli.lajusta.io.models.Cart" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.CartFragment">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/listProducts"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="15dp"
app:layout_constraintBottom_toTopOf="@+id/totalLayout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:context=".ui.ProductsFragment"
tools:listitem="@layout/fragment_products" />
<LinearLayout
android:id="@+id/totalLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginBottom="40dp"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/listProducts">
<TextView
android:id="@+id/titleQuantity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="10dp"
android:text="Cantidad" />
<TextView
android:id="@+id/txtQuantity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="10dp"
android:text="@{String.valueOf(cart.quantity)}" />
<TextView
android:id="@+id/titleTotal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="10dp"
android:text="Total $" />
<TextView
android:id="@+id/txtTotal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="10dp"
android:text="@{String.valueOf(cart.total)}" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment