As suggested by @Jean-BaptisteC, reformatting code with Android Studio

This commit is contained in:
jacques 2022-08-03 19:02:25 +02:00
parent feb95329be
commit 9bb5e62c48
33 changed files with 561 additions and 569 deletions

View file

@ -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) {

View file

@ -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;
}
}

View file

@ -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();
}

View file

@ -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);

View file

@ -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<Drug> 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<Drug> 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<Drug>() {
@ -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;

View file

@ -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;

View file

@ -13,7 +13,7 @@ public class DrugDetailContract extends ActivityResultContract<Intent, Integer>
* 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<Intent, Integer>
/**
* Convert result obtained from to O
*
* @param resultCode Integer
* @param intent Intent
* @param intent Intent
* @return Integer
*/
@Override

View file

@ -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<ScanOptions> 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<ScanOptions> mBarcodeScannerLauncher;
private List<Prescription> 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<Drug> drugs=dbHelper.getAllDrugs();
for (int count=0; count < dbHelper.getCount(); count++) {
if (dbHelper.getCount() != 0) {
List<Drug> 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<Prescription> prescriptions = prescriptionsDAO.getAllMedics();
System.out.println(prescriptions);
Log.d(TAG, "prescriptions ==" + prescriptions);
}
prescriptionsDAO.insert(prescription);
}
List<Prescription> 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<RecyclerViewAdapter.ViewHolder> {
RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder> {
private final List<Prescription> 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) : "???");
}
}

View file

@ -13,23 +13,24 @@ import com.journeyapps.barcodescanner.ScanIntentResult;
import com.journeyapps.barcodescanner.ScanOptions;
public class PilldroidScanContract extends ActivityResultContract<ScanOptions, ScanIntentResult>{
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<ScanOptions, ScanIntentResult> {
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);
}
}

View file

@ -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();
}
}

View file

@ -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
*/

View file

@ -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) {

View file

@ -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

View file

@ -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<Prescription> getAllMedics();
@Query("SELECT * FROM prescriptions")
List<Prescription> 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();
}

View file

@ -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();
}

View file

@ -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 {
}
}

View file

@ -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) {

View file

@ -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;
}

View file

@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="-100%p" android:toXDelta="0"
<translate
android:duration="@integer/slide_animation_duration"
android:fromXDelta="-100%p"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:duration="@integer/slide_animation_duration"/>
android:toXDelta="0" />
</set>

View file

@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="100%p" android:toXDelta="0"
<translate
android:duration="@integer/slide_animation_duration"
android:fromXDelta="100%p"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:duration="@integer/slide_animation_duration"/>
android:toXDelta="0" />
</set>

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="0" android:toXDelta="-100%p"
<translate android:duration="@integer/slide_animation_duration" android:fromXDelta="0"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:duration="@integer/slide_animation_duration"/>
android:toXDelta="-100%p"/>
</set>

View file

@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="0" android:toXDelta="100%p"
<translate
android:duration="@integer/slide_animation_duration"
android:fromXDelta="0"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:duration="@integer/slide_animation_duration"/>
android:toXDelta="100%p" />
</set>

View file

@ -1,9 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:orientation="vertical"
tools:ignore="Overdraw">
<WebView

View file

@ -1,15 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<com.journeyapps.barcodescanner.BarcodeView
android:id="@+id/zxing_barcode_surface"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/zxing_barcode_surface"
app:zxing_framing_rect_width="300dp"
app:zxing_framing_rect_height="150dp">
</com.journeyapps.barcodescanner.BarcodeView>
app:zxing_framing_rect_height="150dp"
app:zxing_framing_rect_width="300dp"></com.journeyapps.barcodescanner.BarcodeView>
<com.journeyapps.barcodescanner.ViewfinderView
android:id="@+id/zxing_viewfinder_view"
@ -20,7 +19,7 @@
app:zxing_result_view="@color/zxing_custom_result_view"
app:zxing_viewfinder_laser="@color/zxing_custom_viewfinder_laser"
app:zxing_viewfinder_laser_visibility="true"
app:zxing_viewfinder_mask="@color/grey"/>
app:zxing_viewfinder_mask="@color/grey" />
<TextView
android:id="@+id/zxing_status_view"
@ -30,10 +29,10 @@
android:layout_marginTop="@dimen/app_bar_height"
android:background="@color/zxing_transparent"
android:fontFamily="sans-serif-black"
android:textSize="32sp"
android:textAlignment="center"
android:text="@string/zxing_msg_default_status"
android:textAlignment="center"
android:textColor="@color/white"
android:textSize="32sp"
tools:ignore="PrivateResource" />
<ImageButton

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="net.foucry.pilldroid.CustomScannerActivity">

View file

@ -8,43 +8,43 @@
<include
android:id="@+id/name_cell"
layout="@layout/info_cell"
android:layout_width="match_parent"
android:layout_height="match_parent"
layout="@layout/info_cell" />
android:layout_height="match_parent" />
<include
android:id="@+id/presentation_cell"
layout="@layout/info_cell"
android:layout_width="match_parent"
android:layout_height="match_parent"
layout="@layout/info_cell"/>
<!-- android:layout_marginTop="5sp" />-->
android:layout_height="match_parent" />
<!-- android:layout_marginTop="5sp" />-->
<include
android:id="@+id/administration_cell"
layout="@layout/info_cell"
android:layout_width="match_parent"
android:layout_height="match_parent"
layout="@layout/info_cell"/>
<!-- android:layout_marginTop="5sp" />-->
android:layout_height="match_parent" />
<!-- android:layout_marginTop="5sp" />-->
<include
android:id="@+id/stock_cell"
layout="@layout/value_input"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
layout="@layout/value_input"/>
<!-- android:layout_marginTop="30sp" />-->
android:layout_height="wrap_content" />
<!-- android:layout_marginTop="30sp" />-->
<include
android:id="@+id/take_cell"
layout="@layout/value_input"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
android:layout_height="wrap_content" />
<include
android:id="@+id/warning_cell"
layout="@layout/value_input"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
layout="@layout/value_input"/>
<!-- android:layout_marginTop="15sp" />-->
android:layout_height="wrap_content" />
<!-- android:layout_marginTop="15sp" />-->
<include
android:id="@+id/alert_cell"

View file

@ -49,9 +49,9 @@
android:layout_height="@dimen/fab_height"
android:layout_gravity="end|bottom"
android:layout_marginTop="?attr/actionBarSize"
android:layout_marginBottom="?attr/actionBarSize"
android:layout_marginEnd="@dimen/fab_margin"
android:layout_marginBottom="?attr/actionBarSize"
android:contentDescription="@string/save_button"
android:src="@drawable/ic_save_black_24dp"
app:backgroundTint="@android:color/transparent"/>
app:backgroundTint="@android:color/transparent" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View file

@ -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" />

View file

@ -29,8 +29,8 @@
<include
layout="@layout/drug_list"
android:layout_height="match_parent"
android:layout_width="match_parent"/>
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
@ -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" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View file

@ -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" />
<TextView
android:id="@+id/value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/list_image"
android:layout_marginStart="5dp"
android:layout_toEndOf="@+id/list_image"
android:text="@string/drugName"
android:textColor="#040404"
android:typeface="sans"
android:textSize="16sp"
android:textStyle="bold"
android:layout_alignTop="@+id/list_image"
android:layout_toEndOf="@+id/list_image"
android:layout_marginStart="5dp" />
android:typeface="sans" />
<TextView
android:id="@+id/endOfStock"

View file

@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/list_selector">
android:background="@drawable/list_selector"
android:orientation="vertical">
<TextView
android:id="@+id/value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="10sp"
android:paddingEnd="10sp"
android:paddingTop="5dp"
android:paddingEnd="10sp"
android:text="@string/Value"
android:textColor="#040404"
android:textSize="16sp"

View file

@ -3,10 +3,11 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/list_selector"
android:orientation="horizontal"
android:padding="10dp"
android:background="@drawable/list_selector"
android:weightSum="1">
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
@ -31,14 +32,14 @@
android:layout_alignParentEnd="true"
android:ems="10"
android:gravity="end|fill_vertical"
android:hint="@string/zero"
android:importantForAutofill="no"
android:inputType="numberDecimal"
android:labelFor="@id/value"
android:paddingEnd="25dp"
android:paddingStart="5dp"
android:hint="@string/zero"
android:textColorHint="@color/grey"
android:paddingEnd="25dp"
android:textAlignment="gravity"
android:importantForAutofill="no"
android:textColorHint="@color/grey"
tools:ignore="LabelFor" />
</RelativeLayout>

View file

@ -19,20 +19,19 @@
android:layout_alignParentBottom="true"
android:layout_marginBottom="@dimen/dots_margin_bottom"
android:gravity="center"
android:orientation="horizontal">
</LinearLayout>
android:orientation="horizontal"></LinearLayout>
<Button
android:id="@+id/btn_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginBottom="@dimen/dots_margin_bottom"
android:background="@null"
android:text="@string/next"
android:layout_marginBottom="@dimen/dots_margin_bottom"
android:textColor="@android:color/white"
tools:ignore="RelativeOverlap,RtlSymmetry"/>
tools:ignore="RelativeOverlap,RtlSymmetry" />
<Button
android:id="@+id/btn_skip"
@ -43,5 +42,5 @@
android:layout_marginBottom="@dimen/dots_margin_bottom"
android:background="@null"
android:text="@string/skip"
android:textColor="@android:color/white"/>
android:textColor="@android:color/white" />
</RelativeLayout>