From 758e633a01f1ebf97fd214368048b65fd22bf91e Mon Sep 17 00:00:00 2001 From: daniel Date: Sat, 18 Nov 2017 00:42:50 -0500 Subject: [PATCH 1/2] Cambios menores --- .../inventario_android/MainActivity.java | 72 +++++- .../inventario_android/Productos.java | 9 + app/src/main/res/layout/activity_main.xml | 208 +++++++++++++++++- 3 files changed, 274 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/danielvargas/inventario_android/MainActivity.java b/app/src/main/java/com/danielvargas/inventario_android/MainActivity.java index 04b7aad..4a2d2de 100644 --- a/app/src/main/java/com/danielvargas/inventario_android/MainActivity.java +++ b/app/src/main/java/com/danielvargas/inventario_android/MainActivity.java @@ -6,6 +6,9 @@ import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.TextView; import android.widget.Toast; import org.json.JSONArray; @@ -14,6 +17,9 @@ import java.io.IOException; +import butterknife.BindView; +import butterknife.ButterKnife; +import butterknife.OnClick; import okhttp3.Call; import okhttp3.Callback; import okhttp3.OkHttpClient; @@ -25,14 +31,51 @@ public class MainActivity extends AppCompatActivity { public static final String TAG = MainActivity.class.getSimpleName(); private Productos[] mProductos; + @BindView(R.id.id1) + TextView id1; + @BindView(R.id.id2) + TextView id2; + @BindView(R.id.id3) + TextView id3; + @BindView(R.id.id4) + TextView id4; + @BindView(R.id.nombre1) + TextView nombre1; + @BindView(R.id.nombre2) + TextView nombre2; + @BindView(R.id.nombre3) + TextView nombre3; + @BindView(R.id.nombre4) + TextView nombre4; + @BindView(R.id.precio1) + TextView precio1; + @BindView(R.id.precio2) + TextView precio2; + @BindView(R.id.precio3) + TextView precio3; + @BindView(R.id.precio4) + TextView precio4; + @BindView(R.id.vendidos1) + TextView vendidos1; + @BindView(R.id.vendidos2) + TextView vendidos2; + @BindView(R.id.vendidos3) + TextView vendidos3; + @BindView(R.id.vendidos4) + TextView vendidos4; + + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); + ButterKnife.bind(this); + + getData(); } private void getData() { - String dataUrl = "http://localhost:8090/api/productos"; + String dataUrl = "https://guarded-shelf-37041.herokuapp.com/api/productos"; if (isNetworkAvailable()) { OkHttpClient client = new OkHttpClient(); @@ -65,7 +108,7 @@ public void run() { runOnUiThread(new Runnable() { @Override public void run() { -// updateDisplay(); + updateDisplay(); } }); } else { @@ -78,7 +121,6 @@ public void run() { }); } else { - //TODO intentar mandar este mensaje por un dialogo en vez de un toast Toast.makeText(this, R.string.network_unavilable_message, Toast.LENGTH_LONG).show(); } @@ -112,6 +154,7 @@ private Productos[] getJsonData(String jsonData) throws JSONException { producto.setPrecio(jsonProducto.getDouble("precio")); producto.setPrecioEntrada(jsonProducto.getDouble("precioEntrada")); producto.setDescripcion(jsonProducto.getString("descripcion")); + producto.setVendidos(jsonProducto.getInt("cantidadVendido")); productos[i] = producto; } @@ -120,6 +163,29 @@ private Productos[] getJsonData(String jsonData) throws JSONException { } public void updateDisplay() { + id1.setText(mProductos[0].getId() + ""); + id2.setText(mProductos[1].getId() + ""); + id3.setText(mProductos[2].getId() + ""); + id4.setText(mProductos[3].getId() + ""); + + nombre1.setText(mProductos[0].getNombre()); + nombre2.setText(mProductos[1].getNombre()); + nombre3.setText(mProductos[2].getNombre()); + nombre4.setText(mProductos[3].getNombre()); + + precio1.setText(mProductos[0].getPrecio() + ""); + precio2.setText(mProductos[1].getPrecio() + ""); + precio3.setText(mProductos[2].getPrecio() + ""); + precio4.setText(mProductos[3].getPrecio() + ""); + + vendidos1.setText(mProductos[0].getVendidos() + ""); + vendidos2.setText(mProductos[1].getVendidos() + ""); + vendidos3.setText(mProductos[2].getVendidos() + ""); + vendidos4.setText(mProductos[3].getVendidos() + ""); + } + @OnClick(R.id.actualizarButton) + public void actualizar(View view){ + getData(); } } diff --git a/app/src/main/java/com/danielvargas/inventario_android/Productos.java b/app/src/main/java/com/danielvargas/inventario_android/Productos.java index 4c5a1b6..bb8e65e 100644 --- a/app/src/main/java/com/danielvargas/inventario_android/Productos.java +++ b/app/src/main/java/com/danielvargas/inventario_android/Productos.java @@ -10,6 +10,7 @@ public class Productos { double precio; double precioEntrada; String descripcion; + int vendidos; public int getId() { return id; @@ -50,4 +51,12 @@ public String getDescripcion() { public void setDescripcion(String descripcion) { this.descripcion = descripcion; } + + public int getVendidos() { + return vendidos; + } + + public void setVendidos(int vendidos) { + this.vendidos = vendidos; + } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 812eff2..5f3e30e 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -12,54 +12,238 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:layout_centerHorizontal="true" - android:layout_centerVertical="true"> + android:layout_centerVertical="true" + android:background="#eee"> + + + + + + + + + + + + android:layout_height="match_parent" + android:padding="15dp"> + android:layout_marginRight="10dp" + android:text="id" + android:textColor="#000" + android:textSize="20sp"/> + + + + + + + + android:layout_height="match_parent" + android:padding="15dp"> + + + + + + + android:layout_marginRight="10dp" + android:text="TextView" + android:textColor="#000" + android:textSize="20sp"/> + android:layout_height="match_parent" + android:padding="15dp"> + android:layout_marginRight="10dp" + android:text="id" + android:textColor="#000" + android:textSize="20sp"/> + + + + + + + + + + + + + + + + + + android:text="TextView" + android:textColor="#eee"/> + +