Commit 8bb419a0 authored by Daniel Cesanelli's avatar Daniel Cesanelli
Browse files

Agregado cart

parent 00d9c4c1
......@@ -90,6 +90,9 @@ public class MainActivity extends AppCompatActivity {
if (response.isSuccessful()) {
token.setValue(jwt);
token.setUser(response.body());
} else {
sharedpreferences.edit().putString("JWT", "").apply();
sharedpreferences.edit().putString("UserID", "").apply();
}
} catch (Exception ex) {
sharedpreferences.edit().putString("JWT", "").apply();
......@@ -118,7 +121,7 @@ public class MainActivity extends AppCompatActivity {
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
return NavigationUI.onNavDestinationSelected(item, navController) || super.onOptionsItemSelected(item);
return NavigationUI.onNavDestinationSelected(item, navController) || super.onOptionsItemSelected(item);
}
@Override
......
......@@ -16,7 +16,8 @@ public class ApiAdapter {
// Creamos un interceptor y le indicamos el log level a usar
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
// logging.setLevel(HttpLoggingInterceptor.Level.BODY);
logging.setLevel(HttpLoggingInterceptor.Level.BASIC);
// Asociamos el interceptor a las peticiones
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
......
package com.cesanelli.lajusta.io;
import com.cesanelli.lajusta.io.models.Cart;
import com.cesanelli.lajusta.io.models.General;
import com.cesanelli.lajusta.io.models.News;
import com.cesanelli.lajusta.io.models.Producer;
import com.cesanelli.lajusta.io.models.Product;
import com.cesanelli.lajusta.io.models.Signup;
......@@ -38,4 +41,13 @@ public interface ApiService {
@GET("user/{id}")
Call<User> getUser(@Path("id") int id, @Header("Authorization") String authHeader);
@GET("news")
Call<News> getNews();
@POST("cart")
Call<Cart> postCart(@Body Cart body, @Header("Authorization") String authHeader);
@GET("general/active")
Call<General> getNodes();
}
package com.cesanelli.lajusta.io.models;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class ActiveNode {
private Integer id;
private Node node;
private String day;
private String dateTimeFrom;
private String dateTimeTo;
public ActiveNode() {
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Node getNode() {
return node;
}
public void setNode(Node node) {
this.node = node;
}
public String getDay() {
return day;
}
public void setDay(String day) {
this.day = day;
}
public String getDateTimeFrom() {
return dateTimeFrom;
}
public void setDateTimeFrom(String dateTimeFrom) {
this.dateTimeFrom = dateTimeFrom;
}
public String getDateTimeTo() {
return dateTimeTo;
}
public void setDateTimeTo(String dateTimeTo) {
this.dateTimeTo = dateTimeTo;
}
public String getOpen() {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.000'Z'");
try {
Date date = format.parse(day);
SimpleDateFormat formatterOut = new SimpleDateFormat("dd/MM/yyyy");
return formatterOut.format(date) + " de " + dateTimeFrom + " hs a " + dateTimeTo + " hs.";
} catch (ParseException e) {
return "";
}
}
}
......@@ -5,6 +5,7 @@ public class Address {
private String street;
private String number;
private String description;
private String betweenStreets;
private float latitude;
private float longitude;
......@@ -55,4 +56,17 @@ public class Address {
public void setLongitude(float longitude) {
this.longitude = longitude;
}
public String getBetweenStreets() {
return betweenStreets;
}
public void setBetweenStreets(String betweenStreets) {
this.betweenStreets = betweenStreets;
}
@Override
public String toString() {
return street + ((number==null || number.isEmpty())?"":" Nº " + number) + " " + betweenStreets;
}
}
......@@ -3,21 +3,26 @@ package com.cesanelli.lajusta.io.models;
import java.util.ArrayList;
public class Cart {
private ArrayList<CartItem> items;
private ArrayList<CartItem> cartProducts;
private boolean isCanceled;
private Integer quantity;
private float total;
public Cart(){
items = new ArrayList<CartItem>();
private ActiveNode nodeDate;
public Cart() {
cartProducts = new ArrayList<CartItem>();
quantity = 0;
total = 0;
isCanceled = false;
nodeDate = null;
}
public ArrayList<CartItem> getItems() {
return items;
public ArrayList<CartItem> getCartProducts() {
return cartProducts;
}
public void setItems(ArrayList<CartItem> items) {
this.items = items;
public void setCartProducts(ArrayList<CartItem> cartProducts) {
this.cartProducts = cartProducts;
}
public Integer getQuantity() {
......@@ -35,4 +40,12 @@ public class Cart {
public void setTotal(float total) {
this.total = total;
}
public ActiveNode getNode() {
return nodeDate;
}
public void setNode(ActiveNode node) {
this.nodeDate = node;
}
}
package com.cesanelli.lajusta.io.models;
import java.util.ArrayList;
public class General {
private ArrayList<ActiveNode> activeNodes;
public General(){
}
public ArrayList<ActiveNode> getActiveNodes() {
return activeNodes;
}
public void setActiveNodes(ArrayList<ActiveNode> activeNodes) {
this.activeNodes = activeNodes;
}
}
package com.cesanelli.lajusta.io.models;
import java.util.ArrayList;
public class News {
private ArrayList<NewsItem> page;
private Integer totalElements;
public News(){
}
public ArrayList<NewsItem> getPage() {
return page;
}
public void setPage(ArrayList<NewsItem> page) {
this.page = page;
}
public Integer getTotalElements() {
return totalElements;
}
public void setTotalElements(Integer totalElements) {
this.totalElements = totalElements;
}
}
package com.cesanelli.lajusta.io.models;
public class NewsItem {
private String title;
private String subtitle;
private String text;
private Image image;
public NewsItem() {
}
public NewsItem(String title, String subtitle, String text, Image image) {
this.title = title;
this.subtitle = subtitle;
this.text = text;
this.image = image;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getSubtitle() {
return subtitle;
}
public void setSubtitle(String subtitle) {
this.subtitle = subtitle;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public Image getImage() {
return image;
}
public void setImage(Image image) {
this.image = image;
}
}
package com.cesanelli.lajusta.io.models;
import java.util.ArrayList;
public class Node {
private Integer id;
private String name;
private String description;
private Address address;
private String phone;
public Node(){
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
}
......@@ -9,13 +9,6 @@ public class Producer {
private String description;
private Image[] images;
private String phone;
private String youtubeVideoId;
private String deletedAt;
private Product[] products;
private Product[] productCataloge;
private String[] tags;
private Address address;
private boolean isCompany;
public int getId() {
return id;
......@@ -81,60 +74,5 @@ public class Producer {
this.phone = phone;
}
public String getYoutubeVideoId() {
return youtubeVideoId;
}
public void setYoutubeVideoId(String youtubeVideoId) {
this.youtubeVideoId = youtubeVideoId;
}
public String getDeletedAt() {
return deletedAt;
}
public void setDeletedAt(String deletedAt) {
this.deletedAt = deletedAt;
}
public Product[] getProducts() {
return products;
}
public void setProducts(Product[] products) {
this.products = products;
}
public Product[] getProductCataloge() {
return productCataloge;
}
public void setProductCataloge(Product[] productCataloge) {
this.productCataloge = productCataloge;
}
public String[] getTags() {
return tags;
}
public void setTags(String[] tags) {
this.tags = tags;
}
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
public boolean isCompany() {
return isCompany;
}
public void setCompany(boolean company) {
isCompany = company;
}
}
......@@ -16,7 +16,6 @@ public class Product {
private boolean isPromotion;
private Category[] categories;
private Image[] images;
private Producer producer;
private Unit unit;
private int unitQuantity;
......@@ -84,14 +83,6 @@ public class Product {
this.images = images;
}
public Producer getProducer() {
return producer;
}
public void setProducer(Producer producer) {
this.producer = producer;
}
public Unit getUnit() {
return unit;
}
......@@ -110,7 +101,7 @@ public class Product {
@BindingAdapter("android:productImage")
public static void loadImage(ImageView imageView, Image[] images){
if (images.length > 0) {
if (images.length > 0 && images[0].getValue() != null) {
String cleanImage = images[0].getValue().replace("data:image/png;base64,", "").replace("data:image/jpeg;base64,", "");
byte[] decodedString = Base64.decode(cleanImage, Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
......
package com.cesanelli.lajusta.ui;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
......@@ -17,9 +18,16 @@ import androidx.recyclerview.widget.RecyclerView;
import com.cesanelli.lajusta.R;
import com.cesanelli.lajusta.databinding.FragmentCartListBinding;
import com.cesanelli.lajusta.io.ApiAdapter;
import com.cesanelli.lajusta.io.models.Cart;
import com.cesanelli.lajusta.io.models.CartItem;
import com.cesanelli.lajusta.io.models.User;
import com.cesanelli.lajusta.ui.viewmodel.CartViewModel;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class CartFragment extends Fragment implements CartRecyclerViewAdapter.OnCartListener {
private FragmentCartListBinding fragmentCartListBinding;
private CartViewModel cartViewModel;
......
......@@ -30,14 +30,14 @@ public class CartRecyclerViewAdapter extends RecyclerView.Adapter<CartRecyclerVi
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
CartItem cartItem = cart.getItems().get(position);
CartItem cartItem = cart.getCartProducts().get(position);
holder.fragmentCartBinding.setCartItem(cartItem);
holder.fragmentCartBinding.setOnCartListener(onCartListener);;
}
@Override
public int getItemCount() {
return cart.getItems().size();
return cart.getCartProducts().size();
}
public interface OnCartListener {
......
package com.cesanelli.lajusta.ui;
import android.content.Context;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import androidx.navigation.Navigation;
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.io.models.Image;
import com.cesanelli.lajusta.io.models.News;
import com.cesanelli.lajusta.io.models.NewsItem;
import com.cesanelli.lajusta.io.models.Producer;
import com.cesanelli.lajusta.ui.viewmodel.NewsListViewModel;
import com.cesanelli.lajusta.ui.viewmodel.ProducerListViewModel;
import com.cesanelli.lajusta.ui.viewmodel.ProducerViewModel;
import java.util.ArrayList;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
/**
* A simple {@link Fragment} subclass.
* Use the {@link NewsFragment#newInstance} factory method to
* create an instance of this fragment.
* A fragment representing a list of Items.
*/
public class NewsFragment extends Fragment {
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
// TODO: Rename and change types of parameters
private String mParam1;
private String mParam2;
private NewsListViewModel newsListViewModel;
public NewsFragment() {
// Required empty public constructor
}
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @param param1 Parameter 1.
* @param param2 Parameter 2.
* @return A new instance of fragment NewsFragment.
*/
// TODO: Rename and change types and number of parameters
public static NewsFragment newInstance(String param1, String param2) {
public static NewsFragment newInstance() {
NewsFragment fragment = new NewsFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_news, container, false);