Mechele

Untitled

Feb 7th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 57.48 KB | None | 0 0
  1. package com.taxipixi.incarapp.activities;
  2.  
  3. import android.app.AlarmManager;
  4. import android.app.AlertDialog;
  5. import android.app.PendingIntent;
  6. import android.app.ProgressDialog;
  7. import android.content.Context;
  8. import android.content.Intent;
  9. import android.content.SharedPreferences;
  10. import android.content.pm.ActivityInfo;
  11. import android.net.Uri;
  12. import android.os.Bundle;
  13. import android.os.Handler;
  14. import android.os.Message;
  15. import android.preference.PreferenceManager;
  16. import android.text.Html;
  17. import android.util.DisplayMetrics;
  18. import android.util.Log;
  19. import android.view.View;
  20. import android.view.View.OnClickListener;
  21. import android.widget.Button;
  22. import android.widget.EditText;
  23. import android.widget.ImageView;
  24. import android.widget.LinearLayout;
  25. import android.widget.RelativeLayout;
  26. import android.widget.TextView;
  27. import android.widget.Toast;
  28.  
  29. import com.google.android.gms.maps.model.LatLng;
  30. import com.google.inject.Inject;
  31. import com.gpsodometer.LocationService;
  32. import com.gpsodometer.Track;
  33. import com.gpsodometer.Ut;
  34. import com.taxipixi.entity.Order;
  35. import com.taxipixi.entity.Promotion;
  36. import com.taxipixi.fare.ApproximatedFareForType;
  37. import com.taxipixi.fare.ApproximatedFareInfo;
  38. import com.taxipixi.incarapp.Constants;
  39. import com.taxipixi.incarapp.LoginPreferences;
  40. import com.taxipixi.incarapp.R;
  41. import com.taxipixi.incarapp.api.SystemTime;
  42. import com.taxipixi.incarapp.api2.Api;
  43. import com.taxipixi.incarapp.application.IncarApp;
  44. import com.taxipixi.incarapp.async.NetworkSubscriber;
  45. import com.taxipixi.incarapp.db.CachedFinishedOrdersDB;
  46. import com.taxipixi.incarapp.fare.JourneyInfoFromOrderExtractor;
  47. import com.taxipixi.incarapp.models.OrderFinish;
  48. import com.taxipixi.incarapp.orders.DriverOrderManager;
  49. import com.taxipixi.incarapp.orders.EndJourney;
  50. import com.taxipixi.utils.DecimalFormating;
  51. import com.taxipixi.utils.ProgressDialogFactory;
  52. import com.taxipixi.widget.ToastFactory;
  53.  
  54. import org.json.JSONArray;
  55. import org.json.JSONException;
  56. import org.json.JSONObject;
  57.  
  58. import java.io.IOException;
  59. import java.lang.ref.WeakReference;
  60. import java.math.BigDecimal;
  61. import java.util.Calendar;
  62. import java.util.List;
  63. import java.util.Locale;
  64.  
  65. import roboguice.util.RoboAsyncTask;
  66. import rx.Subscriber;
  67.  
  68. import static com.taxipixi.utils.ObservableUtils.applyComputeSchedulers;
  69.  
  70. public class DriverMeterActivity extends IncarBaseActivity {
  71. private static final String TAG = DriverMeterActivity.class.getSimpleName();
  72. @Inject
  73. private LoginPreferences loginPrefs;
  74. @Inject
  75. private Api api;
  76.  
  77. private Order orderRequest;
  78. private ApproximatedFareForType cabCategoryFareType;
  79.  
  80. private TextView tv_fare_value, tv_total_time_value, tv_wait_time_value, tv_dist;
  81. private Button btn_play_pause_total;
  82. private ImageView btn_play_pause_wait, img_distance_travelled, img_wait_time, img_total_time, img_fare;
  83. private Button btn_reset_total;
  84. private Button btn_locked;
  85. private Button btn_end_journey;
  86. private Button btn_phone;
  87. private Button btn_currency;
  88. private Button btn_map;
  89. private ImageView btn_reset_wait;
  90. private RelativeLayout rl_fare, rl_wait_time, rl_space;
  91.  
  92. private UITimer timer;
  93.  
  94. private boolean locked = true;
  95. private long timeUnlocked = 0;
  96. private IncarApp app;
  97.  
  98. private ApproximatedFareInfo afi;
  99. private ApproximatedFareForType fareInfoForType;
  100.  
  101. public static final int REQUEST_CONFIRMATION = 0;
  102. public static final int REQUEST_CREDIT_AMT = 3;
  103. public static final int REQUEST_INFO_END_JOURNEY = 1;
  104. private static final int REQUEST_INFO = 2;
  105.  
  106. private BigDecimal perKmCost;
  107. private double fare, f_baseFare, f_distanceFare, f_waitTimeFare, f_hireTimeFare, f_bookingFeesFare, f_discountFare, f_packageFare, f_discountOffered;
  108. private float dayDistance;
  109. private float nightDistance;
  110. private String distance;
  111. private int day_night_start = 0; //0 = day start, 1 = night start
  112.  
  113. private double initialFare, promoInitalFare;
  114. private double minFare;
  115. private double minDistance;
  116.  
  117. double dayDistanceFare = 0;
  118. double nightDistanceFare = 0;
  119. boolean isEnglish = true;
  120.  
  121. Promotion promo = null;
  122.  
  123. public static EndJourney endJourney;
  124. public static long orderId;
  125.  
  126. private OrderFinish orderFinish;
  127.  
  128. AlertDialog alertDialog;
  129. private double topay, remaining;
  130.  
  131. private BigDecimal parking;
  132. private BigDecimal tolls;
  133.  
  134. private AlertDialog tripSummaryDialog;
  135. private AlertDialog extrasDialog;
  136. private ProgressDialog progressDialog;
  137.  
  138. @Override
  139. protected void onCreate(Bundle savedInstanceState) {
  140.  
  141. super.onCreate(savedInstanceState);
  142. setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
  143.  
  144. setContentView(R.layout.activity_driver_meter);
  145.  
  146.  
  147. if (android.os.Build.VERSION.SDK_INT >= 11)
  148. if (getActionBar() != null) getActionBar().hide();
  149.  
  150. app = ((IncarApp) getApplication());
  151. isEnglish = app.getCabType().isEnglish();
  152.  
  153. Bundle b = getIntent().getExtras();
  154. if (b != null) {
  155. orderRequest = (Order) b.get(Constants.EXTRA_ORDER);
  156. }
  157.  
  158. if (savedInstanceState != null) {
  159. orderRequest = savedInstanceState.getParcelable("order");
  160. }
  161.  
  162. if (orderRequest == null) {
  163. int menu_option = Integer.parseInt(loginPrefs.getMenuOption());
  164. goToMenuScreen(menu_option);
  165. return;
  166. }
  167.  
  168. String selId = getApp().prefsSmall.getString("selectedTrack", "");
  169. String newId = "track" + orderRequest.getOrderId();
  170.  
  171. new MeteredJourneyTask(this, orderRequest.getOrderId()).execute();
  172.  
  173. if (!Track.isTrackExist(getApp(), newId)) { //if not exist
  174. newId = Track.generateId(getApp(), orderRequest.getOrderId()); //create track
  175. // Log.e("reali", "Create new track " + newId);
  176. Track.startTracking(getApp(), newId); //start tracking
  177. } else {
  178. Track.startTracking(getApp(), newId); //start tracking
  179. }
  180.  
  181. if (!newId.equals(selId)) {
  182. app.prefsSmall.edit().putString("selectedTrack", newId).commit();
  183. }
  184.  
  185. initializeUI();
  186. endReminderAlarm(orderRequest.getOrderId());
  187.  
  188. }
  189.  
  190. private void showTripSummaryPopup() {
  191. final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
  192.  
  193. View dialogView = getLayoutInflater().inflate(R.layout.dialog_trip_summary, null);
  194. dialogBuilder.setView(dialogView);
  195.  
  196. TextView distanceValue = (TextView) dialogView.findViewById(R.id.trip_distance_value);
  197. distanceValue.setText(distance);
  198.  
  199. TextView timeValue = (TextView) dialogView.findViewById(R.id.trip_time_value);
  200. String selId = getApp().prefsSmall.getString("selectedTrack", "");
  201. timeValue.setText(Track.getTimeElapsedStr(getApp(), selId));
  202.  
  203. View tripExtras = dialogView.findViewById(R.id.trip_extras);
  204. tripExtras.setOnClickListener(view -> showAddExtrasPopup());
  205.  
  206. View charge = dialogView.findViewById(R.id.charge);
  207. charge.setOnClickListener(view -> {
  208. double parkingValue = parking != null ? parking.doubleValue() : 0f;
  209. double tollsValue = tolls != null ? tolls.doubleValue() : 0f;
  210. startEndJourneyButtonClicked(false, 0f, 0f, parkingValue, tollsValue);
  211. tripSummaryDialog.dismiss();
  212. });
  213.  
  214. ImageView close = (ImageView) dialogView.findViewById(R.id.trip_summary_close);
  215. close.setOnClickListener(view -> tripSummaryDialog.dismiss());
  216.  
  217. dialogBuilder.setCancelable(false);
  218.  
  219. tripSummaryDialog = dialogBuilder.create();
  220. tripSummaryDialog.show();
  221. }
  222.  
  223. private void showAddExtrasPopup() {
  224. final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
  225.  
  226. View dialogView = getLayoutInflater().inflate(R.layout.dialog_add_extras, null);
  227. dialogBuilder.setView(dialogView);
  228.  
  229. EditText tolls = (EditText) dialogView.findViewById(R.id.tolls);
  230. tolls.setText(DecimalFormating.getStringFormatted(this.tolls));
  231.  
  232. EditText parking = (EditText) dialogView.findViewById(R.id.parking);
  233. parking.setText(DecimalFormating.getStringFormatted(this.parking));
  234.  
  235. ImageView close = (ImageView) dialogView.findViewById(R.id.add_extras_close);
  236. close.setOnClickListener(view -> extrasDialog.dismiss());
  237.  
  238. Button back = (Button) dialogView.findViewById(R.id.extras_back);
  239. back.setOnClickListener(view -> extrasDialog.dismiss());
  240.  
  241. Button save = (Button) dialogView.findViewById(R.id.extras_save);
  242. save.setOnClickListener(view -> {
  243. double tollsValue = DecimalFormating.parseDouble(tolls.getText().toString());
  244. double parkingValue = DecimalFormating.parseDouble(parking.getText().toString());
  245. saveExtras(tollsValue, parkingValue);
  246. extrasDialog.dismiss();
  247. });
  248.  
  249. dialogBuilder.setCancelable(false);
  250.  
  251. extrasDialog = dialogBuilder.create();
  252. extrasDialog.show();
  253. }
  254.  
  255. private void saveExtras(double tolls, double parking) {
  256. this.tolls = new BigDecimal(tolls);
  257. this.parking = new BigDecimal(parking);
  258. }
  259.  
  260. private void showProgressBar() {
  261. if (progressDialog == null) {
  262. progressDialog = ProgressDialogFactory.show(this,
  263. getString(com.taxipixi.R.string.progress_dialog_title),
  264. getString(com.taxipixi.R.string.progress_dialog_body));
  265. } else {
  266. progressDialog.show();
  267. }
  268. }
  269.  
  270. private void hideProgressBar() {
  271. if (progressDialog != null) {
  272. progressDialog.dismiss();
  273. }
  274. }
  275.  
  276. private void endReminderAlarm(long orderId) {
  277. try {
  278. Intent cancelIntent = new Intent("OrderReminder");
  279. cancelIntent.putExtra("orderReminder", true);
  280. AlarmManager alarmManager = (AlarmManager) getBaseContext().getSystemService(Context.ALARM_SERVICE);
  281. PendingIntent cancelPendingIntent = PendingIntent.getBroadcast(getBaseContext().getApplicationContext(), (int) orderId, cancelIntent, PendingIntent.FLAG_UPDATE_CURRENT);
  282. alarmManager.cancel(cancelPendingIntent);
  283.  
  284. } catch (Exception ex) {
  285. Log.d("CancelOrderHandler", "Error removing reminder alarm");
  286. }
  287. }
  288.  
  289. @Override
  290. public void onSaveInstanceState(Bundle savedInstanceState) {
  291. super.onSaveInstanceState(savedInstanceState);
  292. savedInstanceState.putParcelable("Order", orderRequest);
  293. }
  294.  
  295. public void initializeUI() {
  296.  
  297. tv_dist = (TextView) findViewById(R.id.tv_distance_travelled_value);
  298.  
  299. tv_fare_value = (TextView) findViewById(R.id.tv_fare_value);
  300.  
  301. tv_total_time_value = (TextView) findViewById(R.id.tv_total_time_value);
  302. tv_wait_time_value = (TextView) findViewById(R.id.tv_wait_time_value);
  303. btn_play_pause_total = (Button) findViewById(R.id.btn_play_pause_total);
  304. btn_reset_total = (Button) findViewById(R.id.btn_reset_total);
  305. btn_play_pause_wait = (ImageView) findViewById(R.id.btn_play_pause_wait);
  306. btn_reset_wait = (ImageView) findViewById(R.id.btn_reset_wait);
  307. btn_end_journey = (Button) findViewById(R.id.btn_start_end_journey);
  308.  
  309. btn_phone = (Button) findViewById(R.id.btn_phone);
  310. btn_currency = (Button) findViewById(R.id.btn_currency);
  311. btn_map = (Button) findViewById(R.id.btn_map);
  312.  
  313. btn_locked = (Button) findViewById(R.id.btn_locked);
  314. btn_locked.setBackgroundResource(R.drawable.btn_locked);
  315.  
  316. rl_fare = (RelativeLayout) findViewById(R.id.rl_fare);
  317. rl_wait_time = (RelativeLayout) findViewById(R.id.rl_wait_time);
  318. rl_space = (RelativeLayout) findViewById(R.id.rl_space);
  319.  
  320. int density = getResources().getDisplayMetrics().densityDpi;
  321. if (density == DisplayMetrics.DENSITY_LOW) {
  322. img_distance_travelled = (ImageView) findViewById(R.id.img_distance_travelled);
  323. img_distance_travelled.setVisibility(View.GONE);
  324.  
  325. img_wait_time = (ImageView) findViewById(R.id.img_wait_time);
  326. img_wait_time.setVisibility(View.GONE);
  327.  
  328. img_total_time = (ImageView) findViewById(R.id.img_total_time);
  329. img_total_time.setVisibility(View.GONE);
  330.  
  331. img_fare = (ImageView) findViewById(R.id.img_fare);
  332. img_fare.setVisibility(View.GONE);
  333. }
  334.  
  335. if (!isEnglish) {
  336. btn_end_journey.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
  337. btn_end_journey.setBackgroundResource(R.drawable.end_journey);
  338. btn_end_journey.setText("");
  339. }
  340.  
  341. btn_play_pause_total.setOnClickListener(playPauseTotalClicked);
  342. btn_reset_total.setOnClickListener(resetTotalClicked);
  343. btn_locked.setOnClickListener(lockedClicked);
  344. btn_play_pause_wait.setOnClickListener(playPauseWaitClicked);
  345. btn_reset_wait.setOnClickListener(resetWaitClicked);
  346.  
  347. btn_end_journey.setOnClickListener(view -> showTripSummaryPopup());
  348. btn_phone.setOnClickListener(phoneClicked);
  349. btn_currency.setOnClickListener(currencyClicked);
  350. btn_map.setOnClickListener(mapClicked);
  351.  
  352.  
  353. btn_phone.setText(orderRequest.getPhone());
  354.  
  355. btn_reset_total.setVisibility(View.GONE);
  356. btn_play_pause_total.setVisibility(View.GONE);
  357. btn_play_pause_wait.setVisibility(View.GONE);
  358. btn_reset_wait.setVisibility(View.GONE);
  359.  
  360. enableDisableBottomButtons(false);
  361.  
  362. updateDistanceAndDisplacement();
  363. }
  364.  
  365. private void enableDisableBottomButtons(boolean enabled) {
  366. if (enabled) {
  367. btn_end_journey.setVisibility(View.VISIBLE);
  368. btn_phone.setVisibility(View.VISIBLE);
  369. } else {
  370. btn_end_journey.setVisibility(View.GONE);
  371. btn_phone.setVisibility(View.GONE);
  372. }
  373. }
  374.  
  375. private void setFareInformation(ApproximatedFareForType fareType) {
  376.  
  377. enableDisableBottomButtons(true);
  378.  
  379. cabCategoryFareType = fareType;
  380.  
  381. afi = orderRequest.getApproximatedFareInfo();
  382. fareInfoForType = afi.getFareInfoForType(JourneyInfoFromOrderExtractor.getAllowedPriceType(orderRequest, getApp().getCabType().getCategory()));
  383.  
  384. long networkTS = SystemTime.getSystemTime();
  385.  
  386. Calendar calendar = Calendar.getInstance();
  387. calendar.setTimeInMillis(networkTS);
  388.  
  389.  
  390. if (fareInfoForType.getPromotion() != null) {
  391. promo = fareInfoForType.getPromotion();
  392. }
  393.  
  394. if (calendar.get(Calendar.HOUR_OF_DAY) >= fareType.getDayStartHr() && calendar.get(Calendar.HOUR_OF_DAY) < fareType.getNightStartHr()) {
  395. initialFare = fareType.getInitialFeeDay().doubleValue();
  396. minFare = fareType.getMinFareDay().doubleValue();
  397. perKmCost = fareInfoForType.getPerKmCostDay();
  398.  
  399. if (promo != null && promo.getPromoPerKmDay() > 0) {
  400. perKmCost = new BigDecimal(promo.getPromoPerKmDay());
  401. promoInitalFare = promo.getPromoInitialDay();
  402. }
  403.  
  404. day_night_start = 0;
  405.  
  406. } else {
  407. initialFare = fareType.getInitialFeeNight().doubleValue();
  408. minFare = fareType.getMinFareNight().doubleValue();
  409. perKmCost = fareInfoForType.getPerKmCostNight();
  410.  
  411. if (promo != null && promo.getPromoPerKmNight() > 0) {
  412. perKmCost = new BigDecimal(promo.getPromoPerKmNight());
  413. promoInitalFare = promo.getPromoInitialNight();
  414. }
  415.  
  416. day_night_start = 1;
  417. }
  418.  
  419. minDistance = fareType.getMinimum();
  420.  
  421. if (fareType.getShowMeterFare() == 1) {
  422. rl_fare.setVisibility(View.VISIBLE);
  423. } else {
  424. rl_fare.setVisibility(View.GONE);
  425. rl_space.setVisibility(View.GONE);
  426. LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(
  427. LinearLayout.LayoutParams.MATCH_PARENT,
  428. LinearLayout.LayoutParams.MATCH_PARENT, 2.0f);
  429. rl_wait_time.setLayoutParams(param);
  430. }
  431.  
  432. if (orderRequest.getBookingType().equals(com.taxipixi.Constants.HOURLY) || (fareType.getHireTimeFareDay() != null && fareType.getHireTimeFareDay().doubleValue() > 0)) {
  433. rl_wait_time.setVisibility(View.GONE);
  434. rl_space.setVisibility(View.GONE);
  435. LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(
  436. LinearLayout.LayoutParams.MATCH_PARENT,
  437. LinearLayout.LayoutParams.MATCH_PARENT, 2.0f);
  438. rl_fare.setLayoutParams(param);
  439. } else {
  440. rl_space.setVisibility(View.VISIBLE);
  441. rl_wait_time.setVisibility(View.VISIBLE);
  442. }
  443.  
  444. }
  445.  
  446. public void updateDistanceAndDisplacement() {
  447. String selId = getApp().prefsSmall.getString("selectedTrack", "");
  448.  
  449. distance = Track.getLongUnitDistance(getApp(), selId);
  450.  
  451. if (tv_dist != null)
  452. tv_dist.setText(Html.fromHtml("<b>" + distance + "</b>"));
  453.  
  454. }
  455.  
  456. public void updateFare(boolean calculatePromoFare) {
  457. if (cabCategoryFareType != null) {
  458. if (orderRequest.getBookingType().equals(com.taxipixi.Constants.POINT_TO_POINT)) {
  459. if (!calculatePromoFare)
  460. fare = getP2PFare(calculatePromoFare);
  461. else
  462. f_discountFare = getP2PFare(calculatePromoFare);
  463. } else {
  464. if (!calculatePromoFare)
  465. fare = getHourlyFare(calculatePromoFare);
  466. else
  467. f_discountFare = getHourlyFare(calculatePromoFare);
  468. }
  469.  
  470. // Log.e("reali", "f_discountFare " + f_discountFare);
  471.  
  472. if (f_discountFare > 0 && calculatePromoFare) {
  473. if (promo != null && promo.isFixedDiscountPromo())
  474. f_discountFare = f_discountFare - promo.getFixedDiscount();
  475. else if (promo != null && promo.isPercentDiscountPromo())
  476. f_discountFare = f_discountFare - (f_discountFare * (promo.getPercentDiscount() / 100));
  477. else if (promo != null && promo.isFeeDiscountPromo())
  478. f_discountFare = f_discountFare - promo.getFeeDiscount();
  479.  
  480. if (f_discountFare < 0)
  481. f_discountFare = 0;
  482. else
  483. f_discountFare = (Math.round(f_discountFare * 100)) / 100f;
  484.  
  485. // Log.e("reali", "f_disc0untFare " + f_discountFare);
  486. }
  487. if (!calculatePromoFare)
  488. tv_fare_value.setText(cabCategoryFareType.getCurrency() + " " + DecimalFormating.getStringFormatted(fare));
  489. } else {
  490. tv_fare_value.setText("-");
  491. }
  492.  
  493. }
  494.  
  495. private double getP2PFare(boolean calculatePromoFare) {
  496. String selId = getApp().prefsSmall.getString("selectedTrack", "");
  497.  
  498. dayDistance = Track.getLongUnitDistanceFloat(getApp(), selId, 1);
  499. nightDistance = Track.getLongUnitDistanceFloat(getApp(), selId, 2);
  500. float totalDistance = (Math.round(Track.getLongUnitDistanceFloat(getApp(), selId, 0) * 100)) / 100f;
  501.  
  502. dayDistance = (Math.round(dayDistance * 100)) / 100f;
  503. nightDistance = (Math.round(nightDistance * 100)) / 100f;
  504.  
  505. dayDistance = totalDistance - nightDistance;
  506.  
  507. double tripFare = 0;
  508. if (cabCategoryFareType != null) {
  509. /* Start Distance based pricing */
  510. double fixedFare = getFixedFare();
  511. if (fixedFare > -1) {
  512. f_distanceFare = fixedFare;
  513. tripFare = fixedFare;
  514. } else if (dayDistance + nightDistance <= minDistance) {
  515. if (!calculatePromoFare || promo == null || !promo.isCabCategoryPromo()) {
  516. tripFare = initialFare;
  517. f_distanceFare = initialFare;
  518. } else
  519. tripFare = promoInitalFare;
  520. } else {
  521. fareInfoForType = afi.getFareInfoForType(JourneyInfoFromOrderExtractor.getAllowedPriceType(orderRequest, getApp().getCabType().getCategory()));
  522.  
  523. double minDistanceFare = initialFare;
  524. dayDistanceFare = 0;
  525. nightDistanceFare = 0;
  526. int distance_unit = cabCategoryFareType.getSubsequentDistUnit().contains("KM") ? 1 : 10;
  527. if (day_night_start == 0) {
  528. float newDayDistance = dayDistance - (float) minDistance;
  529. if (newDayDistance < 0) {
  530. float newNightDistance = nightDistance + newDayDistance;
  531. if (!calculatePromoFare || promo == null || !promo.isCabCategoryPromo())
  532. nightDistanceFare = newNightDistance * fareInfoForType.getPerKmCostNight().doubleValue() * distance_unit;
  533. else
  534. nightDistanceFare = newNightDistance * fareInfoForType.getPromotion().getPromoPerKmNight() * distance_unit;
  535.  
  536. } else {
  537. if (!calculatePromoFare || promo == null || !promo.isCabCategoryPromo()) {
  538. dayDistanceFare = newDayDistance * fareInfoForType.getPerKmCostDay().doubleValue() * distance_unit;
  539. nightDistanceFare = nightDistance * fareInfoForType.getPerKmCostNight().doubleValue() * distance_unit;
  540. } else {
  541. dayDistanceFare = newDayDistance * fareInfoForType.getPromotion().getPromoPerKmDay() * distance_unit;
  542. nightDistanceFare = nightDistance * fareInfoForType.getPromotion().getPromoPerKmNight() * distance_unit;
  543. }
  544. }
  545.  
  546. } else {
  547. float newNightDistance = nightDistance - (float) minDistance;
  548. if (newNightDistance < 0) {
  549. float newDayDistance = dayDistance + newNightDistance;
  550. if (!calculatePromoFare || promo == null || !promo.isCabCategoryPromo())
  551. dayDistanceFare = newDayDistance * fareInfoForType.getPerKmCostDay().doubleValue() * distance_unit;
  552. else
  553. dayDistanceFare = newDayDistance * fareInfoForType.getPromotion().getPromoPerKmDay() * distance_unit;
  554.  
  555. } else {
  556. if (!calculatePromoFare || promo == null || !promo.isCabCategoryPromo()) {
  557. nightDistanceFare = newNightDistance * fareInfoForType.getPerKmCostNight().doubleValue() * distance_unit;
  558. dayDistanceFare = dayDistance * fareInfoForType.getPerKmCostDay().doubleValue() * distance_unit;
  559. } else {
  560. nightDistanceFare = newNightDistance * fareInfoForType.getPromotion().getPromoPerKmNight() * distance_unit;
  561. dayDistanceFare = dayDistance * fareInfoForType.getPromotion().getPromoPerKmDay() * distance_unit;
  562. }
  563. }
  564.  
  565. }
  566.  
  567. if (minDistance == 0)
  568. f_baseFare = minDistanceFare;
  569. else
  570. f_baseFare = 0;
  571.  
  572. tripFare = minDistanceFare + dayDistanceFare + nightDistanceFare;
  573.  
  574. if (!calculatePromoFare && minDistance == 0)
  575. f_distanceFare = dayDistanceFare + nightDistanceFare;
  576. else if (!calculatePromoFare)
  577. f_distanceFare = minDistanceFare + dayDistanceFare + nightDistanceFare;
  578.  
  579. Log.d("@meter:fare", tripFare + ": " + " DD:" + dayDistance + " ND:" + nightDistance + " Dist:" + distance + " DF:" + dayDistanceFare + " NF:" + nightDistanceFare);
  580. }
  581.  
  582. /* End Distance based pricing */
  583. double waitTimeFare = getP2PWaitTimeFare();
  584. f_waitTimeFare = waitTimeFare;
  585.  
  586. tripFare = tripFare + waitTimeFare;
  587. /* Start Wait Time based pricing */
  588.  
  589. /* Run Time Fare */
  590. double hireTimeFare = getHireTimeFare();
  591. f_hireTimeFare = hireTimeFare;
  592.  
  593. tripFare = tripFare + hireTimeFare;
  594.  
  595. if (tripFare < minFare) {
  596. tripFare = minFare;
  597. f_hireTimeFare = 0;
  598.  
  599. if (!calculatePromoFare)
  600. f_distanceFare = minFare - f_baseFare;
  601. }
  602.  
  603. /* Start Fee based pricing */
  604. int add_fee = cabCategoryFareType.getFeeInclInitialFee() == 1 ? 0 : 1;
  605. f_bookingFeesFare = cabCategoryFareType.getFee().doubleValue() * add_fee;
  606. tripFare = tripFare + f_bookingFeesFare;
  607.  
  608. /* End Fee based pricing */
  609. return tripFare;
  610. }
  611.  
  612. return 0;
  613. }
  614.  
  615. private double getFixedFare() {
  616. double fixedFare = -1;
  617. fareInfoForType = afi.getFareInfoForType(JourneyInfoFromOrderExtractor.getAllowedPriceType(orderRequest, getApp().getCabType().getCategory()));
  618. if (fareInfoForType != null && fareInfoForType.isFixedFare()) {
  619. Calendar calendar = Calendar.getInstance();
  620. calendar.setTimeInMillis(orderRequest.getRequestedPickupTime() * 1000);
  621. if (calendar.get(Calendar.HOUR_OF_DAY) >= fareInfoForType.getDayStartHr() && calendar.get(Calendar.HOUR_OF_DAY) < fareInfoForType.getNightStartHr()) {
  622. fixedFare = fareInfoForType.getApproxCostDay().doubleValue();
  623. } else {
  624. fixedFare = fareInfoForType.getApproxCostNight().doubleValue();
  625. }
  626.  
  627. }
  628. return fixedFare;
  629. }
  630.  
  631. private double getHourlyFare(boolean calculatePromoFare) {
  632. fareInfoForType = afi.getFareInfoForType(JourneyInfoFromOrderExtractor.getAllowedPriceType(orderRequest, getApp().getCabType().getCategory()));
  633. if (fareInfoForType != null) {
  634. Calendar calendar = Calendar.getInstance();
  635. calendar.setTimeInMillis(orderRequest.getRequestedPickupTime() * 1000);
  636.  
  637. double hourlyTripFare = 0;
  638. int distance_unit = cabCategoryFareType.getSubsequentDistUnit().contains("KM") ? 1 : 10;
  639. if (calendar.get(Calendar.HOUR_OF_DAY) >= fareInfoForType.getDayStartHr() && calendar.get(Calendar.HOUR_OF_DAY) < fareInfoForType.getNightStartHr()) {
  640. hourlyTripFare = fareInfoForType.getApproxCostDay().doubleValue();
  641. } else {
  642. hourlyTripFare = fareInfoForType.getApproxCostNight().doubleValue();
  643. }
  644.  
  645. f_packageFare = hourlyTripFare;
  646.  
  647. double additionalDistFare = 0;
  648.  
  649. String selId = getApp().prefsSmall.getString("selectedTrack", "");
  650. dayDistance = (Math.round(Track.getLongUnitDistanceFloat(getApp(), selId, 1) * 100)) / 100f;
  651. nightDistance = (Math.round(Track.getLongUnitDistanceFloat(getApp(), selId, 2) * 100)) / 100f;
  652.  
  653. if (dayDistance + nightDistance > orderRequest.getDistanceEstimatedKilometers()) {
  654. float newDayDistance = dayDistance + nightDistance - (float) minDistance;
  655. if (!calculatePromoFare || promo == null || !promo.isCabCategoryPromo()) {
  656. additionalDistFare = newDayDistance * fareInfoForType.getPerKmCostDay().doubleValue() * distance_unit;
  657. } else {
  658. additionalDistFare = newDayDistance * fareInfoForType.getPromotion().getPromoPerKmDay() * distance_unit;
  659. }
  660. if (!calculatePromoFare)
  661. f_distanceFare = additionalDistFare;
  662.  
  663. hourlyTripFare = hourlyTripFare + additionalDistFare;
  664. }
  665.  
  666. double additionalTimeFare = 0;
  667.  
  668. long totalTime = Track.getTimeElapsedLong(getApp(), selId);
  669.  
  670. String packageType = orderRequest.getPackageType();
  671. long allowedTime = 2 * 60 * 60 * 1000; //2 hours
  672.  
  673. if (packageType.contains("4"))
  674. allowedTime = 4 * 60 * 60 * 1000; //4 hours
  675. else if (packageType.contains("8"))
  676. allowedTime = 8 * 60 * 60 * 1000; //8 hours
  677. else if (packageType.contains("OUT") || packageType.contains("FULL")) {
  678. int days = orderRequest.getDays();
  679. allowedTime = days * 24 * 60 * 60 * 1000;
  680. }
  681. if (totalTime > allowedTime) {
  682. additionalTimeFare = (totalTime - allowedTime) / 1000 / 60 * cabCategoryFareType.getWaitTimeFare().doubleValue() / 60;
  683. f_hireTimeFare = additionalTimeFare;
  684. }
  685.  
  686. hourlyTripFare = hourlyTripFare + additionalTimeFare;
  687.  
  688. return hourlyTripFare;
  689.  
  690. }
  691. return 0;
  692. }
  693.  
  694. private double getHireTimeFare() {
  695. String selId = getApp().prefsSmall.getString("selectedTrack", "");
  696.  
  697. long totalTime = Track.getTimeElapsedLong(getApp(), selId);
  698. double hireTimeFare = 0;
  699.  
  700. if (totalTime > 0 && fareInfoForType.getHireTimeFareDay() != null && fareInfoForType.getHireTimeFareDay().doubleValue() > 0) {
  701. hireTimeFare = totalTime / 1000 / 60 * fareInfoForType.getHireTimeFareDay().doubleValue();
  702. }
  703.  
  704. hireTimeFare = (Math.round(hireTimeFare * 100)) / 100f;
  705. return hireTimeFare;
  706. }
  707.  
  708. private double getP2PWaitTimeFare() {
  709. String selId = getApp().prefsSmall.getString("selectedTrack", "");
  710.  
  711. long waitTime = Track.getWaitTimeElapsedLong(getApp(), selId);
  712. double waitTimeFare = 0;
  713. if (cabCategoryFareType.getWaitTimeInitialFare() != null && cabCategoryFareType.getWaitTimeInitialFare().doubleValue() > 0) {
  714. String unit = cabCategoryFareType.getWaitTimeInitialUnit();
  715. long waitTimeInitialUnitBased = 0;
  716. if (unit.contains("SEC")) {
  717. waitTimeInitialUnitBased = waitTime / 1000;
  718. waitTime = waitTime - cabCategoryFareType.getWaitTimeInitialMinutes() * 1000;
  719. } else if (unit.contains("MIN")) {
  720. waitTimeInitialUnitBased = waitTime / 1000 / 60;
  721. waitTime = waitTime - cabCategoryFareType.getWaitTimeInitialMinutes() * 1000 * 60;
  722. } else if (unit.contains("HOU")) {
  723. waitTimeInitialUnitBased = waitTime / 1000 / 60 / 60;
  724. waitTime = waitTime - cabCategoryFareType.getWaitTimeInitialMinutes() * 1000 * 60 * 60;
  725. }
  726.  
  727. waitTimeFare = cabCategoryFareType.getWaitTimeInitialFare().doubleValue();
  728.  
  729. if (waitTimeInitialUnitBased < cabCategoryFareType.getWaitTimeInitialMinutes()) {
  730. waitTime = 0;
  731. }
  732.  
  733. }
  734.  
  735. if (waitTime > 0 && cabCategoryFareType.getWaitTimeFare().doubleValue() > 0) {
  736. String unit = cabCategoryFareType.getWaitTimeUnit();
  737. long waitTimeUnitBased = 0;
  738. if (unit.contains("SEC")) {
  739. waitTimeUnitBased = waitTime / 1000;
  740. } else if (unit.contains("MIN")) {
  741. waitTimeUnitBased = waitTime / 1000 / 60;
  742. } else if (unit.contains("HOU")) {
  743. waitTimeUnitBased = waitTime / 1000 / 60 / 60;
  744. }
  745.  
  746. waitTimeFare = waitTimeFare + waitTimeUnitBased * cabCategoryFareType.getWaitTimeFare().doubleValue() / cabCategoryFareType.getWaitTimeMinutes();
  747. }
  748. /* End Wait based pricing */
  749. waitTimeFare = (Math.round(waitTimeFare * 100)) / 100f;
  750.  
  751. return waitTimeFare;
  752.  
  753. }
  754.  
  755. public void updateTimer() {
  756. String selId = getApp().prefsSmall.getString("selectedTrack", "");
  757. if (tv_total_time_value != null) {
  758. tv_total_time_value.setText(Track.getTimeElapsedStr(getApp(), selId));
  759. }
  760. }
  761.  
  762. public void updateWaitTimer() {
  763. String selId = getApp().prefsSmall.getString("selectedTrack", "");
  764.  
  765. if (!Track.getIsWaitTracking(getApp(), selId)) {
  766. return;
  767. }
  768.  
  769. if (tv_wait_time_value != null) {
  770. tv_wait_time_value.setText(Track.getWaitTimeElapsedStr(getApp(), selId));
  771. }
  772. }
  773.  
  774. public void update() {
  775.  
  776. if (!locked && SystemTime.getSystemTime() - timeUnlocked > 7000) {
  777. locked = true;
  778. btn_locked.setBackgroundResource(R.drawable.btn_locked);
  779. lockedSetting();
  780. }
  781.  
  782. }
  783.  
  784. private void lockedSetting() {
  785. btn_reset_total.setVisibility(View.GONE);
  786. btn_play_pause_total.setVisibility(View.GONE);
  787. btn_play_pause_wait.setVisibility(View.GONE);
  788. btn_reset_wait.setVisibility(View.GONE);
  789.  
  790. btn_locked.setBackgroundResource(R.drawable.btn_locked);
  791.  
  792. }
  793.  
  794. private void unLockedSetting() {
  795. btn_reset_total.setVisibility(View.VISIBLE);
  796. btn_play_pause_total.setVisibility(View.VISIBLE);
  797. btn_play_pause_wait.setVisibility(View.VISIBLE);
  798. btn_reset_wait.setVisibility(View.VISIBLE);
  799.  
  800. btn_locked.setBackgroundResource(R.drawable.btn_unlocked);
  801.  
  802. String selId = getApp().prefsSmall.getString("selectedTrack", "");
  803. if (!getApp().prefsSmall.getBoolean(selId + "isTracking", false)) {
  804. btn_play_pause_total.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.play, 0, 0);
  805. } else {
  806. btn_play_pause_total.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.pause, 0, 0);
  807. }
  808.  
  809. if (!Track.getIsWaitTracking(app, selId)) {
  810. btn_play_pause_wait.setImageResource(R.drawable.play_min);
  811. } else {
  812. btn_play_pause_wait.setImageResource(R.drawable.pause_min);
  813. }
  814.  
  815.  
  816. }
  817.  
  818. @Override
  819. public void onResume() {
  820. super.onResume();
  821.  
  822. SharedPreferences.Editor e = PreferenceManager.getDefaultSharedPreferences(this).edit();
  823. e.putString("last_activity", getClass().getSimpleName());
  824. e.commit();
  825.  
  826. if (timer == null) {
  827. timer = new UITimer(handler);
  828. timer.start();
  829. }
  830. updateDistanceAndDisplacement();
  831. updateFare(false);
  832. updateTimer();
  833. updateWaitTimer();
  834. update();
  835.  
  836. String selId = getApp().prefsSmall.getString("selectedTrack", "");
  837.  
  838. if (!selId.equals("")) {
  839. if (getApp().prefsSmall.getBoolean(selId + "isTracking", false)) {
  840. btn_play_pause_total.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.pause, 0, 0);
  841. }
  842.  
  843. if (Track.getIsWaitTracking(getApp(), selId)) {
  844. btn_play_pause_wait.setImageResource(R.drawable.pause_min);
  845. }
  846. }
  847.  
  848.  
  849. }
  850.  
  851. @Override
  852. public void onPause() {
  853. super.onPause();
  854. timer.shutdown();
  855. timer = null;
  856. }
  857.  
  858.  
  859. private OnClickListener lockedClicked = new OnClickListener() {
  860.  
  861. @Override
  862. public void onClick(View v) {
  863. String selId = getApp().prefsSmall.getString("selectedTrack", "");
  864. if (locked) { //start unlocking process
  865. unLockedSetting();
  866. locked = false;
  867. timeUnlocked = SystemTime.getSystemTime();
  868. } else {
  869. btn_locked.setBackgroundResource(R.drawable.btn_locked);
  870. locked = true;
  871. lockedSetting();
  872. }
  873. }
  874. };
  875.  
  876.  
  877. private OnClickListener playPauseTotalClicked = new OnClickListener() {
  878.  
  879. @Override
  880. public void onClick(View v) {
  881.  
  882. startService(new Intent(DriverMeterActivity.this, LocationService.class));
  883.  
  884. String selId = getApp().prefsSmall.getString("selectedTrack", "");
  885. if (!locked || Track.getTimeElapsedLong(getApp(), selId) < 2000) {
  886.  
  887. if (!getApp().prefsSmall.getBoolean(selId + "isTracking", false)) {
  888. if (selId.equals("")) {
  889. selId = Track.generateId(getApp(), orderRequest.getOrderId());
  890. getApp().prefsSmall.edit().putString("selectedTrack", selId).commit();
  891. }
  892. long timeSinceLast = SystemTime.getSystemTime() - getApp().timeOfLastSignal;
  893.  
  894. float lastAcc = 1000;
  895. if (getApp().lastLocation != null) {
  896. lastAcc = getApp().lastLocation.getAccuracy();
  897. }
  898. if (lastAcc > Float.valueOf(IncarApp.prefsMinAccuracy) || timeSinceLast > 4000) {
  899. int nt = getApp().prefsSmall.getInt("timesShownMinAccWarn", 0);
  900. if (nt < 4) {
  901. getApp().prefsSmall.edit().putInt("timesShownMinAccWarn", nt + 1).commit();
  902. Ut.showNotification("", getApp().getResources().getString(R.string.warn_min_accuracy), DriverMeterActivity.this);
  903. }
  904. }
  905. Track.startTracking(getApp(), selId);
  906. unLockedSetting();
  907. } else {
  908. Track.stopTracking(getApp(), selId);
  909.  
  910. if (!Track.isAnyTracking(getApp())) {
  911. startService(new Intent(DriverMeterActivity.this, LocationService.class).putExtra("stop", true));
  912. }
  913.  
  914. unLockedSetting();
  915. }
  916.  
  917. } else {
  918. Toast.makeText(DriverMeterActivity.this, getApp().getResources().getString(R.string.unlock_it_first), Toast.LENGTH_LONG).show();
  919. }
  920. }
  921. };
  922.  
  923. private OnClickListener resetTotalClicked = new OnClickListener() {
  924. @Override
  925. public void onClick(View v) {
  926. if (!locked) {
  927. String selId = getApp().prefsSmall.getString("selectedTrack", "");
  928.  
  929. if (Track.getTimeElapsedLong(getApp(), selId) == 0) {
  930. Ut.showToast(DriverMeterActivity.this, getApp().getResources().getString(R.string.no_trip_to_clear));
  931. }
  932.  
  933. Track.clearTrip(getApp(), selId);
  934.  
  935. updateDistanceAndDisplacement();
  936. updateTimer();
  937. update();
  938.  
  939. Calendar cal = Calendar.getInstance();
  940. cal.setTimeInMillis(Track.getStartTime(getApp(), selId));
  941.  
  942. if (cabCategoryFareType != null)
  943. setFareInformation(cabCategoryFareType);
  944.  
  945. } else {
  946. Ut.showToast(DriverMeterActivity.this, getApp().getResources().getString(R.string.unlock_it_first));
  947. }
  948. }
  949. };
  950.  
  951. private void startEndJourneyButtonClicked(boolean confirmationRequired, float rate, double tips, double parking, double tolls) {
  952. <<<<<<< HEAD
  953. endJourney = new EndJourney();
  954. endJourney.setActualDayDistance(dayDistance);
  955. endJourney.setActualNightDistance(nightDistance);
  956.  
  957. endJourney.setF_baseFare(f_baseFare);
  958. endJourney.setF_distanceFare(f_distanceFare);
  959. endJourney.setF_waitTimeFare(f_waitTimeFare);
  960. endJourney.setF_hireTimeFare(f_hireTimeFare);
  961. endJourney.setF_bookingFeesFare(f_bookingFeesFare);
  962. endJourney.setF_tips(tips);
  963. endJourney.setF_tolls(tolls);
  964. endJourney.setF_parking(parking);
  965. =======
  966. orderId = orderRequest.getOrderId();
  967.  
  968. orderFinish = new OrderFinish();
  969. orderFinish.setOrderId(orderId);
  970. orderFinish.setDayDistance(dayDistance);
  971. orderFinish.setNightDistance(nightDistance);
  972.  
  973. orderFinish.setBaseFare(f_baseFare);
  974. orderFinish.setDistanceFare(f_distanceFare);
  975. orderFinish.setWaitTimeFare(f_waitTimeFare);
  976. orderFinish.setHireTimeFare(f_hireTimeFare);
  977. orderFinish.setBookingFee(f_bookingFeesFare);
  978. orderFinish.setTip(tips);
  979. orderFinish.setTollFare(tolls);
  980. orderFinish.setParkingFare(parking);
  981. >>>>>>> c77e3683aef9bc5c8dafaa3ad4513a0842185100
  982.  
  983. if (promo != null) {
  984. orderFinish.setDiscountFare(fare - f_discountFare);
  985. f_discountFare = f_distanceFare + tips + tolls + parking;
  986. orderFinish.setTotalFare(f_discountFare);
  987. } else {
  988. orderFinish.setDiscountFare(0);
  989. fare = fare + tips + tolls + parking;
  990. orderFinish.setTotalFare(fare);
  991. }
  992.  
  993. orderFinish.setPackageFare(f_packageFare);
  994.  
  995. String selId = getApp().prefsSmall.getString("selectedTrack", "");
  996. orderFinish.setTotalTimeFormatted(Track.getTimeElapsedStr(getApp(), selId));
  997. orderFinish.setTotalTime(Track.getTimeElapsedLong(getApp(), selId));
  998. orderFinish.setTotalWaitTimeFormatted(Track.getWaitTimeElapsedStr(getApp(), selId));
  999. orderFinish.setTotalWaitTime(Track.getWaitTimeElapsedLong(getApp(), selId));
  1000.  
  1001. if (confirmationRequired) {
  1002. showTripSummaryPopup();
  1003. } else {
  1004. api.getOrdersApi().finish(orderId, orderFinish)
  1005. .compose(applyComputeSchedulers())
  1006. .doOnSubscribe(this::showProgressBar)
  1007. .doOnCompleted(this::hideProgressBar)
  1008. .subscribe(new NetworkSubscriber<OrderFinish.Response>(this) {
  1009. @Override
  1010. public void onError(Throwable e) {
  1011. super.onError(e);
  1012. Log.e(TAG, e.getMessage(), e);
  1013. hideProgressBar();
  1014. }
  1015.  
  1016. @Override
  1017. public void onNext(OrderFinish.Response response) {
  1018. closeDriverMeter();
  1019. Intents.openDriverTripInfoActivity(DriverMeterActivity.this, response);
  1020. finish();
  1021. }
  1022. });
  1023. }
  1024. }
  1025.  
  1026. public void showOkConfirmation(String message, String first, String initialDistance, String pkm, String min, boolean endJourney, int hireOrMin) {
  1027. String currency = "";
  1028. if (cabCategoryFareType != null)
  1029. currency = cabCategoryFareType.getCurrency();
  1030.  
  1031. updateFare(false);
  1032. double totalFare = (Math.round(fare * 100)) / 100f;
  1033. double actualFare = totalFare;
  1034. double discount = 0;
  1035. if (promo != null) {
  1036. updateFare(true);
  1037. totalFare = (Math.round(f_discountFare * 100)) / 100f;
  1038. discount = actualFare - totalFare;
  1039. }
  1040.  
  1041. DriverDialogFareActivity.Builder builder = new DriverDialogFareActivity.Builder(this);
  1042. builder.setTitle("")
  1043. .setMessage(message)
  1044. .setFirst(first)
  1045. .setInitialDistance(initialDistance)
  1046. .setPkm(pkm)
  1047. .setMin(min)
  1048. .setDistance(tv_dist.getText().toString())
  1049. .setTime(tv_total_time_value.getText().toString())
  1050. .setTotalFare(DecimalFormating.getStringFormatted(totalFare))
  1051. .setActualFare(DecimalFormating.getStringFormatted(actualFare))
  1052. .setIsEndJourney(endJourney)
  1053. .setHireOrMin(hireOrMin)
  1054. .setCurrency(currency)
  1055. .setCity(app.getCabType() != null ? app.getCabType().getCity() : "")
  1056. .setPositiveButton(getString(R.string.status_ok)).setImageSource(0);
  1057. if (discount > 0) {
  1058. builder.setDiscount(DecimalFormating.getStringFormatted(discount));
  1059. }
  1060.  
  1061. if (endJourney) {
  1062. builder.show(REQUEST_INFO_END_JOURNEY);
  1063. } else {
  1064. builder.show(REQUEST_INFO);
  1065. }
  1066. }
  1067.  
  1068. @Override
  1069. public void onBackPressed() {
  1070. // moveTaskToBack(true); do nothing
  1071. }
  1072.  
  1073. private void showDriverDialogFareActivity(boolean showEndJourney) {
  1074. String currency = "";
  1075. if (cabCategoryFareType != null)
  1076. currency = cabCategoryFareType.getCurrency();
  1077.  
  1078. String message = getString(R.string.total_dist) + " " + distance + " \n" + getString(R.string.total_fare) + " " + currency + " " + DecimalFormating.getStringFormatted(fare);
  1079. int hireOrMin = 0;
  1080. String sMinFare = DecimalFormating.getStringFormatted(minFare);
  1081. if (cabCategoryFareType != null) {
  1082. if (cabCategoryFareType.getHireTimeFareDay() != null && cabCategoryFareType.getHireTimeFareDay().doubleValue() > 0) {
  1083. hireOrMin = 1;
  1084. sMinFare = DecimalFormating.getStringFormatted(cabCategoryFareType.getHireTimeFareDay());
  1085. }
  1086. }
  1087.  
  1088. showOkConfirmation(message, DecimalFormating.getStringFormatted(initialFare), DecimalFormating.getStringFormatted(minDistance), DecimalFormating.getStringFormatted(perKmCost), sMinFare, showEndJourney, hireOrMin);
  1089. }
  1090.  
  1091. private OnClickListener playPauseWaitClicked = new OnClickListener() {
  1092.  
  1093. @Override
  1094. public void onClick(View v) {
  1095. String selId = getApp().prefsSmall.getString("selectedTrack", "");
  1096. if (!locked || (Track.getWaitTimeLast(app, selId) < 2000 && Track.getIsWaitTracking(app, selId))) {
  1097. if (!Track.getIsWaitTracking(app, selId)) {
  1098. btn_play_pause_wait.setImageResource(R.drawable.pause_min);
  1099. Track.startTimerWait(getApp(), selId);
  1100. } else {
  1101. btn_play_pause_wait.setImageResource(R.drawable.play_min);
  1102. Track.stopTimerWait(getApp(), selId);
  1103. }
  1104. // lockedSetting();
  1105.  
  1106. } else {
  1107. Toast.makeText(DriverMeterActivity.this, getApp().getResources().getString(R.string.unlock_it_first), Toast.LENGTH_LONG).show();
  1108. }
  1109. }
  1110. };
  1111.  
  1112. private OnClickListener resetWaitClicked = new OnClickListener() {
  1113. @Override
  1114. public void onClick(View v) {
  1115. if (!locked) {
  1116. String selId = getApp().prefsSmall.getString("selectedTrack", "");
  1117.  
  1118. Track.clearWaitTimer(getApp(), selId);
  1119.  
  1120. tv_wait_time_value.setText(Track.getWaitTimeElapsedStr(getApp(), selId));
  1121.  
  1122. } else {
  1123. Ut.showToast(DriverMeterActivity.this, getApp().getResources().getString(R.string.unlock_it_first));
  1124. }
  1125. }
  1126. };
  1127.  
  1128. private OnClickListener phoneClicked = new OnClickListener() {
  1129. @Override
  1130. public void onClick(View v) {
  1131. String telUrl = "tel:" + orderRequest.getPhone();
  1132. Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(telUrl));
  1133. startActivity(intent);
  1134. }
  1135. };
  1136.  
  1137. private OnClickListener currencyClicked = new OnClickListener() {
  1138. @Override
  1139. public void onClick(View v) {
  1140. showDriverDialogFareActivity(false);
  1141. }
  1142. };
  1143.  
  1144. private OnClickListener mapClicked = new OnClickListener() {
  1145. @Override
  1146. public void onClick(View v) {
  1147.  
  1148. LatLng latLng = null;
  1149. String description = "";
  1150. if (orderRequest.getEndLocation() != null) {
  1151. latLng = orderRequest.getEndLocation().getLatLng();
  1152. description = orderRequest.getEndLocation().getDescription();
  1153. }
  1154. boolean activityFound = true;
  1155. if (latLng != null) {
  1156. try {
  1157. String uri = String.format(Locale.ENGLISH, "http://maps.google.com/maps?daddr=%f,%f (%s)", latLng.latitude, latLng.longitude, description);
  1158. Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
  1159. intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
  1160. intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  1161. getBaseContext().startActivity(intent);
  1162. } catch (Exception ex) {
  1163. activityFound = false;
  1164. }
  1165. }
  1166.  
  1167. if (activityFound)
  1168. return;
  1169.  
  1170. Intent intent = new Intent(DriverMeterActivity.this, MapMoreInfoPopupActivity.class);
  1171. orderRequest.setStatus(Order.STATUS_STARTED);
  1172. intent.putExtra(Constants.EXTRA_ORDER, orderRequest);
  1173. startActivity(intent);
  1174. }
  1175. };
  1176.  
  1177. Handler handler = new IncomingHandler(this);
  1178.  
  1179. class IncomingHandler extends Handler {
  1180. private final WeakReference<DriverMeterActivity> mTarget;
  1181.  
  1182. IncomingHandler(DriverMeterActivity target) {
  1183. mTarget = new WeakReference<DriverMeterActivity>(target);
  1184. }
  1185.  
  1186. @Override
  1187. public void handleMessage(Message msg) {
  1188.  
  1189. DriverMeterActivity target = mTarget.get();
  1190. if (target != null) {
  1191.  
  1192. if (msg.obj instanceof String) {
  1193. String mess = ((String) msg.obj);
  1194. if (mess.equals("update")) {
  1195. update();
  1196. updateDistanceAndDisplacement();
  1197. updateTimer();
  1198. updateWaitTimer();
  1199. updateFare(false);
  1200. } else if (mess.equals("relock")) {
  1201. locked = true;
  1202. lockedSetting();
  1203. }
  1204. }
  1205.  
  1206. }
  1207. }
  1208. }
  1209.  
  1210. private IncarApp getApp() {
  1211. return app;
  1212. }
  1213.  
  1214. final class UITimer extends Thread {
  1215. Handler mHandler;
  1216. private volatile boolean done = false;
  1217. private volatile boolean paused = false;
  1218.  
  1219. public UITimer(Handler h) {
  1220. this.mHandler = h;
  1221. }
  1222.  
  1223. public void shutdown() {
  1224. done = true;
  1225. }
  1226.  
  1227. @Override
  1228. public synchronized void run() {
  1229.  
  1230. w:
  1231. while (true) {
  1232. if (done)
  1233. break w;
  1234.  
  1235. if (!paused) {
  1236. if (!locked && SystemTime.getSystemTime() - timeUnlocked > 7000) {
  1237. Message msg = mHandler.obtainMessage();
  1238. msg.obj = "relock";
  1239. mHandler.sendMessage(msg);
  1240. }
  1241. Message msg = mHandler.obtainMessage();
  1242. msg.obj = "update";
  1243.  
  1244. mHandler.sendMessage(msg);
  1245. }
  1246.  
  1247.  
  1248. try {
  1249. Thread.sleep(990);
  1250. } catch (InterruptedException e) {
  1251. e.printStackTrace();
  1252. }
  1253. }
  1254. }
  1255. }
  1256.  
  1257. <<<<<<< HEAD
  1258.  
  1259. private class EndJourneyTask extends DialogApiAsyncTask<EndJourneyResponseAmount> {
  1260.  
  1261. private long orderId;
  1262. private float rate;
  1263. private EndJourney endJourney;
  1264.  
  1265. @Inject
  1266. private DriverOrderManager orderManager;
  1267.  
  1268. protected EndJourneyTask(Context context, long orderId, EndJourney endJourney, float rate) {
  1269. super(context);
  1270. this.orderId = orderId;
  1271. this.endJourney = endJourney;
  1272. this.rate = rate;
  1273. }
  1274.  
  1275. @Override
  1276. public EndJourneyResponseAmount call() throws Exception {
  1277. EndJourneyResponseAmount amount = orderManager.endJourney(orderId, endJourney, rate);
  1278. return amount;
  1279. }
  1280.  
  1281. @Override
  1282. protected void onSuccess(EndJourneyResponseAmount endJourneyResponseAmount) throws Exception {
  1283.  
  1284. // EndJourneyResponseAmount endJourneyResponseAmount = DriverOrderManager.endJourneyResponseAmount;
  1285. // Log.e("paveltest", endJourneyResponseAmount.toString());
  1286. if (endJourneyResponseAmount!=null && endJourneyResponseAmount.getMessage()!=null && endJourneyResponseAmount.getMessage().contains("wallet")) {
  1287. // final Dialog dialog = new Dialog(DriverMeterActivity.this);
  1288. // dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
  1289. // dialog.setContentView(R.layout.dialog_amount);
  1290. // TextView amountTextView = (TextView) dialog.findViewById(R.id.dialog_amount_textView);
  1291. //Button okButton = (Button) dialog.findViewById(R.id.dialog_amount_ok_button);
  1292. String message = getResources().getString(R.string.amount_credited);
  1293. showCreditedAmt(String.format(message, endJourneyResponseAmount.getAmount()), 0);
  1294. // amountTextView.setText();
  1295. // okButton.setOnClickListener(new OnClickListener() {
  1296. // @Override
  1297. // public void onClick(View view) {
  1298. // dialog.cancel();
  1299. // closeDriverMeter(context);
  1300. // }
  1301. // });
  1302. // dialog.show();
  1303. } else if (endJourneyResponseAmount!=null) {
  1304. closeDriverMeter();
  1305. } else{
  1306. ToastFactory.generateStatic(getBaseContext(), getString(R.string.finished_error), Toast.LENGTH_LONG);
  1307. }
  1308. }
  1309.  
  1310. }
  1311.  
  1312. public class OrderHistory extends DialogApiAsyncTask<List<Order>> {
  1313. List<Order> result=null;
  1314.  
  1315. protected OrderHistory(Context context){
  1316. super(context);
  1317. }
  1318. @Inject
  1319. private DriverOrderManager orderManager;
  1320. public List<Order> call() {
  1321. //orderRequest.getFinishedOrders()
  1322. try {
  1323. result= orderManager.getFinishedOrders(1);
  1324. } catch (IOException e) {
  1325. e.printStackTrace();
  1326. } catch (JSONException e) {
  1327. e.printStackTrace();
  1328. }
  1329. return result;
  1330. }
  1331. // begin the installation by opening the resulting file
  1332. @Override
  1333. protected void onSuccess(List<Order> result) {
  1334. CachedFinishedOrdersDB db = CachedFinishedOrdersDB.getInstance(getBaseContext());
  1335. orderRequest=result.get(0);
  1336. String currency = getString(R.string.Rs);
  1337. if(cabCategoryFareType!=null && cabCategoryFareType.getCurrency()!=null){
  1338. currency = cabCategoryFareType.getCurrency();
  1339. }
  1340. orderRequest.setCurrency(currency);
  1341. db.addDB(orderRequest);
  1342. finishedOrderHistory();
  1343. }
  1344. }
  1345. private void finishedOrderHistory(){
  1346. Intent intent = new Intent(this, FinishedOrderList.class);
  1347. intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  1348. startActivity(intent);
  1349. finish();
  1350. }
  1351. private void closeDriverMeter(){
  1352. =======
  1353. private void closeDriverMeter() {
  1354. >>>>>>> c77e3683aef9bc5c8dafaa3ad4513a0842185100
  1355. String selId = getApp().prefsSmall.getString("selectedTrack", "");
  1356. Track.destroy(getApp(), selId);
  1357. if (!Track.isAnyTrackThere(getApp())) {
  1358. startService(new Intent(DriverMeterActivity.this, LocationService.class).putExtra("stop", true));
  1359. }
  1360. <<<<<<< HEAD
  1361. //addToDB();
  1362. new OrderHistory(this).execute();
  1363. /*Intent intent = new Intent(this, FinishedOrderList.class);
  1364. intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  1365. startActivity(intent);
  1366. finish();*/
  1367.  
  1368. =======
  1369. addToDB();
  1370. >>>>>>> c77e3683aef9bc5c8dafaa3ad4513a0842185100
  1371. }
  1372.  
  1373. private void closeDriverMeterinError() {
  1374. ToastFactory.generateStatic(this.getBaseContext(), getResources().getString(R.string.finished_error), Toast.LENGTH_LONG);
  1375. finish();
  1376. }
  1377.  
  1378. private void addToDB() {
  1379. CachedFinishedOrdersDB db = CachedFinishedOrdersDB.getInstance(getBaseContext());
  1380. // if (topay != 0f) {
  1381. // orderRequest.setActTotFare(topay);
  1382. // } else {
  1383. // orderRequest.setActTotFare(fare);
  1384. // }
  1385.  
  1386. String distStr = tv_dist.getText().toString();
  1387. distStr = distStr.split(" ")[0];
  1388. double dist = Double.parseDouble(distStr);
  1389.  
  1390. orderRequest.setActDayDistance(dist);
  1391. orderRequest.setActNightDistance(0);
  1392.  
  1393. orderRequest.setActTotFare(topay);
  1394. orderRequest.setCustomerPaid(remaining);
  1395. String currency = getString(R.string.Rs);
  1396.  
  1397. if (cabCategoryFareType != null && cabCategoryFareType.getCurrency() != null) {
  1398. currency = cabCategoryFareType.getCurrency();
  1399. }
  1400. orderRequest.setCurrency(currency);
  1401.  
  1402. db.addDB(orderRequest);
  1403. }
  1404.  
  1405. private class MeteredJourneyTask extends RoboAsyncTask<ApproximatedFareForType> {
  1406.  
  1407. private long orderId;
  1408. private String subStatus;
  1409.  
  1410. @Inject
  1411. private DriverOrderManager driverOrderManager;
  1412.  
  1413. protected MeteredJourneyTask(Context context, long orderId) {
  1414. super(context);
  1415. this.orderId = orderId;
  1416. this.subStatus = subStatus;
  1417. }
  1418.  
  1419. @Override
  1420. public ApproximatedFareForType call() throws Exception {
  1421. ApproximatedFareForType fareType = driverOrderManager.getFareInformation(orderId);
  1422. return fareType;
  1423. }
  1424.  
  1425. @Override
  1426. protected void onSuccess(ApproximatedFareForType fareType) throws Exception {
  1427. if (fareType != null)
  1428. setFareInformation(fareType);
  1429. else
  1430. closeDriverMeterinError();
  1431. }
  1432. }
  1433.  
  1434. private void goToMenuScreen(int menu_option) {
  1435. Log.d("DRIVERS", "Menu option to load UI - " + loginPrefs.getMenuOption());
  1436.  
  1437. if (menu_option == 2) {
  1438. Menu6BtnsActivity.start(this);
  1439. } else {
  1440. HomescreenActivity.start(this);
  1441. Log.d("DRIVERS", "Go to menu after registration default");
  1442. }
  1443. finish();
  1444. }
  1445.  
  1446.  
  1447. }
Advertisement
Add Comment
Please, Sign In to add comment