Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.taxipixi.incarapp.activities;
- import android.app.AlarmManager;
- import android.app.AlertDialog;
- import android.app.PendingIntent;
- import android.app.ProgressDialog;
- import android.content.Context;
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.content.pm.ActivityInfo;
- import android.net.Uri;
- import android.os.Bundle;
- import android.os.Handler;
- import android.os.Message;
- import android.preference.PreferenceManager;
- import android.text.Html;
- import android.util.DisplayMetrics;
- import android.util.Log;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.ImageView;
- import android.widget.LinearLayout;
- import android.widget.RelativeLayout;
- import android.widget.TextView;
- import android.widget.Toast;
- import com.google.android.gms.maps.model.LatLng;
- import com.google.inject.Inject;
- import com.gpsodometer.LocationService;
- import com.gpsodometer.Track;
- import com.gpsodometer.Ut;
- import com.taxipixi.entity.Order;
- import com.taxipixi.entity.Promotion;
- import com.taxipixi.fare.ApproximatedFareForType;
- import com.taxipixi.fare.ApproximatedFareInfo;
- import com.taxipixi.incarapp.Constants;
- import com.taxipixi.incarapp.LoginPreferences;
- import com.taxipixi.incarapp.R;
- import com.taxipixi.incarapp.api.SystemTime;
- import com.taxipixi.incarapp.api2.Api;
- import com.taxipixi.incarapp.application.IncarApp;
- import com.taxipixi.incarapp.async.NetworkSubscriber;
- import com.taxipixi.incarapp.db.CachedFinishedOrdersDB;
- import com.taxipixi.incarapp.fare.JourneyInfoFromOrderExtractor;
- import com.taxipixi.incarapp.models.OrderFinish;
- import com.taxipixi.incarapp.orders.DriverOrderManager;
- import com.taxipixi.incarapp.orders.EndJourney;
- import com.taxipixi.utils.DecimalFormating;
- import com.taxipixi.utils.ProgressDialogFactory;
- import com.taxipixi.widget.ToastFactory;
- import org.json.JSONArray;
- import org.json.JSONException;
- import org.json.JSONObject;
- import java.io.IOException;
- import java.lang.ref.WeakReference;
- import java.math.BigDecimal;
- import java.util.Calendar;
- import java.util.List;
- import java.util.Locale;
- import roboguice.util.RoboAsyncTask;
- import rx.Subscriber;
- import static com.taxipixi.utils.ObservableUtils.applyComputeSchedulers;
- public class DriverMeterActivity extends IncarBaseActivity {
- private static final String TAG = DriverMeterActivity.class.getSimpleName();
- @Inject
- private LoginPreferences loginPrefs;
- @Inject
- private Api api;
- private Order orderRequest;
- private ApproximatedFareForType cabCategoryFareType;
- private TextView tv_fare_value, tv_total_time_value, tv_wait_time_value, tv_dist;
- private Button btn_play_pause_total;
- private ImageView btn_play_pause_wait, img_distance_travelled, img_wait_time, img_total_time, img_fare;
- private Button btn_reset_total;
- private Button btn_locked;
- private Button btn_end_journey;
- private Button btn_phone;
- private Button btn_currency;
- private Button btn_map;
- private ImageView btn_reset_wait;
- private RelativeLayout rl_fare, rl_wait_time, rl_space;
- private UITimer timer;
- private boolean locked = true;
- private long timeUnlocked = 0;
- private IncarApp app;
- private ApproximatedFareInfo afi;
- private ApproximatedFareForType fareInfoForType;
- public static final int REQUEST_CONFIRMATION = 0;
- public static final int REQUEST_CREDIT_AMT = 3;
- public static final int REQUEST_INFO_END_JOURNEY = 1;
- private static final int REQUEST_INFO = 2;
- private BigDecimal perKmCost;
- private double fare, f_baseFare, f_distanceFare, f_waitTimeFare, f_hireTimeFare, f_bookingFeesFare, f_discountFare, f_packageFare, f_discountOffered;
- private float dayDistance;
- private float nightDistance;
- private String distance;
- private int day_night_start = 0; //0 = day start, 1 = night start
- private double initialFare, promoInitalFare;
- private double minFare;
- private double minDistance;
- double dayDistanceFare = 0;
- double nightDistanceFare = 0;
- boolean isEnglish = true;
- Promotion promo = null;
- public static EndJourney endJourney;
- public static long orderId;
- private OrderFinish orderFinish;
- AlertDialog alertDialog;
- private double topay, remaining;
- private BigDecimal parking;
- private BigDecimal tolls;
- private AlertDialog tripSummaryDialog;
- private AlertDialog extrasDialog;
- private ProgressDialog progressDialog;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
- setContentView(R.layout.activity_driver_meter);
- if (android.os.Build.VERSION.SDK_INT >= 11)
- if (getActionBar() != null) getActionBar().hide();
- app = ((IncarApp) getApplication());
- isEnglish = app.getCabType().isEnglish();
- Bundle b = getIntent().getExtras();
- if (b != null) {
- orderRequest = (Order) b.get(Constants.EXTRA_ORDER);
- }
- if (savedInstanceState != null) {
- orderRequest = savedInstanceState.getParcelable("order");
- }
- if (orderRequest == null) {
- int menu_option = Integer.parseInt(loginPrefs.getMenuOption());
- goToMenuScreen(menu_option);
- return;
- }
- String selId = getApp().prefsSmall.getString("selectedTrack", "");
- String newId = "track" + orderRequest.getOrderId();
- new MeteredJourneyTask(this, orderRequest.getOrderId()).execute();
- if (!Track.isTrackExist(getApp(), newId)) { //if not exist
- newId = Track.generateId(getApp(), orderRequest.getOrderId()); //create track
- // Log.e("reali", "Create new track " + newId);
- Track.startTracking(getApp(), newId); //start tracking
- } else {
- Track.startTracking(getApp(), newId); //start tracking
- }
- if (!newId.equals(selId)) {
- app.prefsSmall.edit().putString("selectedTrack", newId).commit();
- }
- initializeUI();
- endReminderAlarm(orderRequest.getOrderId());
- }
- private void showTripSummaryPopup() {
- final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
- View dialogView = getLayoutInflater().inflate(R.layout.dialog_trip_summary, null);
- dialogBuilder.setView(dialogView);
- TextView distanceValue = (TextView) dialogView.findViewById(R.id.trip_distance_value);
- distanceValue.setText(distance);
- TextView timeValue = (TextView) dialogView.findViewById(R.id.trip_time_value);
- String selId = getApp().prefsSmall.getString("selectedTrack", "");
- timeValue.setText(Track.getTimeElapsedStr(getApp(), selId));
- View tripExtras = dialogView.findViewById(R.id.trip_extras);
- tripExtras.setOnClickListener(view -> showAddExtrasPopup());
- View charge = dialogView.findViewById(R.id.charge);
- charge.setOnClickListener(view -> {
- double parkingValue = parking != null ? parking.doubleValue() : 0f;
- double tollsValue = tolls != null ? tolls.doubleValue() : 0f;
- startEndJourneyButtonClicked(false, 0f, 0f, parkingValue, tollsValue);
- tripSummaryDialog.dismiss();
- });
- ImageView close = (ImageView) dialogView.findViewById(R.id.trip_summary_close);
- close.setOnClickListener(view -> tripSummaryDialog.dismiss());
- dialogBuilder.setCancelable(false);
- tripSummaryDialog = dialogBuilder.create();
- tripSummaryDialog.show();
- }
- private void showAddExtrasPopup() {
- final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
- View dialogView = getLayoutInflater().inflate(R.layout.dialog_add_extras, null);
- dialogBuilder.setView(dialogView);
- EditText tolls = (EditText) dialogView.findViewById(R.id.tolls);
- tolls.setText(DecimalFormating.getStringFormatted(this.tolls));
- EditText parking = (EditText) dialogView.findViewById(R.id.parking);
- parking.setText(DecimalFormating.getStringFormatted(this.parking));
- ImageView close = (ImageView) dialogView.findViewById(R.id.add_extras_close);
- close.setOnClickListener(view -> extrasDialog.dismiss());
- Button back = (Button) dialogView.findViewById(R.id.extras_back);
- back.setOnClickListener(view -> extrasDialog.dismiss());
- Button save = (Button) dialogView.findViewById(R.id.extras_save);
- save.setOnClickListener(view -> {
- double tollsValue = DecimalFormating.parseDouble(tolls.getText().toString());
- double parkingValue = DecimalFormating.parseDouble(parking.getText().toString());
- saveExtras(tollsValue, parkingValue);
- extrasDialog.dismiss();
- });
- dialogBuilder.setCancelable(false);
- extrasDialog = dialogBuilder.create();
- extrasDialog.show();
- }
- private void saveExtras(double tolls, double parking) {
- this.tolls = new BigDecimal(tolls);
- this.parking = new BigDecimal(parking);
- }
- private void showProgressBar() {
- if (progressDialog == null) {
- progressDialog = ProgressDialogFactory.show(this,
- getString(com.taxipixi.R.string.progress_dialog_title),
- getString(com.taxipixi.R.string.progress_dialog_body));
- } else {
- progressDialog.show();
- }
- }
- private void hideProgressBar() {
- if (progressDialog != null) {
- progressDialog.dismiss();
- }
- }
- private void endReminderAlarm(long orderId) {
- try {
- Intent cancelIntent = new Intent("OrderReminder");
- cancelIntent.putExtra("orderReminder", true);
- AlarmManager alarmManager = (AlarmManager) getBaseContext().getSystemService(Context.ALARM_SERVICE);
- PendingIntent cancelPendingIntent = PendingIntent.getBroadcast(getBaseContext().getApplicationContext(), (int) orderId, cancelIntent, PendingIntent.FLAG_UPDATE_CURRENT);
- alarmManager.cancel(cancelPendingIntent);
- } catch (Exception ex) {
- Log.d("CancelOrderHandler", "Error removing reminder alarm");
- }
- }
- @Override
- public void onSaveInstanceState(Bundle savedInstanceState) {
- super.onSaveInstanceState(savedInstanceState);
- savedInstanceState.putParcelable("Order", orderRequest);
- }
- public void initializeUI() {
- tv_dist = (TextView) findViewById(R.id.tv_distance_travelled_value);
- tv_fare_value = (TextView) findViewById(R.id.tv_fare_value);
- tv_total_time_value = (TextView) findViewById(R.id.tv_total_time_value);
- tv_wait_time_value = (TextView) findViewById(R.id.tv_wait_time_value);
- btn_play_pause_total = (Button) findViewById(R.id.btn_play_pause_total);
- btn_reset_total = (Button) findViewById(R.id.btn_reset_total);
- btn_play_pause_wait = (ImageView) findViewById(R.id.btn_play_pause_wait);
- btn_reset_wait = (ImageView) findViewById(R.id.btn_reset_wait);
- btn_end_journey = (Button) findViewById(R.id.btn_start_end_journey);
- btn_phone = (Button) findViewById(R.id.btn_phone);
- btn_currency = (Button) findViewById(R.id.btn_currency);
- btn_map = (Button) findViewById(R.id.btn_map);
- btn_locked = (Button) findViewById(R.id.btn_locked);
- btn_locked.setBackgroundResource(R.drawable.btn_locked);
- rl_fare = (RelativeLayout) findViewById(R.id.rl_fare);
- rl_wait_time = (RelativeLayout) findViewById(R.id.rl_wait_time);
- rl_space = (RelativeLayout) findViewById(R.id.rl_space);
- int density = getResources().getDisplayMetrics().densityDpi;
- if (density == DisplayMetrics.DENSITY_LOW) {
- img_distance_travelled = (ImageView) findViewById(R.id.img_distance_travelled);
- img_distance_travelled.setVisibility(View.GONE);
- img_wait_time = (ImageView) findViewById(R.id.img_wait_time);
- img_wait_time.setVisibility(View.GONE);
- img_total_time = (ImageView) findViewById(R.id.img_total_time);
- img_total_time.setVisibility(View.GONE);
- img_fare = (ImageView) findViewById(R.id.img_fare);
- img_fare.setVisibility(View.GONE);
- }
- if (!isEnglish) {
- btn_end_journey.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
- btn_end_journey.setBackgroundResource(R.drawable.end_journey);
- btn_end_journey.setText("");
- }
- btn_play_pause_total.setOnClickListener(playPauseTotalClicked);
- btn_reset_total.setOnClickListener(resetTotalClicked);
- btn_locked.setOnClickListener(lockedClicked);
- btn_play_pause_wait.setOnClickListener(playPauseWaitClicked);
- btn_reset_wait.setOnClickListener(resetWaitClicked);
- btn_end_journey.setOnClickListener(view -> showTripSummaryPopup());
- btn_phone.setOnClickListener(phoneClicked);
- btn_currency.setOnClickListener(currencyClicked);
- btn_map.setOnClickListener(mapClicked);
- btn_phone.setText(orderRequest.getPhone());
- btn_reset_total.setVisibility(View.GONE);
- btn_play_pause_total.setVisibility(View.GONE);
- btn_play_pause_wait.setVisibility(View.GONE);
- btn_reset_wait.setVisibility(View.GONE);
- enableDisableBottomButtons(false);
- updateDistanceAndDisplacement();
- }
- private void enableDisableBottomButtons(boolean enabled) {
- if (enabled) {
- btn_end_journey.setVisibility(View.VISIBLE);
- btn_phone.setVisibility(View.VISIBLE);
- } else {
- btn_end_journey.setVisibility(View.GONE);
- btn_phone.setVisibility(View.GONE);
- }
- }
- private void setFareInformation(ApproximatedFareForType fareType) {
- enableDisableBottomButtons(true);
- cabCategoryFareType = fareType;
- afi = orderRequest.getApproximatedFareInfo();
- fareInfoForType = afi.getFareInfoForType(JourneyInfoFromOrderExtractor.getAllowedPriceType(orderRequest, getApp().getCabType().getCategory()));
- long networkTS = SystemTime.getSystemTime();
- Calendar calendar = Calendar.getInstance();
- calendar.setTimeInMillis(networkTS);
- if (fareInfoForType.getPromotion() != null) {
- promo = fareInfoForType.getPromotion();
- }
- if (calendar.get(Calendar.HOUR_OF_DAY) >= fareType.getDayStartHr() && calendar.get(Calendar.HOUR_OF_DAY) < fareType.getNightStartHr()) {
- initialFare = fareType.getInitialFeeDay().doubleValue();
- minFare = fareType.getMinFareDay().doubleValue();
- perKmCost = fareInfoForType.getPerKmCostDay();
- if (promo != null && promo.getPromoPerKmDay() > 0) {
- perKmCost = new BigDecimal(promo.getPromoPerKmDay());
- promoInitalFare = promo.getPromoInitialDay();
- }
- day_night_start = 0;
- } else {
- initialFare = fareType.getInitialFeeNight().doubleValue();
- minFare = fareType.getMinFareNight().doubleValue();
- perKmCost = fareInfoForType.getPerKmCostNight();
- if (promo != null && promo.getPromoPerKmNight() > 0) {
- perKmCost = new BigDecimal(promo.getPromoPerKmNight());
- promoInitalFare = promo.getPromoInitialNight();
- }
- day_night_start = 1;
- }
- minDistance = fareType.getMinimum();
- if (fareType.getShowMeterFare() == 1) {
- rl_fare.setVisibility(View.VISIBLE);
- } else {
- rl_fare.setVisibility(View.GONE);
- rl_space.setVisibility(View.GONE);
- LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(
- LinearLayout.LayoutParams.MATCH_PARENT,
- LinearLayout.LayoutParams.MATCH_PARENT, 2.0f);
- rl_wait_time.setLayoutParams(param);
- }
- if (orderRequest.getBookingType().equals(com.taxipixi.Constants.HOURLY) || (fareType.getHireTimeFareDay() != null && fareType.getHireTimeFareDay().doubleValue() > 0)) {
- rl_wait_time.setVisibility(View.GONE);
- rl_space.setVisibility(View.GONE);
- LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(
- LinearLayout.LayoutParams.MATCH_PARENT,
- LinearLayout.LayoutParams.MATCH_PARENT, 2.0f);
- rl_fare.setLayoutParams(param);
- } else {
- rl_space.setVisibility(View.VISIBLE);
- rl_wait_time.setVisibility(View.VISIBLE);
- }
- }
- public void updateDistanceAndDisplacement() {
- String selId = getApp().prefsSmall.getString("selectedTrack", "");
- distance = Track.getLongUnitDistance(getApp(), selId);
- if (tv_dist != null)
- tv_dist.setText(Html.fromHtml("<b>" + distance + "</b>"));
- }
- public void updateFare(boolean calculatePromoFare) {
- if (cabCategoryFareType != null) {
- if (orderRequest.getBookingType().equals(com.taxipixi.Constants.POINT_TO_POINT)) {
- if (!calculatePromoFare)
- fare = getP2PFare(calculatePromoFare);
- else
- f_discountFare = getP2PFare(calculatePromoFare);
- } else {
- if (!calculatePromoFare)
- fare = getHourlyFare(calculatePromoFare);
- else
- f_discountFare = getHourlyFare(calculatePromoFare);
- }
- // Log.e("reali", "f_discountFare " + f_discountFare);
- if (f_discountFare > 0 && calculatePromoFare) {
- if (promo != null && promo.isFixedDiscountPromo())
- f_discountFare = f_discountFare - promo.getFixedDiscount();
- else if (promo != null && promo.isPercentDiscountPromo())
- f_discountFare = f_discountFare - (f_discountFare * (promo.getPercentDiscount() / 100));
- else if (promo != null && promo.isFeeDiscountPromo())
- f_discountFare = f_discountFare - promo.getFeeDiscount();
- if (f_discountFare < 0)
- f_discountFare = 0;
- else
- f_discountFare = (Math.round(f_discountFare * 100)) / 100f;
- // Log.e("reali", "f_disc0untFare " + f_discountFare);
- }
- if (!calculatePromoFare)
- tv_fare_value.setText(cabCategoryFareType.getCurrency() + " " + DecimalFormating.getStringFormatted(fare));
- } else {
- tv_fare_value.setText("-");
- }
- }
- private double getP2PFare(boolean calculatePromoFare) {
- String selId = getApp().prefsSmall.getString("selectedTrack", "");
- dayDistance = Track.getLongUnitDistanceFloat(getApp(), selId, 1);
- nightDistance = Track.getLongUnitDistanceFloat(getApp(), selId, 2);
- float totalDistance = (Math.round(Track.getLongUnitDistanceFloat(getApp(), selId, 0) * 100)) / 100f;
- dayDistance = (Math.round(dayDistance * 100)) / 100f;
- nightDistance = (Math.round(nightDistance * 100)) / 100f;
- dayDistance = totalDistance - nightDistance;
- double tripFare = 0;
- if (cabCategoryFareType != null) {
- /* Start Distance based pricing */
- double fixedFare = getFixedFare();
- if (fixedFare > -1) {
- f_distanceFare = fixedFare;
- tripFare = fixedFare;
- } else if (dayDistance + nightDistance <= minDistance) {
- if (!calculatePromoFare || promo == null || !promo.isCabCategoryPromo()) {
- tripFare = initialFare;
- f_distanceFare = initialFare;
- } else
- tripFare = promoInitalFare;
- } else {
- fareInfoForType = afi.getFareInfoForType(JourneyInfoFromOrderExtractor.getAllowedPriceType(orderRequest, getApp().getCabType().getCategory()));
- double minDistanceFare = initialFare;
- dayDistanceFare = 0;
- nightDistanceFare = 0;
- int distance_unit = cabCategoryFareType.getSubsequentDistUnit().contains("KM") ? 1 : 10;
- if (day_night_start == 0) {
- float newDayDistance = dayDistance - (float) minDistance;
- if (newDayDistance < 0) {
- float newNightDistance = nightDistance + newDayDistance;
- if (!calculatePromoFare || promo == null || !promo.isCabCategoryPromo())
- nightDistanceFare = newNightDistance * fareInfoForType.getPerKmCostNight().doubleValue() * distance_unit;
- else
- nightDistanceFare = newNightDistance * fareInfoForType.getPromotion().getPromoPerKmNight() * distance_unit;
- } else {
- if (!calculatePromoFare || promo == null || !promo.isCabCategoryPromo()) {
- dayDistanceFare = newDayDistance * fareInfoForType.getPerKmCostDay().doubleValue() * distance_unit;
- nightDistanceFare = nightDistance * fareInfoForType.getPerKmCostNight().doubleValue() * distance_unit;
- } else {
- dayDistanceFare = newDayDistance * fareInfoForType.getPromotion().getPromoPerKmDay() * distance_unit;
- nightDistanceFare = nightDistance * fareInfoForType.getPromotion().getPromoPerKmNight() * distance_unit;
- }
- }
- } else {
- float newNightDistance = nightDistance - (float) minDistance;
- if (newNightDistance < 0) {
- float newDayDistance = dayDistance + newNightDistance;
- if (!calculatePromoFare || promo == null || !promo.isCabCategoryPromo())
- dayDistanceFare = newDayDistance * fareInfoForType.getPerKmCostDay().doubleValue() * distance_unit;
- else
- dayDistanceFare = newDayDistance * fareInfoForType.getPromotion().getPromoPerKmDay() * distance_unit;
- } else {
- if (!calculatePromoFare || promo == null || !promo.isCabCategoryPromo()) {
- nightDistanceFare = newNightDistance * fareInfoForType.getPerKmCostNight().doubleValue() * distance_unit;
- dayDistanceFare = dayDistance * fareInfoForType.getPerKmCostDay().doubleValue() * distance_unit;
- } else {
- nightDistanceFare = newNightDistance * fareInfoForType.getPromotion().getPromoPerKmNight() * distance_unit;
- dayDistanceFare = dayDistance * fareInfoForType.getPromotion().getPromoPerKmDay() * distance_unit;
- }
- }
- }
- if (minDistance == 0)
- f_baseFare = minDistanceFare;
- else
- f_baseFare = 0;
- tripFare = minDistanceFare + dayDistanceFare + nightDistanceFare;
- if (!calculatePromoFare && minDistance == 0)
- f_distanceFare = dayDistanceFare + nightDistanceFare;
- else if (!calculatePromoFare)
- f_distanceFare = minDistanceFare + dayDistanceFare + nightDistanceFare;
- Log.d("@meter:fare", tripFare + ": " + " DD:" + dayDistance + " ND:" + nightDistance + " Dist:" + distance + " DF:" + dayDistanceFare + " NF:" + nightDistanceFare);
- }
- /* End Distance based pricing */
- double waitTimeFare = getP2PWaitTimeFare();
- f_waitTimeFare = waitTimeFare;
- tripFare = tripFare + waitTimeFare;
- /* Start Wait Time based pricing */
- /* Run Time Fare */
- double hireTimeFare = getHireTimeFare();
- f_hireTimeFare = hireTimeFare;
- tripFare = tripFare + hireTimeFare;
- if (tripFare < minFare) {
- tripFare = minFare;
- f_hireTimeFare = 0;
- if (!calculatePromoFare)
- f_distanceFare = minFare - f_baseFare;
- }
- /* Start Fee based pricing */
- int add_fee = cabCategoryFareType.getFeeInclInitialFee() == 1 ? 0 : 1;
- f_bookingFeesFare = cabCategoryFareType.getFee().doubleValue() * add_fee;
- tripFare = tripFare + f_bookingFeesFare;
- /* End Fee based pricing */
- return tripFare;
- }
- return 0;
- }
- private double getFixedFare() {
- double fixedFare = -1;
- fareInfoForType = afi.getFareInfoForType(JourneyInfoFromOrderExtractor.getAllowedPriceType(orderRequest, getApp().getCabType().getCategory()));
- if (fareInfoForType != null && fareInfoForType.isFixedFare()) {
- Calendar calendar = Calendar.getInstance();
- calendar.setTimeInMillis(orderRequest.getRequestedPickupTime() * 1000);
- if (calendar.get(Calendar.HOUR_OF_DAY) >= fareInfoForType.getDayStartHr() && calendar.get(Calendar.HOUR_OF_DAY) < fareInfoForType.getNightStartHr()) {
- fixedFare = fareInfoForType.getApproxCostDay().doubleValue();
- } else {
- fixedFare = fareInfoForType.getApproxCostNight().doubleValue();
- }
- }
- return fixedFare;
- }
- private double getHourlyFare(boolean calculatePromoFare) {
- fareInfoForType = afi.getFareInfoForType(JourneyInfoFromOrderExtractor.getAllowedPriceType(orderRequest, getApp().getCabType().getCategory()));
- if (fareInfoForType != null) {
- Calendar calendar = Calendar.getInstance();
- calendar.setTimeInMillis(orderRequest.getRequestedPickupTime() * 1000);
- double hourlyTripFare = 0;
- int distance_unit = cabCategoryFareType.getSubsequentDistUnit().contains("KM") ? 1 : 10;
- if (calendar.get(Calendar.HOUR_OF_DAY) >= fareInfoForType.getDayStartHr() && calendar.get(Calendar.HOUR_OF_DAY) < fareInfoForType.getNightStartHr()) {
- hourlyTripFare = fareInfoForType.getApproxCostDay().doubleValue();
- } else {
- hourlyTripFare = fareInfoForType.getApproxCostNight().doubleValue();
- }
- f_packageFare = hourlyTripFare;
- double additionalDistFare = 0;
- String selId = getApp().prefsSmall.getString("selectedTrack", "");
- dayDistance = (Math.round(Track.getLongUnitDistanceFloat(getApp(), selId, 1) * 100)) / 100f;
- nightDistance = (Math.round(Track.getLongUnitDistanceFloat(getApp(), selId, 2) * 100)) / 100f;
- if (dayDistance + nightDistance > orderRequest.getDistanceEstimatedKilometers()) {
- float newDayDistance = dayDistance + nightDistance - (float) minDistance;
- if (!calculatePromoFare || promo == null || !promo.isCabCategoryPromo()) {
- additionalDistFare = newDayDistance * fareInfoForType.getPerKmCostDay().doubleValue() * distance_unit;
- } else {
- additionalDistFare = newDayDistance * fareInfoForType.getPromotion().getPromoPerKmDay() * distance_unit;
- }
- if (!calculatePromoFare)
- f_distanceFare = additionalDistFare;
- hourlyTripFare = hourlyTripFare + additionalDistFare;
- }
- double additionalTimeFare = 0;
- long totalTime = Track.getTimeElapsedLong(getApp(), selId);
- String packageType = orderRequest.getPackageType();
- long allowedTime = 2 * 60 * 60 * 1000; //2 hours
- if (packageType.contains("4"))
- allowedTime = 4 * 60 * 60 * 1000; //4 hours
- else if (packageType.contains("8"))
- allowedTime = 8 * 60 * 60 * 1000; //8 hours
- else if (packageType.contains("OUT") || packageType.contains("FULL")) {
- int days = orderRequest.getDays();
- allowedTime = days * 24 * 60 * 60 * 1000;
- }
- if (totalTime > allowedTime) {
- additionalTimeFare = (totalTime - allowedTime) / 1000 / 60 * cabCategoryFareType.getWaitTimeFare().doubleValue() / 60;
- f_hireTimeFare = additionalTimeFare;
- }
- hourlyTripFare = hourlyTripFare + additionalTimeFare;
- return hourlyTripFare;
- }
- return 0;
- }
- private double getHireTimeFare() {
- String selId = getApp().prefsSmall.getString("selectedTrack", "");
- long totalTime = Track.getTimeElapsedLong(getApp(), selId);
- double hireTimeFare = 0;
- if (totalTime > 0 && fareInfoForType.getHireTimeFareDay() != null && fareInfoForType.getHireTimeFareDay().doubleValue() > 0) {
- hireTimeFare = totalTime / 1000 / 60 * fareInfoForType.getHireTimeFareDay().doubleValue();
- }
- hireTimeFare = (Math.round(hireTimeFare * 100)) / 100f;
- return hireTimeFare;
- }
- private double getP2PWaitTimeFare() {
- String selId = getApp().prefsSmall.getString("selectedTrack", "");
- long waitTime = Track.getWaitTimeElapsedLong(getApp(), selId);
- double waitTimeFare = 0;
- if (cabCategoryFareType.getWaitTimeInitialFare() != null && cabCategoryFareType.getWaitTimeInitialFare().doubleValue() > 0) {
- String unit = cabCategoryFareType.getWaitTimeInitialUnit();
- long waitTimeInitialUnitBased = 0;
- if (unit.contains("SEC")) {
- waitTimeInitialUnitBased = waitTime / 1000;
- waitTime = waitTime - cabCategoryFareType.getWaitTimeInitialMinutes() * 1000;
- } else if (unit.contains("MIN")) {
- waitTimeInitialUnitBased = waitTime / 1000 / 60;
- waitTime = waitTime - cabCategoryFareType.getWaitTimeInitialMinutes() * 1000 * 60;
- } else if (unit.contains("HOU")) {
- waitTimeInitialUnitBased = waitTime / 1000 / 60 / 60;
- waitTime = waitTime - cabCategoryFareType.getWaitTimeInitialMinutes() * 1000 * 60 * 60;
- }
- waitTimeFare = cabCategoryFareType.getWaitTimeInitialFare().doubleValue();
- if (waitTimeInitialUnitBased < cabCategoryFareType.getWaitTimeInitialMinutes()) {
- waitTime = 0;
- }
- }
- if (waitTime > 0 && cabCategoryFareType.getWaitTimeFare().doubleValue() > 0) {
- String unit = cabCategoryFareType.getWaitTimeUnit();
- long waitTimeUnitBased = 0;
- if (unit.contains("SEC")) {
- waitTimeUnitBased = waitTime / 1000;
- } else if (unit.contains("MIN")) {
- waitTimeUnitBased = waitTime / 1000 / 60;
- } else if (unit.contains("HOU")) {
- waitTimeUnitBased = waitTime / 1000 / 60 / 60;
- }
- waitTimeFare = waitTimeFare + waitTimeUnitBased * cabCategoryFareType.getWaitTimeFare().doubleValue() / cabCategoryFareType.getWaitTimeMinutes();
- }
- /* End Wait based pricing */
- waitTimeFare = (Math.round(waitTimeFare * 100)) / 100f;
- return waitTimeFare;
- }
- public void updateTimer() {
- String selId = getApp().prefsSmall.getString("selectedTrack", "");
- if (tv_total_time_value != null) {
- tv_total_time_value.setText(Track.getTimeElapsedStr(getApp(), selId));
- }
- }
- public void updateWaitTimer() {
- String selId = getApp().prefsSmall.getString("selectedTrack", "");
- if (!Track.getIsWaitTracking(getApp(), selId)) {
- return;
- }
- if (tv_wait_time_value != null) {
- tv_wait_time_value.setText(Track.getWaitTimeElapsedStr(getApp(), selId));
- }
- }
- public void update() {
- if (!locked && SystemTime.getSystemTime() - timeUnlocked > 7000) {
- locked = true;
- btn_locked.setBackgroundResource(R.drawable.btn_locked);
- lockedSetting();
- }
- }
- private void lockedSetting() {
- btn_reset_total.setVisibility(View.GONE);
- btn_play_pause_total.setVisibility(View.GONE);
- btn_play_pause_wait.setVisibility(View.GONE);
- btn_reset_wait.setVisibility(View.GONE);
- btn_locked.setBackgroundResource(R.drawable.btn_locked);
- }
- private void unLockedSetting() {
- btn_reset_total.setVisibility(View.VISIBLE);
- btn_play_pause_total.setVisibility(View.VISIBLE);
- btn_play_pause_wait.setVisibility(View.VISIBLE);
- btn_reset_wait.setVisibility(View.VISIBLE);
- btn_locked.setBackgroundResource(R.drawable.btn_unlocked);
- String selId = getApp().prefsSmall.getString("selectedTrack", "");
- if (!getApp().prefsSmall.getBoolean(selId + "isTracking", false)) {
- btn_play_pause_total.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.play, 0, 0);
- } else {
- btn_play_pause_total.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.pause, 0, 0);
- }
- if (!Track.getIsWaitTracking(app, selId)) {
- btn_play_pause_wait.setImageResource(R.drawable.play_min);
- } else {
- btn_play_pause_wait.setImageResource(R.drawable.pause_min);
- }
- }
- @Override
- public void onResume() {
- super.onResume();
- SharedPreferences.Editor e = PreferenceManager.getDefaultSharedPreferences(this).edit();
- e.putString("last_activity", getClass().getSimpleName());
- e.commit();
- if (timer == null) {
- timer = new UITimer(handler);
- timer.start();
- }
- updateDistanceAndDisplacement();
- updateFare(false);
- updateTimer();
- updateWaitTimer();
- update();
- String selId = getApp().prefsSmall.getString("selectedTrack", "");
- if (!selId.equals("")) {
- if (getApp().prefsSmall.getBoolean(selId + "isTracking", false)) {
- btn_play_pause_total.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.pause, 0, 0);
- }
- if (Track.getIsWaitTracking(getApp(), selId)) {
- btn_play_pause_wait.setImageResource(R.drawable.pause_min);
- }
- }
- }
- @Override
- public void onPause() {
- super.onPause();
- timer.shutdown();
- timer = null;
- }
- private OnClickListener lockedClicked = new OnClickListener() {
- @Override
- public void onClick(View v) {
- String selId = getApp().prefsSmall.getString("selectedTrack", "");
- if (locked) { //start unlocking process
- unLockedSetting();
- locked = false;
- timeUnlocked = SystemTime.getSystemTime();
- } else {
- btn_locked.setBackgroundResource(R.drawable.btn_locked);
- locked = true;
- lockedSetting();
- }
- }
- };
- private OnClickListener playPauseTotalClicked = new OnClickListener() {
- @Override
- public void onClick(View v) {
- startService(new Intent(DriverMeterActivity.this, LocationService.class));
- String selId = getApp().prefsSmall.getString("selectedTrack", "");
- if (!locked || Track.getTimeElapsedLong(getApp(), selId) < 2000) {
- if (!getApp().prefsSmall.getBoolean(selId + "isTracking", false)) {
- if (selId.equals("")) {
- selId = Track.generateId(getApp(), orderRequest.getOrderId());
- getApp().prefsSmall.edit().putString("selectedTrack", selId).commit();
- }
- long timeSinceLast = SystemTime.getSystemTime() - getApp().timeOfLastSignal;
- float lastAcc = 1000;
- if (getApp().lastLocation != null) {
- lastAcc = getApp().lastLocation.getAccuracy();
- }
- if (lastAcc > Float.valueOf(IncarApp.prefsMinAccuracy) || timeSinceLast > 4000) {
- int nt = getApp().prefsSmall.getInt("timesShownMinAccWarn", 0);
- if (nt < 4) {
- getApp().prefsSmall.edit().putInt("timesShownMinAccWarn", nt + 1).commit();
- Ut.showNotification("", getApp().getResources().getString(R.string.warn_min_accuracy), DriverMeterActivity.this);
- }
- }
- Track.startTracking(getApp(), selId);
- unLockedSetting();
- } else {
- Track.stopTracking(getApp(), selId);
- if (!Track.isAnyTracking(getApp())) {
- startService(new Intent(DriverMeterActivity.this, LocationService.class).putExtra("stop", true));
- }
- unLockedSetting();
- }
- } else {
- Toast.makeText(DriverMeterActivity.this, getApp().getResources().getString(R.string.unlock_it_first), Toast.LENGTH_LONG).show();
- }
- }
- };
- private OnClickListener resetTotalClicked = new OnClickListener() {
- @Override
- public void onClick(View v) {
- if (!locked) {
- String selId = getApp().prefsSmall.getString("selectedTrack", "");
- if (Track.getTimeElapsedLong(getApp(), selId) == 0) {
- Ut.showToast(DriverMeterActivity.this, getApp().getResources().getString(R.string.no_trip_to_clear));
- }
- Track.clearTrip(getApp(), selId);
- updateDistanceAndDisplacement();
- updateTimer();
- update();
- Calendar cal = Calendar.getInstance();
- cal.setTimeInMillis(Track.getStartTime(getApp(), selId));
- if (cabCategoryFareType != null)
- setFareInformation(cabCategoryFareType);
- } else {
- Ut.showToast(DriverMeterActivity.this, getApp().getResources().getString(R.string.unlock_it_first));
- }
- }
- };
- private void startEndJourneyButtonClicked(boolean confirmationRequired, float rate, double tips, double parking, double tolls) {
- <<<<<<< HEAD
- endJourney = new EndJourney();
- endJourney.setActualDayDistance(dayDistance);
- endJourney.setActualNightDistance(nightDistance);
- endJourney.setF_baseFare(f_baseFare);
- endJourney.setF_distanceFare(f_distanceFare);
- endJourney.setF_waitTimeFare(f_waitTimeFare);
- endJourney.setF_hireTimeFare(f_hireTimeFare);
- endJourney.setF_bookingFeesFare(f_bookingFeesFare);
- endJourney.setF_tips(tips);
- endJourney.setF_tolls(tolls);
- endJourney.setF_parking(parking);
- =======
- orderId = orderRequest.getOrderId();
- orderFinish = new OrderFinish();
- orderFinish.setOrderId(orderId);
- orderFinish.setDayDistance(dayDistance);
- orderFinish.setNightDistance(nightDistance);
- orderFinish.setBaseFare(f_baseFare);
- orderFinish.setDistanceFare(f_distanceFare);
- orderFinish.setWaitTimeFare(f_waitTimeFare);
- orderFinish.setHireTimeFare(f_hireTimeFare);
- orderFinish.setBookingFee(f_bookingFeesFare);
- orderFinish.setTip(tips);
- orderFinish.setTollFare(tolls);
- orderFinish.setParkingFare(parking);
- >>>>>>> c77e3683aef9bc5c8dafaa3ad4513a0842185100
- if (promo != null) {
- orderFinish.setDiscountFare(fare - f_discountFare);
- f_discountFare = f_distanceFare + tips + tolls + parking;
- orderFinish.setTotalFare(f_discountFare);
- } else {
- orderFinish.setDiscountFare(0);
- fare = fare + tips + tolls + parking;
- orderFinish.setTotalFare(fare);
- }
- orderFinish.setPackageFare(f_packageFare);
- String selId = getApp().prefsSmall.getString("selectedTrack", "");
- orderFinish.setTotalTimeFormatted(Track.getTimeElapsedStr(getApp(), selId));
- orderFinish.setTotalTime(Track.getTimeElapsedLong(getApp(), selId));
- orderFinish.setTotalWaitTimeFormatted(Track.getWaitTimeElapsedStr(getApp(), selId));
- orderFinish.setTotalWaitTime(Track.getWaitTimeElapsedLong(getApp(), selId));
- if (confirmationRequired) {
- showTripSummaryPopup();
- } else {
- api.getOrdersApi().finish(orderId, orderFinish)
- .compose(applyComputeSchedulers())
- .doOnSubscribe(this::showProgressBar)
- .doOnCompleted(this::hideProgressBar)
- .subscribe(new NetworkSubscriber<OrderFinish.Response>(this) {
- @Override
- public void onError(Throwable e) {
- super.onError(e);
- Log.e(TAG, e.getMessage(), e);
- hideProgressBar();
- }
- @Override
- public void onNext(OrderFinish.Response response) {
- closeDriverMeter();
- Intents.openDriverTripInfoActivity(DriverMeterActivity.this, response);
- finish();
- }
- });
- }
- }
- public void showOkConfirmation(String message, String first, String initialDistance, String pkm, String min, boolean endJourney, int hireOrMin) {
- String currency = "";
- if (cabCategoryFareType != null)
- currency = cabCategoryFareType.getCurrency();
- updateFare(false);
- double totalFare = (Math.round(fare * 100)) / 100f;
- double actualFare = totalFare;
- double discount = 0;
- if (promo != null) {
- updateFare(true);
- totalFare = (Math.round(f_discountFare * 100)) / 100f;
- discount = actualFare - totalFare;
- }
- DriverDialogFareActivity.Builder builder = new DriverDialogFareActivity.Builder(this);
- builder.setTitle("")
- .setMessage(message)
- .setFirst(first)
- .setInitialDistance(initialDistance)
- .setPkm(pkm)
- .setMin(min)
- .setDistance(tv_dist.getText().toString())
- .setTime(tv_total_time_value.getText().toString())
- .setTotalFare(DecimalFormating.getStringFormatted(totalFare))
- .setActualFare(DecimalFormating.getStringFormatted(actualFare))
- .setIsEndJourney(endJourney)
- .setHireOrMin(hireOrMin)
- .setCurrency(currency)
- .setCity(app.getCabType() != null ? app.getCabType().getCity() : "")
- .setPositiveButton(getString(R.string.status_ok)).setImageSource(0);
- if (discount > 0) {
- builder.setDiscount(DecimalFormating.getStringFormatted(discount));
- }
- if (endJourney) {
- builder.show(REQUEST_INFO_END_JOURNEY);
- } else {
- builder.show(REQUEST_INFO);
- }
- }
- @Override
- public void onBackPressed() {
- // moveTaskToBack(true); do nothing
- }
- private void showDriverDialogFareActivity(boolean showEndJourney) {
- String currency = "";
- if (cabCategoryFareType != null)
- currency = cabCategoryFareType.getCurrency();
- String message = getString(R.string.total_dist) + " " + distance + " \n" + getString(R.string.total_fare) + " " + currency + " " + DecimalFormating.getStringFormatted(fare);
- int hireOrMin = 0;
- String sMinFare = DecimalFormating.getStringFormatted(minFare);
- if (cabCategoryFareType != null) {
- if (cabCategoryFareType.getHireTimeFareDay() != null && cabCategoryFareType.getHireTimeFareDay().doubleValue() > 0) {
- hireOrMin = 1;
- sMinFare = DecimalFormating.getStringFormatted(cabCategoryFareType.getHireTimeFareDay());
- }
- }
- showOkConfirmation(message, DecimalFormating.getStringFormatted(initialFare), DecimalFormating.getStringFormatted(minDistance), DecimalFormating.getStringFormatted(perKmCost), sMinFare, showEndJourney, hireOrMin);
- }
- private OnClickListener playPauseWaitClicked = new OnClickListener() {
- @Override
- public void onClick(View v) {
- String selId = getApp().prefsSmall.getString("selectedTrack", "");
- if (!locked || (Track.getWaitTimeLast(app, selId) < 2000 && Track.getIsWaitTracking(app, selId))) {
- if (!Track.getIsWaitTracking(app, selId)) {
- btn_play_pause_wait.setImageResource(R.drawable.pause_min);
- Track.startTimerWait(getApp(), selId);
- } else {
- btn_play_pause_wait.setImageResource(R.drawable.play_min);
- Track.stopTimerWait(getApp(), selId);
- }
- // lockedSetting();
- } else {
- Toast.makeText(DriverMeterActivity.this, getApp().getResources().getString(R.string.unlock_it_first), Toast.LENGTH_LONG).show();
- }
- }
- };
- private OnClickListener resetWaitClicked = new OnClickListener() {
- @Override
- public void onClick(View v) {
- if (!locked) {
- String selId = getApp().prefsSmall.getString("selectedTrack", "");
- Track.clearWaitTimer(getApp(), selId);
- tv_wait_time_value.setText(Track.getWaitTimeElapsedStr(getApp(), selId));
- } else {
- Ut.showToast(DriverMeterActivity.this, getApp().getResources().getString(R.string.unlock_it_first));
- }
- }
- };
- private OnClickListener phoneClicked = new OnClickListener() {
- @Override
- public void onClick(View v) {
- String telUrl = "tel:" + orderRequest.getPhone();
- Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(telUrl));
- startActivity(intent);
- }
- };
- private OnClickListener currencyClicked = new OnClickListener() {
- @Override
- public void onClick(View v) {
- showDriverDialogFareActivity(false);
- }
- };
- private OnClickListener mapClicked = new OnClickListener() {
- @Override
- public void onClick(View v) {
- LatLng latLng = null;
- String description = "";
- if (orderRequest.getEndLocation() != null) {
- latLng = orderRequest.getEndLocation().getLatLng();
- description = orderRequest.getEndLocation().getDescription();
- }
- boolean activityFound = true;
- if (latLng != null) {
- try {
- String uri = String.format(Locale.ENGLISH, "http://maps.google.com/maps?daddr=%f,%f (%s)", latLng.latitude, latLng.longitude, description);
- Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
- intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- getBaseContext().startActivity(intent);
- } catch (Exception ex) {
- activityFound = false;
- }
- }
- if (activityFound)
- return;
- Intent intent = new Intent(DriverMeterActivity.this, MapMoreInfoPopupActivity.class);
- orderRequest.setStatus(Order.STATUS_STARTED);
- intent.putExtra(Constants.EXTRA_ORDER, orderRequest);
- startActivity(intent);
- }
- };
- Handler handler = new IncomingHandler(this);
- class IncomingHandler extends Handler {
- private final WeakReference<DriverMeterActivity> mTarget;
- IncomingHandler(DriverMeterActivity target) {
- mTarget = new WeakReference<DriverMeterActivity>(target);
- }
- @Override
- public void handleMessage(Message msg) {
- DriverMeterActivity target = mTarget.get();
- if (target != null) {
- if (msg.obj instanceof String) {
- String mess = ((String) msg.obj);
- if (mess.equals("update")) {
- update();
- updateDistanceAndDisplacement();
- updateTimer();
- updateWaitTimer();
- updateFare(false);
- } else if (mess.equals("relock")) {
- locked = true;
- lockedSetting();
- }
- }
- }
- }
- }
- private IncarApp getApp() {
- return app;
- }
- final class UITimer extends Thread {
- Handler mHandler;
- private volatile boolean done = false;
- private volatile boolean paused = false;
- public UITimer(Handler h) {
- this.mHandler = h;
- }
- public void shutdown() {
- done = true;
- }
- @Override
- public synchronized void run() {
- w:
- while (true) {
- if (done)
- break w;
- if (!paused) {
- if (!locked && SystemTime.getSystemTime() - timeUnlocked > 7000) {
- Message msg = mHandler.obtainMessage();
- msg.obj = "relock";
- mHandler.sendMessage(msg);
- }
- Message msg = mHandler.obtainMessage();
- msg.obj = "update";
- mHandler.sendMessage(msg);
- }
- try {
- Thread.sleep(990);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
- }
- <<<<<<< HEAD
- private class EndJourneyTask extends DialogApiAsyncTask<EndJourneyResponseAmount> {
- private long orderId;
- private float rate;
- private EndJourney endJourney;
- @Inject
- private DriverOrderManager orderManager;
- protected EndJourneyTask(Context context, long orderId, EndJourney endJourney, float rate) {
- super(context);
- this.orderId = orderId;
- this.endJourney = endJourney;
- this.rate = rate;
- }
- @Override
- public EndJourneyResponseAmount call() throws Exception {
- EndJourneyResponseAmount amount = orderManager.endJourney(orderId, endJourney, rate);
- return amount;
- }
- @Override
- protected void onSuccess(EndJourneyResponseAmount endJourneyResponseAmount) throws Exception {
- // EndJourneyResponseAmount endJourneyResponseAmount = DriverOrderManager.endJourneyResponseAmount;
- // Log.e("paveltest", endJourneyResponseAmount.toString());
- if (endJourneyResponseAmount!=null && endJourneyResponseAmount.getMessage()!=null && endJourneyResponseAmount.getMessage().contains("wallet")) {
- // final Dialog dialog = new Dialog(DriverMeterActivity.this);
- // dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
- // dialog.setContentView(R.layout.dialog_amount);
- // TextView amountTextView = (TextView) dialog.findViewById(R.id.dialog_amount_textView);
- //Button okButton = (Button) dialog.findViewById(R.id.dialog_amount_ok_button);
- String message = getResources().getString(R.string.amount_credited);
- showCreditedAmt(String.format(message, endJourneyResponseAmount.getAmount()), 0);
- // amountTextView.setText();
- // okButton.setOnClickListener(new OnClickListener() {
- // @Override
- // public void onClick(View view) {
- // dialog.cancel();
- // closeDriverMeter(context);
- // }
- // });
- // dialog.show();
- } else if (endJourneyResponseAmount!=null) {
- closeDriverMeter();
- } else{
- ToastFactory.generateStatic(getBaseContext(), getString(R.string.finished_error), Toast.LENGTH_LONG);
- }
- }
- }
- public class OrderHistory extends DialogApiAsyncTask<List<Order>> {
- List<Order> result=null;
- protected OrderHistory(Context context){
- super(context);
- }
- @Inject
- private DriverOrderManager orderManager;
- public List<Order> call() {
- //orderRequest.getFinishedOrders()
- try {
- result= orderManager.getFinishedOrders(1);
- } catch (IOException e) {
- e.printStackTrace();
- } catch (JSONException e) {
- e.printStackTrace();
- }
- return result;
- }
- // begin the installation by opening the resulting file
- @Override
- protected void onSuccess(List<Order> result) {
- CachedFinishedOrdersDB db = CachedFinishedOrdersDB.getInstance(getBaseContext());
- orderRequest=result.get(0);
- String currency = getString(R.string.Rs);
- if(cabCategoryFareType!=null && cabCategoryFareType.getCurrency()!=null){
- currency = cabCategoryFareType.getCurrency();
- }
- orderRequest.setCurrency(currency);
- db.addDB(orderRequest);
- finishedOrderHistory();
- }
- }
- private void finishedOrderHistory(){
- Intent intent = new Intent(this, FinishedOrderList.class);
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- startActivity(intent);
- finish();
- }
- private void closeDriverMeter(){
- =======
- private void closeDriverMeter() {
- >>>>>>> c77e3683aef9bc5c8dafaa3ad4513a0842185100
- String selId = getApp().prefsSmall.getString("selectedTrack", "");
- Track.destroy(getApp(), selId);
- if (!Track.isAnyTrackThere(getApp())) {
- startService(new Intent(DriverMeterActivity.this, LocationService.class).putExtra("stop", true));
- }
- <<<<<<< HEAD
- //addToDB();
- new OrderHistory(this).execute();
- /*Intent intent = new Intent(this, FinishedOrderList.class);
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- startActivity(intent);
- finish();*/
- =======
- addToDB();
- >>>>>>> c77e3683aef9bc5c8dafaa3ad4513a0842185100
- }
- private void closeDriverMeterinError() {
- ToastFactory.generateStatic(this.getBaseContext(), getResources().getString(R.string.finished_error), Toast.LENGTH_LONG);
- finish();
- }
- private void addToDB() {
- CachedFinishedOrdersDB db = CachedFinishedOrdersDB.getInstance(getBaseContext());
- // if (topay != 0f) {
- // orderRequest.setActTotFare(topay);
- // } else {
- // orderRequest.setActTotFare(fare);
- // }
- String distStr = tv_dist.getText().toString();
- distStr = distStr.split(" ")[0];
- double dist = Double.parseDouble(distStr);
- orderRequest.setActDayDistance(dist);
- orderRequest.setActNightDistance(0);
- orderRequest.setActTotFare(topay);
- orderRequest.setCustomerPaid(remaining);
- String currency = getString(R.string.Rs);
- if (cabCategoryFareType != null && cabCategoryFareType.getCurrency() != null) {
- currency = cabCategoryFareType.getCurrency();
- }
- orderRequest.setCurrency(currency);
- db.addDB(orderRequest);
- }
- private class MeteredJourneyTask extends RoboAsyncTask<ApproximatedFareForType> {
- private long orderId;
- private String subStatus;
- @Inject
- private DriverOrderManager driverOrderManager;
- protected MeteredJourneyTask(Context context, long orderId) {
- super(context);
- this.orderId = orderId;
- this.subStatus = subStatus;
- }
- @Override
- public ApproximatedFareForType call() throws Exception {
- ApproximatedFareForType fareType = driverOrderManager.getFareInformation(orderId);
- return fareType;
- }
- @Override
- protected void onSuccess(ApproximatedFareForType fareType) throws Exception {
- if (fareType != null)
- setFareInformation(fareType);
- else
- closeDriverMeterinError();
- }
- }
- private void goToMenuScreen(int menu_option) {
- Log.d("DRIVERS", "Menu option to load UI - " + loginPrefs.getMenuOption());
- if (menu_option == 2) {
- Menu6BtnsActivity.start(this);
- } else {
- HomescreenActivity.start(this);
- Log.d("DRIVERS", "Go to menu after registration default");
- }
- finish();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment