diff --git a/app/build.gradle b/app/build.gradle
index c258254..156466e 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -33,4 +33,5 @@ dependencies {
compile 'com.android.support:support-v4:23.3.0'
compile 'com.android.support:recyclerview-v7:23.3.0'
compile 'com.android.support:design:23.3.0'
+ compile 'com.google.android.gms:play-services-appindexing:8.1.0'
}
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index ebbf6f2..3bd318d 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -3,6 +3,7 @@
package="net.foucry.pilldroid">
+
+
+
+
+
diff --git a/app/src/main/assets/about.html b/app/src/main/assets/about.html
new file mode 100644
index 0000000..a15b457
--- /dev/null
+++ b/app/src/main/assets/about.html
@@ -0,0 +1,32 @@
+
+
+
+
+
+
+
+
+PilStock © 2016 Jacques Foucry
+PilStock est une gestion théorique de votre stock de médicaments.
+PilStock n'a aucune connaissance des interactions des médicaments entre eux.
+EN CAS DE DOUTE, CONSULTEZ VOTRE MÉDECIN OU VOTRE PHARMACIEN.
+PilStock ne vous rappelle pas de prendre vos médicaments.
+LA RESPONSABILITÉ DE L'AUTEUR NE SAURAIT ÊTRE ENGAGÉE EN CAS DE SURDOSAGE OU D'OUBLI DE PRISE.
+
+PilStock n'aurait pas pu voir le jour sans les conseils avisés de Frank, Benoit, Dominique & Aurélien.
+Stéphane en grand chamboulateur d'interface en fait quelque chose d'utilisable
+
+Le soutien actif et les conseils du Dr Kauffmann me permettent de faire évoluer PilStock
+Vous pouvez me contacter à l'adresse suivante : pilstock@pilstock-app.com
+
+
diff --git a/app/src/main/ic_launcher-web.png b/app/src/main/ic_launcher-web.png
new file mode 100644
index 0000000..42559b2
Binary files /dev/null and b/app/src/main/ic_launcher-web.png differ
diff --git a/app/src/main/java/net/foucry/pilldroid/About.java b/app/src/main/java/net/foucry/pilldroid/About.java
new file mode 100644
index 0000000..ced9973
--- /dev/null
+++ b/app/src/main/java/net/foucry/pilldroid/About.java
@@ -0,0 +1,52 @@
+package net.foucry.pilldroid;
+
+import android.graphics.Color;
+import android.graphics.drawable.Drawable;
+import android.os.Bundle;
+import android.support.v7.app.AppCompatActivity;
+import android.text.Html;
+import android.webkit.WebView;
+
+/**
+ * Created by jacques on 12/06/16.
+ */
+public class About extends AppCompatActivity{
+
+ private WebView aboutView;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.about);
+
+ String htmlString = null;
+
+ aboutView = (WebView) findViewById(R.id.aboutHtml);
+
+ aboutView.loadUrl("file:///android_asset/about.html");
+ aboutView.clearCache(true);
+ aboutView.clearHistory();
+ aboutView.getSettings().setJavaScriptEnabled(true);
+ aboutView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
+ aboutView.setBackgroundColor(Color.WHITE);
+
+
+ }
+
+ private class ImageGetter implements Html.ImageGetter {
+
+ public Drawable getDrawable(String source) {
+ int id;
+ if (source.equals("ic_launcher.png")) {
+ id = R.mipmap.ic_launcher;
+ } else {
+ return null;
+ }
+
+ Drawable d = getResources().getDrawable(id);
+// Drawable d = ResourcesCompat.getDrawable(getResources(),id, null);
+ d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
+ return d;
+ }
+ }
+}
diff --git a/app/src/main/java/net/foucry/pilldroid/DBHelper.java b/app/src/main/java/net/foucry/pilldroid/DBHelper.java
index cfc065d..12f13ca 100644
--- a/app/src/main/java/net/foucry/pilldroid/DBHelper.java
+++ b/app/src/main/java/net/foucry/pilldroid/DBHelper.java
@@ -34,6 +34,8 @@ public class DBHelper extends SQLiteOpenHelper {
private static DBHelper sInstance;
+ private static final String TAG = DBHelper.class.getName();
+
private static final String[] COLUMS = {KEY_ID, KEY_CIS,KEY_CIP13, KEY_NAME, KEY_ADMIN, KEY_PRES, KEY_STOCK, KEY_PRISE,
KEY_SEUIL_WARN, KEY_SEUIL_ALERT};
@@ -76,7 +78,7 @@ public class DBHelper extends SQLiteOpenHelper {
public void dropDrug() {
SQLiteDatabase db = this.getWritableDatabase();
- Log.d(MedicamentListActivity.Constants.TAG, "Drop drug table");
+ Log.d(TAG, "Drop drug table");
db.execSQL("DROP TABLE IF EXISTS drug");
this.onCreate(db);
@@ -84,7 +86,7 @@ public class DBHelper extends SQLiteOpenHelper {
public void addDrug(Medicament medicament) {
// Logging
- Log.d(MedicamentListActivity.Constants.TAG, medicament.toString());
+ Log.d(TAG, medicament.toString());
// Get reference to writable DB
SQLiteDatabase db = this.getWritableDatabase();
@@ -144,7 +146,7 @@ public class DBHelper extends SQLiteOpenHelper {
medicament.setAlertThreshold(Integer.parseInt(cursor.getString(9)));
// Log
- Log.d(MedicamentListActivity.Constants.TAG, "getDrug("+id+")" + medicament.toString());
+ Log.d(TAG, "getDrug("+id+")" + medicament.toString());
// Return medicament
@@ -183,7 +185,7 @@ public class DBHelper extends SQLiteOpenHelper {
medicament.setAlertThreshold(Integer.parseInt(cursor.getString(9)));
// Log
- Log.d(MedicamentListActivity.Constants.TAG, "getDrug("+cip13+")" + medicament.toString());
+ Log.d(TAG, "getDrug("+cip13+")" + medicament.toString());
// Return medicament
@@ -225,7 +227,7 @@ public class DBHelper extends SQLiteOpenHelper {
}
cursor.close();
- Log.d(MedicamentListActivity.Constants.TAG, "getAllDrugs " + medicaments.toString());
+ Log.d(TAG, "getAllDrugs " + medicaments.toString());
// return
return medicaments;
@@ -269,7 +271,7 @@ public class DBHelper extends SQLiteOpenHelper {
db.close();
// log
- Log.d(MedicamentListActivity.Constants.TAG, "delete drug "+medicament.toString());
+ Log.d(TAG, "delete drug "+medicament.toString());
}
public int getCount() {
diff --git a/app/src/main/java/net/foucry/pilldroid/DBMedoc.java b/app/src/main/java/net/foucry/pilldroid/DBMedoc.java
index 02f8549..11f910f 100644
--- a/app/src/main/java/net/foucry/pilldroid/DBMedoc.java
+++ b/app/src/main/java/net/foucry/pilldroid/DBMedoc.java
@@ -20,22 +20,24 @@ public class DBMedoc extends SQLiteOpenHelper{
private static final int DATABASE_VERSION = 1;
- File dbFile;
- private final static String DB_PATH = "/data/data/net.foucry.pilldroid/databases/";
- private static String dbName = "medicaments.db";
-
+ private static String DATABASE_PATH = "/data/data/net.foucry.pilldroid/databases/";
+ private static String DATABASE_NAME = "medicaments.db";
private SQLiteDatabase myDataBase;
- Context myContext;
+ private final Context myContext;
private static final String TABLE_NAME = "medicaments";
+// private static final String MEDOC_ID = "id";
private static final String MEDOC_CIS = "cis";
private static final String MEDOC_CIP13 = "cip13";
+// private static final String MEDOC_CIP7 = "cip7";
private static final String MEDOC_ADMIN = "mode_administration";
private static final String MEDOC_NOM = "nom";
private static final String MEDOC_PRES = "presentation";
private static final String[] COLUMNS_NAMES = {MEDOC_CIS, MEDOC_CIP13, MEDOC_ADMIN, MEDOC_NOM, MEDOC_PRES};
+ private static final String TAG = DBMedoc.class.getName();
+
public DBMedoc(Context context) {
super(context, dbName, null, DATABASE_VERSION);
this.myContext = context;
@@ -83,11 +85,15 @@ public class DBMedoc extends SQLiteOpenHelper{
} catch (IOException e) {
e.printStackTrace();
}
+
+ myOutput.flush();
+ myOutput.close();
+ myInput.close();
}
public void openDatabase() throws SQLiteException {
- Log.e(MedicamentListActivity.Constants.TAG, "openDatabase called");
- String myPath = DB_PATH + dbName;
+ Log.e(TAG, "openDatabase called");
+ String myPath = DATABASE_PATH + DATABASE_NAME;
myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
}
@@ -98,11 +104,20 @@ public class DBMedoc extends SQLiteOpenHelper{
myDataBase.close();
}
}
+ @Override
+ public void onCreate(SQLiteDatabase db) {
- // private DBMedoc dbMedoc;
+ }
+
+ @Override
+ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
+
+ }
+
+ private DBMedoc dbMedoc;
public Medicament getMedocByCIP13(String cip13) {
- Log.e(MedicamentListActivity.Constants.TAG, "getNedocByCIP13 - " + cip13);
+ Log.e(TAG, "getNedocByCIP13 - " + cip13);
SQLiteDatabase db = this.getReadableDatabase();
@@ -140,7 +155,7 @@ public class DBMedoc extends SQLiteOpenHelper{
medicament.setAlertThreshold(7);
// Log
- Log.d(MedicamentListActivity.Constants.TAG, "getDrug(" + cip13 + ")" + medicament.toString());
+ Log.d(TAG, "getDrug(" + cip13 + ")" + medicament.toString());
// Return medicament
diff --git a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java b/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java
index aeb097e..41d216c 100644
--- a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java
+++ b/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java
@@ -1,9 +1,17 @@
package net.foucry.pilldroid;
+import android.app.AlarmManager;
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.net.Uri;
import android.os.Bundle;
+import android.os.SystemClock;
import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
@@ -11,6 +19,9 @@ import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
@@ -18,9 +29,15 @@ import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.Toast;
+import com.google.android.gms.appindexing.Action;
+import com.google.android.gms.appindexing.AppIndex;
+import com.google.android.gms.common.api.GoogleApiClient;
+
import java.text.SimpleDateFormat;
+import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
+import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Random;
@@ -45,17 +62,88 @@ public class MedicamentListActivity extends AppCompatActivity {
private boolean mTwoPane;
final static Boolean DEMO = true;
final static Random random = new Random();
- // Log TAG String
- public interface Constants {
- String TAG = "nef.foucry.pilldroid";
+ /**
+ * ATTENTION: This was auto-generated to implement the App Indexing API.
+ * See https://g.co/AppIndexing/AndroidStudio for more information.
+ */
+ private GoogleApiClient client;
+
+ @Override
+ public void onStart() {
+ super.onStart();
+
+ Log.d(TAG, "Remove old notification");
+ NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
+ nm.cancelAll();
+
+ // ATTENTION: This was auto-generated to implement the App Indexing API.
+ // See https://g.co/AppIndexing/AndroidStudio for more information.
+ client.connect();
+ Action viewAction = Action.newAction(
+ Action.TYPE_VIEW, // TODO: choose an action type.
+ "MedicamentList Page", // TODO: Define a title for the content shown.
+ // TODO: If you have web page content that matches this app activity's content,
+ // make sure this auto-generated web page URL is correct.
+ // Otherwise, set the URL to null.
+ Uri.parse("http://host/path"),
+ // TODO: Make sure this auto-generated app URL is correct.
+ Uri.parse("android-app://net.foucry.pilldroid/http/host/path")
+ );
+ AppIndex.AppIndexApi.start(client, viewAction);
}
+ @Override
+ public void onStop() {
+ super.onStop();
+
+ Calendar calendar = Calendar.getInstance();
+ Date now = calendar.getTime();
+
+ long dateSchedule;
+
+ Medicament firstMedicament = medicaments.get(0);
+
+ Date dateAlerte = UtilDate.removeDaysToDate(firstMedicament.getAlertThreshold(), firstMedicament.getDateEndOfStock());
+
+ if (dateAlerte.getTime() < now.getTime())
+ {
+ dateSchedule = 120000;
+ } else {
+ dateSchedule = dateAlerte.getTime() - now.getTime();
+ }
+
+ // int between2DateInMillis = (int) (tomorrow.getTime() - now.getTime());
+ scheduleNotification(getNotification("Vous devez passer à la pharmacie."), dateSchedule);
+
+ Log.d(TAG, "Notification scheduled for "+ UtilDate.convertDate(now.getTime() + dateSchedule));
+
+ // ATTENTION: This was auto-generated to implement the App Indexing API.
+ // See https://g.co/AppIndexing/AndroidStudio for more information.
+ Action viewAction = Action.newAction(
+ Action.TYPE_VIEW, // TODO: choose an action type.
+ "MedicamentList Page", // TODO: Define a title for the content shown.
+ // TODO: If you have web page content that matches this app activity's content,
+ // make sure this auto-generated web page URL is correct.
+ // Otherwise, set the URL to null.
+ Uri.parse("http://host/path"),
+ // TODO: Make sure this auto-generated app URL is correct.
+ Uri.parse("android-app://net.foucry.pilldroid/http/host/path")
+ );
+ AppIndex.AppIndexApi.end(client, viewAction);
+ client.disconnect();
+ }
+
+ private static final String TAG = MedicamentListActivity.class.getName();
+
private static DBHelper dbHelper;
private static DBMedoc dbMedoc;
- private SimpleCursorAdapter drugAdapter;
+ // private SimpleCursorAdapter drugAdapter;
private List medicaments;
+ private View mRecyclerView;
+ private SimpleItemRecyclerViewAdapter mAdapter;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -86,6 +174,9 @@ public class MedicamentListActivity extends AppCompatActivity {
}
});*/
+// Log.d(TAG, "Remove old notification");
+// NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
+// nm.cancelAll();
if (DEMO) {
if (dbHelper.getCount() == 0) {
@@ -136,9 +227,10 @@ public class MedicamentListActivity extends AppCompatActivity {
}
});
}
- View recyclerView = findViewById(R.id.medicament_list);
- assert recyclerView != null;
- setupRecyclerView((RecyclerView) recyclerView);
+
+ mRecyclerView = findViewById(R.id.medicament_list);
+ assert mRecyclerView != null;
+ setupRecyclerView((RecyclerView) mRecyclerView);
if (findViewById(R.id.medicament_detail_container) != null) {
// The detail container view will be present only in the
@@ -147,6 +239,54 @@ public class MedicamentListActivity extends AppCompatActivity {
// activity should be in two-pane mode.
mTwoPane = true;
}
+ // ATTENTION: This was auto-generated to implement the App Indexing API.
+ // See https://g.co/AppIndexing/AndroidStudio for more information.
+ client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
+ }
+
+
+ public boolean onCreateOptionsMenu(Menu menu) {
+ MenuInflater inflater = getMenuInflater();
+ inflater.inflate(R.menu.about, menu);
+ return true;
+ }
+
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case R.id.about:
+ startActivity(new Intent(this, About.class));
+ return true;
+ case R.id.help:
+ //startActivity(new Intent(this, Help.class));
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+
+
+ public void onPause() {
+ super.onPause();
+
+ Calendar calendar = Calendar.getInstance();
+ Date now = calendar.getTime();
+
+ long dateSchedule;
+
+ Medicament firstMedicament = medicaments.get(0);
+
+ Date dateAlerte = UtilDate.removeDaysToDate(firstMedicament.getAlertThreshold(), firstMedicament.getDateEndOfStock());
+
+ if (dateAlerte.getTime() < now.getTime())
+ {
+ dateSchedule = now.getTime() + 10000;
+ } else {
+ dateSchedule = dateAlerte.getTime();
+ }
+
+ // int between2DateInMillis = (int) (tomorrow.getTime() - now.getTime());
+ scheduleNotification(getNotification("It's today + 10s"), dateSchedule);
+
+ Log.d(TAG, "Notification scheduled for "+ UtilDate.convertDate(dateSchedule));
}
public void scanNow(View view) {
@@ -158,32 +298,49 @@ public class MedicamentListActivity extends AppCompatActivity {
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
Context context = getApplicationContext();
- String cip13 = null;
+ String cip13;
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
- Log.i(Constants.TAG, "Format:" + format);
- Log.i(Constants.TAG, "Content:" + contents);
+ Log.i(TAG, "Format:" + format);
+ Log.i(TAG, "Content:" + contents);
+
+ AlertDialog.Builder dlg = new AlertDialog.Builder(this);
+ dlg.setTitle(context.getString(R.string.app_name));
// Handle successful scan
if (format.equals("CODE_128")) { //CODE_128
cip13 = contents;
- } else
- {
- cip13 = contents.substring(4,17);
+ } else {
+ cip13 = contents.substring(4, 17);
}
dbMedoc.openDatabase();
- Medicament scannedMedoc = dbMedoc.getMedocByCIP13(cip13);
+ final Medicament scannedMedoc = dbMedoc.getMedocByCIP13(cip13);
dbMedoc.close();
if (scannedMedoc != null) {
- Toast.makeText(context, "Medicament found in database", Toast.LENGTH_LONG).show();
- } else
- {
- AlertDialog.Builder dlg = new AlertDialog.Builder(this);
- dlg.setTitle(context.getString(R.string.app_name));
+ String msg = scannedMedoc.getNom() + " " + getString(R.string.msgFound);
+
+ dlg.setMessage(msg);
+ dlg.setNegativeButton(context.getString(R.string.button_cancel), new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ // Nothing to do in case of cancel
+ }
+ });
+ dlg.setPositiveButton(context.getString(R.string.button_ok), new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ // Add Medicament to DB then try to show it
+ scannedMedoc.setDateEndOfStock();
+ dbHelper.addDrug(scannedMedoc);
+ mAdapter.addItem(scannedMedoc);
+ }
+ });
+ dlg.show();
+ } else {
dlg.setMessage(context.getString(R.string.msgNotFound));
dlg.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
@@ -202,9 +359,41 @@ public class MedicamentListActivity extends AppCompatActivity {
private void setupRecyclerView(@NonNull RecyclerView recyclerView) {
recyclerView.addItemDecoration(new SimpleDividerItemDecoration(getApplicationContext()));
- recyclerView.setAdapter(new SimpleItemRecyclerViewAdapter(medicaments));
+ mAdapter = new SimpleItemRecyclerViewAdapter(medicaments);
+ recyclerView.setAdapter(mAdapter);
}
+ private void scheduleNotification(Notification notification, long delay) {
+ Intent notificationIntent = new Intent(this, NotificationPublisher.class);
+ notificationIntent.putExtra(NotificationPublisher.NOTIFICATION_ID, 1);
+ notificationIntent.putExtra(NotificationPublisher.NOTIFICATION, notification);
+ PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
+
+ long futureInMillis = SystemClock.elapsedRealtime() + delay;
+ AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
+ alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, futureInMillis, pendingIntent);
+ }
+
+ private Notification getNotification(String content) {
+ Notification.Builder builder = new Notification.Builder(this);
+ builder.setContentTitle(getAppName());
+ builder.setContentText(content);
+ builder.setSmallIcon(R.mipmap.ic_launcher);
+ return builder.build();
+ }
+
+ private String getAppName() {
+ PackageManager packageManager = getApplicationContext().getPackageManager();
+ ApplicationInfo applicationInfo = null;
+ try {
+ applicationInfo = packageManager.getApplicationInfo(this.getPackageName(), 0);
+ } catch (final PackageManager.NameNotFoundException e) {}
+ return (String)((applicationInfo != null) ? packageManager.getApplicationLabel(applicationInfo) : "???");
+ }
+
+ /**
+ * SimpleItemRecyclerViewAdapter
+ */
public class SimpleItemRecyclerViewAdapter
extends RecyclerView.Adapter {
@@ -214,6 +403,12 @@ public class MedicamentListActivity extends AppCompatActivity {
mValues = items;
}
+ public void addItem(Medicament scannedMedoc) {
+ mValues.add(scannedMedoc);
+ notifyDataSetChanged();
+ dbHelper.addDrug(scannedMedoc);
+ }
+
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
@@ -226,11 +421,11 @@ public class MedicamentListActivity extends AppCompatActivity {
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());
+ Log.d(TAG, "dateEndOfStock == " + dateEndOfStock);
+ Log.d(TAG, "stock == " + mValues.get(position).getStock());
+ Log.d(TAG, "prise == " + mValues.get(position).getPrise());
+ Log.d(TAG, "warn == " + mValues.get(position).getWarnThreshold());
+ Log.d(TAG, "alert == " + mValues.get(position).getAlertThreshold());
holder.mItem = mValues.get(position);
holder.mIDView.setText(mValues.get(position).getCip13());
@@ -241,7 +436,7 @@ public class MedicamentListActivity extends AppCompatActivity {
if (mValues.get(position).getPrise() == 0) {
holder.mView.setBackgroundResource(R.drawable.gradient_bg);
} else {
- int remainingStock = (int) Math.floor(mValues.get(position).getStock()/mValues.get(position).getPrise());
+ int remainingStock = (int) Math.floor(mValues.get(position).getStock() / mValues.get(position).getPrise());
if (remainingStock <= mValues.get(position).getAlertThreshold()) {
holder.mView.setBackgroundResource(R.drawable.gradient_bg_alert);
holder.mIconView.setImageResource(R.drawable.stock_alert);
@@ -258,7 +453,7 @@ public class MedicamentListActivity extends AppCompatActivity {
holder.mView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- Medicament medicamentCourant = (Medicament) mValues.get(position);
+ Medicament medicamentCourant = mValues.get(position);
if (mTwoPane) {
Bundle arguments = new Bundle();
arguments.putSerializable("medicament", medicamentCourant);
diff --git a/app/src/main/java/net/foucry/pilldroid/NotificationPublisher.java b/app/src/main/java/net/foucry/pilldroid/NotificationPublisher.java
new file mode 100644
index 0000000..a908fb0
--- /dev/null
+++ b/app/src/main/java/net/foucry/pilldroid/NotificationPublisher.java
@@ -0,0 +1,28 @@
+package net.foucry.pilldroid;
+
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Vibrator;
+
+/**
+ * Created by jfoucry on 6/23/16.
+ */
+public class NotificationPublisher extends BroadcastReceiver {
+
+ public static String NOTIFICATION_ID = "notification-id";
+ public static String NOTIFICATION = "notification";
+
+ public void onReceive(Context context, Intent intent) {
+ NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
+
+ Notification notification = intent.getParcelableExtra(NOTIFICATION);
+ int id = intent.getIntExtra(NOTIFICATION_ID,0);
+ notificationManager.notify(id, notification);
+ Vibrator vibrator = (Vibrator) context.getSystemService(context.VIBRATOR_SERVICE);
+ vibrator.vibrate(400);
+
+ }
+}
diff --git a/app/src/main/java/net/foucry/pilldroid/UtilDate.java b/app/src/main/java/net/foucry/pilldroid/UtilDate.java
index 0d8e301..8ad4b92 100644
--- a/app/src/main/java/net/foucry/pilldroid/UtilDate.java
+++ b/app/src/main/java/net/foucry/pilldroid/UtilDate.java
@@ -12,6 +12,7 @@ import java.util.Date;
*/
public class UtilDate {
+ private static final String TAG = UtilDate.class.getName();
/**
*
* @param aDate
@@ -21,7 +22,7 @@ public class UtilDate {
*/
public static Date dateAtNoon(Date aDate) {
- Log.d(MedicamentListActivity.Constants.TAG, "dateAtNoon " + aDate);
+ Log.d(TAG, "dateAtNoon " + aDate);
Calendar calendar = Calendar.getInstance();
calendar.setTime(aDate);
@@ -32,6 +33,19 @@ public class UtilDate {
return calendar.getTime();
}
+ /**
+ * @return date (tomorrow)
+ */
+
+ public static Date getTomorrow() {
+ Log.d(TAG, "tomorrow");
+
+ Calendar calendar = Calendar.getInstance();
+ calendar.add(Calendar.DAY_OF_YEAR,1);
+
+ return dateAtNoon(calendar.getTime());
+ }
+
/**
*
* @param days
@@ -57,7 +71,7 @@ public class UtilDate {
*/
public static String date2String(Date date, DateFormat dateFormat) {
- Log.d(MedicamentListActivity.Constants.TAG, "date == " + date);
+ Log.d(TAG, "date == " + date);
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
@@ -100,12 +114,10 @@ public class UtilDate {
public static long tomorrowAtNoon() {
Date now = new Date();
+ public static String convertDate(long dateInMilliseconds) {
+ DateFormat formatter = new SimpleDateFormat("dd/MM/yy hh:mm:ss");
Calendar calendar = Calendar.getInstance();
- calendar.setTime(now);
- calendar.add(Calendar.DAY_OF_YEAR,1);
- Date tomorrowAtNoon = dateAtNoon(calendar.getTime());
-
- long millis = tomorrowAtNoon.getTime() - now.getTime();
- return millis;
+ calendar.setTimeInMillis(dateInMilliseconds);
+ return formatter.format(calendar.getTime());
}
}
diff --git a/app/src/main/java/net/foucry/pilldroid/Utils.java b/app/src/main/java/net/foucry/pilldroid/Utils.java
index dc4798e..6b79c60 100644
--- a/app/src/main/java/net/foucry/pilldroid/Utils.java
+++ b/app/src/main/java/net/foucry/pilldroid/Utils.java
@@ -3,6 +3,7 @@ package net.foucry.pilldroid;
import java.io.InputStream;
import java.io.OutputStream;
+import java.util.Date;
import java.util.Random;
import java.lang.Math;
diff --git a/app/src/main/res/drawable/gradient_bg_alert.xml b/app/src/main/res/drawable/gradient_bg_alert.xml
index 7d58d72..6bce62a 100644
--- a/app/src/main/res/drawable/gradient_bg_alert.xml
+++ b/app/src/main/res/drawable/gradient_bg_alert.xml
@@ -2,8 +2,7 @@
\ No newline at end of file
diff --git a/app/src/main/res/drawable/gradient_bg_ok.xml b/app/src/main/res/drawable/gradient_bg_ok.xml
index e2ea5eb..7155d22 100644
--- a/app/src/main/res/drawable/gradient_bg_ok.xml
+++ b/app/src/main/res/drawable/gradient_bg_ok.xml
@@ -2,8 +2,7 @@
+ android:startColor="#FF048F01"
+ android:endColor="#FF5CB65A"
+ android:angle="90" />
\ No newline at end of file
diff --git a/app/src/main/res/drawable/gradient_bg_warning.xml b/app/src/main/res/drawable/gradient_bg_warning.xml
index 59190ce..e07f789 100644
--- a/app/src/main/res/drawable/gradient_bg_warning.xml
+++ b/app/src/main/res/drawable/gradient_bg_warning.xml
@@ -2,8 +2,7 @@
+ android:startColor="#FFF8A253"
+ android:endColor="#FFF7C01E"
+ android:angle="90" />
\ No newline at end of file
diff --git a/app/src/main/res/layout/about.xml b/app/src/main/res/layout/about.xml
new file mode 100644
index 0000000..1dd71d4
--- /dev/null
+++ b/app/src/main/res/layout/about.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/medicament_list_content.xml b/app/src/main/res/layout/medicament_list_content.xml
index 0f038f7..f5be3b6 100644
--- a/app/src/main/res/layout/medicament_list_content.xml
+++ b/app/src/main/res/layout/medicament_list_content.xml
@@ -1,63 +1,67 @@
-
+
+
-
-
-
+ android:src="@drawable/stock_ok"
+ android:contentDescription="Icone de stock"
+ android:layout_centerVertical="true"
+ android:layout_alignParentStart="true" />
+
+
+
+
+
+
+
-
-
+
\ No newline at end of file
diff --git a/app/src/main/res/menu/about.xml b/app/src/main/res/menu/about.xml
new file mode 100644
index 0000000..f25403c
--- /dev/null
+++ b/app/src/main/res/menu/about.xml
@@ -0,0 +1,7 @@
+
+
\ No newline at end of file
diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.png b/app/src/main/res/mipmap-hdpi/ic_launcher.png
index 7a892ff..88aebca 100644
Binary files a/app/src/main/res/mipmap-hdpi/ic_launcher.png and b/app/src/main/res/mipmap-hdpi/ic_launcher.png differ
diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.png b/app/src/main/res/mipmap-mdpi/ic_launcher.png
index 8ad3ae5..1ed05b8 100644
Binary files a/app/src/main/res/mipmap-mdpi/ic_launcher.png and b/app/src/main/res/mipmap-mdpi/ic_launcher.png differ
diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/app/src/main/res/mipmap-xhdpi/ic_launcher.png
index 2842f95..10905ae 100644
Binary files a/app/src/main/res/mipmap-xhdpi/ic_launcher.png and b/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ
diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
index 5451428..3da3b48 100644
Binary files a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ
diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
index 7c7d259..fcaf7e4 100644
Binary files a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index cb93174..f38692b 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -126,4 +126,7 @@
Google Book Search
Requesting connection to network\u2026
Médicament introuvable dans la base de données
+ trouvé dans la base de données
+ À propos
+ Aide