diff --git a/app/build.gradle b/app/build.gradle index ab967fd..c8a20b4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -6,8 +6,8 @@ android { defaultConfig { applicationId "net.foucry.pilldroid" - minSdkVersion 22 - targetSdkVersion 23 + minSdkVersion 21 + targetSdkVersion 21 versionCode 1 versionName "1.0" } diff --git a/app/src/main/java/net/foucry/pilldroid/MedicamentDetailActivity.java b/app/src/main/java/net/foucry/pilldroid/MedicamentDetailActivity.java index 5a7e1ed..3ef5acf 100644 --- a/app/src/main/java/net/foucry/pilldroid/MedicamentDetailActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/MedicamentDetailActivity.java @@ -53,8 +53,8 @@ public class MedicamentDetailActivity extends AppCompatActivity { // Create the detail fragment and add it to the activity // using a fragment transaction. Bundle arguments = new Bundle(); - arguments.putString(MedicamentDetailFragment.ARG_ITEM_ID, - getIntent().getStringExtra(MedicamentDetailFragment.ARG_ITEM_ID)); + arguments.putSerializable("medicament", + getIntent().getSerializableExtra("medicament")); MedicamentDetailFragment fragment = new MedicamentDetailFragment(); fragment.setArguments(arguments); getSupportFragmentManager().beginTransaction() diff --git a/app/src/main/java/net/foucry/pilldroid/MedicamentDetailFragment.java b/app/src/main/java/net/foucry/pilldroid/MedicamentDetailFragment.java index 7ed082a..2a4f954 100644 --- a/app/src/main/java/net/foucry/pilldroid/MedicamentDetailFragment.java +++ b/app/src/main/java/net/foucry/pilldroid/MedicamentDetailFragment.java @@ -22,12 +22,12 @@ public class MedicamentDetailFragment extends Fragment { * The fragment argument representing the item ID that this fragment * represents. */ - public static final String ARG_ITEM_ID = "item_id"; + public static final String ARG_ITEM_ID = "medicament"; /** * The dummy content this fragment is presenting. */ - private DummyContent.DummyItem mItem; + private Medicament medicament; /** * Mandatory empty constructor for the fragment manager to instantiate the @@ -44,12 +44,12 @@ public class MedicamentDetailFragment 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. - mItem = DummyContent.ITEM_MAP.get(getArguments().getString(ARG_ITEM_ID)); + medicament = (Medicament) getArguments().getSerializable(ARG_ITEM_ID); Activity activity = this.getActivity(); CollapsingToolbarLayout appBarLayout = (CollapsingToolbarLayout) activity.findViewById(R.id.toolbar_layout); if (appBarLayout != null) { - appBarLayout.setTitle(mItem.content); + appBarLayout.setTitle(medicament.getNom()); } } } @@ -57,13 +57,61 @@ public class MedicamentDetailFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View rootView = inflater.inflate(R.layout.medicament_detail, container, false); + View detailView = inflater.inflate(R.layout.medicament_detail, container, false); + View nameView; + View adminModeView; + View presentationView; + View stockView; + View priseView; + View warningView; + View alertView; // Show the dummy content as text in a TextView. - if (mItem != null) { - ((TextView) rootView.findViewById(R.id.medicament_detail)).setText(mItem.details); + 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); + 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); + 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); + 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); + 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); + priseLibelle.setText("Prise"); + priseValue.setText(Double.toString(medicament.getPrise())); + + warningView = detailView.findViewById(R.id.warning_cell); + TextView warningLibelle = (TextView) warningView.findViewById(R.id.libelle); + TextView warningValue = (TextView) warningView.findViewById(R.id.valeur); + warningLibelle.setText("Seuil d'alerte"); + 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); + alertLibelle.setText("Seuil critique"); + alertValue.setText(Integer.toString(medicament.getAlertThreshold())); } - return rootView; + return detailView; } } diff --git a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java b/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java index 4f1d9d1..d24cd91 100644 --- a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java @@ -10,6 +10,7 @@ import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -17,14 +18,16 @@ import android.widget.ImageView; import android.widget.SimpleCursorAdapter; import android.widget.TextView; + import net.foucry.pilldroid.Medicament; import net.foucry.pilldroid.dummy.DummyContent; import static net.foucry.pilldroid.UtilDate.*; import static net.foucry.pilldroid.Utils.*; - +import java.text.SimpleDateFormat; import java.util.Collections; import java.util.Comparator; import java.util.List; +import java.util.Locale; import java.util.Random; /** @@ -128,6 +131,7 @@ public class MedicamentListActivity extends AppCompatActivity { } private void setupRecyclerView(@NonNull RecyclerView recyclerView) { + recyclerView.addItemDecoration(new SimpleDividerItemDecoration(getApplicationContext())); recyclerView.setAdapter(new SimpleItemRecyclerViewAdapter(medicaments)); } @@ -148,17 +152,45 @@ public class MedicamentListActivity extends AppCompatActivity { } @Override - public void onBindViewHolder(final ViewHolder holder, int position) { + public void onBindViewHolder(final ViewHolder holder, final int position) { + SimpleDateFormat dateFormat = new SimpleDateFormat("EEEE d MMMM yyyy", Locale.getDefault()); + String dateEndOfStock = date2String(mValues.get(position).getDateEndOfStock(), dateFormat); + + Log.d(Constants.TAG, "dateEndOfStock == " + dateEndOfStock); + Log.d(Constants.TAG, "stock == " + mValues.get(position).getStock()); + Log.d(Constants.TAG, "prise == " + mValues.get(position).getPrise()); + Log.d(Constants.TAG, "warn == " + mValues.get(position).getWarnThreshold()); + Log.d(Constants.TAG, "alert == " + mValues.get(position).getAlertThreshold()); + holder.mItem = mValues.get(position); holder.mIDView.setText(mValues.get(position).getCip13()); holder.mContentView.setText(mValues.get(position).getNom()); + holder.mEndOfStock.setText(dateEndOfStock); + + // Test to change background programmaticaly + if (mValues.get(position).getPrise() == 0) { + holder.mView.setBackgroundResource(R.drawable.gradient_bg); + } else { + if (mValues.get(position).getStock() <= mValues.get(position).getAlertThreshold()) { + holder.mView.setBackgroundResource(R.drawable.gradient_bg_alert); + holder.mIconView.setImageResource(R.drawable.stock_alert); + } else if ((mValues.get(position).getStock() > mValues.get(position).getAlertThreshold()) && + (mValues.get(position).getStock() <= (mValues.get(position).getWarnThreshold() * mValues.get(position).getPrise()))) { + holder.mView.setBackgroundResource(R.drawable.gradient_bg_warning); + holder.mIconView.setImageResource(R.drawable.stock_warn); + } else { + holder.mView.setBackgroundResource(R.drawable.gradient_bg_ok); + holder.mIconView.setImageResource(R.drawable.stock_ok); + } + } holder.mView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { + Medicament medicamentCourant = (Medicament) mValues.get(position); if (mTwoPane) { Bundle arguments = new Bundle(); - arguments.putString(MedicamentDetailFragment.ARG_ITEM_ID, holder.mItem.getCip13()); + arguments.putSerializable("medicament", medicamentCourant); MedicamentDetailFragment fragment = new MedicamentDetailFragment(); fragment.setArguments(arguments); getSupportFragmentManager().beginTransaction() @@ -167,7 +199,7 @@ public class MedicamentListActivity extends AppCompatActivity { } else { Context context = v.getContext(); Intent intent = new Intent(context, MedicamentDetailActivity.class); - intent.putExtra(MedicamentDetailFragment.ARG_ITEM_ID, holder.mItem.getCip13()); + intent.putExtra("medicament", medicamentCourant); context.startActivity(intent); } diff --git a/app/src/main/java/net/foucry/pilldroid/SimpleDividerItemDecoration.java b/app/src/main/java/net/foucry/pilldroid/SimpleDividerItemDecoration.java new file mode 100644 index 0000000..e84e75b --- /dev/null +++ b/app/src/main/java/net/foucry/pilldroid/SimpleDividerItemDecoration.java @@ -0,0 +1,37 @@ +package net.foucry.pilldroid; + +import android.content.Context; +import android.graphics.Canvas; +import android.graphics.drawable.Drawable; +import android.support.v7.widget.RecyclerView; +import android.view.View; + +/** + * Created by jacques on 10/05/16. + */ +public class SimpleDividerItemDecoration extends RecyclerView.ItemDecoration { + private Drawable mDivider; + + public SimpleDividerItemDecoration(Context context) { + mDivider = context.getResources().getDrawable(R.drawable.line_divider); + } + + @Override + public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) { + int left = parent.getPaddingLeft(); + int right = parent.getWidth() - parent.getPaddingRight(); + + int childCount = parent.getChildCount(); + for (int i = 0; i < childCount; i++) { + View child = parent.getChildAt(i); + + RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams(); + + int top = child.getBottom() + params.bottomMargin; + int bottom = top + mDivider.getIntrinsicHeight(); + + mDivider.setBounds(left, top, right, bottom); + mDivider.draw(c); + } + } +} diff --git a/app/src/main/res/layout/activity_medicament_detail.xml b/app/src/main/res/layout/activity_medicament_detail.xml index e000762..1a10701 100644 --- a/app/src/main/res/layout/activity_medicament_detail.xml +++ b/app/src/main/res/layout/activity_medicament_detail.xml @@ -17,8 +17,10 @@ diff --git a/app/src/main/res/layout/info_cell.xml b/app/src/main/res/layout/info_cell.xml index fc77a7a..37b6e01 100644 --- a/app/src/main/res/layout/info_cell.xml +++ b/app/src/main/res/layout/info_cell.xml @@ -1,7 +1,8 @@ + android:layout_height="50dp" + android:background="@drawable/list_selector"> + android:paddingLeft="10dp" + android:paddingTop="5dp"/> + android:paddingLeft="10sp" + android:paddingTop="5dp"/> \ No newline at end of file diff --git a/app/src/main/res/layout/medicament_detail.xml b/app/src/main/res/layout/medicament_detail.xml index 21b72ac..7756e15 100644 --- a/app/src/main/res/layout/medicament_detail.xml +++ b/app/src/main/res/layout/medicament_detail.xml @@ -1,18 +1,10 @@ - - - - - - - - - - + + diff --git a/app/src/main/res/layout/medicament_list_content.xml b/app/src/main/res/layout/medicament_list_content.xml index c796d91..068d97d 100644 --- a/app/src/main/res/layout/medicament_list_content.xml +++ b/app/src/main/res/layout/medicament_list_content.xml @@ -1,7 +1,7 @@ + android:layout_marginRight="0sp"> @@ -28,7 +30,7 @@ android:text="Nom Médicament" android:textColor="#040404" android:typeface="sans" - android:textSize="14sp" + android:textSize="16sp" android:textStyle="bold"/> @@ -38,7 +40,7 @@ android:layout_height="wrap_content" android:layout_below="@id/valeur" android:textColor="#343434" - android:textSize="13sp" + android:textSize="14sp" android:layout_marginTop="1sp" android:layout_toRightOf="@+id/thumbnail" android:text="cip13 goes here" /> @@ -52,8 +54,8 @@ android:layout_alignTop="@id/valeur" android:gravity="right" android:text="lundi 1 janvier 2001" - android:layout_marginRight="5dip" - android:textSize="12sp" + android:layout_marginRight="15dp" + android:textSize="14sp" android:textColor="#212121" android:textStyle="bold"/> diff --git a/app/src/main/res/layout/value_input.xml b/app/src/main/res/layout/value_input.xml index 1861fcc..fca3056 100644 --- a/app/src/main/res/layout/value_input.xml +++ b/app/src/main/res/layout/value_input.xml @@ -11,20 +11,24 @@ android:background="@drawable/list_selector" android:textStyle="bold" android:textColor="#040404" + android:paddingLeft="5dp" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" + android:gravity="center_vertical" android:layout_toLeftOf="@+id/valeur" android:layout_alignBottom="@+id/valeur" /> \ No newline at end of file diff --git a/app/src/main/res/values-v21/styles.xml b/app/src/main/res/values-v21/styles.xml deleted file mode 100644 index dbbdd40..0000000 --- a/app/src/main/res/values-v21/styles.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 868016b..cf7bfc1 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -1,7 +1,7 @@ 16dp - 200dp + 100dp 200dp 16dp