Use Medic instead of Drug

This commit is contained in:
jacques 2022-03-12 21:32:57 +01:00
parent 426092bbad
commit 8257f5477a
2 changed files with 30 additions and 29 deletions

View file

@ -13,6 +13,7 @@ import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import java.io.Serializable;
import java.util.Date; import java.util.Date;
import static net.foucry.pilldroid.R.id.detail_toolbar; import static net.foucry.pilldroid.R.id.detail_toolbar;
@ -37,17 +38,10 @@ public class DrugDetailActivity extends AppCompatActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
Bundle bundle = getIntent().getExtras(); Bundle bundle = getIntent().getExtras();
/* fetching the string passed with intent using extras*/
assert bundle != null; assert bundle != null;
aMedic = (Medic) bundle.getSerializable("medic"); aMedic = (Medic) bundle.get("medic");
assert aMedic != null;
Log.d(TAG, "aMedic == " + aMedic); Log.d(TAG, "aMedic == " + aMedic);
/* fetching the string passed with intent using bundle*/
setContentView(R.layout.activity_drug_detail); setContentView(R.layout.activity_drug_detail);
Toolbar toolbar = findViewById(detail_toolbar); Toolbar toolbar = findViewById(detail_toolbar);
@ -87,9 +81,11 @@ public class DrugDetailActivity extends AppCompatActivity {
if (savedInstanceState == null) { if (savedInstanceState == null) {
// Create the detail fragment and add it to the activity // Create the detail fragment and add it to the activity
// using a fragment transaction. // using a fragment transaction.
/*Bundle arguments = new Bundle();
arguments.putSerializable("medic",
getIntent().getExtras());*/
Bundle arguments = new Bundle(); Bundle arguments = new Bundle();
arguments.putSerializable("drug", arguments.putSerializable("medic", aMedic);
getIntent().getSerializableExtra("drug"));
DrugDetailFragment fragment = new DrugDetailFragment(); DrugDetailFragment fragment = new DrugDetailFragment();
fragment.setArguments(arguments); fragment.setArguments(arguments);
getSupportFragmentManager().beginTransaction() getSupportFragmentManager().beginTransaction()
@ -145,8 +141,8 @@ public class DrugDetailActivity extends AppCompatActivity {
TextView warningTextView = warningView.findViewById(R.id.value); TextView warningTextView = warningView.findViewById(R.id.value);
String warningValue = warningTextView.getText().toString(); String warningValue = warningTextView.getText().toString();
newMedic.setStock(Double.parseDouble(stockValue)); newMedic.setStock(Float.parseFloat(stockValue));
newMedic.setTake(Double.parseDouble(takeValue)); newMedic.setTake(Float.parseFloat(takeValue));
newMedic.setWarning(Integer.parseInt(warningValue)); newMedic.setWarning(Integer.parseInt(warningValue));
newMedic.setAlert(Integer.parseInt(alertValue)); newMedic.setAlert(Integer.parseInt(alertValue));
newMedic.getDateEndOfStock(); newMedic.getDateEndOfStock();

View file

@ -11,6 +11,8 @@ import androidx.fragment.app.Fragment;
import com.google.android.material.appbar.CollapsingToolbarLayout; import com.google.android.material.appbar.CollapsingToolbarLayout;
import net.foucry.pilldroid.models.Medic;
/** /**
* A fragment representing a single Drug detail screen. * A fragment representing a single Drug detail screen.
* This fragment is either contained in a {@link DrugListActivity} * 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 * The fragment argument representing the item ID that this fragment
* represents. * represents.
*/ */
public static final String ARG_ITEM_ID = "drug"; public static final String ARG_ITEM_ID = "medic";
/** /**
* The dummy content this fragment is presenting. * The dummy content this fragment is presenting.
*/ */
private Drug drug; private Medic medic;
/** /**
* Mandatory empty constructor for the fragment manager to instantiate the * 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 // Load the dummy content specified by the fragment
// arguments. In a real-world scenario, use a Loader // arguments. In a real-world scenario, use a Loader
// to load content from a content provider. // 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(); Activity activity = this.getActivity();
assert activity != null; assert activity != null;
CollapsingToolbarLayout appBarLayout = activity.findViewById(R.id.toolbar_layout); CollapsingToolbarLayout appBarLayout = activity.findViewById(R.id.toolbar_layout);
if (appBarLayout != null) { if (appBarLayout != null) {
appBarLayout.setTitle(drug.getName()); appBarLayout.setTitle(medic.getName());
} }
} }
} }
@ -69,47 +71,49 @@ public class DrugDetailFragment extends Fragment {
View alertView; View alertView;
// Show the dummy content as text in a TextView. // Show the dummy content as text in a TextView.
if (drug != null) { if (medic != null) {
// Find each component of rootView // Find each component of rootView
nameView = detailView.findViewById(R.id.name_cell); nameView = detailView.findViewById(R.id.name_cell);
TextView nameLabel = nameView.findViewById(R.id.label); TextView nameLabel = nameView.findViewById(R.id.label);
TextView nameValue = nameView.findViewById(R.id.value); TextView nameValue = nameView.findViewById(R.id.value);
nameLabel.setText(R.string.drug_name_label); nameLabel.setText(R.string.drug_name_label);
nameValue.setText(drug.getName()); nameValue.setText(medic.getName());
presentationView = detailView.findViewById(R.id.presentation_cell); presentationView = detailView.findViewById(R.id.presentation_cell);
TextView presentationLabel = presentationView.findViewById(R.id.label); TextView presentationLabel = presentationView.findViewById(R.id.label);
TextView presentationValue = presentationView.findViewById(R.id.value); TextView presentationValue = presentationView.findViewById(R.id.value);
presentationLabel.setText(R.string.drug_presentation_label); presentationLabel.setText(R.string.drug_presentation_label);
presentationValue.setText(drug.getPresentation()); presentationValue.setText(medic.getPresentation());
adminModeView = detailView.findViewById(R.id.administration_cell); adminModeView = detailView.findViewById(R.id.administration_cell);
TextView adminModeLabel = adminModeView.findViewById(R.id.label); TextView adminModeLabel = adminModeView.findViewById(R.id.label);
TextView adminModeValue = adminModeView.findViewById(R.id.value); TextView adminModeValue = adminModeView.findViewById(R.id.value);
adminModeLabel.setText(R.string.drug_administrationMode_label); adminModeLabel.setText(R.string.drug_administrationMode_label);
adminModeValue.setText(drug.getAdministration_mode()); adminModeValue.setText(medic.getAdministration_mode());
stockView = detailView.findViewById(R.id.stock_cell); stockView = detailView.findViewById(R.id.stock_cell);
TextView stockLibelle = (stockView.findViewById(R.id.label)); TextView stockLibelle = (stockView.findViewById(R.id.label));
TextView stockValue = stockView.findViewById(R.id.value); TextView stockValue = stockView.findViewById(R.id.value);
stockLibelle.setText(R.string.drug_current_stock_label); 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.setHint(R.string.drug_current_stock_label);
stockValue.setSelectAllOnFocus(true); stockValue.setSelectAllOnFocus(true);
takeView = detailView.findViewById(R.id.take_cell); takeView = detailView.findViewById(R.id.take_cell);
TextView priseLabel = takeView.findViewById(R.id.label); TextView takeLabel = takeView.findViewById(R.id.label);
TextView priseValue = (takeView.findViewById(R.id.value)); TextView takeValue = (takeView.findViewById(R.id.value));
priseLabel.setText(R.string.drug_take_label); takeLabel.setText(R.string.drug_take_label);
priseValue.setText(Double.toString(drug.getTake())); //takeValue.setText(Double.toString(medic.getTake()));
priseValue.setHint(R.string.drug_take_label); takeValue.setText(Utils.fmt(medic.getTake()));
priseValue.setSelectAllOnFocus(true); takeValue.setHint(R.string.drug_take_label);
takeValue.setSelectAllOnFocus(true);
warningView = detailView.findViewById(R.id.warning_cell); warningView = detailView.findViewById(R.id.warning_cell);
TextView warningLibelle = warningView.findViewById(R.id.label); TextView warningLibelle = warningView.findViewById(R.id.label);
TextView warningValue = warningView.findViewById(R.id.value); TextView warningValue = warningView.findViewById(R.id.value);
warningLibelle.setText(R.string.drug_warningThreshold_label); 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.setHint(R.string.drug_warningThreshold_label);
warningValue.setSelectAllOnFocus(true); warningValue.setSelectAllOnFocus(true);
@ -117,7 +121,8 @@ public class DrugDetailFragment extends Fragment {
TextView alertLibelle = alertView.findViewById(R.id.label); TextView alertLibelle = alertView.findViewById(R.id.label);
TextView alertValue = alertView.findViewById(R.id.value); TextView alertValue = alertView.findViewById(R.id.value);
alertLibelle.setText(R.string.drug_alertThreshold_label); 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.setHint(R.string.drug_alertThreshold_label);
alertValue.setSelectAllOnFocus(true); alertValue.setSelectAllOnFocus(true);
} }