Browse Source

removed static functions (according to CR)

tobiasKaminsky 9 years ago
parent
commit
45c82e4fed

+ 19 - 38
src/com/owncloud/android/ui/activity/FileDisplayActivity.java

@@ -150,7 +150,6 @@ public class FileDisplayActivity extends HookActivity
     private static String DIALOG_CERT_NOT_SAVED = "DIALOG_CERT_NOT_SAVED";
 
     private OCFile mWaitingToSend;
-    private Menu mOptionsMenu;
 
 
     @Override
@@ -320,8 +319,6 @@ public class FileDisplayActivity extends HookActivity
                     startTextPreview(file);
             }
 
-            switchLayout(getCurrentDir());
-
         } else {
             Log_OC.wtf(TAG, "initFragments() called with invalid NULLs!");
             if (getAccount() == null) {
@@ -333,14 +330,6 @@ public class FileDisplayActivity extends HookActivity
         }
     }
 
-    private void switchLayout(OCFile file){
-        if (DisplayUtils.isGridViewPreferred(file, getStorageManager())){
-            switchToGridView();
-        } else {
-            switchToListView();
-        }
-    }
-
     private Fragment chooseInitialSecondFragment(OCFile file) {
         Fragment secondFragment = null;
         if (file != null && !file.isFolder()) {
@@ -498,7 +487,8 @@ public class FileDisplayActivity extends HookActivity
         menu.findItem(R.id.action_create_dir).setVisible(!drawerOpen);
         menu.findItem(R.id.action_sort).setVisible(!drawerOpen);
         menu.findItem(R.id.action_sync_account).setVisible(!drawerOpen);
-        
+        menu.findItem(R.id.action_switch_view).setVisible(!drawerOpen);
+
         return super.onPrepareOptionsMenu(menu);
     }
 
@@ -506,10 +496,6 @@ public class FileDisplayActivity extends HookActivity
     public boolean onCreateOptionsMenu(Menu menu) {
         MenuInflater inflater = getMenuInflater();
         inflater.inflate(R.menu.main_menu, menu);
-        mOptionsMenu = menu;
-
-        changeGridIcon();
-
         return true;
     }
     
@@ -579,12 +565,16 @@ public class FileDisplayActivity extends HookActivity
             }
             case R.id.action_switch_view:{
                 if (isGridView()){
-                    item.setTitle(getApplicationContext().getString(R.string.action_switch_list_view));
-                    DisplayUtils.setViewMode(getFile(), false);
+                    item.setTitle(getApplicationContext().getString(R.string.action_switch_grid_view));
+                    item.setIcon(ContextCompat.getDrawable(getApplicationContext(),
+                            R.drawable.ic_view_module));
+                    setViewMode(getFile(), false);
                     switchToListView();
                 } else {
-                    item.setTitle(getApplicationContext().getString(R.string.action_switch_grid_view));
-                    DisplayUtils.setViewMode(getFile(), true);
+                    item.setTitle(getApplicationContext().getString(R.string.action_switch_list_view));
+                    item.setIcon(ContextCompat.getDrawable(getApplicationContext(),
+                            R.drawable.ic_view_list));
+                    setViewMode(getFile(), true);
                     switchToGridView();
                 }
                 return true;
@@ -595,6 +585,15 @@ public class FileDisplayActivity extends HookActivity
         return retval;
     }
 
+    public void setViewMode(OCFile file, boolean setGrid){
+        SharedPreferences setting = MainApp.getAppContext().getSharedPreferences(
+                "viewMode", Context.MODE_PRIVATE);
+
+        SharedPreferences.Editor editor = setting.edit();
+        editor.putBoolean(String.valueOf(file.getFileId()), setGrid);
+        editor.commit();
+    }
+
     private void startSynchronization() {
         Log_OC.d(TAG, "Got to start sync");
         if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.KITKAT) {
@@ -825,21 +824,6 @@ public class FileDisplayActivity extends HookActivity
         } else {
             super.onBackPressed();
         }
-
-        changeGridIcon();
-    }
-
-    private void changeGridIcon(){
-        MenuItem menuItem = mOptionsMenu.findItem(R.id.action_switch_view);
-        if (DisplayUtils.isGridViewPreferred(getFile(), getStorageManager())){
-            menuItem.setTitle(getApplicationContext().getString(R.string.action_switch_list_view));
-            menuItem.setIcon(ContextCompat.getDrawable(getApplicationContext(),
-                    R.drawable.ic_view_list));
-        } else {
-            menuItem.setTitle(getApplicationContext().getString(R.string.action_switch_grid_view));
-            menuItem.setIcon(ContextCompat.getDrawable(getApplicationContext(),
-                    R.drawable.ic_view_module));
-        }
     }
 
     @Override
@@ -1252,9 +1236,6 @@ public class FileDisplayActivity extends HookActivity
         cleanSecondFragment();
         // Sync Folder
         startSyncFolderOperation(directory, false);
-
-        changeGridIcon();
-        switchLayout(directory);
     }
 
     /**

+ 70 - 1
src/com/owncloud/android/ui/fragment/OCFileListFragment.java

@@ -23,8 +23,11 @@
 package com.owncloud.android.ui.fragment;
 
 import android.app.Activity;
+import android.content.Context;
 import android.content.Intent;
+import android.content.SharedPreferences;
 import android.os.Bundle;
+import android.support.v4.content.ContextCompat;
 import android.support.v4.widget.SwipeRefreshLayout;
 import android.view.ContextMenu;
 import android.view.Menu;
@@ -35,6 +38,7 @@ import android.widget.AdapterView;
 import android.widget.AdapterView.AdapterContextMenuInfo;
 import android.widget.PopupMenu;
 
+import com.owncloud.android.MainApp;
 import com.owncloud.android.R;
 import com.owncloud.android.authentication.AccountUtils;
 import com.owncloud.android.datamodel.FileDataStorageManager;
@@ -337,6 +341,8 @@ public class OCFileListFragment extends ExtendedListFragment
 
 //            String.format(mContext.getString(R.string.subject_token),
 //                    getClient().getCredentials().getUsername(), file.getFileName()));
+
+            changeGridIcon(menu, targetFile);
         }
     }
 
@@ -523,7 +529,7 @@ public class OCFileListFragment extends ExtendedListFragment
             OwnCloudVersion version = AccountUtils.getServerVersion(
                     ((FileActivity)mContainerActivity).getAccount());
             if (version != null && version.supportsRemoteThumbnails() &&
-                    DisplayUtils.isGridViewPreferred(mFile, mContainerActivity.getStorageManager())) {
+                    isGridViewPreferred(mFile)) {
                 switchToGridView();
                 registerLongClickListener();
             } else {
@@ -583,4 +589,67 @@ public class OCFileListFragment extends ExtendedListFragment
     public void sortBySize(boolean descending) {
         mAdapter.setSortOrder(FileStorageUtils.SORT_SIZE, descending);
     }
+
+    /**
+     * 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
+     * @return
+     */
+    public boolean isGridViewPreferred(OCFile file){
+        if (file != null) {
+            OCFile fileToTest = file;
+            OCFile parentDir = null;
+            String parentPath = null;
+            FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
+
+            SharedPreferences setting = MainApp.getAppContext().getSharedPreferences(
+                    "viewMode", 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);
+                    }
+
+                    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;
+        }
+    }
+
+    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()));
+        }
+    }
+
+    private void changeGridIcon(ContextMenu menu, OCFile targetFile){
+        MenuItem menuItem = menu.findItem(R.id.action_switch_view);
+        if (isGridViewPreferred(targetFile)){
+            menuItem.setTitle(getString(R.string.action_switch_list_view));
+            menuItem.setIcon(R.drawable.ic_view_list);
+        } else {
+            menuItem.setTitle(getString(R.string.action_switch_grid_view));
+            menuItem.setIcon(R.drawable.ic_view_module);
+        }
+    }
 }

+ 0 - 61
src/com/owncloud/android/utils/DisplayUtils.java

@@ -291,65 +291,4 @@ public class DisplayUtils {
         }
     }
 
-    /**
-     * 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
-     * @param storageManager
-     * @return
-     */
-    public static boolean isGridViewPreferred(OCFile file, FileDataStorageManager storageManager){
-        if (file != null) {
-            OCFile fileToTest = file;
-            OCFile parentDir = null;
-            String parentPath = null;
-
-            SharedPreferences setting = MainApp.getAppContext().getSharedPreferences(
-                    "viewMode", 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);
-                    }
-
-                    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;
-        }
-    }
-
-    private static 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 static void setViewMode(OCFile file, boolean setGrid){
-        SharedPreferences setting = MainApp.getAppContext().getSharedPreferences(
-                "viewMode", Context.MODE_PRIVATE);
-
-        SharedPreferences.Editor editor = setting.edit();
-        editor.putBoolean(String.valueOf(file.getFileId()), setGrid);
-        editor.commit();
-    }
-
 }