Commit 68348eda599162200fe4d97c87f207a4f5b94821

Authored by badetitou
1 parent 0ecfc67f

Adding modify and Translate

app/src/main/java/net/plil/clubinfo/etunicorn/app/consommation/ConsommationRecyclerViewAdapter.java
... ... @@ -75,11 +75,12 @@ public class ConsommationRecyclerViewAdapter extends RecyclerView.Adapter<Consom
75 75 public boolean onMenuItemClick(MenuItem item) {
76 76 switch (item.getItemId()) {
77 77 case R.id.delete:
78   - DeleteConsommation paiementConsommation = DeleteConsommation.newInstance(holder.mItem);
79   - paiementConsommation.show(((AppCompatActivity) context).getSupportFragmentManager(), "deleteConsommation");
  78 + DeleteConsommation deleteConsommation = DeleteConsommation.newInstance(holder.mItem);
  79 + deleteConsommation.show(((AppCompatActivity) context).getSupportFragmentManager(), "deleteConsommation");
80 80 break;
81 81 case R.id.modify:
82   - //handle menu2 click
  82 + ModifyConsommation modifyConsommation = ModifyConsommation.newInstance(holder.mItem);
  83 + modifyConsommation.show(((AppCompatActivity) context).getSupportFragmentManager(), "modifyConsommation");
83 84 break;
84 85 }
85 86 return false;
... ...
app/src/main/java/net/plil/clubinfo/etunicorn/app/consommation/ModifyConsommation.java 0 → 100644
... ... @@ -0,0 +1,103 @@
  1 +package net.plil.clubinfo.etunicorn.app.consommation;
  2 +
  3 +import android.app.Dialog;
  4 +import android.content.DialogInterface;
  5 +import android.os.Bundle;
  6 +import android.support.v4.app.DialogFragment;
  7 +import android.support.v7.app.AlertDialog;
  8 +import android.view.LayoutInflater;
  9 +import android.view.View;
  10 +import android.widget.EditText;
  11 +import android.widget.ProgressBar;
  12 +import android.widget.Toast;
  13 +
  14 +import com.android.volley.Request;
  15 +import com.android.volley.Response;
  16 +import com.android.volley.VolleyError;
  17 +import com.android.volley.toolbox.JsonObjectRequest;
  18 +
  19 +import net.plil.clubinfo.etunicorn.R;
  20 +import net.plil.clubinfo.etunicorn.data.Consommation;
  21 +import net.plil.clubinfo.etunicorn.utils.VolleyUtils;
  22 +
  23 +import org.json.JSONException;
  24 +import org.json.JSONObject;
  25 +
  26 +
  27 +public class ModifyConsommation extends DialogFragment {
  28 +
  29 + EditText mNomConsomation;
  30 + EditText mPrice;
  31 + ProgressBar mProgressBar;
  32 +
  33 + public static ModifyConsommation newInstance(Consommation consommation) {
  34 + ModifyConsommation f = new ModifyConsommation();
  35 +
  36 + // Supply num input as an argument.
  37 + Bundle args = new Bundle();
  38 + args.putSerializable("consommation", consommation);
  39 + f.setArguments(args);
  40 +
  41 + return f;
  42 + }
  43 +
  44 +
  45 + @Override
  46 + public Dialog onCreateDialog(Bundle savedInstanceState) {
  47 + // Use the Builder class for convenient dialog construction
  48 + LayoutInflater inflater = getActivity().getLayoutInflater();
  49 + View view = inflater.inflate(R.layout.fragment_create_consomation, null);
  50 + mNomConsomation = (EditText) view.findViewById(R.id.create_consomation_name);
  51 + mPrice = (EditText) view.findViewById(R.id.create_consomation_price);
  52 + mProgressBar = (ProgressBar) view.findViewById(R.id.create_consomation_progress_bar);
  53 +
  54 + final Consommation consommation = (Consommation) getArguments().getSerializable("consommation");
  55 +
  56 + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
  57 + builder
  58 + .setTitle(R.string.modify)
  59 + .setView(view)
  60 + .setPositiveButton(R.string.modify, new DialogInterface.OnClickListener() {
  61 + public void onClick(DialogInterface dialog, int id) {
  62 +
  63 + mProgressBar.setVisibility(View.VISIBLE);
  64 + mPrice.setVisibility(View.GONE);
  65 + mNomConsomation.setVisibility(View.GONE);
  66 + JSONObject jsonObject = new JSONObject();
  67 + try {
  68 + jsonObject.put("nomConsomation", mNomConsomation.getText().toString());
  69 + jsonObject.put("prix", Double.parseDouble(mPrice.getText().toString()));
  70 + } catch (JSONException e){
  71 + e.printStackTrace();
  72 + }
  73 + JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, VolleyUtils.baseUri + "/consomation/" + consommation.getIdConsomation() ,jsonObject , new Response.Listener<JSONObject>() {
  74 + @Override
  75 + public void onResponse(JSONObject response) {
  76 + mProgressBar.setVisibility(View.GONE);
  77 + Toast.makeText(getContext(), R.string.modify_done, Toast.LENGTH_LONG).show();
  78 +
  79 + }
  80 + }, new Response.ErrorListener() {
  81 + @Override
  82 + public void onErrorResponse(VolleyError error) {
  83 + mProgressBar.setVisibility(View.GONE);
  84 + Toast.makeText(getContext(), R.string.modify_refused, Toast.LENGTH_LONG).show();
  85 +
  86 + }
  87 + }
  88 + );
  89 +
  90 + VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest);
  91 + }
  92 + })
  93 + .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
  94 + public void onClick(DialogInterface dialog, int id) {
  95 + // User cancelled the dialog
  96 + }
  97 + });
  98 + // Create the AlertDialog object and return it
  99 + return builder.create();
  100 + }
  101 +
  102 +
  103 +}
... ...
app/src/main/res/layout/fragment_modify_consommation.xml 0 → 100644
... ... @@ -0,0 +1,26 @@
  1 +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2 + xmlns:tools="http://schemas.android.com/tools"
  3 + android:layout_width="match_parent"
  4 + android:layout_height="match_parent"
  5 + tools:context="net.plil.clubinfo.etunicorn.app.consommation.ModifyConsommation"
  6 + android:orientation="vertical">
  7 +
  8 + <EditText
  9 + android:layout_width="wrap_content"
  10 + android:layout_height="wrap_content"
  11 + android:id="@+id/modify_consommation_name" />
  12 +
  13 + <EditText
  14 + android:layout_width="wrap_content"
  15 + android:layout_height="wrap_content"
  16 + android:id="@+id/modify_consommation_price"/>
  17 +
  18 + <ProgressBar
  19 + style="?android:attr/progressBarStyle"
  20 + android:layout_width="match_parent"
  21 + android:layout_height="wrap_content"
  22 + android:id="@+id/modify_consommation_progress_bar"
  23 + android:layout_gravity="center"/>
  24 +
  25 +
  26 +</LinearLayout>
... ...
app/src/main/res/values-fr/strings.xml
... ... @@ -20,4 +20,11 @@
20 20 <string name="payment_done">Paiement refusé</string>
21 21 <string name="payment_consumable_alert_no_selection">Selectionné un produit avant de payer</string>
22 22 <string name="action_delete">Supprimer</string>
  23 + <string name="delete">Supprimer</string>
  24 + <string name="delete_done">Suppression effectué</string>
  25 + <string name="delete_refused">Suppression refusé</string>
  26 + <string name="modify">Modifier</string>
  27 + <string name="modify_done">Modification effectué</string>
  28 + <string name="modify_refused">Modification refusé</string>
  29 + <string name="verif_delete_consomation">Etes-vous sûr ?</string>
23 30 </resources>
24 31 \ No newline at end of file
... ...
app/src/main/res/values/strings.xml
... ... @@ -9,7 +9,6 @@
9 9 <string name="error_field_required">This field is required</string>
10 10 <string name="prompt_username">Username</string>
11 11 <string name="action_settings">Settings</string>
12   -
13 12 <string name="enter_money">Enter value</string>
14 13 <string name="valid">OK</string>
15 14 <string name="cancel">Cancel</string>
... ... @@ -22,12 +21,11 @@
22 21 <string name="payment_done">Payment done</string>
23 22 <string name="payment_refused">Payment refused</string>
24 23 <string name="action_delete">Delete</string>
25   - <string name="modify">Modifier</string>
  24 + <string name="modify">Modify</string>
26 25 <string name="delete">Delete</string>
27   -
28   - <!-- TODO: Remove or change this placeholder text -->
29   - <string name="hello_blank_fragment">Hello blank fragment</string>
30 26 <string name="verif_delete_consomation">Are you sure ?</string>
31 27 <string name="delete_done">Delete done</string>
32 28 <string name="delete_refused">Delete refused</string>
  29 + <string name="modify_done">Modify done</string>
  30 + <string name="modify_refused">Modify refused</string>
33 31 </resources>
... ...