From f90438ab370587bbb40137e5201ad4939cd1967e Mon Sep 17 00:00:00 2001 From: jacques Date: Sun, 3 May 2020 15:14:56 +0200 Subject: [PATCH] Add log facilities --- .../java/net/foucry/pilldroid/DBHelper.java | 4 ++++ .../pilldroid/MedicamentDetailActivity.java | 18 ++++++++++++++++++ .../pilldroid/MedicamentDetailFragment.java | 7 +++---- .../pilldroid/MedicamentListActivity.java | 2 +- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/DBHelper.java b/app/src/main/java/net/foucry/pilldroid/DBHelper.java index 1bf451f..94356ad 100644 --- a/app/src/main/java/net/foucry/pilldroid/DBHelper.java +++ b/app/src/main/java/net/foucry/pilldroid/DBHelper.java @@ -261,6 +261,9 @@ class DBHelper extends SQLiteOpenHelper { * @param medicament object to be updated in DB */ public void updateDrug(Medicament medicament) { + + Log.d(TAG, "Update Drug == " + medicament.toString()); + // Get reference to writable DB SQLiteDatabase db = this.getWritableDatabase(); @@ -279,6 +282,7 @@ class DBHelper extends SQLiteOpenHelper { KEY_ID+" = ?", // selections new String[] {String.valueOf(medicament.getId()) } ); // selections args + Log.d(TAG, "Return update = " + i); // Close DB db.close(); diff --git a/app/src/main/java/net/foucry/pilldroid/MedicamentDetailActivity.java b/app/src/main/java/net/foucry/pilldroid/MedicamentDetailActivity.java index 3e047d1..36d9b24 100644 --- a/app/src/main/java/net/foucry/pilldroid/MedicamentDetailActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/MedicamentDetailActivity.java @@ -5,11 +5,14 @@ import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.support.v7.widget.Toolbar; +import android.util.Log; import android.view.View; import android.support.v7.app.AppCompatActivity; import android.support.v7.app.ActionBar; import android.view.MenuItem; +import net.foucry.pilldroid.Medicament; + /** * An activity representing a single Medicament detail screen. This * activity is only used narrow width devices. On tablet-size devices, @@ -18,12 +21,23 @@ import android.view.MenuItem; */ public class MedicamentDetailActivity extends AppCompatActivity { + private static final String TAG = MedicamentDetailActivity.class.getName(); + + Medicament medicament; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + + Bundle extras = getIntent().getExtras(); + + /* fetching the string passed with intent using ‘extras’*/ + + medicament = (Medicament) extras.getSerializable("medicament"); + setContentView(R.layout.activity_medicament_detail); Toolbar toolbar = findViewById(R.id.detail_toolbar); + if (toolbar != null) { setSupportActionBar(toolbar); toolbar.setTitle(getTitle()); @@ -35,6 +49,10 @@ public class MedicamentDetailActivity extends AppCompatActivity { public void onClick(View view) { Snackbar.make(view, "Will be use to save changes in a drug", Snackbar.LENGTH_LONG) .setAction("Action", null).show(); + Log.d(TAG, "Click on save icone + medicament "); + + // TODO: récupérer les infos de la vue (cf onStop du Fragment) + setResult(1); finish(); diff --git a/app/src/main/java/net/foucry/pilldroid/MedicamentDetailFragment.java b/app/src/main/java/net/foucry/pilldroid/MedicamentDetailFragment.java index b8df391..0689909 100644 --- a/app/src/main/java/net/foucry/pilldroid/MedicamentDetailFragment.java +++ b/app/src/main/java/net/foucry/pilldroid/MedicamentDetailFragment.java @@ -26,7 +26,7 @@ public class MedicamentDetailFragment extends Fragment { * represents. */ public static final String ARG_ITEM_ID = "medicament"; - private static final String TAG = MedicamentListActivity.class.getName(); + private static final String TAG = MedicamentDetailFragment.class.getName(); /** * The dummy content this fragment is presenting. @@ -125,9 +125,6 @@ public class MedicamentDetailFragment extends Fragment { dbHelper = new DBHelper(context); View currentView = getView(); - // View nameView; - // View adminModeView; - // View presentationView; View stockView; View priseView; View warningView; @@ -161,6 +158,8 @@ public class MedicamentDetailFragment extends Fragment { medicament.setPrise(Double.parseDouble(priseValue)); medicament.setWarnThreshold(Integer.parseInt(warningValue)); medicament.setAlertThreshold(Integer.parseInt(alertValue)); + medicament.setDateLastUpdate(); + medicament.setDateEndOfStock(); dbHelper.updateDrug(medicament); super.onStop(); diff --git a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java b/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java index 3395e2c..2f039d5 100644 --- a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java @@ -232,7 +232,7 @@ public class MedicamentListActivity extends AppCompatActivity { public void newStockCalculation() { Medicament currentMedicament; - //DBHelper DBHelper dbHelper; + dbHelper = new DBHelper(this); for (int position = 0 ; position < this. getCount() ; position++ ) { currentMedicament = this.getItem(position);