Skip to content

Commit

Permalink
Realizados cambios para implementar plan de accion
Browse files Browse the repository at this point in the history
  • Loading branch information
alexiasd678 committed Nov 6, 2024
1 parent e643a32 commit af47ee1
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
import static es.unican.gasolineras.utils.MockRepositories.getTestRepository;

import android.content.Context;
import android.graphics.Color;

import androidx.test.espresso.Espresso;
import androidx.test.espresso.matcher.HasBackgroundMatcher;
import androidx.test.ext.junit.rules.ActivityScenarioRule;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;
Expand All @@ -30,7 +28,6 @@
import es.unican.gasolineras.activities.RegistrarRepostajeMenu.RegistrarView;
import es.unican.gasolineras.injection.RepositoriesModule;
import es.unican.gasolineras.repository.IGasolinerasRepository;
import es.unican.gasolineras.utils.Matchers;

@UninstallModules(RepositoriesModule.class)
@HiltAndroidTest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package es.unican.gasolineras.utils;

import android.view.View;
import android.widget.ListView;

import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;


import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import androidx.annotation.DrawableRes;
import androidx.core.content.res.ResourcesCompat;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

import android.app.Application;

import androidx.room.Room;

import dagger.hilt.android.HiltAndroidApp;
import es.unican.gasolineras.repository.AppDatabase;
import lombok.Getter;

/**
* The Application class must be explicitly annotated for the dependency injection to work
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
import android.widget.TextView;
import android.widget.Toast;


import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;


import java.util.List;
import java.util.Locale;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,19 @@ public void init(){
EditText textDescuento = findViewById(R.id.etDescuento);

Button btnGuardar = findViewById(R.id.btnGuardar);
btnGuardar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String marca = spMarcas.getSelectedItem().toString().toUpperCase();
String descuentoStr = textDescuento.getText().toString().trim();
//Se comprueba que el campo del descuento no este vacio
if(descuentoStr.isEmpty()){
mostrarError("Los campos no deben estar vacios", true);
return;
}
try {
double descuento = Double.parseDouble(descuentoStr);
presenter.onBtnGuardarClicked(marca, descuento);
}catch(NumberFormatException e){
mostrarError("El valor del campo debe ser un número entero", true);
}
btnGuardar.setOnClickListener(v -> {
String marca = spMarcas.getSelectedItem().toString().toUpperCase();
String descuentoStr = textDescuento.getText().toString().trim();
//Se comprueba que el campo del descuento no este vacio
if(descuentoStr.isEmpty()){
mostrarError("Los campos no deben estar vacios", true);
return;
}
try {
double descuento = Double.parseDouble(descuentoStr);
presenter.onBtnGuardarClicked(marca, descuento);
}catch(NumberFormatException e){
mostrarError("El valor del campo debe ser un número entero", true);
}
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package es.unican.gasolineras.activities.RegistrarRepostajeMenu;

import android.graphics.Color;
import android.util.Log;

import java.text.SimpleDateFormat;
import java.util.Calendar;
Expand All @@ -14,7 +12,6 @@ public class RegistrarPresenter implements IRegistrar.Presenter {
/** The view that is controlled by this presenter */
private IRegistrar.View view;
private RepostajeDAO repostajeDAO;
//private int uid = 1;

public RegistrarPresenter(RepostajeDAO repostajeDAO) {
this.repostajeDAO = repostajeDAO;
Expand Down Expand Up @@ -65,24 +62,16 @@ public void onBtnGuardarClicked(String litros, String precioTotal) {

// Crear el objeto Repostaje
Repostaje repostaje = new Repostaje();
//repostaje.setUid(uid);
repostaje.setLitros(litrosNum);
repostaje.setPrecioTotal(precioTotalNum);
//uid++;


// Asignar la fecha actual al repostaje
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String fechaActual = sdf.format(Calendar.getInstance().getTime());
repostaje.setFechaRepostaje(fechaActual);

try {
repostajeDAO.registrarRepostaje(repostaje);
view.showBtnGuardar(litros, precioTotal);

} catch (Exception e) {
view.mostrarError("Error al registrar el repostaje en la base de datos", false, false);
}
registrarRepostaje(repostaje, litros, precioTotal);

} catch (NumberFormatException e) {
// Manejo de excepciones si los valores ingresados no son válidos
Expand Down Expand Up @@ -112,4 +101,14 @@ public void onBtnGuardarClicked(String litros, String precioTotal) {
public void onBtnCancelarClicked() {
view.showBtnCancelar();
}

// Nuevo método extraído para manejar el registro en la base de datos
private void registrarRepostaje(Repostaje repostaje, String litros, String precioTotal) {
try {
repostajeDAO.registrarRepostaje(repostaje);
view.showBtnGuardar(litros, precioTotal);
} catch (Exception e) {
view.mostrarError("Error al registrar el repostaje en la base de datos", false, false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,18 @@
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;



import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;


import org.w3c.dom.Text;

import es.unican.gasolineras.R;
import es.unican.gasolineras.activities.ConsultarRepostaje.ConsultarView;
import es.unican.gasolineras.activities.main.MainView;
import es.unican.gasolineras.model.Gasolinera;
import es.unican.gasolineras.repository.AppDatabase;
import es.unican.gasolineras.repository.DatabaseFunction;

Expand Down Expand Up @@ -59,14 +51,11 @@ public void init() {
EditText editTextPrecioTotal = findViewById(R.id.textPrecioTotal);

Button buttonGuardar = findViewById(R.id.btnGuardar);
buttonGuardar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Lógica para obtener los valores de litros y precioTotal
String litros = editTextLitros.getText().toString() ; // Obtén el valor de la forma adecuada
String precioTotal = editTextPrecioTotal.getText().toString(); // Obtén el valor de la forma adecuada
presenter.onBtnGuardarClicked(litros, precioTotal); // Llama al método con los parámetros
}
buttonGuardar.setOnClickListener(v -> {
// Lógica para obtener los valores de litros y precioTotal
String litros = editTextLitros.getText().toString() ; // Obtén el valor de la forma adecuada
String precioTotal = editTextPrecioTotal.getText().toString(); // Obtén el valor de la forma adecuada
presenter.onBtnGuardarClicked(litros, precioTotal); // Llama al método con los parámetros
});

Button buttonCancelar = findViewById(R.id.btnCancelar);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.ArrayList;
import java.util.List;

import es.unican.gasolineras.activities.RegistrarRepostajeMenu.IRegistrar;
import es.unican.gasolineras.model.Gasolinera;
import es.unican.gasolineras.model.IDCCAAs;
import es.unican.gasolineras.repository.ICallBack;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package es.unican.gasolineras.repository;

import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;

import es.unican.gasolineras.model.Repostaje;
import es.unican.gasolineras.model.Descuento;
import lombok.Getter;

@Database(entities = {Repostaje.class, Descuento.class}, version = 5, exportSchema = false)
public abstract class AppDatabase extends RoomDatabase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private GasolinerasService() {
}

/** Open Charge Map API base URL*/
final static String BASE_URL = "https://sedeaplicaciones.minetur.gob.es/ServiciosRESTCarburantes/PreciosCarburantes/";
static final String BASE_URL = "https://sedeaplicaciones.minetur.gob.es/ServiciosRESTCarburantes/PreciosCarburantes/";

/** Custom deserializer to support spanish format of float numbers (with comma separator) */
public static final JsonDeserializer<Double> deserializer;
Expand Down
1 change: 0 additions & 1 deletion AndroidProject/app/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
<!-- Base application theme. -->
<style name="Base.Theme.Gasolineras" parent="Theme.Material3.DayNight.NoActionBar">
<!-- Customize your dark theme here. -->
<!-- <item name="colorPrimary">@color/my_dark_primary</item> -->
</style>
</resources>
1 change: 0 additions & 1 deletion AndroidProject/app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<color name="colorPrimaryDark">#303F9F</color>

<!-- a secondary color for controls like checkboxes and text fields. -->
<!--<color name="colorAccent">#FF4081</color> -->

<color name="text_green">#00CB00</color> <!-- verde -->
<color name="text_default">#000000</color> <!-- color por defecto -->
Expand Down
1 change: 0 additions & 1 deletion AndroidProject/app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<!-- <item name="colorAccent">@color/colorAccent</item> -->

</style>
<style name="Theme.Gasolineras" parent="Base.Theme.Gasolineras" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package es.unican.gasolineras.RegistrarRepostajeMenu;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;

import android.content.Context;
Expand All @@ -20,10 +18,8 @@

import es.unican.gasolineras.activities.RegistrarRepostajeMenu.RegistrarPresenter;
import es.unican.gasolineras.activities.RegistrarRepostajeMenu.RegistrarView;
import es.unican.gasolineras.model.Repostaje;
import es.unican.gasolineras.repository.AppDatabase;
import es.unican.gasolineras.repository.DatabaseFunction;
import es.unican.gasolineras.repository.RepostajeDAO;


@RunWith(RobolectricTestRunner.class)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package es.unican.gasolineras.RegistrarRepostajeMenu;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

Expand Down

0 comments on commit af47ee1

Please sign in to comment.