From be13b83840bf6760282709be2fd78df0c4dbcb8c Mon Sep 17 00:00:00 2001 From: BenoƮt Verhaeghe Date: Sat, 4 Feb 2017 19:10:30 +0100 Subject: [PATCH] Create personne menu --- app/src/main/java/net/plil/clubinfo/etunicorn/app/personne/DeletePersonne.java | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ app/src/main/java/net/plil/clubinfo/etunicorn/app/personne/ModifyPersonne.java | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ app/src/main/java/net/plil/clubinfo/etunicorn/data/Personne.java | 26 +++++++++++++++++++------- app/src/main/res/layout/fragment_delete_personne.xml | 17 +++++++++++++++++ app/src/main/res/layout/fragment_modify_personne.xml | 35 +++++++++++++++++++++++++++++++++++ app/src/main/res/layout/fragment_personne.xml | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ app/src/main/res/layout/fragment_personne_list.xml | 36 ++++++++++++++++++++++++++++++++++++ 7 files changed, 373 insertions(+), 7 deletions(-) create mode 100644 app/src/main/java/net/plil/clubinfo/etunicorn/app/personne/DeletePersonne.java create mode 100644 app/src/main/java/net/plil/clubinfo/etunicorn/app/personne/ModifyPersonne.java create mode 100644 app/src/main/res/layout/fragment_delete_personne.xml create mode 100644 app/src/main/res/layout/fragment_modify_personne.xml create mode 100644 app/src/main/res/layout/fragment_personne.xml create mode 100644 app/src/main/res/layout/fragment_personne_list.xml diff --git a/app/src/main/java/net/plil/clubinfo/etunicorn/app/personne/DeletePersonne.java b/app/src/main/java/net/plil/clubinfo/etunicorn/app/personne/DeletePersonne.java new file mode 100644 index 0000000..c1a97d8 --- /dev/null +++ b/app/src/main/java/net/plil/clubinfo/etunicorn/app/personne/DeletePersonne.java @@ -0,0 +1,96 @@ +package net.plil.clubinfo.etunicorn.app.personne; + +import android.app.Dialog; +import android.content.DialogInterface; +import android.os.Bundle; +import android.support.v4.app.DialogFragment; +import android.support.v7.app.AlertDialog; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.ProgressBar; +import android.widget.Toast; + +import com.android.volley.Request; +import com.android.volley.Response; +import com.android.volley.VolleyError; +import com.android.volley.toolbox.JsonObjectRequest; + +import net.plil.clubinfo.etunicorn.R; +import net.plil.clubinfo.etunicorn.data.Event; +import net.plil.clubinfo.etunicorn.data.Personne; +import net.plil.clubinfo.etunicorn.utils.VolleyUtils; + +import org.json.JSONObject; + + +public class DeletePersonne extends DialogFragment { + + ProgressBar mProgressBar; + + public DeletePersonne(){} + + /** + * Create a new instance of MyDialogFragment, providing "num" + * as an argument. + */ + public static DeletePersonne newInstance(Personne personne) { + DeletePersonne f = new DeletePersonne(); + + // Supply num input as an argument. + Bundle args = new Bundle(); + args.putSerializable("personne", personne); + f.setArguments(args); + + return f; + } + + + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + // Use the Builder class for convenient dialog construction + LayoutInflater inflater = getActivity().getLayoutInflater(); + View view = inflater.inflate(R.layout.fragment_delete_personne, null); + + mProgressBar = (ProgressBar) view.findViewById(R.id.delete_consommation_progress_bar); + final Personne personne = (Personne) getArguments().getSerializable("personne"); + + + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + builder + .setTitle(R.string.verif_delete_personne) + .setView(view) + .setPositiveButton(R.string.delete, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + mProgressBar.setVisibility(View.VISIBLE); + + JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.DELETE, VolleyUtils.baseUri + "/personne/" + personne.getIdPersonne(), null, new Response.Listener() { + @Override + public void onResponse(JSONObject response) { + mProgressBar.setVisibility(View.GONE); + Toast.makeText(getContext(), R.string.delete_done, Toast.LENGTH_LONG).show(); + dismiss(); + } + }, new Response.ErrorListener() { + @Override + public void onErrorResponse(VolleyError error) { + mProgressBar.setVisibility(View.GONE); + Toast.makeText(getContext(), R.string.delete_refused, Toast.LENGTH_LONG).show(); + dismiss(); + } + } + ); + + VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest); + } + }) + .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + + } + }); + return builder.create(); + } + + +} diff --git a/app/src/main/java/net/plil/clubinfo/etunicorn/app/personne/ModifyPersonne.java b/app/src/main/java/net/plil/clubinfo/etunicorn/app/personne/ModifyPersonne.java new file mode 100644 index 0000000..922e429 --- /dev/null +++ b/app/src/main/java/net/plil/clubinfo/etunicorn/app/personne/ModifyPersonne.java @@ -0,0 +1,119 @@ +package net.plil.clubinfo.etunicorn.app.personne; + +import android.app.Dialog; +import android.content.DialogInterface; +import android.os.Bundle; +import android.support.v4.app.DialogFragment; +import android.support.v7.app.AlertDialog; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.EditText; +import android.widget.ProgressBar; +import android.widget.Toast; + +import com.android.volley.Request; +import com.android.volley.Response; +import com.android.volley.VolleyError; +import com.android.volley.toolbox.JsonObjectRequest; + +import net.plil.clubinfo.etunicorn.R; +import net.plil.clubinfo.etunicorn.data.Event; +import net.plil.clubinfo.etunicorn.data.Personne; +import net.plil.clubinfo.etunicorn.utils.VolleyUtils; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Locale; + + +public class ModifyPersonne extends DialogFragment { + + EditText mCarte; + EditText mNaissance; + EditText mLogin; + EditText mRole; + ProgressBar mProgressBar; + + public static ModifyPersonne newInstance(Personne personne) { + ModifyPersonne f = new ModifyPersonne(); + + // Supply num input as an argument. + Bundle args = new Bundle(); + args.putSerializable("event", personne); + f.setArguments(args); + + return f; + } + + + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + // Use the Builder class for convenient dialog construction + LayoutInflater inflater = getActivity().getLayoutInflater(); + View view = inflater.inflate(R.layout.fragment_modify_personne, null); + mLogin = (EditText) view.findViewById(R.id.modify_personne_login); + mCarte = (EditText) view.findViewById(R.id.modify_personne_carte); + mNaissance = (EditText) view.findViewById(R.id.modify_personne_naissance); + mRole = (EditText) view.findViewById(R.id.modify_personne_role); + mProgressBar = (ProgressBar) view.findViewById(R.id.modify_event_progress_bar); + + final Personne personne = (Personne) getArguments().getSerializable("personne"); + + mRole.setText(personne.getRole().getName()); + mCarte.setText(personne.getIdCarte()); + mLogin.setText(personne.getLoginPoly()); + mNaissance.setText(personne.getNaissance().toString()); + + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + builder + .setTitle(R.string.modify) + .setView(view) + .setPositiveButton(R.string.modify, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + + mProgressBar.setVisibility(View.VISIBLE); + mRole.setVisibility(View.GONE); + mLogin.setVisibility(View.GONE); + mCarte.setVisibility(View.GONE); + mNaissance.setVisibility(View.GONE); + JSONObject jsonObject = new JSONObject(); + try { + jsonObject.put("carte", mCarte.getText().toString()); + jsonObject.put("login", mLogin.getText().toString()); + jsonObject.put("role", mRole.getText().toString()); + jsonObject.put("naissance", mNaissance.getText().toString()); + } catch (JSONException e){ + e.printStackTrace(); + } + JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, VolleyUtils.baseUri + "/personne/" + personne.getIdPersonne() ,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(); + + } + }, new Response.ErrorListener() { + @Override + public void onErrorResponse(VolleyError error) { + mProgressBar.setVisibility(View.GONE); + Toast.makeText(getContext(), R.string.modify_refused, Toast.LENGTH_LONG).show(); + + } + } + ); + + 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(); + } + + +} diff --git a/app/src/main/java/net/plil/clubinfo/etunicorn/data/Personne.java b/app/src/main/java/net/plil/clubinfo/etunicorn/data/Personne.java index 1dfc372..c4ff69b 100644 --- a/app/src/main/java/net/plil/clubinfo/etunicorn/data/Personne.java +++ b/app/src/main/java/net/plil/clubinfo/etunicorn/data/Personne.java @@ -1,18 +1,30 @@ package net.plil.clubinfo.etunicorn.data; +import java.io.Serializable; import java.sql.Date; +import java.util.ArrayList; +import java.util.List; -public class Personne { +public class Personne implements Serializable{ private int idPersonne; - private int idCarte; + private String idCarte; private Date naissance; - private int solde = 0; + private double solde = 0; private String loginPoly; + private Role role = new Role(); public Personne() { } + public Role getRole() { + return role; + } + + public void setRole(Role role) { + this.role = role; + } + public int getIdPersonne() { return idPersonne; } @@ -21,11 +33,11 @@ public class Personne { this.idPersonne = idPersonne; } - public int getIdCarte() { + public String getIdCarte() { return idCarte; } - public void setIdCarte(int idCarte) { + public void setIdCarte(String idCarte) { this.idCarte = idCarte; } @@ -37,11 +49,11 @@ public class Personne { this.naissance = naissance; } - public int getSolde() { + public double getSolde() { return solde; } - public void setSolde(int solde) { + public void setSolde(double solde) { this.solde = solde; } diff --git a/app/src/main/res/layout/fragment_delete_personne.xml b/app/src/main/res/layout/fragment_delete_personne.xml new file mode 100644 index 0000000..dc6a18a --- /dev/null +++ b/app/src/main/res/layout/fragment_delete_personne.xml @@ -0,0 +1,17 @@ + + + + + + diff --git a/app/src/main/res/layout/fragment_modify_personne.xml b/app/src/main/res/layout/fragment_modify_personne.xml new file mode 100644 index 0000000..1e307e3 --- /dev/null +++ b/app/src/main/res/layout/fragment_modify_personne.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + diff --git a/app/src/main/res/layout/fragment_personne.xml b/app/src/main/res/layout/fragment_personne.xml new file mode 100644 index 0000000..28851a6 --- /dev/null +++ b/app/src/main/res/layout/fragment_personne.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + diff --git a/app/src/main/res/layout/fragment_personne_list.xml b/app/src/main/res/layout/fragment_personne_list.xml new file mode 100644 index 0000000..7786fad --- /dev/null +++ b/app/src/main/res/layout/fragment_personne_list.xml @@ -0,0 +1,36 @@ + + + + + + + \ No newline at end of file -- libgit2 0.21.2