OSDN Git Service

Global actions: Properties and Refresh
authorjruesga <jorge@ruesga.com>
Sun, 30 Sep 2012 17:35:56 +0000 (19:35 +0200)
committerjruesga <jorge@ruesga.com>
Sun, 30 Sep 2012 17:35:56 +0000 (19:35 +0200)
New global actions for show properties of the current folder and refresh
the current folder

res/menu/actions.xml
res/values/strings.xml
src/com/cyanogenmod/explorer/activities/NavigationActivity.java
src/com/cyanogenmod/explorer/activities/SearchActivity.java
src/com/cyanogenmod/explorer/adapters/FileSystemObjectAdapter.java
src/com/cyanogenmod/explorer/adapters/SearchResultAdapter.java
src/com/cyanogenmod/explorer/ui/dialogs/ActionsDialog.java
src/com/cyanogenmod/explorer/ui/widgets/NavigationView.java

index 9dd2949..5a844f0 100644 (file)
   <!-- Global Actions -->
   <group android:id="@+id/mnu_actions_global">
     <item
+      android:id="@+id/mnu_actions_properties_current_folder"
+      android:showAsAction="always"
+      android:title="@string/actions_menu_properties_current_folder"/>
+    <item
+      android:id="@+id/mnu_actions_refresh"
+      android:showAsAction="always"
+      android:title="@string/actions_menu_refresh"/>
+    <item
       android:id="@+id/mnu_actions_new_directory"
       android:showAsAction="always"
       android:title="@string/actions_menu_new_directory"/>
index d5af921..6ecf4b4 100644 (file)
 
   <!-- Actions Dialog * Title -->
   <string name="actions_dialog_title">Actions</string>
+  <!-- Actions Dialog * Menu * Properties of current folder -->
+  <string name="actions_menu_properties_current_folder">Properties</string>
+  <!-- Actions Dialog * Menu * Refresh -->
+  <string name="actions_menu_refresh">Refresh</string>
   <!-- Actions Dialog * Menu * New directory -->
   <string name="actions_menu_new_directory">New folder</string>
   <!-- Actions Dialog * Menu * New file -->
index 35a22b0..a894e10 100644 (file)
@@ -657,7 +657,7 @@ public class NavigationActivity extends Activity
             //Action Bar buttons
             //######################
             case R.id.ab_actions:
-                openActions();
+                openActionsDialog(getCurrentNavigationView().getCurrentDir(), true);
                 break;
 
             case R.id.ab_bookmarks:
@@ -758,7 +758,11 @@ public class NavigationActivity extends Activity
     @Override
     public void onRequestRefresh(Object o) {
         if (o instanceof FileSystemObject) {
+            // Refresh only the item
             this.getCurrentNavigationView().refresh((FileSystemObject)o);
+        } else if (o == null) {
+            // Refresh all
+            getCurrentNavigationView().refresh();
         }
     }
 
@@ -785,27 +789,8 @@ public class NavigationActivity extends Activity
      */
     @Override
     public void onRequestMenu(NavigationView navView, FileSystemObject item) {
-        // Prior to show the dialog, refresh the item reference
-        FileSystemObject fso = null;
-        try {
-            fso = CommandHelper.getFileInfo(this, item.getFullPath(), null);
-
-        } catch (Exception e) {
-            // Notify the user
-            ExceptionUtil.translateException(this, e);
-
-            // Remove the object
-            if (e instanceof FileNotFoundException || e instanceof NoSuchFileOrDirectory) {
-                getCurrentNavigationView().removeItem(item);
-            }
-            return;
-        }
-
-        // Show the dialog
-        ActionsDialog dialog = new ActionsDialog(this, fso);
-        dialog.setOnRequestRefreshListener(this);
-        dialog.setOnSelectionListener(getCurrentNavigationView());
-        dialog.show();
+        // Show the actions dialog
+        openActionsDialog(item, false);
     }
 
     /**
@@ -1154,9 +1139,41 @@ public class NavigationActivity extends Activity
 
     /**
      * Method that opens the actions dialog
+     *
+     * @param item The path or the {@link FileSystemObject}
+     * @param global If the menu to display is the one with global actions
      */
-    private void openActions() {
-        ActionsDialog dialog = new ActionsDialog(this);
+    private void openActionsDialog(Object item, boolean global) {
+        // Resolve the full path
+        String path = String.valueOf(item);
+        if (item instanceof FileSystemObject) {
+            path = ((FileSystemObject)item).getFullPath();
+        }
+
+        // Prior to show the dialog, refresh the item reference
+        FileSystemObject fso = null;
+        try {
+            fso = CommandHelper.getFileInfo(this, path, null);
+
+        } catch (Exception e) {
+            // Notify the user
+            ExceptionUtil.translateException(this, e);
+
+            // Remove the object
+            if (e instanceof FileNotFoundException || e instanceof NoSuchFileOrDirectory) {
+                // If have a FileSystemObject reference then there is no need to search
+                // the path (less resources used)
+                if (item instanceof FileSystemObject) {
+                    getCurrentNavigationView().removeItem((FileSystemObject)item);
+                } else {
+                    getCurrentNavigationView().removeItem((String)item);
+                }
+            }
+            return;
+        }
+
+        // Show the dialog
+        ActionsDialog dialog = new ActionsDialog(this, fso, global);
         dialog.setOnRequestRefreshListener(this);
         dialog.setOnSelectionListener(getCurrentNavigationView());
         dialog.show();
index 9d1ac73..88efc7b 100644 (file)
@@ -833,7 +833,7 @@ public class SearchActivity extends Activity
             return;
         }
 
-        ActionsDialog dialog = new ActionsDialog(this, fso);
+        ActionsDialog dialog = new ActionsDialog(this, fso, false);
         dialog.setOnRequestRefreshListener(this);
         dialog.show();
     }
@@ -864,16 +864,26 @@ public class SearchActivity extends Activity
      */
     @Override
     public void onRequestRefresh(Object o) {
-        if (o instanceof FileSystemObject) {
-            SearchResultAdapter adapter =
-                    (SearchResultAdapter)this.mSearchListView.getAdapter();
-            if (adapter != null) {
+        // Refresh only the item
+        SearchResultAdapter adapter =
+                (SearchResultAdapter)this.mSearchListView.getAdapter();
+        if (adapter != null) {
+            if (o instanceof FileSystemObject) {
+
                 FileSystemObject fso = (FileSystemObject)o;
                 int pos = adapter.getPosition(fso);
                 if (pos >= 0) {
                     SearchResult sr = adapter.getItem(pos);
                     sr.setFso(fso);
                 }
+            } else if (o == null) {
+                // Refresh all
+                List<SearchResult> results = adapter.getData();
+                this.mResultList = new ArrayList<FileSystemObject>(results.size());
+                for (int i=0; i<results.size(); i++) {
+                    this.mResultList.add(results.get(i).getFso());
+                }
+                drawResults();
             }
         }
     }
index 321af6a..f0493b3 100644 (file)
@@ -200,6 +200,23 @@ public class FileSystemObjectAdapter
     }
 
     /**
+     * Method that returns the {@link FileSystemObject} reference from his path.
+     *
+     * @param path The path of the file system object
+     * @return FileSystemObject The file system object reference
+     */
+    public FileSystemObject getItem(String path) {
+        for (int i = 0; i < getCount(); i++) {
+          //File system object info
+            FileSystemObject fso = getItem(i);
+            if (fso.getFullPath().compareTo(path) == 0) {
+                return fso;
+            }
+        }
+        return null;
+    }
+
+    /**
      * Method that process the data before use {@link #getView} method.
      */
     private void processData() {
index ed062c7..37459fc 100644 (file)
@@ -228,8 +228,6 @@ public class SearchResultAdapter extends ArrayAdapter<SearchResult> implements O
         return data;
     }
 
-
-
     /**
      * Returns the position of the specified item in the array.
      *
index dcb7a60..c3531d8 100644 (file)
@@ -49,6 +49,7 @@ import com.cyanogenmod.explorer.util.SelectionHelper;
 public class ActionsDialog implements OnItemClickListener, OnItemLongClickListener {
 
     private final Context mContext;
+    private final boolean mGlobal;
 
     private AlertDialog mDialog;
     private ListView mListView;
@@ -62,33 +63,19 @@ public class ActionsDialog implements OnItemClickListener, OnItemLongClickListen
      * Constructor of <code>ActionsDialog</code>.
      *
      * @param context The current context
-     */
-    public ActionsDialog(Context context) {
-        super();
-
-        // Initialize data
-        this.mFso = null;
-        this.mContext = context;
-
-        //Initialize dialog
-        init(context, R.id.mnu_actions_global);
-    }
-
-    /**
-     * Constructor of <code>ActionsDialog</code>.
-     *
-     * @param context The current context
      * @param fso The file system object associated
+     * @param global If the menu to display will be the global one (Global actions)
      */
-    public ActionsDialog(Context context, FileSystemObject fso) {
+    public ActionsDialog(Context context, FileSystemObject fso, boolean global) {
         super();
 
         //Save the data
         this.mFso = fso;
         this.mContext = context;
+        this.mGlobal = global;
 
         //Initialize dialog
-        init(context, R.id.mnu_actions_fso);
+        init(context, global ? R.id.mnu_actions_global : R.id.mnu_actions_fso);
     }
 
     /**
@@ -173,6 +160,14 @@ public class ActionsDialog implements OnItemClickListener, OnItemLongClickListen
                         this.mContext, this.mFso, this.mOnRequestRefreshListener);
                 return;
 
+            //- Delete
+            case R.id.mnu_actions_refresh:
+                this.mDialog.dismiss();
+                if (this.mOnRequestRefreshListener != null) {
+                    this.mOnRequestRefreshListener.onRequestRefresh(null); //Refresh all
+                }
+                return;
+
             //- Select/Deselect
             case R.id.mnu_actions_select:
             case R.id.mnu_actions_deselect:
@@ -193,6 +188,7 @@ public class ActionsDialog implements OnItemClickListener, OnItemLongClickListen
 
             //- Properties
             case R.id.mnu_actions_properties:
+            case R.id.mnu_actions_properties_current_folder:
                 ActionsPolicy.showPropertiesDialog(
                         this.mContext, this.mFso, this.mOnRequestRefreshListener);
                 break;
@@ -289,7 +285,7 @@ public class ActionsDialog implements OnItemClickListener, OnItemLongClickListen
      */
     private void configureMenu(Menu menu) {
         // Check actions that needs a valid reference
-        if (this.mFso != null) {
+        if (!this.mGlobal && this.mFso != null) {
             //- Select/Deselect -> Only one of them
             if (this.mOnSelectionListener != null) {
                 boolean selected =
index 78dd12b..d0ea4b7 100644 (file)
@@ -450,6 +450,19 @@ public class NavigationView extends RelativeLayout implements
     }
 
     /**
+     * Method that removes a file system object from his path from the view
+     *
+     * @param path The file system object path
+     */
+    public void removeItem(String path) {
+        FileSystemObject fso = this.mAdapter.getItem(path);
+        if (fso != null) {
+            this.mAdapter.remove(fso);
+            this.mAdapter.notifyDataSetChanged();
+        }
+    }
+
+    /**
      * Method that returns the current directory.
      *
      * @return String The current directory