Merge pull request #9427 from nextcloud/fix/triplicated-search-events

Fix issue where favorites where loaded by triplicate when opening from Media or other search
This commit is contained in:
Álvaro Brey 2021-12-15 11:06:39 +01:00 committed by GitHub
commit 143455b42a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 34 deletions

View file

@ -526,27 +526,22 @@ public abstract class DrawerActivity extends ToolbarActivity
SearchEvent searchEvent = new SearchEvent("image/%", SearchRemoteOperation.SearchType.PHOTO_SEARCH);
MainApp.showOnlyFilesOnDevice(false);
Intent intent = new Intent(getApplicationContext(), FileDisplayActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setAction(Intent.ACTION_SEARCH);
intent.putExtra(OCFileListFragment.SEARCH_EVENT, Parcels.wrap(searchEvent));
intent.putExtra(FileDisplayActivity.DRAWER_MENU_ID, menuItem.getItemId());
startActivity(intent);
launchActivityForSearch(searchEvent, menuItem.getItemId());
}
private void handleSearchEvents(SearchEvent searchEvent, int menuItemId) {
if (this instanceof FileDisplayActivity) {
if (((FileDisplayActivity) this).getListOfFilesFragment() instanceof GalleryFragment) {
Intent intent = new Intent(getApplicationContext(), FileDisplayActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setAction(Intent.ACTION_SEARCH);
intent.putExtra(OCFileListFragment.SEARCH_EVENT, Parcels.wrap(searchEvent));
intent.putExtra(FileDisplayActivity.DRAWER_MENU_ID, menuItemId);
startActivity(intent);
if (((FileDisplayActivity) this).getLeftFragment() instanceof GalleryFragment) {
launchActivityForSearch(searchEvent, menuItemId);
} else {
EventBus.getDefault().post(searchEvent);
}
} else {
launchActivityForSearch(searchEvent, menuItemId);
}
}
private void launchActivityForSearch(SearchEvent searchEvent, int menuItemId) {
Intent intent = new Intent(getApplicationContext(), FileDisplayActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setAction(Intent.ACTION_SEARCH);
@ -554,7 +549,6 @@ public abstract class DrawerActivity extends ToolbarActivity
intent.putExtra(FileDisplayActivity.DRAWER_MENU_ID, menuItemId);
startActivity(intent);
}
}
/**
* sets the new/current account and restarts. In case the given account equals the actual/current account the call

View file

@ -237,7 +237,7 @@ public class OCFileListFragment extends ExtendedListFragment implements
if (intent.getParcelableExtra(OCFileListFragment.SEARCH_EVENT) != null) {
searchEvent = Parcels.unwrap(intent.getParcelableExtra(OCFileListFragment.SEARCH_EVENT));
onMessageEvent(searchEvent);
handleSearchEvent(searchEvent);
}
super.onResume();
@ -747,19 +747,6 @@ public class OCFileListFragment extends ExtendedListFragment implements
((FileActivity) getActivity()).addDrawerListener(mMultiChoiceModeListener);
}
@Override
public void onViewStateRestored(@Nullable Bundle savedInstanceState) {
super.onViewStateRestored(savedInstanceState);
if (savedInstanceState != null) {
searchEvent = Parcels.unwrap(savedInstanceState.getParcelable(SEARCH_EVENT));
}
if (isSearchEventSet(searchEvent)) {
onMessageEvent(searchEvent);
}
}
/**
* Saves the current listed folder.
*/
@ -1489,6 +1476,10 @@ public class OCFileListFragment extends ExtendedListFragment implements
@Subscribe(threadMode = ThreadMode.BACKGROUND)
public void onMessageEvent(final SearchEvent event) {
handleSearchEvent(event);
}
private void handleSearchEvent(SearchEvent event) {
if (SearchRemoteOperation.SearchType.PHOTO_SEARCH == event.searchType) {
return;
}
@ -1663,7 +1654,7 @@ public class OCFileListFragment extends ExtendedListFragment implements
@Override
public void onRefresh() {
if (isSearchEventSet(searchEvent) && searchFragment) {
onMessageEvent(searchEvent);
handleSearchEvent(searchEvent);
mRefreshListLayout.setRefreshing(false);
} else {