From 451b80f64b458a818bf6781221145c50089c8907 Mon Sep 17 00:00:00 2001 From: Jacques Foucry Date: Sun, 19 Jun 2016 18:41:46 +0200 Subject: [PATCH 1/4] =?UTF-8?q?Ajout=20message=20dialogue=20ajout=20de=20m?= =?UTF-8?q?=C3=A9dicament?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/res/values/strings.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d0c5ac7..f38692b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -126,6 +126,7 @@ Google Book Search Requesting connection to network\u2026 Médicament introuvable dans la base de données + trouvé dans la base de données À propos Aide From d394f938213a94b6ddfb2d23804997ff2ee9fad1 Mon Sep 17 00:00:00 2001 From: Jacques Foucry Date: Sun, 19 Jun 2016 18:42:27 +0200 Subject: [PATCH 2/4] =?UTF-8?q?Demande=20ajout=20du=20m=C3=A9dicament=20ap?= =?UTF-8?q?r=C3=A8es=20scan?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pilldroid/MedicamentListActivity.java | 56 ++++++++++--------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java b/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java index 3da720e..8668f4a 100644 --- a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java @@ -59,6 +59,8 @@ public class MedicamentListActivity extends AppCompatActivity { private SimpleCursorAdapter drugAdapter; private List medicaments; + private View mRecyclerView; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -74,20 +76,6 @@ public class MedicamentListActivity extends AppCompatActivity { toolbar.setTitle(getTitle()); } - /*FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); - fab.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - *//* Snackbar.make(view, "Will be used to add a drug to the list", Snackbar.LENGTH_LONG) - .setAction("Action", null).show(); *//* - Intent intent = new Intent("com.google.zxing.client.android.SCAN"); - intent.putExtra("SCAN_MODE", "CODE_128"); - //intent.putExtra("SCAN_FORMATS", "EAN_13,DATA_MATRIX"); - startActivityForResult(intent, 0); - } - });*/ - - if (DEMO) { if (dbHelper.getCount() == 0) { @@ -137,9 +125,10 @@ public class MedicamentListActivity extends AppCompatActivity { } }); } - View recyclerView = findViewById(R.id.medicament_list); - assert recyclerView != null; - setupRecyclerView((RecyclerView) recyclerView); + + mRecyclerView = findViewById(R.id.medicament_list); + assert mRecyclerView != null; + setupRecyclerView((RecyclerView) mRecyclerView); if (findViewById(R.id.medicament_detail_container) != null) { // The detail container view will be present only in the @@ -186,24 +175,39 @@ public class MedicamentListActivity extends AppCompatActivity { Log.i(Constants.TAG, "Format:" + format); Log.i(Constants.TAG, "Content:" + contents); + AlertDialog.Builder dlg = new AlertDialog.Builder(this); + dlg.setTitle(context.getString(R.string.app_name)); + // Handle successful scan if (format.equals("CODE_128")) { //CODE_128 cip13 = contents; - } else - { - cip13 = contents.substring(4,17); + } else { + cip13 = contents.substring(4, 17); } dbMedoc.openDatabase(); - Medicament scannedMedoc = dbMedoc.getMedocByCIP13(cip13); + final Medicament scannedMedoc = dbMedoc.getMedocByCIP13(cip13); dbMedoc.close(); if (scannedMedoc != null) { - Toast.makeText(context, "Medicament found in database", Toast.LENGTH_LONG).show(); - } else - { - AlertDialog.Builder dlg = new AlertDialog.Builder(this); - dlg.setTitle(context.getString(R.string.app_name)); + String msg = scannedMedoc.getNom() + " " + getString(R.string.msgFound); + + dlg.setMessage(msg); + dlg.setNegativeButton(context.getString(R.string.button_cancel), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + // Nothing to do in case of cancel + } + }); + dlg.setPositiveButton(context.getString(R.string.button_ok), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + // Add Medicament to DB then try to show it + dbHelper.addDrug(scannedMedoc); + } + }); + dlg.show(); + } else { dlg.setMessage(context.getString(R.string.msgNotFound)); dlg.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override From 1db5b70667e114c6b6133117d566caa7e1ee6799 Mon Sep 17 00:00:00 2001 From: Jacques Foucry Date: Sun, 19 Jun 2016 18:42:57 +0200 Subject: [PATCH 3/4] =?UTF-8?q?Mise=20=C3=A0=20jour=20du=20graddle=20app/b?= =?UTF-8?q?uild.gradle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/app/build.gradle b/app/build.gradle index c258254..156466e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -33,4 +33,5 @@ dependencies { compile 'com.android.support:support-v4:23.3.0' compile 'com.android.support:recyclerview-v7:23.3.0' compile 'com.android.support:design:23.3.0' + compile 'com.google.android.gms:play-services-appindexing:8.1.0' } From 4b6ec80c52237e3f62dc03328c483efd1da48801 Mon Sep 17 00:00:00 2001 From: Jacques Foucry Date: Mon, 20 Jun 2016 23:03:24 +0200 Subject: [PATCH 4/4] =?UTF-8?q?Notification=20d'ajout=20d'un=20m=C3=A9dica?= =?UTF-8?q?ment=20=C3=A0=20la=20liste?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../foucry/pilldroid/MedicamentListActivity.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java b/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java index 8668f4a..37e3637 100644 --- a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java @@ -60,6 +60,7 @@ public class MedicamentListActivity extends AppCompatActivity { private List medicaments; private View mRecyclerView; + private SimpleItemRecyclerViewAdapter mAdapter; @Override protected void onCreate(Bundle savedInstanceState) { @@ -203,7 +204,9 @@ public class MedicamentListActivity extends AppCompatActivity { @Override public void onClick(DialogInterface dialog, int which) { // Add Medicament to DB then try to show it + scannedMedoc.setDateEndOfStock(); dbHelper.addDrug(scannedMedoc); + mAdapter.addItem(medicaments.size()-1,scannedMedoc); } }); dlg.show(); @@ -226,9 +229,13 @@ public class MedicamentListActivity extends AppCompatActivity { private void setupRecyclerView(@NonNull RecyclerView recyclerView) { recyclerView.addItemDecoration(new SimpleDividerItemDecoration(getApplicationContext())); - recyclerView.setAdapter(new SimpleItemRecyclerViewAdapter(medicaments)); + mAdapter = (SimpleItemRecyclerViewAdapter) new SimpleItemRecyclerViewAdapter(medicaments); + recyclerView.setAdapter(mAdapter); } + /** + * SimpleItemRecyclerViewAdapter + */ public class SimpleItemRecyclerViewAdapter extends RecyclerView.Adapter { @@ -238,6 +245,12 @@ public class MedicamentListActivity extends AppCompatActivity { mValues = items; } + public void addItem(int position, Medicament scannedMedoc) { + mValues.add(scannedMedoc); + notifyDataSetChanged(); + dbHelper.addDrug(scannedMedoc); + } + @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = LayoutInflater.from(parent.getContext())