Merge pull request #5296 from nextcloud/fix/defective-search

Fixed defective search
This commit is contained in:
Tobias Kaminsky 2020-02-05 10:56:19 +01:00 committed by GitHub
commit 7c84a9f929
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 127 additions and 121 deletions

View File

@ -5,4 +5,3 @@ NC_TEST_SERVER_PASSWORD=test
android.enableJetifier=true android.enableJetifier=true
android.useAndroidX=true android.useAndroidX=true
android.debug.obsoleteApi=true android.debug.obsoleteApi=true

View File

@ -790,22 +790,17 @@ public class FileDisplayActivity extends FileActivity
//focus the SearchView //focus the SearchView
if (!TextUtils.isEmpty(searchQuery)) { if (!TextUtils.isEmpty(searchQuery)) {
searchView.post(new Runnable() { searchView.post(() -> {
@Override
public void run() {
searchView.setIconified(false); searchView.setIconified(false);
searchView.setQuery(searchQuery, true); searchView.setQuery(searchQuery, true);
searchView.clearFocus(); searchView.clearFocus();
}
}); });
} }
final View mSearchEditFrame = searchView final View mSearchEditFrame = searchView
.findViewById(androidx.appcompat.R.id.search_edit_frame); .findViewById(androidx.appcompat.R.id.search_edit_frame);
searchView.setOnCloseListener(new SearchView.OnCloseListener() { searchView.setOnCloseListener(() -> {
@Override
public boolean onClose() {
if (TextUtils.isEmpty(searchView.getQuery().toString())) { if (TextUtils.isEmpty(searchView.getQuery().toString())) {
searchView.onActionViewCollapsed(); searchView.onActionViewCollapsed();
setDrawerIndicatorEnabled(isDrawerIndicatorAvailable()); // order matters setDrawerIndicatorEnabled(isDrawerIndicatorAvailable()); // order matters
@ -817,15 +812,9 @@ public class FileDisplayActivity extends FileActivity
getListOfFilesFragment().refreshDirectory(); getListOfFilesFragment().refreshDirectory();
} }
} else { } else {
searchView.post(new Runnable() { searchView.post(() -> searchView.setQuery("", true));
@Override
public void run() {
searchView.setQuery("", true);
}
});
} }
return true; return true;
}
}); });
ViewTreeObserver vto = mSearchEditFrame.getViewTreeObserver(); ViewTreeObserver vto = mSearchEditFrame.getViewTreeObserver();
@ -1141,11 +1130,6 @@ public class FileDisplayActivity extends FileActivity
} }
} }
@Override
public void onBackPressed() {
boolean isDrawerOpen = isDrawerOpen();
boolean isSearchOpen = isSearchOpen();
/* /*
* BackPressed priority/hierarchy: * BackPressed priority/hierarchy:
* 1. close search view if opened * 1. close search view if opened
@ -1153,10 +1137,21 @@ public class FileDisplayActivity extends FileActivity
* 3. close FAB if open (only if drawer isn't open) * 3. close FAB if open (only if drawer isn't open)
* 4. navigate up (only if drawer and FAB aren't open) * 4. navigate up (only if drawer and FAB aren't open)
*/ */
@Override
public void onBackPressed() {
boolean isDrawerOpen = isDrawerOpen();
boolean isSearchOpen = isSearchOpen();
OCFileListFragment listOfFiles = getListOfFilesFragment();
if (isSearchOpen && searchView != null) { if (isSearchOpen && searchView != null) {
searchView.setQuery("", true); searchView.setQuery("", true);
searchView.onActionViewCollapsed(); searchView.onActionViewCollapsed();
searchView.clearFocus();
// Remove the list to the original state
listOfFiles.performSearch("", true);
setDrawerIndicatorEnabled(isDrawerIndicatorAvailable()); setDrawerIndicatorEnabled(isDrawerIndicatorAvailable());
} else if (isDrawerOpen) { } else if (isDrawerOpen) {
// close drawer first // close drawer first
@ -1164,7 +1159,7 @@ public class FileDisplayActivity extends FileActivity
} else { } else {
// all closed // all closed
OCFileListFragment listOfFiles = getListOfFilesFragment(); listOfFiles = getListOfFilesFragment();
if (mDualPane || getSecondFragment() == null) { if (mDualPane || getSecondFragment() == null) {
OCFile currentDir = getCurrentDir(); OCFile currentDir = getCurrentDir();
if (currentDir == null || currentDir.getParentId() == FileDataStorageManager.ROOT_PARENT_ID) { if (currentDir == null || currentDir.getParentId() == FileDataStorageManager.ROOT_PARENT_ID) {

View File

@ -45,6 +45,7 @@ import android.view.ScaleGestureDetector;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewTreeObserver; import android.view.ViewTreeObserver;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView; import android.widget.GridView;
@ -136,6 +137,7 @@ public class ExtendedListFragment extends Fragment implements
private EmptyRecyclerView mRecyclerView; private EmptyRecyclerView mRecyclerView;
protected SearchView searchView; protected SearchView searchView;
private ImageView closeButton;
private Handler handler = new Handler(Looper.getMainLooper()); private Handler handler = new Handler(Looper.getMainLooper());
private float mScale = AppPreferencesImpl.DEFAULT_GRID_COLUMN; private float mScale = AppPreferencesImpl.DEFAULT_GRID_COLUMN;
@ -191,6 +193,7 @@ public class ExtendedListFragment extends Fragment implements
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
final MenuItem item = menu.findItem(R.id.action_search); final MenuItem item = menu.findItem(R.id.action_search);
searchView = (SearchView) MenuItemCompat.getActionView(item); searchView = (SearchView) MenuItemCompat.getActionView(item);
closeButton = searchView.findViewById(androidx.appcompat.R.id.search_close_btn);
searchView.setOnQueryTextListener(this); searchView.setOnQueryTextListener(this);
searchView.setOnCloseListener(this); searchView.setOnCloseListener(this);
ThemeUtils.themeSearchView(searchView, true, requireContext()); ThemeUtils.themeSearchView(searchView, true, requireContext());
@ -216,20 +219,27 @@ public class ExtendedListFragment extends Fragment implements
} }
} }
searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() { searchView.setOnQueryTextFocusChangeListener((v, hasFocus) -> handler.post(() -> {
@Override
public void onFocusChange(View v, final boolean hasFocus) {
handler.postDelayed(new Runnable() {
@Override
public void run() {
if (getActivity() != null && !(getActivity() instanceof FolderPickerActivity) if (getActivity() != null && !(getActivity() instanceof FolderPickerActivity)
&& !(getActivity() instanceof UploadFilesActivity)) { && !(getActivity() instanceof UploadFilesActivity)) {
setFabVisible(!hasFocus); setFabVisible(!hasFocus);
if (TextUtils.isEmpty(searchView.getQuery())) {
closeButton.setVisibility(View.INVISIBLE);
}
}
}));
} // On close -> empty field, show keyboard and
} closeButton.setOnClickListener(view -> {
}, 100); searchView.setQuery("", true);
searchView.requestFocus();
searchView.onActionViewExpanded();
InputMethodManager inputMethodManager =
(InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
if (inputMethodManager != null) {
inputMethodManager.showSoftInput(searchView, InputMethodManager.SHOW_IMPLICIT);
} }
}); });
@ -274,6 +284,13 @@ public class ExtendedListFragment extends Fragment implements
} }
public boolean onQueryTextChange(final String query) { public boolean onQueryTextChange(final String query) {
// After 300 ms, set the query
closeButton.setVisibility(View.VISIBLE);
if (query.isEmpty()) {
closeButton.setVisibility(View.INVISIBLE);
}
if (getFragmentManager() != null && getFragmentManager(). if (getFragmentManager() != null && getFragmentManager().
findFragmentByTag(FileDisplayActivity.TAG_SECOND_FRAGMENT) instanceof ExtendedListFragment) { findFragmentByTag(FileDisplayActivity.TAG_SECOND_FRAGMENT) instanceof ExtendedListFragment) {
performSearch(query, false); performSearch(query, false);
@ -285,52 +302,36 @@ public class ExtendedListFragment extends Fragment implements
@Override @Override
public boolean onQueryTextSubmit(String query) { public boolean onQueryTextSubmit(String query) {
performSearch(query, true); performSearch(query, false);
return true; return true;
} }
private void performSearch(final String query, boolean isSubmit) { public void performSearch(final String query, boolean isBackPressed) {
handler.removeCallbacksAndMessages(null); handler.removeCallbacksAndMessages(null);
RecyclerView.Adapter adapter = getRecyclerView().getAdapter(); RecyclerView.Adapter adapter = getRecyclerView().getAdapter();
Activity activity = getActivity();
if (!TextUtils.isEmpty(query)) { if (activity != null) {
int delay = 500;
if (isSubmit) {
delay = 0;
}
if (adapter instanceof OCFileListAdapter) {
handler.postDelayed(new Runnable() {
@Override
public void run() {
EventBus.getDefault().post(new SearchEvent(query,
SearchRemoteOperation.SearchType.FILE_SEARCH,
SearchEvent.UnsetType.NO_UNSET));
}
}, delay);
} else if (adapter instanceof LocalFileListAdapter) {
handler.postDelayed(new Runnable() {
@Override
public void run() {
LocalFileListAdapter localFileListAdapter = (LocalFileListAdapter) adapter;
localFileListAdapter.filter(query);
}
}, delay);
}
if (searchView != null && delay == 0) {
searchView.clearFocus();
}
} else {
Activity activity;
if ((activity = getActivity()) != null) {
if (activity instanceof FileDisplayActivity) { if (activity instanceof FileDisplayActivity) {
if (isBackPressed && TextUtils.isEmpty(query)) {
FileDisplayActivity fileDisplayActivity = (FileDisplayActivity) activity; FileDisplayActivity fileDisplayActivity = (FileDisplayActivity) activity;
fileDisplayActivity.resetSearchView(); fileDisplayActivity.resetSearchView();
fileDisplayActivity.updateListOfFilesFragment(true); fileDisplayActivity.updateListOfFilesFragment(true);
} else {
handler.post(() -> {
if (adapter instanceof OCFileListAdapter) {
EventBus.getDefault().post(new SearchEvent(query,
SearchRemoteOperation.SearchType.FILE_SEARCH,
SearchEvent.UnsetType.NO_UNSET));
} else if (adapter instanceof LocalFileListAdapter) {
LocalFileListAdapter localFileListAdapter = (LocalFileListAdapter) adapter;
localFileListAdapter.filter(query);
}
});
if (searchView != null) {
searchView.clearFocus();
}
}
} else if (activity instanceof UploadFilesActivity) { } else if (activity instanceof UploadFilesActivity) {
LocalFileListAdapter localFileListAdapter = (LocalFileListAdapter) adapter; LocalFileListAdapter localFileListAdapter = (LocalFileListAdapter) adapter;
localFileListAdapter.filter(query); localFileListAdapter.filter(query);
@ -339,7 +340,6 @@ public class ExtendedListFragment extends Fragment implements
} }
} }
} }
}
@Override @Override
public boolean onClose() { public boolean onClose() {
@ -579,7 +579,7 @@ public class ExtendedListFragment extends Fragment implements
/** /**
* Sets the 'visibility' state of the FAB contained in the fragment. * Sets the 'visibility' state of the FAB contained in the fragment.
* * <p>
* When 'false' is set, FAB visibility is set to View.GONE programmatically. * When 'false' is set, FAB visibility is set to View.GONE programmatically.
* *
* @param visible Desired visibility for the FAB. * @param visible Desired visibility for the FAB.
@ -599,7 +599,7 @@ public class ExtendedListFragment extends Fragment implements
/** /**
* Sets the 'visibility' state of the FAB contained in the fragment. * Sets the 'visibility' state of the FAB contained in the fragment.
* * <p>
* When 'false' is set, FAB is greyed out * When 'false' is set, FAB is greyed out
* *
* @param enabled Desired visibility for the FAB. * @param enabled Desired visibility for the FAB.
@ -622,8 +622,7 @@ public class ExtendedListFragment extends Fragment implements
} }
/** /**
/** * /** Set message for empty list view.
* Set message for empty list view.
*/ */
public void setMessageForEmptyList(String message) { public void setMessageForEmptyList(String message) {
if (mEmptyListContainer != null && mEmptyListMessage != null) { if (mEmptyListContainer != null && mEmptyListMessage != null) {
@ -692,43 +691,56 @@ public class ExtendedListFragment extends Fragment implements
); );
} else if (searchType == SearchType.FILE_SEARCH) { } else if (searchType == SearchType.FILE_SEARCH) {
setMessageForEmptyList(R.string.file_list_empty_headline_server_search, setMessageForEmptyList(R.string.file_list_empty_headline_server_search,
R.string.file_list_empty, R.drawable.ic_search_light_grey); R.string.file_list_empty,
R.drawable.ic_search_light_grey);
} else if (searchType == SearchType.FAVORITE_SEARCH) { } else if (searchType == SearchType.FAVORITE_SEARCH) {
setMessageForEmptyList(R.string.file_list_empty_favorite_headline, setMessageForEmptyList(R.string.file_list_empty_favorite_headline,
R.string.file_list_empty_favorites_filter_list, R.drawable.ic_star_light_yellow); R.string.file_list_empty_favorites_filter_list,
R.drawable.ic_star_light_yellow);
} else if (searchType == SearchType.VIDEO_SEARCH) { } else if (searchType == SearchType.VIDEO_SEARCH) {
setMessageForEmptyList(R.string.file_list_empty_headline_server_search_videos, setMessageForEmptyList(R.string.file_list_empty_headline_server_search_videos,
R.string.file_list_empty_text_videos, R.drawable.ic_list_empty_video); R.string.file_list_empty_text_videos,
R.drawable.ic_list_empty_video);
} else if (searchType == SearchType.PHOTO_SEARCH) { } else if (searchType == SearchType.PHOTO_SEARCH) {
setMessageForEmptyList(R.string.file_list_empty_headline_server_search_photos, setMessageForEmptyList(R.string.file_list_empty_headline_server_search_photos,
R.string.file_list_empty_text_photos, R.drawable.ic_list_empty_image); R.string.file_list_empty_text_photos,
R.drawable.ic_list_empty_image);
} else if (searchType == SearchType.RECENTLY_MODIFIED_SEARCH) { } else if (searchType == SearchType.RECENTLY_MODIFIED_SEARCH) {
setMessageForEmptyList(R.string.file_list_empty_headline_server_search, setMessageForEmptyList(R.string.file_list_empty_headline_server_search,
R.string.file_list_empty_recently_modified, R.drawable.ic_list_empty_recent); R.string.file_list_empty_recently_modified,
R.drawable.ic_list_empty_recent);
} else if (searchType == SearchType.RECENTLY_ADDED_SEARCH) { } else if (searchType == SearchType.RECENTLY_ADDED_SEARCH) {
setMessageForEmptyList(R.string.file_list_empty_headline_server_search, setMessageForEmptyList(R.string.file_list_empty_headline_server_search,
R.string.file_list_empty_recently_added, R.drawable.ic_list_empty_recent); R.string.file_list_empty_recently_added,
R.drawable.ic_list_empty_recent);
} else if (searchType == SearchType.REGULAR_FILTER) { } else if (searchType == SearchType.REGULAR_FILTER) {
setMessageForEmptyList(R.string.file_list_empty_headline_search, setMessageForEmptyList(R.string.file_list_empty_headline_search,
R.string.file_list_empty_search, R.drawable.ic_search_light_grey); R.string.file_list_empty_search,
R.drawable.ic_search_light_grey);
} else if (searchType == SearchType.FAVORITE_SEARCH_FILTER) { } else if (searchType == SearchType.FAVORITE_SEARCH_FILTER) {
setMessageForEmptyList(R.string.file_list_empty_headline_server_search, setMessageForEmptyList(R.string.file_list_empty_headline_server_search,
R.string.file_list_empty_favorites_filter, R.drawable.ic_star_light_yellow); R.string.file_list_empty_favorites_filter,
R.drawable.ic_star_light_yellow);
} else if (searchType == SearchType.VIDEO_SEARCH_FILTER) { } else if (searchType == SearchType.VIDEO_SEARCH_FILTER) {
setMessageForEmptyList(R.string.file_list_empty_headline_server_search_videos, setMessageForEmptyList(R.string.file_list_empty_headline_server_search_videos,
R.string.file_list_empty_text_videos_filter, R.drawable.ic_list_empty_video); R.string.file_list_empty_text_videos_filter,
R.drawable.ic_list_empty_video);
} else if (searchType == SearchType.PHOTOS_SEARCH_FILTER) { } else if (searchType == SearchType.PHOTOS_SEARCH_FILTER) {
setMessageForEmptyList(R.string.file_list_empty_headline_server_search_photos, setMessageForEmptyList(R.string.file_list_empty_headline_server_search_photos,
R.string.file_list_empty_text_photos_filter, R.drawable.ic_list_empty_image); R.string.file_list_empty_text_photos_filter,
R.drawable.ic_list_empty_image);
} else if (searchType == SearchType.RECENTLY_MODIFIED_SEARCH_FILTER) { } else if (searchType == SearchType.RECENTLY_MODIFIED_SEARCH_FILTER) {
setMessageForEmptyList(R.string.file_list_empty_headline_server_search, setMessageForEmptyList(R.string.file_list_empty_headline_server_search,
R.string.file_list_empty_recently_modified_filter, R.drawable.ic_list_empty_recent); R.string.file_list_empty_recently_modified_filter,
R.drawable.ic_list_empty_recent);
} else if (searchType == SearchType.RECENTLY_ADDED_SEARCH_FILTER) { } else if (searchType == SearchType.RECENTLY_ADDED_SEARCH_FILTER) {
setMessageForEmptyList(R.string.file_list_empty_headline_server_search, setMessageForEmptyList(R.string.file_list_empty_headline_server_search,
R.string.file_list_empty_recently_added_filter, R.drawable.ic_list_empty_recent); R.string.file_list_empty_recently_added_filter,
R.drawable.ic_list_empty_recent);
} else if (searchType == SearchType.SHARED_FILTER) { } else if (searchType == SearchType.SHARED_FILTER) {
setMessageForEmptyList(R.string.file_list_empty_shared_headline, setMessageForEmptyList(R.string.file_list_empty_shared_headline,
R.string.file_list_empty_shared, R.drawable.ic_list_empty_shared); R.string.file_list_empty_shared,
R.drawable.ic_list_empty_shared);
} }
} }
}); });