Commit 25857bb395aaf191b39c6b59f4e43c25ae151be8

Authored by badetitou
1 parent d17732ca

Fragment Personne

app/src/main/java/net/plil/clubinfo/etunicorn/app/MainActivity.java
... ... @@ -2,6 +2,7 @@ package net.plil.clubinfo.etunicorn.app;
2 2  
3 3 import android.app.PendingIntent;
4 4 import android.content.Intent;
  5 +import android.net.Uri;
5 6 import android.nfc.NfcAdapter;
6 7 import android.nfc.Tag;
7 8 import android.os.Bundle;
... ... @@ -10,6 +11,7 @@ import android.support.design.widget.TabLayout;
10 11 import android.support.v4.app.Fragment;
11 12 import android.support.v4.app.FragmentManager;
12 13 import android.support.v4.app.FragmentPagerAdapter;
  14 +import android.support.v4.app.FragmentTransaction;
13 15 import android.support.v4.view.ViewPager;
14 16 import android.support.v7.app.AppCompatActivity;
15 17 import android.support.v7.widget.Toolbar;
... ... @@ -24,6 +26,7 @@ import net.plil.clubinfo.etunicorn.app.event.EventFragment;
24 26 import net.plil.clubinfo.etunicorn.app.event.PaiementEvent;
25 27 import net.plil.clubinfo.etunicorn.app.consommation.FragmentConsommation;
26 28 import net.plil.clubinfo.etunicorn.app.consommation.PaiementConsommation;
  29 +import net.plil.clubinfo.etunicorn.app.personne.PersonOverviewFragment;
27 30 import net.plil.clubinfo.etunicorn.app.personne.PersonneFragment;
28 31 import net.plil.clubinfo.etunicorn.data.Consommation;
29 32 import net.plil.clubinfo.etunicorn.data.Event;
... ... @@ -37,7 +40,9 @@ import java.util.List;
37 40 public class MainActivity extends AppCompatActivity
38 41 implements FragmentConsommation.OnListFragmentInteractionListener,
39 42 EventFragment.OnListFragmentInteractionListener,
40   - PersonneFragment.OnListFragmentInteractionListener{
  43 + PersonneFragment.OnListFragmentInteractionListener,
  44 + PersonOverviewFragment.OnFragmentInteractionListener
  45 +{
41 46  
42 47 /**
43 48 * The {@link android.support.v4.view.PagerAdapter} that will provide
... ... @@ -70,17 +75,18 @@ public class MainActivity extends AppCompatActivity
70 75 // config tabbed pan
71 76 Intent intent = this.getIntent();
72 77 Personne p = (Personne) intent.getSerializableExtra("user");
73   - Toast.makeText(getApplicationContext(), p.getRole().getPermissions().get(0).getNom(), Toast.LENGTH_LONG).show();
  78 + //TODO remove this line
  79 + Toast.makeText(getApplicationContext(), p.getRole().getPermissions().get(0).getNom(), Toast.LENGTH_SHORT).show();
74 80 if (p.getRole().getPermissions().get(0).getNom().equals("ROLE_ADMIN")){
75 81 nbPages = 5;
76 82 Action.CONSOMATION.setValue(2);
77 83 Action.EVENT.setValue(3);
78 84 Action.PERSONNE.setValue(4);
79 85 } else if (p.getRole().getPermissions().get(0).getNom().equals("ROLE_BDE")){
80   - nbPages = 4;
81   - Action.CONSOMATION.setValue(-1);
82   - Action.EVENT.setValue(2);
83   - Action.PERSONNE.setValue(3);
  86 + nbPages = 4;
  87 + Action.CONSOMATION.setValue(-1);
  88 + Action.EVENT.setValue(2);
  89 + Action.PERSONNE.setValue(3);
84 90 } else if (p.getRole().getPermissions().get(0).getNom().equals("ROLE_BAR")){
85 91 nbPages = 3;
86 92 Action.CONSOMATION.setValue(2);
... ... @@ -190,6 +196,8 @@ public class MainActivity extends AppCompatActivity
190 196  
191 197 @Override
192 198 public void onListFragmentInteraction(Personne personne) {
  199 + PersonOverviewFragment personOverviewFragment = PersonOverviewFragment.newInstance(personne);
  200 + personOverviewFragment.show(getSupportFragmentManager(), "overviewPersonne");
193 201  
194 202 }
195 203  
... ... @@ -198,6 +206,11 @@ public class MainActivity extends AppCompatActivity
198 206  
199 207 }
200 208  
  209 + @Override
  210 + public void onFragmentInteraction(Uri uri) {
  211 +
  212 + }
  213 +
201 214 /**
202 215 * A {@link FragmentPagerAdapter} that returns a fragment corresponding to
203 216 * one of the sections/tabs/pages.
... ...
app/src/main/java/net/plil/clubinfo/etunicorn/app/personne/ModifyPersonne.java
... ... @@ -40,7 +40,7 @@ public class ModifyPersonne extends DialogFragment {
40 40  
41 41 // Supply num input as an argument.
42 42 Bundle args = new Bundle();
43   - args.putSerializable("event", personne);
  43 + args.putSerializable("personne", personne);
44 44 f.setArguments(args);
45 45  
46 46 return f;
... ...
app/src/main/java/net/plil/clubinfo/etunicorn/app/personne/PersonOverviewFragment.java 0 โ†’ 100644
... ... @@ -0,0 +1,104 @@
  1 +package net.plil.clubinfo.etunicorn.app.personne;
  2 +
  3 +import android.app.Dialog;
  4 +import android.content.Context;
  5 +import android.net.Uri;
  6 +import android.os.Bundle;
  7 +import android.support.v4.app.DialogFragment;
  8 +import android.support.v4.app.Fragment;
  9 +import android.support.v7.app.AlertDialog;
  10 +import android.view.LayoutInflater;
  11 +import android.view.View;
  12 +import android.view.ViewGroup;
  13 +import android.widget.TextView;
  14 +
  15 +import net.plil.clubinfo.etunicorn.R;
  16 +import net.plil.clubinfo.etunicorn.data.Personne;
  17 +
  18 +import java.util.Locale;
  19 +
  20 +/**
  21 + * A simple {@link Fragment} subclass.
  22 + * Activities that contain this fragment must implement the
  23 + * {@link PersonOverviewFragment.OnFragmentInteractionListener} interface
  24 + * to handle interaction events.
  25 + */
  26 +public class PersonOverviewFragment extends DialogFragment{
  27 +
  28 + private OnFragmentInteractionListener mListener;
  29 +
  30 + TextView mCarte;
  31 + TextView mNaissance;
  32 + TextView mSolde;
  33 + TextView mLogin;
  34 + TextView mRole;
  35 +
  36 + public PersonOverviewFragment() {
  37 + // Required empty public constructor
  38 + }
  39 +
  40 + public static PersonOverviewFragment newInstance(Personne item) {
  41 + PersonOverviewFragment f = new PersonOverviewFragment();
  42 + Bundle args = new Bundle();
  43 + args.putSerializable("personne", item);
  44 + f.setArguments(args);
  45 + return f;
  46 + }
  47 +
  48 + @Override
  49 + public Dialog onCreateDialog(Bundle savedInstanceState){
  50 + LayoutInflater inflater = getActivity().getLayoutInflater();
  51 + View view = inflater.inflate(R.layout.fragment_person_overview, null);
  52 +
  53 + final Personne personne = (Personne) getArguments().getSerializable("personne");
  54 +
  55 + mCarte = (TextView) view.findViewById(R.id.personne_overview_carte);
  56 + mLogin = (TextView) view.findViewById(R.id.personne_overview_login);
  57 + mNaissance = (TextView) view.findViewById(R.id.personne_overview_naissance);
  58 + mSolde = (TextView) view.findViewById(R.id.personne_overview_solde);
  59 + mRole = (TextView) view.findViewById(R.id.personne_overview_role);
  60 +
  61 + assert personne != null;
  62 + mCarte.setText(personne.getIdCarte());
  63 + mRole.setText(personne.getRole().getName());
  64 + mSolde.setText(String.format(Locale.FRANCE, "%.2f",personne.getSolde()));
  65 + mNaissance.setText(personne.getNaissance().toString());
  66 + mLogin.setText(personne.getLoginPoly());
  67 +
  68 + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
  69 + builder
  70 + .setTitle(R.string.personne)
  71 + .setView(view);
  72 + return builder.create();
  73 + }
  74 +
  75 + @Override
  76 + public View onCreateView(LayoutInflater inflater, ViewGroup container,
  77 + Bundle savedInstanceState) {
  78 + return inflater.inflate(R.layout.fragment_person_overview, container, false);
  79 + }
  80 +
  81 +
  82 + @Override
  83 + public void onAttach(Context context) {
  84 + super.onAttach(context);
  85 + if (context instanceof OnFragmentInteractionListener) {
  86 + mListener = (OnFragmentInteractionListener) context;
  87 + } else {
  88 + throw new RuntimeException(context.toString()
  89 + + " must implement OnFragmentInteractionListener");
  90 + }
  91 + }
  92 +
  93 + @Override
  94 + public void onDetach() {
  95 + super.onDetach();
  96 + mListener = null;
  97 + }
  98 +
  99 +
  100 + public interface OnFragmentInteractionListener {
  101 + // TODO: Update argument type and name
  102 + void onFragmentInteraction(Uri uri);
  103 + }
  104 +}
... ...
app/src/main/java/net/plil/clubinfo/etunicorn/app/personne/PersonneFragment.java
... ... @@ -12,7 +12,9 @@ import android.view.ViewGroup;
12 12  
13 13 import net.plil.clubinfo.etunicorn.R;
14 14 import net.plil.clubinfo.etunicorn.app.FragmentNFC;
  15 +import net.plil.clubinfo.etunicorn.data.Permission;
15 16 import net.plil.clubinfo.etunicorn.data.Personne;
  17 +import net.plil.clubinfo.etunicorn.data.Role;
16 18  
17 19 import java.sql.Date;
18 20 import java.util.ArrayList;
... ... @@ -56,13 +58,22 @@ public class PersonneFragment extends FragmentNFC {
56 58 recyclerView.setLayoutManager(new LinearLayoutManager(context));
57 59  
58 60 List<Personne> personneList = new ArrayList<>();
  61 + Role r = new Role();
  62 + r.setName("ADMIN_TEST");
  63 + Permission p = new Permission();
  64 + p.setNom("Lire");
  65 + r.getPermissions().add(p);
  66 + p = new Permission();
  67 + p.setNom("Ecrire");
  68 + r.getPermissions().add(p);
59 69 for (int i = 0;i<150;++i){
60   - Personne p = new Personne();
61   - p.setIdCarte("15245698547856");
62   - p.setLoginPoly("bverhaeg");
63   - p.setNaissance(new Date(System.currentTimeMillis()));
64   - p.setSolde(45);
65   - personneList.add(p);
  70 + Personne personne = new Personne();
  71 + personne.setIdCarte("15245698547856");
  72 + personne.setLoginPoly("bverhaeg");
  73 + personne.setNaissance(new Date(System.currentTimeMillis()));
  74 + personne.setSolde(45);
  75 + personne.setRole(r);
  76 + personneList.add(personne);
66 77 }
67 78 recyclerView.setAdapter(new MyPersonneRecyclerViewAdapter(personneList, mListener, getActivity()));
68 79  
... ...
app/src/main/res/layout/fragment_person_overview.xml 0 โ†’ 100644
... ... @@ -0,0 +1,55 @@
  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.personne.PersonOverviewFragment"
  6 + android:orientation="vertical">
  7 +
  8 + <TextView
  9 + android:layout_width="wrap_content"
  10 + android:layout_height="wrap_content"
  11 + android:id="@+id/personne_overview_carte"
  12 + android:textAppearance="@android:style/TextAppearance.Material.Body1"
  13 + android:layout_marginStart="24dp"
  14 + android:layout_marginTop="4dp"
  15 + android:layout_marginBottom="4dp"
  16 + />
  17 +
  18 + <TextView
  19 + android:layout_width="wrap_content"
  20 + android:layout_height="wrap_content"
  21 + android:id="@+id/personne_overview_login"
  22 + android:textAppearance="@android:style/TextAppearance.Material.Body1"
  23 + android:layout_marginStart="24dp"
  24 + android:layout_marginTop="4dp"
  25 + android:layout_marginBottom="4dp"/>
  26 +
  27 + <TextView
  28 + android:layout_width="wrap_content"
  29 + android:layout_height="wrap_content"
  30 + android:id="@+id/personne_overview_naissance"
  31 + android:textAppearance="@android:style/TextAppearance.Material.Body1"
  32 + android:layout_marginStart="24dp"
  33 + android:layout_marginTop="4dp"
  34 + android:layout_marginBottom="4dp"/>
  35 +
  36 + <TextView
  37 + android:layout_width="wrap_content"
  38 + android:layout_height="wrap_content"
  39 + android:id="@+id/personne_overview_solde"
  40 + android:textAppearance="@android:style/TextAppearance.Material.Body1"
  41 + android:layout_marginStart="24dp"
  42 + android:layout_marginTop="4dp"
  43 + android:layout_marginBottom="4dp"/>
  44 +
  45 + <TextView
  46 + android:layout_width="wrap_content"
  47 + android:layout_height="wrap_content"
  48 + android:id="@+id/personne_overview_role"
  49 + android:textAppearance="@android:style/TextAppearance.Material.Body1"
  50 + android:layout_marginStart="24dp"
  51 + android:layout_marginTop="4dp"
  52 + android:layout_marginBottom="4dp"/>
  53 +
  54 +
  55 +</LinearLayout>
... ...
app/src/main/res/values/strings.xml
... ... @@ -41,4 +41,7 @@
41 41 <string name="create_personne_carte">Carte ID</string>
42 42 <string name="create_personne_naissance">Birthday</string>
43 43 <string name="create_personne_role">Role</string>
  44 +
  45 + <!-- TODO: Remove or change this placeholder text -->
  46 + <string name="hello_blank_fragment">Hello blank fragment</string>
44 47 </resources>
... ...