From 8eb2567c78ce6677b39259c30ea0234f46c43b17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Brey=20Vilas?= Date: Wed, 1 Dec 2021 17:56:02 +0100 Subject: [PATCH 1/2] DrawerActivity: extract duplicated search launch logic to a method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Álvaro Brey Vilas --- .../android/ui/activity/DrawerActivity.java | 32 ++++++++----------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java b/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java index 2f32b7e46d..00f6da938c 100644 --- a/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java +++ b/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java @@ -526,36 +526,30 @@ 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 { - 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); + 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); + intent.putExtra(OCFileListFragment.SEARCH_EVENT, Parcels.wrap(searchEvent)); + 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 * will be ignored. From 62df4ff4148f796a6d8dfe673c5043efabdeb99b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Brey=20Vilas?= Date: Wed, 1 Dec 2021 18:03:42 +0100 Subject: [PATCH 2/2] OCFileListFragment: Solve triplicated search events MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Most visible when going to Favorites from another search. Signed-off-by: Álvaro Brey Vilas --- .../ui/fragment/OCFileListFragment.java | 25 +++++-------------- 1 file changed, 6 insertions(+), 19 deletions(-) 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 358bac6503..469edcff37 100644 --- a/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java @@ -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(); @@ -385,10 +385,6 @@ public class OCFileListFragment extends ExtendedListFragment implements setTitle(); - if (searchEvent != null) { - onMessageEvent(searchEvent); - } - FragmentActivity fragmentActivity; if ((fragmentActivity = getActivity()) != null && fragmentActivity instanceof FileDisplayActivity) { FileDisplayActivity fileDisplayActivity = (FileDisplayActivity) fragmentActivity; @@ -749,19 +745,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. */ @@ -1490,6 +1473,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 +1650,7 @@ public class OCFileListFragment extends ExtendedListFragment implements @Override public void onRefresh() { if (isSearchEventSet(searchEvent) && searchFragment) { - onMessageEvent(searchEvent); + handleSearchEvent(searchEvent); mRefreshListLayout.setRefreshing(false); } else {