|
@@ -28,13 +28,11 @@ import android.accounts.OperationCanceledException;
|
|
|
import android.app.Activity;
|
|
|
import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
-import android.content.SharedPreferences;
|
|
|
import android.os.AsyncTask;
|
|
|
import android.os.Build;
|
|
|
import android.os.Bundle;
|
|
|
import android.os.Handler;
|
|
|
import android.os.Looper;
|
|
|
-import android.preference.PreferenceManager;
|
|
|
import android.support.annotation.Nullable;
|
|
|
import android.support.annotation.StringRes;
|
|
|
import android.support.design.widget.BottomNavigationView;
|
|
@@ -63,6 +61,7 @@ import com.owncloud.android.authentication.AccountUtils;
|
|
|
import com.owncloud.android.datamodel.FileDataStorageManager;
|
|
|
import com.owncloud.android.datamodel.OCFile;
|
|
|
import com.owncloud.android.datamodel.VirtualFolderType;
|
|
|
+import com.owncloud.android.db.PreferenceManager;
|
|
|
import com.owncloud.android.files.FileMenuFilter;
|
|
|
import com.owncloud.android.lib.common.OwnCloudAccount;
|
|
|
import com.owncloud.android.lib.common.OwnCloudClient;
|
|
@@ -133,12 +132,9 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi
|
|
|
public static final String SEARCH_EVENT = "SEARCH_EVENT";
|
|
|
|
|
|
private static final String KEY_FILE = MY_PACKAGE + ".extra.FILE";
|
|
|
- private static final String KEY_FAB_EVER_CLICKED = "FAB_EVER_CLICKED";
|
|
|
|
|
|
private static final String KEY_CURRENT_SEARCH_TYPE = "CURRENT_SEARCH_TYPE";
|
|
|
|
|
|
- private static final String GRID_IS_PREFERED_PREFERENCE = "gridIsPrefered";
|
|
|
-
|
|
|
private static final String DIALOG_CREATE_FOLDER = "DIALOG_CREATE_FOLDER";
|
|
|
|
|
|
private static final String SCREEN_NAME = "Remote/Server file browser";
|
|
@@ -325,8 +321,7 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi
|
|
|
registerFabListeners();
|
|
|
|
|
|
// detect if a mini FAB has ever been clicked
|
|
|
- final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
|
|
- if (prefs.getLong(KEY_FAB_EVER_CLICKED, 0) > 0) {
|
|
|
+ if (PreferenceManager.getFABClicked(getActivity()) > 0) {
|
|
|
miniFabClicked = true;
|
|
|
}
|
|
|
|
|
@@ -488,8 +483,7 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi
|
|
|
private void recordMiniFabClick() {
|
|
|
// only record if it hasn't been done already at some other time
|
|
|
if (!miniFabClicked) {
|
|
|
- final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
|
|
- sp.edit().putLong(KEY_FAB_EVER_CLICKED, 1).apply();
|
|
|
+ PreferenceManager.setFABClicked(getActivity());
|
|
|
miniFabClicked = true;
|
|
|
}
|
|
|
}
|
|
@@ -1214,55 +1208,21 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi
|
|
|
* Determines if user set folder to grid or list view. If folder is not set itself,
|
|
|
* it finds a parent that is set (at least root is set).
|
|
|
*
|
|
|
- * @param file Folder to check.
|
|
|
+ * @param folder Folder to check.
|
|
|
* @return 'true' is folder should be shown in grid mode, 'false' if list mode is preferred.
|
|
|
*/
|
|
|
- public boolean isGridViewPreferred(OCFile file) {
|
|
|
- if (file != null) {
|
|
|
- OCFile fileToTest = file;
|
|
|
- OCFile parentDir;
|
|
|
- String parentPath = null;
|
|
|
- FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
|
|
|
-
|
|
|
- SharedPreferences setting =
|
|
|
- getActivity().getSharedPreferences(
|
|
|
- GRID_IS_PREFERED_PREFERENCE, Context.MODE_PRIVATE
|
|
|
- );
|
|
|
-
|
|
|
- if (setting.contains(String.valueOf(fileToTest.getFileId()))) {
|
|
|
- return setting.getBoolean(String.valueOf(fileToTest.getFileId()), false);
|
|
|
- } else {
|
|
|
- do {
|
|
|
- if (fileToTest.getParentId() != FileDataStorageManager.ROOT_PARENT_ID) {
|
|
|
- parentPath = new File(fileToTest.getRemotePath()).getParent();
|
|
|
- parentPath = parentPath.endsWith(OCFile.PATH_SEPARATOR) ? parentPath :
|
|
|
- parentPath + OCFile.PATH_SEPARATOR;
|
|
|
- parentDir = storageManager.getFileByPath(parentPath);
|
|
|
- } else {
|
|
|
- parentDir = storageManager.getFileByPath(OCFile.ROOT_PATH);
|
|
|
- }
|
|
|
+ public boolean isGridViewPreferred(OCFile folder) {
|
|
|
+ return PreferenceManager.getIsGridViewPreferred(getActivity(), folder);
|
|
|
+ }
|
|
|
|
|
|
- while (parentDir == null) {
|
|
|
- parentPath = new File(parentPath).getParent();
|
|
|
- parentPath = parentPath.endsWith(OCFile.PATH_SEPARATOR) ? parentPath :
|
|
|
- parentPath + OCFile.PATH_SEPARATOR;
|
|
|
- parentDir = storageManager.getFileByPath(parentPath);
|
|
|
- }
|
|
|
- fileToTest = parentDir;
|
|
|
- } while (endWhile(parentDir, setting));
|
|
|
- return setting.getBoolean(String.valueOf(fileToTest.getFileId()), false);
|
|
|
- }
|
|
|
- } else {
|
|
|
- return false;
|
|
|
- }
|
|
|
+ public void setListAsPreferred() {
|
|
|
+ PreferenceManager.setIsGridViewPreferred(getActivity(), mFile, false);
|
|
|
+ switchToListView();
|
|
|
}
|
|
|
|
|
|
- private boolean endWhile(OCFile parentDir, SharedPreferences setting) {
|
|
|
- if (parentDir.getRemotePath().compareToIgnoreCase(OCFile.ROOT_PATH) == 0) {
|
|
|
- return false;
|
|
|
- } else {
|
|
|
- return !setting.contains(String.valueOf(parentDir.getFileId()));
|
|
|
- }
|
|
|
+ public void setGridAsPreferred() {
|
|
|
+ PreferenceManager.setIsGridViewPreferred(getActivity(), mFile, true);
|
|
|
+ switchToGridView();
|
|
|
}
|
|
|
|
|
|
private void changeGridIcon(Menu menu) {
|
|
@@ -1278,29 +1238,6 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void setListAsPreferred() {
|
|
|
- saveGridAsPreferred(false);
|
|
|
- switchToListView();
|
|
|
- }
|
|
|
-
|
|
|
- public void setGridAsPreferred() {
|
|
|
- saveGridAsPreferred(true);
|
|
|
- switchToGridView();
|
|
|
- }
|
|
|
-
|
|
|
- private void saveGridAsPreferred(boolean setGrid) {
|
|
|
- SharedPreferences setting = getActivity().getSharedPreferences(
|
|
|
- GRID_IS_PREFERED_PREFERENCE, Context.MODE_PRIVATE
|
|
|
- );
|
|
|
-
|
|
|
- // can be in case of favorites, shared
|
|
|
- if (mFile != null) {
|
|
|
- SharedPreferences.Editor editor = setting.edit();
|
|
|
- editor.putBoolean(String.valueOf(mFile.getFileId()), setGrid);
|
|
|
- editor.apply();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
private void unsetAllMenuItems(final boolean unsetDrawer) {
|
|
|
new Handler(Looper.getMainLooper()).post(new Runnable() {
|
|
|
@Override
|