diff --git a/AndroidProject/app/src/androidTest/java/es/unican/gasolineras/activities/main/MostrarPreciosCombusitbleUITest.java b/AndroidProject/app/src/androidTest/java/es/unican/gasolineras/activities/main/MostrarPreciosCombusitbleUITest.java new file mode 100644 index 0000000..ac04e4f --- /dev/null +++ b/AndroidProject/app/src/androidTest/java/es/unican/gasolineras/activities/main/MostrarPreciosCombusitbleUITest.java @@ -0,0 +1,350 @@ +package es.unican.gasolineras.activities.main; + +import static androidx.test.espresso.Espresso.onData; +import static androidx.test.espresso.Espresso.onView; +import static androidx.test.espresso.action.ViewActions.click; +import static androidx.test.espresso.action.ViewActions.scrollCompletelyTo; +import static androidx.test.espresso.action.ViewActions.scrollTo; +import static androidx.test.espresso.action.ViewActions.swipeDown; +import static androidx.test.espresso.action.ViewActions.swipeUp; +import static androidx.test.espresso.assertion.ViewAssertions.matches; +import static androidx.test.espresso.matcher.ViewMatchers.hasChildCount; +import static androidx.test.espresso.matcher.ViewMatchers.isRoot; +import static androidx.test.espresso.matcher.ViewMatchers.withId; +import static androidx.test.espresso.matcher.ViewMatchers.withText; +import static net.bytebuddy.matcher.ElementMatchers.is; +import static org.hamcrest.CoreMatchers.anything; +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.Matchers.hasToString; +import static java.lang.Thread.sleep; +import static java.util.EnumSet.allOf; +import static es.unican.gasolineras.utils.MockRepositories.getTestRepository; + +import android.app.Activity; +import android.content.Context; +import android.widget.ListView; + +import androidx.test.espresso.DataInteraction; +import androidx.test.ext.junit.rules.ActivityScenarioRule; +import androidx.test.platform.app.InstrumentationRegistry; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import dagger.hilt.android.testing.BindValue; +import dagger.hilt.android.testing.HiltAndroidRule; +import dagger.hilt.android.testing.HiltAndroidTest; +import dagger.hilt.android.testing.UninstallModules; +import es.unican.gasolineras.R; +import es.unican.gasolineras.injection.RepositoriesModule; +import es.unican.gasolineras.model.GasolineraCombustible; +import es.unican.gasolineras.repository.IGasolinerasRepository; + +@UninstallModules(RepositoriesModule.class) +@HiltAndroidTest +public class MostrarPreciosCombusitbleUITest { + @Rule(order = 0) // The Hilt rule must execute first + public HiltAndroidRule hiltRule = new HiltAndroidRule(this); + @Rule(order = 1) + public ActivityScenarioRule activityRule = new ActivityScenarioRule<>(MainView.class); + + // I need the context to access resources, such as the json with test gas stations + final Context context = InstrumentationRegistry.getInstrumentation().getTargetContext(); + + // Mock repository that provides data from a JSON file instead of downloading it from the internet. + @BindValue + public final IGasolinerasRepository repository = getTestRepository(context, R.raw.pruebas_interfaz_mostrar_precios_combustible); + + @Before + public void setUp() { + hiltRule.inject(); + } + + @Test + public void testMostrarTodosLosPreciosCompleto() { + + // Me guardo la gasolinera en una varibale para usarla para comprobar los precios. + DataInteraction gasolineraCompleta = onData(anything()).inAdapterView(withId(R.id.lvStations)).atPosition(0); + + // Accedo a la informacion de la primera gasolinera. + gasolineraCompleta.perform(click()); + + //Compruebo que la lista de combustibles tiene 14 elementos. + onView(withId(R.id.lvCombustibles)).check(matches(hasChildCount(14))); + + /* + En los test de android studio si el elemento de la lista no aparece en pantalla no comprueba ese elemento + Por lo que si no pongo el scroll el test se queda en la pantalla que aparece cuando entras en la primera + Gasolinera y no avanza. He probado muchas cosas con bucle for swipeUp pero la unica manera en la que me + A funcionado ha sido esta. Lo que hago es hacer un scroll hasta gasoleo Premium que es mas o menos la mitad + de la lista para que compruebe del elemento 1 al 8. Luego hago otro scroll hasta el final para que compruebe + todas. Al final de la lista uso un swipeUp para que baje una ultima vez y acabe el test porque sin esa linea + el test no detecta que ha llegado al final no acaba la pantalla y se queda esperando. + */ + onView(withText("Gasoleo Premium")).perform(scrollTo()); + + // Compruebo los nombres y precios de cada combustible. + + //Biodiesel + gasolineraCompleta.inAdapterView(withId(R.id.lvCombustibles)) + .atPosition(0) + .onChildView(withId(R.id.tvNombreCombustible)) + .check(matches(withText("Biodiesel"))); + + gasolineraCompleta.inAdapterView(withId(R.id.lvCombustibles)) + .atPosition(0) + .onChildView(withId(R.id.tvPrecioCombustible)) + .check(matches(withText("1.1"))); + + //Bioetanol + gasolineraCompleta.inAdapterView(withId(R.id.lvCombustibles)) + .atPosition(1) + .onChildView(withId(R.id.tvNombreCombustible)) + .check(matches(withText("Bioetanol"))); + + gasolineraCompleta.inAdapterView(withId(R.id.lvCombustibles)) + .atPosition(1) + .onChildView(withId(R.id.tvPrecioCombustible)) + .check(matches(withText("1.2"))); + + //Gas natural comprimido + gasolineraCompleta.inAdapterView(withId(R.id.lvCombustibles)) + .atPosition(2) + .onChildView(withId(R.id.tvNombreCombustible)) + .check(matches(withText("Gnc"))); + + gasolineraCompleta.inAdapterView(withId(R.id.lvCombustibles)) + .atPosition(2) + .onChildView(withId(R.id.tvPrecioCombustible)) + .check(matches(withText("1.3"))); + + //Gas natural licuado + gasolineraCompleta.inAdapterView(withId(R.id.lvCombustibles)) + .atPosition(3) + .onChildView(withId(R.id.tvNombreCombustible)) + .check(matches(withText("Gnl"))); + + gasolineraCompleta.inAdapterView(withId(R.id.lvCombustibles)) + .atPosition(3) + .onChildView(withId(R.id.tvPrecioCombustible)) + .check(matches(withText("1.4"))); + + //Gases licuados del petroleo + gasolineraCompleta.inAdapterView(withId(R.id.lvCombustibles)) + .atPosition(4) + .onChildView(withId(R.id.tvNombreCombustible)) + .check(matches(withText("Glp"))); + + gasolineraCompleta.inAdapterView(withId(R.id.lvCombustibles)) + .atPosition(4) + .onChildView(withId(R.id.tvPrecioCombustible)) + .check(matches(withText("1.5"))); + + //Gasoleo A + gasolineraCompleta.inAdapterView(withId(R.id.lvCombustibles)) + .atPosition(5) + .onChildView(withId(R.id.tvNombreCombustible)) + .check(matches(withText("Gasoleo A"))); + + gasolineraCompleta.inAdapterView(withId(R.id.lvCombustibles)) + .atPosition(5) + .onChildView(withId(R.id.tvPrecioCombustible)) + .check(matches(withText("1.6"))); + + //Gasoleo B + gasolineraCompleta.inAdapterView(withId(R.id.lvCombustibles)) + .atPosition(6) + .onChildView(withId(R.id.tvNombreCombustible)) + .check(matches(withText("Gasoleo B"))); + + gasolineraCompleta.inAdapterView(withId(R.id.lvCombustibles)) + .atPosition(6) + .onChildView(withId(R.id.tvPrecioCombustible)) + .check(matches(withText("1.7"))); + + // Scroll para avanzar hasta el final. + onView(withText("Hidrogeno")).perform(scrollTo()); + + //Gasoleo Premium + gasolineraCompleta.inAdapterView(withId(R.id.lvCombustibles)) + .atPosition(7) + .onChildView(withId(R.id.tvNombreCombustible)) + .check(matches(withText("Gasoleo Premium"))); + + gasolineraCompleta.inAdapterView(withId(R.id.lvCombustibles)) + .atPosition(7) + .onChildView(withId(R.id.tvPrecioCombustible)) + .check(matches(withText("1.8"))); + + //Gasolina 95 E10 + gasolineraCompleta.inAdapterView(withId(R.id.lvCombustibles)) + .atPosition(8) + .onChildView(withId(R.id.tvNombreCombustible)) + .check(matches(withText("Gasolina 95 E10"))); + + gasolineraCompleta.inAdapterView(withId(R.id.lvCombustibles)) + .atPosition(8) + .onChildView(withId(R.id.tvPrecioCombustible)) + .check(matches(withText("1.9"))); + + //Gasolina 95 E5 + gasolineraCompleta.inAdapterView(withId(R.id.lvCombustibles)) + .atPosition(9) + .onChildView(withId(R.id.tvNombreCombustible)) + .check(matches(withText("Gasolina 95 E5"))); + + gasolineraCompleta.inAdapterView(withId(R.id.lvCombustibles)) + .atPosition(9) + .onChildView(withId(R.id.tvPrecioCombustible)) + .check(matches(withText("2.0"))); + + //Gasolina 95 E5 Premium + gasolineraCompleta.inAdapterView(withId(R.id.lvCombustibles)) + .atPosition(10) + .onChildView(withId(R.id.tvNombreCombustible)) + .check(matches(withText("Gasolina 95 E5 Premium"))); + + gasolineraCompleta.inAdapterView(withId(R.id.lvCombustibles)) + .atPosition(10) + .onChildView(withId(R.id.tvPrecioCombustible)) + .check(matches(withText("2.1"))); + + //Gasolina 98 E10 + gasolineraCompleta.inAdapterView(withId(R.id.lvCombustibles)) + .atPosition(11) + .onChildView(withId(R.id.tvNombreCombustible)) + .check(matches(withText("Gasolina 98 E10"))); + + gasolineraCompleta.inAdapterView(withId(R.id.lvCombustibles)) + .atPosition(11) + .onChildView(withId(R.id.tvPrecioCombustible)) + .check(matches(withText("2.2"))); + + //Gasoleo 98 E5 + gasolineraCompleta.inAdapterView(withId(R.id.lvCombustibles)) + .atPosition(12) + .onChildView(withId(R.id.tvNombreCombustible)) + .check(matches(withText("Gasolina 98 E5"))); + + gasolineraCompleta.inAdapterView(withId(R.id.lvCombustibles)) + .atPosition(12) + .onChildView(withId(R.id.tvPrecioCombustible)) + .check(matches(withText("2.3"))); + + // Bajo hasta que la barra toca con el final para acabar el test. + onView(withId(R.id.lvCombustibles)).perform(swipeUp()); + + //Hidrogeno + gasolineraCompleta.inAdapterView(withId(R.id.lvCombustibles)) + .atPosition(13) + .onChildView(withId(R.id.tvNombreCombustible)) + .check(matches(withText("Hidrogeno"))); + + gasolineraCompleta.inAdapterView(withId(R.id.lvCombustibles)) + .atPosition(13) + .onChildView(withId(R.id.tvPrecioCombustible)) + .check(matches(withText("2.4"))); + + } + + @Test + public void testMostrarTodosLosPreciosParcial() { + // Me guardo la gasolinera en una varibale para usarla para comprobar los precios. + DataInteraction gasolineraParcial = onData(anything()).inAdapterView(withId(R.id.lvStations)).atPosition(1); + + // Accedo a la informacion de la primera gasolinera. + gasolineraParcial.perform(click()); + + //Compruebo que la lista de combustibles tiene 6 elementos. + onView(withId(R.id.lvCombustibles)).check(matches(hasChildCount(6))); + + //En este caso con un solo scroll vale porque ya se muestran todos los elementos a la vez. + onView(withId(R.id.lvCombustibles)).perform(scrollTo()); + + // Compruebo los nombres y precios de cada combustible. + + //Biodiesel + gasolineraParcial.inAdapterView(withId(R.id.lvCombustibles)) + .atPosition(0) + .onChildView(withId(R.id.tvNombreCombustible)) + .check(matches(withText("Biodiesel"))); + + gasolineraParcial.inAdapterView(withId(R.id.lvCombustibles)) + .atPosition(0) + .onChildView(withId(R.id.tvPrecioCombustible)) + .check(matches(withText("1.1"))); + + //Gas natural comprimido + gasolineraParcial.inAdapterView(withId(R.id.lvCombustibles)) + .atPosition(1) + .onChildView(withId(R.id.tvNombreCombustible)) + .check(matches(withText("Gnc"))); + + gasolineraParcial.inAdapterView(withId(R.id.lvCombustibles)) + .atPosition(1) + .onChildView(withId(R.id.tvPrecioCombustible)) + .check(matches(withText("1.3"))); + + //Gasoleo A + gasolineraParcial.inAdapterView(withId(R.id.lvCombustibles)) + .atPosition(2) + .onChildView(withId(R.id.tvNombreCombustible)) + .check(matches(withText("Gasoleo A"))); + + gasolineraParcial.inAdapterView(withId(R.id.lvCombustibles)) + .atPosition(2) + .onChildView(withId(R.id.tvPrecioCombustible)) + .check(matches(withText("1.6"))); + + + //Gasoleo B + gasolineraParcial.inAdapterView(withId(R.id.lvCombustibles)) + .atPosition(3) + .onChildView(withId(R.id.tvNombreCombustible)) + .check(matches(withText("Gasoleo B"))); + + gasolineraParcial.inAdapterView(withId(R.id.lvCombustibles)) + .atPosition(3) + .onChildView(withId(R.id.tvPrecioCombustible)) + .check(matches(withText("1.7"))); + + //Gasoleo Premium + + gasolineraParcial.inAdapterView(withId(R.id.lvCombustibles)) + .atPosition(4) + .onChildView(withId(R.id.tvNombreCombustible)) + .check(matches(withText("Gasoleo Premium"))); + + gasolineraParcial.inAdapterView(withId(R.id.lvCombustibles)) + .atPosition(4) + .onChildView(withId(R.id.tvPrecioCombustible)) + .check(matches(withText("1.8"))); + + //Hidrogeno + gasolineraParcial.inAdapterView(withId(R.id.lvCombustibles)) + .atPosition(5) + .onChildView(withId(R.id.tvNombreCombustible)) + .check(matches(withText("Hidrogeno"))); + + gasolineraParcial.inAdapterView(withId(R.id.lvCombustibles)) + .atPosition(5) + .onChildView(withId(R.id.tvPrecioCombustible)) + .check(matches(withText("2.4"))); + } + + @Test + public void testMostrarTodosLosPreciosVacios() { + // Me guardo la gasolinera en una varibale para usarla para comprobar los precios. + DataInteraction gasolineraVacia = onData(anything()).inAdapterView(withId(R.id.lvStations)).atPosition(2); + + // Accedo a la informacion de la primera gasolinera. + gasolineraVacia.perform(click()); + + //Compruebo que la lista de combustibles tiene 0 elementos. + onView(withId(R.id.lvCombustibles)).check(matches(hasChildCount(0))); + + } + + +} diff --git a/AndroidProject/app/src/main/java/es/unican/gasolineras/activities/details/CombustibleArrayAdapter.java b/AndroidProject/app/src/main/java/es/unican/gasolineras/activities/details/CombustibleArrayAdapter.java new file mode 100644 index 0000000..c86d317 --- /dev/null +++ b/AndroidProject/app/src/main/java/es/unican/gasolineras/activities/details/CombustibleArrayAdapter.java @@ -0,0 +1,62 @@ +package es.unican.gasolineras.activities.details; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.TextView; + +import androidx.annotation.NonNull; + +import java.util.List; + +import es.unican.gasolineras.R; +import es.unican.gasolineras.model.GasolineraCombustible; + +public class CombustibleArrayAdapter extends BaseAdapter { + + private final List combustibles; + private final Context context; + + + public CombustibleArrayAdapter(@NonNull Context context, @NonNull List combustibles) { + this.combustibles = combustibles; + this.context = context; + } + + @Override + public int getCount() { + return combustibles.size(); + } + + @Override + public Object getItem(int position) { + return combustibles.get(position); + } + + @Override + public long getItemId(int position) { + return position; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + + if (convertView == null) { + convertView = LayoutInflater.from(context) + .inflate(R.layout.activity_precio_combustible_list_item, parent, false); + } + + // Configurar nombre + TextView tvNombre = convertView.findViewById(R.id.tvNombreCombustible); + tvNombre.setText(String.valueOf(combustibles.get(position).getCombustible())); + + // Configurar precio + TextView tvPrecio = convertView.findViewById(R.id.tvPrecioCombustible); + tvPrecio.setText(String.valueOf(combustibles.get(position).getPrecio())); + + return convertView; + } + +} diff --git a/AndroidProject/app/src/main/java/es/unican/gasolineras/activities/details/DetailsView.java b/AndroidProject/app/src/main/java/es/unican/gasolineras/activities/details/DetailsView.java index fba68c9..858d083 100644 --- a/AndroidProject/app/src/main/java/es/unican/gasolineras/activities/details/DetailsView.java +++ b/AndroidProject/app/src/main/java/es/unican/gasolineras/activities/details/DetailsView.java @@ -1,12 +1,20 @@ package es.unican.gasolineras.activities.details; +import static es.unican.gasolineras.common.Utils.rellenaListaCombustibles; +import static es.unican.gasolineras.common.Utils.setListViewHeightBasedOnItemCount; +import static es.unican.gasolineras.model.TipoCombustible.*; + import android.annotation.SuppressLint; import android.os.Bundle; import android.view.MenuItem; +import android.view.ViewGroup; import android.widget.ImageView; +import android.widget.ListView; import android.widget.TextView; import androidx.activity.EdgeToEdge; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; @@ -16,8 +24,16 @@ import org.parceler.Parcels; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; + import es.unican.gasolineras.R; import es.unican.gasolineras.model.Gasolinera; +import es.unican.gasolineras.model.GasolineraCombustible; /** * View that shows the details of one gas station. Since this view does not have business logic, @@ -52,9 +68,8 @@ protected void onCreate(Bundle savedInstanceState) { TextView tvMunicipio = findViewById(R.id.tvMunicipio); TextView tvDireccion = findViewById(R.id.tvDireccion); TextView tvHorario = findViewById(R.id.tvHorario); - TextView tvPrecioSumario = findViewById(R.id.tvPrecioSumario); - TextView tvGasoleoA = findViewById(R.id.tvGasoleoA); - TextView tvGasolina95 = findViewById(R.id.tvGasolina95); + ListView list = findViewById(R.id.lvCombustibles); + // Get Gas Station from the intent that triggered this activity Gasolinera gasolinera = Parcels.unwrap(getIntent().getExtras().getParcelable(INTENT_STATION)); @@ -70,28 +85,12 @@ protected void onCreate(Bundle savedInstanceState) { tvDireccion.setText(gasolinera.getDireccion()); tvHorario.setText(gasolinera.getHorario()); - double precioSumario = precioSumario(gasolinera); - - // Mostrar sumario si esta disponible - if (precioSumario > 0) { - tvPrecioSumario.setText(String.format("%.2f", precioSumario) + "€"); - } else { - tvPrecioSumario.setText("-"); - } - - // Mostrar diésel si está disponible - if (gasolinera.getGasoleoA() > 0) { - tvGasoleoA.setText(String.format("%.2f", gasolinera.getGasoleoA()) + "€"); - } else { - tvGasoleoA.setText("-"); - } + //Set Lista Combustibles + List combustibles = new ArrayList<>(); - // Mostrar gasolina si está disponible - if (gasolinera.getGasolina95E5() > 0) { - tvGasolina95.setText(String.format("%.2f", gasolinera.getGasolina95E5()) + "€"); - } else { - tvGasolina95.setText("-"); - } + CombustibleArrayAdapter adapter = new CombustibleArrayAdapter(this, rellenaListaCombustibles(combustibles, gasolinera)); + list.setAdapter(adapter); + setListViewHeightBasedOnItemCount(list); } /** @@ -108,12 +107,4 @@ public boolean onOptionsItemSelected(MenuItem item) { } return super.onOptionsItemSelected(item); } - - /** - * @param gasolinera gasolinera sobre la que calcular el sumario - * @return media ponderada de los precios - */ - public double precioSumario(Gasolinera gasolinera) { - return (gasolinera.getGasoleoA() + gasolinera.getGasolina95E5() * 2) / 3; - } } \ No newline at end of file diff --git a/AndroidProject/app/src/main/java/es/unican/gasolineras/common/Utils.java b/AndroidProject/app/src/main/java/es/unican/gasolineras/common/Utils.java index 91bc667..3d25bf2 100644 --- a/AndroidProject/app/src/main/java/es/unican/gasolineras/common/Utils.java +++ b/AndroidProject/app/src/main/java/es/unican/gasolineras/common/Utils.java @@ -1,8 +1,26 @@ package es.unican.gasolineras.common; +import static es.unican.gasolineras.model.TipoCombustible.BIODIESEL; +import static es.unican.gasolineras.model.TipoCombustible.BIOETANOL; +import static es.unican.gasolineras.model.TipoCombustible.GASOLEO_A; +import static es.unican.gasolineras.model.TipoCombustible.GASOLEO_B; +import static es.unican.gasolineras.model.TipoCombustible.GASOLEO_PREMIUM; +import static es.unican.gasolineras.model.TipoCombustible.GASOLINA_95_E10; +import static es.unican.gasolineras.model.TipoCombustible.GASOLINA_95_E5; +import static es.unican.gasolineras.model.TipoCombustible.GASOLINA_95_E5_PREMIUM; +import static es.unican.gasolineras.model.TipoCombustible.GASOLINA_98_E10; +import static es.unican.gasolineras.model.TipoCombustible.GASOLINA_98_E5; +import static es.unican.gasolineras.model.TipoCombustible.GLP; +import static es.unican.gasolineras.model.TipoCombustible.GNC; +import static es.unican.gasolineras.model.TipoCombustible.GNL; +import static es.unican.gasolineras.model.TipoCombustible.HIDROGENO; import static es.unican.gasolineras.repository.GasolinerasService.deserializer; import android.content.Context; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ListAdapter; +import android.widget.ListView; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; @@ -16,6 +34,7 @@ import java.util.List; import es.unican.gasolineras.model.Gasolinera; +import es.unican.gasolineras.model.GasolineraCombustible; import es.unican.gasolineras.model.GasolinerasResponse; /** @@ -42,4 +61,78 @@ public static List parseGasolineras(Context context, int jsonId) { List gasolineras = response.getGasolineras(); return gasolineras; } + + /** + * Rellena una lista de los combustibles disponibles y su precio de la gasolinera + * @param combustibles lista a rellenar + * @param gasolinera gasolionera de obtener los combustibles + * @return + */ + public static List rellenaListaCombustibles(List combustibles, Gasolinera gasolinera) { + if (gasolinera.getBiodiesel() != 0) { + combustibles.add(new GasolineraCombustible(BIODIESEL, gasolinera.getBiodiesel())); + } + if (gasolinera.getBioetanol() != 0) { + combustibles.add(new GasolineraCombustible(BIOETANOL, gasolinera.getBioetanol())); + } + if (gasolinera.getGnc() != 0) { + combustibles.add(new GasolineraCombustible(GNC, gasolinera.getGnc())); + } + if (gasolinera.getGnl() != 0) { + combustibles.add(new GasolineraCombustible(GNL, gasolinera.getGnl())); + } + if (gasolinera.getGlp() != 0) { + combustibles.add(new GasolineraCombustible(GLP, gasolinera.getGlp())); + } + if (gasolinera.getGasoleoA() != 0) { + combustibles.add(new GasolineraCombustible(GASOLEO_A, gasolinera.getGasoleoA())); + } + if (gasolinera.getGasoleoB() != 0) { + combustibles.add(new GasolineraCombustible(GASOLEO_B, gasolinera.getGasoleoB())); + } + if (gasolinera.getGasoleoPremium() != 0) { + combustibles.add(new GasolineraCombustible(GASOLEO_PREMIUM, gasolinera.getGasoleoPremium())); + } + if (gasolinera.getGasolina95E10() != 0) { + combustibles.add(new GasolineraCombustible(GASOLINA_95_E10, gasolinera.getGasolina95E10())); + } + if (gasolinera.getGasolina95E5() != 0) { + combustibles.add(new GasolineraCombustible(GASOLINA_95_E5, gasolinera.getGasolina95E5())); + } + if (gasolinera.getGasolina95E5Premium() != 0) { + combustibles.add(new GasolineraCombustible(GASOLINA_95_E5_PREMIUM, gasolinera.getGasolina95E5Premium())); + } + if (gasolinera.getGasolina98E10() != 0) { + combustibles.add(new GasolineraCombustible(GASOLINA_98_E10, gasolinera.getGasolina98E10())); + } + if (gasolinera.getGasolina98E5() != 0) { + combustibles.add(new GasolineraCombustible(GASOLINA_98_E5, gasolinera.getGasolina98E5())); + } + if (gasolinera.getHidrogeno() != 0) { + combustibles.add(new GasolineraCombustible(HIDROGENO, gasolinera.getHidrogeno())); + } + + return combustibles; + } + + /** + * establece la altura a la listView segun cuantos elementos tenga en ella de modo que no se + * pueda scrollear + * @param listView + */ + public static void setListViewHeightBasedOnItemCount(ListView listView) { + // Altura de cada elemento en píxeles + int itemHeight = (int) (64 * listView.getContext().getResources().getDisplayMetrics().density); + + // Altura total de la lista + int totalHeight = itemHeight * listView.getAdapter().getCount(); + + // Ajustar la altura de la ListView + ViewGroup.LayoutParams params = listView.getLayoutParams(); + params.height = totalHeight + (listView.getDividerHeight() * (listView.getAdapter().getCount() - 1)); + listView.setLayoutParams(params); + listView.requestLayout(); + } + + } diff --git a/AndroidProject/app/src/main/java/es/unican/gasolineras/model/GasolineraCombustible.java b/AndroidProject/app/src/main/java/es/unican/gasolineras/model/GasolineraCombustible.java new file mode 100644 index 0000000..f0f7c6f --- /dev/null +++ b/AndroidProject/app/src/main/java/es/unican/gasolineras/model/GasolineraCombustible.java @@ -0,0 +1,17 @@ +package es.unican.gasolineras.model; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class GasolineraCombustible { + + private TipoCombustible combustible; + private double precio; + + public GasolineraCombustible(TipoCombustible combustible, double precio){ + this.combustible = combustible; + this.precio = precio; + } +} diff --git a/AndroidProject/app/src/main/res/layout/activity_details_view.xml b/AndroidProject/app/src/main/res/layout/activity_details_view.xml index b6b047e..4101fb0 100644 --- a/AndroidProject/app/src/main/res/layout/activity_details_view.xml +++ b/AndroidProject/app/src/main/res/layout/activity_details_view.xml @@ -25,171 +25,137 @@ android:padding="16dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintHorizontal_bias="0.0" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/toolbar" - app:layout_constraintVertical_bias="0.5"> + app:layout_constraintVertical_bias="0.0"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:layout_height="wrap_content"> - - + android:orientation="vertical" > + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + > + + + + + + + diff --git a/AndroidProject/app/src/main/res/layout/activity_main.xml b/AndroidProject/app/src/main/res/layout/activity_main.xml index 7a79150..ef927ff 100644 --- a/AndroidProject/app/src/main/res/layout/activity_main.xml +++ b/AndroidProject/app/src/main/res/layout/activity_main.xml @@ -26,6 +26,7 @@ android:layout_height="0dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintHorizontal_bias="0.0" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/toolbar" /> diff --git a/AndroidProject/app/src/main/res/layout/activity_precio_combustible_list_item.xml b/AndroidProject/app/src/main/res/layout/activity_precio_combustible_list_item.xml new file mode 100644 index 0000000..812e228 --- /dev/null +++ b/AndroidProject/app/src/main/res/layout/activity_precio_combustible_list_item.xml @@ -0,0 +1,37 @@ + + + + + + + + + \ No newline at end of file diff --git a/AndroidProject/app/src/main/res/raw/pruebas_interfaz_mostrar_precios_combustible.json b/AndroidProject/app/src/main/res/raw/pruebas_interfaz_mostrar_precios_combustible.json new file mode 100644 index 0000000..b8eb4a1 --- /dev/null +++ b/AndroidProject/app/src/main/res/raw/pruebas_interfaz_mostrar_precios_combustible.json @@ -0,0 +1,112 @@ +{ + "Fecha": "19\/08\/2024 14:36:51", + "ListaEESSPrecio": [ + { + "C.P.": "39500", + "Dirección": "CALLE DEL HOYO 55", + "Horario": "L-D: 08:00-21:00", + "Latitud": "16,395944", + "Localidad": "HERRERA", + "Longitud (WGS84)": "-12,155194", + "Margen": "D", + "Municipio": "Mazcuerras", + "Precio Biodiesel": "1,1", + "Precio Bioetanol": "1,2", + "Precio Gas Natural Comprimido": "1,3", + "Precio Gas Natural Licuado": "1,4", + "Precio Gases licuados del petróleo": "1,5", + "Precio Gasoleo A": "1,6", + "Precio Gasoleo B": "1,7", + "Precio Gasoleo Premium": "1,8", + "Precio Gasolina 95 E10": "1,9", + "Precio Gasolina 95 E5": "2,0", + "Precio Gasolina 95 E5 Premium": "2,1", + "Precio Gasolina 98 E10": "2,2", + "Precio Gasolina 98 E5": "2,3", + "Precio Hidrogeno": "2,4", + "Provincia": "CANTABRIA", + "Remisión": "dm", + "Rótulo": "CEPSA", + "Tipo Venta": "P", + "% BioEtanol": "0,0", + "% Éster metílico": "0,0", + "IDEESS": "1039", + "IDMunicipio": "5744", + "IDProvincia": "39", + "IDCCAA": "06" + }, + { + "C.P.": "39500", + "Dirección": "GANDARA", + "Horario": "L-S: 07:30-21:30; D: 08:30-21:30", + "Latitud": "41,341889", + "Localidad": "IBIO", + "Longitud (WGS84)": "-3,568167", + "Margen": "D", + "Municipio": "Mazcuerras", + "Precio Biodiesel": "1,1", + "Precio Bioetanol": "", + "Precio Gas Natural Comprimido": "1,3", + "Precio Gas Natural Licuado": "", + "Precio Gases licuados del petróleo": "", + "Precio Gasoleo A": "1,6", + "Precio Gasoleo B": "1,7", + "Precio Gasoleo Premium": "1,8", + "Precio Gasolina 95 E10": "", + "Precio Gasolina 95 E5": "", + "Precio Gasolina 95 E5 Premium": "", + "Precio Gasolina 98 E10": "", + "Precio Gasolina 98 E5": "", + "Precio Hidrogeno": "2,4", + "Provincia": "CANTABRIA", + "Remisión": "OM", + "Rótulo": "REPSOL", + "Tipo Venta": "P", + "% BioEtanol": "0,0", + "% Éster metílico": "0,0", + "IDEESS": "1048", + "IDMunicipio": "5745", + "IDProvincia": "39", + "IDCCAA": "06" + }, + + + { + "C.P.": "39500", + "Dirección": "PESA", + "Horario": "L-D: 06:00-22:00", + "Latitud": "43,191972", + "Localidad": "CABEZON DE LA SAL", + "Longitud (WGS84)": "-4,057844", + "Margen": "D", + "Municipio": "Cabezon", + "Precio Biodiesel": "", + "Precio Bioetanol": "", + "Precio Gas Natural Comprimido": "", + "Precio Gas Natural Licuado": "", + "Precio Gases licuados del petróleo": "", + "Precio Gasoleo A": "", + "Precio Gasoleo B": "", + "Precio Gasoleo Premium": "", + "Precio Gasolina 95 E10": "", + "Precio Gasolina 95 E5": "", + "Precio Gasolina 95 E5 Premium": "", + "Precio Gasolina 98 E10": "", + "Precio Gasolina 98 E5": "", + "Precio Hidrogeno": "", + "Provincia": "CANTABRIA", + "Remisión": "OM", + "Rótulo": "PETRONOR", + "Tipo Venta": "P", + "% BioEtanol": "0,0", + "% Éster metílico": "0,0", + "IDEESS": "1036", + "IDMunicipio": "5747", + "IDProvincia": "39", + "IDCCAA": "06" + } + ], + "Nota": "Archivo de todos los productos en todas las estaciones de servicio. La actualización de precios se realiza cada media hora, con los precios en vigor en ese momento.", + "ResultadoConsulta": "OK" +} + diff --git a/Docs/Test Plans/506399 - Mostrar Detalles de Horario - TestPlan.pdf b/Docs/Test Plans/506399 - Mostrar Detalles de Horario - TestPlan.pdf new file mode 100644 index 0000000..2f14daa Binary files /dev/null and b/Docs/Test Plans/506399 - Mostrar Detalles de Horario - TestPlan.pdf differ