diff --git a/app/build.gradle b/app/build.gradle index 5946b7b..bf26236 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -30,6 +30,6 @@ dependencies { compile 'com.google.code.gson:gson:2.4' compile 'com.android.support:support-v4:24.2.1' compile 'com.android.support:recyclerview-v7:24.2.1' - testCompile 'junit:junit:4.12' compile 'com.android.support:gridlayout-v7:24.2.1' + testCompile 'junit:junit:4.12' } diff --git a/app/src/main/java/net/plil/clubinfo/etunicorn/app/ConsomationRecyclerViewAdapter.java b/app/src/main/java/net/plil/clubinfo/etunicorn/app/ConsomationRecyclerViewAdapter.java deleted file mode 100644 index 1e187ac..0000000 --- a/app/src/main/java/net/plil/clubinfo/etunicorn/app/ConsomationRecyclerViewAdapter.java +++ /dev/null @@ -1,77 +0,0 @@ -package net.plil.clubinfo.etunicorn.app; - -import android.support.v7.widget.RecyclerView; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import net.plil.clubinfo.etunicorn.R; -import net.plil.clubinfo.etunicorn.data.Consomation; - -import java.util.List; -import java.util.Locale; - - -public class ConsomationRecyclerViewAdapter extends RecyclerView.Adapter { - - private final List mValues; - private final FragmentConsomation.OnListFragmentInteractionListener mListener; - - public ConsomationRecyclerViewAdapter(List items, FragmentConsomation.OnListFragmentInteractionListener listener) { - mValues = items; - mListener = listener; - } - - @Override - public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { - View view = LayoutInflater.from(parent.getContext()) - .inflate(R.layout.fragment_consomation_item, parent, false); - return new ViewHolder(view); - } - - @Override - public void onBindViewHolder(final ViewHolder holder, int position) { - holder.mItem = mValues.get(position); - holder.mIdView.setText(String.format(Locale.FRANCE, "%d", mValues.get(position).getIdConsomation())); - holder.mContentView.setText(mValues.get(position).getNomConsomation()); - holder.mPriceView.setText(String.format(Locale.FRANCE, "%f",mValues.get(position).getPrix())); - - holder.mView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (null != mListener) { - // Notify the active callbacks interface (the activity, if the - // fragment is attached to one) that an item has been selected. - mListener.onListFragmentInteraction(holder.mItem); - } - } - }); - } - - @Override - public int getItemCount() { - return mValues.size(); - } - - public class ViewHolder extends RecyclerView.ViewHolder { - public final View mView; - public final TextView mIdView; - public final TextView mContentView; - public final TextView mPriceView; - public Consomation mItem; - - public ViewHolder(View view) { - super(view); - mView = view; - mIdView = (TextView) view.findViewById(R.id.consomation_id); - mContentView = (TextView) view.findViewById(R.id.consomation_name); - mPriceView = (TextView) view.findViewById(R.id.consomation_price); - } - - @Override - public String toString() { - return super.toString() + " '" + mContentView.getText() + "'"; - } - } -} diff --git a/app/src/main/java/net/plil/clubinfo/etunicorn/app/FragmentConsomation.java b/app/src/main/java/net/plil/clubinfo/etunicorn/app/FragmentConsomation.java deleted file mode 100644 index b7cdfa4..0000000 --- a/app/src/main/java/net/plil/clubinfo/etunicorn/app/FragmentConsomation.java +++ /dev/null @@ -1,117 +0,0 @@ -package net.plil.clubinfo.etunicorn.app; - -import android.content.Context; -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.support.v7.widget.GridLayoutManager; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - -import net.plil.clubinfo.etunicorn.R; -import net.plil.clubinfo.etunicorn.data.Consomation; - -import java.util.ArrayList; -import java.util.List; - -/** - * A fragment representing a list of Items. - *

- * Activities containing this fragment MUST implement the {@link OnListFragmentInteractionListener} - * interface. - */ -public class FragmentConsomation extends FragmentNFC { - - private int mColumnCount = 1; - private OnListFragmentInteractionListener mListener; - - /** - * Mandatory empty constructor for the fragment manager to instantiate the - * fragment (e.g. upon screen orientation changes). - */ - public FragmentConsomation() { - } - - public static FragmentConsomation newInstance() { - return new FragmentConsomation(); - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.fragment_consomation_item_list, container, false); - RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.consomation_list); - // Set the adapter - Context context = recyclerView.getContext(); - if (mColumnCount <= 1) { - recyclerView.setLayoutManager(new LinearLayoutManager(context)); - } else { - recyclerView.setLayoutManager(new GridLayoutManager(context, mColumnCount)); - } - List consomationList = new ArrayList<>(); - Consomation c1 = new Consomation(); - c1.setIdConsomation(1); - c1.setNomConsomation("Hello"); - c1.setPrix(12.5); - consomationList.add(c1); - c1 = new Consomation(); - c1.setIdConsomation(2); - c1.setNomConsomation("World"); - c1.setPrix(42.407); - consomationList.add(c1); - for (int i = 0; i< 100; ++i){ - c1 = new Consomation(); - c1.setIdConsomation(i); - c1.setNomConsomation("World"); - c1.setPrix(42.407); - consomationList.add(c1); - } - recyclerView.setAdapter(new ConsomationRecyclerViewAdapter(consomationList, mListener)); - - return view; - } - - - @Override - public void onAttach(Context context) { - super.onAttach(context); - if (context instanceof OnListFragmentInteractionListener) { - mListener = (OnListFragmentInteractionListener) context; - } else { - throw new RuntimeException(context.toString() - + " must implement OnListFragmentInteractionListener"); - } - } - - @Override - public void onDetach() { - super.onDetach(); - mListener = null; - } - - @Override - public void processNFC() { - - } - - /** - * This interface must be implemented by activities that contain this - * fragment to allow an interaction in this fragment to be communicated - * to the activity and potentially other fragments contained in that - * activity. - *

- * See the Android Training lesson Communicating with Other Fragments for more information. - */ - public interface OnListFragmentInteractionListener { - void onListFragmentInteraction(Consomation item); - } -} diff --git a/app/src/main/java/net/plil/clubinfo/etunicorn/app/MainActivity.java b/app/src/main/java/net/plil/clubinfo/etunicorn/app/MainActivity.java index 6a304a1..27896cc 100644 --- a/app/src/main/java/net/plil/clubinfo/etunicorn/app/MainActivity.java +++ b/app/src/main/java/net/plil/clubinfo/etunicorn/app/MainActivity.java @@ -14,8 +14,10 @@ import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.Menu; import android.view.MenuItem; +import android.view.View; import net.plil.clubinfo.etunicorn.R; +import net.plil.clubinfo.etunicorn.app.consomation.FragmentConsomation; import net.plil.clubinfo.etunicorn.data.Consomation; diff --git a/app/src/main/java/net/plil/clubinfo/etunicorn/app/consomation/ConsomationRecyclerViewAdapter.java b/app/src/main/java/net/plil/clubinfo/etunicorn/app/consomation/ConsomationRecyclerViewAdapter.java new file mode 100644 index 0000000..efd656d --- /dev/null +++ b/app/src/main/java/net/plil/clubinfo/etunicorn/app/consomation/ConsomationRecyclerViewAdapter.java @@ -0,0 +1,85 @@ +package net.plil.clubinfo.etunicorn.app.consomation; + +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; +import android.widget.Toast; + +import net.plil.clubinfo.etunicorn.R; +import net.plil.clubinfo.etunicorn.data.Consomation; + +import java.util.List; +import java.util.Locale; + + +public class ConsomationRecyclerViewAdapter extends RecyclerView.Adapter { + + private final List mValues; + private final FragmentConsomation.OnListFragmentInteractionListener mListener; + + public ConsomationRecyclerViewAdapter(List items, FragmentConsomation.OnListFragmentInteractionListener listener) { + mValues = items; + mListener = listener; + } + + @Override + public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + View view = LayoutInflater.from(parent.getContext()) + .inflate(R.layout.fragment_consomation_item, parent, false); + return new ViewHolder(view); + } + + + @Override + public void onBindViewHolder(final ViewHolder holder, int position) { + holder.mItem = mValues.get(position); + holder.mIdView.setText(String.format(Locale.FRANCE, "%d", mValues.get(position).getIdConsomation())); + holder.mContentView.setText(mValues.get(position).getNomConsomation()); + holder.mPriceView.setText(String.format(Locale.FRANCE, "%f",mValues.get(position).getPrix())); + + holder.mView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (null != mListener) { + mListener.onListFragmentInteraction(holder.mItem); + } + } + }); + + holder.mView.setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + holder.mView.setSelected(!holder.mView.isSelected()); + return true; + } + }); + } + + @Override + public int getItemCount() { + return mValues.size(); + } + + public class ViewHolder extends RecyclerView.ViewHolder { + public final View mView; + public final TextView mIdView; + public final TextView mContentView; + public final TextView mPriceView; + public Consomation mItem; + + public ViewHolder(View view) { + super(view); + mView = view; + mIdView = (TextView) view.findViewById(R.id.consomation_id); + mContentView = (TextView) view.findViewById(R.id.consomation_name); + mPriceView = (TextView) view.findViewById(R.id.consomation_price); + } + + @Override + public String toString() { + return super.toString() + " '" + mContentView.getText() + "'"; + } + } +} diff --git a/app/src/main/java/net/plil/clubinfo/etunicorn/app/consomation/CreateConsomation.java b/app/src/main/java/net/plil/clubinfo/etunicorn/app/consomation/CreateConsomation.java new file mode 100644 index 0000000..0dbdffb --- /dev/null +++ b/app/src/main/java/net/plil/clubinfo/etunicorn/app/consomation/CreateConsomation.java @@ -0,0 +1,87 @@ +package net.plil.clubinfo.etunicorn.app.consomation; + +import android.app.Dialog; +import android.content.Context; +import android.content.DialogInterface; +import android.net.Uri; +import android.os.Bundle; +import android.support.v4.app.DialogFragment; +import android.support.v4.app.Fragment; +import android.support.v7.app.AlertDialog; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.EditText; +import android.widget.ProgressBar; + +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.utils.VolleyUtils; + +import org.json.JSONException; +import org.json.JSONObject; + + +public class CreateConsomation extends DialogFragment { + + EditText mNomConsomation; + EditText mPrice; + ProgressBar mProgressBar; + + + @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_create_consomation, null); + 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 + .setTitle(R.string.create_consomation) + .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(); + } + 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); + } + }, new Response.ErrorListener() { + @Override + public void onErrorResponse(VolleyError error) { + mProgressBar.setVisibility(View.GONE); + } + } + ); + + 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/app/consomation/FragmentConsomation.java b/app/src/main/java/net/plil/clubinfo/etunicorn/app/consomation/FragmentConsomation.java new file mode 100644 index 0000000..d5c7d49 --- /dev/null +++ b/app/src/main/java/net/plil/clubinfo/etunicorn/app/consomation/FragmentConsomation.java @@ -0,0 +1,119 @@ +package net.plil.clubinfo.etunicorn.app.consomation; + +import android.content.Context; +import android.os.Bundle; +import android.support.design.widget.FloatingActionButton; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Toast; + +import net.plil.clubinfo.etunicorn.R; +import net.plil.clubinfo.etunicorn.app.FragmentNFC; +import net.plil.clubinfo.etunicorn.data.Consomation; + +import java.util.ArrayList; +import java.util.List; + +/** + * A fragment representing a list of Items. + *

+ * Activities containing this fragment MUST implement the {@link OnListFragmentInteractionListener} + * interface. + */ +public class FragmentConsomation extends FragmentNFC { + + private OnListFragmentInteractionListener mListener; + + /** + * Mandatory empty constructor for the fragment manager to instantiate the + * fragment (e.g. upon screen orientation changes). + */ + public FragmentConsomation() { + } + + public static FragmentConsomation newInstance() { + return new FragmentConsomation(); + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.fragment_consomation_item_list, container, false); + RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.consomation_list); + // Set the adapter + Context context = recyclerView.getContext(); + + recyclerView.setLayoutManager(new LinearLayoutManager(context)); + + List consomationList = new ArrayList<>(); + Consomation c1 = new Consomation(); + c1.setIdConsomation(1); + c1.setNomConsomation("Hello"); + c1.setPrix(12.5); + consomationList.add(c1); + for (int i = 0; i< 100; ++i){ + c1 = new Consomation(); + c1.setIdConsomation(i); + c1.setNomConsomation("World"); + c1.setPrix(42.407); + consomationList.add(c1); + } + recyclerView.setAdapter(new ConsomationRecyclerViewAdapter(consomationList, mListener)); + + FloatingActionButton fAB = (FloatingActionButton) view.findViewById(R.id.consomation_add); + fAB.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + CreateConsomation newFragment = new CreateConsomation(); + newFragment.show(getFragmentManager(), "CreateConsomation"); + } + }); + + return view; + } + + + @Override + public void onAttach(Context context) { + super.onAttach(context); + if (context instanceof OnListFragmentInteractionListener) { + mListener = (OnListFragmentInteractionListener) context; + } else { + throw new RuntimeException(context.toString() + + " must implement OnListFragmentInteractionListener"); + } + } + + @Override + public void onDetach() { + super.onDetach(); + mListener = null; + } + + @Override + public void processNFC() { + + } + + /** + * This interface must be implemented by activities that contain this + * fragment to allow an interaction in this fragment to be communicated + * to the activity and potentially other fragments contained in that + * activity. + *

+ * See the Android Training lesson Communicating with Other Fragments for more information. + */ + public interface OnListFragmentInteractionListener { + void onListFragmentInteraction(Consomation item); + } +} diff --git a/app/src/main/res/drawable/selected_row.xml b/app/src/main/res/drawable/selected_row.xml new file mode 100644 index 0000000..cc210f7 --- /dev/null +++ b/app/src/main/res/drawable/selected_row.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index a313bc0..5fa6811 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -18,10 +18,10 @@ + app:layout_scrollFlags="enterAlways" + app:popupTheme="@style/AppTheme.PopupOverlay" + android:layout_height="64dp"> @@ -35,7 +35,7 @@ diff --git a/app/src/main/res/layout/fragment_consomation_item.xml b/app/src/main/res/layout/fragment_consomation_item.xml index e6759a0..d87b0e8 100644 --- a/app/src/main/res/layout/fragment_consomation_item.xml +++ b/app/src/main/res/layout/fragment_consomation_item.xml @@ -2,7 +2,9 @@ + android:orientation="horizontal" + android:foreground="?attr/selectableItemBackground" + android:background="@drawable/selected_row"> + tools:context="net.plil.clubinfo.etunicorn.app.consomation.FragmentConsomation" + tools:listitem="@layout/fragment_consomation_item" + /> + app:layout_behavior="net.plil.clubinfo.etunicorn.utils.ScrollAwareFABBehavior" /> \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_create_consomation.xml b/app/src/main/res/layout/fragment_create_consomation.xml new file mode 100644 index 0000000..e93bc1e --- /dev/null +++ b/app/src/main/res/layout/fragment_create_consomation.xml @@ -0,0 +1,32 @@ + + + + + + + + + + diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 6e52005..6b02d2b 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -7,4 +7,12 @@ Mot de passe invalide Mot de passe Nom d\'utilisateur + Paramètres + Annuler + Créer une consomation + Nom + Prix + Entrer une valeur + OK + Etunicorn - Bonjour \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 6d2cf9f..927f6e1 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -3,4 +3,7 @@ #F44336 #C62828 #2196F3 + + #4d90fe + #ffffff diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ad7120c..0e2d425 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -8,11 +8,13 @@ This password is incorrect This field is required Username - MainActivity Settings - Hello World from section: %1$d - - Hello blank fragment Enter value + OK + Cancel + Create Consomation + Name + Price + Etunicorn - Hello -- libgit2 0.21.2