Skip to content

Instantly share code, notes, and snippets.

@HanCheng
Last active August 29, 2015 14:15
Show Gist options
  • Save HanCheng/b921fd0e8696224d20b5 to your computer and use it in GitHub Desktop.
Save HanCheng/b921fd0e8696224d20b5 to your computer and use it in GitHub Desktop.
Slot 1 is for partner merchandising
Slot 2 is for Air Watch when valid. If Air Watch is not valid then show ‘Click to Call’ for US and CA IPs if valid. For all other IPs, show partner merchandising
Slot 3 is for partner merchandising
Slot 4 is for Click to Call if it has not been shown and is valid. If it has been shown, or is not valid, then show Air Watch. Otherwise show partner merchandising
Remaining “n” slots are alternating between merchandising and Air Watch (if valid). Tapping a merchandising unit launches custom web view deep link
============
1. First change the code of calcuating the positions of banner, so in SearchResultAdapter.java:
https://gitlab01d.d.tripadvisor.com/mobile/ta-flights-android/blob/development/TAFlights/src/main/java/com/tripadvisor/android/taflights/adapters/SearchResultAdapter.java#L140
public static Map<Integer, Integer> calculateBannerPositions(int resultSize,
boolean showClickToCallBanner,
boolean showAirWatchBanner) {
// I commented out this code. Based on doc spec, the slot 2: show Ariwatch if valid, else show click to call if valid, otherwise
// show partner merchandising, which means if airwatch and clickToCall are both false, will show merchandising.
// if (!showAirWatchBanner && !showClickToCallBanner) {
// throw new IllegalStateException("Both showClickToCallBanner and " +
// "showAirWatchBanner cannot be false.");
// }
if (resultSize == 0) {
return Collections.emptyMap();
}
boolean isClickToCallShown = false;
Map<Integer, Integer> bannerPositions = new HashMap<Integer, Integer>();
bannerPositions.put(0, TYPE_PARTNER_MERCHANDISING_BANNER); // slot 1 show partner merchandising
if (showAirWatchBanner) {
isClickToCallShown = true;
}
if (resultSize <= INTIAL_BANNER_POSITION) { // for last slot if result size is less than 3
bannerPositions.put(resultSize + 1, showClickToCallBanner ? // since doc does not define which banner to show, will
TYPE_CLICK_TO_CALL_BANNER : TYPE_AIR_WATCH_BANNER); // update once confirmed
} else {
boolean toggleAirWatch = false;
int lastPosition = INTIAL_BANNER_POSITION + 1;
bannerPositions.put(lastPosition, showAirWatchBanner ? TYPE_AIR_WATCH_BANNER :
(showClickToCallBanner ? TYPE_CLICK_TO_CALL_BANNER : TYPE_PARTNER_MERCHANDISING_BANNER)); // slot 2
lastPosition += CONSECUTIVE_BANNER_POSITION + 1;
if (resultSize > lastPosition) {
bannerPositions.put(lastPosition, TYPE_PARTNER_MERCHANDISING_BANNER); // slot 3, partner merchandising
lastPosition += CONSECUTIVE_BANNER_POSITION + 1;
if (resultSize > lastPosition) {
bannerPositions.put(lastPosition, !isClickToCallShown && showClickToCallBanner ?
TYPE_CLICK_TO_CALL_BANNER :
(showAirWatchBanner ? TYPE_AIR_WATCH_BANNER : TYPE_PARTNER_MERCHANDISING_BANNER)); // slot 4
int remainderResults = resultSize - lastPosition + 3;
int offset = 0;
while (remainderResults != 0 && remainderResults > CONSECUTIVE_BANNER_POSITION) {
bannerPositions.put(lastPosition + CONSECUTIVE_BANNER_POSITION + ++offset,
toggleAirWatch && showAirWatchBanner ? TYPE_AIR_WATCH_BANNER :
TYPE_PARTNER_MERCHANDISING_BANNER);
lastPosition += CONSECUTIVE_BANNER_POSITION;
remainderResults -= CONSECUTIVE_BANNER_POSITION;
toggleAirWatch = !toggleAirWatch;
}
}
}
bannerPositions.put(bannerPositions.size() + resultSize, // last slot, if less than 5 itinerary results
toggleAirWatch && showAirWatchBanner ? TYPE_AIR_WATCH_BANNER :
TYPE_PARTNER_MERCHANDISING_BANNER);
}
return bannerPositions;
}
2. create layout file for partner merchandising and inflate it in BannerAdapter.java.
public BannerAdapter(Activity context, boolean isOutboundSegment, FlightSearch flightSearch,
OnBannerVisibilityChangeListener onBannerVisibilityChangeListener) {
super(context, R.layout.click_to_call_banner_row);
// changed mCharSequence variable to mClickToCallCharSequence
mClickToCallCharSequence = Phrase.from(context, R.string.flights_app_call_for_live_agent_cbd)
.put("name", context.getString(R.string.flights_app_cheapo_air)).format();
// check if is outbound
if (isOutboundSegment) {
// flights_app_partner_merchandise_departure_arrival_aiport_code = Search {departure_airport_code} to {arrival_airport_code}
mPartnerSearchFlightCharSequence = Phrase.from(context,
R.string.flights_app_partner_merchandise_departure_arrival_aiport_code)
.put("departure_airport_code", flightSearch.getOriginAirport().getCode())
.put("arrival_airport_code", flightSearch.getDestinationAirport().getCode()).format();
} else {
mPartnerSearchFlightCharSequence = Phrase.from(context,
R.string.flights_app_partner_merchandise_departure_arrival_aiport_code)
.put("departure_airport_code", flightSearch.getDestinationAirport().getCode())
.put("arrival_airport_code", flightSearch.getOriginAirport().getCode()).format();
}
mInflater = LayoutInflater.from(context);
mOnBannerVisibilityChangeListener = onBannerVisibilityChangeListener;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Integer bannerType = mBannerPositions.get(position);
if (convertView == null) {
if (bannerType == SearchResultAdapter.TYPE_CLICK_TO_CALL_BANNER) {
convertView = mInflater.inflate(R.layout.click_to_call_banner_row, parent, false);
} else if (bannerType == SearchResultAdapter.TYPE_AIR_WATCH_BANNER) {
convertView = mInflater.inflate(R.layout.air_watch_banner_row, parent, false);
} else {
// create new layout and inflate if bannerType is partner merchandising
convertView = mInflater.inflate(R.layout.partner_merchandising_banner_row, parent, false);
}
}
if (bannerType == SearchResultAdapter.TYPE_CLICK_TO_CALL_BANNER) {
((TextView) convertView.findViewById(R.id.call_text)).setText(mClickToCallCharSequence);
} else if (bannerType == SearchResultAdapter.TYPE_PARTNER_MERCHANDISING_BANNER) {
// it's still updating, I think I need get the price and logo here.
((RobotoTextView) convertView.findViewById(R.id.partner_search_airport_code))
.setText(mPartnerSearchFlightCharSequence);
}
mOnBannerVisibilityChangeListener.onBannerVisibilityChange(bannerType);
return convertView;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment