[android] Added filter launch from hotel gallery on the discovery screen

This commit is contained in:
Александр Зацепин 2018-02-05 18:02:59 +03:00 committed by Arsentiy Milchakov
parent 8284c776a7
commit b378c80fe3
4 changed files with 121 additions and 57 deletions

View file

@ -1069,29 +1069,50 @@ public class MwmActivity extends BaseMwmFragmentActivity
handleDiscoveryResult(data);
break;
case FilterActivity.REQ_CODE_FILTER:
handleFilterResult(data);
String query = mSearchController != null ? mSearchController.getQuery() : "";
handleFilterResult(data, query.equals(getString(R.string.hotel)));
break;
}
}
private void handleDiscoveryResult(@NonNull Intent data)
{
final MapObject destination = data.getParcelableExtra(DiscoveryActivity
.EXTRA_DISCOVERY_OBJECT);
if (destination == null)
return;
String action = data.getAction();
if (TextUtils.isEmpty(action))
return;
if (action.equals(DiscoveryActivity.ACTION_ROUTE_TO))
onRouteToDiscoveredObject(destination);
else
onShowDiscoveredObject(destination);
switch (action)
{
case DiscoveryActivity.ACTION_ROUTE_TO:
MapObject destination = data.getParcelableExtra(DiscoveryActivity.EXTRA_DISCOVERY_OBJECT);
if (destination == null)
return;
onRouteToDiscoveredObject(destination);
break;
case DiscoveryActivity.ACTION_SHOW_ON_MAP:
destination = data.getParcelableExtra(DiscoveryActivity.EXTRA_DISCOVERY_OBJECT);
if (destination == null)
return;
onShowDiscoveredObject(destination);
break;
case DiscoveryActivity.ACTION_SHOW_FILTER_RESULTS:
String query = data.getStringExtra(DiscoveryActivity.EXTRA_FILTER_SEARCH_QUERY);
if (TextUtils.isEmpty(query))
return;
if (mSearchController != null)
mSearchController.setQuery(query);
handleFilterResult(data, query.equals(getString(R.string.hotel)));
break;
}
}
private void handleFilterResult(@Nullable Intent data)
private void handleFilterResult(@Nullable Intent data, boolean isHotel)
{
if (data == null || mFilterController == null)
return;
@ -1099,38 +1120,38 @@ public class MwmActivity extends BaseMwmFragmentActivity
mFilterController.setFilter(data.getParcelableExtra(FilterActivity.EXTRA_FILTER));
BookingFilterParams params = data.getParcelableExtra(FilterActivity.EXTRA_FILTER_PARAMS);
mFilterController.setBookingFilterParams(params);
mFilterController.updateFilterButtonVisibility(isHotel);
runSearch();
}
@Override
public void onRouteToDiscoveredObject(@NonNull final MapObject object)
{
addTask(new MapTask()
addTask((MapTask) target ->
{
@Override
public boolean run(MwmActivity target)
{
RoutingController.get().setRouterType(Framework.ROUTER_TYPE_PEDESTRIAN);
RoutingController.get().prepare(true, object);
return false;
}
RoutingController.get().setRouterType(Framework.ROUTER_TYPE_PEDESTRIAN);
RoutingController.get().prepare(true, object);
return false;
});
}
@Override
public void onShowDiscoveredObject(@NonNull final MapObject object)
{
addTask(new MapTask()
addTask((MapTask) target ->
{
@Override
public boolean run(MwmActivity target)
{
Framework.nativeShowFeatureByLatLon(object.getLat(), object.getLon());
return false;
}
Framework.nativeShowFeatureByLatLon(object.getLat(), object.getLon());
return false;
});
}
@Override
public void onShowFilter()
{
FilterActivity.startForResult(MwmActivity.this, null, null,
FilterActivity.REQ_CODE_FILTER);
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
@NonNull int[] grantResults)

View file

@ -5,16 +5,20 @@ import android.content.Intent;
import android.support.annotation.NonNull;
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.bookmarks.data.MapObject;
import com.mapswithme.maps.search.FilterActivity;
public class DiscoveryActivity extends BaseMwmFragmentActivity
implements CustomNavigateUpListener, DiscoveryFragment.DiscoveryListener
{
public static final String EXTRA_DISCOVERY_OBJECT = "extra_discovery_object";
public static final String EXTRA_FILTER_SEARCH_QUERY = "extra_filter_search_query";
public static final String ACTION_ROUTE_TO = "action_route_to";
public static final String ACTION_SHOW_ON_MAP = "action_show_on_map";
public static final String ACTION_SHOW_FILTER_RESULTS = "action_show_filter_results";
@Override
protected Class<? extends Fragment> getFragmentClass()
@ -42,10 +46,38 @@ public class DiscoveryActivity extends BaseMwmFragmentActivity
setResult(object, intent);
}
@Override
public void onShowFilter()
{
FilterActivity.startForResult(this, null, null, FilterActivity.REQ_CODE_FILTER);
}
private void setResult(@NonNull MapObject object, @NonNull Intent intent)
{
intent.putExtra(DiscoveryActivity.EXTRA_DISCOVERY_OBJECT, object);
setResult(Activity.RESULT_OK, intent);
finish();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (resultCode != Activity.RESULT_OK)
return;
switch (requestCode)
{
case FilterActivity.REQ_CODE_FILTER:
if (data == null)
return;
data.setAction(ACTION_SHOW_FILTER_RESULTS);
data.putExtra(EXTRA_FILTER_SEARCH_QUERY, getString(R.string.hotel));
setResult(Activity.RESULT_OK, data);
finish();
break;
}
}
}

View file

@ -231,8 +231,8 @@ public class DiscoveryFragment extends BaseMwmToolbarFragment implements UICallb
public void onAttractionsReceived(@NonNull SearchResult[] results)
{
updateViewsVisibility(results, R.id.attractionsTitle, R.id.attractions);
ItemSelectedListener<Items.SearchItem> listener
= createSearchProductItemListener(SEARCH_ATTRACTIONS);
ItemSelectedListener<Items.SearchItem> listener = new SearchBasedListener(this,
SEARCH_ATTRACTIONS);
getGallery(R.id.attractions).setAdapter(Factory.createSearchBasedAdapter(results, listener,
SEARCH_ATTRACTIONS,
DISCOVERY));
@ -243,8 +243,8 @@ public class DiscoveryFragment extends BaseMwmToolbarFragment implements UICallb
public void onCafesReceived(@NonNull SearchResult[] results)
{
updateViewsVisibility(results, R.id.eatAndDrinkTitle, R.id.food);
ItemSelectedListener<Items.SearchItem> listener =
createSearchProductItemListener(SEARCH_RESTAURANTS);
ItemSelectedListener<Items.SearchItem> listener = new SearchBasedListener(this,
SEARCH_RESTAURANTS);
getGallery(R.id.food).setAdapter(Factory.createSearchBasedAdapter(results, listener,
SEARCH_RESTAURANTS,
DISCOVERY));
@ -254,8 +254,7 @@ public class DiscoveryFragment extends BaseMwmToolbarFragment implements UICallb
public void onHotelsReceived(@NonNull SearchResult[] results)
{
updateViewsVisibility(results, R.id.hotelsTitle, R.id.hotels);
ItemSelectedListener<Items.SearchItem> listener =
createSearchProductItemListener(SEARCH_HOTELS);
ItemSelectedListener<Items.SearchItem> listener = new HotelListener(this);
getGallery(R.id.hotels).setAdapter(Factory.createHotelAdapter(results, listener,
SEARCH_HOTELS,
DISCOVERY));
@ -341,6 +340,12 @@ public class DiscoveryFragment extends BaseMwmToolbarFragment implements UICallb
mDiscoveryListener.onShowDiscoveredObject(createMapObject(item));
}
private void showFilter()
{
if (mDiscoveryListener != null)
mDiscoveryListener.onShowFilter();
}
@NonNull
private static MapObject createMapObject(@NonNull Items.SearchItem item)
{
@ -388,28 +393,6 @@ public class DiscoveryFragment extends BaseMwmToolbarFragment implements UICallb
};
}
private ItemSelectedListener<Items.SearchItem> createSearchProductItemListener
(final @NonNull GalleryType type)
{
return new SearchBasedListener(this)
{
@Override
public void onItemSelected(@NonNull Items.SearchItem item, int position)
{
super.onItemSelected(item, position);
Statistics.INSTANCE.trackGalleryProductItemSelected(type, DISCOVERY, position, PLACEPAGE);
}
@Override
public void onActionButtonSelected(@NonNull Items.SearchItem item, int position)
{
super.onActionButtonSelected(item, position);
Statistics.INSTANCE.trackGalleryProductItemSelected(type, DISCOVERY, position,
ROUTING);
}
};
}
private static class ViatorOfflineSelectedListener extends BaseItemSelectedListener<Items.Item>
{
private ViatorOfflineSelectedListener(@NonNull Activity context)
@ -428,11 +411,14 @@ public class DiscoveryFragment extends BaseMwmToolbarFragment implements UICallb
{
@NonNull
private final DiscoveryFragment mFragment;
@NonNull
private final GalleryType mType;
private SearchBasedListener(@NonNull DiscoveryFragment fragment)
private SearchBasedListener(@NonNull DiscoveryFragment fragment, @NonNull GalleryType type)
{
super(fragment.getActivity());
mFragment = fragment;
mType = type;
}
@Override
@ -440,6 +426,7 @@ public class DiscoveryFragment extends BaseMwmToolbarFragment implements UICallb
public void onItemSelected(@NonNull Items.SearchItem item, int position)
{
mFragment.showOnMap(item);
Statistics.INSTANCE.trackGalleryProductItemSelected(mType, DISCOVERY, position, PLACEPAGE);
}
@Override
@ -447,11 +434,36 @@ public class DiscoveryFragment extends BaseMwmToolbarFragment implements UICallb
public void onActionButtonSelected(@NonNull Items.SearchItem item, int position)
{
mFragment.routeTo(item);
Statistics.INSTANCE.trackGalleryProductItemSelected(mType, DISCOVERY, position,
ROUTING);
}
@NonNull
DiscoveryFragment getFragment()
{
return mFragment;
}
}
private static class HotelListener extends SearchBasedListener
{
private HotelListener(@NonNull DiscoveryFragment fragment)
{
super(fragment, SEARCH_HOTELS);
}
@Override
public void onMoreItemSelected(@NonNull Items.SearchItem item)
{
getFragment().showFilter();
Statistics.INSTANCE.trackGalleryEvent(Statistics.EventName.PP_SPONSOR_MORE_SELECTED,
SEARCH_HOTELS, DISCOVERY);
}
}
public interface DiscoveryListener {
void onRouteToDiscoveredObject(@NonNull MapObject object);
void onShowDiscoveredObject(@NonNull MapObject object);
void onShowFilter();
}
}

View file

@ -118,8 +118,7 @@ public class Items
public SearchItem(@NonNull String title)
{
super(TYPE_MORE, title, null,
null);
super(TYPE_MORE, title, null, null);
mResult = SearchResult.EMPTY;
}