From a3494f554c85abcbde6daaf548b459654dced7dc Mon Sep 17 00:00:00 2001 From: Dmitry Donskoy Date: Mon, 4 Jun 2018 19:00:52 +0300 Subject: [PATCH] [android] Fixed processing filter selection action after return to main activity from Discovery screen on tablets --- .../src/com/mapswithme/maps/MwmActivity.java | 77 +++++++++------- .../maps/search/FilterActivity.java | 3 + .../maps/search/FilterFragment.java | 90 ++++++++++--------- 3 files changed, 96 insertions(+), 74 deletions(-) diff --git a/android/src/com/mapswithme/maps/MwmActivity.java b/android/src/com/mapswithme/maps/MwmActivity.java index ea418fbc3a..3384206174 100644 --- a/android/src/com/mapswithme/maps/MwmActivity.java +++ b/android/src/com/mapswithme/maps/MwmActivity.java @@ -194,7 +194,7 @@ public class MwmActivity extends BaseMwmFragmentActivity @Nullable private SearchFilterController mFilterController; - private boolean mIsFragmentContainer; + private boolean mIsTabletLayout; private boolean mIsFullscreen; private boolean mIsFullscreenAnimating; private boolean mIsAppearMenuLater; @@ -382,14 +382,14 @@ public class MwmActivity extends BaseMwmFragmentActivity @Override protected int getFragmentContentResId() { - return (mIsFragmentContainer ? R.id.fragment_container - : super.getFragmentContentResId()); + return (mIsTabletLayout ? R.id.fragment_container + : super.getFragmentContentResId()); } @Nullable Fragment getFragment(Class clazz) { - if (!mIsFragmentContainer) + if (!mIsTabletLayout) throw new IllegalStateException("Must be called for tablets only!"); return getSupportFragmentManager().findFragmentByTag(clazz.getName()); @@ -415,7 +415,7 @@ public class MwmActivity extends BaseMwmFragmentActivity public boolean containsFragment(@NonNull Class fragmentClass) { - return mIsFragmentContainer && getFragment(fragmentClass) != null; + return mIsTabletLayout && getFragment(fragmentClass) != null; } private void showBookmarks() @@ -423,9 +423,18 @@ public class MwmActivity extends BaseMwmFragmentActivity startActivity(new Intent(this, BookmarkCategoriesActivity.class)); } + private void showSearchIfExist(@NonNull Intent data) + { + String query = data.getStringExtra(DiscoveryActivity.EXTRA_FILTER_SEARCH_QUERY); + if (TextUtils.isEmpty(query)) + return; + + showSearch(query); + } + public void showSearch(String query) { - if (mIsFragmentContainer) + if (mIsTabletLayout) { mSearchController.hide(); @@ -458,7 +467,7 @@ public class MwmActivity extends BaseMwmFragmentActivity // TODO(yunikkk) think about refactoring. It probably should be called in editor. Editor.nativeStartEdit(); Statistics.INSTANCE.trackEditorLaunch(false); - if (mIsFragmentContainer) + if (mIsTabletLayout) replaceFragment(EditorHostFragment.class, null, null); else EditorActivity.start(this); @@ -491,7 +500,7 @@ public class MwmActivity extends BaseMwmFragmentActivity final Bundle args = new Bundle(); args.putBoolean(DownloaderActivity.EXTRA_OPEN_DOWNLOADED, openDownloaded); - if (mIsFragmentContainer) + if (mIsTabletLayout) { SearchEngine.INSTANCE.cancel(); mSearchController.refreshToolbar(); @@ -524,9 +533,9 @@ public class MwmActivity extends BaseMwmFragmentActivity super.safeOnCreate(savedInstanceState); if (savedInstanceState != null) mLocationErrorDialogAnnoying = savedInstanceState.getBoolean(EXTRA_LOCATION_DIALOG_IS_ANNOYING); - mIsFragmentContainer = getResources().getBoolean(R.bool.tabletLayout); + mIsTabletLayout = getResources().getBoolean(R.bool.tabletLayout); - if (!mIsFragmentContainer && (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)) + if (!mIsTabletLayout && (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)) getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); setContentView(R.layout.activity_map); @@ -570,7 +579,7 @@ public class MwmActivity extends BaseMwmFragmentActivity mPlacePageTracker = new PlacePageTracker(mPlacePage); } - if (!mIsFragmentContainer) + if (!mIsTabletLayout) { mRoutingPlanInplaceController = new RoutingPlanInplaceController(this, this, this); removeCurrentFragment(false); @@ -755,7 +764,7 @@ public class MwmActivity extends BaseMwmFragmentActivity private void closeAllFloatingPanels() { - if (!mIsFragmentContainer) + if (!mIsTabletLayout) return; closePlacePage(); @@ -846,7 +855,7 @@ public class MwmActivity extends BaseMwmFragmentActivity case ADD_PLACE: closePlacePage(); - if (mIsFragmentContainer) + if (mIsTabletLayout) closeSidePanel(); closeMenu(Statistics.EventName.MENU_ADD_PLACE, AlohaHelper.MENU_ADD_PLACE, new Runnable() { @@ -929,7 +938,7 @@ public class MwmActivity extends BaseMwmFragmentActivity } }); - if (mIsFragmentContainer) + if (mIsTabletLayout) { mPanelAnimator = new PanelAnimator(this); mPanelAnimator.registerListener(mMainMenu.getLeftAnimationTrackListener()); @@ -942,7 +951,7 @@ public class MwmActivity extends BaseMwmFragmentActivity private void showDiscovery() { - if (mIsFragmentContainer) + if (mIsTabletLayout) { replaceFragment(DiscoveryFragment.class, null, null); } @@ -957,7 +966,7 @@ public class MwmActivity extends BaseMwmFragmentActivity private void initOnmapDownloader() { mOnmapDownloader = new OnmapDownloader(this); - if (mIsFragmentContainer) + if (mIsTabletLayout) mPanelAnimator.registerListener(mOnmapDownloader); } @@ -987,10 +996,10 @@ public class MwmActivity extends BaseMwmFragmentActivity mPlacePage.setState(State.HIDDEN); } - if (!mIsFragmentContainer && RoutingController.get().isPlanning()) + if (!mIsTabletLayout && RoutingController.get().isPlanning()) mRoutingPlanInplaceController.onSaveState(outState); - if (mIsFragmentContainer) + if (mIsTabletLayout) { RoutingPlanFragment fragment = (RoutingPlanFragment) getFragment(RoutingPlanFragment.class); if (fragment != null) @@ -1044,7 +1053,7 @@ public class MwmActivity extends BaseMwmFragmentActivity mPlacePageTracker.setMapObject(mapObject); } - if (mIsFragmentContainer) + if (mIsTabletLayout) { RoutingPlanFragment fragment = (RoutingPlanFragment) getFragment(RoutingPlanFragment.class); if (fragment != null) @@ -1058,7 +1067,7 @@ public class MwmActivity extends BaseMwmFragmentActivity } } - if (!mIsFragmentContainer && RoutingController.get().isPlanning()) + if (!mIsTabletLayout && RoutingController.get().isPlanning()) mRoutingPlanInplaceController.restoreState(savedInstanceState); if (mNavigationController != null) @@ -1087,7 +1096,7 @@ public class MwmActivity extends BaseMwmFragmentActivity handleDiscoveryResult(data); break; case FilterActivity.REQ_CODE_FILTER: - handleFilterResult(data); + onActionShowFiltersSelected(data); break; case REQ_CODE_SHOW_SIMILAR_HOTELS: if (mSearchController != null) @@ -1134,6 +1143,14 @@ public class MwmActivity extends BaseMwmFragmentActivity } } + private void onActionShowFiltersSelected(@NonNull Intent data) + { + if (mIsTabletLayout) + showSearchIfExist(data); + else + handleFilterResult(data); + } + private void handleFilterResult(@Nullable Intent data) { if (data == null || mFilterController == null) @@ -1811,7 +1828,7 @@ public class MwmActivity extends BaseMwmFragmentActivity return; } - if (mIsFragmentContainer) + if (mIsTabletLayout) { mMainMenu.setEnabled(MainMenu.Item.P2P, !RoutingController.get().isPlanning()); mMainMenu.setEnabled(MainMenu.Item.SEARCH, !RoutingController.get().isWaitingPoiPick()); @@ -1913,7 +1930,7 @@ public class MwmActivity extends BaseMwmFragmentActivity private void showAddStartFrame() { - if (!mIsFragmentContainer) + if (!mIsTabletLayout) { mRoutingPlanInplaceController.showAddStartFrame(); return; @@ -1926,7 +1943,7 @@ public class MwmActivity extends BaseMwmFragmentActivity private void showAddFinishFrame() { - if (!mIsFragmentContainer) + if (!mIsTabletLayout) { mRoutingPlanInplaceController.showAddFinishFrame(); return; @@ -1939,7 +1956,7 @@ public class MwmActivity extends BaseMwmFragmentActivity private void hideRoutingActionFrame() { - if (!mIsFragmentContainer) + if (!mIsTabletLayout) { mRoutingPlanInplaceController.hideActionFrame(); return; @@ -1994,7 +2011,7 @@ public class MwmActivity extends BaseMwmFragmentActivity { mSearchController.hide(); - if (mIsFragmentContainer) + if (mIsTabletLayout) { replaceFragment(RoutingPlanFragment.class, null, completionListener); if (mRestoreRoutingPlanFragmentNeeded && mSavedForTabletState != null) @@ -2018,7 +2035,7 @@ public class MwmActivity extends BaseMwmFragmentActivity } else { - if (mIsFragmentContainer) + if (mIsTabletLayout) { adjustCompassAndTraffic(UiUtils.getStatusBarHeight(getApplicationContext())); setNavButtonsTopLimit(0); @@ -2120,7 +2137,7 @@ public class MwmActivity extends BaseMwmFragmentActivity @Override public void updateBuildProgress(int progress, @Framework.RouterType int router) { - if (mIsFragmentContainer) + if (mIsTabletLayout) { RoutingPlanFragment fragment = (RoutingPlanFragment) getFragment(RoutingPlanFragment.class); if (fragment != null) @@ -2135,7 +2152,7 @@ public class MwmActivity extends BaseMwmFragmentActivity @Override public void onTaxiInfoReceived(@NonNull TaxiInfo info) { - if (mIsFragmentContainer) + if (mIsTabletLayout) { RoutingPlanFragment fragment = (RoutingPlanFragment) getFragment(RoutingPlanFragment.class); if (fragment != null) @@ -2150,7 +2167,7 @@ public class MwmActivity extends BaseMwmFragmentActivity @Override public void onTaxiError(@NonNull TaxiManager.ErrorCode code) { - if (mIsFragmentContainer) + if (mIsTabletLayout) { RoutingPlanFragment fragment = (RoutingPlanFragment) getFragment(RoutingPlanFragment.class); if (fragment != null) diff --git a/android/src/com/mapswithme/maps/search/FilterActivity.java b/android/src/com/mapswithme/maps/search/FilterActivity.java index 851d578b1f..b77c325cc9 100644 --- a/android/src/com/mapswithme/maps/search/FilterActivity.java +++ b/android/src/com/mapswithme/maps/search/FilterActivity.java @@ -7,8 +7,10 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; +import com.mapswithme.maps.R; import com.mapswithme.maps.activity.CustomNavigateUpListener; import com.mapswithme.maps.base.BaseMwmFragmentActivity; +import com.mapswithme.maps.discovery.DiscoveryActivity; import com.mapswithme.util.ThemeUtils; import com.mapswithme.util.statistics.Statistics; @@ -76,6 +78,7 @@ public class FilterActivity extends BaseMwmFragmentActivity Intent i = new Intent(action); i.putExtra(EXTRA_FILTER, filter); i.putExtra(EXTRA_FILTER_PARAMS, params); + i.putExtra(DiscoveryActivity.EXTRA_FILTER_SEARCH_QUERY, getString(R.string.hotel)); setResult(Activity.RESULT_OK, i); finish(); } diff --git a/android/src/com/mapswithme/maps/search/FilterFragment.java b/android/src/com/mapswithme/maps/search/FilterFragment.java index 4385ac14da..e286b508b1 100644 --- a/android/src/com/mapswithme/maps/search/FilterFragment.java +++ b/android/src/com/mapswithme/maps/search/FilterFragment.java @@ -194,19 +194,7 @@ public class FilterFragment extends BaseMwmToolbarFragment type.addItemDecoration(new TagItemDecoration(mTagsDecorator)); mTypeAdapter = new HotelsTypeAdapter(this); type.setAdapter(mTypeAdapter); - root.findViewById(R.id.done).setOnClickListener( - v -> - { - if (mListener == null) - return; - - HotelsFilter filter = populateFilter(); - mListener.onFilterApply(filter, new BookingFilterParams(mCheckinDate.getTimeInMillis(), - mCheckoutDate.getTimeInMillis(), - BookingFilterParams.Room.DEFAULT)); - Statistics.INSTANCE.trackFilterEvent(Statistics.EventName.SEARCH_FILTER_APPLY, - Statistics.EventParam.HOTEL); - }); + root.findViewById(R.id.done).setOnClickListener(v -> onFilterClicked()); Bundle args = getArguments(); HotelsFilter filter = null; @@ -220,6 +208,19 @@ public class FilterFragment extends BaseMwmToolbarFragment return root; } + private void onFilterClicked() + { + if (mListener == null) + return; + + HotelsFilter filter = populateFilter(); + mListener.onFilterApply(filter, new BookingFilterParams(mCheckinDate.getTimeInMillis(), + mCheckoutDate.getTimeInMillis(), + BookingFilterParams.Room.DEFAULT)); + Statistics.INSTANCE.trackFilterEvent(Statistics.EventName.SEARCH_FILTER_APPLY, + Statistics.EventParam.HOTEL); + } + @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { @@ -231,44 +232,45 @@ public class FilterFragment extends BaseMwmToolbarFragment private void initDateViews(View root) { mCheckIn = root.findViewById(R.id.checkIn); - mCheckIn.setOnClickListener( - v -> - { - DatePickerDialog dialog = - new DatePickerDialog(getActivity(), mCheckinListener, mCheckinDate.get(Calendar.YEAR), - mCheckinDate.get(Calendar.MONTH), - mCheckinDate.get(Calendar.DAY_OF_MONTH)); - dialog.getDatePicker().setMinDate(getMinDateForCheckin().getTimeInMillis()); - dialog.getDatePicker().setMaxDate(getMaxDateForCheckin().getTimeInMillis()); - dialog.show(); - Statistics.INSTANCE.trackFilterClick(Statistics.EventParam.HOTEL, - new Pair<>(Statistics.EventParam.DATE, - Statistics.ParamValue.CHECKIN)); - - }); + mCheckIn.setOnClickListener(v -> onCheckInClicked()); mCheckOut = root.findViewById(R.id.checkOut); - mCheckOut.setOnClickListener( - v -> - { - DatePickerDialog dialog - = new DatePickerDialog(getActivity(), mCheckoutListener, - mCheckoutDate.get(Calendar.YEAR), - mCheckoutDate.get(Calendar.MONTH), - mCheckoutDate.get(Calendar.DAY_OF_MONTH)); - - dialog.getDatePicker().setMinDate(getDayAfter(mCheckinDate).getTimeInMillis()); - dialog.getDatePicker().setMaxDate(getMaxDateForCheckout(mCheckinDate).getTimeInMillis()); - dialog.show(); - Statistics.INSTANCE.trackFilterClick(Statistics.EventParam.HOTEL, - new Pair<>(Statistics.EventParam.DATE, - Statistics.ParamValue.CHECKOUT)); - }); + mCheckOut.setOnClickListener(v -> onCheckOutClicked()); mOfflineWarning = root.findViewById(R.id.offlineWarning); enableDateViewsIfConnected(); } + private void onCheckOutClicked() + { + DatePickerDialog dialog + = new DatePickerDialog(getActivity(), mCheckoutListener, + mCheckoutDate.get(Calendar.YEAR), + mCheckoutDate.get(Calendar.MONTH), + mCheckoutDate.get(Calendar.DAY_OF_MONTH)); + + dialog.getDatePicker().setMinDate(getDayAfter(mCheckinDate).getTimeInMillis()); + dialog.getDatePicker().setMaxDate(getMaxDateForCheckout(mCheckinDate).getTimeInMillis()); + dialog.show(); + Statistics.INSTANCE.trackFilterClick(Statistics.EventParam.HOTEL, + new Pair<>(Statistics.EventParam.DATE, + Statistics.ParamValue.CHECKOUT)); + } + + private void onCheckInClicked() + { + DatePickerDialog dialog = + new DatePickerDialog(getActivity(), mCheckinListener, mCheckinDate.get(Calendar.YEAR), + mCheckinDate.get(Calendar.MONTH), + mCheckinDate.get(Calendar.DAY_OF_MONTH)); + dialog.getDatePicker().setMinDate(getMinDateForCheckin().getTimeInMillis()); + dialog.getDatePicker().setMaxDate(getMaxDateForCheckin().getTimeInMillis()); + dialog.show(); + Statistics.INSTANCE.trackFilterClick(Statistics.EventParam.HOTEL, + new Pair<>(Statistics.EventParam.DATE, + Statistics.ParamValue.CHECKIN)); + } + private void enableDateViewsIfConnected() { UiUtils.showIf(!ConnectionState.isConnected(), mOfflineWarning);