Pilldroid/app/src/main/java/net/foucry/pilldroid/DrugDetailFragment.java

128 lines
5.2 KiB
Java
Raw Normal View History

package net.foucry.pilldroid;
import android.app.Activity;
2020-05-16 19:49:14 +02:00
import com.google.android.material.appbar.CollapsingToolbarLayout;
import android.os.Bundle;
2020-05-16 19:49:14 +02:00
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
/**
2021-04-12 21:11:50 +02:00
* A fragment representing a single Drug detail screen.
* This fragment is either contained in a {@link DrugListActivity}
* in two-pane mode (on tablets) or a {@link DrugDetailActivity}
* on handsets.
*/
2021-04-12 21:11:50 +02:00
public class DrugDetailFragment extends Fragment {
2020-04-21 21:35:28 +02:00
/**
* The fragment argument representing the item ID that this fragment
* represents.
*/
2021-04-12 21:11:50 +02:00
public static final String ARG_ITEM_ID = "drug";
/**
* The dummy content this fragment is presenting.
*/
2021-04-12 21:11:50 +02:00
private Drug drug;
/**
* Mandatory empty constructor for the fragment manager to instantiate the
* fragment (e.g. upon screen orientation changes).
*/
2021-04-12 21:11:50 +02:00
public DrugDetailFragment() {
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
2020-06-12 18:04:36 +02:00
assert getArguments() != null;
if (getArguments().containsKey(ARG_ITEM_ID)) {
// Load the dummy content specified by the fragment
// arguments. In a real-world scenario, use a Loader
// to load content from a content provider.
2021-04-12 21:11:50 +02:00
drug = (Drug) getArguments().getSerializable(ARG_ITEM_ID);
Activity activity = this.getActivity();
2020-07-18 20:17:24 +02:00
assert activity != null;
CollapsingToolbarLayout appBarLayout = activity.findViewById(R.id.toolbar_layout);
if (appBarLayout != null) {
2021-04-12 21:11:50 +02:00
appBarLayout.setTitle(drug.getName());
}
}
}
@Override
2020-04-12 10:32:00 +02:00
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View detailView = inflater.inflate(R.layout.medicament_detail, container, false);
View nameView;
View adminModeView;
View presentationView;
View stockView;
2021-04-12 21:11:50 +02:00
View takeView;
View warningView;
View alertView;
// Show the dummy content as text in a TextView.
2021-04-12 21:11:50 +02:00
if (drug != null) {
// Find each conponment of rootView
nameView = detailView.findViewById(R.id.name_cell);
TextView nameLabel = nameView.findViewById(R.id.label);
2021-04-12 21:11:50 +02:00
TextView nameValue = nameView.findViewById(R.id.value);
2020-05-23 19:12:26 +02:00
nameLabel.setText(R.string.med_name_label);
2021-04-12 21:11:50 +02:00
nameValue.setText(drug.getName());
presentationView = detailView.findViewById(R.id.presentation_cell);
TextView presentationLabel = presentationView.findViewById(R.id.label);
2021-04-12 21:11:50 +02:00
TextView presentationValue = presentationView.findViewById(R.id.value);
2020-05-23 19:12:26 +02:00
presentationLabel.setText(R.string.med_presention_labal);
2021-04-12 21:11:50 +02:00
presentationValue.setText(drug.getPresentation());
adminModeView = detailView.findViewById(R.id.administration_cell);
TextView adminModeLabel = adminModeView.findViewById(R.id.label);
2021-04-12 21:11:50 +02:00
TextView adminModeValue = adminModeView.findViewById(R.id.value);
2020-05-23 19:12:26 +02:00
adminModeLabel.setText(R.string.med_administationMode_label);
2021-04-12 21:11:50 +02:00
adminModeValue.setText(drug.getAdministration_mode());
stockView = detailView.findViewById(R.id.stock_cell);
2021-04-12 21:11:50 +02:00
TextView stockLibelle = (stockView.findViewById(R.id.label));
TextView stockValue = stockView.findViewById(R.id.value);
2020-05-23 19:12:26 +02:00
stockLibelle.setText(R.string.med_current_stock_label);
2021-04-12 21:11:50 +02:00
stockValue.setText(Double.toString(drug.getStock()));
stockValue.setHint(R.string.med_current_stock_label);
stockValue.setSelectAllOnFocus(true);
2021-04-12 21:11:50 +02:00
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.med_take_label);
priseValue.setText(Double.toString(drug.getTake()));
priseValue.setHint(R.string.med_take_label);
priseValue.setSelectAllOnFocus(true);
warningView = detailView.findViewById(R.id.warning_cell);
2021-04-12 21:11:50 +02:00
TextView warningLibelle = warningView.findViewById(R.id.label);
TextView warningValue = warningView.findViewById(R.id.value);
2020-05-23 19:12:26 +02:00
warningLibelle.setText(R.string.med_warningTherehold_label);
2021-04-12 21:11:50 +02:00
warningValue.setText(Integer.toString(drug.getWarnThreshold()));
warningValue.setHint(R.string.med_warningTherehold_label);
warningValue.setSelectAllOnFocus(true);
alertView = detailView.findViewById(R.id.alert_cell);
2021-04-12 21:11:50 +02:00
TextView alertLibelle = alertView.findViewById(R.id.label);
TextView alertValue = alertView.findViewById(R.id.value);
alertLibelle.setText(R.string.med_alertTherehold_label);
2021-04-12 21:11:50 +02:00
alertValue.setText(Integer.toString(drug.getAlertThreshold()));
alertValue.setHint(R.string.med_alertTherehold_label);
alertValue.setSelectAllOnFocus(true);
}
return detailView;
}
}