Commit db2235673b427d787101e29d2eecc3ac4529c218
1 parent
c0f970a0
Evenement modify beautiful dialog
Showing
8 changed files
with
284 additions
and
75 deletions
Show diff stats
app/src/main/java/net/plil/clubinfo/etunicorn/app/Event/CreateEvent.java
1 | package net.plil.clubinfo.etunicorn.app.event; | 1 | package net.plil.clubinfo.etunicorn.app.event; |
2 | 2 | ||
3 | +import android.app.DatePickerDialog; | ||
3 | import android.app.Dialog; | 4 | import android.app.Dialog; |
4 | import android.content.DialogInterface; | 5 | import android.content.DialogInterface; |
5 | import android.os.Bundle; | 6 | import android.os.Bundle; |
7 | +import android.support.design.widget.TextInputLayout; | ||
6 | import android.support.v4.app.DialogFragment; | 8 | import android.support.v4.app.DialogFragment; |
7 | import android.support.v7.app.AlertDialog; | 9 | import android.support.v7.app.AlertDialog; |
8 | import android.view.LayoutInflater; | 10 | import android.view.LayoutInflater; |
11 | +import android.view.MotionEvent; | ||
9 | import android.view.View; | 12 | import android.view.View; |
13 | +import android.widget.ArrayAdapter; | ||
14 | +import android.widget.Button; | ||
15 | +import android.widget.DatePicker; | ||
10 | import android.widget.EditText; | 16 | import android.widget.EditText; |
11 | import android.widget.ProgressBar; | 17 | import android.widget.ProgressBar; |
18 | +import android.widget.Spinner; | ||
19 | +import android.widget.Toast; | ||
12 | 20 | ||
13 | import com.android.volley.Request; | 21 | import com.android.volley.Request; |
14 | import com.android.volley.Response; | 22 | import com.android.volley.Response; |
@@ -16,18 +24,31 @@ import com.android.volley.VolleyError; | @@ -16,18 +24,31 @@ import com.android.volley.VolleyError; | ||
16 | import com.android.volley.toolbox.JsonObjectRequest; | 24 | import com.android.volley.toolbox.JsonObjectRequest; |
17 | 25 | ||
18 | import net.plil.clubinfo.etunicorn.R; | 26 | import net.plil.clubinfo.etunicorn.R; |
19 | -import net.plil.clubinfo.etunicorn.app.consommation.ModifyConsommation; | ||
20 | import net.plil.clubinfo.etunicorn.utils.VolleyUtils; | 27 | import net.plil.clubinfo.etunicorn.utils.VolleyUtils; |
21 | 28 | ||
22 | import org.json.JSONException; | 29 | import org.json.JSONException; |
23 | import org.json.JSONObject; | 30 | import org.json.JSONObject; |
24 | 31 | ||
32 | +import java.text.SimpleDateFormat; | ||
33 | +import java.util.Calendar; | ||
34 | +import java.util.Locale; | ||
35 | + | ||
25 | 36 | ||
26 | public class CreateEvent extends DialogFragment { | 37 | public class CreateEvent extends DialogFragment { |
27 | 38 | ||
39 | + Calendar myCalendar = Calendar.getInstance(); | ||
40 | + | ||
41 | + | ||
28 | EditText mName; | 42 | EditText mName; |
29 | EditText mPrice; | 43 | EditText mPrice; |
30 | - EditText mDate; | 44 | + Spinner mDate; |
45 | + | ||
46 | + TextInputLayout mPriceInput; | ||
47 | + TextInputLayout mNameInput; | ||
48 | + | ||
49 | + private String[] arraySpinnerDate; | ||
50 | + private ArrayAdapter<String> adapterDate; | ||
51 | + | ||
31 | ProgressBar mProgressBar; | 52 | ProgressBar mProgressBar; |
32 | 53 | ||
33 | 54 | ||
@@ -38,46 +59,99 @@ public class CreateEvent extends DialogFragment { | @@ -38,46 +59,99 @@ public class CreateEvent extends DialogFragment { | ||
38 | View view = inflater.inflate(R.layout.fragment_create_event, null); | 59 | View view = inflater.inflate(R.layout.fragment_create_event, null); |
39 | mName = (EditText) view.findViewById(R.id.create_event_name); | 60 | mName = (EditText) view.findViewById(R.id.create_event_name); |
40 | mPrice = (EditText) view.findViewById(R.id.create_event_price); | 61 | mPrice = (EditText) view.findViewById(R.id.create_event_price); |
41 | - mDate = (EditText) view.findViewById(R.id.create_event_date); | 62 | + mDate = (Spinner) view.findViewById(R.id.create_event_date); |
63 | + mPriceInput = (TextInputLayout) view.findViewById(R.id.create_event_price_input); | ||
64 | + mNameInput = (TextInputLayout) view.findViewById(R.id.create_event_name_input); | ||
65 | + arraySpinnerDate = new String[] { | ||
66 | + getString(R.string.create_event_date_input) | ||
67 | + }; | ||
68 | + adapterDate = new ArrayAdapter<>(getActivity(), | ||
69 | + R.layout.simple_item_layout, arraySpinnerDate); | ||
70 | + mDate.setAdapter(adapterDate); | ||
71 | + | ||
42 | mProgressBar = (ProgressBar) view.findViewById(R.id.create_event_progress_bar); | 72 | mProgressBar = (ProgressBar) view.findViewById(R.id.create_event_progress_bar); |
43 | AlertDialog dialog = new AlertDialog.Builder(getActivity()) | 73 | AlertDialog dialog = new AlertDialog.Builder(getActivity()) |
44 | .setTitle(R.string.create_event) | 74 | .setTitle(R.string.create_event) |
45 | .setView(view) | 75 | .setView(view) |
46 | - .setPositiveButton(R.string.valid, new DialogInterface.OnClickListener() { | 76 | + .setPositiveButton(R.string.valid, null) |
77 | + .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { | ||
47 | public void onClick(DialogInterface dialog, int id) { | 78 | public void onClick(DialogInterface dialog, int id) { |
79 | + VolleyUtils.getInstance(getContext()).getRequestQueue().cancelAll(CreateEvent.class); | ||
80 | + } | ||
81 | + }).create(); | ||
82 | + | ||
83 | + mDate.setOnTouchListener(new View.OnTouchListener() { | ||
84 | + @Override | ||
85 | + public boolean onTouch(View v, MotionEvent event) { | ||
86 | + if(event.getAction() == MotionEvent.ACTION_UP) { | ||
87 | + new DatePickerDialog(getContext(), date, myCalendar | ||
88 | + .get(Calendar.YEAR), myCalendar.get(Calendar.MONTH), | ||
89 | + myCalendar.get(Calendar.DAY_OF_MONTH)).show(); | ||
90 | + } | ||
91 | + return true; | ||
92 | + } | ||
93 | + }); | ||
48 | 94 | ||
49 | - mProgressBar.setVisibility(View.VISIBLE); | ||
50 | - mPrice.setVisibility(View.GONE); | ||
51 | - mName.setVisibility(View.GONE); | ||
52 | - JSONObject jsonObject = new JSONObject(); | ||
53 | - try { | ||
54 | - jsonObject.put("nomEvenement", mName.getText().toString()); | ||
55 | - jsonObject.put("prix", Double.parseDouble(mPrice.getText().toString())); | ||
56 | - jsonObject.put("date", mDate.getText().toString()); | ||
57 | - } catch (JSONException e){ | ||
58 | - e.printStackTrace(); | 95 | + dialog.setOnShowListener(new DialogInterface.OnShowListener() { |
96 | + @Override | ||
97 | + public void onShow(DialogInterface dialog) { | ||
98 | + Button button = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE); | ||
99 | + button.setOnClickListener(new View.OnClickListener() { | ||
100 | + @Override | ||
101 | + public void onClick(View v) { | ||
102 | + boolean testDateInputOk = true; | ||
103 | + if (mPrice.getText().toString().isEmpty()) { | ||
104 | + mPriceInput.setError(getString(R.string.error_create_event_input_price)); | ||
105 | + testDateInputOk = false; | ||
106 | + } else { | ||
107 | + mPriceInput.setError(null); | ||
59 | } | 108 | } |
60 | - JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, VolleyUtils.baseUri + "/evenement" ,jsonObject , new Response.Listener<JSONObject>() { | ||
61 | - @Override | ||
62 | - public void onResponse(JSONObject response) { | ||
63 | - mProgressBar.setVisibility(View.GONE); | 109 | + if (mName.getText().toString().isEmpty()){ |
110 | + mNameInput.setError(getString(R.string.error_create_event_input_nom)); | ||
111 | + testDateInputOk = false; | ||
112 | + } else { | ||
113 | + mNameInput.setError(null); | ||
114 | + } | ||
115 | + if (((String)mDate.getSelectedItem()).equals(getString(R.string.create_event_date))) { | ||
116 | + testDateInputOk = false; | ||
117 | + Toast.makeText(getContext(), getString(R.string.error_create_event_date), Toast.LENGTH_LONG).show(); | ||
118 | + } | ||
119 | + if (testDateInputOk) { | ||
120 | + mProgressBar.setVisibility(View.VISIBLE); | ||
121 | + mPriceInput.setVisibility(View.GONE); | ||
122 | + mNameInput.setVisibility(View.GONE); | ||
123 | + mDate.setVisibility(View.GONE); | ||
124 | + JSONObject jsonObject = new JSONObject(); | ||
125 | + try { | ||
126 | + jsonObject.put("nom", mName.getText().toString()); | ||
127 | + jsonObject.put("prix", Double.parseDouble(mPrice.getText().toString())); | ||
128 | + jsonObject.put("date", mDate.getAdapter().getItem(0)); | ||
129 | + } catch (JSONException e){ | ||
130 | + e.printStackTrace(); | ||
64 | } | 131 | } |
65 | - }, new Response.ErrorListener() { | ||
66 | - @Override | ||
67 | - public void onErrorResponse(VolleyError error) { | ||
68 | - mProgressBar.setVisibility(View.GONE); | 132 | + JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, VolleyUtils.baseUri + "/evenement" ,jsonObject , new Response.Listener<JSONObject>() { |
133 | + @Override | ||
134 | + public void onResponse(JSONObject response) { | ||
135 | + mProgressBar.setVisibility(View.GONE); | ||
136 | + } | ||
137 | + }, new Response.ErrorListener() { | ||
138 | + @Override | ||
139 | + public void onErrorResponse(VolleyError error) { | ||
140 | + mProgressBar.setVisibility(View.GONE); | ||
141 | + mPriceInput.setVisibility(View.VISIBLE); | ||
142 | + mNameInput.setVisibility(View.VISIBLE); | ||
143 | + mDate.setVisibility(View.VISIBLE); | ||
144 | + Toast.makeText(getContext(), error.getMessage(), Toast.LENGTH_LONG).show(); | ||
145 | + } | ||
69 | } | 146 | } |
147 | + ); | ||
148 | + jsonObjectRequest.setTag(CreateEvent.class); | ||
149 | + VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest); | ||
70 | } | 150 | } |
71 | - ); | ||
72 | - jsonObjectRequest.setTag(CreateEvent.class); | ||
73 | - VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest); | ||
74 | - } | ||
75 | - }) | ||
76 | - .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { | ||
77 | - public void onClick(DialogInterface dialog, int id) { | ||
78 | - VolleyUtils.getInstance(getContext()).getRequestQueue().cancelAll(CreateEvent.class); | ||
79 | } | 151 | } |
80 | - }).create(); | 152 | + }); |
153 | + } | ||
154 | + }); | ||
81 | dialog.setCanceledOnTouchOutside(false); | 155 | dialog.setCanceledOnTouchOutside(false); |
82 | return dialog; | 156 | return dialog; |
83 | } | 157 | } |
@@ -89,4 +163,23 @@ public class CreateEvent extends DialogFragment { | @@ -89,4 +163,23 @@ public class CreateEvent extends DialogFragment { | ||
89 | super.onStop(); | 163 | super.onStop(); |
90 | } | 164 | } |
91 | 165 | ||
166 | + DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() { | ||
167 | + | ||
168 | + @Override | ||
169 | + public void onDateSet(DatePicker view, int year, int monthOfYear, | ||
170 | + int dayOfMonth) { | ||
171 | + myCalendar.set(Calendar.YEAR, year); | ||
172 | + myCalendar.set(Calendar.MONTH, monthOfYear); | ||
173 | + myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth); | ||
174 | + updateLabel(); | ||
175 | + } | ||
176 | + }; | ||
177 | + | ||
178 | + private void updateLabel() { | ||
179 | + String myFormat = "yyyy-MM-dd"; //In which you need put here | ||
180 | + SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.FRANCE); | ||
181 | + arraySpinnerDate[0] = sdf.format(myCalendar.getTime()); | ||
182 | + adapterDate.notifyDataSetChanged(); | ||
183 | + } | ||
184 | + | ||
92 | } | 185 | } |
app/src/main/java/net/plil/clubinfo/etunicorn/app/Event/DeleteEvent.java
@@ -7,6 +7,7 @@ import android.support.v4.app.DialogFragment; | @@ -7,6 +7,7 @@ import android.support.v4.app.DialogFragment; | ||
7 | import android.support.v7.app.AlertDialog; | 7 | import android.support.v7.app.AlertDialog; |
8 | import android.view.LayoutInflater; | 8 | import android.view.LayoutInflater; |
9 | import android.view.View; | 9 | import android.view.View; |
10 | +import android.widget.Button; | ||
10 | import android.widget.ProgressBar; | 11 | import android.widget.ProgressBar; |
11 | import android.widget.Toast; | 12 | import android.widget.Toast; |
12 | 13 | ||
@@ -51,16 +52,27 @@ public class DeleteEvent extends DialogFragment { | @@ -51,16 +52,27 @@ public class DeleteEvent extends DialogFragment { | ||
51 | LayoutInflater inflater = getActivity().getLayoutInflater(); | 52 | LayoutInflater inflater = getActivity().getLayoutInflater(); |
52 | View view = inflater.inflate(R.layout.fragment_delete_event, null); | 53 | View view = inflater.inflate(R.layout.fragment_delete_event, null); |
53 | 54 | ||
54 | - mProgressBar = (ProgressBar) view.findViewById(R.id.delete_consommation_progress_bar); | ||
55 | - final Event event = (Event) getArguments().getSerializable("event"); | 55 | + mProgressBar = (ProgressBar) view.findViewById(R.id.delete_event_progress_bar); |
56 | + final Event event = (Event) getArguments().getSerializable("evenement"); | ||
56 | 57 | ||
57 | 58 | ||
58 | AlertDialog dialog = new AlertDialog.Builder(getActivity()) | 59 | AlertDialog dialog = new AlertDialog.Builder(getActivity()) |
59 | .setTitle(R.string.verif_delete_event) | 60 | .setTitle(R.string.verif_delete_event) |
60 | .setView(view) | 61 | .setView(view) |
61 | - .setPositiveButton(R.string.delete, new DialogInterface.OnClickListener() { | 62 | + .setPositiveButton(R.string.delete, null) |
63 | + .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { | ||
64 | + public void onClick(DialogInterface dialog, int id) { | ||
65 | + VolleyUtils.getInstance(getContext()).getRequestQueue().cancelAll(DeleteEvent.class); | ||
66 | + } | ||
67 | + }).create(); | ||
68 | + dialog.setCanceledOnTouchOutside(false); | ||
69 | + dialog.setOnShowListener(new DialogInterface.OnShowListener() { | ||
70 | + @Override | ||
71 | + public void onShow(DialogInterface dialog) { | ||
72 | + Button button = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE); | ||
73 | + button.setOnClickListener(new View.OnClickListener() { | ||
62 | @Override | 74 | @Override |
63 | - public void onClick(DialogInterface dialog, int which) { | 75 | + public void onClick(View v) { |
64 | mProgressBar.setVisibility(View.VISIBLE); | 76 | mProgressBar.setVisibility(View.VISIBLE); |
65 | 77 | ||
66 | JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.DELETE, VolleyUtils.baseUri + "/evenement/" + event.getIdEvent(), null, new Response.Listener<JSONObject>() { | 78 | JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.DELETE, VolleyUtils.baseUri + "/evenement/" + event.getIdEvent(), null, new Response.Listener<JSONObject>() { |
@@ -75,20 +87,14 @@ public class DeleteEvent extends DialogFragment { | @@ -75,20 +87,14 @@ public class DeleteEvent extends DialogFragment { | ||
75 | public void onErrorResponse(VolleyError error) { | 87 | public void onErrorResponse(VolleyError error) { |
76 | mProgressBar.setVisibility(View.GONE); | 88 | mProgressBar.setVisibility(View.GONE); |
77 | Toast.makeText(getContext(), R.string.delete_refused, Toast.LENGTH_LONG).show(); | 89 | Toast.makeText(getContext(), R.string.delete_refused, Toast.LENGTH_LONG).show(); |
78 | - dismiss(); | ||
79 | } | 90 | } |
80 | } | 91 | } |
81 | ); | 92 | ); |
82 | jsonObjectRequest.setTag(DeleteEvent.class); | 93 | jsonObjectRequest.setTag(DeleteEvent.class); |
83 | VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest); | 94 | VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest); |
84 | } | 95 | } |
85 | - }) | ||
86 | - .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { | ||
87 | - public void onClick(DialogInterface dialog, int id) { | ||
88 | - VolleyUtils.getInstance(getContext()).getRequestQueue().cancelAll(DeleteEvent.class); | ||
89 | - } | ||
90 | - }).create(); | ||
91 | - dialog.setCanceledOnTouchOutside(false); | 96 | + }); |
97 | + }}); | ||
92 | return dialog; | 98 | return dialog; |
93 | } | 99 | } |
94 | 100 |
app/src/main/java/net/plil/clubinfo/etunicorn/app/Event/ModifyEvent.java
1 | package net.plil.clubinfo.etunicorn.app.event; | 1 | package net.plil.clubinfo.etunicorn.app.event; |
2 | 2 | ||
3 | +import android.app.DatePickerDialog; | ||
3 | import android.app.Dialog; | 4 | import android.app.Dialog; |
4 | import android.content.DialogInterface; | 5 | import android.content.DialogInterface; |
5 | import android.os.Bundle; | 6 | import android.os.Bundle; |
7 | +import android.support.design.widget.TextInputLayout; | ||
6 | import android.support.v4.app.DialogFragment; | 8 | import android.support.v4.app.DialogFragment; |
7 | import android.support.v7.app.AlertDialog; | 9 | import android.support.v7.app.AlertDialog; |
8 | import android.view.LayoutInflater; | 10 | import android.view.LayoutInflater; |
11 | +import android.view.MotionEvent; | ||
9 | import android.view.View; | 12 | import android.view.View; |
13 | +import android.widget.ArrayAdapter; | ||
14 | +import android.widget.Button; | ||
15 | +import android.widget.DatePicker; | ||
10 | import android.widget.EditText; | 16 | import android.widget.EditText; |
11 | import android.widget.ProgressBar; | 17 | import android.widget.ProgressBar; |
18 | +import android.widget.Spinner; | ||
12 | import android.widget.Toast; | 19 | import android.widget.Toast; |
13 | 20 | ||
14 | import com.android.volley.Request; | 21 | import com.android.volley.Request; |
@@ -23,16 +30,25 @@ import net.plil.clubinfo.etunicorn.utils.VolleyUtils; | @@ -23,16 +30,25 @@ import net.plil.clubinfo.etunicorn.utils.VolleyUtils; | ||
23 | import org.json.JSONException; | 30 | import org.json.JSONException; |
24 | import org.json.JSONObject; | 31 | import org.json.JSONObject; |
25 | 32 | ||
33 | +import java.text.SimpleDateFormat; | ||
34 | +import java.util.Calendar; | ||
26 | import java.util.Locale; | 35 | import java.util.Locale; |
27 | 36 | ||
28 | 37 | ||
29 | public class ModifyEvent extends DialogFragment { | 38 | public class ModifyEvent extends DialogFragment { |
30 | 39 | ||
40 | + Calendar myCalendar = Calendar.getInstance(); | ||
41 | + private String[] arraySpinnerDate; | ||
42 | + private ArrayAdapter<String> adapterDate; | ||
43 | + | ||
31 | EditText mNom; | 44 | EditText mNom; |
32 | EditText mPrice; | 45 | EditText mPrice; |
33 | - EditText mDate; | 46 | + Spinner mDate; |
34 | ProgressBar mProgressBar; | 47 | ProgressBar mProgressBar; |
35 | 48 | ||
49 | + TextInputLayout mNomInput; | ||
50 | + TextInputLayout mPriceInput; | ||
51 | + | ||
36 | public static ModifyEvent newInstance(Event event) { | 52 | public static ModifyEvent newInstance(Event event) { |
37 | ModifyEvent f = new ModifyEvent(); | 53 | ModifyEvent f = new ModifyEvent(); |
38 | 54 | ||
@@ -52,30 +68,64 @@ public class ModifyEvent extends DialogFragment { | @@ -52,30 +68,64 @@ public class ModifyEvent extends DialogFragment { | ||
52 | View view = inflater.inflate(R.layout.fragment_modify_event, null); | 68 | View view = inflater.inflate(R.layout.fragment_modify_event, null); |
53 | mNom = (EditText) view.findViewById(R.id.modify_event_name); | 69 | mNom = (EditText) view.findViewById(R.id.modify_event_name); |
54 | mPrice = (EditText) view.findViewById(R.id.modify_event_price); | 70 | mPrice = (EditText) view.findViewById(R.id.modify_event_price); |
55 | - mDate = (EditText) view.findViewById(R.id.modify_event_date); | 71 | + mDate = (Spinner) view.findViewById(R.id.modify_event_date); |
56 | mProgressBar = (ProgressBar) view.findViewById(R.id.modify_event_progress_bar); | 72 | mProgressBar = (ProgressBar) view.findViewById(R.id.modify_event_progress_bar); |
73 | + mNomInput = (TextInputLayout) view.findViewById(R.id.modify_event_name_input); | ||
74 | + mPriceInput = (TextInputLayout) view.findViewById(R.id.modify_event_price_input); | ||
75 | + | ||
57 | 76 | ||
58 | final Event event = (Event) getArguments().getSerializable("event"); | 77 | final Event event = (Event) getArguments().getSerializable("event"); |
59 | 78 | ||
79 | + String myFormat = "yyyy-MM-dd"; //In which you need put here | ||
80 | + SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.FRANCE); | ||
81 | + arraySpinnerDate = new String[] { | ||
82 | + sdf.format(event.getDate().getTime()) | ||
83 | + }; | ||
84 | + adapterDate = new ArrayAdapter<>(getActivity(), | ||
85 | + R.layout.simple_item_layout, arraySpinnerDate); | ||
86 | + mDate.setAdapter(adapterDate); | ||
87 | + | ||
60 | mNom.setText(event.getNomEvent()); | 88 | mNom.setText(event.getNomEvent()); |
61 | - mPrice.setText(String.format(Locale.FRANCE, "%.2f", event.getPrice())); | ||
62 | - mDate.setText(event.getDate().toString()); | 89 | + mPrice.setText(String.format(Locale.US, "%.2f", event.getPrice())); |
63 | 90 | ||
64 | AlertDialog dialog = new AlertDialog.Builder(getActivity()) | 91 | AlertDialog dialog = new AlertDialog.Builder(getActivity()) |
65 | .setTitle(R.string.modify) | 92 | .setTitle(R.string.modify) |
66 | .setView(view) | 93 | .setView(view) |
67 | - .setPositiveButton(R.string.modify, new DialogInterface.OnClickListener() { | 94 | + .setPositiveButton(R.string.modify, null) |
95 | + .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { | ||
68 | public void onClick(DialogInterface dialog, int id) { | 96 | public void onClick(DialogInterface dialog, int id) { |
69 | - | 97 | + VolleyUtils.getInstance(getContext()).getRequestQueue().cancelAll(ModifyEvent.class); |
98 | + } | ||
99 | + }).create(); | ||
100 | + // Create the AlertDialog object and return it | ||
101 | + mDate.setOnTouchListener(new View.OnTouchListener() { | ||
102 | + @Override | ||
103 | + public boolean onTouch(View v, MotionEvent event) { | ||
104 | + if(event.getAction() == MotionEvent.ACTION_UP) { | ||
105 | + new DatePickerDialog(getContext(), date, myCalendar | ||
106 | + .get(Calendar.YEAR), myCalendar.get(Calendar.MONTH), | ||
107 | + myCalendar.get(Calendar.DAY_OF_MONTH)).show(); | ||
108 | + } | ||
109 | + return true; | ||
110 | + } | ||
111 | + }); | ||
112 | + dialog.setCanceledOnTouchOutside(false); | ||
113 | + dialog.setOnShowListener(new DialogInterface.OnShowListener() { | ||
114 | + @Override | ||
115 | + public void onShow(DialogInterface dialog) { | ||
116 | + Button button = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE); | ||
117 | + button.setOnClickListener(new View.OnClickListener() { | ||
118 | + @Override | ||
119 | + public void onClick(View v) { | ||
70 | mProgressBar.setVisibility(View.VISIBLE); | 120 | mProgressBar.setVisibility(View.VISIBLE); |
71 | - mPrice.setVisibility(View.GONE); | ||
72 | - mNom.setVisibility(View.GONE); | 121 | + mPriceInput.setVisibility(View.GONE); |
122 | + mNomInput.setVisibility(View.GONE); | ||
73 | mDate.setVisibility(View.GONE); | 123 | mDate.setVisibility(View.GONE); |
74 | JSONObject jsonObject = new JSONObject(); | 124 | JSONObject jsonObject = new JSONObject(); |
75 | try { | 125 | try { |
76 | jsonObject.put("nomEvenement", mNom.getText().toString()); | 126 | jsonObject.put("nomEvenement", mNom.getText().toString()); |
77 | jsonObject.put("prix", Double.parseDouble(mPrice.getText().toString())); | 127 | jsonObject.put("prix", Double.parseDouble(mPrice.getText().toString())); |
78 | - jsonObject.put("date", mDate.getText().toString()); | 128 | + jsonObject.put("date", mDate.getSelectedItem()); |
79 | } catch (JSONException e){ | 129 | } catch (JSONException e){ |
80 | e.printStackTrace(); | 130 | e.printStackTrace(); |
81 | } | 131 | } |
@@ -90,6 +140,9 @@ public class ModifyEvent extends DialogFragment { | @@ -90,6 +140,9 @@ public class ModifyEvent extends DialogFragment { | ||
90 | @Override | 140 | @Override |
91 | public void onErrorResponse(VolleyError error) { | 141 | public void onErrorResponse(VolleyError error) { |
92 | mProgressBar.setVisibility(View.GONE); | 142 | mProgressBar.setVisibility(View.GONE); |
143 | + mPriceInput.setVisibility(View.VISIBLE); | ||
144 | + mNomInput.setVisibility(View.VISIBLE); | ||
145 | + mDate.setVisibility(View.VISIBLE); | ||
93 | Toast.makeText(getContext(), R.string.modify_refused, Toast.LENGTH_LONG).show(); | 146 | Toast.makeText(getContext(), R.string.modify_refused, Toast.LENGTH_LONG).show(); |
94 | 147 | ||
95 | } | 148 | } |
@@ -98,14 +151,10 @@ public class ModifyEvent extends DialogFragment { | @@ -98,14 +151,10 @@ public class ModifyEvent extends DialogFragment { | ||
98 | jsonObjectRequest.setTag(ModifyEvent.class); | 151 | jsonObjectRequest.setTag(ModifyEvent.class); |
99 | VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest); | 152 | VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest); |
100 | } | 153 | } |
101 | - }) | ||
102 | - .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { | ||
103 | - public void onClick(DialogInterface dialog, int id) { | ||
104 | - VolleyUtils.getInstance(getContext()).getRequestQueue().cancelAll(ModifyEvent.class); | ||
105 | - } | ||
106 | - }).create(); | ||
107 | - // Create the AlertDialog object and return it | ||
108 | - dialog.setCanceledOnTouchOutside(false); | 154 | + }); |
155 | + | ||
156 | + } | ||
157 | + }); | ||
109 | return dialog; | 158 | return dialog; |
110 | } | 159 | } |
111 | 160 | ||
@@ -116,5 +165,23 @@ public class ModifyEvent extends DialogFragment { | @@ -116,5 +165,23 @@ public class ModifyEvent extends DialogFragment { | ||
116 | super.onStop(); | 165 | super.onStop(); |
117 | } | 166 | } |
118 | 167 | ||
168 | + DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() { | ||
169 | + | ||
170 | + @Override | ||
171 | + public void onDateSet(DatePicker view, int year, int monthOfYear, | ||
172 | + int dayOfMonth) { | ||
173 | + myCalendar.set(Calendar.YEAR, year); | ||
174 | + myCalendar.set(Calendar.MONTH, monthOfYear); | ||
175 | + myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth); | ||
176 | + updateLabel(); | ||
177 | + } | ||
178 | + }; | ||
179 | + | ||
180 | + private void updateLabel() { | ||
181 | + String myFormat = "yyyy-MM-dd"; //In which you need put here | ||
182 | + SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.FRANCE); | ||
183 | + arraySpinnerDate[0] = sdf.format(myCalendar.getTime()); | ||
184 | + adapterDate.notifyDataSetChanged(); | ||
185 | + } | ||
119 | 186 | ||
120 | -} | 187 | -} |
188 | +} | ||
121 | \ No newline at end of file | 189 | \ No newline at end of file |
app/src/main/java/net/plil/clubinfo/etunicorn/data/Event.java
1 | package net.plil.clubinfo.etunicorn.data; | 1 | package net.plil.clubinfo.etunicorn.data; |
2 | 2 | ||
3 | import java.io.Serializable; | 3 | import java.io.Serializable; |
4 | -import java.sql.Date; | 4 | +import java.util.Date; |
5 | 5 | ||
6 | /** | 6 | /** |
7 | * Created by badetitou on 04/02/2017. | 7 | * Created by badetitou on 04/02/2017. |
app/src/main/res/layout/fragment_create_event.xml
@@ -7,21 +7,32 @@ | @@ -7,21 +7,32 @@ | ||
7 | android:layout_height="match_parent" | 7 | android:layout_height="match_parent" |
8 | > | 8 | > |
9 | 9 | ||
10 | - <EditText | 10 | + <android.support.design.widget.TextInputLayout |
11 | android:layout_width="match_parent" | 11 | android:layout_width="match_parent" |
12 | android:layout_height="wrap_content" | 12 | android:layout_height="wrap_content" |
13 | - android:id="@+id/create_event_name" | ||
14 | - android:hint="@string/create_event_name"/> | 13 | + android:hint="@string/create_event_name" |
14 | + android:id="@+id/create_event_name_input"> | ||
15 | + <android.support.design.widget.TextInputEditText | ||
16 | + android:layout_width="match_parent" | ||
17 | + android:layout_height="wrap_content" | ||
18 | + android:id="@+id/create_event_name" | ||
19 | + /> | ||
20 | + </android.support.design.widget.TextInputLayout> | ||
15 | 21 | ||
16 | - <EditText | 22 | + <android.support.design.widget.TextInputLayout |
17 | android:layout_width="match_parent" | 23 | android:layout_width="match_parent" |
18 | android:layout_height="wrap_content" | 24 | android:layout_height="wrap_content" |
19 | android:hint="@string/create_consumable_price" | 25 | android:hint="@string/create_consumable_price" |
20 | - android:id="@+id/create_event_price" | ||
21 | - android:inputType="numberSigned|numberDecimal" | ||
22 | - android:maxLines="1" /> | 26 | + android:id="@+id/create_event_price_input"> |
27 | + <android.support.design.widget.TextInputEditText | ||
28 | + android:layout_width="match_parent" | ||
29 | + android:layout_height="wrap_content" | ||
30 | + android:id="@+id/create_event_price" | ||
31 | + android:inputType="numberSigned|numberDecimal" | ||
32 | + android:maxLines="1" /> | ||
33 | + </android.support.design.widget.TextInputLayout> | ||
23 | 34 | ||
24 | - <EditText | 35 | + <Spinner |
25 | android:layout_width="match_parent" | 36 | android:layout_width="match_parent" |
26 | android:layout_height="wrap_content" | 37 | android:layout_height="wrap_content" |
27 | android:hint="@string/create_event_date" | 38 | android:hint="@string/create_event_date" |
app/src/main/res/layout/fragment_modify_event.xml
@@ -5,18 +5,34 @@ | @@ -5,18 +5,34 @@ | ||
5 | tools:context="net.plil.clubinfo.etunicorn.app.event.ModifyEvent" | 5 | tools:context="net.plil.clubinfo.etunicorn.app.event.ModifyEvent" |
6 | android:orientation="vertical"> | 6 | android:orientation="vertical"> |
7 | 7 | ||
8 | - <EditText | 8 | + <android.support.design.widget.TextInputLayout |
9 | android:layout_width="match_parent" | 9 | android:layout_width="match_parent" |
10 | android:layout_height="wrap_content" | 10 | android:layout_height="wrap_content" |
11 | - android:id="@+id/modify_event_name" /> | 11 | + android:id="@+id/modify_event_name_input"> |
12 | 12 | ||
13 | - <EditText | 13 | + <android.support.design.widget.TextInputEditText |
14 | + android:layout_width="match_parent" | ||
15 | + android:layout_height="wrap_content" | ||
16 | + android:id="@+id/modify_event_name" | ||
17 | + android:hint="@string/modify_event_hint_name"/> | ||
18 | + | ||
19 | + </android.support.design.widget.TextInputLayout> | ||
20 | + | ||
21 | + <android.support.design.widget.TextInputLayout | ||
14 | android:layout_width="match_parent" | 22 | android:layout_width="match_parent" |
15 | android:layout_height="wrap_content" | 23 | android:layout_height="wrap_content" |
16 | - android:id="@+id/modify_event_price"/> | 24 | + android:id="@+id/modify_event_price_input"> |
25 | + | ||
26 | + <android.support.design.widget.TextInputEditText | ||
27 | + android:layout_width="match_parent" | ||
28 | + android:layout_height="wrap_content" | ||
29 | + android:id="@+id/modify_event_price" | ||
30 | + android:hint="@string/modify_event_hint_price"/> | ||
31 | + | ||
32 | + </android.support.design.widget.TextInputLayout> | ||
17 | 33 | ||
18 | 34 | ||
19 | - <EditText | 35 | + <Spinner |
20 | android:layout_width="match_parent" | 36 | android:layout_width="match_parent" |
21 | android:layout_height="wrap_content" | 37 | android:layout_height="wrap_content" |
22 | android:id="@+id/modify_event_date" | 38 | android:id="@+id/modify_event_date" |
app/src/main/res/values-fr/strings.xml
@@ -43,4 +43,14 @@ | @@ -43,4 +43,14 @@ | ||
43 | <string name="error_enter_debit">Veuillez entrer une valeur avant d\'utiliser la carte NFC</string> | 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> | 44 | <string name="error_create_consomation_input_nom">Entrer le nom</string> |
45 | <string name="error_create_consomation_input_price">Entrer le prix</string> | 45 | <string name="error_create_consomation_input_price">Entrer le prix</string> |
46 | + <string name="create_event_date_input">Date</string> | ||
47 | + <string name="error_create_event_date">Entrer la date</string> | ||
48 | + <string name="error_create_event_input_nom">Entrer le nom</string> | ||
49 | + <string name="error_create_event_input_price">Entrer le prix</string> | ||
50 | + <string name="error_modify_consommation_input_nom">Entrer le nouveau nom</string> | ||
51 | + <string name="error_modify_consommation_input_price">Entrer le nouveau prix</string> | ||
52 | + <string name="modify_consomation_hint_name">Nom</string> | ||
53 | + <string name="modify_consomation_hint_price">Prix</string> | ||
54 | + <string name="modify_event_hint_name">Nom</string> | ||
55 | + <string name="modify_event_hint_price">Prix</string> | ||
46 | </resources> | 56 | </resources> |
47 | \ No newline at end of file | 57 | \ No newline at end of file |
app/src/main/res/values/strings.xml
@@ -48,4 +48,10 @@ | @@ -48,4 +48,10 @@ | ||
48 | <string name="error_modify_consommation_input_nom">Enter the new name</string> | 48 | <string name="error_modify_consommation_input_nom">Enter the new name</string> |
49 | <string name="modify_consomation_hint_name">Name</string> | 49 | <string name="modify_consomation_hint_name">Name</string> |
50 | <string name="modify_consomation_hint_price">Price</string> | 50 | <string name="modify_consomation_hint_price">Price</string> |
51 | + <string name="create_event_date_input">Date</string> | ||
52 | + <string name="error_create_event_input_price">Enter the price</string> | ||
53 | + <string name="error_create_event_input_nom">Enter the name</string> | ||
54 | + <string name="error_create_event_date">Enter the date</string> | ||
55 | + <string name="modify_event_hint_name">Name</string> | ||
56 | + <string name="modify_event_hint_price">Price</string> | ||
51 | </resources> | 57 | </resources> |