From 92d13f2f1a9f0e75bed5ed9b968f964b1387c890 Mon Sep 17 00:00:00 2001 From: Chris Narkiewicz Date: Mon, 11 Mar 2019 17:02:27 +0000 Subject: [PATCH] Move hidden files pref to AppPreferences Signed-off-by: Chris Narkiewicz --- .../nextcloud/client/preferences/AppPreferences.java | 3 +++ .../client/preferences/PreferenceManager.java | 11 +++++++++-- .../android/ui/activity/SettingsActivity.java | 6 +----- .../android/ui/adapter/LocalFileListAdapter.java | 2 +- .../android/ui/adapter/OCFileListAdapter.java | 6 +++--- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/nextcloud/client/preferences/AppPreferences.java b/src/main/java/com/nextcloud/client/preferences/AppPreferences.java index 4937090c3b..c781c6d254 100644 --- a/src/main/java/com/nextcloud/client/preferences/AppPreferences.java +++ b/src/main/java/com/nextcloud/client/preferences/AppPreferences.java @@ -27,6 +27,9 @@ public interface AppPreferences { boolean instantPictureUploadEnabled(); boolean instantVideoUploadEnabled(); + boolean isShowHiddenFilesEnabled(); + void setShowHiddenFilesEnabled(boolean enabled); + /** * Gets the selected file extension position the user selected to do the * last upload of a url file shared from other app. diff --git a/src/main/java/com/nextcloud/client/preferences/PreferenceManager.java b/src/main/java/com/nextcloud/client/preferences/PreferenceManager.java index 3061e968b7..b36822bbbb 100644 --- a/src/main/java/com/nextcloud/client/preferences/PreferenceManager.java +++ b/src/main/java/com/nextcloud/client/preferences/PreferenceManager.java @@ -50,6 +50,7 @@ public final class PreferenceManager implements AppPreferences { public static final String AUTO_PREF__LAST_SEEN_VERSION_CODE = "lastSeenVersionCode"; private static final String PREF__INSTANT_UPLOADING = "instant_uploading"; private static final String PREF__INSTANT_VIDEO_UPLOADING = "instant_video_uploading"; + private static final String PREF__SHOW_HIDDEN_FILES = "show_hidden_files_pref"; private static final String PREF__LEGACY_CLEAN = "legacyClean"; public static final String PREF__KEYS_MIGRATION = "keysMigration"; private static final String PREF__FIX_STORAGE_PATH = "storagePathFix"; @@ -103,8 +104,14 @@ public final class PreferenceManager implements AppPreferences { return preferences.getBoolean(PREF__INSTANT_VIDEO_UPLOADING, false); } - public static boolean showHiddenFilesEnabled(Context context) { - return PreferenceManager.getDefaultSharedPreferences(context).getBoolean("show_hidden_files_pref", false); + @Override + public boolean isShowHiddenFilesEnabled() { + return preferences.getBoolean(PREF__SHOW_HIDDEN_FILES, false); + } + + @Override + public void setShowHiddenFilesEnabled(boolean enabled) { + preferences.edit().putBoolean(PREF__SHOW_HIDDEN_FILES, enabled).apply(); } @Override diff --git a/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java b/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java index c490e64d8c..3394a9302b 100644 --- a/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java +++ b/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java @@ -534,11 +534,7 @@ public class SettingsActivity extends PreferenceActivity showHiddenFiles = (SwitchPreference) findPreference("show_hidden_files"); if (fShowHiddenFilesEnabled) { showHiddenFiles.setOnPreferenceClickListener(preference -> { - SharedPreferences appPrefs = - PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); - SharedPreferences.Editor editor = appPrefs.edit(); - editor.putBoolean("show_hidden_files_pref", showHiddenFiles.isChecked()); - editor.apply(); + preferences.setShowHiddenFilesEnabled(showHiddenFiles.isChecked()); return true; }); } else { diff --git a/src/main/java/com/owncloud/android/ui/adapter/LocalFileListAdapter.java b/src/main/java/com/owncloud/android/ui/adapter/LocalFileListAdapter.java index 3f9aeb6aec..dcef29a3c7 100644 --- a/src/main/java/com/owncloud/android/ui/adapter/LocalFileListAdapter.java +++ b/src/main/java/com/owncloud/android/ui/adapter/LocalFileListAdapter.java @@ -324,7 +324,7 @@ public class LocalFileListAdapter extends RecyclerView.Adapter