diff --git a/app/src/main/java/net/foucry/pilldroid/MedicamentDetailActivity.java b/app/src/main/java/net/foucry/pilldroid/MedicamentDetailActivity.java index d556206..773be84 100644 --- a/app/src/main/java/net/foucry/pilldroid/MedicamentDetailActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/MedicamentDetailActivity.java @@ -22,21 +22,21 @@ public class MedicamentDetailActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_medicament_detail); - Toolbar toolbar = (Toolbar) findViewById(R.id.detail_toolbar); + Toolbar toolbar = findViewById(R.id.detail_toolbar); if (toolbar != null) { setSupportActionBar(toolbar); toolbar.setTitle(getTitle()); } - FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); + FloatingActionButton fab = findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view, "Will be use to save changes in a drug", Snackbar.LENGTH_LONG) .setAction("Action", null).show(); setResult(1); - return; + finish(); } }); diff --git a/app/src/main/java/net/foucry/pilldroid/MedicamentDetailFragment.java b/app/src/main/java/net/foucry/pilldroid/MedicamentDetailFragment.java index f84ce2d..ac7caa3 100644 --- a/app/src/main/java/net/foucry/pilldroid/MedicamentDetailFragment.java +++ b/app/src/main/java/net/foucry/pilldroid/MedicamentDetailFragment.java @@ -1,6 +1,7 @@ package net.foucry.pilldroid; import android.app.Activity; +import android.content.Context; import android.support.design.widget.CollapsingToolbarLayout; import android.os.Bundle; import android.support.v4.app.Fragment; @@ -8,6 +9,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; +import android.widget.Toast; /** * A fragment representing a single Medicament detail screen. @@ -68,32 +70,32 @@ public class MedicamentDetailFragment extends Fragment { if (medicament != null) { // Find each conponment of rootView nameView = detailView.findViewById(R.id.name_cell); - TextView nameLabel = (TextView) nameView.findViewById(R.id.label); - TextView nameValeur = (TextView) nameView.findViewById(R.id.valeur); + TextView nameLabel = nameView.findViewById(R.id.label); + TextView nameValeur = nameView.findViewById(R.id.valeur); nameLabel.setText("Nom"); nameValeur.setText(medicament.getNom()); presentationView = detailView.findViewById(R.id.presentation_cell); - TextView presentationLabel = (TextView) presentationView.findViewById(R.id.label); - TextView presentationValeur = (TextView) presentationView.findViewById(R.id.valeur); + TextView presentationLabel = presentationView.findViewById(R.id.label); + TextView presentationValeur = presentationView.findViewById(R.id.valeur); presentationLabel.setText("Presentation"); presentationValeur.setText(medicament.getPresentation()); adminModeView = detailView.findViewById(R.id.administration_cell); - TextView adminModeLabel = (TextView) adminModeView.findViewById(R.id.label); - TextView adminModeValeur = (TextView) adminModeView.findViewById(R.id.valeur); + TextView adminModeLabel = adminModeView.findViewById(R.id.label); + TextView adminModeValeur = adminModeView.findViewById(R.id.valeur); adminModeLabel.setText("Mode d'administration"); adminModeValeur.setText(medicament.getMode_administration()); stockView = detailView.findViewById(R.id.stock_cell); - TextView stockLibelle = (TextView) stockView.findViewById(R.id.libelle); - TextView stockValue = (TextView) stockView.findViewById(R.id.valeur); + TextView stockLibelle = (stockView.findViewById(R.id.libelle)); + TextView stockValue = stockView.findViewById(R.id.valeur); stockLibelle.setText("Stock courant"); stockValue.setText(Double.toString(medicament.getStock())); priseView = detailView.findViewById(R.id.prise_cell); - TextView priseLibelle = (TextView) priseView.findViewById(R.id.libelle); - TextView priseValue = (TextView) priseView.findViewById(R.id.valeur); + TextView priseLibelle = priseView.findViewById(R.id.libelle); + TextView priseValue = (priseView.findViewById(R.id.valeur)); priseLibelle.setText("Prise"); priseValue.setText(Double.toString(medicament.getPrise())); @@ -104,12 +106,19 @@ public class MedicamentDetailFragment extends Fragment { warningValue.setText(Integer.toString(medicament.getWarnThreshold())); alertView = detailView.findViewById(R.id.alert_cell); - TextView alertLibelle = (TextView) alertView.findViewById(R.id.libelle); - TextView alertValue = (TextView) alertView.findViewById(R.id.valeur); + TextView alertLibelle = alertView.findViewById(R.id.libelle); + TextView alertValue = alertView.findViewById(R.id.valeur); alertLibelle.setText("Seuil critique"); alertValue.setText(Integer.toString(medicament.getAlertThreshold())); } return detailView; } + @Override + public void onStop() + { + Context context = getContext(); + Toast.makeText(context, "***PROUT***", Toast.LENGTH_SHORT).show(); + 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 1391198..7643d23 100644 --- a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java @@ -10,7 +10,6 @@ import android.content.Intent; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.graphics.BitmapFactory; -import android.net.Uri; import android.os.Bundle; import android.os.SystemClock; import android.support.annotation.NonNull; @@ -107,7 +106,7 @@ public class MedicamentListActivity extends AppCompatActivity { dbHelper = new DBHelper(this); dbMedoc = new DBMedoc(this); - Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + Toolbar toolbar = findViewById(R.id.toolbar); if (toolbar != null) { setSupportActionBar(toolbar); @@ -319,10 +318,11 @@ public class MedicamentListActivity extends AppCompatActivity { // Handle cancel Toast.makeText(context, "Scan annulé", Toast.LENGTH_LONG).show(); } - else { - Toast.makeText(context, "back from detail", Toast.LENGTH_SHORT).show(); - } - } // TODO : Si requestCode=1 -> Sauvegarde du medoc dans la base et raffraichissement de la base. + } + else if (requestCode == 1) { + // TODO : Si requestCode=1 -> Sauvegarde du medoc dans la base et raffraichissement de la base. + Toast.makeText(context, "back from detail == "+requestCode, Toast.LENGTH_SHORT).show(); + } } private void setupRecyclerView(@NonNull RecyclerView recyclerView) { @@ -442,8 +442,8 @@ public class MedicamentListActivity extends AppCompatActivity { Context context = v.getContext(); Intent intent = new Intent(context, MedicamentDetailActivity.class); intent.putExtra("medicament", medicamentCourant); - - context.startActivity(intent); + int requestCode = 1; + startActivityForResult(intent, requestCode); } } }); @@ -466,10 +466,10 @@ public class MedicamentListActivity extends AppCompatActivity { ViewHolder(View view) { super(view); mView = view; - mIDView = (TextView) view.findViewById(R.id.cip13); - mContentView = (TextView) view.findViewById(R.id.valeur); - mEndOfStock = (TextView) view.findViewById(R.id.endOfStock); - mIconView = (ImageView) view.findViewById(R.id.list_image); + mIDView = view.findViewById(R.id.cip13); + mContentView = view.findViewById(R.id.valeur); + mEndOfStock = view.findViewById(R.id.endOfStock); + mIconView = view.findViewById(R.id.list_image); } @Override