Merge après ajout feature notification
|
@ -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'
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
package="net.foucry.pilldroid">
|
||||
|
||||
<uses-permission android:name="android.permission.CAMERA"/>
|
||||
<uses-permission android:name="android.permission.VIBRATE"/>
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
|
@ -43,6 +44,16 @@
|
|||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name=".About"
|
||||
android:label="À propos de PillDroid"
|
||||
android:parentActivityName=".MedicamentListActivity"
|
||||
android:theme="@style/AppTheme">
|
||||
</activity>
|
||||
<receiver android:name=".NotificationPublisher" /><!-- ATTENTION: This was auto-generated to add Google Play services to your project for
|
||||
App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information. -->
|
||||
<meta-data
|
||||
android:name="com.google.android.gms.version"
|
||||
android:value="@integer/google_play_services_version" />
|
||||
<service android:name=".TimeService"/>
|
||||
</application>
|
||||
|
||||
|
|
32
app/src/main/assets/about.html
Normal file
|
@ -0,0 +1,32 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
||||
<style>
|
||||
p {
|
||||
font-size: .8em;
|
||||
}
|
||||
div.build {
|
||||
font-size: .7em;
|
||||
text-align: center;
|
||||
}
|
||||
p.red {
|
||||
color: #ff2600;
|
||||
}</style>
|
||||
</head>
|
||||
<body>
|
||||
<center><img src="file:///android_res/mipmap/ic_launcher.png" width="64"/></center>
|
||||
<!--<div class="build">[[[about_string]]]</div>-->
|
||||
<h5>PilStock © 2016 Jacques Foucry </h5>
|
||||
<p>PilStock est une gestion théorique de votre stock de médicaments.</p>
|
||||
<p>PilStock n'a aucune connaissance des interactions des médicaments entre eux.</p>
|
||||
<p class="red">EN CAS DE DOUTE, CONSULTEZ VOTRE MÉDECIN OU VOTRE PHARMACIEN.</p>
|
||||
<p>PilStock ne vous rappelle pas de prendre vos médicaments.</p>
|
||||
<p class="red">LA RESPONSABILITÉ DE L'AUTEUR NE SAURAIT ÊTRE ENGAGÉE EN CAS DE SURDOSAGE OU D'OUBLI DE PRISE.</p>
|
||||
<hr width=45%/>
|
||||
<p>PilStock n'aurait pas pu voir le jour sans les conseils avisés de Frank, Benoit, Dominique & Aurélien.</p>
|
||||
<p>Stéphane en grand chamboulateur d'interface en fait quelque chose d'utilisable</p>
|
||||
<hr width=45%/>
|
||||
<p>Le soutien actif et les conseils du Dr Kauffmann me permettent de faire évoluer PilStock</p>
|
||||
<p>Vous pouvez me contacter à l'adresse suivante : <a href="mailto:pilstock@pilstock-app.com?subject=À propos de PilStock">pilstock@pilstock-app.com</a></p>
|
||||
</body>
|
||||
</html>
|
BIN
app/src/main/ic_launcher-web.png
Normal file
After Width: | Height: | Size: 52 KiB |
52
app/src/main/java/net/foucry/pilldroid/About.java
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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() {
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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<Medicament> 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<SimpleItemRecyclerViewAdapter.ViewHolder> {
|
||||
|
||||
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -2,8 +2,7 @@
|
|||
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
|
||||
<!-- Gradient Bg for listrow -->
|
||||
<gradient
|
||||
android:startColor="#D4666E"
|
||||
android:centerColor="#BD1421"
|
||||
android:endColor="#D4666E"
|
||||
android:startColor="#FFD4666E"
|
||||
android:endColor="#FFBD1421"
|
||||
android:angle="270" />
|
||||
</shape>
|
|
@ -2,8 +2,7 @@
|
|||
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
|
||||
<!-- Gradient Bg for listrow -->
|
||||
<gradient
|
||||
android:startColor="#048F01"
|
||||
android:centerColor="#5CB65A"
|
||||
android:endColor="#048F01"
|
||||
android:angle="270" />
|
||||
android:startColor="#FF048F01"
|
||||
android:endColor="#FF5CB65A"
|
||||
android:angle="90" />
|
||||
</shape>
|
|
@ -2,8 +2,7 @@
|
|||
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
|
||||
<!-- Gradient Bg for listrow -->
|
||||
<gradient
|
||||
android:startColor="#F8A253"
|
||||
android:centerColor="#F7C01E"
|
||||
android:endColor="#F8A253"
|
||||
android:angle="270" />
|
||||
android:startColor="#FFF8A253"
|
||||
android:endColor="#FFF7C01E"
|
||||
android:angle="90" />
|
||||
</shape>
|
11
app/src/main/res/layout/about.xml
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@android:color/white">
|
||||
|
||||
<WebView
|
||||
android:id="@+id/aboutHtml"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
|
@ -1,63 +1,67 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="60dp"
|
||||
android:layout_height="80dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<LinearLayout android:id="@+id/thumbnail"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="3dip"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:background="@android:color/transparent"
|
||||
android:layout_marginRight="0sp">
|
||||
<!-- Drug's name-->
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/list_image"
|
||||
android:layout_width="50sp"
|
||||
android:layout_height="50sp"
|
||||
android:layout_marginLeft="5dp"
|
||||
android:layout_marginTop="2dp"
|
||||
android:src="@drawable/stock_ok" />
|
||||
</LinearLayout>
|
||||
<!-- Drug's name-->
|
||||
android:src="@drawable/stock_ok"
|
||||
android:contentDescription="Icone de stock"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_alignParentStart="true" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/valeur"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignTop="@+id/thumbnail"
|
||||
android:layout_toRightOf="@+id/thumbnail"
|
||||
android:text="Nom Médicament"
|
||||
android:textColor="#040404"
|
||||
android:typeface="sans"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold"/>
|
||||
android:textStyle="bold"
|
||||
android:layout_alignTop="@+id/list_image"
|
||||
android:layout_toEndOf="@+id/list_image"
|
||||
android:layout_marginLeft="5dp" />
|
||||
|
||||
<!-- CIP 13 (should change) -->
|
||||
<TextView
|
||||
android:id="@+id/cip13"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/valeur"
|
||||
android:textColor="#343434"
|
||||
android:textSize="14sp"
|
||||
android:layout_marginTop="1sp"
|
||||
android:layout_toRightOf="@+id/thumbnail"
|
||||
android:text="cip13 goes here" />
|
||||
android:text="cip13 goes here"
|
||||
android:layout_below="@+id/valeur"
|
||||
android:layout_toEndOf="@+id/list_image"
|
||||
android:layout_marginLeft="5dp" />
|
||||
|
||||
<!-- dateEndOfStock -->
|
||||
<TextView
|
||||
android:id="@+id/endOfStock"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignTop="@id/valeur"
|
||||
android:gravity="right"
|
||||
android:text="lundi 1 janvier 2001"
|
||||
android:layout_marginRight="15dp"
|
||||
android:textSize="14sp"
|
||||
android:textColor="#212121"
|
||||
android:textStyle="bold"/>
|
||||
android:textStyle="bold"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:layout_marginBottom="5dp" />
|
||||
</RelativeLayout>
|
||||
|
||||
<!-- CIP 13 (should change) -->
|
||||
|
||||
<!-- dateEndOfStock -->
|
||||
|
||||
<!-- Rightend Arrow -->
|
||||
<ImageView android:layout_width="wrap_content"
|
||||
|
@ -66,4 +70,5 @@
|
|||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginRight="10sp"/>
|
||||
|
||||
</RelativeLayout>
|
7
app/src/main/res/menu/about.xml
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:id="@+id/about"
|
||||
android:title="@string/about"/>
|
||||
<item android:id="@+id/help"
|
||||
android:title="@string/help"/>
|
||||
</menu>
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 4.4 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 6.5 KiB |
Before Width: | Height: | Size: 5.4 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 7.9 KiB After Width: | Height: | Size: 16 KiB |
|
@ -126,4 +126,7 @@
|
|||
<string name="sbc_name">Google Book Search</string>
|
||||
<string name="wifi_changing_network">Requesting connection to network\u2026</string>
|
||||
<string name="msgNotFound">Médicament introuvable dans la base de données</string>
|
||||
<string name="msgFound">trouvé dans la base de données</string>
|
||||
<string name="about">À propos</string>
|
||||
<string name="help">Aide</string>
|
||||
</resources>
|
||||
|
|