Skip to content

Commit

Permalink
Merge branch 'feature/506090-RegistrarDescuentoEnMarca' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Sara Saiz committed Nov 1, 2024
2 parents 42fe46a + 8b890ff commit 6218875
Show file tree
Hide file tree
Showing 16 changed files with 446 additions and 14 deletions.
2 changes: 2 additions & 0 deletions AndroidProject/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
<activity
android:name=".activities.details.DetailsView"
android:exported="false" />
<activity android:name=".activities.RegistrarDescuentoEnMarca.RegistrarDescuentoView"
android:exported="false" />
<activity
android:name=".activities.main.MainView"
android:exported="true">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
package es.unican.gasolineras.activities.ConsultarRepostaje;

import android.content.Context;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Collections;
import java.util.List;
import java.util.Locale;

import es.unican.gasolineras.activities.main.IMainContract;
import es.unican.gasolineras.model.Gasolinera;

import es.unican.gasolineras.model.Repostaje;
import es.unican.gasolineras.repository.AppDatabase;
import es.unican.gasolineras.repository.DatabaseFunction;
import es.unican.gasolineras.repository.RepostajeDAO;

public class ConsultarPresenter implements IConsultar.Presenter {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
package es.unican.gasolineras.activities.ConsultarRepostaje;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.ActionBar;

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

import java.text.SimpleDateFormat;
import java.util.Calendar;

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

import es.unican.gasolineras.R;

import es.unican.gasolineras.activities.main.IMainContract;
import es.unican.gasolineras.activities.main.MainView;
import es.unican.gasolineras.model.Gasolinera;
import es.unican.gasolineras.model.Repostaje;
import es.unican.gasolineras.repository.AppDatabase;
import es.unican.gasolineras.repository.DatabaseFunction;
import es.unican.gasolineras.repository.RepostajeDAO;


public class ConsultarView extends AppCompatActivity implements IConsultar.View {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package es.unican.gasolineras.activities.RegistrarDescuentoEnMarca;

import es.unican.gasolineras.activities.ConsultarRepostaje.IConsultar;

public interface IRegistrarDescuento {

/**
* Methods that must be implemented in the Main Presenter.
* Only the View should call these methods.
*/
public interface Presenter {
/**
* Links the presenter with its view.
* Only the View should call this method
* @param view
*/
public void init(View view);

/**
* Handles the process of validating and registering the discount
* Called when the user clicks the save button.
*/
void onBtnGuardarClicked(String marca, int descuento);

/**
* Llamado cuando se pulsa el boton de cancelar
*/
void onBtnCancelarClicked();
}

public interface View {
/**
* Initialize the view. Typically this should initialize all the listeners in the view.
* Only the Presenter should call this method
*/
public void init();

/**
* Muestra si el repostaje se ha realizado correctamente o si hay algun problema
* @param marca marca a la que aplica el descuento
* @param descuento cantidad en % a descontar
*/
void showBtnGuardar(String marca, int descuento);

void showBtnCancelar();

void mostrarError(String mensajeError, boolean errorDescuento);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package es.unican.gasolineras.activities.RegistrarDescuentoEnMarca;

import java.util.List;

import es.unican.gasolineras.activities.ConsultarRepostaje.IConsultar;
import es.unican.gasolineras.activities.RegistrarRepostajeMenu.IRegistrar;
import es.unican.gasolineras.model.Gasolinera;
import es.unican.gasolineras.repository.DescuentoDAO;
import es.unican.gasolineras.repository.RepostajeDAO;

public class RegistrarDescuentoPresenter implements IRegistrarDescuento.Presenter{

private IRegistrarDescuento.View view;
private DescuentoDAO descuentoDAO;

public RegistrarDescuentoPresenter(DescuentoDAO descuentoDAO) {
this.descuentoDAO = descuentoDAO;
}

/**
* @see IRegistrarDescuento.Presenter#init(IResgistarDescuento.View)
* @param view the view to control
*/
@Override
public void init(IRegistrarDescuento.View view){

this.view = view;
this.view.init();
load();

}

private void load(){

}


/**
* @see IRegistrar.Presenter#onBtnGuardarClicked(String, String)
* @param marca marca a la que aplicar el filtro
* @param descuento descuento que se aplica
*/
public void onBtnGuardarClicked(String marca, int descuento) {
}

/**
* @see IRegistrar.Presenter#onBtnCancelarClicked()
*/
public void onBtnCancelarClicked() {
view.showBtnCancelar();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
package es.unican.gasolineras.activities.RegistrarDescuentoEnMarca;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;

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

import es.unican.gasolineras.R;
import es.unican.gasolineras.activities.RegistrarRepostajeMenu.IRegistrar;
import es.unican.gasolineras.activities.main.MainView;
import es.unican.gasolineras.repository.AppDatabase;
import es.unican.gasolineras.repository.DatabaseFunction;

public class RegistrarDescuentoView extends AppCompatActivity implements IRegistrarDescuento.View {

private RegistrarDescuentoPresenter presenter;

/**
* @see AppCompatActivity#onCreate(Bundle)
* @param savedInstanceState
*/
@Override
public void onCreate (Bundle savedInstanceState){

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_registrar_descuento_view);

Toolbar toolbar = findViewById(R.id.toolbar3);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle("Registrar descuento");

Spinner spn = findViewById(R.id.spMarcas);
// Configuramos el Spinner
// Tomamos sus valores posibles del array de strings "marcasArray", definido
// en string.xml
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.marcasArray,
android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spn.setAdapter(adapter);

AppDatabase db = DatabaseFunction.getDatabase(this);

presenter = new RegistrarDescuentoPresenter(db.descuentoDao());
presenter.init(this);
}

/**
* @see IRegistrarDescuento.View#init()
*/
@Override
public void init(){
Spinner spMarca = findViewById(R.id.spMarcas);
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 = spMarca.toString();
int descuento = Integer.parseInt(textDescuento.getText().toString());
presenter.onBtnGuardarClicked(marca, descuento);
}
});

Button btnCancelar = findViewById(R.id.btnCancelar);
btnCancelar.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
presenter.onBtnCancelarClicked();
}
});
}

/**
* @see IRegistrar.View#showBtnGuardar(String, String)
*/
@Override
public void showBtnGuardar(String marca, int descuento) {
try {
new AlertDialog.Builder(RegistrarDescuentoView.this)
.setMessage(getString(R.string.registro_descuento_exito))
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(RegistrarDescuentoView.this, MainView.class);
startActivity(intent);
}
})
.show();

} catch (Exception e) {

new AlertDialog.Builder(RegistrarDescuentoView.this)
.setTitle("Error")
.setMessage(getString(R.string.error_acceso_bbdd))
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Puedes agregar alguna acción adicional si es necesario
Intent intent = new Intent(RegistrarDescuentoView.this, MainView.class);
startActivity(intent);
}
})
.show();
}

}

@Override
public void showBtnCancelar() {

}

/**
*
* @see IRegistrarDescuento.View#mostrarError(String mensajeError, boolean errorDescuento)
*
* @param mensajeError the error message to show
*/
@Override
public void mostrarError(String mensajeError, boolean errorDescuento){
TextView tvError = findViewById(R.id.tvError2);
tvError.setText(mensajeError);
tvError.setVisibility(View.VISIBLE);

EditText etDescuento = findViewById(R.id.etDescuento);
if(errorDescuento) {
etDescuento.setBackgroundResource(R.drawable.border_red);
}else {
etDescuento.setBackgroundResource(R.drawable.border_default);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public interface Presenter {
*/
public void onMenuConsultarClicked();

void onMenuDescuentoClicked();
}

/**
Expand Down Expand Up @@ -124,5 +125,6 @@ public interface View {
public void showConsultarActivity();


void showDescuentoActivity();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class MainPresenter implements IMainContract.Presenter {
/** The view that is controlled by this presenter */
private IMainContract.View view;

private List<Gasolinera> gasolineras;

/**
* @see IMainContract.Presenter#init(IMainContract.View)
* @param view the view to control
Expand Down Expand Up @@ -57,6 +59,12 @@ public void onMenuConsultarClicked() {
view.showConsultarActivity();
}

/**
* @see IMainContract.Presenter#onMenuDescuentoClicked()
*/
@Override
public void onMenuDescuentoClicked() { view.showDescuentoActivity();}



/**
Expand All @@ -69,6 +77,7 @@ private void load() {

@Override
public void onSuccess(List<Gasolinera> stations) {
gasolineras = stations;
view.showStations(stations);
view.showLoadCorrect(stations.size());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import dagger.hilt.android.AndroidEntryPoint;
import es.unican.gasolineras.R;
import es.unican.gasolineras.activities.ConsultarRepostaje.ConsultarView;
import es.unican.gasolineras.activities.RegistrarDescuentoEnMarca.RegistrarDescuentoView;
import es.unican.gasolineras.activities.RegistrarRepostajeMenu.RegistrarView;
import es.unican.gasolineras.activities.info.InfoView;
import es.unican.gasolineras.activities.details.DetailsView;
Expand Down Expand Up @@ -95,6 +96,10 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
presenter.onMenuConsultarClicked();
return true;
}
if(itemId == R.id.menuItemDescuento) {
presenter.onMenuDescuentoClicked();
return true;
}
return super.onOptionsItemSelected(item);
}

Expand Down Expand Up @@ -186,4 +191,13 @@ public void showConsultarActivity() {
Intent intent = new Intent(this, ConsultarView.class);
startActivity(intent);
}

/**
* @see IMainContract.View#showDescuentoActivity()
*/
@Override
public void showDescuentoActivity() {
Intent intent = new Intent(this, RegistrarDescuentoView.class);
startActivity(intent);
}
}
Loading

0 comments on commit 6218875

Please sign in to comment.