Commit 73b70b1e57953c1be72f5d483e7dd84c35894a54

Authored by badetitou
1 parent d6367fe9

Ajout de Consomation

app/build.gradle
... ... @@ -30,6 +30,6 @@ dependencies {
30 30 compile 'com.google.code.gson:gson:2.4'
31 31 compile 'com.android.support:support-v4:24.2.1'
32 32 compile 'com.android.support:recyclerview-v7:24.2.1'
33   - testCompile 'junit:junit:4.12'
34 33 compile 'com.android.support:gridlayout-v7:24.2.1'
  34 + testCompile 'junit:junit:4.12'
35 35 }
... ...
app/src/main/java/net/plil/clubinfo/etunicorn/app/MainActivity.java
... ... @@ -14,8 +14,10 @@ import android.support.v7.app.AppCompatActivity;
14 14 import android.support.v7.widget.Toolbar;
15 15 import android.view.Menu;
16 16 import android.view.MenuItem;
  17 +import android.view.View;
17 18  
18 19 import net.plil.clubinfo.etunicorn.R;
  20 +import net.plil.clubinfo.etunicorn.app.consomation.FragmentConsomation;
19 21 import net.plil.clubinfo.etunicorn.data.Consomation;
20 22  
21 23  
... ...
app/src/main/java/net/plil/clubinfo/etunicorn/app/ConsomationRecyclerViewAdapter.java renamed to app/src/main/java/net/plil/clubinfo/etunicorn/app/consomation/ConsomationRecyclerViewAdapter.java
1   -package net.plil.clubinfo.etunicorn.app;
  1 +package net.plil.clubinfo.etunicorn.app.consomation;
2 2  
3 3 import android.support.v7.widget.RecyclerView;
4 4 import android.view.LayoutInflater;
5 5 import android.view.View;
6 6 import android.view.ViewGroup;
7 7 import android.widget.TextView;
  8 +import android.widget.Toast;
8 9  
9 10 import net.plil.clubinfo.etunicorn.R;
10 11 import net.plil.clubinfo.etunicorn.data.Consomation;
... ... @@ -30,6 +31,7 @@ public class ConsomationRecyclerViewAdapter extends RecyclerView.Adapter<Consoma
30 31 return new ViewHolder(view);
31 32 }
32 33  
  34 +
33 35 @Override
34 36 public void onBindViewHolder(final ViewHolder holder, int position) {
35 37 holder.mItem = mValues.get(position);
... ... @@ -41,12 +43,18 @@ public class ConsomationRecyclerViewAdapter extends RecyclerView.Adapter<Consoma
41 43 @Override
42 44 public void onClick(View v) {
43 45 if (null != mListener) {
44   - // Notify the active callbacks interface (the activity, if the
45   - // fragment is attached to one) that an item has been selected.
46 46 mListener.onListFragmentInteraction(holder.mItem);
47 47 }
48 48 }
49 49 });
  50 +
  51 + holder.mView.setOnLongClickListener(new View.OnLongClickListener() {
  52 + @Override
  53 + public boolean onLongClick(View v) {
  54 + holder.mView.setSelected(!holder.mView.isSelected());
  55 + return true;
  56 + }
  57 + });
50 58 }
51 59  
52 60 @Override
... ...
app/src/main/java/net/plil/clubinfo/etunicorn/app/consomation/CreateConsomation.java 0 → 100644
... ... @@ -0,0 +1,87 @@
  1 +package net.plil.clubinfo.etunicorn.app.consomation;
  2 +
  3 +import android.app.Dialog;
  4 +import android.content.Context;
  5 +import android.content.DialogInterface;
  6 +import android.net.Uri;
  7 +import android.os.Bundle;
  8 +import android.support.v4.app.DialogFragment;
  9 +import android.support.v4.app.Fragment;
  10 +import android.support.v7.app.AlertDialog;
  11 +import android.view.LayoutInflater;
  12 +import android.view.View;
  13 +import android.view.ViewGroup;
  14 +import android.widget.EditText;
  15 +import android.widget.ProgressBar;
  16 +
  17 +import com.android.volley.Request;
  18 +import com.android.volley.Response;
  19 +import com.android.volley.VolleyError;
  20 +import com.android.volley.toolbox.JsonObjectRequest;
  21 +
  22 +import net.plil.clubinfo.etunicorn.R;
  23 +import net.plil.clubinfo.etunicorn.utils.VolleyUtils;
  24 +
  25 +import org.json.JSONException;
  26 +import org.json.JSONObject;
  27 +
  28 +
  29 +public class CreateConsomation extends DialogFragment {
  30 +
  31 + EditText mNomConsomation;
  32 + EditText mPrice;
  33 + ProgressBar mProgressBar;
  34 +
  35 +
  36 + @Override
  37 + public Dialog onCreateDialog(Bundle savedInstanceState) {
  38 + // Use the Builder class for convenient dialog construction
  39 + LayoutInflater inflater = getActivity().getLayoutInflater();
  40 + View view = inflater.inflate(R.layout.fragment_create_consomation, null);
  41 + mNomConsomation = (EditText) view.findViewById(R.id.create_consomation_name);
  42 + mPrice = (EditText) view.findViewById(R.id.create_consomation_price);
  43 + mProgressBar = (ProgressBar) view.findViewById(R.id.create_consomation_progress_bar);
  44 + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
  45 + builder
  46 + .setTitle(R.string.create_consomation)
  47 + .setView(view)
  48 + .setPositiveButton(R.string.valid, new DialogInterface.OnClickListener() {
  49 + public void onClick(DialogInterface dialog, int id) {
  50 +
  51 + mProgressBar.setVisibility(View.VISIBLE);
  52 + mPrice.setVisibility(View.GONE);
  53 + mNomConsomation.setVisibility(View.GONE);
  54 + JSONObject jsonObject = new JSONObject();
  55 + try {
  56 + jsonObject.put("nomConsomation", mNomConsomation.getText().toString());
  57 + jsonObject.put("prix", Double.parseDouble(mPrice.getText().toString()));
  58 + } catch (JSONException e){
  59 + e.printStackTrace();
  60 + }
  61 + JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, VolleyUtils.baseUri + "/transaction/debit" ,jsonObject , new Response.Listener<JSONObject>() {
  62 + @Override
  63 + public void onResponse(JSONObject response) {
  64 + mProgressBar.setVisibility(View.GONE);
  65 + }
  66 + }, new Response.ErrorListener() {
  67 + @Override
  68 + public void onErrorResponse(VolleyError error) {
  69 + mProgressBar.setVisibility(View.GONE);
  70 + }
  71 + }
  72 + );
  73 +
  74 + VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest);
  75 + }
  76 + })
  77 + .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
  78 + public void onClick(DialogInterface dialog, int id) {
  79 + // User cancelled the dialog
  80 + }
  81 + });
  82 + // Create the AlertDialog object and return it
  83 + return builder.create();
  84 + }
  85 +
  86 +
  87 +}
... ...
app/src/main/java/net/plil/clubinfo/etunicorn/app/FragmentConsomation.java renamed to app/src/main/java/net/plil/clubinfo/etunicorn/app/consomation/FragmentConsomation.java
1   -package net.plil.clubinfo.etunicorn.app;
  1 +package net.plil.clubinfo.etunicorn.app.consomation;
2 2  
3 3 import android.content.Context;
4 4 import android.os.Bundle;
5   -import android.support.v4.app.Fragment;
6   -import android.support.v7.widget.GridLayoutManager;
  5 +import android.support.design.widget.FloatingActionButton;
7 6 import android.support.v7.widget.LinearLayoutManager;
8 7 import android.support.v7.widget.RecyclerView;
9 8 import android.view.LayoutInflater;
10 9 import android.view.View;
11 10 import android.view.ViewGroup;
  11 +import android.widget.Toast;
12 12  
13 13 import net.plil.clubinfo.etunicorn.R;
  14 +import net.plil.clubinfo.etunicorn.app.FragmentNFC;
14 15 import net.plil.clubinfo.etunicorn.data.Consomation;
15 16  
16 17 import java.util.ArrayList;
... ... @@ -24,7 +25,6 @@ import java.util.List;
24 25 */
25 26 public class FragmentConsomation extends FragmentNFC {
26 27  
27   - private int mColumnCount = 1;
28 28 private OnListFragmentInteractionListener mListener;
29 29  
30 30 /**
... ... @@ -50,22 +50,15 @@ public class FragmentConsomation extends FragmentNFC {
50 50 RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.consomation_list);
51 51 // Set the adapter
52 52 Context context = recyclerView.getContext();
53   - if (mColumnCount <= 1) {
54   - recyclerView.setLayoutManager(new LinearLayoutManager(context));
55   - } else {
56   - recyclerView.setLayoutManager(new GridLayoutManager(context, mColumnCount));
57   - }
  53 +
  54 + recyclerView.setLayoutManager(new LinearLayoutManager(context));
  55 +
58 56 List<Consomation> consomationList = new ArrayList<>();
59 57 Consomation c1 = new Consomation();
60 58 c1.setIdConsomation(1);
61 59 c1.setNomConsomation("Hello");
62 60 c1.setPrix(12.5);
63 61 consomationList.add(c1);
64   - c1 = new Consomation();
65   - c1.setIdConsomation(2);
66   - c1.setNomConsomation("World");
67   - c1.setPrix(42.407);
68   - consomationList.add(c1);
69 62 for (int i = 0; i< 100; ++i){
70 63 c1 = new Consomation();
71 64 c1.setIdConsomation(i);
... ... @@ -75,6 +68,15 @@ public class FragmentConsomation extends FragmentNFC {
75 68 }
76 69 recyclerView.setAdapter(new ConsomationRecyclerViewAdapter(consomationList, mListener));
77 70  
  71 + FloatingActionButton fAB = (FloatingActionButton) view.findViewById(R.id.consomation_add);
  72 + fAB.setOnClickListener(new View.OnClickListener() {
  73 + @Override
  74 + public void onClick(View v) {
  75 + CreateConsomation newFragment = new CreateConsomation();
  76 + newFragment.show(getFragmentManager(), "CreateConsomation");
  77 + }
  78 + });
  79 +
78 80 return view;
79 81 }
80 82  
... ...
app/src/main/res/drawable/selected_row.xml 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<selector xmlns:android="http://schemas.android.com/apk/res/android" >
  3 + <item android:state_selected="true">
  4 + <color android:color="#EEEEEE"/>
  5 + </item>
  6 + <item android:state_selected="false">
  7 + <color android:color="#FFFFFF"/>
  8 + </item>
  9 +</selector>
0 10 \ No newline at end of file
... ...
app/src/main/res/layout/activity_main.xml
... ... @@ -18,10 +18,10 @@
18 18 <android.support.v7.widget.Toolbar
19 19 android:id="@+id/toolbar"
20 20 android:layout_width="match_parent"
21   - android:layout_height="?attr/actionBarSize"
22 21 android:background="?attr/colorPrimary"
23   - app:layout_scrollFlags="scroll|enterAlways"
24   - app:popupTheme="@style/AppTheme.PopupOverlay">
  22 + app:layout_scrollFlags="enterAlways"
  23 + app:popupTheme="@style/AppTheme.PopupOverlay"
  24 + android:layout_height="64dp">
25 25  
26 26 </android.support.v7.widget.Toolbar>
27 27  
... ... @@ -35,7 +35,7 @@
35 35 <android.support.v4.view.ViewPager
36 36 android:id="@+id/container"
37 37 android:layout_width="match_parent"
38   - android:layout_height="match_parent"
  38 + android:layout_height="wrap_content"
39 39 app:layout_behavior="@string/appbar_scrolling_view_behavior" />
40 40  
41 41  
... ...
app/src/main/res/layout/fragment_consomation_item.xml
... ... @@ -2,7 +2,9 @@
2 2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 3 android:layout_width="wrap_content"
4 4 android:layout_height="wrap_content"
5   - android:orientation="horizontal">
  5 + android:orientation="horizontal"
  6 + android:foreground="?attr/selectableItemBackground"
  7 + android:background="@drawable/selected_row">
6 8  
7 9 <TextView
8 10 android:id="@+id/consomation_id"
... ...
app/src/main/res/layout/fragment_consomation_item_list.xml
... ... @@ -14,8 +14,9 @@
14 14 android:layout_marginLeft="16dp"
15 15 android:layout_marginRight="16dp"
16 16 app:layoutManager="LinearLayoutManager"
17   - tools:context="net.plil.clubinfo.etunicorn.app.FragmentConsomation"
18   - tools:listitem="@layout/fragment_consomation_item" />
  17 + tools:context="net.plil.clubinfo.etunicorn.app.consomation.FragmentConsomation"
  18 + tools:listitem="@layout/fragment_consomation_item"
  19 + />
19 20  
20 21 <android.support.design.widget.FloatingActionButton
21 22 android:layout_width="wrap_content"
... ... @@ -31,6 +32,6 @@
31 32 app:rippleColor="@color/colorAccent"
32 33 app:layout_anchor="@id/consomation_list"
33 34 app:layout_anchorGravity="bottom|right|end"
34   - app:layout_behavior="net.plil.clubinfo.etunicorn.utils.ScrollAwareFABBehavior"/>
  35 + app:layout_behavior="net.plil.clubinfo.etunicorn.utils.ScrollAwareFABBehavior" />
35 36  
36 37 </android.support.design.widget.CoordinatorLayout>
37 38 \ No newline at end of file
... ...
app/src/main/res/layout/fragment_create_consomation.xml 0 → 100644
... ... @@ -0,0 +1,32 @@
  1 +<LinearLayout
  2 + xmlns:android="http://schemas.android.com/apk/res/android"
  3 + xmlns:tools="http://schemas.android.com/tools"
  4 + tools:context="net.plil.clubinfo.etunicorn.app.consomation.CreateConsomation"
  5 + android:orientation="vertical"
  6 + android:layout_width="match_parent"
  7 + android:layout_height="match_parent"
  8 + >
  9 +
  10 + <EditText
  11 + android:layout_width="match_parent"
  12 + android:layout_height="wrap_content"
  13 + android:id="@+id/create_consomation_name"
  14 + android:hint="@string/create_consomation_name"/>
  15 +
  16 + <EditText
  17 + android:layout_width="match_parent"
  18 + android:layout_height="match_parent"
  19 + android:hint="@string/create_consomation_price"
  20 + android:id="@+id/create_consomation_price"
  21 + android:inputType="numberSigned|numberDecimal"
  22 + android:maxLines="1" />
  23 +
  24 + <ProgressBar
  25 + style="?android:attr/progressBarStyle"
  26 + android:layout_width="match_parent"
  27 + android:layout_height="wrap_content"
  28 + android:id="@+id/create_consomation_progress_bar"
  29 + android:visibility="gone"/>
  30 +
  31 +</LinearLayout>
  32 +
... ...
app/src/main/res/values-fr/strings.xml
... ... @@ -7,4 +7,12 @@
7 7 <string name="error_invalid_password">Mot de passe invalide</string>
8 8 <string name="prompt_password">Mot de passe</string>
9 9 <string name="prompt_username">Nom d\'utilisateur</string>
  10 + <string name="action_settings">Paramètres</string>
  11 + <string name="cancel">Annuler</string>
  12 + <string name="create_consomation">Créer une consomation</string>
  13 + <string name="create_consomation_name">Nom</string>
  14 + <string name="create_consomation_price">Prix</string>
  15 + <string name="enter_money">Entrer une valeur</string>
  16 + <string name="valid">OK</string>
  17 + <string name="title_activity_main">Etunicorn - Bonjour</string>
10 18 </resources>
11 19 \ No newline at end of file
... ...
app/src/main/res/values/colors.xml
... ... @@ -3,4 +3,7 @@
3 3 <color name="colorPrimary">#F44336</color>
4 4 <color name="colorPrimaryDark">#C62828</color>
5 5 <color name="colorAccent">#2196F3</color>
  6 +
  7 + <color name="pressed_color">#4d90fe</color>
  8 + <color name="default_color">#ffffff</color>
6 9 </resources>
... ...
app/src/main/res/values/strings.xml
... ... @@ -8,11 +8,13 @@
8 8 <string name="error_incorrect_password">This password is incorrect</string>
9 9 <string name="error_field_required">This field is required</string>
10 10 <string name="prompt_username">Username</string>
11   - <string name="title_activity_main">MainActivity</string>
12 11 <string name="action_settings">Settings</string>
13   - <string name="section_format">Hello World from section: %1$d</string>
14 12  
15   - <!-- TODO: Remove or change this placeholder text -->
16   - <string name="hello_blank_fragment">Hello blank fragment</string>
17 13 <string name="enter_money">Enter value</string>
  14 + <string name="valid">OK</string>
  15 + <string name="cancel">Cancel</string>
  16 + <string name="create_consomation">Create Consomation</string>
  17 + <string name="create_consomation_name">Name</string>
  18 + <string name="create_consomation_price">Price</string>
  19 + <string name="title_activity_main">Etunicorn - Hello</string>
18 20 </resources>
... ...