Commit dd5511fd authored by Daniel Cesanelli's avatar Daniel Cesanelli
Browse files

Agregados ViewModels para Producers y Products y agregado retrofit para traer...

Agregados ViewModels para Producers y Products y agregado retrofit para traer eso valores desde la API
parent 394bc7d7
......@@ -8,7 +8,7 @@ android {
defaultConfig {
applicationId "com.cesanelli.lajusta"
minSdkVersion 22
minSdkVersion 23
targetSdkVersion 30
versionCode 1
versionName "1.0"
......@@ -38,14 +38,19 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.navigation:navigation-fragment:2.3.1'
implementation 'androidx.navigation:navigation-ui:2.3.1'
implementation 'androidx.navigation:navigation-fragment:2.3.2'
implementation 'androidx.navigation:navigation-ui:2.3.2'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.2.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.annotation:annotation:1.1.0'
testImplementation 'junit:junit:4.+'
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-jackson:2.3.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.9.1'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
\ No newline at end of file
......@@ -2,13 +2,16 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cesanelli.lajusta">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.LaJusta">
android:theme="@style/Theme.LaJusta"
android:networkSecurityConfig="@xml/network_security_config">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
......
......@@ -30,7 +30,7 @@ public class MainActivity extends AppCompatActivity {
// Passing each menu ID as a set of Ids because each
// menu should be considered as top level destinations.
mAppBarConfiguration = new AppBarConfiguration.Builder(
R.id.nav_quienes_somos, R.id.nav_noticias, R.id.nav_productores, R.id.nav_productos, R.id.nav_login)
R.id.nav_quienes_somos, R.id.nav_news, R.id.nav_producers, R.id.nav_products, R.id.nav_login)
.setDrawerLayout(drawer)
.build();
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
......
package com.cesanelli.lajusta.dummy;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Helper class for providing sample content for user interfaces created by
* Android template wizards.
* <p>
* TODO: Replace all uses of this class before publishing your app.
*/
public class ProductoContent {
/**
* An array of sample (dummy) items.
*/
public static final List<ProductoItem> ITEMS = new ArrayList<ProductoItem>();
/**
* A map of sample (dummy) items, by ID.
*/
public static final Map<String, ProductoItem> ITEM_MAP = new HashMap<String, ProductoItem>();
private static final int COUNT = 25;
static {
// Add some sample items.
for (int i = 1; i <= COUNT; i++) {
addItem(createProductoItem(i));
}
}
private static void addItem(ProductoItem item) {
ITEMS.add(item);
ITEM_MAP.put(item.id, item);
}
private static ProductoItem createProductoItem(int position) {
return new ProductoItem(String.valueOf(position), "Producto " + position, makeDetails(position));
}
private static String makeDetails(int position) {
StringBuilder builder = new StringBuilder();
builder.append("Details about Item: ").append(position);
for (int i = 0; i < position; i++) {
builder.append("\nMore details information here.");
}
return builder.toString();
}
/**
* A dummy item representing a piece of content.
*/
public static class ProductoItem {
public final String id;
public final String content;
public final String details;
public ProductoItem(String id, String content, String details) {
this.id = id;
this.content = content;
this.details = details;
}
@Override
public String toString() {
return content;
}
}
}
\ No newline at end of file
package com.cesanelli.lajusta.dummy;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Helper class for providing sample content for user interfaces created by
* Android template wizards.
* <p>
* TODO: Replace all uses of this class before publishing your app.
*/
public class ProductorContent {
/**
* An array of sample (dummy) items.
*/
public static final List<ProductorItem> ITEMS = new ArrayList<ProductorItem>();
/**
* A map of sample (dummy) items, by ID.
*/
public static final Map<String, ProductorItem> ITEM_MAP = new HashMap<String, ProductorItem>();
private static final int COUNT = 25;
static {
// Add some sample items.
for (int i = 1; i <= COUNT; i++) {
addItem(createProductorItem(i));
}
}
private static void addItem(ProductorItem item) {
ITEMS.add(item);
ITEM_MAP.put(item.id, item);
}
private static ProductorItem createProductorItem(int position) {
return new ProductorItem(String.valueOf(position), "Productor " + position, makeDetails(position));
}
private static String makeDetails(int position) {
StringBuilder builder = new StringBuilder();
builder.append("Details about Item: ").append(position);
for (int i = 0; i < position; i++) {
builder.append("\nMore details information here.");
}
return builder.toString();
}
/**
* A dummy item representing a piece of content.
*/
public static class ProductorItem {
public final String id;
public final String content;
public final String details;
public ProductorItem(String id, String content, String details) {
this.id = id;
this.content = content;
this.details = details;
}
@Override
public String toString() {
return content;
}
}
}
\ No newline at end of file
package com.cesanelli.lajusta.io;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.converter.jackson.JacksonConverterFactory;
public class ApiAdapter {
private static ApiService API_SERVICE;
public static ApiService getApiService() {
// Creamos un interceptor y le indicamos el log level a usar
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
// Asociamos el interceptor a las peticiones
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.addInterceptor(logging);
String baseUrl = "http://ec2-3-235-40-183.compute-1.amazonaws.com/api/";
if (API_SERVICE == null) {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(baseUrl)
.addConverterFactory(JacksonConverterFactory.create(objectMapper))
.client(httpClient.build())
.build();
API_SERVICE = retrofit.create(ApiService.class);
}
return API_SERVICE;
}
}
package com.cesanelli.lajusta.io;
import com.cesanelli.lajusta.io.models.Producer;
import com.cesanelli.lajusta.io.models.Product;
import java.util.ArrayList;
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Path;
public interface ApiService {
@GET("product")
Call<ArrayList<Product>> getProducts();
@GET("product/{id}")
Call<Product> getProduct(@Path("id") int id);
@GET("producer")
Call<ArrayList<Producer>> getProducers();
@GET("producer/{id}")
Call<Producer> getProducer(@Path("id") int id);
}
package com.cesanelli.lajusta.io.models;
public class Address {
private int id;
private String street;
private String number;
private String description;
private float latitude;
private float longitude;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public float getLatitude() {
return latitude;
}
public void setLatitude(float latitude) {
this.latitude = latitude;
}
public float getLongitude() {
return longitude;
}
public void setLongitude(float longitude) {
this.longitude = longitude;
}
}
package com.cesanelli.lajusta.io.models;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@JsonIgnoreProperties
public class Category {
private int id;
private Image image;
private String name;
private int level;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public Image getImage() {
return image;
}
public void setImage(Image image) {
this.image = image;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getLevel() {
return level;
}
public void setLevel(int level) {
this.level = level;
}
}
package com.cesanelli.lajusta.io.models;
public class Image {
private int id;
private boolean isMain;
private String name;
private String type;
private String value;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public boolean isMain() {
return isMain;
}
public void setMain(boolean main) {
isMain = main;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
package com.cesanelli.lajusta.io.models;
public class Producer {
private int id;
private String name;
private String lastName;
private String email;
private String origin;
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;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getOrigin() {
return origin;
}
public void setOrigin(String origin) {
this.origin = origin;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Image[] getImages() {
return images;
}
public void setImages(Image[] images) {
this.images = images;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
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;
}
}
package com.cesanelli.lajusta.io.models;
public class Product {
private int id;
private String title;
private String brand;
private float buyPrice;
private String description;
private boolean isPromotion;
private Category[] categories;
private Image[] images;
private Producer producer;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public <