Merge branch 'bugfix/Create_MainActivity' into develop

This commit is contained in:
jacques 2022-03-23 09:19:53 +01:00
commit 1ea57f813c
7 changed files with 74 additions and 46 deletions

View file

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

View file

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

View file

@ -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) : "???");
}
}

View file

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

View file

@ -1,8 +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_height="match_parent"
android:background="@android:color/white">
android:background="@android:color/white"
tools:ignore="Overdraw">
<WebView
android:id="@+id/aboutHtml"

View file

@ -66,4 +66,6 @@
<string name="notInterpreted">Le code barre ne peut pas être interprété</string>
<string name="cancelled_scan">Scan annulé</string>
<string name="missing_camera_permission">Permission appareil photo manquante</string>
<string name="Yes">Oui, j\'ai compris</string>
<string name="understood">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Ë.</string>
</resources>

View file

@ -68,4 +68,6 @@
<string name="notInterpreted">Barre code cannot be interpreted</string>
<string name="cancelled_scan">Scan canceled</string>
<string name="missing_camera_permission">Missing camera permission</string>
<string name="Yes">Yes, I understood</string>
<string name="understood">I understood that de developer of app_name cannot be responsible ot your medication management. IT\'S YOU OWN RESPONSIBILITY.</string>
</resources>