diff --git a/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java b/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java index c2fe9ca..7912308 100644 --- a/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java +++ b/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java @@ -148,4 +148,10 @@ public class AlarmReceiver extends BroadcastReceiver { 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/BarcodeValues.java b/app/src/main/java/net/foucry/pilldroid/BarcodeValues.java deleted file mode 100644 index 5c19af2..0000000 --- a/app/src/main/java/net/foucry/pilldroid/BarcodeValues.java +++ /dev/null @@ -1,23 +0,0 @@ -package net.foucry.pilldroid; - -public class BarcodeValues { - private final String mFormat; - private final String mContent; - - public BarcodeValues(String format, String content) { - mFormat = format; - mContent = content; - } - - public String format() { - return mFormat; - } - - public String content() { - return mContent; - } - - public boolean isEmpty() { - return mFormat == null && mContent == null; - } -} diff --git a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java index cfa8ee5..0366db2 100644 --- a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java @@ -79,7 +79,7 @@ public class DrugListActivity extends AppCompatActivity { public void onStart() { super.onStart(); - if(net.foucry.pilldroid.BuildConfig.DEBUG) { + if(BuildConfig.DEBUG) { String manufacturer = Build.MANUFACTURER; String model = Build.MODEL; int version = Build.VERSION.SDK_INT; @@ -92,12 +92,19 @@ public class DrugListActivity extends AppCompatActivity { ); } + // Create medicines Room database from drugs.db files medicines = Room .databaseBuilder(getApplicationContext(), MedicineDatabase.class, "medicines") .createFromAsset("drugs.db") .allowMainThreadQueries() .build(); + // Create prescriptions Room database + prescriptions = Room + .databaseBuilder(getApplicationContext(), PrescriptionDatabase.class, "prescriptions") + .allowMainThreadQueries() + .build(); + // Manually migrate old database to room PrescriptionsDAO prescriptionsDAO = prescriptions.getPrescriptionsDAO(); DBHelper dbHelper = new DBHelper(this); @@ -134,11 +141,19 @@ public class DrugListActivity extends AppCompatActivity { nm.cancelAll(); } - // start tutorial (only in non debug mode - if(!net.foucry.pilldroid.BuildConfig.DEBUG) { + // start tutorial (only in non debug mode) + // 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()) { + askForComprehensive(); + prefManager.setUnderstood(true); } + + } @Override @@ -146,9 +161,18 @@ public class DrugListActivity extends AppCompatActivity { super.onStop(); } + public void onPause() { + super.onPause(); + Log.d(TAG, "onPause"); + + if (!AlarmReceiver.isAlarmScheduled(this)){ + AlarmReceiver.scheduleAlarm(this); + } + + } @SuppressLint("NotifyDataSetChanged") @Override - protected void onCreate(Bundle savedInstanceState) { + public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Create Room database @@ -295,12 +319,6 @@ public class DrugListActivity extends AppCompatActivity { constructDrugsList(); } - public void onPause() { - super.onPause(); - Log.d(TAG, "onPause"); - AlarmReceiver.scheduleAlarm(this); - } - public void onResume() { super.onResume(); } @@ -343,7 +361,6 @@ public class DrugListActivity extends AppCompatActivity { MedicinesDAO medicineDAO = medicines.getMedicinesDAO(); Medicine aMedicine = medicineDAO.getMedicineByCIP13(cip13); - //Prescription aPrescription = medications.getDrugByCIP13(cip13); askToAddInDB(aMedicine); }) .setNegativeButton("Cancel", @@ -415,6 +432,21 @@ public class DrugListActivity extends AppCompatActivity { dlg.show(); } + /** + * askForCompréhensive + */ + private void askForComprehensive() { + AlertDialog.Builder dlg = new AlertDialog.Builder(this); + dlg.setTitle(getString(R.string.app_name)); + + dlg.setMessage(R.string.understood); + dlg.setPositiveButton(R.string.Yes, (dialog, which) -> { + // Nothing to do just dismiss dialog + }); + dlg.show(); + } + + /** * Add New drug to the user database * @@ -434,17 +466,6 @@ public class DrugListActivity extends AppCompatActivity { startActivityForResult(intent, CUSTOMIZED_REQUEST_CODE); overridePendingTransition(R.anim.slide_from_right, R.anim.slide_to_left); } - - 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) : "???"); - } - /** * setupRecyclerView (list of drugs) * @@ -581,4 +602,14 @@ 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/PrefManager.java b/app/src/main/java/net/foucry/pilldroid/PrefManager.java index 352df03..8d0989d 100644 --- a/app/src/main/java/net/foucry/pilldroid/PrefManager.java +++ b/app/src/main/java/net/foucry/pilldroid/PrefManager.java @@ -18,6 +18,7 @@ import android.content.SharedPreferences; 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); @@ -35,10 +36,17 @@ import android.content.SharedPreferences; 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); } } diff --git a/app/src/main/res/layout/about.xml b/app/src/main/res/layout/about.xml index 764c19e..e45cf76 100644 --- a/app/src/main/res/layout/about.xml +++ b/app/src/main/res/layout/about.xml @@ -1,8 +1,10 @@ + android:background="@android:color/white" + tools:ignore="Overdraw"> Le code barre ne peut pas être interprété Scan annulé Permission appareil photo manquante + Oui, j\'ai compris + Je comprend que le développeur de app_name n\'est pas responsable de la gestion de vos médicaments. CELA RELÈVE DE VOTRE SEULE RESPONSABILITË. \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d4070ac..64a23c9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -68,4 +68,6 @@ Barre code cannot be interpreted Scan canceled Missing camera permission + Yes, I understood + I understood that de developer of app_name cannot be responsible ot your medication management. IT\'S YOU OWN RESPONSIBILITY.