-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/506090-RegistrarDescuentoEnMarca' into develop
- Loading branch information
Showing
16 changed files
with
446 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 1 addition & 6 deletions
7
...src/main/java/es/unican/gasolineras/activities/ConsultarRepostaje/ConsultarPresenter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 3 additions & 7 deletions
10
.../app/src/main/java/es/unican/gasolineras/activities/ConsultarRepostaje/ConsultarView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
.../java/es/unican/gasolineras/activities/RegistrarDescuentoEnMarca/IRegistrarDescuento.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
|
||
} |
52 changes: 52 additions & 0 deletions
52
.../unican/gasolineras/activities/RegistrarDescuentoEnMarca/RegistrarDescuentoPresenter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
144 changes: 144 additions & 0 deletions
144
...va/es/unican/gasolineras/activities/RegistrarDescuentoEnMarca/RegistrarDescuentoView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.