diff --git a/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java index 6daa0bf96c..ec31c329e5 100644 --- a/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -1,22 +1,22 @@ /** - * ownCloud Android client application + * ownCloud Android client application * - * @author Bartek Przybylski - * @author David A. Velasco - * Copyright (C) 2011 Bartek Przybylski - * Copyright (C) 2016 ownCloud Inc. - * - * 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. - * - * 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. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * @author Bartek Przybylski + * @author David A. Velasco + * Copyright (C) 2011 Bartek Przybylski + * Copyright (C) 2016 ownCloud Inc. + *

+ * 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. + *

+ * 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. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package com.owncloud.android.ui.activity; @@ -81,6 +81,7 @@ import com.owncloud.android.operations.SynchronizeFileOperation; import com.owncloud.android.operations.UploadFileOperation; import com.owncloud.android.services.observer.FileObserverService; import com.owncloud.android.syncadapter.FileSyncAdapter; +import com.owncloud.android.ui.events.ToggleMenuItemsVisibilityEvent; import com.owncloud.android.ui.fragment.ExtendedListFragment; import com.owncloud.android.ui.fragment.FileDetailFragment; import com.owncloud.android.ui.fragment.FileFragment; @@ -97,6 +98,9 @@ import com.owncloud.android.utils.DisplayUtils; import com.owncloud.android.utils.ErrorMessageAdapter; import com.owncloud.android.utils.PermissionUtil; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; + import java.io.File; import java.util.ArrayList; import java.util.Collection; @@ -146,10 +150,15 @@ public class FileDisplayActivity extends HookActivity private OCFile mWaitingToSend; private Collection mDrawerMenuItemstoShowHideList; + private Collection mMenuItemsToHide = new ArrayList<>(); + private Collection mMenuItemsToShow = new ArrayList<>(); + private String searchQuery; private SearchView searchView; + private Menu mMenu; + @Override protected void onCreate(Bundle savedInstanceState) { Log_OC.v(TAG, "onCreate() start"); @@ -186,7 +195,7 @@ public class FileDisplayActivity extends HookActivity setupToolbar(); // setup drawer - if(MainApp.isOnlyOnDevice()) { + if (MainApp.isOnlyOnDevice()) { setupDrawer(R.id.nav_on_device); } else { setupDrawer(R.id.nav_all_files); @@ -576,17 +585,62 @@ public class FileDisplayActivity extends HookActivity public boolean onPrepareOptionsMenu(Menu menu) { boolean drawerOpen = isDrawerOpen(); - for (MenuItem menuItem:mDrawerMenuItemstoShowHideList) { + for (MenuItem menuItem : mDrawerMenuItemstoShowHideList) { menuItem.setVisible(!drawerOpen); } + for (MenuItem menuItem : mMenuItemsToHide) { + menuItem.setVisible(false); + } + + for (MenuItem menuItem : mMenuItemsToShow) { + menuItem.setVisible(true); + } + return super.onPrepareOptionsMenu(menu); } + @Subscribe(threadMode = ThreadMode.MAIN) + public void onMessageEvent(final ToggleMenuItemsVisibilityEvent event) { + mMenuItemsToHide = new ArrayList<>(); + mMenuItemsToShow = new ArrayList<>(); + + if (mMenu != null) { + if (event.getMenuHideType().equals( + ToggleMenuItemsVisibilityEvent.MenuHideType.HIDE_LIST_GRID_SWITCH_ITEM)) { + if (event.isHideMenuItems()) { + mMenuItemsToHide.add(mMenu.findItem(R.id.action_switch_view)); + } else { + mMenuItemsToShow.add(mMenu.findItem(R.id.action_switch_view)); + } + } else if (event.getMenuHideType().equals( + ToggleMenuItemsVisibilityEvent.MenuHideType.HIDE_SORT_AND_LG_SWITCH_ITEM)) { + if (event.isHideMenuItems()) { + mMenuItemsToHide.add(mMenu.findItem(R.id.action_switch_view)); + mMenuItemsToHide.add(mMenu.findItem(R.id.action_sort)); + } else { + mMenuItemsToShow.add(mMenu.findItem(R.id.action_switch_view)); + mMenuItemsToHide.add(mMenu.findItem(R.id.action_sort)); + } + + } else if (event.getMenuHideType().equals( + ToggleMenuItemsVisibilityEvent.MenuHideType.HIDE_SORT_ITEM)) { + if (event.isHideMenuItems()) { + mMenuItemsToHide.add(mMenu.findItem(R.id.action_sort)); + } else { + mMenuItemsToShow.add(mMenu.findItem(R.id.action_sort)); + } + } + } + + invalidateOptionsMenu(); + } + @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.main_menu, menu); + mMenu = menu; menu.findItem(R.id.action_create_dir).setVisible(false); final MenuItem item = menu.findItem(R.id.action_search); @@ -765,16 +819,16 @@ public class FileDisplayActivity extends HookActivity protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_CODE__SELECT_CONTENT_FROM_APPS && - (resultCode == RESULT_OK || - resultCode == UploadFilesActivity.RESULT_OK_AND_MOVE)) { + (resultCode == RESULT_OK || + resultCode == UploadFilesActivity.RESULT_OK_AND_MOVE)) { requestUploadOfContentFromApps(data, resultCode); } else if (requestCode == REQUEST_CODE__SELECT_FILES_FROM_FILE_SYSTEM && - (resultCode == RESULT_OK || - resultCode == UploadFilesActivity.RESULT_OK_AND_MOVE || - resultCode == UploadFilesActivity.RESULT_OK_AND_DO_NOTHING || - resultCode == UploadFilesActivity.RESULT_OK_AND_DELETE)) { + (resultCode == RESULT_OK || + resultCode == UploadFilesActivity.RESULT_OK_AND_MOVE || + resultCode == UploadFilesActivity.RESULT_OK_AND_DO_NOTHING || + resultCode == UploadFilesActivity.RESULT_OK_AND_DELETE)) { requestUploadOfFilesFromFileSystem(data, resultCode); @@ -863,8 +917,8 @@ public class FileDisplayActivity extends HookActivity //getClipData is only supported on api level 16+, Jelly Bean if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && - contentIntent.getClipData() != null && - contentIntent.getClipData().getItemCount() > 0) { + contentIntent.getClipData() != null && + contentIntent.getClipData().getItemCount() > 0) { for (int i = 0; i < contentIntent.getClipData().getItemCount(); i++) { streamsToUpload.add(contentIntent.getClipData().getItemAt(i).getUri()); @@ -949,10 +1003,10 @@ public class FileDisplayActivity extends HookActivity searchView.setQuery("", true); searchView.onActionViewCollapsed(); setDrawerIndicatorEnabled(isDrawerIndicatorAvailable()); - } else if(isDrawerOpen && isFabOpen) { + } else if (isDrawerOpen && isFabOpen) { // close drawer first super.onBackPressed(); - } else if(isDrawerOpen && !isFabOpen) { + } else if (isDrawerOpen && !isFabOpen) { // close drawer super.onBackPressed(); } else if (!isDrawerOpen && isFabOpen) { @@ -1059,7 +1113,7 @@ public class FileDisplayActivity extends HookActivity } public boolean isFabOpen() { - if(getListOfFilesFragment() != null + if (getListOfFilesFragment() != null && getListOfFilesFragment().getFabMain() != null && getListOfFilesFragment().getFabMain().isExpanded()) { return true; @@ -1124,7 +1178,7 @@ public class FileDisplayActivity extends HookActivity OCFileListFragment fileListFragment = getListOfFilesFragment(); if (fileListFragment != null) { fileListFragment.listDirectory(currentDir, - MainApp.isOnlyOnDevice(), false); + MainApp.isOnlyOnDevice(), false); } } setFile(currentFile); @@ -1189,7 +1243,7 @@ public class FileDisplayActivity extends HookActivity OCFileListFragment ocFileListFragment = getListOfFilesFragment(); if (ocFileListFragment != null) { if (!mSyncInProgress) { - ocFileListFragment.setEmptyListMessage(ExtendedListFragment.SearchType.NO_SEARCH); + ocFileListFragment.setEmptyListMessage(ExtendedListFragment.SearchType.NO_SEARCH); } else { ocFileListFragment.setEmptyListLoadingMessage(); } @@ -1264,8 +1318,7 @@ public class FileDisplayActivity extends HookActivity OCFile ocFile = getFile(); if (PreviewImageFragment.canBePreviewed(ocFile)) { startImagePreview(getFile()); - } - else if (PreviewTextFragment.canBePreviewed(ocFile)) { + } else if (PreviewTextFragment.canBePreviewed(ocFile)) { startTextPreview(ocFile); } // TODO what about other kind of previews? @@ -1544,8 +1597,8 @@ public class FileDisplayActivity extends HookActivity private void onRemoveFileOperationFinish(RemoveFileOperation operation, RemoteOperationResult result) { Toast msg = Toast.makeText(this, - ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()), - Toast.LENGTH_LONG); + ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()), + Toast.LENGTH_LONG); msg.show(); if (result.isSuccess()) { @@ -1925,7 +1978,7 @@ public class FileDisplayActivity extends HookActivity * @param files collection of {@link OCFile} files which operations are wanted to be cancel */ public void cancelTransference(Collection files) { - for(OCFile file: files) { + for (OCFile file : files) { cancelTransference(file); } } diff --git a/src/main/java/com/owncloud/android/ui/adapter/FileListListAdapter.java b/src/main/java/com/owncloud/android/ui/adapter/FileListListAdapter.java index 0aecdbfa9b..8cd0fccfbd 100644 --- a/src/main/java/com/owncloud/android/ui/adapter/FileListListAdapter.java +++ b/src/main/java/com/owncloud/android/ui/adapter/FileListListAdapter.java @@ -53,6 +53,7 @@ import com.owncloud.android.files.services.FileUploader.FileUploaderBinder; import com.owncloud.android.lib.resources.files.RemoteFile; import com.owncloud.android.services.OperationsService.OperationsServiceBinder; import com.owncloud.android.ui.activity.ComponentsGetter; +import com.owncloud.android.ui.fragment.ExtendedListFragment; import com.owncloud.android.ui.interfaces.OCFileListFragmentInterface; import com.owncloud.android.utils.DisplayUtils; import com.owncloud.android.utils.FileStorageUtils; @@ -81,6 +82,7 @@ public class FileListListAdapter extends BaseAdapter { private FilesFilter mFilesFilter; private OCFile currentDirectory; + private boolean isSpecialFilter; public FileListListAdapter( boolean justFolders, @@ -300,7 +302,7 @@ public class FileListListAdapter extends BaseAdapter { checkBoxV.setVisibility(View.VISIBLE); } - // this if-else is needed even though favorite icon is visible by default + // this if-else is needed even though kept-in-sync icon is visible by default // because android reuses views in listview if (!file.isAvailableOffline()) { view.findViewById(R.id.favoriteIcon).setVisibility(View.GONE); @@ -396,6 +398,8 @@ public class FileListListAdapter extends BaseAdapter { */ public void swapDirectory(OCFile directory, FileDataStorageManager updatedStorageManager , boolean onlyOnDevice) { + isSpecialFilter = false; + if (updatedStorageManager != null && !updatedStorageManager.equals(mStorageManager)) { mStorageManager = updatedStorageManager; mAccount = AccountUtils.getCurrentOwnCloudAccount(mContext); @@ -422,18 +426,37 @@ public class FileListListAdapter extends BaseAdapter { notifyDataSetChanged(); } - public void setData(ArrayList objects) { + public void setData(ArrayList objects, ExtendedListFragment.SearchType searchType) { + isSpecialFilter = true; + mFiles = new Vector<>(); for (int i = 0; i < objects.size(); i++) { OCFile ocFile = FileStorageUtils.fillOCFile((RemoteFile) objects.get(i)); mFiles.add(ocFile); } - if (!mShowHiddenFiles) { + /*if (!mShowHiddenFiles) { mFiles = filterHiddenFiles(mFiles); - } + }*/ - mFiles = FileStorageUtils.sortOcFolder(mFiles); + if (searchType.equals(ExtendedListFragment.SearchType.FAVORITE_SEARCH) || + searchType.equals(ExtendedListFragment.SearchType.FAVORITE_SEARCH_FILTER) || + searchType.equals(ExtendedListFragment.SearchType.RECENTLY_MODIFIED_SEARCH) || + searchType.equals(ExtendedListFragment.SearchType.RECENTLY_MODIFIED_SEARCH_FILTER) || + searchType.equals(ExtendedListFragment.SearchType.PHOTO_SEARCH) || + searchType.equals(ExtendedListFragment.SearchType.PHOTOS_SEARCH_FILTER) || + searchType.equals(ExtendedListFragment.SearchType.VIDEO_SEARCH) || + searchType.equals(ExtendedListFragment.SearchType.VIDEO_SEARCH_FILTER)) { + Integer tempSortOrder = FileStorageUtils.mSortOrder; + Boolean tempSortAsc = FileStorageUtils.mSortAscending; + FileStorageUtils.mSortOrder = 1; + FileStorageUtils.mSortAscending = false; + mFiles = FileStorageUtils.sortOcFolder(mFiles); + FileStorageUtils.mSortOrder = tempSortOrder; + FileStorageUtils.mSortAscending = tempSortAsc; + } else { + mFiles = FileStorageUtils.sortOcFolder(mFiles); + } mFilesAll = new Vector<>(); mFilesAll.addAll(mFiles); @@ -505,18 +528,23 @@ public class FileListListAdapter extends BaseAdapter { @Override protected FilterResults performFiltering(CharSequence constraint) { - - FilterResults results = new FilterResults(); Vector filteredFiles = new Vector<>(); if (!TextUtils.isEmpty(constraint)) { for (int i = 0; i < mFilesAll.size(); i++) { OCFile currentFile = mFilesAll.get(i); - if (currentFile.getParentRemotePath().equals(currentDirectory.getRemotePath()) && - currentFile.getFileName().toLowerCase().contains(constraint.toString().toLowerCase()) && - !filteredFiles.contains(currentFile)) { - filteredFiles.add(currentFile); + if (!isSpecialFilter) { + if (currentFile.getParentRemotePath().equals(currentDirectory.getRemotePath()) && + currentFile.getFileName().toLowerCase().contains(constraint.toString().toLowerCase()) && + !filteredFiles.contains(currentFile)) { + filteredFiles.add(currentFile); + } + } else { + if (currentFile.getFileName().toLowerCase().contains(constraint.toString().toLowerCase()) && + !filteredFiles.contains(currentFile)) { + filteredFiles.add(currentFile); + } } } } diff --git a/src/main/java/com/owncloud/android/ui/events/ToggleMenuItemsVisibilityEvent.java b/src/main/java/com/owncloud/android/ui/events/ToggleMenuItemsVisibilityEvent.java new file mode 100644 index 0000000000..4fc1f17fa0 --- /dev/null +++ b/src/main/java/com/owncloud/android/ui/events/ToggleMenuItemsVisibilityEvent.java @@ -0,0 +1,50 @@ +/** + * Nextcloud Android client application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package com.owncloud.android.ui.events; + +/** + * Hide menu items event + */ + +public class ToggleMenuItemsVisibilityEvent { + public enum MenuHideType { + HIDE_LIST_GRID_SWITCH_ITEM, + HIDE_SORT_ITEM, + HIDE_SORT_AND_LG_SWITCH_ITEM + } + + + public final MenuHideType menuHideType; + public final boolean hideMenuItems; + + public ToggleMenuItemsVisibilityEvent(MenuHideType menuHideType, boolean hideMenuItems) { + this.menuHideType = menuHideType; + this.hideMenuItems = hideMenuItems; + } + + public boolean isHideMenuItems() { + return hideMenuItems; + } + + public MenuHideType getMenuHideType() { + return menuHideType; + } + +} diff --git a/src/main/java/com/owncloud/android/ui/fragment/ExtendedListFragment.java b/src/main/java/com/owncloud/android/ui/fragment/ExtendedListFragment.java index 824610255d..11d180dfad 100644 --- a/src/main/java/com/owncloud/android/ui/fragment/ExtendedListFragment.java +++ b/src/main/java/com/owncloud/android/ui/fragment/ExtendedListFragment.java @@ -52,8 +52,11 @@ import android.widget.TextView; import com.getbase.floatingactionbutton.FloatingActionButton; import com.getbase.floatingactionbutton.FloatingActionsMenu; +import com.owncloud.android.MainApp; import com.owncloud.android.R; +import com.owncloud.android.authentication.AccountUtils; import com.owncloud.android.lib.common.utils.Log_OC; +import com.owncloud.android.lib.resources.files.SearchOperation; import com.owncloud.android.ui.ExtendedListView; import com.owncloud.android.ui.activity.FileDisplayActivity; import com.owncloud.android.ui.activity.FolderPickerActivity; @@ -61,7 +64,9 @@ import com.owncloud.android.ui.activity.OnEnforceableRefreshListener; import com.owncloud.android.ui.activity.UploadFilesActivity; import com.owncloud.android.ui.adapter.FileListListAdapter; import com.owncloud.android.ui.adapter.LocalFileListAdapter; +import com.owncloud.android.ui.events.SearchEvent; +import org.greenrobot.eventbus.EventBus; import org.parceler.Parcel; import java.util.ArrayList; @@ -306,8 +311,14 @@ public class ExtendedListFragment extends Fragment handler.postDelayed(new Runnable() { @Override public void run() { - FileListListAdapter fileListListAdapter = (FileListListAdapter) mAdapter; - fileListListAdapter.getFilter().filter(query); + if (AccountUtils.hasSearchSupport(AccountUtils. + getCurrentOwnCloudAccount(MainApp.getAppContext()))) { + EventBus.getDefault().post(new SearchEvent(query, SearchOperation.SearchType.FILE_SEARCH, + SearchEvent.UnsetType.NO_UNSET)); + } else { + FileListListAdapter fileListListAdapter = (FileListListAdapter) mAdapter; + fileListListAdapter.getFilter().filter(query); + } } }, delay); } else if (mAdapter != null && mAdapter instanceof LocalFileListAdapter) { @@ -444,12 +455,12 @@ public class ExtendedListFragment extends Fragment * Calculates the position of the item that will be used as a reference to * reposition the visible items in the list when the device is turned to * other position. - * + *

* The current policy is take as a reference the visible item in the center * of the screen. * * @return The position in the list of the visible item in the center of the - * screen. + * screen. */ protected int getReferencePosition() { if (mCurrentListView != null) { @@ -549,12 +560,12 @@ public class ExtendedListFragment extends Fragment /** * Disables swipe gesture. - * + *

* Sets the 'enabled' state of the refresh layouts contained in the fragment. - * + *

* When 'false' is set, prevents user gestures but keeps the option to refresh programatically, * - * @param enabled Desired state for capturing swipe gesture. + * @param enabled Desired state for capturing swipe gesture. */ public void setSwipeEnabled(boolean enabled) { mRefreshListLayout.setEnabled(enabled); @@ -564,10 +575,10 @@ public class ExtendedListFragment extends Fragment /** * Sets the 'visibility' state of the FAB contained in the fragment. - * + *

* When 'false' is set, FAB visibility is set to View.GONE programmatically, * - * @param enabled Desired visibility for the FAB. + * @param enabled Desired visibility for the FAB. */ public void setFabEnabled(boolean enabled) { if (enabled) { @@ -593,77 +604,84 @@ public class ExtendedListFragment extends Fragment * @param message the message * @param icon the icon to be shown */ - public void setMessageForEmptyList(@StringRes int headline, @StringRes int message, @DrawableRes int icon) { - if (mEmptyListContainer != null && mEmptyListMessage != null) { - mEmptyListHeadline.setText(headline); - mEmptyListMessage.setText(message); - mEmptyListIcon.setImageResource(icon); + public void setMessageForEmptyList(@StringRes final int headline, @StringRes final int message, @DrawableRes final int icon) { + new Handler(Looper.getMainLooper()).post(new Runnable() { + @Override + public void run() { + + if (mEmptyListContainer != null && mEmptyListMessage != null) { + mEmptyListHeadline.setText(headline); + mEmptyListMessage.setText(message); + mEmptyListIcon.setImageResource(icon); - new Handler(Looper.getMainLooper()).post(new Runnable() { - @Override - public void run() { mEmptyListIcon.setVisibility(View.VISIBLE); mEmptyListProgress.setVisibility(View.GONE); } - }); - } + } + }); } - public void setEmptyListMessage(SearchType searchType) { - if (searchType == NO_SEARCH) { - setMessageForEmptyList( - R.string.file_list_empty_headline, - R.string.file_list_empty, - R.drawable.ic_list_empty_folder - ); - } else if (searchType == FILE_SEARCH) { - setMessageForEmptyList(R.string.file_list_empty_headline_server_search, - R.string.file_list_empty, R.drawable.ic_search_light_grey); - } else if (searchType == FAVORITE_SEARCH) { - setMessageForEmptyList(R.string.file_list_empty_headline_server_search, - R.string.file_list_empty_favorites, R.drawable.ic_search_light_grey); - } else if (searchType == VIDEO_SEARCH) { - setMessageForEmptyList(R.string.file_list_empty_headline_server_search_videos, - R.string.file_list_empty_text_videos, R.drawable.ic_search_light_grey); - } else if (searchType == PHOTO_SEARCH) { - setMessageForEmptyList(R.string.file_list_empty_headline_server_search_photos, - R.string.file_list_empty_text_photos, R.drawable.ic_search_light_grey); - } else if (searchType == RECENTLY_MODIFIED_SEARCH) { - setMessageForEmptyList(R.string.file_list_empty_headline_server_search, - R.string.file_list_empty_recently_modified, R.drawable.ic_search_light_grey); - } else if (searchType == RECENTLY_ADDED_SEARCH) { - setMessageForEmptyList(R.string.file_list_empty_headline_server_search, - R.string.file_list_empty_recently_added, R.drawable.ic_search_light_grey); - } else if (searchType == REGULAR_FILTER) { - setMessageForEmptyList(R.string.file_list_empty_headline_search, - R.string.file_list_empty_search, R.drawable.ic_search_light_grey); - } else if (searchType == FAVORITE_SEARCH_FILTER) { + public void setEmptyListMessage(final SearchType searchType) { + new Handler(Looper.getMainLooper()).post(new Runnable() { + @Override + public void run() { - } else if (searchType == VIDEO_SEARCH_FILTER) { + if (searchType == NO_SEARCH) { + setMessageForEmptyList( + R.string.file_list_empty_headline, + R.string.file_list_empty, + R.drawable.ic_list_empty_folder + ); + } else if (searchType == FILE_SEARCH) { + setMessageForEmptyList(R.string.file_list_empty_headline_server_search, + R.string.file_list_empty, R.drawable.ic_search_light_grey); + } else if (searchType == FAVORITE_SEARCH) { + setMessageForEmptyList(R.string.file_list_empty_headline_server_search, + R.string.file_list_empty_favorites, R.drawable.ic_search_light_grey); + } else if (searchType == VIDEO_SEARCH) { + setMessageForEmptyList(R.string.file_list_empty_headline_server_search_videos, + R.string.file_list_empty_text_videos, R.drawable.ic_search_light_grey); + } else if (searchType == PHOTO_SEARCH) { + setMessageForEmptyList(R.string.file_list_empty_headline_server_search_photos, + R.string.file_list_empty_text_photos, R.drawable.ic_search_light_grey); + } else if (searchType == RECENTLY_MODIFIED_SEARCH) { + setMessageForEmptyList(R.string.file_list_empty_headline_server_search, + R.string.file_list_empty_recently_modified, R.drawable.ic_search_light_grey); + } else if (searchType == RECENTLY_ADDED_SEARCH) { + setMessageForEmptyList(R.string.file_list_empty_headline_server_search, + R.string.file_list_empty_recently_added, R.drawable.ic_search_light_grey); + } else if (searchType == REGULAR_FILTER) { + setMessageForEmptyList(R.string.file_list_empty_headline_search, + R.string.file_list_empty_search, R.drawable.ic_search_light_grey); + } else if (searchType == FAVORITE_SEARCH_FILTER) { - } else if (searchType == RECENTLY_MODIFIED_SEARCH_FILTER) { + } else if (searchType == VIDEO_SEARCH_FILTER) { - } else if (searchType == RECENTLY_ADDED_SEARCH_FILTER) { + } else if (searchType == RECENTLY_MODIFIED_SEARCH_FILTER) { - } + } else if (searchType == RECENTLY_ADDED_SEARCH_FILTER) { + + } + } + }); } /** * Set message for empty list view. */ public void setEmptyListLoadingMessage() { - if (mEmptyListContainer != null && mEmptyListMessage != null) { - mEmptyListHeadline.setText(R.string.file_list_loading); - mEmptyListMessage.setText(""); + new Handler(Looper.getMainLooper()).post(new Runnable() { + @Override + public void run() { + if (mEmptyListContainer != null && mEmptyListMessage != null) { + mEmptyListHeadline.setText(R.string.file_list_loading); + mEmptyListMessage.setText(""); - new Handler(Looper.getMainLooper()).post(new Runnable() { - @Override - public void run() { mEmptyListIcon.setVisibility(View.GONE); mEmptyListProgress.setVisibility(View.VISIBLE); } - }); - } + } + }); } /** diff --git a/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java b/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java index 5f995e53f1..2c45c490e4 100644 --- a/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java @@ -77,6 +77,7 @@ import com.owncloud.android.ui.dialog.RenameFileDialogFragment; import com.owncloud.android.ui.events.DummyDrawerEvent; import com.owncloud.android.ui.events.MenuItemClickEvent; import com.owncloud.android.ui.events.SearchEvent; +import com.owncloud.android.ui.events.ToggleMenuItemsVisibilityEvent; import com.owncloud.android.ui.helpers.SparseBooleanArrayParcelable; import com.owncloud.android.ui.interfaces.OCFileListFragmentInterface; import com.owncloud.android.ui.preview.PreviewImageFragment; @@ -97,7 +98,7 @@ import java.util.List; /** * A Fragment that lists all files and folders in a given path. - * + *

* TODO refactor to get rid of direct dependency on FileDisplayActivity */ public class OCFileListFragment extends ExtendedListFragment implements OCFileListFragmentInterface { @@ -407,8 +408,8 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi /** * records a click on a mini FAB and thus: *

    - *
  1. persists the click fact
  2. - *
  3. removes the mini FAB labels
  4. + *
  5. persists the click fact
  6. + *
  7. removes the mini FAB labels
  8. *
*/ private void recordMiniFabClick() { @@ -442,9 +443,9 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi /** * Handler for multiple selection mode. - * + *

* Manages input from the user when one or more files or folders are selected in the list. - * + *

* Also listens to changes in navigation drawer to hide and recover multiple selection when it's opened * and closed. */ @@ -478,7 +479,7 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi * When the navigation drawer is closed, action mode is recovered in the same state as was * when the drawer was (started to be) opened. * - * @param drawerView Navigation drawer just closed. + * @param drawerView Navigation drawer just closed. */ @Override public void onDrawerClosed(View drawerView) { @@ -499,7 +500,7 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi * If the action mode is active when the navigation drawer starts to move, the action * mode is closed and the selection stored to be recovered when the drawer is closed. * - * @param newState One of STATE_IDLE, STATE_DRAGGING or STATE_SETTLING. + * @param newState One of STATE_IDLE, STATE_DRAGGING or STATE_SETTLING. */ @Override public void onDrawerStateChanged(int newState) { @@ -644,7 +645,7 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi /** * Call this, when the user presses the up button. - * + *

* Tries to move up the current folder one level. If the parent folder was removed from the * database, it continues browsing up until finding an existing folders. *

@@ -730,8 +731,8 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi /** * Start the appropriate action(s) on the currently selected files given menu selected by the user. * - * @param menuId Identifier of the action menu selected by the user - * @return 'true' if the menu selection started any action, 'false' otherwise. + * @param menuId Identifier of the action menu selected by the user + * @return 'true' if the menu selection started any action, 'false' otherwise. */ public boolean onFileActionChosen(int menuId) { final ArrayList checkedFiles = mAdapter.getCheckedItems(getListView()); @@ -998,8 +999,9 @@ 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. - * @return 'true' is folder should be shown in grid mode, 'false' if list mode is preferred. + * + * @param file 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) { @@ -1106,6 +1108,39 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi unsetAllMenuItems(true); } + if (event.getSearchType().equals(SearchOperation.SearchType.FILE_SEARCH)) { + setEmptyListMessage(SearchType.FILE_SEARCH); + currentSearchType = SearchType.FILE_SEARCH; + } else if (event.getSearchType().equals(SearchOperation.SearchType.CONTENT_TYPE_SEARCH)) { + if (event.getSearchQuery().equals("image/%")) { + setEmptyListMessage(SearchType.PHOTO_SEARCH); + currentSearchType = SearchType.PHOTO_SEARCH; + } else if (event.getSearchQuery().equals("video/%")) { + setEmptyListMessage(SearchType.VIDEO_SEARCH); + currentSearchType = SearchType.VIDEO_SEARCH; + } + } else if (event.getSearchType().equals(SearchOperation.SearchType.FAVORITE_SEARCH)) { + setEmptyListMessage(SearchType.FAVORITE_SEARCH); + currentSearchType = SearchType.FAVORITE_SEARCH; + } else if (event.getSearchType().equals(SearchOperation.SearchType.RECENTLY_ADDED_SEARCH)) { + setEmptyListMessage(SearchType.RECENTLY_ADDED_SEARCH); + currentSearchType = SearchType.RECENTLY_ADDED_SEARCH; + } else if (event.getSearchType().equals(SearchOperation.SearchType.RECENTLY_MODIFIED_SEARCH)) { + setEmptyListMessage(SearchType.RECENTLY_MODIFIED_SEARCH); + currentSearchType = SearchType.RECENTLY_MODIFIED_SEARCH; + } + + + Runnable switchViewsRunnable = new Runnable() { + @Override + public void run() { + if (isGridViewPreferred(mFile) && !isGridEnabled()) { + switchToGridView(); + } else if (!isGridViewPreferred(mFile) && isGridEnabled()) { + switchToListView(); + } + } + }; Account currentAccount = com.owncloud.android.authentication.AccountUtils. getCurrentOwnCloudAccount(MainApp.getAppContext()); @@ -1120,33 +1155,33 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi getClientFor(ocAccount, MainApp.getAppContext()); SearchOperation operation = new SearchOperation(event.getSearchQuery(), event.getSearchType()); RemoteOperationResult remoteOperationResult = operation.execute(mClient); - if (remoteOperationResult.isSuccess() || remoteOperationResult.getData() != null) { - - if (event.getSearchType().equals(SearchOperation.SearchType.FILE_SEARCH)) { - setEmptyListMessage(SearchType.FILE_SEARCH); - currentSearchType = SearchType.FILE_SEARCH; - } else if (event.getSearchType().equals(SearchOperation.SearchType.CONTENT_TYPE_SEARCH)) { - if (event.getSearchQuery().equals("image/%")) { - setEmptyListMessage(SearchType.PHOTO_SEARCH); - currentSearchType = SearchType.PHOTO_SEARCH; - } else if (event.getSearchQuery().equals("video/%")) { - setEmptyListMessage(SearchType.VIDEO_SEARCH); - currentSearchType = SearchType.VIDEO_SEARCH; - } - } else if (event.getSearchType().equals(SearchOperation.SearchType.FAVORITE_SEARCH)) { - setEmptyListMessage(SearchType.FAVORITE_SEARCH); - currentSearchType = SearchType.FAVORITE_SEARCH; - } else if (event.getSearchType().equals(SearchOperation.SearchType.RECENTLY_ADDED_SEARCH)) { - setEmptyListMessage(SearchType.RECENTLY_ADDED_SEARCH); - currentSearchType = SearchType.RECENTLY_ADDED_SEARCH; - } else if (event.getSearchType().equals(SearchOperation.SearchType.RECENTLY_MODIFIED_SEARCH)) { - setEmptyListMessage(SearchType.RECENTLY_MODIFIED_SEARCH); - currentSearchType = SearchType.RECENTLY_MODIFIED_SEARCH; - } - - mAdapter.setData(remoteOperationResult.getData()); + if (remoteOperationResult.isSuccess() && remoteOperationResult.getData() != null) { + mAdapter.setData(remoteOperationResult.getData(), currentSearchType); } + + if (currentSearchType.equals(SearchType.PHOTO_SEARCH)) { + new Handler(Looper.getMainLooper()).post(new Runnable() { + @Override + public void run() { + switchToGridView(); + } + }); + + EventBus.getDefault().post(new ToggleMenuItemsVisibilityEvent( + ToggleMenuItemsVisibilityEvent.MenuHideType.HIDE_SORT_AND_LG_SWITCH_ITEM, true)); + } else if (currentSearchType.equals(SearchType.NO_SEARCH) || currentSearchType.equals( + SearchType.REGULAR_FILTER)) { + EventBus.getDefault().post(new ToggleMenuItemsVisibilityEvent( + ToggleMenuItemsVisibilityEvent.MenuHideType.HIDE_SORT_AND_LG_SWITCH_ITEM, false)); + + new Handler(Looper.getMainLooper()).post(switchViewsRunnable); + } else { + EventBus.getDefault().post(new ToggleMenuItemsVisibilityEvent( + ToggleMenuItemsVisibilityEvent.MenuHideType.HIDE_SORT_ITEM, true)); + new Handler(Looper.getMainLooper()).post(switchViewsRunnable); + } + } catch (AuthenticatorException e) { e.printStackTrace(); } catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) {