1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-13 12:14:19 +02:00

- 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
This commit is contained in:
oliexdev
2023-02-27 09:02:58 +01:00
parent 715874f8ec
commit 55ae65d122
4 changed files with 21 additions and 25 deletions

View File

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

View File

@@ -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)
{
for (StatusBarNotification notification : activeNotifications) {
if (notification.getId() == ALARM_NOTIFICATION_ID) mNotifyMgr.cancel(ALARM_NOTIFICATION_ID);
}
}
else mNotifyMgr.cancel(ALARM_NOTIFICATION_ID);
}
}

View File

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

View File

@@ -5,7 +5,7 @@
<Preference android:title="@string/label_importBackup" android:key="importBackup"/>
<CheckBoxPreference android:title="@string/label_auto_backup" android:summaryOn="@string/info_is_enable" android:summaryOff="@string/info_is_not_enable" android:key="autoBackup" android:defaultValue="false"/>
<Preference android:title="@string/label_export_dir" android:dependency="autoBackup" android:key="exportDir" />
<Preference android:title="@string/label_export_dir" android:dependency="autoBackup" android:key="backupDir" />
<CheckBoxPreference android:title="@string/label_overwrite_backup" android:dependency="autoBackup" android:summaryOn="@string/info_is_enable" android:summaryOff="@string/info_is_not_enable" android:key="overwriteBackup" android:defaultValue="false"/>
<ListPreference
android:dependency="autoBackup"