Advertisement
Mechele

Untitled

Apr 6th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 102.90 KB | None | 0 0
  1. package com.taxipixi.taxiexchange.activities;
  2.  
  3. import android.app.Activity;
  4. import android.app.AlertDialog;
  5. import android.content.Context;
  6. import android.content.DialogInterface;
  7. import android.content.Intent;
  8. import android.net.ConnectivityManager;
  9. import android.net.NetworkInfo;
  10. import android.os.Bundle;
  11. import android.support.v4.app.LoaderManager;
  12. import android.support.v4.content.Loader;
  13. import android.text.TextUtils;
  14. import android.util.Log;
  15. import android.util.TypedValue;
  16. import android.view.View;
  17. import android.widget.AdapterView;
  18. import android.widget.ArrayAdapter;
  19. import android.widget.FrameLayout;
  20. import android.widget.ImageView;
  21. import android.widget.LinearLayout;
  22. import android.widget.ListView;
  23. import android.widget.ProgressBar;
  24. import android.widget.RelativeLayout;
  25. import android.widget.TextView;
  26. import android.widget.Toast;
  27.  
  28. import com.facebook.AppEventsLogger;
  29. import com.google.gson.reflect.TypeToken;
  30. import com.google.inject.Inject;
  31. import com.taxipixi.Constants;
  32. import com.taxipixi.activities.DialogActivity;
  33. import com.taxipixi.api.ApiAsyncTask;
  34. import com.taxipixi.api.ApiConstants;
  35. import com.taxipixi.entity.Order;
  36. import com.taxipixi.entity.PaymentMethod;
  37. import com.taxipixi.entity.Place;
  38. import com.taxipixi.entity.Profile;
  39. import com.taxipixi.fare.ApproximatedFareForType;
  40. import com.taxipixi.fare.ApproximatedFareInfo;
  41. import com.taxipixi.fare.IsItDayOrNight;
  42. import com.taxipixi.gcm.PushRegistrar;
  43. import com.taxipixi.navigation.CurrentPlaceListener;
  44. import com.taxipixi.navigation.GetAddressesTask;
  45. import com.taxipixi.taxiexchange.CustomerConstants;
  46. import com.taxipixi.taxiexchange.LoginPreferences;
  47. import com.taxipixi.taxiexchange.R;
  48. import com.taxipixi.taxiexchange.TaxiPixiApp;
  49. import com.taxipixi.taxiexchange.api.BookingSettings;
  50. import com.taxipixi.taxiexchange.api.GetBookingSettings;
  51. import com.taxipixi.taxiexchange.api.GetInappMessages;
  52. import com.taxipixi.taxiexchange.api.GetProfileTask;
  53. import com.taxipixi.taxiexchange.api.GlobalVariable;
  54. import com.taxipixi.taxiexchange.api.OrderManager;
  55. import com.taxipixi.taxiexchange.api.PlaceListFromServer;
  56. import com.taxipixi.taxiexchange.api.PreOrder;
  57. import com.taxipixi.taxiexchange.api.SubmitOrderTask;
  58. import com.taxipixi.taxiexchange.api.UserLocationAndHourlyPackages;
  59. import com.taxipixi.taxiexchange.api.cached.CachingOrderManager;
  60. import com.taxipixi.taxiexchange.api.cached.CachingPlacesManager;
  61. import com.taxipixi.taxiexchange.api.payment.GetMyCardsTask;
  62. import com.taxipixi.taxiexchange.data.serverResponce;
  63. import com.taxipixi.taxiexchange.database.DatabaseHelper;
  64. import com.taxipixi.taxiexchange.database.NotificationDatabaseConnector;
  65. import com.taxipixi.taxiexchange.fragments.BottomRecConfirmFragment;
  66. import com.taxipixi.taxiexchange.fragments.BottomRecFragment;
  67. import com.taxipixi.taxiexchange.fragments.MapFragmentWithCenteredMarker;
  68. import com.taxipixi.taxiexchange.fragments.ServiceNotAvailableFragment;
  69. import com.taxipixi.taxiexchange.models.FavouriteBean;
  70. import com.taxipixi.taxiexchange.models.FavouriteSync;
  71. import com.taxipixi.taxiexchange.models.FavouritedPlaces;
  72. import com.taxipixi.taxiexchange.utils.Lists;
  73. import com.taxipixi.taxiexchange.utils.SetFont;
  74. import com.taxipixi.taxiexchange.widgets.ClosestCabInfoHintView;
  75. import com.taxipixi.taxiexchange.widgets.HeaderWidget;
  76. import com.taxipixi.taxiexchange.widgets.MenuUtility;
  77. import com.taxipixi.taxiexchange.widgets.ProfileWidget;
  78. import com.taxipixi.utils.Animator;
  79. import com.taxipixi.utils.DecimalFormating;
  80. import com.taxipixi.widget.AddressWidget;
  81. import com.taxipixi.widget.WidgetListBox;
  82.  
  83. import org.jetbrains.annotations.NotNull;
  84. import org.jetbrains.annotations.Nullable;
  85. import org.json.JSONArray;
  86. import org.json.JSONObject;
  87.  
  88. import java.text.SimpleDateFormat;
  89. import java.util.ArrayList;
  90. import java.util.Arrays;
  91. import java.util.Calendar;
  92. import java.util.Date;
  93. import java.util.List;
  94. import java.util.Locale;
  95. import java.util.concurrent.TimeUnit;
  96.  
  97. import roboguice.content.RoboAsyncTaskLoader;
  98. import roboguice.inject.InjectView;
  99. import rx.Observable;
  100. import rx.Observer;
  101. import rx.Subscriber;
  102. import rx.Subscription;
  103. import rx.android.schedulers.AndroidSchedulers;
  104. import rx.functions.Action1;
  105. import rx.functions.Func1;
  106. import rx.functions.Func2;
  107. import rx.functions.FuncN;
  108. import rx.schedulers.Schedulers;
  109. import rx.subscriptions.Subscriptions;
  110. import timber.log.Timber;
  111.  
  112. import static com.taxipixi.taxiexchange.models.IJson.gson;
  113.  
  114. public class DestinationActivity extends PickingLocationActivity
  115. implements AddressWidget.OnUserLocationLoadedListener,
  116. AddressWidget.OnPointChangedListener,
  117. WidgetListBox.OnUIChangedListener, CurrentPlaceListener,
  118. BottomRecFragment.OnFragmentButtonsClicked {
  119.  
  120. public static final String NEW_BOOKING = "new_booking";
  121. public static final String FROM_DESTINATION_ACTIVITY = "from_destination_activity";
  122. public static final String ADDRESS_TYPE = "requested_address_type";
  123. public static final int REQUEST_BOOKING_SUMMARY = 12;
  124. private static final int REQUEST_CONFIRMATION = 7;
  125. public static final int TIME_EDIT = 14;
  126. private static final String KEY_PICKUP_TIME = "pickup_time";
  127. private static final String PICK_UP = "pick_up";
  128. public static final String DESTINATION = "destination";
  129. private static final String STATE_ASK_LOCATION = "ask_location";
  130. public static final String ORDER = "ORDER";
  131.  
  132. private static final String TAG = "DestinationActivity";
  133.  
  134. private GetAddressesTask.Runner taskRunner;
  135. private boolean isAskToEnableLocation = true;
  136. private boolean isDialogShown = false;
  137. private MapFragmentWithCenteredMarker mMapFragmentWithCenteredMarker;
  138. @InjectView(R.id.pickup_address)
  139. private AddressWidget pickupWidget;
  140. @InjectView(R.id.pickup_marker)
  141. private ImageView mPickUpMarkerImageView;
  142. @InjectView(R.id.destination_marker)
  143. private ImageView mDestinationMarkerImageView;
  144. @InjectView(R.id.header)
  145. private HeaderWidget mHeaderWidgetView;
  146. @InjectView(R.id.destination_address)
  147. private AddressWidget mDestinationWidgetView;
  148. @InjectView(R.id.submitBtn)
  149. private RelativeLayout mSubmitBtn;
  150. @InjectView(R.id.map_selector)
  151. private View map_selector;
  152. @InjectView(R.id.icon_my_location)
  153. private View mMyCurrentLocationView;
  154. @InjectView(R.id.hint)
  155. private ClosestCabInfoHintView mClosestTaxiHintView;
  156. @InjectView(R.id.chooseTimeBtn)
  157. private LinearLayout mChooseTimeLayout;
  158. @InjectView(R.id.timeDateText)
  159. private TextView mTimeDisplayTextView;
  160. @Inject
  161. private PushRegistrar pushRegistrar;
  162. @Inject
  163. private LoginPreferences loginPrefs;
  164. @Inject
  165. private PreferencesStorage preferencesStorage;
  166. @Inject
  167. private Context context;
  168. @Inject
  169. CachingPlacesManager cachingPlacesManager;
  170. @Inject
  171. DatabaseHelper databaseHelper;
  172. @Inject
  173. PlaceListFromServer placeListFromServer;
  174. @Inject
  175. CachingOrderManager cachedOrderManager;
  176.  
  177. // @InjectExtra(Constants.PICKUP_PLACE)
  178. // private Place pickup;
  179.  
  180. private long selectedTime;
  181. private boolean isToday;
  182.  
  183. private String bookingType = CustomerConstants.POINT_TO_POINT;
  184.  
  185. private RelativeLayout mDurationBlocksLayout;
  186. private RelativeLayout mDurationColorLayout;
  187. private ImageView mDurationArrowImg;
  188. private RelativeLayout mSelectDurationLayout;
  189. private View mSelectDurationView;
  190. private boolean isInDurationSelectionMode = false;
  191. private boolean isDurationActive = false;
  192. private ListView mDurationListView;
  193. private TextView mSelectedDurationTextView;
  194. private ArrayList<String> mDurationsList = new ArrayList<String>();
  195. private ArrayList<String> mDurationsIDList = new ArrayList<String>();
  196. private int current = -1;
  197.  
  198. public static final int LOADER_COUNTRIES_HOURLY = 1;
  199.  
  200. private String userCountry = "";
  201. private
  202. @Nullable
  203. String userCity = "";
  204.  
  205. private RelativeLayout mDaysWidgetLayout;
  206. private String[] daysDurationArray = new String[]{"1 DAY", "2 DAYS", "3 DAYS", "4 DAYS", "5 DAYS", "6 DAYS", "7 DAYS", "8 DAYS"};
  207. private String[] daysDurationArabicArray = new String[]{"يوم واحد", "يومين", "ثلاثة أيام", "أربعة أيام", "خمسة أيام", "ستة أيام", "سبعة أيام", "ثمانية أيام"};
  208. private WidgetListBox mWidgetListBox;
  209.  
  210. private TextView mAddDestLabel;
  211. private static boolean p2pOneScreen = true, hourlyOneScreen = false, p2pDestMandatory = false, hourlyDestMandatory = false, p2p_job_assignment = false;
  212. private static int per_km_speed = 360;
  213. private String previousCountry = "", previousCity = "";
  214. private FrameLayout bottomBarContainer;
  215. private BottomRecFragment bottomBarFragment;
  216. private BottomRecConfirmFragment bottomBarConfirmFragment;
  217. public ApproximatedFareInfo approximatedFareInfo = null;
  218. private BookingSettings bookingSettings = null;
  219. private String countryNameFromPlace = null;
  220. Subscription subscription = Subscriptions.empty();
  221. private static PopupSms.ActivityFinishListener mListener;
  222. private ServiceNotAvailableFragment mServiceNotAvailableFragment = new ServiceNotAvailableFragment();
  223.  
  224. private boolean isPickup, isDest;
  225. private ApproximatedFareForType selectedType;
  226. private boolean rideNow = false;
  227. private ProgressBar progress;
  228.  
  229. private Date currentDate;
  230. @Inject
  231. private IsItDayOrNight isItDayOrNight;
  232.  
  233. private List<String> list_inapp;
  234. private long lastOrderID;
  235.  
  236. // private Receiver receiver = new Receiver();
  237.  
  238. public static void setOnActivityFinishListener(Activity listener) {
  239. mListener = (PopupSms.ActivityFinishListener) listener;
  240. }
  241.  
  242. @Override
  243. protected void onCreate(Bundle savedInstanceState) {
  244. super.onCreate(savedInstanceState);
  245. setContentView(com.taxipixi.taxiexchange.R.layout.activity_destination);
  246.  
  247. MenuUtility.setLoginPrefs(loginPrefs);
  248. ProfileWidget.setLoginPrefs(loginPrefs);
  249. Log.e(TAG, "lang - " + Locale.getDefault().getLanguage());
  250. getPickUpWidget().setUserLocationLoadedListener(this);
  251.  
  252. getPickUpWidget().setPointChangedListener(this);
  253. getDestinationWidgetView().setPointChangedListener(this);
  254.  
  255. mMapFragmentWithCenteredMarker = (MapFragmentWithCenteredMarker) getSupportFragmentManager().findFragmentById(R.id.mapfragment);
  256. mMapFragmentWithCenteredMarker.initializePickUpMarkers(mPickUpMarkerImageView, R.drawable.customer_place);
  257. mMapFragmentWithCenteredMarker.initializeDestinationMarkers(mDestinationMarkerImageView, R.drawable.customer_place);
  258. setTitle(R.string.booking_title);
  259.  
  260. bookingSettings = ((TaxiPixiApp) getApplication()).getBookingSettings();
  261.  
  262. pickupWidget.setParentActivity(this);
  263. mDestinationWidgetView.setParentActivity(this);
  264.  
  265. // add for arabic layout !!!
  266. mAddDestLabel = (TextView) findViewById(R.id.addDestLabel);
  267. SetFont.setNeoSansStdRegular(this, mAddDestLabel);
  268. mAddDestLabel.setOnClickListener(new View.OnClickListener() {
  269. @Override
  270. public void onClick(View v) {
  271. if (bookingType.equals(CustomerConstants.POINT_TO_POINT) && mDestinationWidgetView.getVisibility() != View.VISIBLE) {
  272. mAddDestLabel.setVisibility(View.GONE);
  273. mDestinationWidgetView.startAnimation(Animator.getSingleInstance().getSlideRightIn(context));
  274. mDestinationWidgetView.setVisibility(View.VISIBLE);
  275. try {
  276. setWidgetsActive(false, true);
  277. } catch (Exception ex) {
  278. Toast.makeText(getApplicationContext(), R.string.internal_application_error, Toast.LENGTH_SHORT).show();
  279. }
  280. }
  281. }
  282. });
  283. bottomBarContainer = (FrameLayout) findViewById(R.id.bottombar);
  284. bottomBarContainer.setVisibility(View.GONE);
  285. mSubmitBtn.setVisibility(View.GONE);
  286.  
  287. LinearLayout btn_selectDuration = (LinearLayout) findViewById(R.id.btn_select_duration);
  288. mSelectDurationLayout = (RelativeLayout) findViewById(R.id.durationSelectBlockLayout);
  289. mSelectDurationView = findViewById(R.id.view_select_duration);
  290. mDurationListView = (ListView) findViewById(R.id.durationList);
  291. mSelectedDurationTextView = (TextView) findViewById(R.id.tv_select_duration);
  292. mDurationBlocksLayout = (RelativeLayout) findViewById(R.id.durationBlocksLayout);
  293. mDurationColorLayout = (RelativeLayout) findViewById(R.id.iv_duration_color);
  294. mDurationArrowImg = (ImageView) findViewById(R.id.duration_arrow_img);
  295. mDaysWidgetLayout = (RelativeLayout) findViewById(R.id.daysChooseLayout);
  296. mWidgetListBox = (WidgetListBox) findViewById(R.id.days_widget_listbox);
  297. SetFont.setNeoSansStdRegular(this, mSelectedDurationTextView);
  298. SetFont.setNeoSansStdRegular(this, mTimeDisplayTextView);
  299. mWidgetListBox.setListenerToUIChanges(this);
  300.  
  301. btn_selectDuration.setOnClickListener(selectDurationClick);
  302. 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))),
  303. new int[]{R.drawable.fare_menu_point_selected, R.drawable.fare_menu_hour_selected}, clickListener);
  304. mHeaderWidgetView.setImagesSelected(new int[]{R.drawable.fare_menu_point, R.drawable.fare_menu_hour});
  305. bookingType = CustomerConstants.POINT_TO_POINT;
  306. pickupWidget.getSearchAddress().setOnClickListener(new View.OnClickListener() {
  307. @Override
  308. public void onClick(View view) {
  309. setWidgetsActive(true, false);
  310. startManualAddressPicker(PICK_UP);
  311. }
  312. });
  313. mDestinationWidgetView.getSearchAddress().setOnClickListener(new View.OnClickListener() {
  314. @Override
  315. public void onClick(View view) {
  316. setWidgetsActive(false, true);
  317. startManualAddressPicker(DESTINATION);
  318. }
  319. });
  320.  
  321. mMyCurrentLocationView.setOnClickListener(new View.OnClickListener() {
  322. @Override
  323. public void onClick(View view) {
  324. mMapFragmentWithCenteredMarker.onCurrentLocationClicked();
  325. }
  326. });
  327.  
  328. setSelectedTime(getSelectedTime());
  329. getCabOverlaysProvider().setClosestCabInfoListener(mClosestTaxiHintView);
  330. mChooseTimeLayout.setOnClickListener(new View.OnClickListener() {
  331. @Override
  332. public void onClick(View v) {
  333. Intent i = new Intent(DestinationActivity.this, CalendarScreen.class);
  334. i.putExtra(CalendarScreen.TAG_SELECTED_TIME, selectedTime);
  335. startActivityForResult(i, TIME_EDIT);
  336. overridePendingTransition(R.anim.bottom_in, R.anim.top_out);
  337. }
  338. });
  339. if (savedInstanceState != null) {
  340. isAskToEnableLocation = savedInstanceState.getBoolean(STATE_ASK_LOCATION, true);
  341. bookingType = savedInstanceState.getString(CustomerConstants.BOOKING_TYPE);
  342. }
  343. //pickupWidget.setTitleText(getResources().getString(R.string.map_seatchbox_top));
  344. //mDestinationWidgetView.setTitleText(getResources().getString(R.string.widget_destination));
  345. pickupWidget.setIsPickup(true);
  346. mDestinationWidgetView.setIsPickup(false);
  347. setZoomButtonPosition();
  348.  
  349. subscription = databaseHelper.getSyncQueue()
  350. .map(new Func1<List<FavouriteSync>, List<Observable<?>>>() {
  351. @Override
  352. public List<Observable<?>> call(List<FavouriteSync> favouriteSyncs) {
  353. return Lists.map(favouriteSyncs, new Func1<FavouriteSync, Observable<?>>() {
  354. @Override
  355. public Observable<?> call(FavouriteSync sync) {
  356. return from(sync);
  357. }
  358. });
  359. }
  360. })
  361. .flatMap(new Func1<List<Observable<?>>, Observable<?>>() {
  362. @Override
  363. public Observable<?> call(List<Observable<?>> observables) {
  364. Timber.d("gonna make %d requests", observables.size());
  365. return Observable.zip(observables, new FuncN<Object>() {
  366. @Override
  367. public Object call(Object... args) {
  368. return null;
  369. }
  370. });
  371. }
  372. })
  373. .observeOn(AndroidSchedulers.mainThread())
  374. .subscribe(new Observer<Object>() {
  375. @Override
  376. public void onCompleted() {
  377. preloadFavouritesAndRecents();
  378. }
  379.  
  380. @Override
  381. public void onError(Throwable e) {
  382. Timber.e(e, "");
  383. }
  384.  
  385. @Override
  386. public void onNext(Object o) {
  387. }
  388. });
  389.  
  390. progress = (ProgressBar) findViewById(R.id.progressBar2);
  391.  
  392. checkInapp_msgs();
  393. defaultPayment();
  394. defaultCard();
  395.  
  396. }
  397.  
  398. private void defaultCard() {
  399. new GetMyCardsTask(this) {
  400. @Override
  401. protected void onSuccess(serverResponce res) throws Exception {
  402. super.onSuccess(res);
  403.  
  404. JSONArray jsonArray_cards = new JSONArray(res.getText());
  405. for (int i = 0; i < jsonArray_cards.length(); i++) {
  406. JSONObject card = (JSONObject) jsonArray_cards.get(i);
  407. String token = card.getString("token");
  408. String last4 = card.getString("last4");
  409. String brand = card.getString("brand");
  410. boolean selected = card.getBoolean("default_card");
  411. String name = brand.toUpperCase() + " - " + last4;
  412. if (selected) {
  413. GlobalVariable.defaultpayment = last4;
  414. }
  415. }
  416. }
  417. }.execute();
  418. }
  419.  
  420. private void defaultPayment() {
  421. new GetProfileTask(this) {
  422. @Override
  423. protected void onSuccess(Profile profile) throws Exception {
  424. if (profile != null) {
  425. super.onSuccess(profile);
  426. if (profile.getDefault_payment_method().equals(PaymentMethod.DEF_PAY_METH_CASH)) {
  427. Log.d("default_way1", profile.getDefault_payment_method());
  428. GlobalVariable.defaultpaymentway = "cash";
  429. } else if (profile.getDefault_payment_method().equals(PaymentMethod.DEF_PAY_METH_CARD)) {
  430. Log.d("default_way2", profile.getDefault_payment_method());
  431. GlobalVariable.defaultpaymentway = "card";
  432. }
  433.  
  434. }
  435. }
  436. }.execute();
  437. }
  438.  
  439. private void checkInapp_msgs() {
  440. new GetInappMessages(DestinationActivity.this) {
  441. @Override
  442. protected void onSuccess(List<String> str) throws Exception {
  443. super.onSuccess(str);
  444.  
  445. list_inapp = str;
  446.  
  447. Log.e("reali", "inapp_msgs " + str.size());
  448.  
  449. Intent i = new Intent(context, WebViewActivityPopup.class);
  450.  
  451. if (list_inapp.size() == 1) {
  452.  
  453. i.putExtra(NotificationDatabaseConnector.URL, list_inapp.get(0));
  454.  
  455. } else if (list_inapp.size() > 1) {
  456.  
  457. i.putStringArrayListExtra("urls", (ArrayList) list_inapp);
  458. } else {
  459. return;
  460. }
  461.  
  462. i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  463. startActivity(i);
  464.  
  465. }
  466. }.execute();
  467. }
  468.  
  469. @Override
  470. public void onResume() {
  471. super.onResume();
  472. if (mListener != null) {
  473. if (mListener instanceof ProfileActivity) {
  474. mListener.closeActivity();
  475. }
  476. }
  477. if (selectedTime < System.currentTimeMillis()) {
  478. selectedTime = getSelectedTime();
  479. }
  480.  
  481. new CheckRunningOrders(this).execute();
  482.  
  483. // IntentFilter filter = new IntentFilter();
  484. // filter.addAction(CustomerConstants.WEB_POPUP_BROADCAST_ACTION);
  485. //
  486. // registerReceiver(receiver, filter);
  487.  
  488. // removeLabel();//cased destination location disapearing, should remove if no bugs appeared;
  489. AppEventsLogger.activateApp(getBaseContext(), CustomerConstants.FACEBOOK_API_KEY);
  490. }
  491.  
  492. @Override
  493. protected void onPause() {
  494. super.onPause();
  495. }
  496.  
  497. @NotNull
  498. Observable<?> from(@NotNull final FavouriteSync sync) {
  499. return Observable
  500. .create(new Observable.OnSubscribe<Place>() {
  501. @Override
  502. public void call(Subscriber<? super Place> subscriber) {
  503. subscriber.onNext(gson.fromJson(sync.getData(), Place.class));
  504. subscriber.onCompleted();
  505. }
  506. })
  507. .flatMap(new Func1<Place, Observable<?>>() {
  508. @Override
  509. public Observable<?> call(final Place place) {
  510. return (sync.getAction() == FavouriteSync.Action.ADD
  511. ? placeListFromServer.addToFavourites(place)
  512. : placeListFromServer.removeFromFavourites(place))
  513. .retry(2)
  514. .map(new Func1<String, List<Place>>() {
  515. @Override
  516. public List<Place> call(String s) {
  517. final List<FavouriteBean> list = gson.fromJson(
  518. s,
  519. new TypeToken<List<FavouriteBean>>() {
  520. }.getType());
  521. return Lists.map(
  522. list,
  523. new Func1<FavouriteBean, Place>() {
  524. @Override
  525. public Place call(FavouriteBean favouriteBean) {
  526. return favouriteBean.toPlace();
  527. }
  528. });
  529. }
  530. })
  531. .doOnNext(new Action1<List<Place>>() {
  532. @Override
  533. public void call(List<Place> places) {
  534. final int i = places.indexOf(place);
  535. if (i != -1) {
  536. databaseHelper.replaceInFavs(place, places.get(i));
  537. }
  538. }
  539. });
  540. }
  541. })
  542. .subscribeOn(Schedulers.io());
  543. }
  544.  
  545. @Override
  546. protected void onDestroy() {
  547. subscription.unsubscribe();
  548. p2pOneScreen = true;
  549. p2pDestMandatory = hourlyDestMandatory = hourlyOneScreen = false;
  550. super.onDestroy();
  551. }
  552.  
  553. void preloadFavouritesAndRecents() {
  554. Observable.merge(cachingPlacesManager.preloadFavourites()
  555. .subscribeOn(Schedulers.io())
  556. .retry(5),
  557. cachingPlacesManager.preloadRecents()
  558. .subscribeOn(Schedulers.io())
  559. .retry(5))
  560. .onErrorReturn(new Func1<Throwable, List<Place>>() {
  561. @Override
  562. public List<Place> call(Throwable throwable) {
  563. return null;
  564. }
  565. })
  566. .subscribe();
  567. }
  568.  
  569. private HeaderWidget.HeaderTextClickedListener clickListener = new HeaderWidget.HeaderTextClickedListener() {
  570. @Override
  571. public void onClicked(int index) {
  572. if (index == 0) {
  573. if (!bookingType.equals(CustomerConstants.POINT_TO_POINT)) {
  574. resetBookings();
  575. }
  576. bookingType = CustomerConstants.POINT_TO_POINT;
  577. if (p2pOneScreen)
  578. getSupportLoaderManager().restartLoader(0, null, infoLoaderCallbacks);
  579. else
  580. removeBottomBar();
  581. } else {
  582. if (!bookingType.equals(CustomerConstants.HOURLY)) {
  583. resetBookings();
  584. }
  585. bookingType = CustomerConstants.HOURLY;
  586. getSupportLoaderManager().destroyLoader(0);
  587.  
  588. removeBottomBar();
  589.  
  590. //determineBookingFlow();
  591.  
  592. //HOURLY!
  593.  
  594. // if(hourlyOneScreen)
  595. // getSupportLoaderManager().restartLoader(0, null, infoLoaderCallbacks);
  596. }
  597. }
  598. };
  599.  
  600. @Override
  601. public void onUserLocationChanged(Place place) {
  602. Log.e(TAG, "onUserLocationChanged");
  603. if (place.getUserCurrentCountry() == null) {
  604. taskRunner = new GetAddressesTask.Runner(getApplicationContext(), new Locale("en"));
  605. taskRunner.runTask(place.getLatLng(), this);
  606. } else {
  607. if (!place.getUserCurrentCountry().equals("Nigeria") &&
  608. !place.getUserCurrentCountry().equals("Saudi Arabia") &&
  609. !place.getUserCurrentCountry().equals("USA") &&
  610. !place.getUserCurrentCountry().equals("India")) {
  611. getSupportLoaderManager().restartLoader(0, null, infoLoaderCallbacks);
  612. } else {
  613. removeLabel();
  614. removeBottomBar();
  615. determineBookingFlow();
  616. }
  617. }
  618. }
  619.  
  620. @Override
  621. public void onPointChanged(boolean isPickup) {
  622.  
  623. Log.e(TAG, "onPointChanged onPointChanged onPointChanged");
  624.  
  625. if (isPickup)
  626. this.isPickup = true;
  627. else
  628. this.isDest = true;
  629.  
  630. if (bookingType.equals(CustomerConstants.POINT_TO_POINT) && this.isPickup && isDest)
  631. calcEstimFare(true);
  632. }
  633.  
  634. private void calcEstimFare(boolean check) {
  635. if (!check || (check && !pickupWidget.getPlace().equals(mDestinationWidgetView.getPlace()))) {
  636.  
  637. bottomBarConfirmFragment.showEstimatedCostProgress();
  638.  
  639. getSupportLoaderManager().restartLoader(0, null, fareLoaderCallbacks);
  640. //Log.e(TAG, "CALC CALC CALC");
  641. }
  642. }
  643.  
  644. @Override
  645. public void onUserLocationLoaded(Place place) {
  646. previousCountry = userCountry = place.getUserCurrentCountry();
  647. previousCity = userCity = place.getUserCurrentCity();
  648. determineBookingFlow();
  649. preloadStuff(userCity);
  650. // if (isConnectingToInternet(DestinationActivity.this)) {
  651. // getSupportLoaderManager().initLoader(LOADER_COUNTRIES_HOURLY, null, callbackHourlyCountries);
  652. // }
  653. }
  654.  
  655. @Override
  656. public void onTextSelected(String text) {
  657. getSupportLoaderManager().restartLoader(0, null, infoLoaderCallbacks);
  658. }
  659.  
  660. public void nextClicked(View w) {
  661. Log.d(TAG, "nextClicked");
  662.  
  663. if (bookingType.equals(CustomerConstants.HOURLY)) {
  664. Log.d(TAG, "here-1");
  665. try {
  666. if (pickupWidget != null) {
  667. String country = pickupWidget.getPlace().getUserCurrentCountry();
  668. // Log.e("reali", "hourly country _" + country + "_ countryNameFromPlace " + countryNameFromPlace);
  669. // for (BookingSettings settings : bookingSettings.mBookingSettingsList) {
  670. // Log.e("reali", "bookingSettings _" + settings.getCountry() + "_");
  671. // }
  672.  
  673. boolean isInList = false;
  674.  
  675. if (country != null) {
  676. //["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"]
  677. for (BookingSettings settings : bookingSettings.mBookingSettingsList) {
  678. if (settings.getCountry().equals(country)) {
  679.  
  680. isInList = true;
  681. Log.e("reali", "InList _" + country);
  682.  
  683. mDurationsList.clear();
  684. mDurationsList.addAll(settings.getmPackages());
  685.  
  686. mDurationsIDList.clear();
  687. mDurationsIDList.addAll(settings.getmPackagesId());
  688. }
  689. }
  690. if (!isInList) {
  691. Toast.makeText(getApplicationContext(), getString(R.string.booking_not_available), Toast.LENGTH_LONG).show();
  692. return;
  693. }
  694. } else if (countryNameFromPlace != null) {
  695. for (BookingSettings settings : bookingSettings.mBookingSettingsList) {
  696. if (settings.getCountry().equals(countryNameFromPlace)) {
  697.  
  698. isInList = true;
  699. Log.e("reali", "InList _" + countryNameFromPlace);
  700.  
  701. mDurationsList.clear();
  702. mDurationsList.addAll(settings.getmPackages());
  703.  
  704. mDurationsIDList.clear();
  705. mDurationsIDList.addAll(settings.getmPackagesId());
  706. }
  707. }
  708. if (!isInList) {
  709. Toast.makeText(getApplicationContext(), getString(R.string.booking_not_available), Toast.LENGTH_LONG).show();
  710. return;
  711. }
  712. } else {
  713. Toast.makeText(this, getString(R.string.cannot_determine_country), Toast.LENGTH_LONG).show();
  714. return;
  715. }
  716. } else {
  717. Toast.makeText(this, getString(R.string.cannot_determine_country), Toast.LENGTH_LONG).show();
  718. return;
  719. }
  720. } catch (Exception ex) {
  721. Log.e(TAG, "unexpected error = " + ex.getMessage());
  722. }
  723. ArrayAdapter<String> adapterCity = null;
  724. // if (Locale.getDefault().getLanguage().equals("ar")) {
  725. // adapterCity = new ArrayAdapter<String>(this, R.layout.duration_list_item, R.id.tv_name_selection, mDurationsArabicList);
  726. // } else {
  727. // if (mDurationsList.size() != 0)
  728. adapterCity = new ArrayAdapter<String>(this, R.layout.duration_list_item, R.id.tv_name_selection, mDurationsList);
  729. // }
  730. mDurationListView.setAdapter(adapterCity);
  731. mDurationListView.setOnItemClickListener(durationListListener);
  732. }
  733. Log.d(TAG, "here-2");
  734. String[] arr = mSelectedDurationTextView.getText().toString().split("/");
  735. String packageStr = arr[0];
  736. Log.d("DestinationActivity:", "Selected _" + packageStr + "_");
  737. Log.d(TAG, "here-3");
  738. if (bookingType.equals(CustomerConstants.POINT_TO_POINT) && mDestinationWidgetView.getVisibility() != View.VISIBLE) {
  739. if (mAddDestLabel.getVisibility() == View.VISIBLE) {
  740. mAddDestLabel.setVisibility(View.GONE);
  741. }
  742.  
  743. Log.d(TAG, "here-4");
  744. mDestinationWidgetView.startAnimation(Animator.getSingleInstance().getSlideRightIn(context));
  745. mDestinationWidgetView.setVisibility(View.VISIBLE);
  746. try {
  747. setWidgetsActive(false, true);
  748. } catch (Exception ex) {
  749. Toast.makeText(getApplicationContext(), R.string.internal_application_error, Toast.LENGTH_SHORT).show();
  750. }
  751. } else if (bookingType.equals(CustomerConstants.HOURLY) && hourlyDestMandatory && mDestinationWidgetView.getVisibility() != View.VISIBLE) {
  752. mDestinationWidgetView.startAnimation(Animator.getSingleInstance().getSlideRightIn(context));
  753. mDestinationWidgetView.setVisibility(View.VISIBLE);
  754. isDurationActive = true;
  755. try {
  756. setWidgetsActive(false, true);
  757. } catch (Exception ex) {
  758. Toast.makeText(getApplicationContext(), R.string.internal_application_error, Toast.LENGTH_SHORT).show();
  759. }
  760. } else if (bookingType.equals(CustomerConstants.HOURLY) && mDurationBlocksLayout.getVisibility() != View.VISIBLE) {
  761. Log.d(TAG, "here-5");
  762. mDurationBlocksLayout.startAnimation(Animator.getSingleInstance().getSlideRightIn(context));
  763. mDurationBlocksLayout.setVisibility(View.VISIBLE);
  764. isDurationActive = true;
  765. try {
  766. setWidgetsActive(false, false);
  767. } catch (Exception ex) {
  768. Log.d(TAG, "--ex=" + ex.getMessage());
  769. Toast.makeText(getApplicationContext(), R.string.internal_application_error, Toast.LENGTH_SHORT).show();
  770. }
  771.  
  772. } else if (!validateLocation(true)) {
  773. Log.d(TAG, "here-6");
  774. return;
  775. } else if (bookingType.equals(CustomerConstants.HOURLY) && !(mDurationsList.contains(mSelectedDurationTextView.getText()))) {
  776. Log.d(TAG, "here-7");
  777. if (mDurationsList.size() != 0)
  778. Toast.makeText(this, R.string.no_duration_message, Toast.LENGTH_LONG).show();
  779. else
  780. Toast.makeText(getApplicationContext(), getString(R.string.booking_not_available), Toast.LENGTH_LONG).show();
  781. return;
  782. } else if (bookingType.equals(CustomerConstants.HOURLY) && mDurationBlocksLayout.getVisibility() == View.VISIBLE &&
  783. mDaysWidgetLayout.getVisibility() != View.VISIBLE && (packageStr.equals(CustomerConstants.OUTSTATION) || packageStr.equals(CustomerConstants.OUTSTATION_AR))) {
  784. Log.d(TAG, "here-8");
  785. mDaysWidgetLayout.startAnimation(Animator.getSingleInstance().getSlideRightIn(context));
  786. mDaysWidgetLayout.setVisibility(View.VISIBLE);
  787. isDurationActive = false;
  788. showDurationWidget(false);
  789. mWidgetListBox.setTextView(getString(R.string.full_package_days_in_package_select), getString(R.string.full_package_days_in_package), R.drawable.clock_gray);
  790.  
  791. if (Locale.getDefault().getLanguage().equals("ar")) {
  792. mWidgetListBox.setListItems(daysDurationArabicArray);
  793. } else {
  794. mWidgetListBox.setListItems(daysDurationArray);
  795. }
  796.  
  797. } else if (bookingType.equals(CustomerConstants.HOURLY) && mDaysWidgetLayout.getVisibility() == View.VISIBLE
  798. && (mWidgetListBox.getTextCenter()).equals(getString(R.string.full_package_days_in_package_select))) {
  799. Toast.makeText(this, R.string.no_days_in_package_message, Toast.LENGTH_LONG).show();
  800. return;
  801. } else if (bookingType.equals(CustomerConstants.HOURLY) && hourlyOneScreen) {
  802. getSupportLoaderManager().restartLoader(0, null, infoLoaderCallbacks);
  803. } else if (mChooseTimeLayout.getVisibility() != View.VISIBLE && !hourlyOneScreen) {
  804. Log.d(TAG, "here-9");
  805. if (mDaysWidgetLayout.getVisibility() == View.VISIBLE) {
  806. mWidgetListBox.setActiveState(false);
  807. }
  808. isDurationActive = false;
  809. mSelectDurationLayout.setVisibility(View.GONE);
  810. mSelectDurationView.setVisibility(View.GONE);
  811. isInDurationSelectionMode = false;
  812. mChooseTimeLayout.startAnimation(Animator.getSingleInstance().getSlideRightIn(context));
  813. mChooseTimeLayout.setVisibility(View.VISIBLE);
  814. try {
  815. setWidgetsActive(false, false);
  816. } catch (Exception ex) {
  817. Log.d(TAG, "3-ex=" + ex.getMessage());
  818. Toast.makeText(getApplicationContext(), R.string.internal_application_error, Toast.LENGTH_SHORT).show();
  819. }
  820. } else if ((bookingType.equals(CustomerConstants.HOURLY) && hourlyDestMandatory) ||
  821. (bookingType.equals(CustomerConstants.POINT_TO_POINT) && p2pDestMandatory)) {
  822. confirmFlow();
  823. } else {
  824. Log.d(TAG, "here-10");
  825. startBookingSummaryActivity(true);
  826. }
  827. Log.d(TAG, "here-11");
  828. }
  829.  
  830. private void determineBookingFlow() {
  831. if (pickupWidget == null)
  832. return;
  833. simpleCheck();
  834.  
  835. serviceAvailable();
  836. if (bookingSettings == null || bookingSettings.mBookingSettingsList == null) {
  837. getBookingSettings();
  838. return;
  839. }
  840.  
  841. if (bookingSettings.mBookingSettingsList != null && bookingSettings.mBookingSettingsList.size() <= 0) {
  842. //default settings
  843. getSupportLoaderManager().restartLoader(0, null, infoLoaderCallbacks);
  844. } else {
  845. if (pickupWidget.getPlace() != null) {
  846. String currentCountry = null;
  847. Log.d(TAG, "UserCurrentCountry=" + pickupWidget.getPlace().getUserCurrentCountry());
  848. String tempCountry = "";
  849. if (pickupWidget.getPlace().getUserCurrentCountry() != null)
  850. tempCountry = pickupWidget.getPlace().getUserCurrentCountry();
  851. else if (!TextUtils.isEmpty(previousCountry))
  852. tempCountry = previousCountry;
  853.  
  854. String tempCity = "";
  855. if (pickupWidget.getPlace().getUserCurrentCity() != null)
  856. tempCity = pickupWidget.getPlace().getUserCurrentCity();
  857. else if (!TextUtils.isEmpty(previousCountry))
  858. tempCity = previousCity;
  859.  
  860. Log.e(TAG, "tempCountry=" + tempCountry + " tempCity=" + tempCity);
  861. UserLocationAndHourlyPackages.setUserLocationCountry(context, tempCountry);
  862. UserLocationAndHourlyPackages.setUserLocationCity(context, tempCity);
  863. for (BookingSettings settings : bookingSettings.mBookingSettingsList) {
  864. if (settings.getCountry().equals(tempCountry)) {
  865. currentCountry = settings.getCountry();
  866. p2pOneScreen = settings.isP2p_one_screen_app();
  867. hourlyOneScreen = settings.isHourly_one_screen_app();
  868. p2pDestMandatory = settings.isP2p_dest_mandatory();
  869. hourlyDestMandatory = settings.isHourly_dest_mandatory();
  870. p2p_job_assignment = settings.isP2p_job_assignment();
  871. per_km_speed = settings.getPer_km_speed();
  872.  
  873. Log.i(TAG, "country=" + currentCountry);
  874. Log.i(TAG, "p2pOneScreen=" + p2pOneScreen);
  875. Log.i(TAG, "hourlyOneScreen=" + hourlyOneScreen);
  876. Log.i(TAG, "p2pDestMandatory=" + p2pDestMandatory);
  877. Log.i(TAG, "hourlyDestMandatory=" + hourlyDestMandatory);
  878. Log.i(TAG, "p2p_job_assignment=" + p2p_job_assignment);
  879. }
  880. }
  881. Log.e(TAG, "currentCountry=" + currentCountry);
  882. if (currentCountry != null) {
  883. if (p2pOneScreen == false && bookingType.equals(CustomerConstants.POINT_TO_POINT)) {
  884. Log.i(TAG, "1");
  885. mSubmitBtn.setVisibility(View.VISIBLE);
  886. } else if (p2pOneScreen == true && bookingType.equals(CustomerConstants.POINT_TO_POINT)) {
  887. Log.i(TAG, "2");
  888. getSupportLoaderManager().restartLoader(0, null, infoLoaderCallbacks);
  889. } else if (hourlyOneScreen == false && bookingType.equals(CustomerConstants.HOURLY)) {
  890. Log.i(TAG, "3");
  891. mSubmitBtn.setVisibility(View.VISIBLE);
  892. } else if (hourlyOneScreen == true && bookingType.equals(CustomerConstants.HOURLY)) {
  893. Log.i(TAG, "4");
  894. mSubmitBtn.setVisibility(View.VISIBLE);
  895. //getSupportLoaderManager().restartLoader(0, null, infoLoaderCallbacks);
  896. }
  897. } else {
  898. getSupportLoaderManager().restartLoader(0, null, infoLoaderCallbacks);
  899. }
  900. }
  901. }
  902. }
  903.  
  904. private void removeBottomBar() {
  905. removeLabel();
  906. if (bottomBarFragment != null) {
  907. if (bottomBarFragment.isVisible()) {
  908. RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
  909. (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 35, getResources().getDisplayMetrics()));
  910. lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
  911. bottomBarContainer.setLayoutParams(lp);
  912. map_selector.setVisibility(View.GONE);
  913. getSupportFragmentManager().beginTransaction().remove(bottomBarFragment).commitAllowingStateLoss();
  914. mSubmitBtn.setVisibility(View.VISIBLE);
  915.  
  916. //bottomBarContainer.setVisibility(View.VISIBLE);
  917. }
  918. }
  919. if (bottomBarConfirmFragment != null) {
  920. if (bottomBarConfirmFragment.isVisible()) {
  921. RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
  922. (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 35, getResources().getDisplayMetrics()));
  923. lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
  924. bottomBarContainer.setLayoutParams(lp);
  925. map_selector.setVisibility(View.GONE);
  926. getSupportFragmentManager().beginTransaction().remove(bottomBarConfirmFragment).commitAllowingStateLoss();
  927. mSubmitBtn.setVisibility(View.VISIBLE);
  928. }
  929. }
  930. }
  931.  
  932. private LoaderManager.LoaderCallbacks<ApproximatedFareInfo> infoLoaderCallbacks = new LoaderManager.LoaderCallbacks<ApproximatedFareInfo>() {
  933.  
  934. @Override
  935. public Loader<ApproximatedFareInfo> onCreateLoader(int id, Bundle args) {
  936.  
  937. mSubmitBtn.setVisibility(View.GONE);
  938. if (progress != null) progress.setVisibility(View.VISIBLE);
  939.  
  940. PreOrder preOrder = new PreOrder();
  941. preOrder.setBookingType(bookingType);
  942. preOrder.setOrigin(pickupWidget.getPlace());
  943.  
  944. if (bookingType.equals(CustomerConstants.POINT_TO_POINT))
  945. preOrder.setDestination(pickupWidget.getPlace());
  946.  
  947. if (bookingType.equals(CustomerConstants.HOURLY)) {
  948. String[] arr = mSelectedDurationTextView.getText().toString().split("/");
  949. String packageStr = arr[0];
  950. if (packageStr.equals(CustomerConstants.OUTSTATION) || packageStr.equals(CustomerConstants.OUTSTATION_AR))
  951. packageStr = CustomerConstants.FULL_DAY;
  952.  
  953. for (int i = 0; i < mDurationsList.size(); i++) {
  954. if (mDurationsList.get(i).contains(packageStr)) {
  955. packageStr = mDurationsIDList.get(i);
  956. break;
  957. }
  958. }
  959. preOrder.setPackageType(packageStr);
  960.  
  961. if (packageStr.equals(CustomerConstants.FULL_DAY)) {
  962. String daysStr = null;
  963. if (mWidgetListBox.getTextCenter().contains(" DAY")) {
  964. if (Locale.getDefault().getLanguage().equals("ar")) {
  965. for (int i = 0; i < daysDurationArabicArray.length; i++) {
  966. if (mWidgetListBox.getTextCenter().equals(daysDurationArabicArray[i])) {
  967. daysStr = daysDurationArray[i].split(" ")[0];
  968. break;
  969. }
  970. }
  971. } else {
  972. String[] arr2 = mWidgetListBox.getTextCenter().split(" ");
  973. Log.d(TAG, "arr2=" + mWidgetListBox.getTextCenter());
  974. daysStr = arr2[0];
  975. }
  976. preOrder.setDays(Integer.parseInt(daysStr));
  977. }
  978. Log.d(TAG, "days in package=" + daysStr);
  979. }
  980. }
  981. return new FareInfoLoader(getApplicationContext(), preOrder, "true");
  982. }
  983.  
  984. @Override
  985. public void onLoadFinished(Loader<ApproximatedFareInfo> loader, ApproximatedFareInfo data) {
  986. progress.setVisibility(View.GONE);
  987.  
  988. if (data != null) {
  989. if (data.getTypes().size() > 0) {
  990. showBottomView(data);
  991. approximatedFareInfo = data;
  992. } else {
  993. serviceNotAvailable();
  994. }
  995. } else {
  996. serviceNotAvailable();
  997. }
  998. }
  999.  
  1000. @Override
  1001. public void onLoaderReset(Loader<ApproximatedFareInfo> loader) {
  1002. progress.setVisibility(View.GONE);
  1003. }
  1004. };
  1005.  
  1006. private LoaderManager.LoaderCallbacks<ApproximatedFareInfo> fareLoaderCallbacks = new LoaderManager.LoaderCallbacks<ApproximatedFareInfo>() {
  1007.  
  1008. @Override
  1009. public Loader<ApproximatedFareInfo> onCreateLoader(int id, Bundle args) {
  1010.  
  1011. PreOrder preOrder = new PreOrder();
  1012. preOrder.setBookingType(bookingType);
  1013. preOrder.setOrigin(pickupWidget.getPlace());
  1014.  
  1015. if (bookingType.equals(CustomerConstants.POINT_TO_POINT) ||
  1016. (bookingType.equals(CustomerConstants.HOURLY) && mDestinationWidgetView.getVisibility() == View.VISIBLE))
  1017. preOrder.setDestination(mDestinationWidgetView.getPlace());
  1018.  
  1019. if (bookingType.equals(CustomerConstants.HOURLY)) {
  1020. String[] arr = mSelectedDurationTextView.getText().toString().split("/");
  1021. String packageStr = arr[0];
  1022. if (packageStr.equals(CustomerConstants.OUTSTATION) || packageStr.equals(CustomerConstants.OUTSTATION_AR))
  1023. packageStr = CustomerConstants.FULL_DAY;
  1024.  
  1025. for (int i = 0; i < mDurationsList.size(); i++) {
  1026. if (mDurationsList.get(i).contains(packageStr)) {
  1027. packageStr = mDurationsIDList.get(i);
  1028. break;
  1029. }
  1030. }
  1031. preOrder.setPackageType(packageStr);
  1032.  
  1033. if (packageStr.equals(CustomerConstants.FULL_DAY)) {
  1034. String daysStr = null;
  1035. if (mWidgetListBox.getTextCenter().contains(" DAY")) {
  1036. if (Locale.getDefault().getLanguage().equals("ar")) {
  1037. for (int i = 0; i < daysDurationArabicArray.length; i++) {
  1038. if (mWidgetListBox.getTextCenter().equals(daysDurationArabicArray[i])) {
  1039. daysStr = daysDurationArray[i].split(" ")[0];
  1040. break;
  1041. }
  1042. }
  1043. } else {
  1044. String[] arr2 = mWidgetListBox.getTextCenter().split(" ");
  1045. Log.d(TAG, "arr2=" + mWidgetListBox.getTextCenter());
  1046. daysStr = arr2[0];
  1047. }
  1048. preOrder.setDays(Integer.parseInt(daysStr));
  1049. }
  1050. Log.d(TAG, "days in package=" + daysStr);
  1051. }
  1052. }
  1053. return new FareInfoLoader(getApplicationContext(), preOrder, "");
  1054. }
  1055.  
  1056. @Override
  1057. public void onLoadFinished(Loader<ApproximatedFareInfo> loader, ApproximatedFareInfo data) {
  1058.  
  1059. if (data != null) {
  1060. if (data.getTypes().size() > 0) {
  1061.  
  1062. String estimFareStr = "";
  1063.  
  1064. ApproximatedFareForType mFareType = null;
  1065.  
  1066. for (final ApproximatedFareForType info : data.getTypes()) {
  1067.  
  1068. //Log.e(TAG, info.getCategory() + "_" + info.getCabModel() + "_" + info.getDisplayCategoryName());
  1069.  
  1070. if (selectedType == null)
  1071. return;
  1072. else if (info.getCategory().equals(selectedType.getCategory())) {
  1073. mFareType = info;
  1074. break;
  1075. }
  1076. }
  1077.  
  1078. if (mFareType == null) {
  1079. return;
  1080. }
  1081.  
  1082. // Log.e(TAG, "fareLoaderCallbacks mFareType " + mFareType.getDisplayCategoryName() + " " +
  1083. // selectedType.getDisplayCategoryName() + " " + mFareType.getCabModel() + " " +
  1084. // selectedType.getCabModel());
  1085.  
  1086. currentDate = new Date(System.currentTimeMillis());
  1087.  
  1088. if (isItDayOrNight.isItDay(currentDate, mFareType.getNightStartHr(), mFareType.getDayStartHr())) {
  1089. estimFareStr = mFareType.getCurrency() + " " + DecimalFormating.getStringFormatted(mFareType.getApproxCostDay());
  1090. } else {
  1091. estimFareStr = mFareType.getCurrency() + " " + DecimalFormating.getStringFormatted(mFareType.getApproxCostNight());
  1092. }
  1093.  
  1094. Log.e(TAG, "ApproximatedFareForType onLoadFinished " + estimFareStr);
  1095.  
  1096. if (bottomBarConfirmFragment != null && bottomBarConfirmFragment.isAdded()) {
  1097.  
  1098. bottomBarConfirmFragment.setEstimatedCost(estimFareStr);
  1099.  
  1100. }
  1101. }
  1102. }
  1103. }
  1104.  
  1105. @Override
  1106. public void onLoaderReset(Loader<ApproximatedFareInfo> loader) {
  1107. }
  1108. };
  1109.  
  1110. private void serviceNotAvailable() {
  1111. removeBottomBar();
  1112. mSubmitBtn.setVisibility(View.GONE);
  1113.  
  1114. RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
  1115. (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 60, getResources().getDisplayMetrics()));
  1116. lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
  1117. bottomBarContainer.setLayoutParams(lp);
  1118.  
  1119. getSupportFragmentManager().beginTransaction().replace(R.id.bottombar, mServiceNotAvailableFragment).commitAllowingStateLoss();
  1120.  
  1121. }
  1122.  
  1123. private void serviceAvailable() {
  1124. if (mServiceNotAvailableFragment.isAdded() || mServiceNotAvailableFragment.isVisible()) {
  1125. getSupportFragmentManager().beginTransaction().remove(mServiceNotAvailableFragment).commitAllowingStateLoss();
  1126. }
  1127. }
  1128.  
  1129. private void showBottomView(ApproximatedFareInfo data) {
  1130.  
  1131. RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
  1132. (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 134, getResources().getDisplayMetrics()));
  1133. lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
  1134. bottomBarContainer.setLayoutParams(lp);
  1135.  
  1136. Log.d("ETA Display", "Setting bottombar caboverlays");
  1137. bottomBarFragment = BottomRecFragment.newInstance(data, getCabOverlaysProvider(), per_km_speed);
  1138. // getCabOverlaysProvider().setEtaListener(bottomBarFragment);
  1139. bottomBarFragment.setListener(this);
  1140. getSupportFragmentManager()
  1141. .beginTransaction()
  1142. .replace(R.id.bottombar, bottomBarFragment)
  1143. .commitAllowingStateLoss();
  1144.  
  1145. bottomBarContainer.setVisibility(View.VISIBLE);
  1146. map_selector.setVisibility(View.VISIBLE);
  1147. }
  1148.  
  1149. public void showTimeWidget(boolean pickupWidgetActive, boolean destinationActive) {
  1150. if (pickupWidgetActive || (bookingType.equals(CustomerConstants.POINT_TO_POINT) && destinationActive) || (bookingType.equals(CustomerConstants.HOURLY) && isDurationActive)) {
  1151. mChooseTimeLayout.setVisibility(View.INVISIBLE);
  1152. } else {
  1153. mChooseTimeLayout.setVisibility(View.VISIBLE);
  1154. }
  1155. }
  1156.  
  1157. public void showDurationWidget(boolean pickupWidgetActive) {
  1158. try {
  1159. if (pickupWidgetActive) {
  1160. if (mDurationBlocksLayout.getVisibility() == View.VISIBLE) {
  1161. mDurationBlocksLayout.startAnimation(Animator.getSingleInstance().getSlideRightOut(context));
  1162. mDurationBlocksLayout.setVisibility(View.GONE);
  1163. }
  1164. } else if (isDurationActive) {
  1165. if (Locale.getDefault().getLanguage().equals("ar")) {
  1166. mDurationColorLayout.setBackgroundResource(R.drawable.select_cab_left_en);
  1167. mDurationArrowImg.setImageResource(R.drawable.btn_detail_arrow_down_brown);
  1168. } else {
  1169. //mDurationColorLayout.setBackgroundResource(R.drawable.select_cab_right);
  1170. }
  1171.  
  1172.  
  1173. } else if (!isDurationActive) {
  1174.  
  1175. if (Locale.getDefault().getLanguage().equals("ar")) {
  1176. mDurationColorLayout.setBackgroundResource(R.drawable.searchbox_right_ar);
  1177. mDurationArrowImg.setImageResource(R.drawable.btn_detail_arrow_down);
  1178. } else {
  1179. //mDurationColorLayout.setBackgroundResource(R.drawable.searchbox_right);
  1180. }
  1181.  
  1182. }
  1183. } catch (Exception ex) {
  1184. Log.e(TAG, "unexpected exception = " + ex.getMessage());
  1185. }
  1186. }
  1187.  
  1188. @Override
  1189. protected void onSaveInstanceState(Bundle outState) {
  1190. super.onSaveInstanceState(outState);
  1191. outState.putBoolean(STATE_ASK_LOCATION, isAskToEnableLocation);
  1192. outState.putString(CustomerConstants.BOOKING_TYPE, bookingType);
  1193. }
  1194.  
  1195. private void startManualAddressPicker(String source) {
  1196. Intent intent = new Intent(DestinationActivity.this, ManualSelectAddressActivity.class);
  1197. intent.putExtra("image", source);
  1198. intent.putExtra(FROM_DESTINATION_ACTIVITY, true);
  1199. startActivityForResult(intent, Constants.REQUEST_TYPE_ADDRESS);
  1200. if (Locale.getDefault().getLanguage().equals("ar")) {
  1201. overridePendingTransition(R.anim.left_in, R.anim.right_out);
  1202. } else {
  1203. overridePendingTransition(R.anim.right_in, R.anim.left_out);
  1204. }
  1205. }
  1206.  
  1207. private boolean validateLocation(boolean withValidation) {
  1208. if (pickupWidget.getPlace() == null) {
  1209. Toast.makeText(this, R.string.no_pickup_message, Toast.LENGTH_LONG).show();
  1210. return false;
  1211. } else if (bookingType.equals(CustomerConstants.POINT_TO_POINT) && mDestinationWidgetView.getPlace() == null) {
  1212. Toast.makeText(this, R.string.no_destination_message, Toast.LENGTH_LONG).show();
  1213. return false;
  1214. } else {
  1215. if (withValidation && bookingType.equals(CustomerConstants.POINT_TO_POINT) && (pickupWidget.getPlace().getDescription().equals(mDestinationWidgetView.getPlace().getDescription()))) {
  1216.  
  1217. Intent i = new Intent(context, GenericPopup.class);
  1218. i.putExtra(GenericPopup.BTN_YES, true);
  1219. i.putExtra(GenericPopup.BTN_YES_TEXT, getString(R.string.dest_popup_btn_ok));
  1220. i.putExtra(GenericPopup.BTN_NO, false);
  1221. i.putExtra(GenericPopup.TITLE, getString(R.string.dest_popup_warning));
  1222. i.putExtra(GenericPopup.MESS, getString(R.string.dest_popup_pickup_dest_same) + " \n \n" + getString(R.string.dest_popup_dest_far));
  1223. i.putExtra(GenericPopup.IS_CANCEL, false);
  1224. startActivity(i);
  1225. overridePendingTransition(R.anim.bottom_in, R.anim.top_out);
  1226. return false;
  1227. }
  1228. }
  1229. return true;
  1230. }
  1231.  
  1232. private void startBookingSummaryActivity(boolean withValidation) {
  1233. if (validateLocation(withValidation)) {
  1234. Intent intent = new Intent(this, BookingSummaryActivity.class);
  1235. intent.putExtra(CustomerConstants.BOOKING_TYPE, bookingType);
  1236. intent.putExtra(Constants.PICKUP_PLACE, pickupWidget.getPlace());
  1237. if (bookingType.equals(CustomerConstants.POINT_TO_POINT))
  1238. intent.putExtra(Constants.DESTINATION_PLACE, mDestinationWidgetView.getPlace());
  1239.  
  1240. intent.putExtra(Constants.PICKUP_TIME, selectedTime);
  1241. if (bookingType.equals(CustomerConstants.HOURLY)) {
  1242. // intent.putExtra(Constants.PACKAGE_TYPE, tv_selectedDuration.getText());
  1243. String[] arr = mSelectedDurationTextView.getText().toString().split("/");
  1244. String packageStr = arr[0];
  1245. if (packageStr.equals(CustomerConstants.OUTSTATION) || packageStr.equals(CustomerConstants.OUTSTATION_AR))
  1246. packageStr = CustomerConstants.FULL_DAY;
  1247.  
  1248. for (int i = 0; i < mDurationsList.size(); i++) {
  1249. Log.e("reali", "duration " + packageStr + " " + mDurationsList.get(i));
  1250. if (mDurationsList.get(i).contains(packageStr)) {
  1251. packageStr = mDurationsIDList.get(i);
  1252. break;
  1253. }
  1254. }
  1255. intent.putExtra(Constants.PACKAGE_TYPE, packageStr);
  1256.  
  1257. if (packageStr.equals(CustomerConstants.FULL_DAY)) {
  1258. String daysStr = null;
  1259. if (Locale.getDefault().getLanguage().equals("ar")) {
  1260. for (int i = 0; i < daysDurationArabicArray.length; i++) {
  1261. if (mWidgetListBox.getTextCenter().equals(daysDurationArabicArray[i])) {
  1262. daysStr = daysDurationArray[i].split(" ")[0];
  1263. break;
  1264. }
  1265. }
  1266. } else {
  1267. String[] arr2 = mWidgetListBox.getTextCenter().toString().split(" ");
  1268. daysStr = arr2[0];
  1269. }
  1270. intent.putExtra(CustomerConstants.DAYS_IN_FULL_PACKAGE, daysStr);
  1271. Log.d("DestinationActivity:", "days in package passed to start booking " + daysStr);
  1272. }
  1273. }
  1274. startActivityForResult(intent, REQUEST_BOOKING_SUMMARY);
  1275. if (Locale.getDefault().getLanguage().equals("ar")) {
  1276. overridePendingTransition(R.anim.left_in, R.anim.right_out);
  1277. } else {
  1278. overridePendingTransition(R.anim.right_in, R.anim.left_out);
  1279. }
  1280. }
  1281. }
  1282.  
  1283. @Override
  1284. protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  1285. Log.d(TAG, "onActivityResult Request Code: " + requestCode + ", Result Code: " + resultCode);
  1286. if (requestCode == REQUEST_CONFIRMATION) {
  1287. if (resultCode == DialogActivity.RESULT_CANCELED) {
  1288. startBookingSummaryActivity(false);
  1289. return;
  1290. } else if (resultCode == DialogActivity.RESULT_POSITIVE) {
  1291. return;
  1292. }
  1293.  
  1294. } else if (requestCode == REQUEST_BOOKING_SUMMARY && resultCode == BookingSummaryActivity.RESULT_ORDER_SENT) {
  1295. finish();
  1296. } else if (resultCode == ManualSelectAddressActivity.RESULT_OK && requestCode == Constants.REQUEST_TYPE_ADDRESS) {
  1297. if (data.hasExtra(ManualSelectAddressActivity.EXTRA_PLACE)) {
  1298. String address_type = data.getStringExtra(ADDRESS_TYPE);
  1299. Place place = data.getParcelableExtra(ManualSelectAddressActivity.EXTRA_PLACE);
  1300.  
  1301. taskRunner = new GetAddressesTask.Runner(getApplicationContext());
  1302. if (place != null) {
  1303. taskRunner.runTask(place.getLatLng(), this);
  1304. }
  1305.  
  1306. if (address_type == null || address_type.equalsIgnoreCase(PICK_UP)) {
  1307. pickupWidget.onNewPlace(place);
  1308. } else {
  1309. mDestinationWidgetView.onNewPlace(place);
  1310. }
  1311. getMapFragmentWithCenteredMarker().navigateTo(place.getLatLng());
  1312. }
  1313. } else if (requestCode == Constants.ERROR_GEOCODING_SERVICE_PICKUP) {
  1314. startManualAddressPicker(PICK_UP);
  1315. } else if (requestCode == Constants.ERROR_GEOCODING_SERVICE_DESTINATION) {
  1316. startManualAddressPicker(DESTINATION);
  1317. } else if (requestCode == TIME_EDIT && resultCode == Constants.RESULT_SUCCESS) {
  1318. long time = data.getLongExtra(NewCalendarAcitivity.TAG_SELECTED_TIME, 0);// date/time from calendar screen
  1319. Log.d("timeresult2",time+"_");
  1320. isToday = data.getBooleanExtra(NewCalendarAcitivity.TAG_TODAY, true);
  1321. if (time < System.currentTimeMillis())
  1322. time = System.currentTimeMillis() + TimeUnit.MINUTES.toMillis(15);
  1323. setSelectedTime(time);// current day
  1324. if (bookingType.equals(CustomerConstants.POINT_TO_POINT)) {
  1325. addLabel();
  1326. }
  1327. bottomBarConfirm(time, false);
  1328.  
  1329. } else if (requestCode == TIME_EDIT && resultCode == RESULT_CANCELED) {
  1330. removeBottomBar();
  1331. getSupportLoaderManager().restartLoader(0, null, infoLoaderCallbacks);
  1332. removeLabel();
  1333. mSubmitBtn.setVisibility(View.GONE);
  1334. } else if (requestCode == 1313 && resultCode == 1) {
  1335. AccountSettingsActivity.start(DestinationActivity.this);
  1336. finish();
  1337. } else if (requestCode == 1414 && resultCode == 1) {
  1338. Intents.openTrackingActivity(this, lastOrderID);
  1339. finish();
  1340. } else {
  1341. super.onActivityResult(requestCode, resultCode, data);
  1342. }
  1343. }
  1344.  
  1345. private void bottomBarConfirm(long time, boolean isRideNowClicked) {
  1346. if (approximatedFareInfo != null) {
  1347. if (approximatedFareInfo.getTypes().size() > 0) {
  1348. bottomBarConfirmFragment = BottomRecConfirmFragment.newInstance(approximatedFareInfo, time, createOrder(), isRideNowClicked);
  1349. bottomBarConfirmFragment.setListener(this);
  1350. if (!bottomBarConfirmFragment.isAdded()) {
  1351. getSupportFragmentManager()
  1352. .beginTransaction()
  1353. .replace(R.id.bottombar, bottomBarConfirmFragment)
  1354. .commitAllowingStateLoss();
  1355. }
  1356. }
  1357. }
  1358. }//Mechele
  1359.  
  1360. private void submitOrder() {
  1361.  
  1362. if (!validateLocation(true)) {
  1363. return;
  1364. } else {
  1365. final Order newOrder = createOrder();
  1366. new SubmitOrderTask(context, newOrder) {
  1367. @Override
  1368. protected void onSuccess(Long createdOrderId) throws Exception {
  1369. super.onSuccess(createdOrderId);
  1370. newOrder.setOrderId(createdOrderId);
  1371. newOrder.setStatus(Order.STATUS_PENDING);
  1372. databaseHelper.insert(newOrder);
  1373. //clean
  1374. Intent intent = new Intent(context, PopupBookingReceived.class);
  1375. intent.putExtra(Constants.ORDER_ID, createdOrderId);
  1376. intent.putExtra(Constants.ORDER, newOrder);
  1377. intent.putExtra(Constants.COUNTRY_CODE, "");
  1378. startActivity(intent);
  1379. overridePendingTransition(R.anim.bottom_in, R.anim.top_out);
  1380. }
  1381. }.execute();
  1382. }
  1383. }
  1384.  
  1385. private class CheckRunningOrders extends ApiAsyncTask<List<Order>> {
  1386.  
  1387. @Inject
  1388. private OrderManager orderManager;
  1389.  
  1390. public CheckRunningOrders(Context context) {
  1391. super(context);
  1392. }
  1393.  
  1394. @Override
  1395. public List<Order> call() throws Exception {
  1396. return orderManager.getOrders();
  1397. }
  1398.  
  1399. @Override
  1400. protected void onSuccess(List<Order> orders) throws Exception {
  1401. super.onSuccess(orders);
  1402. if (orders != null) {
  1403. if ((orders.size() > 0) && (ApiConstants.actived == 0)) {
  1404.  
  1405. Order o = orders.get(0);
  1406. if (o.getStatus().equals(Order.STATUS_PENDING)) {
  1407. Intent intent = new Intent(DestinationActivity.this, AccountSettingsActivity.class);
  1408. intent.putExtra("key", '2');
  1409. DestinationActivity.this.startActivity(new Intent(DestinationActivity.this, AccountSettingsActivity.class).putExtra("key", '2'));
  1410. DestinationActivity.this.finish();
  1411.  
  1412. } else if (o.getStatus().equals(Order.STATUS_ACCEPTED) ||
  1413. o.getStatus().equals(Order.STATUS_STARTED)) {
  1414. Log.d("status_view", "accepted");
  1415. Intents.openTrackingActivity(DestinationActivity.this, o.getOrderId());
  1416. DestinationActivity.this.finish();
  1417. }
  1418. }
  1419. }
  1420.  
  1421. /*if (orders != null && orders.size() > 0) {
  1422.  
  1423. boolean foundActive = false;
  1424. for (Order o : orders) {
  1425. if (o.getStatus().equals(Order.STATUS_ACCEPTED) ||
  1426. o.getStatus().equals(Order.STATUS_STARTED)) {
  1427. lastOrderID = o.getOrderId();
  1428. foundActive = true;
  1429. break;
  1430. }
  1431. }
  1432.  
  1433. if (foundActive) {
  1434. Intent intent = new Intent(DestinationActivity.this, PopupScreenNew.class);
  1435. // intent.putExtra("title",activ. getResources().getString(R.string.info_title));
  1436. intent.putExtra("message", getResources().getString(R.string.already_have_booking));
  1437. startActivityForResult(intent, 1414);
  1438. } else {
  1439. Order o1 = orders.get(0);
  1440. if (o1.getStatus().equals(Order.STATUS_PENDING)) {
  1441. Intent intent = new Intent(DestinationActivity.this, PopupScreenNew.class);
  1442. // intent.putExtra("title",activ. getResources().getString(R.string.info_title));
  1443. intent.putExtra("message", getResources().getString(R.string.already_have_booking));
  1444. startActivityForResult(intent, 1313);
  1445. }
  1446.  
  1447. }
  1448. Order o = orders.get(0);
  1449. if (o.getStatus().equals(Order.STATUS_PENDING) ||
  1450. o.getStatus().equals(Order.STATUS_ACCEPTED) ||
  1451. o.getStatus().equals(Order.STATUS_STARTED)) {
  1452.  
  1453.  
  1454. }
  1455. }*/
  1456. }
  1457. }
  1458.  
  1459. private void confirmFlow() {
  1460. if (mDestinationWidgetView.getVisibility() != View.VISIBLE) {
  1461. Toast.makeText(context, "Please, add the destination", Toast.LENGTH_SHORT).show();
  1462. } else {
  1463. submitOrder();
  1464. }
  1465. }
  1466.  
  1467. @Override
  1468. public void onConfirmClicked() {
  1469.  
  1470. if (p2pDestMandatory || hourlyDestMandatory) {
  1471. confirmFlow();
  1472. } else if (bookingType.equals(CustomerConstants.POINT_TO_POINT) && rideNow && p2p_job_assignment) {
  1473. final Order newOrder = createOrder();
  1474. new SubmitOrderTask(context, newOrder) {
  1475. @Override
  1476. protected void onSuccess(Long createdOrderId) throws Exception {
  1477. super.onSuccess(createdOrderId);
  1478. newOrder.setOrderId(createdOrderId);
  1479. newOrder.setStatus(Order.STATUS_PENDING);
  1480. databaseHelper.insert(newOrder);
  1481. //clean
  1482. Intent intent = new Intent(context, WaitingForDriverActivity.class);
  1483. intent.putExtra(ORDER, newOrder);
  1484. startActivity(intent);
  1485. // overridePendingTransition(R.anim.bottom_in, R.anim.top_out);
  1486. overridePendingTransition(R.anim.bottom_in, R.anim.show);
  1487. }
  1488. }.execute();
  1489. } else {
  1490. final Order newOrder = createOrder();
  1491. new SubmitOrderTask(context, newOrder) {
  1492. @Override
  1493. protected void onSuccess(Long createdOrderId) throws Exception {
  1494. super.onSuccess(createdOrderId);
  1495. newOrder.setOrderId(createdOrderId);
  1496. newOrder.setStatus(Order.STATUS_PENDING);
  1497. databaseHelper.insert(newOrder);
  1498. //clean
  1499. Intent intent = new Intent(context, PopupBookingReceived.class);
  1500. intent.putExtra(Constants.ORDER_ID, createdOrderId);
  1501. intent.putExtra(Constants.ORDER, newOrder);
  1502. intent.putExtra(Constants.COUNTRY_CODE, "");
  1503. startActivity(intent);
  1504. overridePendingTransition(R.anim.bottom_in, R.anim.top_out);
  1505. }
  1506. }.execute();
  1507. }
  1508. }
  1509.  
  1510. @Override
  1511. public void onNewPlace(Place place) {
  1512. if (place != null) {
  1513. if (!TextUtils.isEmpty(place.getUserCurrentCountry()))
  1514. previousCountry = place.getUserCurrentCountry();
  1515. if (!TextUtils.isEmpty(place.getUserCurrentCity()))
  1516. previousCity = place.getUserCurrentCity();
  1517. countryNameFromPlace = place.getUserCurrentCountry();
  1518.  
  1519. if (bookingType.equals(CustomerConstants.POINT_TO_POINT)) {
  1520. Log.i(TAG, "new Place");
  1521. onUserLocationChanged(place);
  1522. } else {
  1523. if (bookingType.equals(CustomerConstants.HOURLY)) {
  1524. boolean isInList = false;
  1525. if (countryNameFromPlace != null) {
  1526. for (BookingSettings settings : bookingSettings.mBookingSettingsList) {
  1527. if (settings.getCountry().equals(countryNameFromPlace)) {
  1528.  
  1529. isInList = true;
  1530. Log.e("reali", "InList _" + countryNameFromPlace);
  1531.  
  1532. mDurationsList.clear();
  1533. mDurationsList.addAll(settings.getmPackages());
  1534.  
  1535. mDurationsIDList.clear();
  1536. mDurationsIDList.addAll(settings.getmPackagesId());
  1537. }
  1538. }
  1539. if (!isInList) {
  1540. Toast.makeText(getApplicationContext(), getString(R.string.booking_not_available), Toast.LENGTH_LONG).show();
  1541. return;
  1542. }
  1543. } else {
  1544. Toast.makeText(this, getString(R.string.cannot_determine_country), Toast.LENGTH_LONG).show();
  1545. return;
  1546. }
  1547. }
  1548. ArrayAdapter<String> adapterCity = null;
  1549. adapterCity = new ArrayAdapter<String>(this, R.layout.duration_list_item, R.id.tv_name_selection, mDurationsList);
  1550. mDurationListView.setAdapter(adapterCity);
  1551. mDurationListView.setOnItemClickListener(durationListListener);
  1552. //}
  1553. String[] arr = mSelectedDurationTextView.getText().toString().split("/");
  1554. String packageStr = arr[0];
  1555. Log.d("DestinationActivity:", "Selected _" + packageStr + "_");
  1556.  
  1557. if (bookingType.equals(CustomerConstants.HOURLY) && mDurationBlocksLayout.getVisibility() != View.VISIBLE) {
  1558. mDurationBlocksLayout.startAnimation(Animator.getSingleInstance().getSlideRightIn(context));
  1559. mDurationBlocksLayout.setVisibility(View.VISIBLE);
  1560. isDurationActive = true;
  1561. try {
  1562. setWidgetsActive(false, false);
  1563. } catch (Exception ex) {
  1564. Log.d(TAG, "--ex=" + ex.getMessage());
  1565. Toast.makeText(getApplicationContext(), R.string.internal_application_error, Toast.LENGTH_SHORT).show();
  1566. }
  1567. } else if (bookingType.equals(CustomerConstants.HOURLY) && mDurationBlocksLayout.getVisibility() == View.VISIBLE &&
  1568. mDaysWidgetLayout.getVisibility() != View.VISIBLE && (packageStr.equals(CustomerConstants.OUTSTATION)
  1569. || packageStr.equals(CustomerConstants.OUTSTATION_AR))) {
  1570. mDaysWidgetLayout.startAnimation(Animator.getSingleInstance().getSlideRightIn(context));
  1571. mDaysWidgetLayout.setVisibility(View.VISIBLE);
  1572. isDurationActive = false;
  1573. showDurationWidget(false);
  1574. mWidgetListBox.setTextView(getString(R.string.full_package_days_in_package_select), getString(R.string.full_package_days_in_package), R.drawable.clock_gray);
  1575.  
  1576. if (Locale.getDefault().getLanguage().equals("ar")) {
  1577. mWidgetListBox.setListItems(daysDurationArabicArray);
  1578. } else {
  1579. mWidgetListBox.setListItems(daysDurationArray);
  1580. }
  1581. } else if (bookingType.equals(CustomerConstants.HOURLY) && mDaysWidgetLayout.getVisibility() == View.VISIBLE
  1582. && (mWidgetListBox.getTextCenter()).equals(getString(R.string.full_package_days_in_package_select))) {
  1583. Toast.makeText(this, R.string.no_days_in_package_message, Toast.LENGTH_LONG).show();
  1584. return;
  1585. }
  1586. }
  1587. // determineBookingFlow();
  1588. }
  1589. }
  1590.  
  1591. @Override
  1592. public void onPlaceError() {
  1593. countryNameFromPlace = null;
  1594. }
  1595.  
  1596. @Override
  1597. public void onNoLocationFound() {
  1598. countryNameFromPlace = null;
  1599. }
  1600.  
  1601. @Override
  1602. protected void startNextActivity() {
  1603. startBookingSummaryActivity(true);
  1604. }
  1605.  
  1606. @Override
  1607. public void onBackPressed() {
  1608. if (bookingType.equalsIgnoreCase(CustomerConstants.POINT_TO_POINT)) {
  1609. if (mChooseTimeLayout.getVisibility() == View.VISIBLE) {
  1610. mChooseTimeLayout.startAnimation(Animator.getSingleInstance().getSlideRightOut(context));
  1611. mChooseTimeLayout.setVisibility(View.GONE);
  1612. try {
  1613. setWidgetsActive(false, true);
  1614. } catch (Exception ex) {
  1615. Log.d(TAG, "5-ex=" + ex.getMessage());
  1616. Toast.makeText(getApplicationContext(), R.string.internal_application_error, Toast.LENGTH_SHORT).show();
  1617. }
  1618. } else if (mDestinationWidgetView.getVisibility() == View.VISIBLE) {
  1619. mChooseTimeLayout.startAnimation(Animator.getSingleInstance().getSlideRightOut(context));
  1620. mDestinationWidgetView.setVisibility(View.GONE);
  1621. try {
  1622. setWidgetsActive(true, false);
  1623. } catch (Exception ex) {
  1624. Log.d(TAG, "6-ex=" + ex.getMessage());
  1625. Toast.makeText(getApplicationContext(), R.string.internal_application_error, Toast.LENGTH_SHORT).show();
  1626. }
  1627. } else if (mAddDestLabel.getVisibility() == View.VISIBLE) {
  1628. // mAddDestLabel.startAnimation(Animator.getSingleInstance().getSlideRightOut(context));
  1629. mAddDestLabel.setVisibility(View.GONE);
  1630. } else {
  1631. finish();
  1632. }
  1633. } else {
  1634. if (mChooseTimeLayout.getVisibility() == View.VISIBLE) {
  1635. mChooseTimeLayout.startAnimation(Animator.getSingleInstance().getSlideRightOut(context));
  1636. mChooseTimeLayout.setVisibility(View.GONE);
  1637. if (mDaysWidgetLayout.getVisibility() != View.VISIBLE) {
  1638. isDurationActive = true;
  1639. try {
  1640. setWidgetsActive(false, false);
  1641. } catch (Exception ex) {
  1642. Log.d(TAG, "7-ex=" + ex.getMessage());
  1643. Toast.makeText(getApplicationContext(), R.string.internal_application_error, Toast.LENGTH_SHORT).show();
  1644. }
  1645.  
  1646. } else {
  1647. mWidgetListBox.setActiveState(true);
  1648. }
  1649.  
  1650. } else if (mDaysWidgetLayout.getVisibility() == View.VISIBLE) { // FULL DAY package was chosen
  1651. makeDaysInFullPackageInvisible();
  1652. isDurationActive = true;
  1653. showDurationWidget(false);
  1654. } else if (mDurationBlocksLayout.getVisibility() == View.VISIBLE) {
  1655. isDurationActive = false;
  1656. mSelectDurationLayout.setVisibility(View.GONE);
  1657. mSelectDurationView.setVisibility(View.GONE);
  1658. isInDurationSelectionMode = false;
  1659. try {
  1660. setWidgetsActive(true, false);
  1661. } catch (Exception ex) {
  1662. Log.d(TAG, "8-ex=" + ex.getMessage());
  1663. Toast.makeText(getApplicationContext(), R.string.internal_application_error, Toast.LENGTH_SHORT).show();
  1664. }
  1665. } else {
  1666. finish();
  1667. }
  1668. }
  1669. }
  1670.  
  1671. private void setSelectedTime(long time) {
  1672. selectedTime = time;
  1673. Calendar c = Calendar.getInstance();
  1674. c.setTimeInMillis(selectedTime);
  1675. SimpleDateFormat format = new SimpleDateFormat("dd/MMM/yyyy");
  1676. int hr = c.get(Calendar.HOUR_OF_DAY);
  1677. int min = c.get(Calendar.MINUTE);
  1678.  
  1679. String minDisplay = "";
  1680. if (min < 10) {
  1681. minDisplay = "0" + min;
  1682. } else {
  1683. minDisplay = min + "";
  1684. }
  1685.  
  1686. if (Locale.getDefault().getLanguage().equals("ar")) {
  1687. String timeDisplay = hr + ":" + minDisplay;
  1688. if (!isToday) {
  1689. timeDisplay = format.format(time) + ", " + timeDisplay;
  1690. } else {
  1691. timeDisplay += " اليوم";
  1692. }
  1693. mTimeDisplayTextView.setText(timeDisplay);
  1694. } else {
  1695.  
  1696. String am_pm = ((c.get(Calendar.AM_PM) == Calendar.AM) ? "AM" : "PM");
  1697. if (hr == 0) {
  1698. hr = 12;
  1699. }
  1700.  
  1701. if (min < 10) {
  1702. minDisplay = "0" + min;
  1703. } else {
  1704. minDisplay = min + "";
  1705. }
  1706.  
  1707. String timeDisplay = hr + ":" + minDisplay + " " + am_pm;
  1708.  
  1709. if (!isToday) {
  1710. timeDisplay += ", " + format.format(time);
  1711. } else {
  1712. timeDisplay += " " + getString(R.string.today);
  1713. }
  1714. mTimeDisplayTextView.setText(timeDisplay);
  1715. }
  1716. }
  1717.  
  1718. public long getSelectedTime() {
  1719.  
  1720. long time = System.currentTimeMillis();
  1721.  
  1722. Calendar c = Calendar.getInstance();
  1723. c.setTimeInMillis(time);
  1724.  
  1725. int min = c.get(Calendar.MINUTE);
  1726. int sec = c.get(Calendar.SECOND);
  1727. int additionalMinutes = 0;
  1728. if (min <= 10) {
  1729. additionalMinutes = 15 - min + CustomerConstants.DEFAULT_ASAP_TIME_LAG;
  1730. } else if (min <= 25) {
  1731. additionalMinutes = 30 - min + CustomerConstants.DEFAULT_ASAP_TIME_LAG;
  1732. } else if (min <= 40) {
  1733. additionalMinutes = 45 - min + CustomerConstants.DEFAULT_ASAP_TIME_LAG;
  1734. } else if (min <= 55) {
  1735. additionalMinutes = 60 - min + CustomerConstants.DEFAULT_ASAP_TIME_LAG;
  1736. } else if (min <= 60) {
  1737. additionalMinutes = 75 - min + CustomerConstants.DEFAULT_ASAP_TIME_LAG;
  1738. }
  1739.  
  1740. time = time + additionalMinutes * 60 * 1000 - sec * 1000;
  1741.  
  1742. Date today = new Date();
  1743. Date date = new Date(time);
  1744. if (date.getDate() == today.getDate() && date.getMonth() == today.getMonth() && date.getYear() == today.getYear()) {
  1745. isToday = true;
  1746. } else {
  1747. isToday = false;
  1748. }
  1749.  
  1750. return time;
  1751. }
  1752.  
  1753. @Override
  1754. protected void onStart() {
  1755. super.onStart();
  1756.  
  1757. if (!isOnline()) {
  1758. Toast.makeText(this, R.string.toast_no_network_connection, Toast.LENGTH_LONG).show();
  1759. } else {
  1760. boolean networkEnabled = mMyLocationProvider.isNetworkEnabled();
  1761. boolean gpsEnabled = mMyLocationProvider.isGpsEnabled();
  1762.  
  1763. boolean noneEnabled = !networkEnabled && !gpsEnabled;
  1764. boolean allEnabled = networkEnabled && gpsEnabled;
  1765.  
  1766. if (isAskToEnableLocation && !allEnabled) {
  1767. int title = noneEnabled ? R.string.dialog_location_disabled_title
  1768. : R.string.dialog_location_not_all_enabled_title;
  1769. int message = noneEnabled ? R.string.dialog_location_disabled_message
  1770. : R.string.dialog_location_not_all_enabled_message;
  1771. int positive = noneEnabled ? R.string.dialog_location_disabled_positive
  1772. : gpsEnabled ? R.string.dialog_network_disabled_positive
  1773. : R.string.dialog_gps_disabled_positive;
  1774.  
  1775. showLocationDialog(title, message, positive,
  1776. R.string.dialog_location_disabled_negative);
  1777. }
  1778. }
  1779. }
  1780.  
  1781. private void showLocationDialog(int title, int message, int positive, int negative) {
  1782. if (!isDialogShown) {
  1783. AlertDialog.Builder builder = new AlertDialog.Builder(this);
  1784. builder.setTitle(title);
  1785. builder.setMessage(message);
  1786. builder.setNegativeButton(negative, new DialogInterface.OnClickListener() {
  1787. @Override
  1788. public void onClick(DialogInterface dialog, int which) {
  1789. isAskToEnableLocation = false;
  1790. }
  1791. });
  1792. builder.setPositiveButton(positive, new DialogInterface.OnClickListener() {
  1793. @Override
  1794. public void onClick(DialogInterface dialog, int which) {
  1795. mMyLocationProvider.enableLocationSettings(DestinationActivity.this);
  1796. }
  1797. });
  1798.  
  1799. AlertDialog dialog = builder.show();
  1800. dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
  1801. @Override
  1802. public void onDismiss(DialogInterface dialog) {
  1803. isDialogShown = false;
  1804. }
  1805. });
  1806. isDialogShown = true;
  1807. }
  1808. }
  1809.  
  1810. private void addLabel() {
  1811. if (mAddDestLabel.getVisibility() != View.VISIBLE && mDestinationWidgetView.getVisibility() != View.VISIBLE) {
  1812. mAddDestLabel.setVisibility(View.VISIBLE);
  1813. }
  1814. }
  1815.  
  1816. private void removeLabel() {
  1817. isDest = false;
  1818. if (mAddDestLabel.getVisibility() == View.VISIBLE)
  1819. mAddDestLabel.setVisibility(View.GONE);
  1820. if (mDestinationWidgetView.getVisibility() == View.VISIBLE && bookingType.equals(CustomerConstants.HOURLY)) {
  1821. mDestinationWidgetView.setVisibility(View.GONE);
  1822. try {
  1823. setWidgetsActive(true, false);
  1824. } catch (Exception ex) {
  1825. Log.e(TAG, "ex=" + ex.getMessage());
  1826. }
  1827. }
  1828. }
  1829.  
  1830. @Override
  1831. public void onRideNowClicked(ApproximatedFareForType type) {
  1832. int isCabAvailable = bottomBarFragment.isCabAvailableForNow(type);
  1833. if (isCabAvailable == -1) {
  1834. Toast.makeText(getApplicationContext(), R.string.pls_wait, Toast.LENGTH_SHORT).show();
  1835. } else if (isCabAvailable == 0) {
  1836. Toast.makeText(getApplicationContext(), R.string.no_ride_now, Toast.LENGTH_SHORT).show();
  1837. } else {
  1838. selectedType = type;
  1839. if (bookingType.equals(CustomerConstants.POINT_TO_POINT)) {
  1840. addLabel();
  1841. }
  1842. rideNow = true;
  1843. //setSelectedTime(System.currentTimeMillis() + TimeUnit.MINUTES.toMillis(15));
  1844. bottomBarConfirm(System.currentTimeMillis() + TimeUnit.MINUTES.toMillis(15), true);
  1845. }
  1846. }
  1847.  
  1848. @Override
  1849. public void onRideLaterClicked(ApproximatedFareForType type) {
  1850. selectedType = type;
  1851. rideNow = false;
  1852. // addLabel();
  1853. }
  1854.  
  1855. @Override
  1856. public void onCancelClicked() {
  1857. removeLabel();
  1858.  
  1859. if (bookingType.equals(CustomerConstants.HOURLY)) {
  1860. resetBookings();
  1861. mSubmitBtn.setVisibility(View.VISIBLE);
  1862. } else if (bottomBarConfirmFragment != null && bottomBarFragment != null) {
  1863. getSupportFragmentManager()
  1864. .beginTransaction()
  1865. .replace(R.id.bottombar, bottomBarFragment)
  1866. .commitAllowingStateLoss();
  1867. }
  1868. }
  1869.  
  1870. @Override
  1871. public void onEstimFareClicked() {
  1872. if (bookingType.equals(CustomerConstants.POINT_TO_POINT) && mDestinationWidgetView.getVisibility() != View.VISIBLE) {
  1873. mAddDestLabel.callOnClick();
  1874. } else if ((bookingType.equals(CustomerConstants.HOURLY) && !hourlyDestMandatory) || (
  1875. mDestinationWidgetView.getVisibility() == View.VISIBLE && !pickupWidget.getPlace().equals(mDestinationWidgetView.getPlace()))) {
  1876.  
  1877. calcEstimFare(false);
  1878. }
  1879. }
  1880.  
  1881. public static class FareInfoLoader extends RoboAsyncTaskLoader<ApproximatedFareInfo> {
  1882.  
  1883. @Inject
  1884. private OrderManager orderManager;
  1885. private PreOrder preOrder;
  1886. private String onlyFares;
  1887.  
  1888. public FareInfoLoader(Context context, PreOrder preOrder, String onlyFares) {
  1889. super(context);
  1890. this.preOrder = preOrder;
  1891. this.onlyFares = onlyFares;
  1892. }
  1893.  
  1894. @Override
  1895. protected void onStartLoading() {
  1896. super.onStartLoading();
  1897. forceLoad();
  1898. }
  1899.  
  1900. @Override
  1901. public ApproximatedFareInfo loadInBackground() {
  1902. try {
  1903. return orderManager.getApproximatedOrderData(preOrder, onlyFares);
  1904. } catch (Exception e) {
  1905. return null;
  1906. }
  1907. }
  1908. }
  1909.  
  1910. private Order createOrder() {
  1911. Order order = new Order();
  1912. order.setBookingType(bookingType);
  1913. order.setPromoCode(ValidatePromoCodePopup.sPromoCode);//gets promocode that is checked and stored, if it is
  1914.  
  1915. // for setting cab type from rotation wheel
  1916. ArrayList<String> temp = new ArrayList<>();
  1917. if (selectedType != null) {
  1918. temp.add(selectedType.getCategory());
  1919. } else {
  1920. for (ApproximatedFareForType type : approximatedFareInfo.getTypes()) {
  1921. temp.add(type.getCabModel());
  1922. }
  1923. }
  1924. order.setCabTypes(temp);
  1925.  
  1926.  
  1927. if (pickupWidget != null) {
  1928. order.setStartLocation(pickupWidget.getPlace());
  1929. if (bookingType.equals(CustomerConstants.POINT_TO_POINT)) {
  1930. if (mDestinationWidgetView.getVisibility() == View.VISIBLE)
  1931. order.setEndLocation(mDestinationWidgetView.getPlace());
  1932. }
  1933. }
  1934.  
  1935. if (bookingType.equals(CustomerConstants.HOURLY)) {
  1936. if (mSelectedDurationTextView != null) {
  1937. String[] arr = mSelectedDurationTextView.getText().toString().split("/");
  1938. String packageStr = arr[0];
  1939. if (packageStr.equals(CustomerConstants.OUTSTATION) || packageStr.equals(CustomerConstants.OUTSTATION_AR))
  1940. packageStr = CustomerConstants.FULL_DAY;
  1941.  
  1942. for (int i = 0; i < mDurationsList.size(); i++) {
  1943. if (mDurationsList.get(i).contains(packageStr)) {
  1944. packageStr = mDurationsIDList.get(i);
  1945. break;
  1946. }
  1947. }
  1948. order.setPackageType(packageStr);
  1949.  
  1950. if (packageStr.equals(CustomerConstants.FULL_DAY)) {
  1951. String daysStr = null;
  1952. if (mWidgetListBox != null) {
  1953. if (mWidgetListBox.getTextCenter().contains(" DAY")) {
  1954. if (Locale.getDefault().getLanguage().equals("ar")) {
  1955. for (int i = 0; i < daysDurationArabicArray.length; i++) {
  1956. if (mWidgetListBox.getTextCenter().equals(daysDurationArabicArray[i])) {
  1957. daysStr = daysDurationArray[i].split(" ")[0];
  1958. break;
  1959. }
  1960. }
  1961. } else {
  1962. String[] arr2 = mWidgetListBox.getTextCenter().split(" ");
  1963. Log.d(TAG, "arr2=" + mWidgetListBox.getTextCenter());
  1964. daysStr = arr2[0];
  1965. }
  1966. order.setDays(Integer.parseInt(daysStr));
  1967. }
  1968. }
  1969. Log.d(TAG, "days in package=" + daysStr);
  1970. }
  1971. }
  1972. }
  1973.  
  1974. PaymentMethod selectedPm = preferencesStorage.getSelectedCard();
  1975.  
  1976. if (selectedPm != null) {
  1977. order.setCardToken(selectedPm.getToken());
  1978. }
  1979.  
  1980. order.setRequestedPickupTime(selectedTime);
  1981. order.setName(preferencesStorage.getName());
  1982. order.setPhone(preferencesStorage.getPhoneNumber());
  1983. order.setEmailId(preferencesStorage.getEmailID());
  1984. return order;
  1985. }
  1986.  
  1987. private AdapterView.OnItemClickListener durationListListener = new AdapterView.OnItemClickListener() {
  1988. public void onItemClick(AdapterView<?> adapterView, View v, int position, long id) {
  1989. if (current != -1) {
  1990. View last = mDurationListView.getChildAt(current);
  1991. last.findViewById(R.id.topSelectLayout).setBackgroundResource(R.drawable.car_bg_not_selected);
  1992. ((TextView) last.findViewById(R.id.tv_name_selection)).setTextColor(last.getContext().getResources().
  1993. getColor(R.color.color_tv_city_not_selected));
  1994. }
  1995. v.findViewById(R.id.topSelectLayout).setBackgroundResource(R.drawable.car_bg_selected);
  1996. ((TextView) v.findViewById(R.id.tv_name_selection)).setTextColor(v.getContext().getResources().
  1997. getColor(R.color.color_tv_city_selected));
  1998. current = position;
  1999.  
  2000. // if (Locale.getDefault().getLanguage().equals("ar")) {
  2001. // mSelectedDurationTextView.setText(mDurationsArabicList.get(position));
  2002. // } else {
  2003. String selected = mDurationsList.get(position);
  2004. Log.d(TAG, "selected=" + selected);
  2005. mSelectedDurationTextView.setText(selected);
  2006. String[] temp = selected.split("/");
  2007. if (temp[0].equals(CustomerConstants.OUTSTATION) || temp[0].equals(CustomerConstants.OUTSTATION_AR)) {
  2008. mDaysWidgetLayout.startAnimation(Animator.getSingleInstance().getSlideRightIn(context));
  2009. mDaysWidgetLayout.setVisibility(View.VISIBLE);
  2010. isDurationActive = false;
  2011. showDurationWidget(false);
  2012. mWidgetListBox.setTextView(getString(R.string.full_package_days_in_package_select), getString(R.string.full_package_days_in_package), R.drawable.clock_gray);
  2013.  
  2014. if (Locale.getDefault().getLanguage().equals("ar")) {
  2015. mWidgetListBox.setListItems(daysDurationArabicArray);
  2016. } else {
  2017. mWidgetListBox.setListItems(daysDurationArray);
  2018. }
  2019. } else {
  2020. getSupportLoaderManager().restartLoader(0, null, infoLoaderCallbacks);
  2021. }
  2022. mSelectDurationLayout.setVisibility(View.GONE);
  2023. mSelectDurationView.setVisibility(View.GONE);
  2024. }
  2025. };
  2026.  
  2027. @Override
  2028. protected View getStepForwardView() {
  2029. return mSubmitBtn;
  2030. }
  2031.  
  2032. @Override
  2033. protected AddressWidget getPickUpWidget() {
  2034. return pickupWidget;
  2035. }
  2036.  
  2037. @Override
  2038. protected AddressWidget getDestinationWidgetView() {
  2039. return mDestinationWidgetView;
  2040. }
  2041.  
  2042. @Override
  2043. protected MapFragmentWithCenteredMarker getMapFragmentWithCenteredMarker() {
  2044. return mMapFragmentWithCenteredMarker;
  2045. }
  2046.  
  2047. private View.OnClickListener selectDurationClick = new View.OnClickListener() {
  2048. @Override
  2049. public void onClick(View v) {
  2050. if (mDurationsList.size() != 0) {
  2051. isInDurationSelectionMode = !isInDurationSelectionMode;
  2052. if (isInDurationSelectionMode) { //open
  2053. mSelectDurationLayout.setVisibility(View.VISIBLE);
  2054. mSelectDurationView.setVisibility(View.VISIBLE);
  2055. } else {
  2056. mSelectDurationLayout.setVisibility(View.GONE);
  2057. mSelectDurationView.setVisibility(View.GONE);
  2058. }
  2059. isDurationActive = true;
  2060. showDurationWidget(false);
  2061. showTimeWidget(false, false);
  2062. if (mDaysWidgetLayout.getVisibility() == View.VISIBLE) {
  2063. makeDaysInFullPackageInvisible();
  2064. }
  2065. }
  2066. }
  2067. };
  2068.  
  2069. @Override
  2070. public void onUIChanged() {
  2071. if (mChooseTimeLayout.getVisibility() == View.VISIBLE) {
  2072. mChooseTimeLayout.startAnimation(Animator.getSingleInstance().getSlideRightOut(context));
  2073. mChooseTimeLayout.setVisibility(View.GONE);
  2074. }
  2075. }
  2076.  
  2077. private void makeDaysInFullPackageInvisible() {
  2078. mDaysWidgetLayout.setVisibility(View.GONE);
  2079. mWidgetListBox.setActiveState(true); //by default
  2080. mWidgetListBox.closeListBox();
  2081. }
  2082.  
  2083. void preloadStuff(@Nullable String city) {
  2084. final String emptyCity = getString(R.string.manual_select_city);
  2085. if (city != null) {
  2086. Observable.zip(
  2087. cachingPlacesManager.travelPopular(city, emptyCity, CachingPlacesManager.urlForState(ManualSelectAddressActivity.TRAVEL, city))
  2088. .subscribeOn(Schedulers.io()),
  2089. cachingPlacesManager.travelPopular(city, emptyCity, CachingPlacesManager.urlForState(ManualSelectAddressActivity.POPULAR, city))
  2090. .subscribeOn(Schedulers.io()),
  2091. new Func2<FavouritedPlaces, FavouritedPlaces, Object>() {
  2092. @Override
  2093. public Object call(FavouritedPlaces favouritedPlaces,
  2094. FavouritedPlaces favouritedPlaces2) {
  2095. return null;
  2096. }
  2097. })
  2098. .onErrorReturn(new Func1<Throwable, Object>() {
  2099. @Override
  2100. public Object call(Throwable throwable) {
  2101. return null;
  2102. }
  2103. })
  2104. .subscribe();
  2105. }
  2106. }
  2107.  
  2108. private void resetBookings() {
  2109. mDestinationWidgetView.setPlace(null);
  2110. if (mChooseTimeLayout.getVisibility() == View.VISIBLE) {
  2111. mChooseTimeLayout.startAnimation(Animator.getSingleInstance().getSlideRightOut(context));
  2112. mChooseTimeLayout.setVisibility(View.GONE);
  2113. }
  2114. if (mDurationBlocksLayout.getVisibility() == View.VISIBLE) {
  2115. mDurationBlocksLayout.startAnimation(Animator.getSingleInstance().getSlideRightOut(context));
  2116. mDurationBlocksLayout.setVisibility(View.GONE);
  2117. }
  2118. if (mDestinationWidgetView.getVisibility() == View.VISIBLE) {
  2119. mDestinationWidgetView.startAnimation(Animator.getSingleInstance().getSlideRightOut(context));
  2120. mDestinationWidgetView.setVisibility(View.GONE);
  2121. }
  2122. if (mDaysWidgetLayout.getVisibility() == View.VISIBLE) {
  2123. mDaysWidgetLayout.startAnimation(Animator.getSingleInstance().getSlideRightOut(context));
  2124. makeDaysInFullPackageInvisible();
  2125. }
  2126. setWidgetsActive(true, false);
  2127. }
  2128.  
  2129. private void setZoomButtonPosition() {
  2130. View zoomControls = mMapFragmentWithCenteredMarker.getView().findViewById(0x1);
  2131. if (zoomControls != null && zoomControls.getLayoutParams() instanceof RelativeLayout.LayoutParams) {
  2132. // ZoomControl is inside of RelativeLayout
  2133. RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) zoomControls.getLayoutParams();
  2134. // Align it to - parent bottom above Buttons
  2135. //params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, R.id.actionButtonsLayout);
  2136. final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10,
  2137. getResources().getDisplayMetrics());
  2138. final int marginBottom = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 150, getResources().getDisplayMetrics());
  2139. params.setMargins(margin, margin, margin, marginBottom);
  2140. zoomControls.setLayoutParams(params);
  2141. }
  2142. }
  2143.  
  2144. private void simpleCheck() {
  2145. if (TextUtils.isEmpty(previousCountry)) previousCountry = "";
  2146. if (TextUtils.isEmpty(previousCity)) previousCity = "";
  2147. }
  2148.  
  2149. // LoaderManager.LoaderCallbacks<ArrayList<String>> callbackHourlyCountries = new LoaderManager.LoaderCallbacks<ArrayList<String>>() {
  2150. //
  2151. // private boolean isHourlyPackageVisible = false;
  2152. //
  2153. // public Loader<ArrayList<String>> onCreateLoader(int id, Bundle args) {
  2154. // return new GetHourlyCountryList(DestinationActivity.this);
  2155. // }
  2156. //
  2157. // @Override
  2158. // public void onLoadFinished(Loader<ArrayList<String>> loader, ArrayList<String> data) {
  2159. // if (data != null) {
  2160. // ArrayList<String> countries = new ArrayList<String>();
  2161. // countries.addAll(data);
  2162. // String countriesWithHourlyPackages = "";
  2163. // Log.e("reali", "my country " + userCountry);
  2164. // for (String country : countries) {
  2165. // if (country.equals(userCountry)) {
  2166. // isHourlyPackageVisible = true;
  2167. // //break;
  2168. // }
  2169. // countriesWithHourlyPackages += country + ",";
  2170. // }
  2171. // if (userCountry != null && !userCountry.equals("")) { // on Place error or No location found in Address widget - don't go to onUserLocationLoaded
  2172. //// setHourlyPackageVisibility(isHourlyPackageVisible);
  2173. // }
  2174. //
  2175. // saveUserLocationData(countriesWithHourlyPackages);
  2176. // }
  2177. // }
  2178. //
  2179. // @Override
  2180. // public void onLoaderReset(Loader<ArrayList<String>> loader) {
  2181. //
  2182. // }
  2183. // };
  2184.  
  2185. private void setHourlyPackageVisibility(boolean isVisible) {
  2186. if (!isVisible) {
  2187. mHeaderWidgetView.makeSecondInvisibleInDoubleMode();
  2188. }
  2189. }
  2190.  
  2191. private void saveUserLocationData(String countriesWithHourlyPacakages) {
  2192. UserLocationAndHourlyPackages.setUserLocationData(DestinationActivity.this, userCountry, userCity);
  2193. UserLocationAndHourlyPackages.setCountriesWithHourlyPackages(DestinationActivity.this, countriesWithHourlyPacakages);
  2194. }
  2195.  
  2196. public static class GetHourlyCountryList extends RoboAsyncTaskLoader<ArrayList<String>> {
  2197. private ArrayList<String> countries;
  2198. @Inject
  2199. private PlaceListFromServer placeListFromServer;
  2200.  
  2201. public GetHourlyCountryList(Context context) {
  2202. super(context);
  2203. }
  2204.  
  2205. @Override
  2206. protected void onStartLoading() {
  2207. super.onStartLoading();
  2208. forceLoad();
  2209. }
  2210.  
  2211. @Override
  2212. public ArrayList<String> loadInBackground() {
  2213. try {
  2214. countries = placeListFromServer.getHourlyCountries();
  2215. return countries;
  2216. } catch (Exception e) {
  2217. Log.e(getClass().getName(), "Problem during downloading coutries for hourly packages", e);
  2218. return null;
  2219. }
  2220. }
  2221. }
  2222.  
  2223. public boolean isOnline() {
  2224. ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
  2225. return cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isConnectedOrConnecting();
  2226. }
  2227.  
  2228. public boolean isConnectingToInternet(Context ctx) {
  2229. ConnectivityManager connectivity = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
  2230. if (connectivity != null) {
  2231. NetworkInfo[] info = connectivity.getAllNetworkInfo();
  2232. if (info != null)
  2233. for (int i = 0; i < info.length; i++)
  2234. if (info[i].getState() == NetworkInfo.State.CONNECTED) {
  2235. return true;
  2236. }
  2237. }
  2238. return false;
  2239. }
  2240.  
  2241. private void getBookingSettings() {
  2242. new GetBookingSettings(DestinationActivity.this) {
  2243. @Override
  2244. protected void onSuccess(BookingSettings settings) throws Exception {
  2245. super.onSuccess(settings);
  2246. bookingSettings = settings;
  2247. //BookingSettings.bookingSettings = settings;
  2248. TaxiPixiApp app = (TaxiPixiApp) getApplication();
  2249. app.setBookingSettings(settings);
  2250. determineBookingFlow();
  2251. }
  2252. }.execute();
  2253. }
  2254.  
  2255. // private class Receiver extends BroadcastReceiver {
  2256. //
  2257. // @Override
  2258. // public void onReceive(Context context, Intent intent) {
  2259. // if (intent.getAction().equals(CustomerConstants.WEB_POPUP_BROADCAST_ACTION)){
  2260. //
  2261. //// String url = intent.getStringExtra(NotificationDatabaseConnector.URL);
  2262. // Intent i = new Intent(context, WebViewActivityPopup.class);
  2263. // i.putExtra(NotificationDatabaseConnector.URL, loginPrefs.getPopupUrl());
  2264. // i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  2265. // context.startActivity(i);
  2266. // }
  2267. // }
  2268. // }
  2269.  
  2270. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement