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 6feba38..339afa7 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 @@ -3,10 +3,14 @@ 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.text.Editable; +import android.text.TextWatcher; import android.view.LayoutInflater; import android.view.View; +import android.widget.Button; import android.widget.EditText; import android.widget.ProgressBar; @@ -27,6 +31,8 @@ public class CreateConsommation extends DialogFragment { EditText mNomConsomation; EditText mPrice; ProgressBar mProgressBar; + TextInputLayout mNomInput; + TextInputLayout mPriceInput; @Override @@ -37,46 +43,68 @@ public class CreateConsommation extends DialogFragment { mNomConsomation = (EditText) view.findViewById(R.id.create_consomation_name); mPrice = (EditText) view.findViewById(R.id.create_consomation_price); mProgressBar = (ProgressBar) view.findViewById(R.id.create_consomation_progress_bar); - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); - builder + mNomInput = (TextInputLayout) view.findViewById(R.id.create_consomation_name_input); + mPriceInput = (TextInputLayout) view.findViewById(R.id.create_consomation_price_input); + AlertDialog dialog = new AlertDialog.Builder(getActivity()) .setTitle(R.string.create_consumable) .setView(view) - .setPositiveButton(R.string.valid, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - - 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(); + .setPositiveButton(R.string.valid, null) + .setNegativeButton(R.string.cancel, null) + .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(View v) { + boolean testDateInputOk = true; + if (mPrice.getText().toString().isEmpty()) { + mPriceInput.setError(getString(R.string.error_create_consomation_input_price)); + testDateInputOk = false; + } else { + mPriceInput.setError(null); + } + if (mNomConsomation.getText().toString().isEmpty()){ + mNomInput.setError(getString(R.string.error_create_consomation_input_nom)); + testDateInputOk = false; + } else { + mNomInput.setError(null); } - JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, VolleyUtils.baseUri + "/transaction/debit" ,jsonObject , new Response.Listener() { - @Override - public void onResponse(JSONObject response) { - mProgressBar.setVisibility(View.GONE); + if (testDateInputOk) { + mPriceInput.setError(null); + mNomInput.setError(null); + mProgressBar.setVisibility(View.VISIBLE); + mPriceInput.setVisibility(View.GONE); + mNomInput.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(); } - }, new Response.ErrorListener() { - @Override - public void onErrorResponse(VolleyError error) { - mProgressBar.setVisibility(View.GONE); + JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, VolleyUtils.baseUri + "/transaction/debit", jsonObject, new Response.Listener() { + @Override + public void onResponse(JSONObject response) { + mProgressBar.setVisibility(View.GONE); + dismiss(); + } + }, new Response.ErrorListener() { + @Override + public void onErrorResponse(VolleyError error) { + mProgressBar.setVisibility(View.GONE); + dismiss(); + } } + ); + 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(); + } + }); + return dialog; } diff --git a/app/src/main/java/net/plil/clubinfo/etunicorn/app/personne/CreatePersonne.java b/app/src/main/java/net/plil/clubinfo/etunicorn/app/personne/CreatePersonne.java index 009c2ea..f5b781f 100644 --- a/app/src/main/java/net/plil/clubinfo/etunicorn/app/personne/CreatePersonne.java +++ b/app/src/main/java/net/plil/clubinfo/etunicorn/app/personne/CreatePersonne.java @@ -144,12 +144,13 @@ public class CreatePersonne extends DialogFragment { public void onResponse(JSONObject response) { JSONArray jsonArray = null; try { + //TODO change this by the real name of the array jsonArray = response.getJSONArray("roles"); arraySpinnerRole.clear(); for (int i =0; i permissions) { this.permissions = permissions; } + + @Override + public String toString(){ + return getName(); + } } diff --git a/app/src/main/res/layout/fragment_create_consomation.xml b/app/src/main/res/layout/fragment_create_consomation.xml index 853f3bc..c171ac7 100644 --- a/app/src/main/res/layout/fragment_create_consomation.xml +++ b/app/src/main/res/layout/fragment_create_consomation.xml @@ -7,19 +7,29 @@ android:layout_height="match_parent" > - + android:id="@+id/create_consomation_name_input"> + + - + android:id="@+id/create_consomation_price_input"> + + Date de naissance Role Veuillez entrer une valeur avant d\'utiliser la carte NFC + Entrer le nom + Entrer le prix \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2d44f78..b978c71 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -42,4 +42,6 @@ Birthday Role Please enter a value before using your NFC card + Enter the price + Enter the name -- libgit2 0.21.2