Commit 835e98866a1f4d1fd6ecf90771efacf2a674c1c0

Authored by badetitou
1 parent 393ff95e

Design create Consommation

app/src/main/java/net/plil/clubinfo/etunicorn/app/consommation/CreateConsommation.java
... ... @@ -3,10 +3,14 @@ package net.plil.clubinfo.etunicorn.app.consommation;
3 3 import android.app.Dialog;
4 4 import android.content.DialogInterface;
5 5 import android.os.Bundle;
  6 +import android.support.design.widget.TextInputLayout;
6 7 import android.support.v4.app.DialogFragment;
7 8 import android.support.v7.app.AlertDialog;
  9 +import android.text.Editable;
  10 +import android.text.TextWatcher;
8 11 import android.view.LayoutInflater;
9 12 import android.view.View;
  13 +import android.widget.Button;
10 14 import android.widget.EditText;
11 15 import android.widget.ProgressBar;
12 16  
... ... @@ -27,6 +31,8 @@ public class CreateConsommation extends DialogFragment {
27 31 EditText mNomConsomation;
28 32 EditText mPrice;
29 33 ProgressBar mProgressBar;
  34 + TextInputLayout mNomInput;
  35 + TextInputLayout mPriceInput;
30 36  
31 37  
32 38 @Override
... ... @@ -37,46 +43,68 @@ public class CreateConsommation extends DialogFragment {
37 43 mNomConsomation = (EditText) view.findViewById(R.id.create_consomation_name);
38 44 mPrice = (EditText) view.findViewById(R.id.create_consomation_price);
39 45 mProgressBar = (ProgressBar) view.findViewById(R.id.create_consomation_progress_bar);
40   - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
41   - builder
  46 + mNomInput = (TextInputLayout) view.findViewById(R.id.create_consomation_name_input);
  47 + mPriceInput = (TextInputLayout) view.findViewById(R.id.create_consomation_price_input);
  48 + AlertDialog dialog = new AlertDialog.Builder(getActivity())
42 49 .setTitle(R.string.create_consumable)
43 50 .setView(view)
44   - .setPositiveButton(R.string.valid, new DialogInterface.OnClickListener() {
45   - public void onClick(DialogInterface dialog, int id) {
46   -
47   - mProgressBar.setVisibility(View.VISIBLE);
48   - mPrice.setVisibility(View.GONE);
49   - mNomConsomation.setVisibility(View.GONE);
50   - JSONObject jsonObject = new JSONObject();
51   - try {
52   - jsonObject.put("nomConsomation", mNomConsomation.getText().toString());
53   - jsonObject.put("prix", Double.parseDouble(mPrice.getText().toString()));
54   - } catch (JSONException e){
55   - e.printStackTrace();
  51 + .setPositiveButton(R.string.valid, null)
  52 + .setNegativeButton(R.string.cancel, null)
  53 + .create();
  54 + dialog.setOnShowListener(new DialogInterface.OnShowListener() {
  55 + @Override
  56 + public void onShow(DialogInterface dialog) {
  57 + Button button = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE);
  58 + button.setOnClickListener(new View.OnClickListener() {
  59 + @Override
  60 + public void onClick(View v) {
  61 + boolean testDateInputOk = true;
  62 + if (mPrice.getText().toString().isEmpty()) {
  63 + mPriceInput.setError(getString(R.string.error_create_consomation_input_price));
  64 + testDateInputOk = false;
  65 + } else {
  66 + mPriceInput.setError(null);
  67 + }
  68 + if (mNomConsomation.getText().toString().isEmpty()){
  69 + mNomInput.setError(getString(R.string.error_create_consomation_input_nom));
  70 + testDateInputOk = false;
  71 + } else {
  72 + mNomInput.setError(null);
56 73 }
57   - JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, VolleyUtils.baseUri + "/transaction/debit" ,jsonObject , new Response.Listener<JSONObject>() {
58   - @Override
59   - public void onResponse(JSONObject response) {
60   - mProgressBar.setVisibility(View.GONE);
  74 + if (testDateInputOk) {
  75 + mPriceInput.setError(null);
  76 + mNomInput.setError(null);
  77 + mProgressBar.setVisibility(View.VISIBLE);
  78 + mPriceInput.setVisibility(View.GONE);
  79 + mNomInput.setVisibility(View.GONE);
  80 + JSONObject jsonObject = new JSONObject();
  81 + try {
  82 + jsonObject.put("nomConsomation", mNomConsomation.getText().toString());
  83 + jsonObject.put("prix", Double.parseDouble(mPrice.getText().toString()));
  84 + } catch (JSONException e) {
  85 + e.printStackTrace();
61 86 }
62   - }, new Response.ErrorListener() {
63   - @Override
64   - public void onErrorResponse(VolleyError error) {
65   - mProgressBar.setVisibility(View.GONE);
  87 + JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, VolleyUtils.baseUri + "/transaction/debit", jsonObject, new Response.Listener<JSONObject>() {
  88 + @Override
  89 + public void onResponse(JSONObject response) {
  90 + mProgressBar.setVisibility(View.GONE);
  91 + dismiss();
  92 + }
  93 + }, new Response.ErrorListener() {
  94 + @Override
  95 + public void onErrorResponse(VolleyError error) {
  96 + mProgressBar.setVisibility(View.GONE);
  97 + dismiss();
  98 + }
66 99 }
  100 + );
  101 + VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest);
67 102 }
68   - );
69   -
70   - VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest);
71   - }
72   - })
73   - .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
74   - public void onClick(DialogInterface dialog, int id) {
75   - // User cancelled the dialog
76 103 }
77 104 });
78   - // Create the AlertDialog object and return it
79   - return builder.create();
  105 + }
  106 + });
  107 + return dialog;
80 108 }
81 109  
82 110  
... ...
app/src/main/java/net/plil/clubinfo/etunicorn/app/personne/CreatePersonne.java
... ... @@ -144,12 +144,13 @@ public class CreatePersonne extends DialogFragment {
144 144 public void onResponse(JSONObject response) {
145 145 JSONArray jsonArray = null;
146 146 try {
  147 + //TODO change this by the real name of the array
147 148 jsonArray = response.getJSONArray("roles");
148 149 arraySpinnerRole.clear();
149 150 for (int i =0; i<jsonArray.length();++i){
150 151 arraySpinnerRole.add(new Gson().fromJson(String.valueOf(jsonArray.getJSONObject(i)), Role.class));
151 152 }
152   - response.getJSONArray("hello").length();
  153 + adapterRole.notifyDataSetChanged();
153 154 } catch (JSONException e) {
154 155 e.printStackTrace();
155 156 }
... ...
app/src/main/java/net/plil/clubinfo/etunicorn/data/Role.java
... ... @@ -29,4 +29,9 @@ public class Role implements Serializable{
29 29 public void setPermissions(List<Permission> permissions) {
30 30 this.permissions = permissions;
31 31 }
  32 +
  33 + @Override
  34 + public String toString(){
  35 + return getName();
  36 + }
32 37 }
... ...
app/src/main/res/layout/fragment_create_consomation.xml
... ... @@ -7,19 +7,29 @@
7 7 android:layout_height="match_parent"
8 8 >
9 9  
10   - <EditText
  10 + <android.support.design.widget.TextInputLayout
11 11 android:layout_width="match_parent"
12 12 android:layout_height="wrap_content"
13   - android:id="@+id/create_consomation_name"
14   - android:hint="@string/create_consumable_name"/>
  13 + android:id="@+id/create_consomation_name_input">
  14 + <android.support.design.widget.TextInputEditText
  15 + android:layout_width="match_parent"
  16 + android:layout_height="wrap_content"
  17 + android:id="@+id/create_consomation_name"
  18 + android:hint="@string/create_consumable_name"/>
  19 + </android.support.design.widget.TextInputLayout>
15 20  
16   - <EditText
  21 + <android.support.design.widget.TextInputLayout
17 22 android:layout_width="match_parent"
18 23 android:layout_height="match_parent"
19   - android:hint="@string/create_consumable_price"
20   - android:id="@+id/create_consomation_price"
21   - android:inputType="numberSigned|numberDecimal"
22   - android:maxLines="1" />
  24 + android:id="@+id/create_consomation_price_input">
  25 + <android.support.design.widget.TextInputEditText
  26 + android:layout_width="match_parent"
  27 + android:layout_height="match_parent"
  28 + android:hint="@string/create_consumable_price"
  29 + android:id="@+id/create_consomation_price"
  30 + android:inputType="numberSigned|numberDecimal"
  31 + android:maxLines="1" />
  32 + </android.support.design.widget.TextInputLayout>
23 33  
24 34 <ProgressBar
25 35 style="?android:attr/progressBarStyle"
... ...
app/src/main/res/values-fr/strings.xml
... ... @@ -41,4 +41,6 @@
41 41 <string name="create_personne_naissance">Date de naissance</string>
42 42 <string name="create_personne_role">Role</string>
43 43 <string name="error_enter_debit">Veuillez entrer une valeur avant d\'utiliser la carte NFC</string>
  44 + <string name="error_create_consomation_input_nom">Entrer le nom</string>
  45 + <string name="error_create_consomation_input_price">Entrer le prix</string>
44 46 </resources>
45 47 \ No newline at end of file
... ...
app/src/main/res/values/strings.xml
... ... @@ -42,4 +42,6 @@
42 42 <string name="create_personne_naissance">Birthday</string>
43 43 <string name="create_personne_role">Role</string>
44 44 <string name="error_enter_debit">Please enter a value before using your NFC card</string>
  45 + <string name="error_create_consomation_input_price">Enter the price</string>
  46 + <string name="error_create_consomation_input_nom">Enter the name</string>
45 47 </resources>
... ...