Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.taxipixi.taxiexchange.activities;
- import android.app.Activity;
- import android.app.AlertDialog;
- import android.content.Context;
- import android.content.DialogInterface;
- import android.content.Intent;
- import android.net.ConnectivityManager;
- import android.net.NetworkInfo;
- import android.os.Bundle;
- import android.support.v4.app.LoaderManager;
- import android.support.v4.content.Loader;
- import android.text.TextUtils;
- import android.util.Log;
- import android.util.TypedValue;
- import android.view.View;
- import android.widget.AdapterView;
- import android.widget.ArrayAdapter;
- import android.widget.FrameLayout;
- import android.widget.ImageView;
- import android.widget.LinearLayout;
- import android.widget.ListView;
- import android.widget.ProgressBar;
- import android.widget.RelativeLayout;
- import android.widget.TextView;
- import android.widget.Toast;
- import com.facebook.AppEventsLogger;
- import com.google.gson.reflect.TypeToken;
- import com.google.inject.Inject;
- import com.taxipixi.Constants;
- import com.taxipixi.activities.DialogActivity;
- import com.taxipixi.api.ApiAsyncTask;
- import com.taxipixi.api.ApiConstants;
- import com.taxipixi.entity.Order;
- import com.taxipixi.entity.PaymentMethod;
- import com.taxipixi.entity.Place;
- import com.taxipixi.entity.Profile;
- import com.taxipixi.fare.ApproximatedFareForType;
- import com.taxipixi.fare.ApproximatedFareInfo;
- import com.taxipixi.fare.IsItDayOrNight;
- import com.taxipixi.gcm.PushRegistrar;
- import com.taxipixi.navigation.CurrentPlaceListener;
- import com.taxipixi.navigation.GetAddressesTask;
- import com.taxipixi.taxiexchange.CustomerConstants;
- import com.taxipixi.taxiexchange.LoginPreferences;
- import com.taxipixi.taxiexchange.R;
- import com.taxipixi.taxiexchange.TaxiPixiApp;
- import com.taxipixi.taxiexchange.api.BookingSettings;
- import com.taxipixi.taxiexchange.api.GetBookingSettings;
- import com.taxipixi.taxiexchange.api.GetInappMessages;
- import com.taxipixi.taxiexchange.api.GetProfileTask;
- import com.taxipixi.taxiexchange.api.GlobalVariable;
- import com.taxipixi.taxiexchange.api.OrderManager;
- import com.taxipixi.taxiexchange.api.PlaceListFromServer;
- import com.taxipixi.taxiexchange.api.PreOrder;
- import com.taxipixi.taxiexchange.api.SubmitOrderTask;
- import com.taxipixi.taxiexchange.api.UserLocationAndHourlyPackages;
- import com.taxipixi.taxiexchange.api.cached.CachingOrderManager;
- import com.taxipixi.taxiexchange.api.cached.CachingPlacesManager;
- import com.taxipixi.taxiexchange.api.payment.GetMyCardsTask;
- import com.taxipixi.taxiexchange.data.serverResponce;
- import com.taxipixi.taxiexchange.database.DatabaseHelper;
- import com.taxipixi.taxiexchange.database.NotificationDatabaseConnector;
- import com.taxipixi.taxiexchange.fragments.BottomRecConfirmFragment;
- import com.taxipixi.taxiexchange.fragments.BottomRecFragment;
- import com.taxipixi.taxiexchange.fragments.MapFragmentWithCenteredMarker;
- import com.taxipixi.taxiexchange.fragments.ServiceNotAvailableFragment;
- import com.taxipixi.taxiexchange.models.FavouriteBean;
- import com.taxipixi.taxiexchange.models.FavouriteSync;
- import com.taxipixi.taxiexchange.models.FavouritedPlaces;
- import com.taxipixi.taxiexchange.utils.Lists;
- import com.taxipixi.taxiexchange.utils.SetFont;
- import com.taxipixi.taxiexchange.widgets.ClosestCabInfoHintView;
- import com.taxipixi.taxiexchange.widgets.HeaderWidget;
- import com.taxipixi.taxiexchange.widgets.MenuUtility;
- import com.taxipixi.taxiexchange.widgets.ProfileWidget;
- import com.taxipixi.utils.Animator;
- import com.taxipixi.utils.DecimalFormating;
- import com.taxipixi.widget.AddressWidget;
- import com.taxipixi.widget.WidgetListBox;
- import org.jetbrains.annotations.NotNull;
- import org.jetbrains.annotations.Nullable;
- import org.json.JSONArray;
- import org.json.JSONObject;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Calendar;
- import java.util.Date;
- import java.util.List;
- import java.util.Locale;
- import java.util.concurrent.TimeUnit;
- import roboguice.content.RoboAsyncTaskLoader;
- import roboguice.inject.InjectView;
- import rx.Observable;
- import rx.Observer;
- import rx.Subscriber;
- import rx.Subscription;
- import rx.android.schedulers.AndroidSchedulers;
- import rx.functions.Action1;
- import rx.functions.Func1;
- import rx.functions.Func2;
- import rx.functions.FuncN;
- import rx.schedulers.Schedulers;
- import rx.subscriptions.Subscriptions;
- import timber.log.Timber;
- import static com.taxipixi.taxiexchange.models.IJson.gson;
- public class DestinationActivity extends PickingLocationActivity
- implements AddressWidget.OnUserLocationLoadedListener,
- AddressWidget.OnPointChangedListener,
- WidgetListBox.OnUIChangedListener, CurrentPlaceListener,
- BottomRecFragment.OnFragmentButtonsClicked {
- public static final String NEW_BOOKING = "new_booking";
- public static final String FROM_DESTINATION_ACTIVITY = "from_destination_activity";
- public static final String ADDRESS_TYPE = "requested_address_type";
- public static final int REQUEST_BOOKING_SUMMARY = 12;
- private static final int REQUEST_CONFIRMATION = 7;
- public static final int TIME_EDIT = 14;
- private static final String KEY_PICKUP_TIME = "pickup_time";
- private static final String PICK_UP = "pick_up";
- public static final String DESTINATION = "destination";
- private static final String STATE_ASK_LOCATION = "ask_location";
- public static final String ORDER = "ORDER";
- private static final String TAG = "DestinationActivity";
- private GetAddressesTask.Runner taskRunner;
- private boolean isAskToEnableLocation = true;
- private boolean isDialogShown = false;
- private MapFragmentWithCenteredMarker mMapFragmentWithCenteredMarker;
- @InjectView(R.id.pickup_address)
- private AddressWidget pickupWidget;
- @InjectView(R.id.pickup_marker)
- private ImageView mPickUpMarkerImageView;
- @InjectView(R.id.destination_marker)
- private ImageView mDestinationMarkerImageView;
- @InjectView(R.id.header)
- private HeaderWidget mHeaderWidgetView;
- @InjectView(R.id.destination_address)
- private AddressWidget mDestinationWidgetView;
- @InjectView(R.id.submitBtn)
- private RelativeLayout mSubmitBtn;
- @InjectView(R.id.map_selector)
- private View map_selector;
- @InjectView(R.id.icon_my_location)
- private View mMyCurrentLocationView;
- @InjectView(R.id.hint)
- private ClosestCabInfoHintView mClosestTaxiHintView;
- @InjectView(R.id.chooseTimeBtn)
- private LinearLayout mChooseTimeLayout;
- @InjectView(R.id.timeDateText)
- private TextView mTimeDisplayTextView;
- @Inject
- private PushRegistrar pushRegistrar;
- @Inject
- private LoginPreferences loginPrefs;
- @Inject
- private PreferencesStorage preferencesStorage;
- @Inject
- private Context context;
- @Inject
- CachingPlacesManager cachingPlacesManager;
- @Inject
- DatabaseHelper databaseHelper;
- @Inject
- PlaceListFromServer placeListFromServer;
- @Inject
- CachingOrderManager cachedOrderManager;
- // @InjectExtra(Constants.PICKUP_PLACE)
- // private Place pickup;
- private long selectedTime;
- private boolean isToday;
- private String bookingType = CustomerConstants.POINT_TO_POINT;
- private RelativeLayout mDurationBlocksLayout;
- private RelativeLayout mDurationColorLayout;
- private ImageView mDurationArrowImg;
- private RelativeLayout mSelectDurationLayout;
- private View mSelectDurationView;
- private boolean isInDurationSelectionMode = false;
- private boolean isDurationActive = false;
- private ListView mDurationListView;
- private TextView mSelectedDurationTextView;
- private ArrayList<String> mDurationsList = new ArrayList<String>();
- private ArrayList<String> mDurationsIDList = new ArrayList<String>();
- private int current = -1;
- public static final int LOADER_COUNTRIES_HOURLY = 1;
- private String userCountry = "";
- private
- @Nullable
- String userCity = "";
- private RelativeLayout mDaysWidgetLayout;
- private String[] daysDurationArray = new String[]{"1 DAY", "2 DAYS", "3 DAYS", "4 DAYS", "5 DAYS", "6 DAYS", "7 DAYS", "8 DAYS"};
- private String[] daysDurationArabicArray = new String[]{"يوم واحد", "يومين", "ثلاثة أيام", "أربعة أيام", "خمسة أيام", "ستة أيام", "سبعة أيام", "ثمانية أيام"};
- private WidgetListBox mWidgetListBox;
- private TextView mAddDestLabel;
- private static boolean p2pOneScreen = true, hourlyOneScreen = false, p2pDestMandatory = false, hourlyDestMandatory = false, p2p_job_assignment = false;
- private static int per_km_speed = 360;
- private String previousCountry = "", previousCity = "";
- private FrameLayout bottomBarContainer;
- private BottomRecFragment bottomBarFragment;
- private BottomRecConfirmFragment bottomBarConfirmFragment;
- public ApproximatedFareInfo approximatedFareInfo = null;
- private BookingSettings bookingSettings = null;
- private String countryNameFromPlace = null;
- Subscription subscription = Subscriptions.empty();
- private static PopupSms.ActivityFinishListener mListener;
- private ServiceNotAvailableFragment mServiceNotAvailableFragment = new ServiceNotAvailableFragment();
- private boolean isPickup, isDest;
- private ApproximatedFareForType selectedType;
- private boolean rideNow = false;
- private ProgressBar progress;
- private Date currentDate;
- @Inject
- private IsItDayOrNight isItDayOrNight;
- private List<String> list_inapp;
- private long lastOrderID;
- // private Receiver receiver = new Receiver();
- public static void setOnActivityFinishListener(Activity listener) {
- mListener = (PopupSms.ActivityFinishListener) listener;
- }
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(com.taxipixi.taxiexchange.R.layout.activity_destination);
- MenuUtility.setLoginPrefs(loginPrefs);
- ProfileWidget.setLoginPrefs(loginPrefs);
- Log.e(TAG, "lang - " + Locale.getDefault().getLanguage());
- getPickUpWidget().setUserLocationLoadedListener(this);
- getPickUpWidget().setPointChangedListener(this);
- getDestinationWidgetView().setPointChangedListener(this);
- mMapFragmentWithCenteredMarker = (MapFragmentWithCenteredMarker) getSupportFragmentManager().findFragmentById(R.id.mapfragment);
- mMapFragmentWithCenteredMarker.initializePickUpMarkers(mPickUpMarkerImageView, R.drawable.customer_place);
- mMapFragmentWithCenteredMarker.initializeDestinationMarkers(mDestinationMarkerImageView, R.drawable.customer_place);
- setTitle(R.string.booking_title);
- bookingSettings = ((TaxiPixiApp) getApplication()).getBookingSettings();
- pickupWidget.setParentActivity(this);
- mDestinationWidgetView.setParentActivity(this);
- // add for arabic layout !!!
- mAddDestLabel = (TextView) findViewById(R.id.addDestLabel);
- SetFont.setNeoSansStdRegular(this, mAddDestLabel);
- mAddDestLabel.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- if (bookingType.equals(CustomerConstants.POINT_TO_POINT) && mDestinationWidgetView.getVisibility() != View.VISIBLE) {
- mAddDestLabel.setVisibility(View.GONE);
- mDestinationWidgetView.startAnimation(Animator.getSingleInstance().getSlideRightIn(context));
- mDestinationWidgetView.setVisibility(View.VISIBLE);
- try {
- setWidgetsActive(false, true);
- } catch (Exception ex) {
- Toast.makeText(getApplicationContext(), R.string.internal_application_error, Toast.LENGTH_SHORT).show();
- }
- }
- }
- });
- bottomBarContainer = (FrameLayout) findViewById(R.id.bottombar);
- bottomBarContainer.setVisibility(View.GONE);
- mSubmitBtn.setVisibility(View.GONE);
- LinearLayout btn_selectDuration = (LinearLayout) findViewById(R.id.btn_select_duration);
- mSelectDurationLayout = (RelativeLayout) findViewById(R.id.durationSelectBlockLayout);
- mSelectDurationView = findViewById(R.id.view_select_duration);
- mDurationListView = (ListView) findViewById(R.id.durationList);
- mSelectedDurationTextView = (TextView) findViewById(R.id.tv_select_duration);
- mDurationBlocksLayout = (RelativeLayout) findViewById(R.id.durationBlocksLayout);
- mDurationColorLayout = (RelativeLayout) findViewById(R.id.iv_duration_color);
- mDurationArrowImg = (ImageView) findViewById(R.id.duration_arrow_img);
- mDaysWidgetLayout = (RelativeLayout) findViewById(R.id.daysChooseLayout);
- mWidgetListBox = (WidgetListBox) findViewById(R.id.days_widget_listbox);
- SetFont.setNeoSansStdRegular(this, mSelectedDurationTextView);
- SetFont.setNeoSansStdRegular(this, mTimeDisplayTextView);
- mWidgetListBox.setListenerToUIChanges(this);
- btn_selectDuration.setOnClickListener(selectDurationClick);
- mHeaderWidgetView.initialize(this, preferencesStorage, CustomerConstants.HEADER_DOUBLE_MODE, false, new ArrayList<String>(Arrays.asList(getResources().getString(R.string.title_point_to_point), getResources().getString(R.string.title_hourly))),
- new int[]{R.drawable.fare_menu_point_selected, R.drawable.fare_menu_hour_selected}, clickListener);
- mHeaderWidgetView.setImagesSelected(new int[]{R.drawable.fare_menu_point, R.drawable.fare_menu_hour});
- bookingType = CustomerConstants.POINT_TO_POINT;
- pickupWidget.getSearchAddress().setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- setWidgetsActive(true, false);
- startManualAddressPicker(PICK_UP);
- }
- });
- mDestinationWidgetView.getSearchAddress().setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- setWidgetsActive(false, true);
- startManualAddressPicker(DESTINATION);
- }
- });
- mMyCurrentLocationView.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- mMapFragmentWithCenteredMarker.onCurrentLocationClicked();
- }
- });
- setSelectedTime(getSelectedTime());
- getCabOverlaysProvider().setClosestCabInfoListener(mClosestTaxiHintView);
- mChooseTimeLayout.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Intent i = new Intent(DestinationActivity.this, CalendarScreen.class);
- i.putExtra(CalendarScreen.TAG_SELECTED_TIME, selectedTime);
- startActivityForResult(i, TIME_EDIT);
- overridePendingTransition(R.anim.bottom_in, R.anim.top_out);
- }
- });
- if (savedInstanceState != null) {
- isAskToEnableLocation = savedInstanceState.getBoolean(STATE_ASK_LOCATION, true);
- bookingType = savedInstanceState.getString(CustomerConstants.BOOKING_TYPE);
- }
- //pickupWidget.setTitleText(getResources().getString(R.string.map_seatchbox_top));
- //mDestinationWidgetView.setTitleText(getResources().getString(R.string.widget_destination));
- pickupWidget.setIsPickup(true);
- mDestinationWidgetView.setIsPickup(false);
- setZoomButtonPosition();
- subscription = databaseHelper.getSyncQueue()
- .map(new Func1<List<FavouriteSync>, List<Observable<?>>>() {
- @Override
- public List<Observable<?>> call(List<FavouriteSync> favouriteSyncs) {
- return Lists.map(favouriteSyncs, new Func1<FavouriteSync, Observable<?>>() {
- @Override
- public Observable<?> call(FavouriteSync sync) {
- return from(sync);
- }
- });
- }
- })
- .flatMap(new Func1<List<Observable<?>>, Observable<?>>() {
- @Override
- public Observable<?> call(List<Observable<?>> observables) {
- Timber.d("gonna make %d requests", observables.size());
- return Observable.zip(observables, new FuncN<Object>() {
- @Override
- public Object call(Object... args) {
- return null;
- }
- });
- }
- })
- .observeOn(AndroidSchedulers.mainThread())
- .subscribe(new Observer<Object>() {
- @Override
- public void onCompleted() {
- preloadFavouritesAndRecents();
- }
- @Override
- public void onError(Throwable e) {
- Timber.e(e, "");
- }
- @Override
- public void onNext(Object o) {
- }
- });
- progress = (ProgressBar) findViewById(R.id.progressBar2);
- checkInapp_msgs();
- defaultPayment();
- defaultCard();
- }
- private void defaultCard() {
- new GetMyCardsTask(this) {
- @Override
- protected void onSuccess(serverResponce res) throws Exception {
- super.onSuccess(res);
- JSONArray jsonArray_cards = new JSONArray(res.getText());
- for (int i = 0; i < jsonArray_cards.length(); i++) {
- JSONObject card = (JSONObject) jsonArray_cards.get(i);
- String token = card.getString("token");
- String last4 = card.getString("last4");
- String brand = card.getString("brand");
- boolean selected = card.getBoolean("default_card");
- String name = brand.toUpperCase() + " - " + last4;
- if (selected) {
- GlobalVariable.defaultpayment = last4;
- }
- }
- }
- }.execute();
- }
- private void defaultPayment() {
- new GetProfileTask(this) {
- @Override
- protected void onSuccess(Profile profile) throws Exception {
- if (profile != null) {
- super.onSuccess(profile);
- if (profile.getDefault_payment_method().equals(PaymentMethod.DEF_PAY_METH_CASH)) {
- Log.d("default_way1", profile.getDefault_payment_method());
- GlobalVariable.defaultpaymentway = "cash";
- } else if (profile.getDefault_payment_method().equals(PaymentMethod.DEF_PAY_METH_CARD)) {
- Log.d("default_way2", profile.getDefault_payment_method());
- GlobalVariable.defaultpaymentway = "card";
- }
- }
- }
- }.execute();
- }
- private void checkInapp_msgs() {
- new GetInappMessages(DestinationActivity.this) {
- @Override
- protected void onSuccess(List<String> str) throws Exception {
- super.onSuccess(str);
- list_inapp = str;
- Log.e("reali", "inapp_msgs " + str.size());
- Intent i = new Intent(context, WebViewActivityPopup.class);
- if (list_inapp.size() == 1) {
- i.putExtra(NotificationDatabaseConnector.URL, list_inapp.get(0));
- } else if (list_inapp.size() > 1) {
- i.putStringArrayListExtra("urls", (ArrayList) list_inapp);
- } else {
- return;
- }
- i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- startActivity(i);
- }
- }.execute();
- }
- @Override
- public void onResume() {
- super.onResume();
- if (mListener != null) {
- if (mListener instanceof ProfileActivity) {
- mListener.closeActivity();
- }
- }
- if (selectedTime < System.currentTimeMillis()) {
- selectedTime = getSelectedTime();
- }
- new CheckRunningOrders(this).execute();
- // IntentFilter filter = new IntentFilter();
- // filter.addAction(CustomerConstants.WEB_POPUP_BROADCAST_ACTION);
- //
- // registerReceiver(receiver, filter);
- // removeLabel();//cased destination location disapearing, should remove if no bugs appeared;
- AppEventsLogger.activateApp(getBaseContext(), CustomerConstants.FACEBOOK_API_KEY);
- }
- @Override
- protected void onPause() {
- super.onPause();
- }
- @NotNull
- Observable<?> from(@NotNull final FavouriteSync sync) {
- return Observable
- .create(new Observable.OnSubscribe<Place>() {
- @Override
- public void call(Subscriber<? super Place> subscriber) {
- subscriber.onNext(gson.fromJson(sync.getData(), Place.class));
- subscriber.onCompleted();
- }
- })
- .flatMap(new Func1<Place, Observable<?>>() {
- @Override
- public Observable<?> call(final Place place) {
- return (sync.getAction() == FavouriteSync.Action.ADD
- ? placeListFromServer.addToFavourites(place)
- : placeListFromServer.removeFromFavourites(place))
- .retry(2)
- .map(new Func1<String, List<Place>>() {
- @Override
- public List<Place> call(String s) {
- final List<FavouriteBean> list = gson.fromJson(
- s,
- new TypeToken<List<FavouriteBean>>() {
- }.getType());
- return Lists.map(
- list,
- new Func1<FavouriteBean, Place>() {
- @Override
- public Place call(FavouriteBean favouriteBean) {
- return favouriteBean.toPlace();
- }
- });
- }
- })
- .doOnNext(new Action1<List<Place>>() {
- @Override
- public void call(List<Place> places) {
- final int i = places.indexOf(place);
- if (i != -1) {
- databaseHelper.replaceInFavs(place, places.get(i));
- }
- }
- });
- }
- })
- .subscribeOn(Schedulers.io());
- }
- @Override
- protected void onDestroy() {
- subscription.unsubscribe();
- p2pOneScreen = true;
- p2pDestMandatory = hourlyDestMandatory = hourlyOneScreen = false;
- super.onDestroy();
- }
- void preloadFavouritesAndRecents() {
- Observable.merge(cachingPlacesManager.preloadFavourites()
- .subscribeOn(Schedulers.io())
- .retry(5),
- cachingPlacesManager.preloadRecents()
- .subscribeOn(Schedulers.io())
- .retry(5))
- .onErrorReturn(new Func1<Throwable, List<Place>>() {
- @Override
- public List<Place> call(Throwable throwable) {
- return null;
- }
- })
- .subscribe();
- }
- private HeaderWidget.HeaderTextClickedListener clickListener = new HeaderWidget.HeaderTextClickedListener() {
- @Override
- public void onClicked(int index) {
- if (index == 0) {
- if (!bookingType.equals(CustomerConstants.POINT_TO_POINT)) {
- resetBookings();
- }
- bookingType = CustomerConstants.POINT_TO_POINT;
- if (p2pOneScreen)
- getSupportLoaderManager().restartLoader(0, null, infoLoaderCallbacks);
- else
- removeBottomBar();
- } else {
- if (!bookingType.equals(CustomerConstants.HOURLY)) {
- resetBookings();
- }
- bookingType = CustomerConstants.HOURLY;
- getSupportLoaderManager().destroyLoader(0);
- removeBottomBar();
- //determineBookingFlow();
- //HOURLY!
- // if(hourlyOneScreen)
- // getSupportLoaderManager().restartLoader(0, null, infoLoaderCallbacks);
- }
- }
- };
- @Override
- public void onUserLocationChanged(Place place) {
- Log.e(TAG, "onUserLocationChanged");
- if (place.getUserCurrentCountry() == null) {
- taskRunner = new GetAddressesTask.Runner(getApplicationContext(), new Locale("en"));
- taskRunner.runTask(place.getLatLng(), this);
- } else {
- if (!place.getUserCurrentCountry().equals("Nigeria") &&
- !place.getUserCurrentCountry().equals("Saudi Arabia") &&
- !place.getUserCurrentCountry().equals("USA") &&
- !place.getUserCurrentCountry().equals("India")) {
- getSupportLoaderManager().restartLoader(0, null, infoLoaderCallbacks);
- } else {
- removeLabel();
- removeBottomBar();
- determineBookingFlow();
- }
- }
- }
- @Override
- public void onPointChanged(boolean isPickup) {
- Log.e(TAG, "onPointChanged onPointChanged onPointChanged");
- if (isPickup)
- this.isPickup = true;
- else
- this.isDest = true;
- if (bookingType.equals(CustomerConstants.POINT_TO_POINT) && this.isPickup && isDest)
- calcEstimFare(true);
- }
- private void calcEstimFare(boolean check) {
- if (!check || (check && !pickupWidget.getPlace().equals(mDestinationWidgetView.getPlace()))) {
- bottomBarConfirmFragment.showEstimatedCostProgress();
- getSupportLoaderManager().restartLoader(0, null, fareLoaderCallbacks);
- //Log.e(TAG, "CALC CALC CALC");
- }
- }
- @Override
- public void onUserLocationLoaded(Place place) {
- previousCountry = userCountry = place.getUserCurrentCountry();
- previousCity = userCity = place.getUserCurrentCity();
- determineBookingFlow();
- preloadStuff(userCity);
- // if (isConnectingToInternet(DestinationActivity.this)) {
- // getSupportLoaderManager().initLoader(LOADER_COUNTRIES_HOURLY, null, callbackHourlyCountries);
- // }
- }
- @Override
- public void onTextSelected(String text) {
- getSupportLoaderManager().restartLoader(0, null, infoLoaderCallbacks);
- }
- public void nextClicked(View w) {
- Log.d(TAG, "nextClicked");
- if (bookingType.equals(CustomerConstants.HOURLY)) {
- Log.d(TAG, "here-1");
- try {
- if (pickupWidget != null) {
- String country = pickupWidget.getPlace().getUserCurrentCountry();
- // Log.e("reali", "hourly country _" + country + "_ countryNameFromPlace " + countryNameFromPlace);
- // for (BookingSettings settings : bookingSettings.mBookingSettingsList) {
- // Log.e("reali", "bookingSettings _" + settings.getCountry() + "_");
- // }
- boolean isInList = false;
- if (country != null) {
- //["Bangalore","Delhi\/NCR","Hyderabad","Mumbai","Kuala Lumpur","Jaipur","Udaipur","Kerala","Kanyakumari","Lucknow","Goa","Penang","Ahmedabad","Kolkata","Riyadh","Abha","Jeddah","Mecca","Cairo","Baku","Lagos","Amman","Pune","Medina"]
- for (BookingSettings settings : bookingSettings.mBookingSettingsList) {
- if (settings.getCountry().equals(country)) {
- isInList = true;
- Log.e("reali", "InList _" + country);
- mDurationsList.clear();
- mDurationsList.addAll(settings.getmPackages());
- mDurationsIDList.clear();
- mDurationsIDList.addAll(settings.getmPackagesId());
- }
- }
- if (!isInList) {
- Toast.makeText(getApplicationContext(), getString(R.string.booking_not_available), Toast.LENGTH_LONG).show();
- return;
- }
- } else if (countryNameFromPlace != null) {
- for (BookingSettings settings : bookingSettings.mBookingSettingsList) {
- if (settings.getCountry().equals(countryNameFromPlace)) {
- isInList = true;
- Log.e("reali", "InList _" + countryNameFromPlace);
- mDurationsList.clear();
- mDurationsList.addAll(settings.getmPackages());
- mDurationsIDList.clear();
- mDurationsIDList.addAll(settings.getmPackagesId());
- }
- }
- if (!isInList) {
- Toast.makeText(getApplicationContext(), getString(R.string.booking_not_available), Toast.LENGTH_LONG).show();
- return;
- }
- } else {
- Toast.makeText(this, getString(R.string.cannot_determine_country), Toast.LENGTH_LONG).show();
- return;
- }
- } else {
- Toast.makeText(this, getString(R.string.cannot_determine_country), Toast.LENGTH_LONG).show();
- return;
- }
- } catch (Exception ex) {
- Log.e(TAG, "unexpected error = " + ex.getMessage());
- }
- ArrayAdapter<String> adapterCity = null;
- // if (Locale.getDefault().getLanguage().equals("ar")) {
- // adapterCity = new ArrayAdapter<String>(this, R.layout.duration_list_item, R.id.tv_name_selection, mDurationsArabicList);
- // } else {
- // if (mDurationsList.size() != 0)
- adapterCity = new ArrayAdapter<String>(this, R.layout.duration_list_item, R.id.tv_name_selection, mDurationsList);
- // }
- mDurationListView.setAdapter(adapterCity);
- mDurationListView.setOnItemClickListener(durationListListener);
- }
- Log.d(TAG, "here-2");
- String[] arr = mSelectedDurationTextView.getText().toString().split("/");
- String packageStr = arr[0];
- Log.d("DestinationActivity:", "Selected _" + packageStr + "_");
- Log.d(TAG, "here-3");
- if (bookingType.equals(CustomerConstants.POINT_TO_POINT) && mDestinationWidgetView.getVisibility() != View.VISIBLE) {
- if (mAddDestLabel.getVisibility() == View.VISIBLE) {
- mAddDestLabel.setVisibility(View.GONE);
- }
- Log.d(TAG, "here-4");
- mDestinationWidgetView.startAnimation(Animator.getSingleInstance().getSlideRightIn(context));
- mDestinationWidgetView.setVisibility(View.VISIBLE);
- try {
- setWidgetsActive(false, true);
- } catch (Exception ex) {
- Toast.makeText(getApplicationContext(), R.string.internal_application_error, Toast.LENGTH_SHORT).show();
- }
- } else if (bookingType.equals(CustomerConstants.HOURLY) && hourlyDestMandatory && mDestinationWidgetView.getVisibility() != View.VISIBLE) {
- mDestinationWidgetView.startAnimation(Animator.getSingleInstance().getSlideRightIn(context));
- mDestinationWidgetView.setVisibility(View.VISIBLE);
- isDurationActive = true;
- try {
- setWidgetsActive(false, true);
- } catch (Exception ex) {
- Toast.makeText(getApplicationContext(), R.string.internal_application_error, Toast.LENGTH_SHORT).show();
- }
- } else if (bookingType.equals(CustomerConstants.HOURLY) && mDurationBlocksLayout.getVisibility() != View.VISIBLE) {
- Log.d(TAG, "here-5");
- mDurationBlocksLayout.startAnimation(Animator.getSingleInstance().getSlideRightIn(context));
- mDurationBlocksLayout.setVisibility(View.VISIBLE);
- isDurationActive = true;
- try {
- setWidgetsActive(false, false);
- } catch (Exception ex) {
- Log.d(TAG, "--ex=" + ex.getMessage());
- Toast.makeText(getApplicationContext(), R.string.internal_application_error, Toast.LENGTH_SHORT).show();
- }
- } else if (!validateLocation(true)) {
- Log.d(TAG, "here-6");
- return;
- } else if (bookingType.equals(CustomerConstants.HOURLY) && !(mDurationsList.contains(mSelectedDurationTextView.getText()))) {
- Log.d(TAG, "here-7");
- if (mDurationsList.size() != 0)
- Toast.makeText(this, R.string.no_duration_message, Toast.LENGTH_LONG).show();
- else
- Toast.makeText(getApplicationContext(), getString(R.string.booking_not_available), Toast.LENGTH_LONG).show();
- return;
- } else if (bookingType.equals(CustomerConstants.HOURLY) && mDurationBlocksLayout.getVisibility() == View.VISIBLE &&
- mDaysWidgetLayout.getVisibility() != View.VISIBLE && (packageStr.equals(CustomerConstants.OUTSTATION) || packageStr.equals(CustomerConstants.OUTSTATION_AR))) {
- Log.d(TAG, "here-8");
- mDaysWidgetLayout.startAnimation(Animator.getSingleInstance().getSlideRightIn(context));
- mDaysWidgetLayout.setVisibility(View.VISIBLE);
- isDurationActive = false;
- showDurationWidget(false);
- mWidgetListBox.setTextView(getString(R.string.full_package_days_in_package_select), getString(R.string.full_package_days_in_package), R.drawable.clock_gray);
- if (Locale.getDefault().getLanguage().equals("ar")) {
- mWidgetListBox.setListItems(daysDurationArabicArray);
- } else {
- mWidgetListBox.setListItems(daysDurationArray);
- }
- } else if (bookingType.equals(CustomerConstants.HOURLY) && mDaysWidgetLayout.getVisibility() == View.VISIBLE
- && (mWidgetListBox.getTextCenter()).equals(getString(R.string.full_package_days_in_package_select))) {
- Toast.makeText(this, R.string.no_days_in_package_message, Toast.LENGTH_LONG).show();
- return;
- } else if (bookingType.equals(CustomerConstants.HOURLY) && hourlyOneScreen) {
- getSupportLoaderManager().restartLoader(0, null, infoLoaderCallbacks);
- } else if (mChooseTimeLayout.getVisibility() != View.VISIBLE && !hourlyOneScreen) {
- Log.d(TAG, "here-9");
- if (mDaysWidgetLayout.getVisibility() == View.VISIBLE) {
- mWidgetListBox.setActiveState(false);
- }
- isDurationActive = false;
- mSelectDurationLayout.setVisibility(View.GONE);
- mSelectDurationView.setVisibility(View.GONE);
- isInDurationSelectionMode = false;
- mChooseTimeLayout.startAnimation(Animator.getSingleInstance().getSlideRightIn(context));
- mChooseTimeLayout.setVisibility(View.VISIBLE);
- try {
- setWidgetsActive(false, false);
- } catch (Exception ex) {
- Log.d(TAG, "3-ex=" + ex.getMessage());
- Toast.makeText(getApplicationContext(), R.string.internal_application_error, Toast.LENGTH_SHORT).show();
- }
- } else if ((bookingType.equals(CustomerConstants.HOURLY) && hourlyDestMandatory) ||
- (bookingType.equals(CustomerConstants.POINT_TO_POINT) && p2pDestMandatory)) {
- confirmFlow();
- } else {
- Log.d(TAG, "here-10");
- startBookingSummaryActivity(true);
- }
- Log.d(TAG, "here-11");
- }
- private void determineBookingFlow() {
- if (pickupWidget == null)
- return;
- simpleCheck();
- serviceAvailable();
- if (bookingSettings == null || bookingSettings.mBookingSettingsList == null) {
- getBookingSettings();
- return;
- }
- if (bookingSettings.mBookingSettingsList != null && bookingSettings.mBookingSettingsList.size() <= 0) {
- //default settings
- getSupportLoaderManager().restartLoader(0, null, infoLoaderCallbacks);
- } else {
- if (pickupWidget.getPlace() != null) {
- String currentCountry = null;
- Log.d(TAG, "UserCurrentCountry=" + pickupWidget.getPlace().getUserCurrentCountry());
- String tempCountry = "";
- if (pickupWidget.getPlace().getUserCurrentCountry() != null)
- tempCountry = pickupWidget.getPlace().getUserCurrentCountry();
- else if (!TextUtils.isEmpty(previousCountry))
- tempCountry = previousCountry;
- String tempCity = "";
- if (pickupWidget.getPlace().getUserCurrentCity() != null)
- tempCity = pickupWidget.getPlace().getUserCurrentCity();
- else if (!TextUtils.isEmpty(previousCountry))
- tempCity = previousCity;
- Log.e(TAG, "tempCountry=" + tempCountry + " tempCity=" + tempCity);
- UserLocationAndHourlyPackages.setUserLocationCountry(context, tempCountry);
- UserLocationAndHourlyPackages.setUserLocationCity(context, tempCity);
- for (BookingSettings settings : bookingSettings.mBookingSettingsList) {
- if (settings.getCountry().equals(tempCountry)) {
- currentCountry = settings.getCountry();
- p2pOneScreen = settings.isP2p_one_screen_app();
- hourlyOneScreen = settings.isHourly_one_screen_app();
- p2pDestMandatory = settings.isP2p_dest_mandatory();
- hourlyDestMandatory = settings.isHourly_dest_mandatory();
- p2p_job_assignment = settings.isP2p_job_assignment();
- per_km_speed = settings.getPer_km_speed();
- Log.i(TAG, "country=" + currentCountry);
- Log.i(TAG, "p2pOneScreen=" + p2pOneScreen);
- Log.i(TAG, "hourlyOneScreen=" + hourlyOneScreen);
- Log.i(TAG, "p2pDestMandatory=" + p2pDestMandatory);
- Log.i(TAG, "hourlyDestMandatory=" + hourlyDestMandatory);
- Log.i(TAG, "p2p_job_assignment=" + p2p_job_assignment);
- }
- }
- Log.e(TAG, "currentCountry=" + currentCountry);
- if (currentCountry != null) {
- if (p2pOneScreen == false && bookingType.equals(CustomerConstants.POINT_TO_POINT)) {
- Log.i(TAG, "1");
- mSubmitBtn.setVisibility(View.VISIBLE);
- } else if (p2pOneScreen == true && bookingType.equals(CustomerConstants.POINT_TO_POINT)) {
- Log.i(TAG, "2");
- getSupportLoaderManager().restartLoader(0, null, infoLoaderCallbacks);
- } else if (hourlyOneScreen == false && bookingType.equals(CustomerConstants.HOURLY)) {
- Log.i(TAG, "3");
- mSubmitBtn.setVisibility(View.VISIBLE);
- } else if (hourlyOneScreen == true && bookingType.equals(CustomerConstants.HOURLY)) {
- Log.i(TAG, "4");
- mSubmitBtn.setVisibility(View.VISIBLE);
- //getSupportLoaderManager().restartLoader(0, null, infoLoaderCallbacks);
- }
- } else {
- getSupportLoaderManager().restartLoader(0, null, infoLoaderCallbacks);
- }
- }
- }
- }
- private void removeBottomBar() {
- removeLabel();
- if (bottomBarFragment != null) {
- if (bottomBarFragment.isVisible()) {
- RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
- (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 35, getResources().getDisplayMetrics()));
- lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
- bottomBarContainer.setLayoutParams(lp);
- map_selector.setVisibility(View.GONE);
- getSupportFragmentManager().beginTransaction().remove(bottomBarFragment).commitAllowingStateLoss();
- mSubmitBtn.setVisibility(View.VISIBLE);
- //bottomBarContainer.setVisibility(View.VISIBLE);
- }
- }
- if (bottomBarConfirmFragment != null) {
- if (bottomBarConfirmFragment.isVisible()) {
- RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
- (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 35, getResources().getDisplayMetrics()));
- lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
- bottomBarContainer.setLayoutParams(lp);
- map_selector.setVisibility(View.GONE);
- getSupportFragmentManager().beginTransaction().remove(bottomBarConfirmFragment).commitAllowingStateLoss();
- mSubmitBtn.setVisibility(View.VISIBLE);
- }
- }
- }
- private LoaderManager.LoaderCallbacks<ApproximatedFareInfo> infoLoaderCallbacks = new LoaderManager.LoaderCallbacks<ApproximatedFareInfo>() {
- @Override
- public Loader<ApproximatedFareInfo> onCreateLoader(int id, Bundle args) {
- mSubmitBtn.setVisibility(View.GONE);
- if (progress != null) progress.setVisibility(View.VISIBLE);
- PreOrder preOrder = new PreOrder();
- preOrder.setBookingType(bookingType);
- preOrder.setOrigin(pickupWidget.getPlace());
- if (bookingType.equals(CustomerConstants.POINT_TO_POINT))
- preOrder.setDestination(pickupWidget.getPlace());
- if (bookingType.equals(CustomerConstants.HOURLY)) {
- String[] arr = mSelectedDurationTextView.getText().toString().split("/");
- String packageStr = arr[0];
- if (packageStr.equals(CustomerConstants.OUTSTATION) || packageStr.equals(CustomerConstants.OUTSTATION_AR))
- packageStr = CustomerConstants.FULL_DAY;
- for (int i = 0; i < mDurationsList.size(); i++) {
- if (mDurationsList.get(i).contains(packageStr)) {
- packageStr = mDurationsIDList.get(i);
- break;
- }
- }
- preOrder.setPackageType(packageStr);
- if (packageStr.equals(CustomerConstants.FULL_DAY)) {
- String daysStr = null;
- if (mWidgetListBox.getTextCenter().contains(" DAY")) {
- if (Locale.getDefault().getLanguage().equals("ar")) {
- for (int i = 0; i < daysDurationArabicArray.length; i++) {
- if (mWidgetListBox.getTextCenter().equals(daysDurationArabicArray[i])) {
- daysStr = daysDurationArray[i].split(" ")[0];
- break;
- }
- }
- } else {
- String[] arr2 = mWidgetListBox.getTextCenter().split(" ");
- Log.d(TAG, "arr2=" + mWidgetListBox.getTextCenter());
- daysStr = arr2[0];
- }
- preOrder.setDays(Integer.parseInt(daysStr));
- }
- Log.d(TAG, "days in package=" + daysStr);
- }
- }
- return new FareInfoLoader(getApplicationContext(), preOrder, "true");
- }
- @Override
- public void onLoadFinished(Loader<ApproximatedFareInfo> loader, ApproximatedFareInfo data) {
- progress.setVisibility(View.GONE);
- if (data != null) {
- if (data.getTypes().size() > 0) {
- showBottomView(data);
- approximatedFareInfo = data;
- } else {
- serviceNotAvailable();
- }
- } else {
- serviceNotAvailable();
- }
- }
- @Override
- public void onLoaderReset(Loader<ApproximatedFareInfo> loader) {
- progress.setVisibility(View.GONE);
- }
- };
- private LoaderManager.LoaderCallbacks<ApproximatedFareInfo> fareLoaderCallbacks = new LoaderManager.LoaderCallbacks<ApproximatedFareInfo>() {
- @Override
- public Loader<ApproximatedFareInfo> onCreateLoader(int id, Bundle args) {
- PreOrder preOrder = new PreOrder();
- preOrder.setBookingType(bookingType);
- preOrder.setOrigin(pickupWidget.getPlace());
- if (bookingType.equals(CustomerConstants.POINT_TO_POINT) ||
- (bookingType.equals(CustomerConstants.HOURLY) && mDestinationWidgetView.getVisibility() == View.VISIBLE))
- preOrder.setDestination(mDestinationWidgetView.getPlace());
- if (bookingType.equals(CustomerConstants.HOURLY)) {
- String[] arr = mSelectedDurationTextView.getText().toString().split("/");
- String packageStr = arr[0];
- if (packageStr.equals(CustomerConstants.OUTSTATION) || packageStr.equals(CustomerConstants.OUTSTATION_AR))
- packageStr = CustomerConstants.FULL_DAY;
- for (int i = 0; i < mDurationsList.size(); i++) {
- if (mDurationsList.get(i).contains(packageStr)) {
- packageStr = mDurationsIDList.get(i);
- break;
- }
- }
- preOrder.setPackageType(packageStr);
- if (packageStr.equals(CustomerConstants.FULL_DAY)) {
- String daysStr = null;
- if (mWidgetListBox.getTextCenter().contains(" DAY")) {
- if (Locale.getDefault().getLanguage().equals("ar")) {
- for (int i = 0; i < daysDurationArabicArray.length; i++) {
- if (mWidgetListBox.getTextCenter().equals(daysDurationArabicArray[i])) {
- daysStr = daysDurationArray[i].split(" ")[0];
- break;
- }
- }
- } else {
- String[] arr2 = mWidgetListBox.getTextCenter().split(" ");
- Log.d(TAG, "arr2=" + mWidgetListBox.getTextCenter());
- daysStr = arr2[0];
- }
- preOrder.setDays(Integer.parseInt(daysStr));
- }
- Log.d(TAG, "days in package=" + daysStr);
- }
- }
- return new FareInfoLoader(getApplicationContext(), preOrder, "");
- }
- @Override
- public void onLoadFinished(Loader<ApproximatedFareInfo> loader, ApproximatedFareInfo data) {
- if (data != null) {
- if (data.getTypes().size() > 0) {
- String estimFareStr = "";
- ApproximatedFareForType mFareType = null;
- for (final ApproximatedFareForType info : data.getTypes()) {
- //Log.e(TAG, info.getCategory() + "_" + info.getCabModel() + "_" + info.getDisplayCategoryName());
- if (selectedType == null)
- return;
- else if (info.getCategory().equals(selectedType.getCategory())) {
- mFareType = info;
- break;
- }
- }
- if (mFareType == null) {
- return;
- }
- // Log.e(TAG, "fareLoaderCallbacks mFareType " + mFareType.getDisplayCategoryName() + " " +
- // selectedType.getDisplayCategoryName() + " " + mFareType.getCabModel() + " " +
- // selectedType.getCabModel());
- currentDate = new Date(System.currentTimeMillis());
- if (isItDayOrNight.isItDay(currentDate, mFareType.getNightStartHr(), mFareType.getDayStartHr())) {
- estimFareStr = mFareType.getCurrency() + " " + DecimalFormating.getStringFormatted(mFareType.getApproxCostDay());
- } else {
- estimFareStr = mFareType.getCurrency() + " " + DecimalFormating.getStringFormatted(mFareType.getApproxCostNight());
- }
- Log.e(TAG, "ApproximatedFareForType onLoadFinished " + estimFareStr);
- if (bottomBarConfirmFragment != null && bottomBarConfirmFragment.isAdded()) {
- bottomBarConfirmFragment.setEstimatedCost(estimFareStr);
- }
- }
- }
- }
- @Override
- public void onLoaderReset(Loader<ApproximatedFareInfo> loader) {
- }
- };
- private void serviceNotAvailable() {
- removeBottomBar();
- mSubmitBtn.setVisibility(View.GONE);
- RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
- (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 60, getResources().getDisplayMetrics()));
- lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
- bottomBarContainer.setLayoutParams(lp);
- getSupportFragmentManager().beginTransaction().replace(R.id.bottombar, mServiceNotAvailableFragment).commitAllowingStateLoss();
- }
- private void serviceAvailable() {
- if (mServiceNotAvailableFragment.isAdded() || mServiceNotAvailableFragment.isVisible()) {
- getSupportFragmentManager().beginTransaction().remove(mServiceNotAvailableFragment).commitAllowingStateLoss();
- }
- }
- private void showBottomView(ApproximatedFareInfo data) {
- RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
- (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 134, getResources().getDisplayMetrics()));
- lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
- bottomBarContainer.setLayoutParams(lp);
- Log.d("ETA Display", "Setting bottombar caboverlays");
- bottomBarFragment = BottomRecFragment.newInstance(data, getCabOverlaysProvider(), per_km_speed);
- // getCabOverlaysProvider().setEtaListener(bottomBarFragment);
- bottomBarFragment.setListener(this);
- getSupportFragmentManager()
- .beginTransaction()
- .replace(R.id.bottombar, bottomBarFragment)
- .commitAllowingStateLoss();
- bottomBarContainer.setVisibility(View.VISIBLE);
- map_selector.setVisibility(View.VISIBLE);
- }
- public void showTimeWidget(boolean pickupWidgetActive, boolean destinationActive) {
- if (pickupWidgetActive || (bookingType.equals(CustomerConstants.POINT_TO_POINT) && destinationActive) || (bookingType.equals(CustomerConstants.HOURLY) && isDurationActive)) {
- mChooseTimeLayout.setVisibility(View.INVISIBLE);
- } else {
- mChooseTimeLayout.setVisibility(View.VISIBLE);
- }
- }
- public void showDurationWidget(boolean pickupWidgetActive) {
- try {
- if (pickupWidgetActive) {
- if (mDurationBlocksLayout.getVisibility() == View.VISIBLE) {
- mDurationBlocksLayout.startAnimation(Animator.getSingleInstance().getSlideRightOut(context));
- mDurationBlocksLayout.setVisibility(View.GONE);
- }
- } else if (isDurationActive) {
- if (Locale.getDefault().getLanguage().equals("ar")) {
- mDurationColorLayout.setBackgroundResource(R.drawable.select_cab_left_en);
- mDurationArrowImg.setImageResource(R.drawable.btn_detail_arrow_down_brown);
- } else {
- //mDurationColorLayout.setBackgroundResource(R.drawable.select_cab_right);
- }
- } else if (!isDurationActive) {
- if (Locale.getDefault().getLanguage().equals("ar")) {
- mDurationColorLayout.setBackgroundResource(R.drawable.searchbox_right_ar);
- mDurationArrowImg.setImageResource(R.drawable.btn_detail_arrow_down);
- } else {
- //mDurationColorLayout.setBackgroundResource(R.drawable.searchbox_right);
- }
- }
- } catch (Exception ex) {
- Log.e(TAG, "unexpected exception = " + ex.getMessage());
- }
- }
- @Override
- protected void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- outState.putBoolean(STATE_ASK_LOCATION, isAskToEnableLocation);
- outState.putString(CustomerConstants.BOOKING_TYPE, bookingType);
- }
- private void startManualAddressPicker(String source) {
- Intent intent = new Intent(DestinationActivity.this, ManualSelectAddressActivity.class);
- intent.putExtra("image", source);
- intent.putExtra(FROM_DESTINATION_ACTIVITY, true);
- startActivityForResult(intent, Constants.REQUEST_TYPE_ADDRESS);
- if (Locale.getDefault().getLanguage().equals("ar")) {
- overridePendingTransition(R.anim.left_in, R.anim.right_out);
- } else {
- overridePendingTransition(R.anim.right_in, R.anim.left_out);
- }
- }
- private boolean validateLocation(boolean withValidation) {
- if (pickupWidget.getPlace() == null) {
- Toast.makeText(this, R.string.no_pickup_message, Toast.LENGTH_LONG).show();
- return false;
- } else if (bookingType.equals(CustomerConstants.POINT_TO_POINT) && mDestinationWidgetView.getPlace() == null) {
- Toast.makeText(this, R.string.no_destination_message, Toast.LENGTH_LONG).show();
- return false;
- } else {
- if (withValidation && bookingType.equals(CustomerConstants.POINT_TO_POINT) && (pickupWidget.getPlace().getDescription().equals(mDestinationWidgetView.getPlace().getDescription()))) {
- Intent i = new Intent(context, GenericPopup.class);
- i.putExtra(GenericPopup.BTN_YES, true);
- i.putExtra(GenericPopup.BTN_YES_TEXT, getString(R.string.dest_popup_btn_ok));
- i.putExtra(GenericPopup.BTN_NO, false);
- i.putExtra(GenericPopup.TITLE, getString(R.string.dest_popup_warning));
- i.putExtra(GenericPopup.MESS, getString(R.string.dest_popup_pickup_dest_same) + " \n \n" + getString(R.string.dest_popup_dest_far));
- i.putExtra(GenericPopup.IS_CANCEL, false);
- startActivity(i);
- overridePendingTransition(R.anim.bottom_in, R.anim.top_out);
- return false;
- }
- }
- return true;
- }
- private void startBookingSummaryActivity(boolean withValidation) {
- if (validateLocation(withValidation)) {
- Intent intent = new Intent(this, BookingSummaryActivity.class);
- intent.putExtra(CustomerConstants.BOOKING_TYPE, bookingType);
- intent.putExtra(Constants.PICKUP_PLACE, pickupWidget.getPlace());
- if (bookingType.equals(CustomerConstants.POINT_TO_POINT))
- intent.putExtra(Constants.DESTINATION_PLACE, mDestinationWidgetView.getPlace());
- intent.putExtra(Constants.PICKUP_TIME, selectedTime);
- if (bookingType.equals(CustomerConstants.HOURLY)) {
- // intent.putExtra(Constants.PACKAGE_TYPE, tv_selectedDuration.getText());
- String[] arr = mSelectedDurationTextView.getText().toString().split("/");
- String packageStr = arr[0];
- if (packageStr.equals(CustomerConstants.OUTSTATION) || packageStr.equals(CustomerConstants.OUTSTATION_AR))
- packageStr = CustomerConstants.FULL_DAY;
- for (int i = 0; i < mDurationsList.size(); i++) {
- Log.e("reali", "duration " + packageStr + " " + mDurationsList.get(i));
- if (mDurationsList.get(i).contains(packageStr)) {
- packageStr = mDurationsIDList.get(i);
- break;
- }
- }
- intent.putExtra(Constants.PACKAGE_TYPE, packageStr);
- if (packageStr.equals(CustomerConstants.FULL_DAY)) {
- String daysStr = null;
- if (Locale.getDefault().getLanguage().equals("ar")) {
- for (int i = 0; i < daysDurationArabicArray.length; i++) {
- if (mWidgetListBox.getTextCenter().equals(daysDurationArabicArray[i])) {
- daysStr = daysDurationArray[i].split(" ")[0];
- break;
- }
- }
- } else {
- String[] arr2 = mWidgetListBox.getTextCenter().toString().split(" ");
- daysStr = arr2[0];
- }
- intent.putExtra(CustomerConstants.DAYS_IN_FULL_PACKAGE, daysStr);
- Log.d("DestinationActivity:", "days in package passed to start booking " + daysStr);
- }
- }
- startActivityForResult(intent, REQUEST_BOOKING_SUMMARY);
- if (Locale.getDefault().getLanguage().equals("ar")) {
- overridePendingTransition(R.anim.left_in, R.anim.right_out);
- } else {
- overridePendingTransition(R.anim.right_in, R.anim.left_out);
- }
- }
- }
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- Log.d(TAG, "onActivityResult Request Code: " + requestCode + ", Result Code: " + resultCode);
- if (requestCode == REQUEST_CONFIRMATION) {
- if (resultCode == DialogActivity.RESULT_CANCELED) {
- startBookingSummaryActivity(false);
- return;
- } else if (resultCode == DialogActivity.RESULT_POSITIVE) {
- return;
- }
- } else if (requestCode == REQUEST_BOOKING_SUMMARY && resultCode == BookingSummaryActivity.RESULT_ORDER_SENT) {
- finish();
- } else if (resultCode == ManualSelectAddressActivity.RESULT_OK && requestCode == Constants.REQUEST_TYPE_ADDRESS) {
- if (data.hasExtra(ManualSelectAddressActivity.EXTRA_PLACE)) {
- String address_type = data.getStringExtra(ADDRESS_TYPE);
- Place place = data.getParcelableExtra(ManualSelectAddressActivity.EXTRA_PLACE);
- taskRunner = new GetAddressesTask.Runner(getApplicationContext());
- if (place != null) {
- taskRunner.runTask(place.getLatLng(), this);
- }
- if (address_type == null || address_type.equalsIgnoreCase(PICK_UP)) {
- pickupWidget.onNewPlace(place);
- } else {
- mDestinationWidgetView.onNewPlace(place);
- }
- getMapFragmentWithCenteredMarker().navigateTo(place.getLatLng());
- }
- } else if (requestCode == Constants.ERROR_GEOCODING_SERVICE_PICKUP) {
- startManualAddressPicker(PICK_UP);
- } else if (requestCode == Constants.ERROR_GEOCODING_SERVICE_DESTINATION) {
- startManualAddressPicker(DESTINATION);
- } else if (requestCode == TIME_EDIT && resultCode == Constants.RESULT_SUCCESS) {
- long time = data.getLongExtra(NewCalendarAcitivity.TAG_SELECTED_TIME, 0);// date/time from calendar screen
- Log.d("timeresult2",time+"_");
- isToday = data.getBooleanExtra(NewCalendarAcitivity.TAG_TODAY, true);
- if (time < System.currentTimeMillis())
- time = System.currentTimeMillis() + TimeUnit.MINUTES.toMillis(15);
- setSelectedTime(time);// current day
- if (bookingType.equals(CustomerConstants.POINT_TO_POINT)) {
- addLabel();
- }
- bottomBarConfirm(time, false);
- } else if (requestCode == TIME_EDIT && resultCode == RESULT_CANCELED) {
- removeBottomBar();
- getSupportLoaderManager().restartLoader(0, null, infoLoaderCallbacks);
- removeLabel();
- mSubmitBtn.setVisibility(View.GONE);
- } else if (requestCode == 1313 && resultCode == 1) {
- AccountSettingsActivity.start(DestinationActivity.this);
- finish();
- } else if (requestCode == 1414 && resultCode == 1) {
- Intents.openTrackingActivity(this, lastOrderID);
- finish();
- } else {
- super.onActivityResult(requestCode, resultCode, data);
- }
- }
- private void bottomBarConfirm(long time, boolean isRideNowClicked) {
- if (approximatedFareInfo != null) {
- if (approximatedFareInfo.getTypes().size() > 0) {
- bottomBarConfirmFragment = BottomRecConfirmFragment.newInstance(approximatedFareInfo, time, createOrder(), isRideNowClicked);
- bottomBarConfirmFragment.setListener(this);
- if (!bottomBarConfirmFragment.isAdded()) {
- getSupportFragmentManager()
- .beginTransaction()
- .replace(R.id.bottombar, bottomBarConfirmFragment)
- .commitAllowingStateLoss();
- }
- }
- }
- }//Mechele
- private void submitOrder() {
- if (!validateLocation(true)) {
- return;
- } else {
- final Order newOrder = createOrder();
- new SubmitOrderTask(context, newOrder) {
- @Override
- protected void onSuccess(Long createdOrderId) throws Exception {
- super.onSuccess(createdOrderId);
- newOrder.setOrderId(createdOrderId);
- newOrder.setStatus(Order.STATUS_PENDING);
- databaseHelper.insert(newOrder);
- //clean
- Intent intent = new Intent(context, PopupBookingReceived.class);
- intent.putExtra(Constants.ORDER_ID, createdOrderId);
- intent.putExtra(Constants.ORDER, newOrder);
- intent.putExtra(Constants.COUNTRY_CODE, "");
- startActivity(intent);
- overridePendingTransition(R.anim.bottom_in, R.anim.top_out);
- }
- }.execute();
- }
- }
- private class CheckRunningOrders extends ApiAsyncTask<List<Order>> {
- @Inject
- private OrderManager orderManager;
- public CheckRunningOrders(Context context) {
- super(context);
- }
- @Override
- public List<Order> call() throws Exception {
- return orderManager.getOrders();
- }
- @Override
- protected void onSuccess(List<Order> orders) throws Exception {
- super.onSuccess(orders);
- if (orders != null) {
- if ((orders.size() > 0) && (ApiConstants.actived == 0)) {
- Order o = orders.get(0);
- if (o.getStatus().equals(Order.STATUS_PENDING)) {
- Intent intent = new Intent(DestinationActivity.this, AccountSettingsActivity.class);
- intent.putExtra("key", '2');
- DestinationActivity.this.startActivity(new Intent(DestinationActivity.this, AccountSettingsActivity.class).putExtra("key", '2'));
- DestinationActivity.this.finish();
- } else if (o.getStatus().equals(Order.STATUS_ACCEPTED) ||
- o.getStatus().equals(Order.STATUS_STARTED)) {
- Log.d("status_view", "accepted");
- Intents.openTrackingActivity(DestinationActivity.this, o.getOrderId());
- DestinationActivity.this.finish();
- }
- }
- }
- /*if (orders != null && orders.size() > 0) {
- boolean foundActive = false;
- for (Order o : orders) {
- if (o.getStatus().equals(Order.STATUS_ACCEPTED) ||
- o.getStatus().equals(Order.STATUS_STARTED)) {
- lastOrderID = o.getOrderId();
- foundActive = true;
- break;
- }
- }
- if (foundActive) {
- Intent intent = new Intent(DestinationActivity.this, PopupScreenNew.class);
- // intent.putExtra("title",activ. getResources().getString(R.string.info_title));
- intent.putExtra("message", getResources().getString(R.string.already_have_booking));
- startActivityForResult(intent, 1414);
- } else {
- Order o1 = orders.get(0);
- if (o1.getStatus().equals(Order.STATUS_PENDING)) {
- Intent intent = new Intent(DestinationActivity.this, PopupScreenNew.class);
- // intent.putExtra("title",activ. getResources().getString(R.string.info_title));
- intent.putExtra("message", getResources().getString(R.string.already_have_booking));
- startActivityForResult(intent, 1313);
- }
- }
- Order o = orders.get(0);
- if (o.getStatus().equals(Order.STATUS_PENDING) ||
- o.getStatus().equals(Order.STATUS_ACCEPTED) ||
- o.getStatus().equals(Order.STATUS_STARTED)) {
- }
- }*/
- }
- }
- private void confirmFlow() {
- if (mDestinationWidgetView.getVisibility() != View.VISIBLE) {
- Toast.makeText(context, "Please, add the destination", Toast.LENGTH_SHORT).show();
- } else {
- submitOrder();
- }
- }
- @Override
- public void onConfirmClicked() {
- if (p2pDestMandatory || hourlyDestMandatory) {
- confirmFlow();
- } else if (bookingType.equals(CustomerConstants.POINT_TO_POINT) && rideNow && p2p_job_assignment) {
- final Order newOrder = createOrder();
- new SubmitOrderTask(context, newOrder) {
- @Override
- protected void onSuccess(Long createdOrderId) throws Exception {
- super.onSuccess(createdOrderId);
- newOrder.setOrderId(createdOrderId);
- newOrder.setStatus(Order.STATUS_PENDING);
- databaseHelper.insert(newOrder);
- //clean
- Intent intent = new Intent(context, WaitingForDriverActivity.class);
- intent.putExtra(ORDER, newOrder);
- startActivity(intent);
- // overridePendingTransition(R.anim.bottom_in, R.anim.top_out);
- overridePendingTransition(R.anim.bottom_in, R.anim.show);
- }
- }.execute();
- } else {
- final Order newOrder = createOrder();
- new SubmitOrderTask(context, newOrder) {
- @Override
- protected void onSuccess(Long createdOrderId) throws Exception {
- super.onSuccess(createdOrderId);
- newOrder.setOrderId(createdOrderId);
- newOrder.setStatus(Order.STATUS_PENDING);
- databaseHelper.insert(newOrder);
- //clean
- Intent intent = new Intent(context, PopupBookingReceived.class);
- intent.putExtra(Constants.ORDER_ID, createdOrderId);
- intent.putExtra(Constants.ORDER, newOrder);
- intent.putExtra(Constants.COUNTRY_CODE, "");
- startActivity(intent);
- overridePendingTransition(R.anim.bottom_in, R.anim.top_out);
- }
- }.execute();
- }
- }
- @Override
- public void onNewPlace(Place place) {
- if (place != null) {
- if (!TextUtils.isEmpty(place.getUserCurrentCountry()))
- previousCountry = place.getUserCurrentCountry();
- if (!TextUtils.isEmpty(place.getUserCurrentCity()))
- previousCity = place.getUserCurrentCity();
- countryNameFromPlace = place.getUserCurrentCountry();
- if (bookingType.equals(CustomerConstants.POINT_TO_POINT)) {
- Log.i(TAG, "new Place");
- onUserLocationChanged(place);
- } else {
- if (bookingType.equals(CustomerConstants.HOURLY)) {
- boolean isInList = false;
- if (countryNameFromPlace != null) {
- for (BookingSettings settings : bookingSettings.mBookingSettingsList) {
- if (settings.getCountry().equals(countryNameFromPlace)) {
- isInList = true;
- Log.e("reali", "InList _" + countryNameFromPlace);
- mDurationsList.clear();
- mDurationsList.addAll(settings.getmPackages());
- mDurationsIDList.clear();
- mDurationsIDList.addAll(settings.getmPackagesId());
- }
- }
- if (!isInList) {
- Toast.makeText(getApplicationContext(), getString(R.string.booking_not_available), Toast.LENGTH_LONG).show();
- return;
- }
- } else {
- Toast.makeText(this, getString(R.string.cannot_determine_country), Toast.LENGTH_LONG).show();
- return;
- }
- }
- ArrayAdapter<String> adapterCity = null;
- adapterCity = new ArrayAdapter<String>(this, R.layout.duration_list_item, R.id.tv_name_selection, mDurationsList);
- mDurationListView.setAdapter(adapterCity);
- mDurationListView.setOnItemClickListener(durationListListener);
- //}
- String[] arr = mSelectedDurationTextView.getText().toString().split("/");
- String packageStr = arr[0];
- Log.d("DestinationActivity:", "Selected _" + packageStr + "_");
- if (bookingType.equals(CustomerConstants.HOURLY) && mDurationBlocksLayout.getVisibility() != View.VISIBLE) {
- mDurationBlocksLayout.startAnimation(Animator.getSingleInstance().getSlideRightIn(context));
- mDurationBlocksLayout.setVisibility(View.VISIBLE);
- isDurationActive = true;
- try {
- setWidgetsActive(false, false);
- } catch (Exception ex) {
- Log.d(TAG, "--ex=" + ex.getMessage());
- Toast.makeText(getApplicationContext(), R.string.internal_application_error, Toast.LENGTH_SHORT).show();
- }
- } else if (bookingType.equals(CustomerConstants.HOURLY) && mDurationBlocksLayout.getVisibility() == View.VISIBLE &&
- mDaysWidgetLayout.getVisibility() != View.VISIBLE && (packageStr.equals(CustomerConstants.OUTSTATION)
- || packageStr.equals(CustomerConstants.OUTSTATION_AR))) {
- mDaysWidgetLayout.startAnimation(Animator.getSingleInstance().getSlideRightIn(context));
- mDaysWidgetLayout.setVisibility(View.VISIBLE);
- isDurationActive = false;
- showDurationWidget(false);
- mWidgetListBox.setTextView(getString(R.string.full_package_days_in_package_select), getString(R.string.full_package_days_in_package), R.drawable.clock_gray);
- if (Locale.getDefault().getLanguage().equals("ar")) {
- mWidgetListBox.setListItems(daysDurationArabicArray);
- } else {
- mWidgetListBox.setListItems(daysDurationArray);
- }
- } else if (bookingType.equals(CustomerConstants.HOURLY) && mDaysWidgetLayout.getVisibility() == View.VISIBLE
- && (mWidgetListBox.getTextCenter()).equals(getString(R.string.full_package_days_in_package_select))) {
- Toast.makeText(this, R.string.no_days_in_package_message, Toast.LENGTH_LONG).show();
- return;
- }
- }
- // determineBookingFlow();
- }
- }
- @Override
- public void onPlaceError() {
- countryNameFromPlace = null;
- }
- @Override
- public void onNoLocationFound() {
- countryNameFromPlace = null;
- }
- @Override
- protected void startNextActivity() {
- startBookingSummaryActivity(true);
- }
- @Override
- public void onBackPressed() {
- if (bookingType.equalsIgnoreCase(CustomerConstants.POINT_TO_POINT)) {
- if (mChooseTimeLayout.getVisibility() == View.VISIBLE) {
- mChooseTimeLayout.startAnimation(Animator.getSingleInstance().getSlideRightOut(context));
- mChooseTimeLayout.setVisibility(View.GONE);
- try {
- setWidgetsActive(false, true);
- } catch (Exception ex) {
- Log.d(TAG, "5-ex=" + ex.getMessage());
- Toast.makeText(getApplicationContext(), R.string.internal_application_error, Toast.LENGTH_SHORT).show();
- }
- } else if (mDestinationWidgetView.getVisibility() == View.VISIBLE) {
- mChooseTimeLayout.startAnimation(Animator.getSingleInstance().getSlideRightOut(context));
- mDestinationWidgetView.setVisibility(View.GONE);
- try {
- setWidgetsActive(true, false);
- } catch (Exception ex) {
- Log.d(TAG, "6-ex=" + ex.getMessage());
- Toast.makeText(getApplicationContext(), R.string.internal_application_error, Toast.LENGTH_SHORT).show();
- }
- } else if (mAddDestLabel.getVisibility() == View.VISIBLE) {
- // mAddDestLabel.startAnimation(Animator.getSingleInstance().getSlideRightOut(context));
- mAddDestLabel.setVisibility(View.GONE);
- } else {
- finish();
- }
- } else {
- if (mChooseTimeLayout.getVisibility() == View.VISIBLE) {
- mChooseTimeLayout.startAnimation(Animator.getSingleInstance().getSlideRightOut(context));
- mChooseTimeLayout.setVisibility(View.GONE);
- if (mDaysWidgetLayout.getVisibility() != View.VISIBLE) {
- isDurationActive = true;
- try {
- setWidgetsActive(false, false);
- } catch (Exception ex) {
- Log.d(TAG, "7-ex=" + ex.getMessage());
- Toast.makeText(getApplicationContext(), R.string.internal_application_error, Toast.LENGTH_SHORT).show();
- }
- } else {
- mWidgetListBox.setActiveState(true);
- }
- } else if (mDaysWidgetLayout.getVisibility() == View.VISIBLE) { // FULL DAY package was chosen
- makeDaysInFullPackageInvisible();
- isDurationActive = true;
- showDurationWidget(false);
- } else if (mDurationBlocksLayout.getVisibility() == View.VISIBLE) {
- isDurationActive = false;
- mSelectDurationLayout.setVisibility(View.GONE);
- mSelectDurationView.setVisibility(View.GONE);
- isInDurationSelectionMode = false;
- try {
- setWidgetsActive(true, false);
- } catch (Exception ex) {
- Log.d(TAG, "8-ex=" + ex.getMessage());
- Toast.makeText(getApplicationContext(), R.string.internal_application_error, Toast.LENGTH_SHORT).show();
- }
- } else {
- finish();
- }
- }
- }
- private void setSelectedTime(long time) {
- selectedTime = time;
- Calendar c = Calendar.getInstance();
- c.setTimeInMillis(selectedTime);
- SimpleDateFormat format = new SimpleDateFormat("dd/MMM/yyyy");
- int hr = c.get(Calendar.HOUR_OF_DAY);
- int min = c.get(Calendar.MINUTE);
- String minDisplay = "";
- if (min < 10) {
- minDisplay = "0" + min;
- } else {
- minDisplay = min + "";
- }
- if (Locale.getDefault().getLanguage().equals("ar")) {
- String timeDisplay = hr + ":" + minDisplay;
- if (!isToday) {
- timeDisplay = format.format(time) + ", " + timeDisplay;
- } else {
- timeDisplay += " اليوم";
- }
- mTimeDisplayTextView.setText(timeDisplay);
- } else {
- String am_pm = ((c.get(Calendar.AM_PM) == Calendar.AM) ? "AM" : "PM");
- if (hr == 0) {
- hr = 12;
- }
- if (min < 10) {
- minDisplay = "0" + min;
- } else {
- minDisplay = min + "";
- }
- String timeDisplay = hr + ":" + minDisplay + " " + am_pm;
- if (!isToday) {
- timeDisplay += ", " + format.format(time);
- } else {
- timeDisplay += " " + getString(R.string.today);
- }
- mTimeDisplayTextView.setText(timeDisplay);
- }
- }
- public long getSelectedTime() {
- long time = System.currentTimeMillis();
- Calendar c = Calendar.getInstance();
- c.setTimeInMillis(time);
- int min = c.get(Calendar.MINUTE);
- int sec = c.get(Calendar.SECOND);
- int additionalMinutes = 0;
- if (min <= 10) {
- additionalMinutes = 15 - min + CustomerConstants.DEFAULT_ASAP_TIME_LAG;
- } else if (min <= 25) {
- additionalMinutes = 30 - min + CustomerConstants.DEFAULT_ASAP_TIME_LAG;
- } else if (min <= 40) {
- additionalMinutes = 45 - min + CustomerConstants.DEFAULT_ASAP_TIME_LAG;
- } else if (min <= 55) {
- additionalMinutes = 60 - min + CustomerConstants.DEFAULT_ASAP_TIME_LAG;
- } else if (min <= 60) {
- additionalMinutes = 75 - min + CustomerConstants.DEFAULT_ASAP_TIME_LAG;
- }
- time = time + additionalMinutes * 60 * 1000 - sec * 1000;
- Date today = new Date();
- Date date = new Date(time);
- if (date.getDate() == today.getDate() && date.getMonth() == today.getMonth() && date.getYear() == today.getYear()) {
- isToday = true;
- } else {
- isToday = false;
- }
- return time;
- }
- @Override
- protected void onStart() {
- super.onStart();
- if (!isOnline()) {
- Toast.makeText(this, R.string.toast_no_network_connection, Toast.LENGTH_LONG).show();
- } else {
- boolean networkEnabled = mMyLocationProvider.isNetworkEnabled();
- boolean gpsEnabled = mMyLocationProvider.isGpsEnabled();
- boolean noneEnabled = !networkEnabled && !gpsEnabled;
- boolean allEnabled = networkEnabled && gpsEnabled;
- if (isAskToEnableLocation && !allEnabled) {
- int title = noneEnabled ? R.string.dialog_location_disabled_title
- : R.string.dialog_location_not_all_enabled_title;
- int message = noneEnabled ? R.string.dialog_location_disabled_message
- : R.string.dialog_location_not_all_enabled_message;
- int positive = noneEnabled ? R.string.dialog_location_disabled_positive
- : gpsEnabled ? R.string.dialog_network_disabled_positive
- : R.string.dialog_gps_disabled_positive;
- showLocationDialog(title, message, positive,
- R.string.dialog_location_disabled_negative);
- }
- }
- }
- private void showLocationDialog(int title, int message, int positive, int negative) {
- if (!isDialogShown) {
- AlertDialog.Builder builder = new AlertDialog.Builder(this);
- builder.setTitle(title);
- builder.setMessage(message);
- builder.setNegativeButton(negative, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- isAskToEnableLocation = false;
- }
- });
- builder.setPositiveButton(positive, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- mMyLocationProvider.enableLocationSettings(DestinationActivity.this);
- }
- });
- AlertDialog dialog = builder.show();
- dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
- @Override
- public void onDismiss(DialogInterface dialog) {
- isDialogShown = false;
- }
- });
- isDialogShown = true;
- }
- }
- private void addLabel() {
- if (mAddDestLabel.getVisibility() != View.VISIBLE && mDestinationWidgetView.getVisibility() != View.VISIBLE) {
- mAddDestLabel.setVisibility(View.VISIBLE);
- }
- }
- private void removeLabel() {
- isDest = false;
- if (mAddDestLabel.getVisibility() == View.VISIBLE)
- mAddDestLabel.setVisibility(View.GONE);
- if (mDestinationWidgetView.getVisibility() == View.VISIBLE && bookingType.equals(CustomerConstants.HOURLY)) {
- mDestinationWidgetView.setVisibility(View.GONE);
- try {
- setWidgetsActive(true, false);
- } catch (Exception ex) {
- Log.e(TAG, "ex=" + ex.getMessage());
- }
- }
- }
- @Override
- public void onRideNowClicked(ApproximatedFareForType type) {
- int isCabAvailable = bottomBarFragment.isCabAvailableForNow(type);
- if (isCabAvailable == -1) {
- Toast.makeText(getApplicationContext(), R.string.pls_wait, Toast.LENGTH_SHORT).show();
- } else if (isCabAvailable == 0) {
- Toast.makeText(getApplicationContext(), R.string.no_ride_now, Toast.LENGTH_SHORT).show();
- } else {
- selectedType = type;
- if (bookingType.equals(CustomerConstants.POINT_TO_POINT)) {
- addLabel();
- }
- rideNow = true;
- //setSelectedTime(System.currentTimeMillis() + TimeUnit.MINUTES.toMillis(15));
- bottomBarConfirm(System.currentTimeMillis() + TimeUnit.MINUTES.toMillis(15), true);
- }
- }
- @Override
- public void onRideLaterClicked(ApproximatedFareForType type) {
- selectedType = type;
- rideNow = false;
- // addLabel();
- }
- @Override
- public void onCancelClicked() {
- removeLabel();
- if (bookingType.equals(CustomerConstants.HOURLY)) {
- resetBookings();
- mSubmitBtn.setVisibility(View.VISIBLE);
- } else if (bottomBarConfirmFragment != null && bottomBarFragment != null) {
- getSupportFragmentManager()
- .beginTransaction()
- .replace(R.id.bottombar, bottomBarFragment)
- .commitAllowingStateLoss();
- }
- }
- @Override
- public void onEstimFareClicked() {
- if (bookingType.equals(CustomerConstants.POINT_TO_POINT) && mDestinationWidgetView.getVisibility() != View.VISIBLE) {
- mAddDestLabel.callOnClick();
- } else if ((bookingType.equals(CustomerConstants.HOURLY) && !hourlyDestMandatory) || (
- mDestinationWidgetView.getVisibility() == View.VISIBLE && !pickupWidget.getPlace().equals(mDestinationWidgetView.getPlace()))) {
- calcEstimFare(false);
- }
- }
- public static class FareInfoLoader extends RoboAsyncTaskLoader<ApproximatedFareInfo> {
- @Inject
- private OrderManager orderManager;
- private PreOrder preOrder;
- private String onlyFares;
- public FareInfoLoader(Context context, PreOrder preOrder, String onlyFares) {
- super(context);
- this.preOrder = preOrder;
- this.onlyFares = onlyFares;
- }
- @Override
- protected void onStartLoading() {
- super.onStartLoading();
- forceLoad();
- }
- @Override
- public ApproximatedFareInfo loadInBackground() {
- try {
- return orderManager.getApproximatedOrderData(preOrder, onlyFares);
- } catch (Exception e) {
- return null;
- }
- }
- }
- private Order createOrder() {
- Order order = new Order();
- order.setBookingType(bookingType);
- order.setPromoCode(ValidatePromoCodePopup.sPromoCode);//gets promocode that is checked and stored, if it is
- // for setting cab type from rotation wheel
- ArrayList<String> temp = new ArrayList<>();
- if (selectedType != null) {
- temp.add(selectedType.getCategory());
- } else {
- for (ApproximatedFareForType type : approximatedFareInfo.getTypes()) {
- temp.add(type.getCabModel());
- }
- }
- order.setCabTypes(temp);
- if (pickupWidget != null) {
- order.setStartLocation(pickupWidget.getPlace());
- if (bookingType.equals(CustomerConstants.POINT_TO_POINT)) {
- if (mDestinationWidgetView.getVisibility() == View.VISIBLE)
- order.setEndLocation(mDestinationWidgetView.getPlace());
- }
- }
- if (bookingType.equals(CustomerConstants.HOURLY)) {
- if (mSelectedDurationTextView != null) {
- String[] arr = mSelectedDurationTextView.getText().toString().split("/");
- String packageStr = arr[0];
- if (packageStr.equals(CustomerConstants.OUTSTATION) || packageStr.equals(CustomerConstants.OUTSTATION_AR))
- packageStr = CustomerConstants.FULL_DAY;
- for (int i = 0; i < mDurationsList.size(); i++) {
- if (mDurationsList.get(i).contains(packageStr)) {
- packageStr = mDurationsIDList.get(i);
- break;
- }
- }
- order.setPackageType(packageStr);
- if (packageStr.equals(CustomerConstants.FULL_DAY)) {
- String daysStr = null;
- if (mWidgetListBox != null) {
- if (mWidgetListBox.getTextCenter().contains(" DAY")) {
- if (Locale.getDefault().getLanguage().equals("ar")) {
- for (int i = 0; i < daysDurationArabicArray.length; i++) {
- if (mWidgetListBox.getTextCenter().equals(daysDurationArabicArray[i])) {
- daysStr = daysDurationArray[i].split(" ")[0];
- break;
- }
- }
- } else {
- String[] arr2 = mWidgetListBox.getTextCenter().split(" ");
- Log.d(TAG, "arr2=" + mWidgetListBox.getTextCenter());
- daysStr = arr2[0];
- }
- order.setDays(Integer.parseInt(daysStr));
- }
- }
- Log.d(TAG, "days in package=" + daysStr);
- }
- }
- }
- PaymentMethod selectedPm = preferencesStorage.getSelectedCard();
- if (selectedPm != null) {
- order.setCardToken(selectedPm.getToken());
- }
- order.setRequestedPickupTime(selectedTime);
- order.setName(preferencesStorage.getName());
- order.setPhone(preferencesStorage.getPhoneNumber());
- order.setEmailId(preferencesStorage.getEmailID());
- return order;
- }
- private AdapterView.OnItemClickListener durationListListener = new AdapterView.OnItemClickListener() {
- public void onItemClick(AdapterView<?> adapterView, View v, int position, long id) {
- if (current != -1) {
- View last = mDurationListView.getChildAt(current);
- last.findViewById(R.id.topSelectLayout).setBackgroundResource(R.drawable.car_bg_not_selected);
- ((TextView) last.findViewById(R.id.tv_name_selection)).setTextColor(last.getContext().getResources().
- getColor(R.color.color_tv_city_not_selected));
- }
- v.findViewById(R.id.topSelectLayout).setBackgroundResource(R.drawable.car_bg_selected);
- ((TextView) v.findViewById(R.id.tv_name_selection)).setTextColor(v.getContext().getResources().
- getColor(R.color.color_tv_city_selected));
- current = position;
- // if (Locale.getDefault().getLanguage().equals("ar")) {
- // mSelectedDurationTextView.setText(mDurationsArabicList.get(position));
- // } else {
- String selected = mDurationsList.get(position);
- Log.d(TAG, "selected=" + selected);
- mSelectedDurationTextView.setText(selected);
- String[] temp = selected.split("/");
- if (temp[0].equals(CustomerConstants.OUTSTATION) || temp[0].equals(CustomerConstants.OUTSTATION_AR)) {
- mDaysWidgetLayout.startAnimation(Animator.getSingleInstance().getSlideRightIn(context));
- mDaysWidgetLayout.setVisibility(View.VISIBLE);
- isDurationActive = false;
- showDurationWidget(false);
- mWidgetListBox.setTextView(getString(R.string.full_package_days_in_package_select), getString(R.string.full_package_days_in_package), R.drawable.clock_gray);
- if (Locale.getDefault().getLanguage().equals("ar")) {
- mWidgetListBox.setListItems(daysDurationArabicArray);
- } else {
- mWidgetListBox.setListItems(daysDurationArray);
- }
- } else {
- getSupportLoaderManager().restartLoader(0, null, infoLoaderCallbacks);
- }
- mSelectDurationLayout.setVisibility(View.GONE);
- mSelectDurationView.setVisibility(View.GONE);
- }
- };
- @Override
- protected View getStepForwardView() {
- return mSubmitBtn;
- }
- @Override
- protected AddressWidget getPickUpWidget() {
- return pickupWidget;
- }
- @Override
- protected AddressWidget getDestinationWidgetView() {
- return mDestinationWidgetView;
- }
- @Override
- protected MapFragmentWithCenteredMarker getMapFragmentWithCenteredMarker() {
- return mMapFragmentWithCenteredMarker;
- }
- private View.OnClickListener selectDurationClick = new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- if (mDurationsList.size() != 0) {
- isInDurationSelectionMode = !isInDurationSelectionMode;
- if (isInDurationSelectionMode) { //open
- mSelectDurationLayout.setVisibility(View.VISIBLE);
- mSelectDurationView.setVisibility(View.VISIBLE);
- } else {
- mSelectDurationLayout.setVisibility(View.GONE);
- mSelectDurationView.setVisibility(View.GONE);
- }
- isDurationActive = true;
- showDurationWidget(false);
- showTimeWidget(false, false);
- if (mDaysWidgetLayout.getVisibility() == View.VISIBLE) {
- makeDaysInFullPackageInvisible();
- }
- }
- }
- };
- @Override
- public void onUIChanged() {
- if (mChooseTimeLayout.getVisibility() == View.VISIBLE) {
- mChooseTimeLayout.startAnimation(Animator.getSingleInstance().getSlideRightOut(context));
- mChooseTimeLayout.setVisibility(View.GONE);
- }
- }
- private void makeDaysInFullPackageInvisible() {
- mDaysWidgetLayout.setVisibility(View.GONE);
- mWidgetListBox.setActiveState(true); //by default
- mWidgetListBox.closeListBox();
- }
- void preloadStuff(@Nullable String city) {
- final String emptyCity = getString(R.string.manual_select_city);
- if (city != null) {
- Observable.zip(
- cachingPlacesManager.travelPopular(city, emptyCity, CachingPlacesManager.urlForState(ManualSelectAddressActivity.TRAVEL, city))
- .subscribeOn(Schedulers.io()),
- cachingPlacesManager.travelPopular(city, emptyCity, CachingPlacesManager.urlForState(ManualSelectAddressActivity.POPULAR, city))
- .subscribeOn(Schedulers.io()),
- new Func2<FavouritedPlaces, FavouritedPlaces, Object>() {
- @Override
- public Object call(FavouritedPlaces favouritedPlaces,
- FavouritedPlaces favouritedPlaces2) {
- return null;
- }
- })
- .onErrorReturn(new Func1<Throwable, Object>() {
- @Override
- public Object call(Throwable throwable) {
- return null;
- }
- })
- .subscribe();
- }
- }
- private void resetBookings() {
- mDestinationWidgetView.setPlace(null);
- if (mChooseTimeLayout.getVisibility() == View.VISIBLE) {
- mChooseTimeLayout.startAnimation(Animator.getSingleInstance().getSlideRightOut(context));
- mChooseTimeLayout.setVisibility(View.GONE);
- }
- if (mDurationBlocksLayout.getVisibility() == View.VISIBLE) {
- mDurationBlocksLayout.startAnimation(Animator.getSingleInstance().getSlideRightOut(context));
- mDurationBlocksLayout.setVisibility(View.GONE);
- }
- if (mDestinationWidgetView.getVisibility() == View.VISIBLE) {
- mDestinationWidgetView.startAnimation(Animator.getSingleInstance().getSlideRightOut(context));
- mDestinationWidgetView.setVisibility(View.GONE);
- }
- if (mDaysWidgetLayout.getVisibility() == View.VISIBLE) {
- mDaysWidgetLayout.startAnimation(Animator.getSingleInstance().getSlideRightOut(context));
- makeDaysInFullPackageInvisible();
- }
- setWidgetsActive(true, false);
- }
- private void setZoomButtonPosition() {
- View zoomControls = mMapFragmentWithCenteredMarker.getView().findViewById(0x1);
- if (zoomControls != null && zoomControls.getLayoutParams() instanceof RelativeLayout.LayoutParams) {
- // ZoomControl is inside of RelativeLayout
- RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) zoomControls.getLayoutParams();
- // Align it to - parent bottom above Buttons
- //params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, R.id.actionButtonsLayout);
- final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10,
- getResources().getDisplayMetrics());
- final int marginBottom = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 150, getResources().getDisplayMetrics());
- params.setMargins(margin, margin, margin, marginBottom);
- zoomControls.setLayoutParams(params);
- }
- }
- private void simpleCheck() {
- if (TextUtils.isEmpty(previousCountry)) previousCountry = "";
- if (TextUtils.isEmpty(previousCity)) previousCity = "";
- }
- // LoaderManager.LoaderCallbacks<ArrayList<String>> callbackHourlyCountries = new LoaderManager.LoaderCallbacks<ArrayList<String>>() {
- //
- // private boolean isHourlyPackageVisible = false;
- //
- // public Loader<ArrayList<String>> onCreateLoader(int id, Bundle args) {
- // return new GetHourlyCountryList(DestinationActivity.this);
- // }
- //
- // @Override
- // public void onLoadFinished(Loader<ArrayList<String>> loader, ArrayList<String> data) {
- // if (data != null) {
- // ArrayList<String> countries = new ArrayList<String>();
- // countries.addAll(data);
- // String countriesWithHourlyPackages = "";
- // Log.e("reali", "my country " + userCountry);
- // for (String country : countries) {
- // if (country.equals(userCountry)) {
- // isHourlyPackageVisible = true;
- // //break;
- // }
- // countriesWithHourlyPackages += country + ",";
- // }
- // if (userCountry != null && !userCountry.equals("")) { // on Place error or No location found in Address widget - don't go to onUserLocationLoaded
- //// setHourlyPackageVisibility(isHourlyPackageVisible);
- // }
- //
- // saveUserLocationData(countriesWithHourlyPackages);
- // }
- // }
- //
- // @Override
- // public void onLoaderReset(Loader<ArrayList<String>> loader) {
- //
- // }
- // };
- private void setHourlyPackageVisibility(boolean isVisible) {
- if (!isVisible) {
- mHeaderWidgetView.makeSecondInvisibleInDoubleMode();
- }
- }
- private void saveUserLocationData(String countriesWithHourlyPacakages) {
- UserLocationAndHourlyPackages.setUserLocationData(DestinationActivity.this, userCountry, userCity);
- UserLocationAndHourlyPackages.setCountriesWithHourlyPackages(DestinationActivity.this, countriesWithHourlyPacakages);
- }
- public static class GetHourlyCountryList extends RoboAsyncTaskLoader<ArrayList<String>> {
- private ArrayList<String> countries;
- @Inject
- private PlaceListFromServer placeListFromServer;
- public GetHourlyCountryList(Context context) {
- super(context);
- }
- @Override
- protected void onStartLoading() {
- super.onStartLoading();
- forceLoad();
- }
- @Override
- public ArrayList<String> loadInBackground() {
- try {
- countries = placeListFromServer.getHourlyCountries();
- return countries;
- } catch (Exception e) {
- Log.e(getClass().getName(), "Problem during downloading coutries for hourly packages", e);
- return null;
- }
- }
- }
- public boolean isOnline() {
- ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
- return cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isConnectedOrConnecting();
- }
- public boolean isConnectingToInternet(Context ctx) {
- ConnectivityManager connectivity = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
- if (connectivity != null) {
- NetworkInfo[] info = connectivity.getAllNetworkInfo();
- if (info != null)
- for (int i = 0; i < info.length; i++)
- if (info[i].getState() == NetworkInfo.State.CONNECTED) {
- return true;
- }
- }
- return false;
- }
- private void getBookingSettings() {
- new GetBookingSettings(DestinationActivity.this) {
- @Override
- protected void onSuccess(BookingSettings settings) throws Exception {
- super.onSuccess(settings);
- bookingSettings = settings;
- //BookingSettings.bookingSettings = settings;
- TaxiPixiApp app = (TaxiPixiApp) getApplication();
- app.setBookingSettings(settings);
- determineBookingFlow();
- }
- }.execute();
- }
- // private class Receiver extends BroadcastReceiver {
- //
- // @Override
- // public void onReceive(Context context, Intent intent) {
- // if (intent.getAction().equals(CustomerConstants.WEB_POPUP_BROADCAST_ACTION)){
- //
- //// String url = intent.getStringExtra(NotificationDatabaseConnector.URL);
- // Intent i = new Intent(context, WebViewActivityPopup.class);
- // i.putExtra(NotificationDatabaseConnector.URL, loginPrefs.getPopupUrl());
- // i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- // context.startActivity(i);
- // }
- // }
- // }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement