浏览代码

search only folders when copy/move

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
tobiasKaminsky 7 年之前
父节点
当前提交
fab57d271e

+ 28 - 13
src/main/java/com/owncloud/android/ui/activity/FolderPickerActivity.java

@@ -64,12 +64,11 @@ import java.util.ArrayList;
 public class FolderPickerActivity extends FileActivity implements FileFragment.ContainerActivity,
     OnClickListener, OnEnforceableRefreshListener {
 
-    public static final String EXTRA_FOLDER = FolderPickerActivity.class.getCanonicalName()
-                                                            + ".EXTRA_FOLDER";
-    public static final String EXTRA_FILES = FolderPickerActivity.class.getCanonicalName()
-            + ".EXTRA_FILES";
-    public static final String EXTRA_ACTION = FolderPickerActivity.class.getCanonicalName()
-            + ".EXTRA_ACTION";
+    public static final String EXTRA_FOLDER = FolderPickerActivity.class.getCanonicalName() + ".EXTRA_FOLDER";
+    public static final String EXTRA_FILES = FolderPickerActivity.class.getCanonicalName() + ".EXTRA_FILES";
+    public static final String EXTRA_ACTION = FolderPickerActivity.class.getCanonicalName() + ".EXTRA_ACTION";
+    public static final String MOVE = "MOVE";
+    public static final String COPY = "COPY";
 
     private SyncBroadcastReceiver mSyncBroadcastReceiver;
 
@@ -81,6 +80,8 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C
        
     private boolean mSyncInProgress = false;
 
+    private boolean mSearchOnlyFolders = false;
+
     protected Button mCancelBtn;
     protected Button mChooseBtn;
     private String caption;
@@ -92,10 +93,7 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C
         super.onCreate(savedInstanceState);
 
         setContentView(R.layout.files_folder_picker);
-        
-        if (savedInstanceState == null) {
-            createFragments();
-        }
+
 
         // sets callback listeners for UI elements
         initControls();
@@ -104,11 +102,27 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C
         setupToolbar();
         
         if (getIntent().getStringExtra(EXTRA_ACTION) != null) {
-            caption = getIntent().getStringExtra(EXTRA_ACTION);
+            switch (getIntent().getStringExtra(EXTRA_ACTION)) {
+                case MOVE:
+                    caption = getResources().getText(R.string.move_to).toString();
+                    mSearchOnlyFolders = true;
+                    break;
+                case COPY:
+                    caption = getResources().getText(R.string.copy_to).toString();
+                    mSearchOnlyFolders = true;
+                    break;
+                default:
+                    caption = ThemeUtils.getDefaultDisplayNameForRootFolder();
+                    break;
+            }
         } else {
             caption = ThemeUtils.getDefaultDisplayNameForRootFolder();
         }
 
+        if (savedInstanceState == null) {
+            createFragments();
+        }
+
         if (getSupportActionBar() != null) {
             getSupportActionBar().setDisplayShowTitleEnabled(true);
             getSupportActionBar().setTitle(caption);
@@ -166,6 +180,7 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C
         args.putBoolean(OCFileListFragment.ARG_JUST_FOLDERS, true);
         args.putBoolean(OCFileListFragment.ARG_HIDE_FAB, true);
         args.putBoolean(OCFileListFragment.ARG_HIDE_ITEM_OPTIONS, true);
+        args.putBoolean(OCFileListFragment.ARG_SEARCH_ONLY_FOLDER, mSearchOnlyFolders);
         listOfFiles.setArguments(args);
         FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
         transaction.add(R.id.fragment_container, listOfFiles, TAG_LIST_OF_FOLDERS);
@@ -371,9 +386,9 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C
      * Set per-view controllers
      */
     private void initControls(){
-        mCancelBtn = (Button) findViewById(R.id.folder_picker_btn_cancel);
+        mCancelBtn = findViewById(R.id.folder_picker_btn_cancel);
         mCancelBtn.setOnClickListener(this);
-        mChooseBtn = (Button) findViewById(R.id.folder_picker_btn_choose);
+        mChooseBtn = findViewById(R.id.folder_picker_btn_choose);
         mChooseBtn.getBackground().setColorFilter(ThemeUtils.primaryColor(), PorterDuff.Mode.SRC_ATOP);
         mChooseBtn.setOnClickListener(this);
     }

+ 9 - 3
src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java

@@ -132,6 +132,7 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi
     public final static String ARG_ALLOW_CONTEXTUAL_ACTIONS = MY_PACKAGE + ".ALLOW_CONTEXTUAL";
     public final static String ARG_HIDE_FAB = MY_PACKAGE + ".HIDE_FAB";
     public final static String ARG_HIDE_ITEM_OPTIONS = MY_PACKAGE + ".HIDE_ITEM_OPTIONS";
+    public final static String ARG_SEARCH_ONLY_FOLDER = MY_PACKAGE + ".SEARCH_ONLY_FOLDER";
 
     public static final String DOWNLOAD_BEHAVIOUR = "DOWNLOAD_BEHAVIOUR";
     public static final String DOWNLOAD_SEND = "DOWNLOAD_SEND";
@@ -1075,14 +1076,14 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi
             case R.id.action_move: {
                 Intent action = new Intent(getActivity(), FolderPickerActivity.class);
                 action.putParcelableArrayListExtra(FolderPickerActivity.EXTRA_FILES, checkedFiles);
-                action.putExtra(FolderPickerActivity.EXTRA_ACTION, getResources().getText(R.string.move_to));
+                action.putExtra(FolderPickerActivity.EXTRA_ACTION, FolderPickerActivity.MOVE);
                 getActivity().startActivityForResult(action, FileDisplayActivity.REQUEST_CODE__MOVE_FILES);
                 return true;
             }
             case R.id.action_copy: {
                 Intent action = new Intent(getActivity(), FolderPickerActivity.class);
                 action.putParcelableArrayListExtra(FolderPickerActivity.EXTRA_FILES, checkedFiles);
-                action.putExtra(FolderPickerActivity.EXTRA_ACTION, getResources().getText(R.string.copy_to));
+                action.putExtra(FolderPickerActivity.EXTRA_ACTION, FolderPickerActivity.COPY);
                 getActivity().startActivityForResult(action, FileDisplayActivity.REQUEST_CODE__COPY_FILES);
                 return true;
             }
@@ -1517,7 +1518,12 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi
 
         final RemoteOperation remoteOperation;
         if (!currentSearchType.equals(SearchType.SHARED_FILTER)) {
-            remoteOperation = new SearchOperation(event.getSearchQuery(), event.getSearchType());
+            boolean searchOnlyFolders = false;
+            if (getArguments() != null && getArguments().getBoolean(ARG_SEARCH_ONLY_FOLDER, false)) {
+                searchOnlyFolders = true;
+            }
+
+            remoteOperation = new SearchOperation(event.getSearchQuery(), event.getSearchType(), searchOnlyFolders);
         } else {
             remoteOperation = new GetRemoteSharesOperation();
         }