From 55ae65d122cd2048b771cbe912d46404ef0bd766 Mon Sep 17 00:00:00 2001 From: oliexdev Date: Mon, 27 Feb 2023 09:02:58 +0100 Subject: [PATCH] - rename exportDir to backupDir so we don't have conflict during an openScale version update with old stored shared preferences values, see #932 with the PR #924 - fixed notification icon --- .../core/alarm/AlarmBackupHandler.java | 14 +++++++------- .../openscale/core/alarm/AlarmHandler.java | 18 +++++++----------- .../gui/preferences/BackupPreferences.java | 12 ++++++------ .../src/main/res/xml/backup_preferences.xml | 2 +- 4 files changed, 21 insertions(+), 25 deletions(-) diff --git a/android_app/app/src/main/java/com/health/openscale/core/alarm/AlarmBackupHandler.java b/android_app/app/src/main/java/com/health/openscale/core/alarm/AlarmBackupHandler.java index fbe8c2c3..d9c64a82 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/alarm/AlarmBackupHandler.java +++ b/android_app/app/src/main/java/com/health/openscale/core/alarm/AlarmBackupHandler.java @@ -91,16 +91,16 @@ public class AlarmBackupHandler SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - // Extra check that there is a exportDir saved in settings - String exportDirString = prefs.getString("exportDir", null); - if (exportDirString == null) { + // Extra check that there is a backupDir saved in settings + String backupDirString = prefs.getString("backupDir", null); + if (backupDirString == null) { return; } - DocumentFile exportDir = DocumentFile.fromTreeUri(context, Uri.parse(exportDirString)); + DocumentFile backupDir = DocumentFile.fromTreeUri(context, Uri.parse(backupDirString)); // Check if it is possible to read and write to auto export dir // If it is not possible auto backup function will be disabled - if (!exportDir.canRead() || !exportDir.canWrite()) { + if (!backupDir.canRead() || !backupDir.canWrite()) { SharedPreferences.Editor editor = prefs.edit(); editor.putBoolean("autoBackup", false); editor.apply(); @@ -112,9 +112,9 @@ public class AlarmBackupHandler databaseName = dateFormat.format(new Date()) + "_" + databaseName; } - DocumentFile exportFile = exportDir.findFile(databaseName); + DocumentFile exportFile = backupDir.findFile(databaseName); if (exportFile == null) { - exportFile = exportDir.createFile("application/x-sqlite3", databaseName); + exportFile = backupDir.createFile("application/x-sqlite3", databaseName); } try { diff --git a/android_app/app/src/main/java/com/health/openscale/core/alarm/AlarmHandler.java b/android_app/app/src/main/java/com/health/openscale/core/alarm/AlarmHandler.java index 68ee9777..67e5017e 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/alarm/AlarmHandler.java +++ b/android_app/app/src/main/java/com/health/openscale/core/alarm/AlarmHandler.java @@ -24,6 +24,7 @@ import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; +import android.graphics.BitmapFactory; import android.os.Build; import android.service.notification.StatusBarNotification; @@ -170,7 +171,8 @@ public class AlarmHandler notificationManager.createNotificationChannel(channel); } - Notification notification = mBuilder.setSmallIcon(R.drawable.ic_launcher_openscale) + Notification notification = mBuilder.setSmallIcon(R.drawable.ic_notification_openscale_monochrome) + .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher_openscale)) .setContentTitle(context.getString(R.string.app_name)) .setContentText(notifyText) .setAutoCancel(true) @@ -184,16 +186,10 @@ public class AlarmHandler private void cancelAlarmNotification(Context context) { NotificationManager mNotifyMgr = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) - { - StatusBarNotification[] activeNotifications = mNotifyMgr.getActiveNotifications(); - for (StatusBarNotification notification : activeNotifications) - { - if (notification.getId() == ALARM_NOTIFICATION_ID) mNotifyMgr.cancel(ALARM_NOTIFICATION_ID); - } + + StatusBarNotification[] activeNotifications = mNotifyMgr.getActiveNotifications(); + for (StatusBarNotification notification : activeNotifications) { + if (notification.getId() == ALARM_NOTIFICATION_ID) mNotifyMgr.cancel(ALARM_NOTIFICATION_ID); } - else mNotifyMgr.cancel(ALARM_NOTIFICATION_ID); } - - } diff --git a/android_app/app/src/main/java/com/health/openscale/gui/preferences/BackupPreferences.java b/android_app/app/src/main/java/com/health/openscale/gui/preferences/BackupPreferences.java index 1664f8d7..7fd39eb1 100644 --- a/android_app/app/src/main/java/com/health/openscale/gui/preferences/BackupPreferences.java +++ b/android_app/app/src/main/java/com/health/openscale/gui/preferences/BackupPreferences.java @@ -52,7 +52,7 @@ public class BackupPreferences extends PreferenceFragmentCompat implements Share private static final String PREFERENCE_KEY_IMPORT_BACKUP = "importBackup"; private static final String PREFERENCE_KEY_EXPORT_BACKUP = "exportBackup"; private static final String PREFERENCE_KEY_AUTO_BACKUP = "autoBackup"; - private static final String PREFERENCE_KEY_AUTO_BACKUP_DIR = "exportDir"; + private static final String PREFERENCE_KEY_AUTO_BACKUP_DIR = "backupDir"; private static final int IMPORT_DATA_REQUEST = 100; private static final int EXPORT_DATA_REQUEST = 101; @@ -92,7 +92,7 @@ public class BackupPreferences extends PreferenceFragmentCompat implements Share autoBackupDir = (Preference) findPreference(PREFERENCE_KEY_AUTO_BACKUP_DIR); autoBackupDir.setOnPreferenceClickListener(new onClickListenerAutoBackupDir()); // Setting auto backup preference's summary to location or message that none is selected - String autoBackupDirString = prefs.getString("exportDir", null); + String autoBackupDirString = prefs.getString("backupDir", null); autoBackupDir.setSummary(autoBackupDirString != null ? Uri.parse(autoBackupDirString).getLastPathSegment() : getString(R.string.label_auto_backup_lacation)); updateBackupPreferences(); @@ -147,8 +147,8 @@ public class BackupPreferences extends PreferenceFragmentCompat implements Share public boolean onPreferenceClick(Preference preference) { if (autoBackup.isChecked()) { autoBackup.setChecked(true); - // If exportDir location already saved user won't be prompted to select a new location - if (prefs.getString("exportDir", null) == null) { + // If backupDir location already saved user won't be prompted to select a new location + if (prefs.getString("backupDir", null) == null) { Toast.makeText(getContext(), R.string.info_select_auto_backup_export_dir, Toast.LENGTH_SHORT).show(); selectAutoBackupDir.launch(null); } @@ -180,10 +180,10 @@ public class BackupPreferences extends PreferenceFragmentCompat implements Share getActivity().getContentResolver().takePersistableUriPermission(result, Intent.FLAG_GRANT_READ_URI_PERMISSION|Intent.FLAG_GRANT_WRITE_URI_PERMISSION); autoBackupDir.setSummary(result.getLastPathSegment()); SharedPreferences.Editor editor = prefs.edit(); - editor.putString("exportDir", result.toString()); + editor.putString("backupDir", result.toString()); editor.commit(); } else { - if (prefs.getString("exportDir", null) == null) { + if (prefs.getString("backupDir", null) == null) { this.autoBackup.setChecked(false); } } diff --git a/android_app/app/src/main/res/xml/backup_preferences.xml b/android_app/app/src/main/res/xml/backup_preferences.xml index e08e361f..ff2e4f9e 100644 --- a/android_app/app/src/main/res/xml/backup_preferences.xml +++ b/android_app/app/src/main/res/xml/backup_preferences.xml @@ -5,7 +5,7 @@ - +