dd839264
badetitou
All done
|
1
2
3
4
|
package net.plil.clubinfo.etunicorn.app;
import android.app.PendingIntent;
import android.content.Intent;
|
dd839264
badetitou
All done
|
5
|
import android.nfc.NfcAdapter;
|
c8a73f2c
badetitou
Adding Event frag...
|
6
|
import android.nfc.Tag;
|
d6367fe9
badetitou
Ajout liste
|
7
|
import android.os.Bundle;
|
0ecfc67f
badetitou
Modify Consommation
|
8
|
import android.support.design.widget.AppBarLayout;
|
dd839264
badetitou
All done
|
9
|
import android.support.design.widget.TabLayout;
|
dd839264
badetitou
All done
|
10
11
12
13
|
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
|
d6367fe9
badetitou
Ajout liste
|
14
15
|
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
|
dd839264
badetitou
All done
|
16
17
|
import android.view.Menu;
import android.view.MenuItem;
|
bed80725
badetitou
Correctif/PATCH
|
18
|
import android.widget.Toast;
|
dd839264
badetitou
All done
|
19
|
|
dd839264
badetitou
All done
|
20
|
import net.plil.clubinfo.etunicorn.R;
|
bed80725
badetitou
Correctif/PATCH
|
21
22
|
import net.plil.clubinfo.etunicorn.app.credit.Crediter;
import net.plil.clubinfo.etunicorn.app.debit.Debiter;
|
8bcd81b8
badetitou
some staff
|
23
24
|
import net.plil.clubinfo.etunicorn.app.event.EventFragment;
import net.plil.clubinfo.etunicorn.app.event.PaiementEvent;
|
299af019
badetitou
Add payment conso...
|
25
26
|
import net.plil.clubinfo.etunicorn.app.consommation.FragmentConsommation;
import net.plil.clubinfo.etunicorn.app.consommation.PaiementConsommation;
|
bed80725
badetitou
Correctif/PATCH
|
27
|
import net.plil.clubinfo.etunicorn.app.personne.PersonneFragment;
|
299af019
badetitou
Add payment conso...
|
28
|
import net.plil.clubinfo.etunicorn.data.Consommation;
|
c8a73f2c
badetitou
Adding Event frag...
|
29
|
import net.plil.clubinfo.etunicorn.data.Event;
|
bed80725
badetitou
Correctif/PATCH
|
30
|
import net.plil.clubinfo.etunicorn.data.Personne;
|
c8a73f2c
badetitou
Adding Event frag...
|
31
|
import net.plil.clubinfo.etunicorn.utils.ConvertBytesToString;
|
dd839264
badetitou
All done
|
32
|
|
0ecfc67f
badetitou
Modify Consommation
|
33
34
|
import java.util.ArrayList;
import java.util.List;
|
dd839264
badetitou
All done
|
35
|
|
0ecfc67f
badetitou
Modify Consommation
|
36
|
|
bed80725
badetitou
Correctif/PATCH
|
37
38
39
40
|
public class MainActivity extends AppCompatActivity
implements FragmentConsommation.OnListFragmentInteractionListener,
EventFragment.OnListFragmentInteractionListener,
PersonneFragment.OnListFragmentInteractionListener{
|
dd839264
badetitou
All done
|
41
42
43
44
45
46
47
48
49
50
51
|
/**
* The {@link android.support.v4.view.PagerAdapter} that will provide
* fragments for each of the sections. We use a
* {@link FragmentPagerAdapter} derivative, which will keep every
* loaded fragment in memory. If this becomes too memory intensive, it
* may be best to switch to a
* {@link android.support.v4.app.FragmentStatePagerAdapter}.
*/
private SectionsPagerAdapter mSectionsPagerAdapter;
|
bed80725
badetitou
Correctif/PATCH
|
52
53
|
private int nbPages = 0;
|
dd839264
badetitou
All done
|
54
55
56
57
|
/**
* The {@link ViewPager} that will host the section contents.
*/
private ViewPager mViewPager;
|
0ecfc67f
badetitou
Modify Consommation
|
58
59
|
private Toolbar toolbar;
private AppBarLayout appBarLayout;
|
dd839264
badetitou
All done
|
60
|
|
0ecfc67f
badetitou
Modify Consommation
|
61
|
private List<Consommation> consommationsToModify = new ArrayList<>();
|
dd839264
badetitou
All done
|
62
63
64
65
66
67
68
|
NfcAdapter mAdapter;
PendingIntent mPendingIntent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
|
bed80725
badetitou
Correctif/PATCH
|
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
// config tabbed pan
Intent intent = this.getIntent();
Personne p = (Personne) intent.getSerializableExtra("user");
Toast.makeText(getApplicationContext(), p.getRole().getPermissions().get(0).getNom(), Toast.LENGTH_LONG).show();
if (p.getRole().getPermissions().get(0).getNom().equals("ROLE_ADMIN")){
nbPages = 5;
Action.CONSOMATION.setValue(2);
Action.EVENT.setValue(3);
Action.PERSONNE.setValue(4);
} else if (p.getRole().getPermissions().get(0).getNom().equals("ROLE_BDE")){
nbPages = 4;
Action.CONSOMATION.setValue(-1);
Action.EVENT.setValue(2);
Action.PERSONNE.setValue(3);
} else if (p.getRole().getPermissions().get(0).getNom().equals("ROLE_BAR")){
nbPages = 3;
Action.CONSOMATION.setValue(2);
Action.EVENT.setValue(-1);
Action.PERSONNE.setValue(-1);
} else {
nbPages = 2;
}
// config other stuff
|
dd839264
badetitou
All done
|
94
95
|
setContentView(R.layout.activity_main);
|
0ecfc67f
badetitou
Modify Consommation
|
96
|
appBarLayout = (AppBarLayout) findViewById(R.id.appbar);
|
0ecfc67f
badetitou
Modify Consommation
|
97
|
toolbar = (Toolbar) findViewById(R.id.toolbar);
|
dd839264
badetitou
All done
|
98
|
setSupportActionBar(toolbar);
|
0ecfc67f
badetitou
Modify Consommation
|
99
|
|
dd839264
badetitou
All done
|
100
101
102
103
104
105
106
107
108
109
110
|
// Create the adapter that will return a fragment for each of the three
// primary sections of the activity.
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(mViewPager);
|
dd839264
badetitou
All done
|
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
mAdapter = NfcAdapter.getDefaultAdapter(this);
if (mAdapter == null) {
//nfc not support your device.
return;
}
mPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this,
getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
|
6790f988
badetitou
Find way to somet...
|
147
|
if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(intent.getAction())) {
|
c8a73f2c
badetitou
Adding Event frag...
|
148
|
Tag myTag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
|
6790f988
badetitou
Find way to somet...
|
149
|
FragmentNFC fNFC = (FragmentNFC) getSupportFragmentManager().getFragments().get(mViewPager.getCurrentItem());
|
c8a73f2c
badetitou
Adding Event frag...
|
150
|
fNFC.processNFC(ConvertBytesToString.bytesToHexString(myTag.getId()));
|
6790f988
badetitou
Find way to somet...
|
151
|
}
|
dd839264
badetitou
All done
|
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
}
@Override
public void onResume(){
super.onResume();
mAdapter.enableForegroundDispatch(this, mPendingIntent, null, null);
}
@Override
public void onPause(){
super.onPause();
if (mAdapter != null) {
mAdapter.disableForegroundDispatch(this);
}
}
|
d6367fe9
badetitou
Ajout liste
|
168
|
|
299af019
badetitou
Add payment conso...
|
169
170
171
172
|
@Override
public void onListFragmentInteraction(Consommation item) {
PaiementConsommation paiementConsommation = PaiementConsommation.newInstance(item);
paiementConsommation.show(getSupportFragmentManager(), "paiementConsommation");
|
d6367fe9
badetitou
Ajout liste
|
173
174
|
}
|
0ecfc67f
badetitou
Modify Consommation
|
175
|
@Override
|
c8a73f2c
badetitou
Adding Event frag...
|
176
177
178
179
180
181
182
183
184
185
186
187
|
public void onListFragmentInteractionLong(Consommation consommation) {
}
@Override
public void onListFragmentInteraction(Event item) {
PaiementEvent paiementEvent = PaiementEvent.newInstance(item);
paiementEvent.show(getSupportFragmentManager(), "paiementEvent");
}
@Override
public void onListFragmentInteractionLong(Event item) {
|
0ecfc67f
badetitou
Modify Consommation
|
188
189
190
|
}
|
bed80725
badetitou
Correctif/PATCH
|
191
192
193
194
195
196
197
198
199
200
|
@Override
public void onListFragmentInteraction(Personne personne) {
}
@Override
public void onListFragmentInteractionLong(Personne personne) {
}
|
dd839264
badetitou
All done
|
201
202
203
204
205
206
207
208
209
210
211
212
|
/**
* A {@link FragmentPagerAdapter} that returns a fragment corresponding to
* one of the sections/tabs/pages.
*/
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
|
6790f988
badetitou
Find way to somet...
|
213
214
215
216
|
if (position == Action.CREDITER.getValue())
return Crediter.newInstance();
else if (position == Action.DEBITER.getValue())
return Debiter.newInstance();
|
d6367fe9
badetitou
Ajout liste
|
217
|
else if (position == Action.CONSOMATION.getValue())
|
299af019
badetitou
Add payment conso...
|
218
|
return FragmentConsommation.newInstance();
|
c8a73f2c
badetitou
Adding Event frag...
|
219
220
|
else if (position == Action.EVENT.getValue())
return EventFragment.newInstance();
|
bed80725
badetitou
Correctif/PATCH
|
221
222
|
else if (position == Action.PERSONNE.getValue())
return PersonneFragment.newInstance();
|
6790f988
badetitou
Find way to somet...
|
223
224
|
else
return null;
|
dd839264
badetitou
All done
|
225
226
227
228
|
}
@Override
public int getCount() {
|
bed80725
badetitou
Correctif/PATCH
|
229
|
return nbPages;
|
dd839264
badetitou
All done
|
230
231
232
233
234
235
236
237
|
}
@Override
public CharSequence getPageTitle(int position) {
if(position == Action.DEBITER.getValue())
return "Debiter";
else if (position == Action.CREDITER.getValue())
return "Crediter";
|
d6367fe9
badetitou
Ajout liste
|
238
|
else if (position == Action.CONSOMATION.getValue())
|
299af019
badetitou
Add payment conso...
|
239
|
return "Consommation";
|
c8a73f2c
badetitou
Adding Event frag...
|
240
241
|
else if(position == Action.EVENT.getValue())
return getString(R.string.event);
|
bed80725
badetitou
Correctif/PATCH
|
242
243
|
else if(position == Action.PERSONNE.getValue())
return getString(R.string.personne);
|
dd839264
badetitou
All done
|
244
245
246
247
248
|
return null;
}
}
private enum Action {
|
bed80725
badetitou
Correctif/PATCH
|
249
|
DEBITER(0), CREDITER(1), CONSOMATION(2), EVENT(3), PERSONNE(4);
|
dd839264
badetitou
All done
|
250
|
|
bed80725
badetitou
Correctif/PATCH
|
251
|
private int value;
|
dd839264
badetitou
All done
|
252
253
254
255
256
257
258
|
Action(int value) {
this.value = value;
}
public int getValue() {
return value;
}
|
bed80725
badetitou
Correctif/PATCH
|
259
260
261
262
|
public void setValue(int value) {
this.value = value;
}
|
dd839264
badetitou
All done
|
263
264
|
}
}
|