diff --git a/app/src/main/java/net/plil/clubinfo/etunicorn/app/consommation/CreateConsommation.java b/app/src/main/java/net/plil/clubinfo/etunicorn/app/consommation/CreateConsommation.java index 339afa7..7759bd2 100644 --- a/app/src/main/java/net/plil/clubinfo/etunicorn/app/consommation/CreateConsommation.java +++ b/app/src/main/java/net/plil/clubinfo/etunicorn/app/consommation/CreateConsommation.java @@ -49,7 +49,12 @@ public class CreateConsommation extends DialogFragment { .setTitle(R.string.create_consumable) .setView(view) .setPositiveButton(R.string.valid, null) - .setNegativeButton(R.string.cancel, null) + .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + VolleyUtils.getInstance(getContext()).getRequestQueue().cancelAll(CreateConsommation.class); + } + }) .create(); dialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override @@ -79,7 +84,7 @@ public class CreateConsommation extends DialogFragment { mNomInput.setVisibility(View.GONE); JSONObject jsonObject = new JSONObject(); try { - jsonObject.put("nomConsomation", mNomConsomation.getText().toString()); + jsonObject.put("nom", mNomConsomation.getText().toString()); jsonObject.put("prix", Double.parseDouble(mPrice.getText().toString())); } catch (JSONException e) { e.printStackTrace(); @@ -98,14 +103,24 @@ public class CreateConsommation extends DialogFragment { } } ); + jsonObjectRequest.setTag(CreateConsommation.class); VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest); } } }); } }); + dialog.setCanceledOnTouchOutside(false); return dialog; } + @Override + public void onStop() { + VolleyUtils.getInstance(getContext()).getRequestQueue().cancelAll(CreateConsommation.class); + dismissAllowingStateLoss(); + super.onStop(); + } + + } diff --git a/app/src/main/java/net/plil/clubinfo/etunicorn/app/consommation/DeleteConsommation.java b/app/src/main/java/net/plil/clubinfo/etunicorn/app/consommation/DeleteConsommation.java index 0eef416..552c3bb 100644 --- a/app/src/main/java/net/plil/clubinfo/etunicorn/app/consommation/DeleteConsommation.java +++ b/app/src/main/java/net/plil/clubinfo/etunicorn/app/consommation/DeleteConsommation.java @@ -7,6 +7,7 @@ import android.support.v4.app.DialogFragment; import android.support.v7.app.AlertDialog; import android.view.LayoutInflater; import android.view.View; +import android.widget.Button; import android.widget.ProgressBar; import android.widget.TextView; import android.widget.Toast; @@ -58,15 +59,23 @@ public class DeleteConsommation extends DialogFragment { final Consommation consommation = (Consommation) getArguments().getSerializable("consommation"); - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); - builder + AlertDialog dialog = new AlertDialog.Builder(getActivity()) .setTitle(R.string.verif_delete_consomation) .setView(view) - .setPositiveButton(R.string.delete, new DialogInterface.OnClickListener() { + .setPositiveButton(R.string.delete, null) + .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + VolleyUtils.getInstance(getContext()).getRequestQueue().cancelAll(DeleteConsommation.class); + } + }).create(); + dialog.setOnShowListener(new DialogInterface.OnShowListener() { + @Override + public void onShow(DialogInterface dialog) { + Button button = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE); + button.setOnClickListener(new View.OnClickListener() { @Override - public void onClick(DialogInterface dialog, int which) { + public void onClick(View v) { mProgressBar.setVisibility(View.VISIBLE); - JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.DELETE, VolleyUtils.baseUri + "/consomation/" + consommation.getIdConsomation(), null, new Response.Listener() { @Override public void onResponse(JSONObject response) { @@ -79,20 +88,24 @@ public class DeleteConsommation extends DialogFragment { public void onErrorResponse(VolleyError error) { mProgressBar.setVisibility(View.GONE); Toast.makeText(getContext(), R.string.delete_refused, Toast.LENGTH_LONG).show(); - dismiss(); } } ); - + jsonObjectRequest.setTag(DeleteConsommation.class); VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest); } - }) - .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - - } }); - return builder.create(); + } + }); + dialog.setCanceledOnTouchOutside(false); + return dialog; + } + + @Override + public void onStop() { + VolleyUtils.getInstance(getContext()).getRequestQueue().cancelAll(DeleteConsommation.class); + dismissAllowingStateLoss(); + super.onStop(); } diff --git a/app/src/main/java/net/plil/clubinfo/etunicorn/app/consommation/FragmentConsommation.java b/app/src/main/java/net/plil/clubinfo/etunicorn/app/consommation/FragmentConsommation.java index 36170e3..631dfe7 100644 --- a/app/src/main/java/net/plil/clubinfo/etunicorn/app/consommation/FragmentConsommation.java +++ b/app/src/main/java/net/plil/clubinfo/etunicorn/app/consommation/FragmentConsommation.java @@ -105,7 +105,7 @@ public class FragmentConsommation extends FragmentNFC { Toast.makeText(getContext(), R.string.payment_consumable_alert_no_selection, Toast.LENGTH_LONG).show(); } else { - paiementConsommation.processNFC(); + paiementConsommation.processNFC(idCardUser); } } diff --git a/app/src/main/java/net/plil/clubinfo/etunicorn/app/consommation/ModifyConsommation.java b/app/src/main/java/net/plil/clubinfo/etunicorn/app/consommation/ModifyConsommation.java index 7682192..750f7dc 100644 --- a/app/src/main/java/net/plil/clubinfo/etunicorn/app/consommation/ModifyConsommation.java +++ b/app/src/main/java/net/plil/clubinfo/etunicorn/app/consommation/ModifyConsommation.java @@ -3,10 +3,12 @@ package net.plil.clubinfo.etunicorn.app.consommation; import android.app.Dialog; import android.content.DialogInterface; import android.os.Bundle; +import android.support.design.widget.TextInputLayout; import android.support.v4.app.DialogFragment; import android.support.v7.app.AlertDialog; import android.view.LayoutInflater; import android.view.View; +import android.widget.Button; import android.widget.EditText; import android.widget.ProgressBar; import android.widget.Toast; @@ -30,6 +32,8 @@ public class ModifyConsommation extends DialogFragment { EditText mNomConsomation; EditText mPrice; + TextInputLayout mPriceInput; + TextInputLayout mNomInput; ProgressBar mProgressBar; public static ModifyConsommation newInstance(Consommation consommation) { @@ -47,62 +51,92 @@ public class ModifyConsommation extends DialogFragment { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { // Use the Builder class for convenient dialog construction - LayoutInflater inflater = getActivity().getLayoutInflater(); + final LayoutInflater inflater = getActivity().getLayoutInflater(); View view = inflater.inflate(R.layout.fragment_modify_consommation, null); mNomConsomation = (EditText) view.findViewById(R.id.modify_consommation_name); mPrice = (EditText) view.findViewById(R.id.modify_consommation_price); mProgressBar = (ProgressBar) view.findViewById(R.id.modify_consommation_progress_bar); + mNomInput = (TextInputLayout) view.findViewById(R.id.modify_consommation_input_name); + mPriceInput = (TextInputLayout) view.findViewById(R.id.modify_consommation_input_price); final Consommation consommation = (Consommation) getArguments().getSerializable("consommation"); mNomConsomation.setText(consommation.getNomConsomation()); - mPrice.setText(String.format(Locale.FRANCE,"%.2f", consommation.getPrix())); + mPrice.setText(String.format(Locale.US,"%.2f", consommation.getPrix())); - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); - builder + AlertDialog dialog = new AlertDialog.Builder(getActivity()) .setTitle(R.string.modify) .setView(view) - .setPositiveButton(R.string.modify, new DialogInterface.OnClickListener() { + .setPositiveButton(R.string.modify, null) + .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { + VolleyUtils.getInstance(getContext()).getRequestQueue().cancelAll(ModifyConsommation.class); + } + }).create(); + // Create the AlertDialog object and return it - mProgressBar.setVisibility(View.VISIBLE); - mPrice.setVisibility(View.GONE); - mNomConsomation.setVisibility(View.GONE); - JSONObject jsonObject = new JSONObject(); - try { - jsonObject.put("nomConsomation", mNomConsomation.getText().toString()); - jsonObject.put("prix", Double.parseDouble(mPrice.getText().toString())); - } catch (JSONException e){ - e.printStackTrace(); + dialog.setOnShowListener(new DialogInterface.OnShowListener() { + @Override + public void onShow(DialogInterface dialog) { + Button button = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE); + button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + boolean inputOk = true; + if (mPrice.getText().toString().isEmpty()){ + inputOk = false; + mPriceInput.setError(getString(R.string.error_modify_consommation_input_price)); + } else { + mPriceInput.setError(null); } - JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.PUT, VolleyUtils.baseUri + "/consomation/" + consommation.getIdConsomation() ,jsonObject , new Response.Listener() { - @Override - public void onResponse(JSONObject response) { - mProgressBar.setVisibility(View.GONE); - Toast.makeText(getContext(), R.string.modify_done, Toast.LENGTH_LONG).show(); - + if (mNomConsomation.getText().toString().isEmpty()){ + inputOk = false; + mNomInput.setError(getString(R.string.error_modify_consommation_input_nom)); + } else { + mNomInput.setError(null); + } + if (inputOk) { + mProgressBar.setVisibility(View.VISIBLE); + mPriceInput.setVisibility(View.GONE); + mNomInput.setVisibility(View.GONE); + JSONObject jsonObject = new JSONObject(); + try { + jsonObject.put("nom", mNomConsomation.getText().toString()); + jsonObject.put("prix", Double.parseDouble(mPrice.getText().toString())); + } catch (JSONException e) { + e.printStackTrace(); } - }, new Response.ErrorListener() { - @Override - public void onErrorResponse(VolleyError error) { - mProgressBar.setVisibility(View.GONE); - Toast.makeText(getContext(), R.string.modify_refused, Toast.LENGTH_LONG).show(); - + JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.PUT, VolleyUtils.baseUri + "/consomation/" + consommation.getIdConsomation(), jsonObject, new Response.Listener() { + @Override + public void onResponse(JSONObject response) { + mProgressBar.setVisibility(View.GONE); + Toast.makeText(getContext(), R.string.modify_done, Toast.LENGTH_LONG).show(); + dismiss(); + + } + }, new Response.ErrorListener() { + @Override + public void onErrorResponse(VolleyError error) { + mProgressBar.setVisibility(View.GONE); + Toast.makeText(getContext(), R.string.modify_refused, Toast.LENGTH_LONG).show(); + } } + ); + jsonObjectRequest.setTag(ModifyConsommation.class); + VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest); } - ); - - VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest); - } - }) - .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - // User cancelled the dialog } }); - // Create the AlertDialog object and return it - return builder.create(); + }}); + dialog.setCanceledOnTouchOutside(false); + return dialog; } + @Override + public void onStop() { + VolleyUtils.getInstance(getContext()).getRequestQueue().cancelAll(ModifyConsommation.class); + dismissAllowingStateLoss(); + super.onStop(); + } } diff --git a/app/src/main/java/net/plil/clubinfo/etunicorn/app/consommation/PaiementConsommation.java b/app/src/main/java/net/plil/clubinfo/etunicorn/app/consommation/PaiementConsommation.java index 6e575aa..936a58d 100644 --- a/app/src/main/java/net/plil/clubinfo/etunicorn/app/consommation/PaiementConsommation.java +++ b/app/src/main/java/net/plil/clubinfo/etunicorn/app/consommation/PaiementConsommation.java @@ -5,6 +5,7 @@ import android.content.DialogInterface; import android.os.Bundle; import android.support.v4.app.DialogFragment; import android.support.v7.app.AlertDialog; +import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; import android.widget.ProgressBar; @@ -72,9 +73,9 @@ public class PaiementConsommation extends DialogFragment { .setView(view) .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { + VolleyUtils.getInstance(getContext()).getRequestQueue().cancelAll(PaiementConsommation.class); } }); - // Create the AlertDialog object and return it Dialog dialog = builder.create(); dialog.setCanceledOnTouchOutside(false); @@ -82,12 +83,12 @@ public class PaiementConsommation extends DialogFragment { } - public void processNFC() { + public void processNFC(String idCardUser) { + Toast.makeText(getContext(), "Hello " + idCardUser, Toast.LENGTH_LONG).show(); mProgressBar.setVisibility(View.VISIBLE); JSONObject jsonObject = new JSONObject(); try { - jsonObject.put("participant", 1); - jsonObject.put("acteur", 2); + jsonObject.put("participant", idCardUser); jsonObject.put("id", consommationId); } catch (JSONException e) { e.printStackTrace(); @@ -104,7 +105,6 @@ public class PaiementConsommation extends DialogFragment { public void onErrorResponse(VolleyError error) { mProgressBar.setVisibility(View.GONE); Toast.makeText(getContext(), R.string.payment_refused, Toast.LENGTH_LONG).show(); - dismiss(); } } ); @@ -112,21 +112,12 @@ public class PaiementConsommation extends DialogFragment { VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest); } - @Override - public void onCancel(DialogInterface dialog) { - VolleyUtils.getInstance(getContext()).getRequestQueue().cancelAll(PaiementConsommation.class); - super.onCancel(dialog); - } @Override public void onStop() { VolleyUtils.getInstance(getContext()).getRequestQueue().cancelAll(PaiementConsommation.class); + dismissAllowingStateLoss(); super.onStop(); } - @Override - public void onPause() { - super.onPause(); - dismiss(); - } } diff --git a/app/src/main/res/layout/fragment_modify_consommation.xml b/app/src/main/res/layout/fragment_modify_consommation.xml index cfa47d6..185b9b3 100644 --- a/app/src/main/res/layout/fragment_modify_consommation.xml +++ b/app/src/main/res/layout/fragment_modify_consommation.xml @@ -5,15 +5,27 @@ tools:context="net.plil.clubinfo.etunicorn.app.consommation.ModifyConsommation" android:orientation="vertical"> - + android:id="@+id/modify_consommation_input_name"> + + - + android:id="@+id/modify_consommation_input_price"> + + Please enter a value before using your NFC card Enter the price Enter the name + Enter the new price + Enter the new name + Name + Price -- libgit2 0.21.2