From 9bb5e62c48c2c241f5a644e97e3de12cb3594f94 Mon Sep 17 00:00:00 2001 From: jacques Date: Wed, 3 Aug 2022 19:02:25 +0200 Subject: [PATCH 01/89] As suggested by @Jean-BaptisteC, reformatting code with Android Studio --- .../main/java/net/foucry/pilldroid/About.java | 5 +- .../net/foucry/pilldroid/AlarmReceiver.java | 110 ++++---- .../pilldroid/CustomScannerActivity.java | 6 +- .../java/net/foucry/pilldroid/DBDrugs.java | 58 ++--- .../java/net/foucry/pilldroid/DBHelper.java | 95 ++++--- .../main/java/net/foucry/pilldroid/Drug.java | 103 ++++---- .../foucry/pilldroid/DrugDetailContract.java | 5 +- .../foucry/pilldroid/DrugListActivity.java | 238 +++++++++--------- .../pilldroid/PilldroidScanContract.java | 31 +-- .../net/foucry/pilldroid/PrefManager.java | 90 +++---- .../java/net/foucry/pilldroid/UtilDate.java | 3 +- .../main/java/net/foucry/pilldroid/Utils.java | 12 +- .../net/foucry/pilldroid/WelcomeActivity.java | 74 +++--- .../pilldroid/dao/PrescriptionsDAO.java | 24 +- .../pilldroid/databases/MedicineDatabase.java | 4 +- .../databases/PrescriptionDatabase.java | 40 +-- .../net/foucry/pilldroid/models/Medicine.java | 17 +- .../foucry/pilldroid/models/Prescription.java | 85 +++---- app/src/main/res/anim/slide_from_left.xml | 6 +- app/src/main/res/anim/slide_from_right.xml | 6 +- app/src/main/res/anim/slide_to_left.xml | 4 +- app/src/main/res/anim/slide_to_right.xml | 6 +- app/src/main/res/layout/about.xml | 3 +- .../res/layout/custom_barcode_scanner.xml | 17 +- .../res/layout/custom_scanner_activty.xml | 2 +- app/src/main/res/layout/drug_detail.xml | 30 +-- .../main/res/layout/drug_detail_activity.xml | 4 +- app/src/main/res/layout/drug_list.xml | 2 +- .../main/res/layout/drug_list_activity.xml | 6 +- app/src/main/res/layout/drug_list_content.xml | 16 +- app/src/main/res/layout/info_cell.xml | 6 +- app/src/main/res/layout/value_input.xml | 11 +- app/src/main/res/layout/welcome_activity.xml | 11 +- 33 files changed, 561 insertions(+), 569 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/About.java b/app/src/main/java/net/foucry/pilldroid/About.java index cabe0e8..99312ba 100644 --- a/app/src/main/java/net/foucry/pilldroid/About.java +++ b/app/src/main/java/net/foucry/pilldroid/About.java @@ -2,15 +2,14 @@ package net.foucry.pilldroid; import android.graphics.Color; import android.os.Bundle; +import android.webkit.WebView; import androidx.appcompat.app.AppCompatActivity; -import android.webkit.WebView; - /** * Created by jacques on 12/06/16. */ -public class About extends AppCompatActivity{ +public class About extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { diff --git a/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java b/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java index 7555267..1aeb4c7 100644 --- a/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java +++ b/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java @@ -31,9 +31,56 @@ public class AlarmReceiver extends BroadcastReceiver { NotificationManager notificationManager; + public static void scheduleAlarm(Context context) { + Calendar calendar = Calendar.getInstance(); + Date today; + Date tomorrow; + LocalTime todayNow = LocalTime.now(); + + /*if (BuildConfig.DEBUG) { + Date nextSchedule = calendar.getTime(); + calendar.setTimeInMillis(nextSchedule.getTime()); + } else {*/ + calendar.set(Calendar.HOUR_OF_DAY, 11); + today = calendar.getTime(); + calendar.add(Calendar.DAY_OF_YEAR, 1); + tomorrow = calendar.getTime(); + if (todayNow.isBefore(LocalTime.NOON)) { + calendar.setTimeInMillis(today.getTime()); + } else { + calendar.setTimeInMillis(tomorrow.getTime()); + } + //} + + PendingIntent alarmIntent; + + Intent intent = new Intent(context, AlarmReceiver.class); + alarmIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_IMMUTABLE); + + AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); + + /*if (BuildConfig.DEBUG) { + alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP,(calendar.getTimeInMillis()), + AlarmManager.ELAPSED_REALTIME, alarmIntent); + } else {*/ + + alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, (calendar.getTimeInMillis()), + AlarmManager.INTERVAL_DAY, alarmIntent); + //} + + Log.d(TAG, "Alarm scheduled for " + UtilDate.convertDate(calendar.getTimeInMillis())); + if (BuildConfig.DEBUG) { + Toast.makeText(context, "Alarm scheduled for " + UtilDate.convertDate(calendar.getTimeInMillis()), Toast.LENGTH_SHORT).show(); + } + } + + public static Boolean isAlarmScheduled(Context context) { + AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); + return alarmManager.getNextAlarmClock() != null; + } + @Override - public void onReceive(Context context, Intent intent) - { + public void onReceive(Context context, Intent intent) { // Show the toast like in above screen shot Log.d(TAG, "onReceive"); @@ -45,7 +92,9 @@ public class AlarmReceiver extends BroadcastReceiver { scheduleAlarm(context); } - if (BuildConfig.DEBUG) { Toast.makeText(context, "New stock calculated", Toast.LENGTH_LONG).show(); } + if (BuildConfig.DEBUG) { + Toast.makeText(context, "New stock calculated", Toast.LENGTH_LONG).show(); + } createNotificationChannel(context); PrescriptionDatabase prescriptions = PrescriptionDatabase.getInstanceDatabase(context.getApplicationContext()); PrescriptionsDAO prescriptionsDAO = prescriptions.getPrescriptionsDAO(); @@ -53,7 +102,7 @@ public class AlarmReceiver extends BroadcastReceiver { Prescription firstPrescription = null; Prescription currentPrescription; - for (int i=0 ; i < prescriptionList.size(); i++ ) { + for (int i = 0; i < prescriptionList.size(); i++) { currentPrescription = prescriptionList.get(i); currentPrescription.newStock(); prescriptionsDAO.update(currentPrescription); @@ -63,15 +112,14 @@ public class AlarmReceiver extends BroadcastReceiver { Utils.sortPrescriptionList(prescriptionList); try { firstPrescription = prescriptionList.get(0); - } - catch (Exception e){ + } catch (Exception e) { Log.e(TAG, e.toString()); e.printStackTrace(); } if (firstPrescription != null) { if (firstPrescription.getTake() != 0) { - if(firstPrescription.getStock() <= firstPrescription.getAlertThreshold()) { + if (firstPrescription.getStock() <= firstPrescription.getAlertThreshold()) { notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Intent notificationIntent = new Intent(context, DrugListActivity.class); @@ -92,8 +140,7 @@ public class AlarmReceiver extends BroadcastReceiver { NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); int notificationId = 666; notificationManager.notify(notificationId, builder.build()); - } else - { + } else { double dummy = (firstPrescription.getStock() - firstPrescription.getAlertThreshold()); Log.d(TAG, "no notification scheduled " + dummy); } @@ -128,49 +175,4 @@ public class AlarmReceiver extends BroadcastReceiver { e.printStackTrace(); } } - public static void scheduleAlarm(Context context) { - Calendar calendar = Calendar.getInstance(); - Date today; - Date tomorrow; - LocalTime todayNow = LocalTime.now(); - - /*if (BuildConfig.DEBUG) { - Date nextSchedule = calendar.getTime(); - calendar.setTimeInMillis(nextSchedule.getTime()); - } else {*/ - calendar.set(Calendar.HOUR_OF_DAY, 11); - today = calendar.getTime(); - calendar.add(Calendar.DAY_OF_YEAR, 1); - tomorrow = calendar.getTime(); - if (todayNow.isBefore(LocalTime.NOON)) { - calendar.setTimeInMillis(today.getTime()); - } else { - calendar.setTimeInMillis(tomorrow.getTime()); - } - //} - - PendingIntent alarmIntent; - - Intent intent = new Intent(context, AlarmReceiver.class); - alarmIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_IMMUTABLE); - - AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); - - /*if (BuildConfig.DEBUG) { - alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP,(calendar.getTimeInMillis()), - AlarmManager.ELAPSED_REALTIME, alarmIntent); - } else {*/ - - alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, (calendar.getTimeInMillis()), - AlarmManager.INTERVAL_DAY, alarmIntent); - //} - - Log.d(TAG, "Alarm scheduled for " + UtilDate.convertDate(calendar.getTimeInMillis())); - if (BuildConfig.DEBUG) { Toast.makeText(context, "Alarm scheduled for " + UtilDate.convertDate(calendar.getTimeInMillis()), Toast.LENGTH_SHORT).show(); } - } - - public static Boolean isAlarmScheduled(Context context) { - AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); - return alarmManager.getNextAlarmClock() != null; - } } diff --git a/app/src/main/java/net/foucry/pilldroid/CustomScannerActivity.java b/app/src/main/java/net/foucry/pilldroid/CustomScannerActivity.java index 14d90a8..3806408 100644 --- a/app/src/main/java/net/foucry/pilldroid/CustomScannerActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/CustomScannerActivity.java @@ -23,14 +23,12 @@ import com.journeyapps.barcodescanner.ViewfinderView; public class CustomScannerActivity extends Activity implements DecoratedBarcodeView.TorchListener { private static final String TAG = CustomScannerActivity.class.getName(); - + final Bundle captureIntentBundle = new Bundle(); private CaptureManager capture; private DecoratedBarcodeView barcodeScannerView; private ImageButton switchFlashlightButton; private ViewfinderView viewfinderView; - final Bundle captureIntentBundle = new Bundle(); - @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -147,7 +145,7 @@ public class CustomScannerActivity extends Activity implements DecoratedBarcodeV public void onKeyboard(View view) { Log.d(TAG, "onkeyboard"); Intent resultIntent = new Intent(); - resultIntent.putExtra("returnCode",3); + resultIntent.putExtra("returnCode", 3); CustomScannerActivity.this.setResult(RESULT_OK, resultIntent); finish(); } diff --git a/app/src/main/java/net/foucry/pilldroid/DBDrugs.java b/app/src/main/java/net/foucry/pilldroid/DBDrugs.java index 912cf42..04116d2 100644 --- a/app/src/main/java/net/foucry/pilldroid/DBDrugs.java +++ b/app/src/main/java/net/foucry/pilldroid/DBDrugs.java @@ -21,35 +21,29 @@ class DBDrugs extends SQLiteOpenHelper { private static final int DATABASE_VERSION = 1; - private static final String dbName = "drugs.db"; + private static final String dbName = "drugs.db"; + private static final String TABLE_NAME = "drugs"; + private static final String DRUG_CIS = "cis"; + private static final String DRUG_CIP13 = "cip13"; + private static final String DRUG_CIP7 = "cip7"; + private static final String DRUG_ADMIN = "administration_mode"; + private static final String DRUG_NAME = "name"; + private static final String DRUG_PRES = "presentation"; + private static final String[] COLUMNS_NAMES = {DRUG_CIS, DRUG_CIP13, DRUG_CIP7, DRUG_ADMIN, DRUG_NAME, DRUG_PRES}; + private static final String TAG = DBDrugs.class.getName(); private final Context myContext; private final SQLiteDatabase myDataBase = null; - private static final String TABLE_NAME = "drugs"; - private static final String DRUG_CIS = "cis"; - private static final String DRUG_CIP13 = "cip13"; - private static final String DRUG_CIP7 = "cip7"; - private static final String DRUG_ADMIN = "administration_mode"; - private static final String DRUG_NAME = "name"; - private static final String DRUG_PRES = "presentation"; - - private static final String[] COLUMNS_NAMES = {DRUG_CIS, DRUG_CIP13, DRUG_CIP7, DRUG_ADMIN, DRUG_NAME, DRUG_PRES}; - - private static final String TAG = DBDrugs.class.getName(); - - DBDrugs(Context context) { super(context, dbName, null, DATABASE_VERSION); this.myContext = context; } - public boolean isDBFileExist(File database) - { - try { + public boolean isDBFileExist(File database) { + try { myContext.getDatabasePath(String.valueOf(database)); - } - catch (final Exception e){ + } catch (final Exception e) { return false; } return true; @@ -166,26 +160,24 @@ class DBDrugs extends SQLiteOpenHelper { String getCIP13FromCIP7(String cip7) { - String cip13 = null; + String cip13 = null; - try { - Cursor c = this.getReadableDatabase().rawQuery("SELECT cip13 FROM "+ TABLE_NAME + " where cip7 = "+cip7, null); + try { + Cursor c = this.getReadableDatabase().rawQuery("SELECT cip13 FROM " + TABLE_NAME + " where cip7 = " + cip7, null); - Log.d(TAG, "Cursor == " + DatabaseUtils.dumpCursorToString(c)); + Log.d(TAG, "Cursor == " + DatabaseUtils.dumpCursorToString(c)); - c.moveToFirst(); + c.moveToFirst(); - if(c.getCount()>0) - { - cip13 = c.getString(0); - } - c.close(); - } catch(Exception e) - { - e.printStackTrace(); + if (c.getCount() > 0) { + cip13 = c.getString(0); } - return cip13; + c.close(); + } catch (Exception e) { + e.printStackTrace(); } + return cip13; + } Drug getDrugByCIP7(String cip7) { Log.d(TAG, "CIP7 - " + cip7); diff --git a/app/src/main/java/net/foucry/pilldroid/DBHelper.java b/app/src/main/java/net/foucry/pilldroid/DBHelper.java index d2dc1bf..16fa01a 100644 --- a/app/src/main/java/net/foucry/pilldroid/DBHelper.java +++ b/app/src/main/java/net/foucry/pilldroid/DBHelper.java @@ -18,31 +18,27 @@ import java.util.List; */ - class DBHelper extends SQLiteOpenHelper { private static final int DATABASE_VERSION = 1; private static final String DATABASE_NAME = "prescription.db"; - private static final String TABLE_DRUG = "drug"; - private static final String KEY_ID = "id"; - private static final String KEY_CIS = "cis"; - private static final String KEY_CIP13 = "cip13"; - private static final String KEY_NAME = "name"; - private static final String KEY_ADMIN = "administration_mode"; - private static final String KEY_PRES = "presentation"; - private static final String KEY_STOCK = "stock"; - private static final String KEY_TAKE = "take"; - private static final String KEY_THRESHOLD_WARN = "warning"; + private static final String TABLE_DRUG = "drug"; + private static final String KEY_ID = "id"; + private static final String KEY_CIS = "cis"; + private static final String KEY_CIP13 = "cip13"; + private static final String KEY_NAME = "name"; + private static final String KEY_ADMIN = "administration_mode"; + private static final String KEY_PRES = "presentation"; + private static final String KEY_STOCK = "stock"; + private static final String KEY_TAKE = "take"; + private static final String KEY_THRESHOLD_WARN = "warning"; private static final String KEY_THRESHOLD_ALERT = "alert"; - private static final String KEY_LAST_UPDATE = "last_update"; - - final List drugs = new ArrayList<>(); - + private static final String KEY_LAST_UPDATE = "last_update"; private static final String TAG = DBHelper.class.getName(); - - private static final String[] COLUMNS = {KEY_ID, KEY_CIS,KEY_CIP13, KEY_NAME, KEY_ADMIN, KEY_PRES, KEY_STOCK, KEY_TAKE, + private static final String[] COLUMNS = {KEY_ID, KEY_CIS, KEY_CIP13, KEY_NAME, KEY_ADMIN, KEY_PRES, KEY_STOCK, KEY_TAKE, KEY_THRESHOLD_WARN, KEY_THRESHOLD_ALERT, KEY_LAST_UPDATE}; + final List drugs = new ArrayList<>(); DBHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); @@ -53,7 +49,7 @@ class DBHelper extends SQLiteOpenHelper { String CREATE_DRUG_TABLE = "CREATE TABLE drug ( " + "id INTEGER PRIMARY KEY AUTOINCREMENT," + "cis TEXT, " + - "cip13 TEXT, " + + "cip13 TEXT, " + "name TEXT, " + "administration_mode TEXT, " + "presentation TEXT, " + @@ -88,6 +84,7 @@ class DBHelper extends SQLiteOpenHelper { /** * Split drug values into database record and record it to the DB + * * @param drug the drug object to be saved */ void addDrug(Drug drug) { @@ -123,6 +120,7 @@ class DBHelper extends SQLiteOpenHelper { /** * return a drug from the DB with is id + * * @param id of the drug we looking for (not used) * @return return the found drug of null */ @@ -134,7 +132,7 @@ class DBHelper extends SQLiteOpenHelper { Cursor cursor = db.query(TABLE_DRUG, // Which table COLUMNS, // column names " id = ?", // selections - new String[] { String.valueOf(id) }, // selections args + new String[]{String.valueOf(id)}, // selections args null, // group by null, // having null, // order by @@ -161,7 +159,7 @@ class DBHelper extends SQLiteOpenHelper { drug.setDateLastUpdate(Long.parseLong(cursor.getString(10))); } // Log - Log.d(TAG, "getDrug("+id+")" + drug); + Log.d(TAG, "getDrug(" + id + ")" + drug); assert cursor != null; cursor.close(); @@ -172,7 +170,6 @@ class DBHelper extends SQLiteOpenHelper { } /** - * * @param cip13 drug id in French nomenclature * @return the drug object found in DB or null */ @@ -218,7 +215,6 @@ class DBHelper extends SQLiteOpenHelper { } /** - * * @return a Sorted and updated by dateEndOfStock List of All drugs presents in database */ @@ -262,18 +258,16 @@ class DBHelper extends SQLiteOpenHelper { db.close(); Drug currentDrug; - for (int position = 0 ; position < getCount() ; position++ ) { + for (int position = 0; position < getCount(); position++) { currentDrug = getItem(position); - if (!DateUtils.isToday(currentDrug.getDateLastUpdate())) - { + if (!DateUtils.isToday(currentDrug.getDateLastUpdate())) { currentDrug.newStock(); updateDrug(currentDrug); } } - Log.d(TAG, "Before sort == " + drugs); drugs.sort(new Comparator() { @@ -289,16 +283,14 @@ class DBHelper extends SQLiteOpenHelper { // Move drug with prise = 0 at the end of the list // todo: If some drug moved, must redo all the loop - int position = 0 ; - for ( int nbOps = 0; nbOps < getCount() ; nbOps ++ ) { + int position = 0; + for (int nbOps = 0; nbOps < getCount(); nbOps++) { currentDrug = getItem(position); double currentTake = currentDrug.getTake(); - if (currentTake == 0) - { + if (currentTake == 0) { drug = drugs.remove(position); drugs.add(drug); - } else - { + } else { position++; } } @@ -306,7 +298,6 @@ class DBHelper extends SQLiteOpenHelper { } /** - * * @param drug object to be updated in DB */ public void updateDrug(Drug drug) { @@ -319,19 +310,19 @@ class DBHelper extends SQLiteOpenHelper { // Create ContentValues to add column/value ContentValues values = new ContentValues(); - values.put(KEY_ID, drug.getId()); - values.put(KEY_CIS, drug.getCis()); - values.put(KEY_CIP13, drug.getCip13()); - values.put(KEY_NAME, drug.getName()); - values.put(KEY_ADMIN, drug.getAdministration_mode()); - values.put(KEY_PRES, drug.getPresentation()); - values.put(KEY_STOCK, drug.getStock()); - values.put(KEY_TAKE, drug.getTake()); - values.put(KEY_THRESHOLD_WARN, drug.getWarnThreshold()); + values.put(KEY_ID, drug.getId()); + values.put(KEY_CIS, drug.getCis()); + values.put(KEY_CIP13, drug.getCip13()); + values.put(KEY_NAME, drug.getName()); + values.put(KEY_ADMIN, drug.getAdministration_mode()); + values.put(KEY_PRES, drug.getPresentation()); + values.put(KEY_STOCK, drug.getStock()); + values.put(KEY_TAKE, drug.getTake()); + values.put(KEY_THRESHOLD_WARN, drug.getWarnThreshold()); values.put(KEY_THRESHOLD_ALERT, drug.getAlertThreshold()); - values.put(KEY_LAST_UPDATE, drug.getDateLastUpdate()); + values.put(KEY_LAST_UPDATE, drug.getDateLastUpdate()); - String[] selectionArgs = { String.valueOf(drug.getId()) }; + String[] selectionArgs = {String.valueOf(drug.getId())}; db.update(TABLE_DRUG, // table values, // column/value @@ -345,6 +336,7 @@ class DBHelper extends SQLiteOpenHelper { /** * Delete a drug object in database + * * @param drug object to be delete in the DB */ public void deleteDrug(Drug drug) { @@ -353,18 +345,19 @@ class DBHelper extends SQLiteOpenHelper { // Delete record db.delete(TABLE_DRUG, // table - KEY_ID+ " = ?", // selections - new String[] { String.valueOf(drug.getId()) } ); // selections args + KEY_ID + " = ?", // selections + new String[]{String.valueOf(drug.getId())}); // selections args // Close DB db.close(); // log - Log.d(TAG, "delete drug "+ drug); + Log.d(TAG, "delete drug " + drug); } /** * Get count of all drug present in database + * * @return number of drug in DB */ int getCount() { @@ -389,15 +382,13 @@ class DBHelper extends SQLiteOpenHelper { boolean isDrugExist(String cip13) { boolean value = false; try { - Cursor c = this.getReadableDatabase().rawQuery("SELECT * FROM "+ TABLE_DRUG + " where cip13 = "+cip13, null); + Cursor c = this.getReadableDatabase().rawQuery("SELECT * FROM " + TABLE_DRUG + " where cip13 = " + cip13, null); - if(c.getCount()>0) - { + if (c.getCount() > 0) { value = true; } c.close(); - } catch(Exception e) - { + } catch (Exception e) { e.printStackTrace(); } return value; diff --git a/app/src/main/java/net/foucry/pilldroid/Drug.java b/app/src/main/java/net/foucry/pilldroid/Drug.java index 5c5b011..2491c55 100644 --- a/app/src/main/java/net/foucry/pilldroid/Drug.java +++ b/app/src/main/java/net/foucry/pilldroid/Drug.java @@ -1,5 +1,8 @@ package net.foucry.pilldroid; +import static net.foucry.pilldroid.UtilDate.dateAtNoon; +import static net.foucry.pilldroid.UtilDate.nbOfDaysBetweenDateAndToday; + import android.util.Log; import java.io.Serializable; @@ -7,9 +10,6 @@ import java.util.Calendar; import java.util.Date; import java.util.Objects; -import static net.foucry.pilldroid.UtilDate.dateAtNoon; -import static net.foucry.pilldroid.UtilDate.nbOfDaysBetweenDateAndToday; - /** * Created by jacques on 26/11/15. */ @@ -56,86 +56,68 @@ public class Drug implements Serializable { return id; } - String getName() { - return name; - } - - String getCip13() { - return cip13; - } - - String getCis() { - return cis; - } - - String getAdministration_mode() { - return administration_mode; - } - - String getPresentation() { - return presentation; - } - - double getStock() { - return stock; - } - - double getTake() { - return take; - } - - int getAlertThreshold() { - return alertThreshold; - } - - int getWarnThreshold() { - return warnThreshold; - } - - long getDateLastUpdate() { - return dateLastUpdate; - } - - Date getDateEndOfStock() { - return dateEndOfStock; - } - public void setId(int id) { this.id = id; } + String getName() { + return name; + } + void setName(String name) { this.name = name; } + String getCip13() { + return cip13; + } + void setCip13(String cip13) { this.cip13 = cip13; } + String getCis() { + return cis; + } + void setCis(String cis) { this.cis = cis; } + String getAdministration_mode() { + return administration_mode; + } + void setAdministration_mode(String administration_mode) { this.administration_mode = administration_mode; } + String getPresentation() { + return presentation; + } + void setPresentation(String presentation) { this.presentation = presentation; } + double getStock() { + return stock; + } + void setStock(double stock) { this.stock = stock; } + double getTake() { + return take; + } + void setTake(double take) { this.take = take; } - void setWarnThreshold(int warn) { - if (warn == 0) - warn = 14; - this.warnThreshold = warn; + int getAlertThreshold() { + return alertThreshold; } void setAlertThreshold(int alert) { @@ -144,10 +126,28 @@ public class Drug implements Serializable { this.alertThreshold = alert; } + int getWarnThreshold() { + return warnThreshold; + } + + void setWarnThreshold(int warn) { + if (warn == 0) + warn = 14; + this.warnThreshold = warn; + } + + long getDateLastUpdate() { + return dateLastUpdate; + } + void setDateLastUpdate(long l) { this.dateLastUpdate = l; } + Date getDateEndOfStock() { + return dateEndOfStock; + } + void setDateEndOfStock() { int numberDayOfTake; if (this.take > 0) { @@ -176,6 +176,7 @@ public class Drug implements Serializable { setDateLastUpdate(new Date().getTime()); } } + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/app/src/main/java/net/foucry/pilldroid/DrugDetailContract.java b/app/src/main/java/net/foucry/pilldroid/DrugDetailContract.java index 1dcef08..48bbc16 100644 --- a/app/src/main/java/net/foucry/pilldroid/DrugDetailContract.java +++ b/app/src/main/java/net/foucry/pilldroid/DrugDetailContract.java @@ -13,7 +13,7 @@ public class DrugDetailContract extends ActivityResultContract * Create an intent that can be used for {@link Activity#startActivityForResult} * * @param context Context - * @param input Drug + * @param input Drug */ @NonNull @Override @@ -26,8 +26,9 @@ public class DrugDetailContract extends ActivityResultContract /** * Convert result obtained from to O + * * @param resultCode Integer - * @param intent Intent + * @param intent Intent * @return Integer */ @Override diff --git a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java index 049fc81..2650c94 100644 --- a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java @@ -39,6 +39,7 @@ import androidx.recyclerview.widget.RecyclerView; import androidx.room.Room; import com.google.android.material.snackbar.Snackbar; +import com.google.zxing.client.android.BuildConfig; import com.google.zxing.client.android.Intents; import com.journeyapps.barcodescanner.ScanOptions; @@ -54,8 +55,6 @@ import java.util.Date; import java.util.List; import java.util.Locale; -import com.google.zxing.client.android.BuildConfig; - /** * An activity representing a list of Drugs is activity * has different presentations for handset and tablet-size devices. On @@ -65,19 +64,15 @@ import com.google.zxing.client.android.BuildConfig; * item details side-by-side using two vertical panes. */ public class DrugListActivity extends AppCompatActivity { - // Used for dev and debug - final Boolean DEMO = false; - + private static final String TAG = DrugListActivity.class.getName(); public final int CUSTOMIZED_REQUEST_CODE = 0x0000ffff; public final String BARCODE_FORMAT_NAME = "Barcode Format name"; public final String BARCODE_CONTENT = "Barcode Content"; - - private ActivityResultLauncher mBarcodeScannerLauncher; - private static final String TAG = DrugListActivity.class.getName(); - + // Used for dev and debug + final Boolean DEMO = false; public PrescriptionDatabase prescriptions; public MedicineDatabase medicines; - + private ActivityResultLauncher mBarcodeScannerLauncher; private List prescriptionList; // used for prescriptions private RecyclerViewAdapter mAdapter; @@ -86,7 +81,7 @@ public class DrugListActivity extends AppCompatActivity { public void onStart() { super.onStart(); - if(BuildConfig.DEBUG) { + if (BuildConfig.DEBUG) { String manufacturer = Build.MANUFACTURER; String model = Build.MODEL; int version = Build.VERSION.SDK_INT; @@ -108,13 +103,13 @@ public class DrugListActivity extends AppCompatActivity { // Manually migrate old database to room PrescriptionsDAO prescriptionsDAO = prescriptions.getPrescriptionsDAO(); DBHelper dbHelper = new DBHelper(this); - if (dbHelper.getCount() !=0) { - List drugs=dbHelper.getAllDrugs(); - for (int count=0; count < dbHelper.getCount(); count++) { + if (dbHelper.getCount() != 0) { + List drugs = dbHelper.getAllDrugs(); + for (int count = 0; count < dbHelper.getCount(); count++) { Drug drug = drugs.get(count); Prescription prescription = new Prescription(); - if(prescriptionsDAO.getMedicByCIP13(drug.getCip13()) == null) { + if (prescriptionsDAO.getMedicByCIP13(drug.getCip13()) == null) { prescription.setName(drug.getName()); prescription.setCip13(drug.getCip13()); prescription.setCis(drug.getCis()); @@ -127,8 +122,7 @@ public class DrugListActivity extends AppCompatActivity { prescription.setLast_update(drug.getDateLastUpdate()); prescriptionsDAO.insert(prescription); - } - else { + } else { Log.i(TAG, "Already in the database"); } } @@ -142,10 +136,10 @@ public class DrugListActivity extends AppCompatActivity { } // start tutorial (only in non debug mode) - // if(!net.foucry.pilldroid.BuildConfig.DEBUG) { - Log.i(TAG, "Launch tutorial"); - startActivity(new Intent(this, WelcomeActivity.class)); - // } + // if(!net.foucry.pilldroid.BuildConfig.DEBUG) { + Log.i(TAG, "Launch tutorial"); + startActivity(new Intent(this, WelcomeActivity.class)); + // } PrefManager prefManager = new PrefManager(this); if (!prefManager.isUnderstood()) { @@ -165,11 +159,12 @@ public class DrugListActivity extends AppCompatActivity { super.onPause(); Log.d(TAG, "onPause"); - if (!AlarmReceiver.isAlarmScheduled(this)){ + if (!AlarmReceiver.isAlarmScheduled(this)) { AlarmReceiver.scheduleAlarm(this); } } + @SuppressLint("NotifyDataSetChanged") @Override public void onCreate(Bundle savedInstanceState) { @@ -192,33 +187,33 @@ public class DrugListActivity extends AppCompatActivity { } if (DEMO) { - PrescriptionsDAO prescriptionsDAO = prescriptions.getPrescriptionsDAO(); + PrescriptionsDAO prescriptionsDAO = prescriptions.getPrescriptionsDAO(); - if (prescriptionsDAO.getMedicCount() == 0) { - final int min_stock = 5; - final int max_stock = 50; - final int min_take = 0; - final int max_take = 3; + if (prescriptionsDAO.getMedicCount() == 0) { + final int min_stock = 5; + final int max_stock = 50; + final int min_take = 0; + final int max_take = 3; - for (int i = 1; i < 9; i++) { - Prescription prescription = new Prescription(); - prescription.setName("Medicament test " + i); - prescription.setCip13("340093000001" + i); - prescription.setCis("6000001" + i); - prescription.setAdministration_mode("oral"); - prescription.setPresentation("plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)"); - prescription.setStock((float) intRandomExclusive(min_stock, max_stock)); - prescription.setTake((float) intRandomExclusive(min_take, max_take)); - prescription.setWarning(14); - prescription.setAlert(7); - prescription.setLast_update(UtilDate.dateAtNoon(new Date()).getTime()); + for (int i = 1; i < 9; i++) { + Prescription prescription = new Prescription(); + prescription.setName("Medicament test " + i); + prescription.setCip13("340093000001" + i); + prescription.setCis("6000001" + i); + prescription.setAdministration_mode("oral"); + prescription.setPresentation("plaquette(s) thermoformée(s) PVC PVDC aluminium de 10 comprimé(s)"); + prescription.setStock((float) intRandomExclusive(min_stock, max_stock)); + prescription.setTake((float) intRandomExclusive(min_take, max_take)); + prescription.setWarning(14); + prescription.setAlert(7); + prescription.setLast_update(UtilDate.dateAtNoon(new Date()).getTime()); - prescriptionsDAO.insert(prescription); - } - List prescriptions = prescriptionsDAO.getAllMedics(); - System.out.println(prescriptions); - Log.d(TAG, "prescriptions ==" + prescriptions); - } + prescriptionsDAO.insert(prescription); + } + List prescriptions = prescriptionsDAO.getAllMedics(); + System.out.println(prescriptions); + Log.d(TAG, "prescriptions ==" + prescriptions); + } } mBarcodeScannerLauncher = registerForActivityResult(new PilldroidScanContract(), @@ -336,7 +331,7 @@ public class DrugListActivity extends AppCompatActivity { options.addExtra(Intents.Scan.SCAN_TYPE, Intents.Scan.MIXED_SCAN); options.addExtra(Intents.Scan.SCAN_TYPE, Intents.Scan.INVERTED_SCAN); - Log.d(TAG, "scanOptions == " + options); + Log.d(TAG, "scanOptions == " + options); mBarcodeScannerLauncher.launch(options); } @@ -369,10 +364,12 @@ public class DrugListActivity extends AppCompatActivity { editText.addTextChangedListener(new TextWatcher() { @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) { } + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + } @Override - public void onTextChanged(CharSequence s, int start, int before, int count) { } + public void onTextChanged(CharSequence s, int start, int before, int count) { + } @Override public void afterTextChanged(Editable s) { @@ -460,6 +457,7 @@ public class DrugListActivity extends AppCompatActivity { startActivityForResult(intent, CUSTOMIZED_REQUEST_CODE); overridePendingTransition(R.anim.slide_from_right, R.anim.slide_to_left); } + /** * setupRecyclerView (list of drugs) * @@ -470,7 +468,7 @@ public class DrugListActivity extends AppCompatActivity { mAdapter = new RecyclerViewAdapter(prescriptionList); recyclerView.setAdapter(mAdapter); - new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(0, (ItemTouchHelper.RIGHT|ItemTouchHelper.LEFT)) { + new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(0, (ItemTouchHelper.RIGHT | ItemTouchHelper.LEFT)) { @Override public boolean onMove(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder target) { return false; @@ -492,80 +490,90 @@ public class DrugListActivity extends AppCompatActivity { } else { // Call DetailView Intent intent = new Intent(getApplicationContext(), DrugDetailActivity.class); - intent.putExtra("prescription", prescription); + intent.putExtra("prescription", prescription); startActivityForResult(intent, CUSTOMIZED_REQUEST_CODE); } Snackbar.make(recyclerView, prescription.getName(), Snackbar.LENGTH_LONG).setAction(R.string.Undo, new View.OnClickListener() { - @Override + @Override public void onClick(View v) { - prescriptionList.add(position, prescription); - mAdapter.notifyItemInserted(position); - } - }).show(); - } - - @Override - public void onChildDraw(@NonNull Canvas c, @NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) { - if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) { - // Get RecyclerView item from the ViewHolder - View itemView = viewHolder.itemView; - - Paint p = new Paint(); - Drawable icon; - icon = ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_trash_can_outline); - - int xMarkMargin = (int) getApplicationContext().getResources().getDimension(R.dimen.fab_margin); - - assert icon != null; - int intrinsicWidth = icon.getIntrinsicWidth(); - int intrinsicHeight = icon.getIntrinsicHeight(); - int itemHeight = itemView.getBottom() - itemView.getTop(); - - if (dX > 0) { - p.setColor(getColor(R.color.bg_screen3)); - icon = ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_edit_black_48dp); - - // Draw Rect with varying right side, equal to displacement dX - c.drawRect((float) itemView.getLeft(), (float) itemView.getTop(), dX, - (float) itemView.getBottom(), p); - - int xMarkLeft = itemView.getLeft() + xMarkMargin; - int xMarkRight = itemView.getLeft() + xMarkMargin + intrinsicWidth; - int xMarkTop = itemView.getTop() + (itemHeight - intrinsicHeight) / 2; - int xMarkBottom = xMarkTop + intrinsicHeight;// +xMarkTop; - assert icon != null; - icon.setBounds(xMarkLeft, xMarkTop, xMarkRight, xMarkBottom); - - } else { - p.setColor(getColor(R.color.bg_screen4)); - // Draw Rect with varying left side, equal to the item's right side plus negative displacement dX - c.drawRect((float) itemView.getRight() + dX, (float) itemView.getTop(), - (float) itemView.getRight(), (float) itemView.getBottom(), p); - - - int xMarkLeft = itemView.getRight() - xMarkMargin - intrinsicWidth; - int xMarkRight = itemView.getRight() - xMarkMargin; - int xMarkTop = itemView.getTop() + (itemHeight - intrinsicHeight) / 2; - int xMarkBottom = xMarkTop + intrinsicHeight; - icon.setBounds(xMarkLeft, xMarkTop, xMarkRight, xMarkBottom); - - } - icon.draw(c); - - super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive); + prescriptionList.add(position, prescription); + mAdapter.notifyItemInserted(position); } + }).show(); + } + + @Override + public void onChildDraw(@NonNull Canvas c, @NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) { + if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) { + // Get RecyclerView item from the ViewHolder + View itemView = viewHolder.itemView; + + Paint p = new Paint(); + Drawable icon; + icon = ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_trash_can_outline); + + int xMarkMargin = (int) getApplicationContext().getResources().getDimension(R.dimen.fab_margin); + + assert icon != null; + int intrinsicWidth = icon.getIntrinsicWidth(); + int intrinsicHeight = icon.getIntrinsicHeight(); + int itemHeight = itemView.getBottom() - itemView.getTop(); + + if (dX > 0) { + p.setColor(getColor(R.color.bg_screen3)); + icon = ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_edit_black_48dp); + + // Draw Rect with varying right side, equal to displacement dX + c.drawRect((float) itemView.getLeft(), (float) itemView.getTop(), dX, + (float) itemView.getBottom(), p); + + int xMarkLeft = itemView.getLeft() + xMarkMargin; + int xMarkRight = itemView.getLeft() + xMarkMargin + intrinsicWidth; + int xMarkTop = itemView.getTop() + (itemHeight - intrinsicHeight) / 2; + int xMarkBottom = xMarkTop + intrinsicHeight;// +xMarkTop; + assert icon != null; + icon.setBounds(xMarkLeft, xMarkTop, xMarkRight, xMarkBottom); + + } else { + p.setColor(getColor(R.color.bg_screen4)); + // Draw Rect with varying left side, equal to the item's right side plus negative displacement dX + c.drawRect((float) itemView.getRight() + dX, (float) itemView.getTop(), + (float) itemView.getRight(), (float) itemView.getBottom(), p); + + + int xMarkLeft = itemView.getRight() - xMarkMargin - intrinsicWidth; + int xMarkRight = itemView.getRight() - xMarkMargin; + int xMarkTop = itemView.getTop() + (itemHeight - intrinsicHeight) / 2; + int xMarkBottom = xMarkTop + intrinsicHeight; + icon.setBounds(xMarkLeft, xMarkTop, xMarkRight, xMarkBottom); + + } + icon.draw(c); + + super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive); } + } }).attachToRecyclerView(recyclerView); - } + } + + private String getAppName() { + PackageManager packageManager = getApplicationContext().getPackageManager(); + ApplicationInfo applicationInfo = null; + try { + applicationInfo = packageManager.getApplicationInfo(this.getPackageName(), 0); + } catch (final PackageManager.NameNotFoundException ignored) { + } + return (String) ((applicationInfo != null) ? packageManager.getApplicationLabel(applicationInfo) : "???"); + } /** * SimpleItemRecyclerViewAdapter */ public class RecyclerViewAdapter extends - RecyclerView.Adapter { + RecyclerView.Adapter { private final List mValues; @@ -626,7 +634,7 @@ public class DrugListActivity extends AppCompatActivity { Prescription aPrescription = mValues.get(position); Context context = v.getContext(); Intent intent = new Intent(context, DrugDetailActivity.class); - intent.putExtra("prescription", aPrescription); + intent.putExtra("prescription", aPrescription); startActivityForResult(intent, CUSTOMIZED_REQUEST_CODE); overridePendingTransition(R.anim.slide_from_right, R.anim.slide_to_left); @@ -687,14 +695,4 @@ public class DrugListActivity extends AppCompatActivity { } } } - - private String getAppName() { - PackageManager packageManager = getApplicationContext().getPackageManager(); - ApplicationInfo applicationInfo = null; - try { - applicationInfo = packageManager.getApplicationInfo(this.getPackageName(), 0); - } catch (final PackageManager.NameNotFoundException ignored) { - } - return (String) ((applicationInfo != null) ? packageManager.getApplicationLabel(applicationInfo) : "???"); - } } diff --git a/app/src/main/java/net/foucry/pilldroid/PilldroidScanContract.java b/app/src/main/java/net/foucry/pilldroid/PilldroidScanContract.java index 8c8478a..4be8727 100644 --- a/app/src/main/java/net/foucry/pilldroid/PilldroidScanContract.java +++ b/app/src/main/java/net/foucry/pilldroid/PilldroidScanContract.java @@ -13,23 +13,24 @@ import com.journeyapps.barcodescanner.ScanIntentResult; import com.journeyapps.barcodescanner.ScanOptions; -public class PilldroidScanContract extends ActivityResultContract{ - private static final String TAG = PilldroidScanContract.class.getName(); - @NonNull - @Override - public Intent createIntent(@NonNull Context context, ScanOptions input) { - Log.d(TAG, "create Intent"); +public class PilldroidScanContract extends ActivityResultContract { + private static final String TAG = PilldroidScanContract.class.getName(); - Intent intent = new Intent(context, CustomScannerActivity.class); + @NonNull + @Override + public Intent createIntent(@NonNull Context context, ScanOptions input) { + Log.d(TAG, "create Intent"); - intent.setAction(Intents.Scan.ACTION); + Intent intent = new Intent(context, CustomScannerActivity.class); - Log.d(TAG, "intent ==" + intent); - return(intent); - } + intent.setAction(Intents.Scan.ACTION); - @Override - public ScanIntentResult parseResult(int resultCode, @Nullable Intent intent) { - return ScanIntentResult.parseActivityResult(resultCode, intent); - } + Log.d(TAG, "intent ==" + intent); + return (intent); + } + + @Override + public ScanIntentResult parseResult(int resultCode, @Nullable Intent intent) { + return ScanIntentResult.parseActivityResult(resultCode, intent); + } } diff --git a/app/src/main/java/net/foucry/pilldroid/PrefManager.java b/app/src/main/java/net/foucry/pilldroid/PrefManager.java index 8d0989d..6e2429c 100644 --- a/app/src/main/java/net/foucry/pilldroid/PrefManager.java +++ b/app/src/main/java/net/foucry/pilldroid/PrefManager.java @@ -4,49 +4,51 @@ package net.foucry.pilldroid; import android.content.Context; import android.content.SharedPreferences; - /** - * Created by Lincoln on 05/05/16. - */ - public class PrefManager { - final SharedPreferences pref; - SharedPreferences.Editor editor; +/** + * Created by Lincoln on 05/05/16. + */ +public class PrefManager { + // Shared preferences file name + private static final String PREF_NAME = "Pildroid-Prefs"; + private static final String IS_FIRST_TIME_LAUNCH = "IsFirstTimeLaunch"; + private static final String DATABASE_VERSION = "DatabaseVersion"; + private static final String IS_UNDERSTOOD = "IsUnderStood"; + final SharedPreferences pref; + // shared pref mode + final int PRIVATE_MODE = 0; + SharedPreferences.Editor editor; - // shared pref mode - final int PRIVATE_MODE = 0; - - // Shared preferences file name - private static final String PREF_NAME = "Pildroid-Prefs"; - private static final String IS_FIRST_TIME_LAUNCH = "IsFirstTimeLaunch"; - private static final String DATABASE_VERSION = "DatabaseVersion"; - private static final String IS_UNDERSTOOD = "IsUnderStood"; - - public PrefManager(Context context) { - pref = context.getSharedPreferences(PREF_NAME, PRIVATE_MODE); - } - - public void setFirstTimeLaunch(boolean isFirstTime) { - editor = pref.edit(); - editor.putBoolean(IS_FIRST_TIME_LAUNCH, isFirstTime); - editor.apply(); - } - - public void setDatabaseVersion(int version) { - editor = pref.edit(); - editor.putInt(DATABASE_VERSION, version); - editor.apply(); - } - - public void setUnderstood(boolean isUnderstood) { - editor = pref.edit(); - editor.putBoolean(IS_UNDERSTOOD, isUnderstood); - editor.apply(); - } - - public boolean isFirstTimeLaunch() { - return pref.getBoolean(IS_FIRST_TIME_LAUNCH, true); - } - public int getDatabaseVersion() { - return pref.getInt(DATABASE_VERSION, 0); - } - public boolean isUnderstood() {return pref.getBoolean(IS_UNDERSTOOD, false); } + public PrefManager(Context context) { + pref = context.getSharedPreferences(PREF_NAME, PRIVATE_MODE); } + + public boolean isFirstTimeLaunch() { + return pref.getBoolean(IS_FIRST_TIME_LAUNCH, true); + } + + public void setFirstTimeLaunch(boolean isFirstTime) { + editor = pref.edit(); + editor.putBoolean(IS_FIRST_TIME_LAUNCH, isFirstTime); + editor.apply(); + } + + public int getDatabaseVersion() { + return pref.getInt(DATABASE_VERSION, 0); + } + + public void setDatabaseVersion(int version) { + editor = pref.edit(); + editor.putInt(DATABASE_VERSION, version); + editor.apply(); + } + + public boolean isUnderstood() { + return pref.getBoolean(IS_UNDERSTOOD, false); + } + + public void setUnderstood(boolean isUnderstood) { + editor = pref.edit(); + editor.putBoolean(IS_UNDERSTOOD, isUnderstood); + editor.apply(); + } +} diff --git a/app/src/main/java/net/foucry/pilldroid/UtilDate.java b/app/src/main/java/net/foucry/pilldroid/UtilDate.java index 9a67307..37595dc 100644 --- a/app/src/main/java/net/foucry/pilldroid/UtilDate.java +++ b/app/src/main/java/net/foucry/pilldroid/UtilDate.java @@ -86,11 +86,12 @@ public class UtilDate { Date oldDate = dateAtNoon(date); // Be sure that the old date is at Noon Date todayDate = dateAtNoon(new Date()); // Be sure that we use today at Noon - return (int) (todayDate.getTime() - oldDate.getTime())/(86400*1000); + return (int) (todayDate.getTime() - oldDate.getTime()) / (86400 * 1000); } /** * Convert dateInMilliseconds into string formatted date + * * @param dateInMilliseconds long * @return formatted Date String */ diff --git a/app/src/main/java/net/foucry/pilldroid/Utils.java b/app/src/main/java/net/foucry/pilldroid/Utils.java index b5b65ff..bca6971 100644 --- a/app/src/main/java/net/foucry/pilldroid/Utils.java +++ b/app/src/main/java/net/foucry/pilldroid/Utils.java @@ -14,21 +14,21 @@ public class Utils { /** * Return a random number between two values - use to generate a false demo DB + * * @param min minimal value accepted * @param max maximum value accepted * @return int random number */ static int intRandomExclusive(int min, int max) { Random r = new Random(); - return r.nextInt(max - min) +max; + return r.nextInt(max - min) + max; } - public static String fmt(double d) - { - if(d == (long) d) - return String.format(Locale.getDefault(),"%d",(long)d); + public static String fmt(double d) { + if (d == (long) d) + return String.format(Locale.getDefault(), "%d", (long) d); else - return String.format("%s",d); + return String.format("%s", d); } public static Prescription medicine2prescription(Medicine aMedicine) { diff --git a/app/src/main/java/net/foucry/pilldroid/WelcomeActivity.java b/app/src/main/java/net/foucry/pilldroid/WelcomeActivity.java index 43791a2..9cc4f3a 100644 --- a/app/src/main/java/net/foucry/pilldroid/WelcomeActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/WelcomeActivity.java @@ -27,6 +27,35 @@ public class WelcomeActivity extends AppCompatActivity { private LinearLayout dotsLayout; private int[] layouts; private Button btnSkip, btnNext; + // viewpager change listener + final ViewPager.OnPageChangeListener viewPagerPageChangeListener = new ViewPager.OnPageChangeListener() { + + @Override + public void onPageSelected(int position) { + addBottomDots(position); + + // changing the next button text 'NEXT' / 'GOT IT' + if (position == layouts.length - 1) { + // last page. make button text to GOT IT + btnNext.setText(getString(R.string.start)); + btnSkip.setVisibility(View.GONE); + } else { + // still pages are left + btnNext.setText(getString(R.string.next)); + btnSkip.setVisibility(View.VISIBLE); + } + } + + @Override + public void onPageScrolled(int arg0, float arg1, int arg2) { + + } + + @Override + public void onPageScrollStateChanged(int arg0) { + + } + }; private PrefManager prefManager; @Override @@ -49,10 +78,10 @@ public class WelcomeActivity extends AppCompatActivity { setFullScreen(); - viewPager = findViewById(R.id.view_pager); - dotsLayout = findViewById(R.id.layoutDots); - btnSkip = findViewById(R.id.btn_skip); - btnNext = findViewById(R.id.btn_next); + viewPager = findViewById(R.id.view_pager); + dotsLayout = findViewById(R.id.layoutDots); + btnSkip = findViewById(R.id.btn_skip); + btnNext = findViewById(R.id.btn_next); // layouts of all welcome sliders @@ -131,36 +160,6 @@ public class WelcomeActivity extends AppCompatActivity { finish(); } - // viewpager change listener - final ViewPager.OnPageChangeListener viewPagerPageChangeListener = new ViewPager.OnPageChangeListener() { - - @Override - public void onPageSelected(int position) { - addBottomDots(position); - - // changing the next button text 'NEXT' / 'GOT IT' - if (position == layouts.length - 1) { - // last page. make button text to GOT IT - btnNext.setText(getString(R.string.start)); - btnSkip.setVisibility(View.GONE); - } else { - // still pages are left - btnNext.setText(getString(R.string.next)); - btnSkip.setVisibility(View.VISIBLE); - } - } - - @Override - public void onPageScrolled(int arg0, float arg1, int arg2) { - - } - - @Override - public void onPageScrollStateChanged(int arg0) { - - } - }; - /** * Making notification bar transparent */ @@ -170,16 +169,15 @@ public class WelcomeActivity extends AppCompatActivity { window.setStatusBarColor(Color.TRANSPARENT); } - private void setFullScreen(){ + private void setFullScreen() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { getWindow().setDecorFitsSystemWindows(false); WindowInsetsController controller = getWindow().getInsetsController(); - if(controller != null) { + if (controller != null) { controller.hide(WindowInsets.Type.statusBars() | WindowInsets.Type.navigationBars()); controller.setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE); } - } - else { + } else { //noinspection getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_FULLSCREEN diff --git a/app/src/main/java/net/foucry/pilldroid/dao/PrescriptionsDAO.java b/app/src/main/java/net/foucry/pilldroid/dao/PrescriptionsDAO.java index 969ac4a..4eb920a 100644 --- a/app/src/main/java/net/foucry/pilldroid/dao/PrescriptionsDAO.java +++ b/app/src/main/java/net/foucry/pilldroid/dao/PrescriptionsDAO.java @@ -12,23 +12,23 @@ import java.util.List; @Dao public interface PrescriptionsDAO { - @Insert - void insert(Prescription... prescriptions); + @Insert + void insert(Prescription... prescriptions); - @Update - void update(Prescription... prescriptions); + @Update + void update(Prescription... prescriptions); - @Delete - void delete(Prescription prescription); + @Delete + void delete(Prescription prescription); - @Query("SELECT * FROM prescriptions") - List getAllMedics(); + @Query("SELECT * FROM prescriptions") + List getAllMedics(); - @Query("SELECT * FROM prescriptions WHERE cip13 = :cip13") - Prescription getMedicByCIP13(String cip13); + @Query("SELECT * FROM prescriptions WHERE cip13 = :cip13") + Prescription getMedicByCIP13(String cip13); - @Query("SELECT count(*) FROM prescriptions") - int getMedicCount(); + @Query("SELECT count(*) FROM prescriptions") + int getMedicCount(); } diff --git a/app/src/main/java/net/foucry/pilldroid/databases/MedicineDatabase.java b/app/src/main/java/net/foucry/pilldroid/databases/MedicineDatabase.java index 0f50517..763ce18 100644 --- a/app/src/main/java/net/foucry/pilldroid/databases/MedicineDatabase.java +++ b/app/src/main/java/net/foucry/pilldroid/databases/MedicineDatabase.java @@ -16,7 +16,7 @@ import net.foucry.pilldroid.models.Medicine; public abstract class MedicineDatabase extends RoomDatabase { private static MedicineDatabase INSTANCE; - public abstract MedicinesDAO getMedicinesDAO(); + public static MedicineDatabase getInstanceDatabase(Context context) { if (INSTANCE == null) { INSTANCE = @@ -32,4 +32,6 @@ public abstract class MedicineDatabase extends RoomDatabase { public static void destroyInstance() { INSTANCE = null; } + + public abstract MedicinesDAO getMedicinesDAO(); } \ No newline at end of file diff --git a/app/src/main/java/net/foucry/pilldroid/databases/PrescriptionDatabase.java b/app/src/main/java/net/foucry/pilldroid/databases/PrescriptionDatabase.java index 406f05e..10e826e 100644 --- a/app/src/main/java/net/foucry/pilldroid/databases/PrescriptionDatabase.java +++ b/app/src/main/java/net/foucry/pilldroid/databases/PrescriptionDatabase.java @@ -13,38 +13,40 @@ import net.foucry.pilldroid.dao.PrescriptionsDAO; import net.foucry.pilldroid.models.Prescription; @Database( - version = 2, - entities = {Prescription.class}, - autoMigrations = { - @AutoMigration( - from = 1, - to = 2, - spec = PrescriptionDatabase.generic_typeMigration.class - ) - } + version = 2, + entities = {Prescription.class}, + autoMigrations = { + @AutoMigration( + from = 1, + to = 2, + spec = PrescriptionDatabase.generic_typeMigration.class + ) + } ) public abstract class PrescriptionDatabase extends RoomDatabase { private static PrescriptionDatabase INSTANCE; - public abstract PrescriptionsDAO getPrescriptionsDAO(); - - @RenameColumn(tableName = "prescriptions", fromColumnName = "genetic_type", toColumnName = "generic_type") - static class generic_typeMigration implements AutoMigrationSpec { } - public static PrescriptionDatabase getInstanceDatabase(Context context) { if (INSTANCE == null) { INSTANCE = - Room - .databaseBuilder(context.getApplicationContext(), - PrescriptionDatabase.class, "prescriptions") - .allowMainThreadQueries() - .build(); + Room + .databaseBuilder(context.getApplicationContext(), + PrescriptionDatabase.class, "prescriptions") + .allowMainThreadQueries() + .build(); } return INSTANCE; } + public static void destroyInstance() { INSTANCE = null; } + + public abstract PrescriptionsDAO getPrescriptionsDAO(); + + @RenameColumn(tableName = "prescriptions", fromColumnName = "genetic_type", toColumnName = "generic_type") + static class generic_typeMigration implements AutoMigrationSpec { + } } diff --git a/app/src/main/java/net/foucry/pilldroid/models/Medicine.java b/app/src/main/java/net/foucry/pilldroid/models/Medicine.java index 1fd10be..ec69cd1 100644 --- a/app/src/main/java/net/foucry/pilldroid/models/Medicine.java +++ b/app/src/main/java/net/foucry/pilldroid/models/Medicine.java @@ -7,14 +7,15 @@ import androidx.room.PrimaryKey; @Entity(tableName = "drugs") public class Medicine { @PrimaryKey - @NonNull private Integer _id; - private String cis; - private String cip13; - private String cip7; - private String administration_mode; - private String name; - private String presentation; - private String label_group; + @NonNull + private Integer _id; + private String cis; + private String cip13; + private String cip7; + private String administration_mode; + private String name; + private String presentation; + private String label_group; private Integer generic_type; public Medicine(@NonNull String cis) { diff --git a/app/src/main/java/net/foucry/pilldroid/models/Prescription.java b/app/src/main/java/net/foucry/pilldroid/models/Prescription.java index 7ce3ea9..75df514 100644 --- a/app/src/main/java/net/foucry/pilldroid/models/Prescription.java +++ b/app/src/main/java/net/foucry/pilldroid/models/Prescription.java @@ -1,8 +1,5 @@ package net.foucry.pilldroid.models; -import android.util.Log; -import android.widget.Toast; - import androidx.annotation.NonNull; import androidx.room.Entity; import androidx.room.PrimaryKey; @@ -15,7 +12,7 @@ import java.util.Date; @Entity(tableName = "prescriptions") public class Prescription implements Serializable { - private static final String TAG = Prescription.class.getName();; + private static final String TAG = Prescription.class.getName(); @PrimaryKey @NonNull private String cis; @@ -31,87 +28,87 @@ public class Prescription implements Serializable { private String label_group; private Integer generic_type; - public void setCis(@NonNull String cis) { - this.cis = cis; - } - - public void setCip13(String cip13) { - this.cip13 = cip13; - } - - public void setName(String name) { - this.name = name; - } - - public void setAdministration_mode(String administration_mode) { - this.administration_mode = administration_mode; - } - - public void setPresentation(String presentation) { - this.presentation = presentation; - } - - public void setStock(Float stock) { - this.stock = stock; - } - - public void setTake(Float take) { - this.take = take; - } - - public void setWarning(Integer warning) { - this.warning = warning; - } - - public void setAlert(Integer alert) { - this.alert = alert; - } - - public void setLast_update(Long last_update) { - this.last_update = last_update; - } - @NonNull public String getCis() { return this.cis; } + public void setCis(@NonNull String cis) { + this.cis = cis; + } + public Integer getWarning() { return warning; } + public void setWarning(Integer warning) { + this.warning = warning; + } + public String getCip13() { return cip13; } + public void setCip13(String cip13) { + this.cip13 = cip13; + } + public String getName() { return name; } + public void setName(String name) { + this.name = name; + } + public String getAdministration_mode() { return administration_mode; } + public void setAdministration_mode(String administration_mode) { + this.administration_mode = administration_mode; + } + public String getPresentation() { return presentation; } + public void setPresentation(String presentation) { + this.presentation = presentation; + } + public Float getStock() { return stock; } + public void setStock(Float stock) { + this.stock = stock; + } + public Float getTake() { return take; } + public void setTake(Float take) { + this.take = take; + } + public Integer getAlert() { return alert; } + public void setAlert(Integer alert) { + this.alert = alert; + } + public Long getLast_update() { return last_update; } + public void setLast_update(Long last_update) { + this.last_update = last_update; + } + public int getAlertThreshold() { return this.alert; } diff --git a/app/src/main/res/anim/slide_from_left.xml b/app/src/main/res/anim/slide_from_left.xml index e28db8a..084e18e 100644 --- a/app/src/main/res/anim/slide_from_left.xml +++ b/app/src/main/res/anim/slide_from_left.xml @@ -1,6 +1,8 @@ - + android:toXDelta="0" /> \ No newline at end of file diff --git a/app/src/main/res/anim/slide_from_right.xml b/app/src/main/res/anim/slide_from_right.xml index b4224a5..ca260c8 100644 --- a/app/src/main/res/anim/slide_from_right.xml +++ b/app/src/main/res/anim/slide_from_right.xml @@ -1,6 +1,8 @@ - + android:toXDelta="0" /> \ No newline at end of file diff --git a/app/src/main/res/anim/slide_to_left.xml b/app/src/main/res/anim/slide_to_left.xml index 4e9dc22..00190ff 100644 --- a/app/src/main/res/anim/slide_to_left.xml +++ b/app/src/main/res/anim/slide_to_left.xml @@ -1,6 +1,6 @@ - + android:toXDelta="-100%p"/> \ No newline at end of file diff --git a/app/src/main/res/anim/slide_to_right.xml b/app/src/main/res/anim/slide_to_right.xml index 1d73b17..705daa9 100644 --- a/app/src/main/res/anim/slide_to_right.xml +++ b/app/src/main/res/anim/slide_to_right.xml @@ -1,6 +1,8 @@ - + android:toXDelta="100%p" /> \ No newline at end of file diff --git a/app/src/main/res/layout/about.xml b/app/src/main/res/layout/about.xml index e45cf76..51b7569 100644 --- a/app/src/main/res/layout/about.xml +++ b/app/src/main/res/layout/about.xml @@ -1,9 +1,10 @@ + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools"> - + app:zxing_framing_rect_height="150dp" + app:zxing_framing_rect_width="300dp"> + app:zxing_viewfinder_mask="@color/grey" /> diff --git a/app/src/main/res/layout/drug_detail.xml b/app/src/main/res/layout/drug_detail.xml index 1592f83..dc7a32e 100644 --- a/app/src/main/res/layout/drug_detail.xml +++ b/app/src/main/res/layout/drug_detail.xml @@ -8,43 +8,43 @@ + android:layout_height="match_parent" /> - + android:layout_height="match_parent" /> + - + android:layout_height="match_parent" /> + - + android:layout_height="wrap_content" /> + + android:layout_height="wrap_content" /> - + android:layout_height="wrap_content" /> + + app:backgroundTint="@android:color/transparent" /> diff --git a/app/src/main/res/layout/drug_list.xml b/app/src/main/res/layout/drug_list.xml index d798d15..a831757 100644 --- a/app/src/main/res/layout/drug_list.xml +++ b/app/src/main/res/layout/drug_list.xml @@ -6,7 +6,7 @@ android:name="net.foucry.pilldroid.MedicamentListFragment" android:layout_width="match_parent" android:layout_height="match_parent" - app:layoutManager="LinearLayoutManager" android:background="@drawable/list_selector" + app:layoutManager="LinearLayoutManager" tools:context="net.foucry.pilldroid.DrugListActivity" tools:listitem="@layout/drug_list_content" /> diff --git a/app/src/main/res/layout/drug_list_activity.xml b/app/src/main/res/layout/drug_list_activity.xml index 0664590..146258b 100644 --- a/app/src/main/res/layout/drug_list_activity.xml +++ b/app/src/main/res/layout/drug_list_activity.xml @@ -29,8 +29,8 @@ + android:layout_width="match_parent" + android:layout_height="match_parent" /> @@ -45,11 +45,11 @@ android:backgroundTint="@android:color/transparent" android:baselineAlignBottom="false" android:clickable="false" + android:contentDescription="@string/add_button" android:onClick="onButtonClick" android:src="@drawable/ic_add_circle_black_24dp" app:backgroundTint="@android:color/darker_gray" app:fabCustomSize="60dp" app:maxImageSize="60dp" - android:contentDescription="@string/add_button" tools:ignore="OnClick" /> diff --git a/app/src/main/res/layout/drug_list_content.xml b/app/src/main/res/layout/drug_list_content.xml index 93a2b46..7bef7bb 100644 --- a/app/src/main/res/layout/drug_list_content.xml +++ b/app/src/main/res/layout/drug_list_content.xml @@ -13,24 +13,24 @@ android:id="@+id/list_image" android:layout_width="50sp" android:layout_height="50sp" - android:layout_marginStart="5dp" - android:src="@drawable/ok_stock_vect" - android:contentDescription="@string/stockIcon" + android:layout_alignParentStart="true" android:layout_centerVertical="true" - android:layout_alignParentStart="true" /> + android:layout_marginStart="5dp" + android:contentDescription="@string/stockIcon" + android:src="@drawable/ok_stock_vect" /> + android:typeface="sans" /> + android:background="@drawable/list_selector" + android:orientation="vertical"> + \ No newline at end of file diff --git a/app/src/main/res/layout/welcome_activity.xml b/app/src/main/res/layout/welcome_activity.xml index 2004232..1638869 100644 --- a/app/src/main/res/layout/welcome_activity.xml +++ b/app/src/main/res/layout/welcome_activity.xml @@ -19,20 +19,19 @@ android:layout_alignParentBottom="true" android:layout_marginBottom="@dimen/dots_margin_bottom" android:gravity="center" - android:orientation="horizontal"> - + android:orientation="horizontal">