diff --git a/app/src/main/java/com/nextcloud/client/preferences/AppPreferences.java b/app/src/main/java/com/nextcloud/client/preferences/AppPreferences.java index 4f4baef713..7266894c6e 100644 --- a/app/src/main/java/com/nextcloud/client/preferences/AppPreferences.java +++ b/app/src/main/java/com/nextcloud/client/preferences/AppPreferences.java @@ -20,7 +20,6 @@ package com.nextcloud.client.preferences; -import com.nextcloud.client.account.User; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.utils.FileSortOrder; @@ -378,10 +377,4 @@ public interface AppPreferences { boolean isStoragePermissionRequested(); void setStoragePermissionRequested(boolean value); - - boolean isContactsBackupEnabled(final User user); - void setContactsBackupEnabled(final User user, final boolean value); - - boolean isCalendarBackupEnabled(final User user); - void setCalendarBackupEnabled(final User user, final boolean value); } diff --git a/app/src/main/java/com/nextcloud/client/preferences/AppPreferencesImpl.java b/app/src/main/java/com/nextcloud/client/preferences/AppPreferencesImpl.java index 5ab0d1de8b..6754c379c7 100644 --- a/app/src/main/java/com/nextcloud/client/preferences/AppPreferencesImpl.java +++ b/app/src/main/java/com/nextcloud/client/preferences/AppPreferencesImpl.java @@ -24,7 +24,6 @@ package com.nextcloud.client.preferences; import android.annotation.SuppressLint; import android.content.Context; import android.content.SharedPreferences; -import android.net.Uri; import com.nextcloud.client.account.CurrentAccountProvider; import com.nextcloud.client.account.User; @@ -100,9 +99,6 @@ public final class AppPreferencesImpl implements AppPreferences { private static final String PREF__STORAGE_PERMISSION_REQUESTED = "storage_permission_requested"; - private static final String PREF__CALENDAR_BACKUP_ENABLED = "calendar_backup_enabled"; - private static final String PREF__CONTACTS_BACKUP_ENABLED = "contacts_backup_enabled"; - private final Context context; private final SharedPreferences preferences; private final CurrentAccountProvider currentAccountProvider; @@ -168,10 +164,6 @@ public final class AppPreferencesImpl implements AppPreferences { this.preferences.registerOnSharedPreferenceChangeListener(listeners); } - private String getUserScopedKey(final User user, final String originalKey) { - return Uri.encode(user.getAccountName()) + "__" + originalKey; - } - @Override public void addListener(@Nullable AppPreferences.Listener listener) { this.listeners.add(listener); @@ -716,30 +708,6 @@ public final class AppPreferencesImpl implements AppPreferences { preferences.edit().putBoolean(PREF__STORAGE_PERMISSION_REQUESTED, value).apply(); } - @Override - public boolean isContactsBackupEnabled(final User user) { - final String key = getUserScopedKey(user, PREF__CONTACTS_BACKUP_ENABLED); - return preferences.getBoolean(key, false); - } - - @Override - public void setContactsBackupEnabled(final User user, boolean value) { - final String key = getUserScopedKey(user, PREF__CONTACTS_BACKUP_ENABLED); - preferences.edit().putBoolean(key, value).apply(); - } - - @Override - public boolean isCalendarBackupEnabled(final User user) { - final String key = getUserScopedKey(user, PREF__CALENDAR_BACKUP_ENABLED); - return preferences.getBoolean(key, false); - } - - @Override - public void setCalendarBackupEnabled(final User user, boolean value) { - final String key = getUserScopedKey(user, PREF__CALENDAR_BACKUP_ENABLED); - preferences.edit().putBoolean(key, value).apply(); - } - @VisibleForTesting public int computeBruteForceDelay(int count) { return (int) Math.min(count / 3d, 10); diff --git a/app/src/main/java/com/owncloud/android/datamodel/ArbitraryDataProvider.java b/app/src/main/java/com/owncloud/android/datamodel/ArbitraryDataProvider.java index 5751067cc0..de05dc1009 100644 --- a/app/src/main/java/com/owncloud/android/datamodel/ArbitraryDataProvider.java +++ b/app/src/main/java/com/owncloud/android/datamodel/ArbitraryDataProvider.java @@ -65,6 +65,10 @@ public class ArbitraryDataProvider { storeOrUpdateKeyValue(accountName, key, String.valueOf(newValue)); } + public void storeOrUpdateKeyValue(final String accountName, final String key, final boolean newValue) { + storeOrUpdateKeyValue(accountName, key, String.valueOf(newValue)); + } + public void storeOrUpdateKeyValue(@NonNull String accountName, @NonNull String key, @Nullable String newValue) { diff --git a/app/src/main/java/com/owncloud/android/ui/fragment/contactsbackup/BackupFragment.java b/app/src/main/java/com/owncloud/android/ui/fragment/contactsbackup/BackupFragment.java index 32cd8ff4a0..547087f80e 100644 --- a/app/src/main/java/com/owncloud/android/ui/fragment/contactsbackup/BackupFragment.java +++ b/app/src/main/java/com/owncloud/android/ui/fragment/contactsbackup/BackupFragment.java @@ -84,6 +84,10 @@ public class BackupFragment extends FileFragment implements DatePickerDialog.OnD private static final String KEY_CALENDAR_MONTH = "CALENDAR_MONTH"; private static final String KEY_CALENDAR_YEAR = "CALENDAR_YEAR"; + public static final String PREFERENCE_CONTACTS_BACKUP_ENABLED = "PREFERENCE_CONTACTS_BACKUP_ENABLED"; + public static final String PREFERENCE_CALENDAR_BACKUP_ENABLED = "PREFERENCE_CALENDAR_BACKUP_ENABLED"; + + private BackupFragmentBinding binding; @Inject BackgroundJobManager backgroundJobManager; @@ -93,7 +97,6 @@ public class BackupFragment extends FileFragment implements DatePickerDialog.OnD @Inject ThemeCheckableUtils themeCheckableUtils; @Inject ThemeButtonUtils themeButtonUtils; @Inject ArbitraryDataProvider arbitraryDataProvider; - @Inject AppPreferences appPreferences; private Date selectedDate; private boolean calendarPickerOpen; @@ -115,19 +118,19 @@ public class BackupFragment extends FileFragment implements DatePickerDialog.OnD } private boolean isCalendarBackupEnabled() { - return appPreferences.isCalendarBackupEnabled(user); + return arbitraryDataProvider.getBooleanValue(user, PREFERENCE_CALENDAR_BACKUP_ENABLED); } private void setCalendarBackupEnabled(final boolean enabled) { - appPreferences.setCalendarBackupEnabled(user, enabled); + arbitraryDataProvider.storeOrUpdateKeyValue(user.getAccountName(), PREFERENCE_CALENDAR_BACKUP_ENABLED, enabled); } private boolean isContactsBackupEnabled() { - return appPreferences.isContactsBackupEnabled(user); + return arbitraryDataProvider.getBooleanValue(user, PREFERENCE_CONTACTS_BACKUP_ENABLED); } private void setContactsBackupEnabled(final boolean enabled) { - appPreferences.setContactsBackupEnabled(user, enabled); + arbitraryDataProvider.storeOrUpdateKeyValue(user.getAccountName(), PREFERENCE_CONTACTS_BACKUP_ENABLED, enabled); } @Override