From 8257f5477a3273b5c506568d337e5a229582f502 Mon Sep 17 00:00:00 2001 From: jacques Date: Sat, 12 Mar 2022 21:32:57 +0100 Subject: [PATCH] Use Medic instead of Drug --- .../foucry/pilldroid/DrugDetailActivity.java | 20 ++++------ .../foucry/pilldroid/DrugDetailFragment.java | 39 +++++++++++-------- 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java b/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java index bf6e138..bafe995 100644 --- a/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java @@ -13,6 +13,7 @@ import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; +import java.io.Serializable; import java.util.Date; import static net.foucry.pilldroid.R.id.detail_toolbar; @@ -37,17 +38,10 @@ public class DrugDetailActivity extends AppCompatActivity { super.onCreate(savedInstanceState); Bundle bundle = getIntent().getExtras(); - - /* fetching the string passed with intent using ‘extras’*/ - assert bundle != null; - aMedic = (Medic) bundle.getSerializable("medic"); - - assert aMedic != null; + aMedic = (Medic) bundle.get("medic"); Log.d(TAG, "aMedic == " + aMedic); - /* fetching the string passed with intent using ‘bundle’*/ - setContentView(R.layout.activity_drug_detail); Toolbar toolbar = findViewById(detail_toolbar); @@ -87,9 +81,11 @@ public class DrugDetailActivity extends AppCompatActivity { if (savedInstanceState == null) { // Create the detail fragment and add it to the activity // using a fragment transaction. + /*Bundle arguments = new Bundle(); + arguments.putSerializable("medic", + getIntent().getExtras());*/ Bundle arguments = new Bundle(); - arguments.putSerializable("drug", - getIntent().getSerializableExtra("drug")); + arguments.putSerializable("medic", aMedic); DrugDetailFragment fragment = new DrugDetailFragment(); fragment.setArguments(arguments); getSupportFragmentManager().beginTransaction() @@ -145,8 +141,8 @@ public class DrugDetailActivity extends AppCompatActivity { TextView warningTextView = warningView.findViewById(R.id.value); String warningValue = warningTextView.getText().toString(); - newMedic.setStock(Double.parseDouble(stockValue)); - newMedic.setTake(Double.parseDouble(takeValue)); + newMedic.setStock(Float.parseFloat(stockValue)); + newMedic.setTake(Float.parseFloat(takeValue)); newMedic.setWarning(Integer.parseInt(warningValue)); newMedic.setAlert(Integer.parseInt(alertValue)); newMedic.getDateEndOfStock(); diff --git a/app/src/main/java/net/foucry/pilldroid/DrugDetailFragment.java b/app/src/main/java/net/foucry/pilldroid/DrugDetailFragment.java index 04a74e1..52169da 100644 --- a/app/src/main/java/net/foucry/pilldroid/DrugDetailFragment.java +++ b/app/src/main/java/net/foucry/pilldroid/DrugDetailFragment.java @@ -11,6 +11,8 @@ import androidx.fragment.app.Fragment; import com.google.android.material.appbar.CollapsingToolbarLayout; +import net.foucry.pilldroid.models.Medic; + /** * A fragment representing a single Drug detail screen. * This fragment is either contained in a {@link DrugListActivity} @@ -23,12 +25,12 @@ public class DrugDetailFragment extends Fragment { * The fragment argument representing the item ID that this fragment * represents. */ - public static final String ARG_ITEM_ID = "drug"; + public static final String ARG_ITEM_ID = "medic"; /** * The dummy content this fragment is presenting. */ - private Drug drug; + private Medic medic; /** * Mandatory empty constructor for the fragment manager to instantiate the @@ -46,13 +48,13 @@ public class DrugDetailFragment extends Fragment { // Load the dummy content specified by the fragment // arguments. In a real-world scenario, use a Loader // to load content from a content provider. - drug = (Drug) getArguments().getSerializable(ARG_ITEM_ID); + medic = (Medic) getArguments().getSerializable(ARG_ITEM_ID); Activity activity = this.getActivity(); assert activity != null; CollapsingToolbarLayout appBarLayout = activity.findViewById(R.id.toolbar_layout); if (appBarLayout != null) { - appBarLayout.setTitle(drug.getName()); + appBarLayout.setTitle(medic.getName()); } } } @@ -69,47 +71,49 @@ public class DrugDetailFragment extends Fragment { View alertView; // Show the dummy content as text in a TextView. - if (drug != null) { + if (medic != null) { // Find each component of rootView nameView = detailView.findViewById(R.id.name_cell); TextView nameLabel = nameView.findViewById(R.id.label); TextView nameValue = nameView.findViewById(R.id.value); nameLabel.setText(R.string.drug_name_label); - nameValue.setText(drug.getName()); + nameValue.setText(medic.getName()); presentationView = detailView.findViewById(R.id.presentation_cell); TextView presentationLabel = presentationView.findViewById(R.id.label); TextView presentationValue = presentationView.findViewById(R.id.value); presentationLabel.setText(R.string.drug_presentation_label); - presentationValue.setText(drug.getPresentation()); + presentationValue.setText(medic.getPresentation()); adminModeView = detailView.findViewById(R.id.administration_cell); TextView adminModeLabel = adminModeView.findViewById(R.id.label); TextView adminModeValue = adminModeView.findViewById(R.id.value); adminModeLabel.setText(R.string.drug_administrationMode_label); - adminModeValue.setText(drug.getAdministration_mode()); + adminModeValue.setText(medic.getAdministration_mode()); stockView = detailView.findViewById(R.id.stock_cell); TextView stockLibelle = (stockView.findViewById(R.id.label)); TextView stockValue = stockView.findViewById(R.id.value); stockLibelle.setText(R.string.drug_current_stock_label); - stockValue.setText(Double.toString(drug.getStock())); + stockValue.setText(Utils.fmt(medic.getStock())); stockValue.setHint(R.string.drug_current_stock_label); stockValue.setSelectAllOnFocus(true); takeView = detailView.findViewById(R.id.take_cell); - TextView priseLabel = takeView.findViewById(R.id.label); - TextView priseValue = (takeView.findViewById(R.id.value)); - priseLabel.setText(R.string.drug_take_label); - priseValue.setText(Double.toString(drug.getTake())); - priseValue.setHint(R.string.drug_take_label); - priseValue.setSelectAllOnFocus(true); + TextView takeLabel = takeView.findViewById(R.id.label); + TextView takeValue = (takeView.findViewById(R.id.value)); + takeLabel.setText(R.string.drug_take_label); + //takeValue.setText(Double.toString(medic.getTake())); + takeValue.setText(Utils.fmt(medic.getTake())); + takeValue.setHint(R.string.drug_take_label); + takeValue.setSelectAllOnFocus(true); warningView = detailView.findViewById(R.id.warning_cell); TextView warningLibelle = warningView.findViewById(R.id.label); TextView warningValue = warningView.findViewById(R.id.value); warningLibelle.setText(R.string.drug_warningThreshold_label); - warningValue.setText(Integer.toString(drug.getWarnThreshold())); + //warningValue.setText(Integer.toString(medic.getWarnThreshold())); + warningValue.setText(Utils.fmt(medic.getWarning())); warningValue.setHint(R.string.drug_warningThreshold_label); warningValue.setSelectAllOnFocus(true); @@ -117,7 +121,8 @@ public class DrugDetailFragment extends Fragment { TextView alertLibelle = alertView.findViewById(R.id.label); TextView alertValue = alertView.findViewById(R.id.value); alertLibelle.setText(R.string.drug_alertThreshold_label); - alertValue.setText(Integer.toString(drug.getAlertThreshold())); + //alertValue.setText(Integer.toString(medic.getAlertThreshold())); + alertValue.setText(Utils.fmt(medic.getAlert())); alertValue.setHint(R.string.drug_alertThreshold_label); alertValue.setSelectAllOnFocus(true); }