forked from organicmaps/organicmaps
[android] Added processing of BookingFilterParams
This commit is contained in:
parent
a47da1f052
commit
9eb00886d0
9 changed files with 175 additions and 37 deletions
|
@ -279,6 +279,8 @@ public:
|
|||
|
||||
jobjectArray const jrooms =
|
||||
static_cast<jobjectArray>(env->GetObjectField(bookingFilterParams, m_roomsId));
|
||||
ASSERT(jrooms, ("Rooms musn't be non-null!"));
|
||||
|
||||
auto const length = static_cast<size_t>(env->GetArrayLength(jrooms));
|
||||
result.m_rooms.resize(length);
|
||||
for (size_t i = 0; i < length; ++i)
|
||||
|
@ -290,7 +292,6 @@ public:
|
|||
room.SetAgeOfChild(static_cast<int8_t>(env->GetIntField(jroom, m_roomAgeOfChildId)));
|
||||
result.m_rooms[i] = move(room);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -65,6 +65,7 @@ import com.mapswithme.maps.routing.RoutingBottomMenuListener;
|
|||
import com.mapswithme.maps.routing.RoutingController;
|
||||
import com.mapswithme.maps.routing.RoutingPlanFragment;
|
||||
import com.mapswithme.maps.routing.RoutingPlanInplaceController;
|
||||
import com.mapswithme.maps.search.BookingFilterParams;
|
||||
import com.mapswithme.maps.search.FilterActivity;
|
||||
import com.mapswithme.maps.search.FloatingSearchToolbarController;
|
||||
import com.mapswithme.maps.search.HotelsFilter;
|
||||
|
@ -419,12 +420,22 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
final Bundle args = new Bundle();
|
||||
args.putString(SearchActivity.EXTRA_QUERY, query);
|
||||
if (mFilterController != null)
|
||||
args.putParcelable(SearchActivity.EXTRA_HOTELS_FILTER, mFilterController.getFilter());
|
||||
{
|
||||
args.putParcelable(FilterActivity.EXTRA_FILTER, mFilterController.getFilter());
|
||||
args.putParcelable(FilterActivity.EXTRA_FILTER_PARAMS, mFilterController.getBookingFilterParams());
|
||||
}
|
||||
replaceFragment(SearchFragment.class, args, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
SearchActivity.start(this, query, mFilterController != null ? mFilterController.getFilter() : null);
|
||||
HotelsFilter filter = null;
|
||||
BookingFilterParams params = null;
|
||||
if (mFilterController != null)
|
||||
{
|
||||
filter = mFilterController.getFilter();
|
||||
params = mFilterController.getBookingFilterParams();
|
||||
}
|
||||
SearchActivity.start(this, query, filter, params);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -575,8 +586,14 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
@Override
|
||||
public void onFilterClick()
|
||||
{
|
||||
HotelsFilter filter = mFilterController != null ? mFilterController.getFilter() : null;
|
||||
FilterActivity.startForResult(MwmActivity.this, filter,
|
||||
HotelsFilter filter = null;
|
||||
BookingFilterParams params = null;
|
||||
if (mFilterController != null)
|
||||
{
|
||||
filter = mFilterController.getFilter();
|
||||
params = mFilterController.getBookingFilterParams();
|
||||
}
|
||||
FilterActivity.startForResult(MwmActivity.this, filter, params,
|
||||
FilterActivity.REQ_CODE_FILTER);
|
||||
}
|
||||
|
||||
|
@ -1080,6 +1097,8 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
return;
|
||||
|
||||
mFilterController.setFilter(data.getParcelableExtra(FilterActivity.EXTRA_FILTER));
|
||||
BookingFilterParams params = data.getParcelableExtra(FilterActivity.EXTRA_FILTER_PARAMS);
|
||||
mFilterController.setBookingFilterParams(params);
|
||||
runSearch();
|
||||
}
|
||||
|
||||
|
@ -1150,12 +1169,14 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
return true;
|
||||
}
|
||||
|
||||
HotelsFilter filter = intent.getParcelableExtra(SearchActivity.EXTRA_HOTELS_FILTER);
|
||||
HotelsFilter filter = intent.getParcelableExtra(FilterActivity.EXTRA_FILTER);
|
||||
BookingFilterParams params = intent.getParcelableExtra(FilterActivity.EXTRA_FILTER_PARAMS);
|
||||
if (mFilterController != null)
|
||||
{
|
||||
mFilterController.show(filter != null || !TextUtils.isEmpty(SearchEngine.getQuery()), true);
|
||||
mFilterController.setFilter(filter);
|
||||
return filter != null;
|
||||
mFilterController.setBookingFilterParams(params);
|
||||
return filter != null || params != null;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -1638,7 +1659,8 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
return true;
|
||||
case ParsedUrlMwmRequest.RESULT_SEARCH:
|
||||
final ParsedSearchRequest request = Framework.nativeGetParsedSearchRequest();
|
||||
SearchActivity.start(target, request.mQuery, request.mLocale, request.mIsSearchOnMap, null);
|
||||
SearchActivity.start(target, request.mQuery, request.mLocale, request.mIsSearchOnMap,
|
||||
null, null);
|
||||
return true;
|
||||
case ParsedUrlMwmRequest.RESULT_LEAD:
|
||||
return true;
|
||||
|
|
|
@ -1,14 +1,53 @@
|
|||
package com.mapswithme.maps.search;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
class BookingFilterParams
|
||||
public class BookingFilterParams implements Parcelable
|
||||
{
|
||||
static class Room
|
||||
protected BookingFilterParams(Parcel in)
|
||||
{
|
||||
mCheckinMillisec = in.readLong();
|
||||
mCheckoutMillisec = in.readLong();
|
||||
mRooms = in.createTypedArray(Room.CREATOR);
|
||||
}
|
||||
|
||||
public static final Creator<BookingFilterParams> CREATOR = new Creator<BookingFilterParams>()
|
||||
{
|
||||
@Override
|
||||
public BookingFilterParams createFromParcel(Parcel in)
|
||||
{
|
||||
return new BookingFilterParams(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BookingFilterParams[] newArray(int size)
|
||||
{
|
||||
return new BookingFilterParams[size];
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public int describeContents()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags)
|
||||
{
|
||||
dest.writeLong(mCheckinMillisec);
|
||||
dest.writeLong(mCheckoutMillisec);
|
||||
dest.writeTypedArray(mRooms, flags);
|
||||
}
|
||||
|
||||
static class Room implements Parcelable
|
||||
{
|
||||
// This value is corresponds to AvailabilityParams::Room::kNoChildren in core.
|
||||
static final int NO_CHILDREN = -1;
|
||||
|
||||
static final Room DEFAULT = new Room(2, 4);
|
||||
private int mAdultsCount;
|
||||
private int mAgeOfChild;
|
||||
|
||||
|
@ -23,14 +62,48 @@ class BookingFilterParams
|
|||
mAdultsCount = adultsCount;
|
||||
mAgeOfChild = ageOfChild;
|
||||
}
|
||||
|
||||
protected Room(Parcel in)
|
||||
{
|
||||
mAdultsCount = in.readInt();
|
||||
mAgeOfChild = in.readInt();
|
||||
}
|
||||
|
||||
public static final Creator<Room> CREATOR = new Creator<Room>()
|
||||
{
|
||||
@Override
|
||||
public Room createFromParcel(Parcel in)
|
||||
{
|
||||
return new Room(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Room[] newArray(int size)
|
||||
{
|
||||
return new Room[size];
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public int describeContents()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags)
|
||||
{
|
||||
dest.writeInt(mAdultsCount);
|
||||
dest.writeInt(mAgeOfChild);
|
||||
}
|
||||
}
|
||||
|
||||
private long mCheckinMillisec;
|
||||
private long mCheckoutMillisec;
|
||||
@NonNull
|
||||
private Room[] mRooms;
|
||||
private final Room[] mRooms;
|
||||
|
||||
BookingFilterParams(long checkinMillisec, long checkoutMillisec, @NonNull Room[] rooms)
|
||||
BookingFilterParams(long checkinMillisec, long checkoutMillisec, @NonNull Room... rooms)
|
||||
{
|
||||
mCheckinMillisec = checkinMillisec;
|
||||
mCheckoutMillisec = checkoutMillisec;
|
||||
|
|
|
@ -16,28 +16,31 @@ public class FilterActivity extends BaseMwmFragmentActivity
|
|||
{
|
||||
public static final int REQ_CODE_FILTER = 101;
|
||||
public static final String EXTRA_FILTER = "extra_filter";
|
||||
public static final String EXTRA_FILTER_PARAMS = "extra_filter_params";
|
||||
public static final String ACTION_FILTER_APPLY = "action_filter_apply";
|
||||
|
||||
public static void startForResult(@NonNull Activity activity, @Nullable HotelsFilter filter,
|
||||
int requestCode)
|
||||
@Nullable BookingFilterParams params, int requestCode)
|
||||
{
|
||||
Intent i = buildFilterIntent(activity, filter);
|
||||
Intent i = buildFilterIntent(activity, filter, params);
|
||||
activity.startActivityForResult(i, requestCode);
|
||||
}
|
||||
|
||||
public static void startForResult(@NonNull Fragment fragment, @Nullable HotelsFilter filter,
|
||||
int requestCode)
|
||||
@Nullable BookingFilterParams params, int requestCode)
|
||||
{
|
||||
Intent i = buildFilterIntent(fragment.getActivity(), filter);
|
||||
Intent i = buildFilterIntent(fragment.getActivity(), filter, params);
|
||||
fragment.startActivityForResult(i, requestCode);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private static Intent buildFilterIntent(@NonNull Activity activity, @Nullable HotelsFilter filter)
|
||||
private static Intent buildFilterIntent(@NonNull Activity activity, @Nullable HotelsFilter filter,
|
||||
@Nullable BookingFilterParams params)
|
||||
{
|
||||
Intent i = new Intent(activity, FilterActivity.class);
|
||||
Bundle args = new Bundle();
|
||||
args.putParcelable(FilterFragment.ARG_FILTER, filter);
|
||||
args.putParcelable(FilterFragment.ARG_FILTER_PARAMS, params);
|
||||
i.putExtras(args);
|
||||
return i;
|
||||
}
|
||||
|
@ -61,15 +64,17 @@ public class FilterActivity extends BaseMwmFragmentActivity
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onFilterApply(@Nullable HotelsFilter filter)
|
||||
public void onFilterApply(@Nullable HotelsFilter filter, @Nullable BookingFilterParams params)
|
||||
{
|
||||
setResult(filter, ACTION_FILTER_APPLY);
|
||||
setResult(filter, params, ACTION_FILTER_APPLY);
|
||||
}
|
||||
|
||||
private void setResult(@Nullable HotelsFilter filter, @NonNull String action)
|
||||
private void setResult(@Nullable HotelsFilter filter, @Nullable BookingFilterParams params,
|
||||
@NonNull String action)
|
||||
{
|
||||
Intent i = new Intent(action);
|
||||
i.putExtra(EXTRA_FILTER, filter);
|
||||
i.putExtra(EXTRA_FILTER_PARAMS, params);
|
||||
setResult(Activity.RESULT_OK, i);
|
||||
finish();
|
||||
}
|
||||
|
|
|
@ -194,7 +194,9 @@ public class FilterFragment extends BaseMwmToolbarFragment
|
|||
return;
|
||||
|
||||
HotelsFilter filter = populateFilter();
|
||||
mListener.onFilterApply(filter);
|
||||
mListener.onFilterApply(filter, new BookingFilterParams(mCheckinDate.getTimeInMillis(),
|
||||
mCheckoutDate.getTimeInMillis(),
|
||||
BookingFilterParams.Room.DEFAULT));
|
||||
});
|
||||
|
||||
Bundle args = getArguments();
|
||||
|
@ -375,7 +377,7 @@ public class FilterFragment extends BaseMwmToolbarFragment
|
|||
|
||||
Calendar checkout = Calendar.getInstance();
|
||||
checkout.setTimeInMillis(params.getCheckoutMillisec());
|
||||
mCheckinDate = checkout;
|
||||
mCheckoutDate = checkout;
|
||||
mCheckOut.setText(DATE_FORMATTER.format(mCheckoutDate.getTime()));
|
||||
}
|
||||
}
|
||||
|
@ -478,6 +480,6 @@ public class FilterFragment extends BaseMwmToolbarFragment
|
|||
|
||||
interface Listener
|
||||
{
|
||||
void onFilterApply(@Nullable HotelsFilter filter);
|
||||
void onFilterApply(@Nullable HotelsFilter filter, @Nullable BookingFilterParams params);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,4 +6,6 @@ interface HotelsFilterHolder
|
|||
{
|
||||
@Nullable
|
||||
HotelsFilter getHotelsFilter();
|
||||
@Nullable
|
||||
BookingFilterParams getFilterParams();
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.mapswithme.maps.search;
|
|||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StyleRes;
|
||||
|
@ -20,22 +21,26 @@ public class SearchActivity extends BaseMwmFragmentActivity implements CustomNav
|
|||
public static final String EXTRA_QUERY = "search_query";
|
||||
public static final String EXTRA_LOCALE = "locale";
|
||||
public static final String EXTRA_SEARCH_ON_MAP = "search_on_map";
|
||||
public static final String EXTRA_HOTELS_FILTER = "hotels_filter";
|
||||
|
||||
public static void start(@NonNull Activity activity, @Nullable String query,
|
||||
@Nullable HotelsFilter filter)
|
||||
@Nullable HotelsFilter filter, @Nullable BookingFilterParams params)
|
||||
{
|
||||
start(activity, query, null /* locale */, false /* isSearchOnMap */, filter);
|
||||
start(activity, query, null /* locale */, false /* isSearchOnMap */,
|
||||
filter, params);
|
||||
}
|
||||
|
||||
public static void start(@NonNull Activity activity, @Nullable String query, @Nullable String locale,
|
||||
boolean isSearchOnMap, @Nullable HotelsFilter filter)
|
||||
boolean isSearchOnMap, @Nullable HotelsFilter filter,
|
||||
@Nullable BookingFilterParams params)
|
||||
{
|
||||
final Intent i = new Intent(activity, SearchActivity.class);
|
||||
i.putExtra(EXTRA_QUERY, query);
|
||||
i.putExtra(EXTRA_LOCALE, locale);
|
||||
i.putExtra(EXTRA_SEARCH_ON_MAP, isSearchOnMap);
|
||||
i.putExtra(EXTRA_HOTELS_FILTER, filter);
|
||||
Bundle args = new Bundle();
|
||||
args.putString(EXTRA_QUERY, query);
|
||||
args.putString(EXTRA_LOCALE, locale);
|
||||
args.putBoolean(EXTRA_SEARCH_ON_MAP, isSearchOnMap);
|
||||
args.putParcelable(FilterActivity.EXTRA_FILTER, filter);
|
||||
args.putParcelable(FilterActivity.EXTRA_FILTER_PARAMS, params);
|
||||
i.putExtras(args);
|
||||
activity.startActivity(i);
|
||||
activity.overridePendingTransition(R.anim.search_fade_in, R.anim.search_fade_out);
|
||||
}
|
||||
|
@ -75,11 +80,14 @@ public class SearchActivity extends BaseMwmFragmentActivity implements CustomNav
|
|||
{
|
||||
if (fragment instanceof HotelsFilterHolder)
|
||||
{
|
||||
HotelsFilter filter = ((HotelsFilterHolder) fragment).getHotelsFilter();
|
||||
HotelsFilterHolder holder = (HotelsFilterHolder) fragment;
|
||||
HotelsFilter filter = holder.getHotelsFilter();
|
||||
BookingFilterParams params = holder.getFilterParams();
|
||||
if (filter != null)
|
||||
{
|
||||
Intent intent = NavUtils.getParentActivityIntent(this);
|
||||
intent.putExtra(EXTRA_HOTELS_FILTER, filter);
|
||||
intent.putExtra(FilterActivity.EXTRA_FILTER, filter);
|
||||
intent.putExtra(FilterActivity.EXTRA_FILTER_PARAMS, params);
|
||||
NavUtils.navigateUpTo(this, intent);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import com.mapswithme.util.UiUtils;
|
|||
public class SearchFilterController
|
||||
{
|
||||
private static final String STATE_HOTEL_FILTER = "state_hotel_filter";
|
||||
private static final String STATE_FILTER_PARAMS = "state_filter_params";
|
||||
private static final String STATE_HOTEL_FILTER_VISIBILITY = "state_hotel_filter_visibility";
|
||||
|
||||
@NonNull
|
||||
|
@ -165,6 +166,7 @@ public class SearchFilterController
|
|||
public void onSaveState(@NonNull Bundle outState)
|
||||
{
|
||||
outState.putParcelable(STATE_HOTEL_FILTER, mFilter);
|
||||
outState.putParcelable(STATE_FILTER_PARAMS, mBookingFilterParams);
|
||||
outState.putBoolean(STATE_HOTEL_FILTER_VISIBILITY,
|
||||
mFilterButton.getVisibility() == View.VISIBLE);
|
||||
}
|
||||
|
@ -172,6 +174,7 @@ public class SearchFilterController
|
|||
public void onRestoreState(@NonNull Bundle state)
|
||||
{
|
||||
setFilter(state.getParcelable(STATE_HOTEL_FILTER));
|
||||
setBookingFilterParams(state.getParcelable(STATE_FILTER_PARAMS));
|
||||
updateFilterButtonVisibility(state.getBoolean(STATE_HOTEL_FILTER_VISIBILITY, false));
|
||||
}
|
||||
|
||||
|
|
|
@ -216,6 +216,8 @@ public class SearchFragment extends BaseMwmFragment
|
|||
private boolean mInitialSearchOnMap = false;
|
||||
@Nullable
|
||||
private HotelsFilter mInitialHotelsFilter;
|
||||
@Nullable
|
||||
private BookingFilterParams mInitialFilterParams;
|
||||
|
||||
private boolean mIsHotel;
|
||||
@NonNull
|
||||
|
@ -263,6 +265,16 @@ public class SearchFragment extends BaseMwmFragment
|
|||
return mFilterController.getFilter();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public BookingFilterParams getFilterParams()
|
||||
{
|
||||
if (mFilterController == null)
|
||||
return null;
|
||||
|
||||
return mFilterController.getBookingFilterParams();
|
||||
}
|
||||
|
||||
private void showDownloadSuggest()
|
||||
{
|
||||
final FragmentManager fm = getChildFragmentManager();
|
||||
|
@ -374,8 +386,14 @@ public class SearchFragment extends BaseMwmFragment
|
|||
@Override
|
||||
public void onFilterClick()
|
||||
{
|
||||
HotelsFilter filter = mFilterController != null ? mFilterController.getFilter() : null;
|
||||
FilterActivity.startForResult(SearchFragment.this, filter,
|
||||
HotelsFilter filter = null;
|
||||
BookingFilterParams params = null;
|
||||
if (mFilterController != null)
|
||||
{
|
||||
filter = mFilterController.getFilter();
|
||||
params = mFilterController.getBookingFilterParams();
|
||||
}
|
||||
FilterActivity.startForResult(SearchFragment.this, filter, params,
|
||||
FilterActivity.REQ_CODE_FILTER);
|
||||
}
|
||||
|
||||
|
@ -389,6 +407,7 @@ public class SearchFragment extends BaseMwmFragment
|
|||
mFilterController.onRestoreState(savedInstanceState);
|
||||
if (mInitialHotelsFilter != null)
|
||||
mFilterController.setFilter(mInitialHotelsFilter);
|
||||
mFilterController.setBookingFilterParams(mInitialFilterParams);
|
||||
mFilterController.updateFilterButtonVisibility(false);
|
||||
|
||||
if (mSearchAdapter == null)
|
||||
|
@ -491,7 +510,8 @@ public class SearchFragment extends BaseMwmFragment
|
|||
mInitialQuery = arguments.getString(SearchActivity.EXTRA_QUERY);
|
||||
mInitialLocale = arguments.getString(SearchActivity.EXTRA_LOCALE);
|
||||
mInitialSearchOnMap = arguments.getBoolean(SearchActivity.EXTRA_SEARCH_ON_MAP);
|
||||
mInitialHotelsFilter = arguments.getParcelable(SearchActivity.EXTRA_HOTELS_FILTER);
|
||||
mInitialHotelsFilter = arguments.getParcelable(FilterActivity.EXTRA_FILTER);
|
||||
mInitialFilterParams = arguments.getParcelable(FilterActivity.EXTRA_FILTER_PARAMS);
|
||||
}
|
||||
|
||||
private boolean tryRecognizeLoggingCommand(@NonNull String str)
|
||||
|
@ -752,6 +772,8 @@ public class SearchFragment extends BaseMwmFragment
|
|||
return;
|
||||
|
||||
mFilterController.setFilter(data.getParcelableExtra(FilterActivity.EXTRA_FILTER));
|
||||
BookingFilterParams params = data.getParcelableExtra(FilterActivity.EXTRA_FILTER_PARAMS);
|
||||
mFilterController.setBookingFilterParams(params);
|
||||
runSearch();
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue