mirror of
https://github.com/jfoucry/Pilldroid.git
synced 2024-11-22 04:29:22 +01:00
Utilisation de la base de méciament
This commit is contained in:
parent
55d3e8b903
commit
19a9850f37
1 changed files with 51 additions and 5 deletions
|
@ -19,7 +19,11 @@ import android.widget.TextView;
|
||||||
|
|
||||||
import net.foucry.pilldroid.Medicament;
|
import net.foucry.pilldroid.Medicament;
|
||||||
import net.foucry.pilldroid.dummy.DummyContent;
|
import net.foucry.pilldroid.dummy.DummyContent;
|
||||||
|
import static net.foucry.pilldroid.UtilDate.*;
|
||||||
|
import static net.foucry.pilldroid.Utils.*;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
@ -47,6 +51,7 @@ public class MedicamentListActivity extends AppCompatActivity {
|
||||||
|
|
||||||
private static DBHelper dbHelper;
|
private static DBHelper dbHelper;
|
||||||
private SimpleCursorAdapter drugAdapter;
|
private SimpleCursorAdapter drugAdapter;
|
||||||
|
private List<Medicament> medicaments;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -68,6 +73,47 @@ public class MedicamentListActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
if (DEMO) {
|
||||||
|
if (dbHelper.getCount() == 0) {
|
||||||
|
|
||||||
|
// String cis, String cip13, String nom, String mode_administration,
|
||||||
|
// String presentation,double stock, double prise, int warn, int alert
|
||||||
|
|
||||||
|
dbHelper.addDrug(new Medicament("60000011", "3400930000011", "Médicament test 01", "orale",
|
||||||
|
"plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)",
|
||||||
|
doubleRandomInclusive(0, 100), doubleRandomInclusive(0, 10), 14, 7));
|
||||||
|
dbHelper.addDrug(new Medicament("60000012", "3400930000012", "Médicament test 02", "orale",
|
||||||
|
"plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)",
|
||||||
|
doubleRandomInclusive(0, 100), doubleRandomInclusive(0, 10), 14, 7));
|
||||||
|
dbHelper.addDrug(new Medicament("60000013", "3400930000013", "Médicament test 03", "orale",
|
||||||
|
"plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)",
|
||||||
|
doubleRandomInclusive(0, 100), doubleRandomInclusive(0, 10), 14, 7));
|
||||||
|
dbHelper.addDrug(new Medicament("60000014", "3400930000014", "Médicament test 04", "orale",
|
||||||
|
"plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)",
|
||||||
|
doubleRandomInclusive(0, 100), doubleRandomInclusive(0, 10), 14, 7));
|
||||||
|
dbHelper.addDrug(new Medicament("60000015", "3400930000015", "Médicament test 05", "orale",
|
||||||
|
"plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)",
|
||||||
|
doubleRandomInclusive(0, 100), doubleRandomInclusive(0, 10), 14, 7));
|
||||||
|
dbHelper.addDrug(new Medicament("60000016", "3400930000016", "Médicament test 06", "orale",
|
||||||
|
"plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)",
|
||||||
|
doubleRandomInclusive(0, 100), doubleRandomInclusive(0, 10), 14, 7));
|
||||||
|
dbHelper.addDrug(new Medicament("60000017", "3400930000017", "Médicament test 07", "orale",
|
||||||
|
"plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)",
|
||||||
|
doubleRandomInclusive(0, 100), doubleRandomInclusive(0, 10), 14, 7));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.medicaments == null) {
|
||||||
|
this.medicaments = dbHelper.getAllDrugs();
|
||||||
|
|
||||||
|
Collections.sort(this.medicaments, new Comparator<Medicament>() {
|
||||||
|
@Override
|
||||||
|
public int compare(Medicament lhs, Medicament rhs) {
|
||||||
|
return lhs.getDateEndOfStock().compareTo(rhs.getDateEndOfStock());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
View recyclerView = findViewById(R.id.medicament_list);
|
View recyclerView = findViewById(R.id.medicament_list);
|
||||||
assert recyclerView != null;
|
assert recyclerView != null;
|
||||||
setupRecyclerView((RecyclerView) recyclerView);
|
setupRecyclerView((RecyclerView) recyclerView);
|
||||||
|
@ -82,15 +128,15 @@ public class MedicamentListActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupRecyclerView(@NonNull RecyclerView recyclerView) {
|
private void setupRecyclerView(@NonNull RecyclerView recyclerView) {
|
||||||
recyclerView.setAdapter(new SimpleItemRecyclerViewAdapter(DummyContent.ITEMS));
|
recyclerView.setAdapter(new SimpleItemRecyclerViewAdapter(medicaments));
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SimpleItemRecyclerViewAdapter
|
public class SimpleItemRecyclerViewAdapter
|
||||||
extends RecyclerView.Adapter<SimpleItemRecyclerViewAdapter.ViewHolder> {
|
extends RecyclerView.Adapter<SimpleItemRecyclerViewAdapter.ViewHolder> {
|
||||||
|
|
||||||
private final List<DummyContent.DummyItem> mValues;
|
private final List<Medicament> mValues;
|
||||||
|
|
||||||
public SimpleItemRecyclerViewAdapter(List<DummyContent.DummyItem> items) {
|
public SimpleItemRecyclerViewAdapter(List<Medicament> items) {
|
||||||
mValues = items;
|
mValues = items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,8 +150,8 @@ public class MedicamentListActivity extends AppCompatActivity {
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(final ViewHolder holder, int position) {
|
public void onBindViewHolder(final ViewHolder holder, int position) {
|
||||||
holder.mItem = mValues.get(position);
|
holder.mItem = mValues.get(position);
|
||||||
holder.mIDView.setText(mValues.get(position).id);
|
holder.mIDView.setText(mValues.get(position).getCip13());
|
||||||
holder.mContentView.setText(mValues.get(position).content);
|
holder.mContentView.setText(mValues.get(position).getNom());
|
||||||
|
|
||||||
holder.mView.setOnClickListener(new View.OnClickListener() {
|
holder.mView.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue