Configurable calendar backup.

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
A117870935 2023-04-20 20:12:23 +05:30 committed by Andy Scherzinger
parent a77ab9eb66
commit 16c957c834
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
6 changed files with 29 additions and 5 deletions

View file

@ -29,6 +29,7 @@ import androidx.work.Worker
import androidx.work.WorkerParameters import androidx.work.WorkerParameters
import com.nextcloud.client.account.UserAccountManager import com.nextcloud.client.account.UserAccountManager
import com.nextcloud.client.preferences.AppPreferences import com.nextcloud.client.preferences.AppPreferences
import com.owncloud.android.R
import com.owncloud.android.lib.common.utils.Log_OC import com.owncloud.android.lib.common.utils.Log_OC
import third_parties.sufficientlysecure.AndroidCalendar import third_parties.sufficientlysecure.AndroidCalendar
import third_parties.sufficientlysecure.SaveCalendar import third_parties.sufficientlysecure.SaveCalendar
@ -50,6 +51,12 @@ class CalendarBackupWork(
} }
override fun doWork(): Result { override fun doWork(): Result {
val showCalendarBackup = applicationContext.resources.getBoolean(R.bool.show_calendar_backup)
if (!showCalendarBackup) {
Log_OC.d(TAG, "Calendar backup is disabled.")
return Result.success()
}
val accountName = inputData.getString(ACCOUNT) ?: "" val accountName = inputData.getString(ACCOUNT) ?: ""
val optionalUser = accountManager.getUser(accountName) val optionalUser = accountManager.getUser(accountName)
if (!optionalUser.isPresent || TextUtils.isEmpty(accountName)) { // no account provided if (!optionalUser.isPresent || TextUtils.isEmpty(accountName)) { // no account provided

View file

@ -561,6 +561,13 @@ public class SettingsActivity extends PreferenceActivity
private void setupBackupPreference() { private void setupBackupPreference() {
Preference pContactsBackup = findPreference("backup"); Preference pContactsBackup = findPreference("backup");
if (pContactsBackup != null) { if (pContactsBackup != null) {
boolean showCalendarBackup = getResources().getBoolean(R.bool.show_calendar_backup);
pContactsBackup.setTitle(showCalendarBackup
? getString(R.string.backup_title)
: getString(R.string.contact_backup_title));
pContactsBackup.setSummary(showCalendarBackup
? getString(R.string.prefs_daily_backup_summary)
: getString(R.string.prefs_daily_contact_backup_summary));
pContactsBackup.setOnPreferenceClickListener(preference -> { pContactsBackup.setOnPreferenceClickListener(preference -> {
ContactsPreferenceActivity.startActivityWithoutSidebar(this); ContactsPreferenceActivity.startActivityWithoutSidebar(this);
return true; return true;

View file

@ -102,7 +102,8 @@ public class BackupFragment extends FileFragment implements DatePickerDialog.OnD
private CompoundButton.OnCheckedChangeListener calendarCheckedListener; private CompoundButton.OnCheckedChangeListener calendarCheckedListener;
private User user; private User user;
private boolean showSidebar = true; private boolean showSidebar = true;
//flag to check if calendar backup should be shown and backup should be done or not
private boolean showCalendarBackup = true;
public static BackupFragment create(boolean showSidebar) { public static BackupFragment create(boolean showSidebar) {
BackupFragment fragment = new BackupFragment(); BackupFragment fragment = new BackupFragment();
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
@ -144,6 +145,8 @@ public class BackupFragment extends FileFragment implements DatePickerDialog.OnD
showSidebar = getArguments().getBoolean(ARG_SHOW_SIDEBAR); showSidebar = getArguments().getBoolean(ARG_SHOW_SIDEBAR);
} }
showCalendarBackup = requireContext().getResources().getBoolean(R.bool.show_calendar_backup);
final ContactsPreferenceActivity contactsPreferenceActivity = (ContactsPreferenceActivity) getActivity(); final ContactsPreferenceActivity contactsPreferenceActivity = (ContactsPreferenceActivity) getActivity();
user = contactsPreferenceActivity.getUser().orElseThrow(RuntimeException::new); user = contactsPreferenceActivity.getUser().orElseThrow(RuntimeException::new);
@ -151,7 +154,8 @@ public class BackupFragment extends FileFragment implements DatePickerDialog.OnD
if (actionBar != null) { if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true);
viewThemeUtils.files.themeActionBar(requireContext(), actionBar, R.string.backup_title); viewThemeUtils.files.themeActionBar(requireContext(), actionBar,
showCalendarBackup ? R.string.backup_title : R.string.contact_backup_title);
} }
@ -164,6 +168,7 @@ public class BackupFragment extends FileFragment implements DatePickerDialog.OnD
binding.contacts.setChecked(isContactsBackupEnabled() && checkContactBackupPermission()); binding.contacts.setChecked(isContactsBackupEnabled() && checkContactBackupPermission());
binding.calendar.setChecked(isCalendarBackupEnabled() && checkCalendarBackupPermission(getContext())); binding.calendar.setChecked(isCalendarBackupEnabled() && checkCalendarBackupPermission(getContext()));
binding.calendar.setVisibility(showCalendarBackup ? View.VISIBLE : View.GONE);
setupCheckListeners(); setupCheckListeners();
@ -395,7 +400,7 @@ public class BackupFragment extends FileFragment implements DatePickerDialog.OnD
startContactsBackupJob(); startContactsBackupJob();
} }
if (isCalendarBackupEnabled() && checkCalendarBackupPermission(requireContext())) { if (showCalendarBackup && isCalendarBackupEnabled() && checkCalendarBackupPermission(requireContext())) {
startCalendarBackupJob(); startCalendarBackupJob();
} }
@ -651,7 +656,7 @@ public class BackupFragment extends FileFragment implements DatePickerDialog.OnD
} }
// calendars // calendars
if (MimeTypeUtil.isCalendar(file)) { if (showCalendarBackup && MimeTypeUtil.isCalendar(file)) {
calendarBackupsToRestore.add(file); calendarBackupsToRestore.add(file);
} }
} }

View file

@ -80,6 +80,7 @@
<string name="away">Abwesend</string> <string name="away">Abwesend</string>
<string name="backup_settings">Sicherungseinstellungen</string> <string name="backup_settings">Sicherungseinstellungen</string>
<string name="backup_title">Kontakte &amp; Kalender-Sicherung</string> <string name="backup_title">Kontakte &amp; Kalender-Sicherung</string>
<string name="contact_backup_title">Kontakte-Sicherung</string>
<string name="battery_optimization_close">Schliessen</string> <string name="battery_optimization_close">Schliessen</string>
<string name="battery_optimization_disable">Deaktivieren</string> <string name="battery_optimization_disable">Deaktivieren</string>
<string name="battery_optimization_message">Ihr Gerät hat möglicherweise Batterieoptimierung aktiv. AutoUpload funktioniert nur dann richtig, wenn Sie diese App davon ausschließen.</string> <string name="battery_optimization_message">Ihr Gerät hat möglicherweise Batterieoptimierung aktiv. AutoUpload funktioniert nur dann richtig, wenn Sie diese App davon ausschließen.</string>
@ -561,6 +562,7 @@
<string name="prefs_category_general">Allgemein</string> <string name="prefs_category_general">Allgemein</string>
<string name="prefs_category_more">Mehr</string> <string name="prefs_category_more">Mehr</string>
<string name="prefs_daily_backup_summary">Tägliche Sicherung Ihrer Kalender &amp; Kontakte</string> <string name="prefs_daily_backup_summary">Tägliche Sicherung Ihrer Kalender &amp; Kontakte</string>
<string name="prefs_daily_contact_backup_summary">Tägliche Sicherung Ihrer Kontakte</string>
<string name="prefs_davx5_setup_error">Unerwarteter Fehler beim Einrichten von DAVx5 (früher bekannt als DAVdroid)</string> <string name="prefs_davx5_setup_error">Unerwarteter Fehler beim Einrichten von DAVx5 (früher bekannt als DAVdroid)</string>
<string name="prefs_e2e_active">Ende-zu-Ende-Verschlüsselung ist eingerichtet!</string> <string name="prefs_e2e_active">Ende-zu-Ende-Verschlüsselung ist eingerichtet!</string>
<string name="prefs_e2e_mnemonic">E2E-Gedächtnisstütze</string> <string name="prefs_e2e_mnemonic">E2E-Gedächtnisstütze</string>

View file

@ -36,6 +36,8 @@
<string name="contacts_backup_folder">/.Contacts-Backup</string> <string name="contacts_backup_folder">/.Contacts-Backup</string>
<integer name="contacts_backup_expire">-1</integer> <integer name="contacts_backup_expire">-1</integer>
<string name="calendar_backup_folder">/.Calendar-Backup</string> <string name="calendar_backup_folder">/.Calendar-Backup</string>
<!-- flag to enable/disable contact backup -->
<bool name="show_calendar_backup">true</bool>
<!-- What's new --> <!-- What's new -->
<bool name="show_whats_new">true</bool> <bool name="show_whats_new">true</bool>

View file

@ -50,6 +50,7 @@
<string name="prefs_calendar_contacts_no_store_error">Neither F-Droid nor Google Play is installed</string> <string name="prefs_calendar_contacts_no_store_error">Neither F-Droid nor Google Play is installed</string>
<string name="prefs_calendar_contacts_sync_setup_successful">Calendar &amp; contacts sync set up</string> <string name="prefs_calendar_contacts_sync_setup_successful">Calendar &amp; contacts sync set up</string>
<string name="prefs_daily_backup_summary">Daily backup of your calendar &amp; contacts</string> <string name="prefs_daily_backup_summary">Daily backup of your calendar &amp; contacts</string>
<string name="prefs_daily_contact_backup_summary">Daily backup of your contacts</string>
<string name="prefs_sycned_folders_summary">Manage folders for auto upload</string> <string name="prefs_sycned_folders_summary">Manage folders for auto upload</string>
<string name="prefs_help">Help</string> <string name="prefs_help">Help</string>
<string name="prefs_recommend">Recommend to a friend</string> <string name="prefs_recommend">Recommend to a friend</string>
@ -605,7 +606,7 @@
<string name="contacts_preferences_backup_scheduled">Backup scheduled and will start shortly</string> <string name="contacts_preferences_backup_scheduled">Backup scheduled and will start shortly</string>
<string name="contacts_preferences_import_scheduled">Import scheduled and will start shortly</string> <string name="contacts_preferences_import_scheduled">Import scheduled and will start shortly</string>
<string name="backup_title">Contacts &amp; calendar backup</string> <string name="backup_title">Contacts &amp; calendar backup</string>
<string name="contact_backup_title">Contacts backup</string>
<string name="drawer_logout">Log out</string> <string name="drawer_logout">Log out</string>
<string name="picture_set_as_no_app">No app found to set a picture with</string> <string name="picture_set_as_no_app">No app found to set a picture with</string>
<string name="privacy">Privacy</string> <string name="privacy">Privacy</string>