GestionActivity.java
3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package com.example.martin.projetv5;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;
import java.util.ArrayList;
/**
* Created by martin on 28/02/2017.
*/
public class GestionActivity extends AppCompatActivity implements MedocAdapterMenu.MedocAdapterListener {
ArrayList<Medicament> listMedocs = new ArrayList<>();
MedocAdapterMenu adapter = null;
ListView list = null;
StringBDD eventBDD = null;
void addElementList(Medicament m, ArrayList<Medicament> listM){
listM.add(m);
adapter.notifyDataSetChanged();
}
void supList(ArrayList<Medicament> listM){
listM.clear();
adapter.notifyDataSetChanged();
}
public void onClickAjoutMedoc(View view){
Intent i = new Intent(this, AjoutMedocActivity.class);
startActivity(i);
}
public void gestionList(){
boolean present = false;
for(int w=0; w<eventBDD.getIndiceMaxMedoc(); w++){
boolean ok = false;
Medicament m = eventBDD.getMedocWithId(w+1);
int x=1;
while(x <= eventBDD.getIndiceMaxPrise() && !ok){
Prise2 p = eventBDD.getPriseWithId(x);
if (p != null) {
if (p.getIdMedoc().equals(m.getIdM())) {
ok = true;
present = true;
}
}
x++;
}
if(ok) addElementList(m,listMedocs);
}
if(!present){
TextView textView = (TextView) findViewById(R.id.aucunMedoc);
textView.setText(R.string.gestion2);
}
else{
TextView textView = (TextView) findViewById(R.id.aucunMedoc);
textView.setText("");
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gestion_layout);
eventBDD = new StringBDD(this);
eventBDD.open();
}
@Override
protected void onResume() {
eventBDD.open();
super.onResume();
adapter = new MedocAdapterMenu(this,listMedocs);
adapter.addListener(this);
list = (ListView)findViewById(R.id.listMedoc);
list.setAdapter(adapter);
gestionList();
}
@Override
protected void onPause() {
super.onPause();
eventBDD.close();
adapter = new MedocAdapterMenu(this,listMedocs);
adapter.addListener(this);
list = (ListView)findViewById(R.id.listMedoc);
list.setAdapter(adapter);
supList(listMedocs);
}
@Override
public void onClickButton(Medicament item, int position) {
Intent i = new Intent(this, ModifMedocActivity.class);
i.putExtra("id",item.getIdM());
startActivity(i);
}
}