123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- /**
- * ownCloud Android client application
- *
- * @author David A. Velasco
- * Copyright (C) 2016 ownCloud Inc.
- * <p/>
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2,
- * as published by the Free Software Foundation.
- * <p/>
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- * <p/>
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package com.owncloud.android.db;
- import android.content.Context;
- import android.content.SharedPreferences;
- import com.owncloud.android.utils.FileStorageUtils;
- /**
- * Helper to simplify reading of Preferences all around the app
- */
- public abstract class PreferenceManager {
- /**
- * Constant to access value of last path selected by the user to upload a file shared from other app.
- * Value handled by the app without direct access in the UI.
- */
- private static final String AUTO_PREF__LAST_UPLOAD_PATH = "last_upload_path";
- private static final String AUTO_PREF__SORT_ORDER = "sort_order";
- private static final String AUTO_PREF__SORT_ASCENDING = "sort_ascending";
- private static final String AUTO_PREF__UPLOAD_FILE_EXTENSION_MAP_URL = "prefs_upload_file_extension_map_url";
- private static final String AUTO_PREF__UPLOAD_FILE_EXTENSION_URL = "prefs_upload_file_extension_url";
- private static final String AUTO_PREF__UPLOADER_BEHAVIOR = "prefs_uploader_behaviour";
- 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__INSTANT_UPLOAD_PATH_USE_SUBFOLDERS = "instant_upload_path_use_subfolders";
- private static final String PREF__INSTANT_UPLOAD_ON_WIFI = "instant_upload_on_wifi";
- private static final String PREF__INSTANT_VIDEO_UPLOAD_ON_WIFI = "instant_video_upload_on_wifi";
- private static final String PREF__INSTANT_VIDEO_UPLOAD_PATH_USE_SUBFOLDERS = "instant_video_upload_path_use_subfolders";
- private static final String PREF__LEGACY_CLEAN = "legacyClean";
- public static boolean instantPictureUploadEnabled(Context context) {
- return getDefaultSharedPreferences(context).getBoolean(PREF__INSTANT_UPLOADING, false);
- }
- public static boolean instantVideoUploadEnabled(Context context) {
- return getDefaultSharedPreferences(context).getBoolean(PREF__INSTANT_VIDEO_UPLOADING, false);
- }
- public static boolean instantPictureUploadPathUseSubfolders(Context context) {
- return getDefaultSharedPreferences(context).getBoolean(PREF__INSTANT_UPLOAD_PATH_USE_SUBFOLDERS, false);
- }
- public static boolean instantPictureUploadViaWiFiOnly(Context context) {
- return getDefaultSharedPreferences(context).getBoolean(PREF__INSTANT_UPLOAD_ON_WIFI, false);
- }
- public static boolean instantVideoUploadPathUseSubfolders(Context context) {
- return getDefaultSharedPreferences(context).getBoolean(PREF__INSTANT_VIDEO_UPLOAD_PATH_USE_SUBFOLDERS, false);
- }
- public static boolean instantVideoUploadViaWiFiOnly(Context context) {
- return getDefaultSharedPreferences(context).getBoolean(PREF__INSTANT_VIDEO_UPLOAD_ON_WIFI, false);
- }
- public static boolean instantPictureUploadWhenChargingOnly(Context context) {
- return PreferenceManager.getDefaultSharedPreferences(context).getBoolean("instant_upload_on_charging", false);
- }
- public static boolean instantVideoUploadWhenChargingOnly(Context context) {
- return PreferenceManager.getDefaultSharedPreferences(context).getBoolean("instant_video_upload_on_charging", false);
- }
- public static boolean showHiddenFilesEnabled(Context context) {
- return PreferenceManager.getDefaultSharedPreferences(context).getBoolean("show_hidden_files_pref", false);
- }
- /**
- * Gets the selected file extension position the user selected to do the last upload of a url file shared from other
- * app.
- *
- * @param context Caller {@link Context}, used to access to shared preferences manager.
- * @return selectedPos the selected file extension position.
- */
- public static int getUploadUrlFileExtensionUrlSelectedPos(Context context) {
- return getDefaultSharedPreferences(context).getInt(AUTO_PREF__UPLOAD_FILE_EXTENSION_URL, 0);
- }
- /**
- * Saves the selected file extension position the user selected to do the last upload of a url file shared from
- * other app.
- *
- * @param context Caller {@link Context}, used to access to shared preferences manager.
- * @param selectedPos the selected file extension position.
- */
- public static void setUploadUrlFileExtensionUrlSelectedPos(Context context, int selectedPos) {
- saveIntPreference(context, AUTO_PREF__UPLOAD_FILE_EXTENSION_URL, selectedPos);
- }
- /**
- * Gets the selected map file extension position the user selected to do the last upload of a url file shared
- * from other app.
- *
- * @param context Caller {@link Context}, used to access to shared preferences manager.
- * @return selectedPos the selected file extension position.
- */
- public static int getUploadMapFileExtensionUrlSelectedPos(Context context) {
- return getDefaultSharedPreferences(context).getInt(AUTO_PREF__UPLOAD_FILE_EXTENSION_MAP_URL, 0);
- }
- /**
- * Saves the selected map file extension position the user selected to do the last upload of a url file shared from
- * other app.
- *
- * @param context Caller {@link Context}, used to access to shared preferences manager.
- * @param selectedPos the selected file extension position.
- */
- public static void setUploadMapFileExtensionUrlSelectedPos(Context context, int selectedPos) {
- saveIntPreference(context, AUTO_PREF__UPLOAD_FILE_EXTENSION_MAP_URL, selectedPos);
- }
- /**
- * Gets the path where the user selected to do the last upload of a file shared from other app.
- *
- * @param context Caller {@link Context}, used to access to shared preferences manager.
- * @return path Absolute path to a folder, as previously stored by {@link #setLastUploadPath(Context, String)},
- * or empty String if never saved before.
- */
- public static String getLastUploadPath(Context context) {
- return getDefaultSharedPreferences(context).getString(AUTO_PREF__LAST_UPLOAD_PATH, "");
- }
- /**
- * Saves the path where the user selected to do the last upload of a file shared from other app.
- *
- * @param context Caller {@link Context}, used to access to shared preferences manager.
- * @param path Absolute path to a folder.
- */
- public static void setLastUploadPath(Context context, String path) {
- saveStringPreference(context, AUTO_PREF__LAST_UPLOAD_PATH, path);
- }
- /**
- * Gets the sort order which the user has set last.
- *
- * @param context Caller {@link Context}, used to access to shared preferences manager.
- * @return sort order the sort order, default is {@link FileStorageUtils#SORT_NAME} (sort by name)
- */
- public static int getSortOrder(Context context) {
- return getDefaultSharedPreferences(context).getInt(AUTO_PREF__SORT_ORDER, FileStorageUtils.SORT_NAME);
- }
- /**
- * Save the sort order which the user has set last.
- *
- * @param context Caller {@link Context}, used to access to shared preferences manager.
- * @param order the sort order
- */
- public static void setSortOrder(Context context, int order) {
- saveIntPreference(context, AUTO_PREF__SORT_ORDER, order);
- }
- /**
- * Gets the ascending order flag which the user has set last.
- *
- * @param context Caller {@link Context}, used to access to shared preferences manager.
- * @return ascending order the ascending order, default is true
- */
- public static boolean getSortAscending(Context context) {
- return getDefaultSharedPreferences(context).getBoolean(AUTO_PREF__SORT_ASCENDING, true);
- }
- /**
- * Saves the ascending order flag which the user has set last.
- *
- * @param context Caller {@link Context}, used to access to shared preferences manager.
- * @param ascending flag if sorting is ascending or descending
- */
- public static void setSortAscending(Context context, boolean ascending) {
- saveBooleanPreference(context, AUTO_PREF__SORT_ASCENDING, ascending);
- }
- /**
- * Gets the legacy cleaning flag last set.
- *
- * @param context Caller {@link Context}, used to access to shared preferences manager.
- * @return ascending order the alegacy cleaning flag, default is false
- */
- public static boolean getLegacyClean(Context context) {
- return getDefaultSharedPreferences(context).getBoolean(PREF__LEGACY_CLEAN, false);
- }
- /**
- * Saves the legacy cleaning flag which the user has set last.
- *
- * @param context Caller {@link Context}, used to access to shared preferences manager.
- * @param legacyClean flag if it is a legacy cleaning
- */
- public static void setLegacyClean(Context context, boolean legacyClean) {
- saveBooleanPreference(context, PREF__LEGACY_CLEAN, legacyClean);
- }
- /**
- * Gets the uploader behavior which the user has set last.
- *
- * @param context Caller {@link Context}, used to access to shared preferences manager.
- * @return uploader behavior the uploader behavior
- */
- public static int getUploaderBehaviour(Context context) {
- return getDefaultSharedPreferences(context).getInt(AUTO_PREF__UPLOADER_BEHAVIOR, 1);
- }
- /**
- * Saves the uploader behavior which the user has set last.
- *
- * @param context Caller {@link Context}, used to access to shared preferences manager.
- * @param uploaderBehaviour the uploader behavior
- */
- public static void setUploaderBehaviour(Context context, int uploaderBehaviour) {
- saveIntPreference(context, AUTO_PREF__UPLOADER_BEHAVIOR, uploaderBehaviour);
- }
- public static void saveBooleanPreference(Context context, String key, boolean value) {
- SharedPreferences.Editor appPreferences = getDefaultSharedPreferences(context.getApplicationContext()).edit();
- appPreferences.putBoolean(key, value);
- appPreferences.apply();
- }
- private static void saveStringPreference(Context context, String key, String value) {
- SharedPreferences.Editor appPreferences = getDefaultSharedPreferences(context.getApplicationContext()).edit();
- appPreferences.putString(key, value);
- appPreferences.apply();
- }
- private static void saveIntPreference(Context context, String key, int value) {
- SharedPreferences.Editor appPreferences = getDefaultSharedPreferences(context.getApplicationContext()).edit();
- appPreferences.putInt(key, value);
- appPreferences.apply();
- }
- public static SharedPreferences getDefaultSharedPreferences(Context context) {
- return android.preference.PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
- }
- }
|