Advertisement
Guest User

Untitled

a guest
Sep 1st, 2015
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.39 KB | None | 0 0
  1. package com.fasten.communication.data.history;
  2.  
  3. import android.os.Parcel;
  4. import android.os.Parcelable;
  5.  
  6. import com.fasten.communication.OrderStatus;
  7. import com.fasten.communication.OrderSubStatus;
  8. import com.fasten.utils.DateUtils;
  9. import com.google.gson.annotations.Expose;
  10. import com.google.gson.annotations.SerializedName;
  11.  
  12. import com.fasten.communication.tick.CustomerCost;
  13.  
  14. import java.text.SimpleDateFormat;
  15. import java.util.Arrays;
  16. import java.util.Calendar;
  17. import java.util.Date;
  18.  
  19. /**
  20.  * Created by ios on 30.04.15.
  21.  */
  22. public class OrderDetails implements Parcelable {
  23.  
  24.     @SerializedName("order_id")
  25.     String orderId;
  26.  
  27.     @SerializedName("start_address")
  28.     String startAddress;
  29.  
  30.     @SerializedName("end_address")
  31.     String endAddress;
  32.  
  33.     @SerializedName("track_url")
  34.     String trackUrl;
  35.  
  36.     @SerializedName("promo_code_discount")
  37.     int promoDiscount;
  38.  
  39.     @SerializedName("promo_code_desc")
  40.     String promoDescription;
  41.  
  42.     @SerializedName("customer_costs")
  43.     CustomerCost[] customerCosts;
  44.  
  45.     @SerializedName("car_info")
  46.     HistoryCarInfo carInfo;
  47.  
  48.     HistoryRating rating;
  49.  
  50.     @SerializedName("payment")
  51.     PaymentInfo paymentInfo;
  52.  
  53.     String comments;
  54.  
  55.     @SerializedName("driver_info")
  56.     DriverInfo driverInfo;
  57.  
  58.     Toll[] tolls;
  59.  
  60.     @SerializedName("lost_stuff_counter")
  61.     byte lostStuffCounter;
  62. // ------------------------------------- //
  63.     @SerializedName("start_date")
  64.     Date startDate;
  65.  
  66.     @SerializedName("end_date")
  67.     Date endDate;
  68.  
  69.     int total;
  70.  
  71.     @SerializedName("car_class")
  72.     int carClass;
  73.  
  74.     @SerializedName("car_capacity")
  75.     int carCapacity;
  76.  
  77.  
  78.     @Expose
  79.     @SerializedName("state")
  80.     OrderStatus state;
  81.  
  82.     @Expose
  83.     @SerializedName("sub_state")
  84.     OrderSubStatus subState;
  85. // ------------------------------ //
  86.     public static final Creator<OrderDetails> CREATOR = new Creator<OrderDetails>() {
  87.         @Override
  88.         public OrderDetails createFromParcel(Parcel source) {
  89.             return new OrderDetails(source);
  90.         }
  91.  
  92.         @Override
  93.         public OrderDetails[] newArray(int size) {
  94.             return new OrderDetails[size];
  95.         }
  96.     };
  97.  
  98.     private CustomerCost[] convertParcelableArray(Parcel parcel) {
  99.         Parcelable[] parcelableArray =
  100.                 parcel.readParcelableArray(CustomerCost.class.getClassLoader());
  101.         CustomerCost[] resultArray = null;
  102.         if (parcelableArray != null) {
  103.             resultArray = Arrays.copyOf(parcelableArray, parcelableArray.length, CustomerCost[].class);
  104.         }
  105.         return resultArray;
  106.     }
  107.  
  108.  
  109.     private OrderDetails(Parcel in) {
  110.         orderId = in.readString();
  111.         startAddress = in.readString();
  112.         endAddress = in.readString();
  113.         trackUrl = in.readString();
  114.         promoDiscount = in.readInt();
  115.         promoDescription = in.readString();
  116.         customerCosts = convertParcelableArray(in);
  117.         carInfo = in.readParcelable(HistoryCarInfo.class.getClassLoader());
  118.         rating = in.readParcelable(HistoryRating.class.getClassLoader());
  119.         comments = in.readString();
  120.         driverInfo = in.readParcelable(DriverInfo.class.getClassLoader());
  121.         paymentInfo = in.readParcelable(PaymentInfo.class.getClassLoader());
  122.         tolls = in.createTypedArray(Toll.CREATOR);
  123.         lostStuffCounter = in.readByte();
  124.         // ------------------------- //
  125.         startDate = (Date) in.readSerializable();
  126.         endDate = (Date) in.readSerializable();
  127.         total = in.readInt();
  128.         carClass = in.readInt();
  129.         carCapacity = in.readInt();
  130.         state = (OrderStatus) in.readSerializable();
  131.         subState = (OrderSubStatus) in.readSerializable();
  132.         // ------------------------- //
  133.     }
  134.  
  135.     @Override
  136.     public int describeContents() {
  137.         return 0;
  138.     }
  139.  
  140.     @Override
  141.     public void writeToParcel(Parcel dest, int flags) {
  142.         dest.writeString(orderId);
  143.         dest.writeString(startAddress);
  144.         dest.writeString(endAddress);
  145.         dest.writeString(trackUrl);
  146.         dest.writeInt(promoDiscount);
  147.         dest.writeString(promoDescription);
  148.         dest.writeParcelableArray(customerCosts, flags);
  149.         dest.writeParcelable(carInfo, flags);
  150.         dest.writeParcelable(rating, flags);
  151.         dest.writeString(comments);
  152.         dest.writeParcelable(driverInfo, flags);
  153.         dest.writeParcelable(paymentInfo, flags);
  154.         dest.writeTypedArray(tolls, flags);
  155.         dest.writeByte(lostStuffCounter);
  156.         //-------------------------------- //
  157.         dest.writeSerializable(startDate);
  158.         dest.writeSerializable(endDate);
  159.         dest.writeInt(total);
  160.         dest.writeInt(carClass);
  161.         dest.writeInt(carCapacity);
  162.         dest.writeSerializable(state);
  163.         dest.writeSerializable(subState);
  164.         //------------------------------- //
  165.     }
  166.  
  167.     public PaymentInfo getPaymentInfo() {
  168.         return paymentInfo;
  169.     }
  170.  
  171.     public String getOrderId() {
  172.         return orderId;
  173.     }
  174.  
  175.     public CustomerCost[] getCustomerCosts() {
  176.         return customerCosts;
  177.     }
  178.  
  179.     public String getStartAddress() {
  180.         return startAddress;
  181.     }
  182.  
  183.     public String getEndAddress() {
  184.         return endAddress;
  185.     }
  186.  
  187.     public String getTrackUrl() {
  188.         return trackUrl;
  189.     }
  190.  
  191.     public int getPromoDiscount() {
  192.         return promoDiscount;
  193.     }
  194.  
  195.     public String getPromoDescription() {
  196.         return promoDescription;
  197.     }
  198.  
  199.     public HistoryCarInfo getCarInfo() {
  200.         return carInfo;
  201.     }
  202.  
  203.     public HistoryRating getRating() {
  204.         return rating;
  205.     }
  206.  
  207.     public String getComments() {
  208.         return comments;
  209.     }
  210.  
  211.     public DriverInfo getDriverInfo() {
  212.         return driverInfo;
  213.     }
  214.  
  215.     public Toll[] getTolls() {
  216.         return tolls;
  217.     }
  218.     public boolean isHotCall() {
  219.         if(getCustomerCosts()[0].getHotCoefficient() > 1) {
  220.             return true;
  221.         }
  222.         return false;
  223.     }
  224.     static SimpleDateFormat TIME_FORMAT = new SimpleDateFormat("HH:mm");
  225.     public String getStartTime() {
  226.         Calendar calendar = Calendar.getInstance();
  227.         TIME_FORMAT.setTimeZone(calendar.getTimeZone());
  228.         return TIME_FORMAT.format(startDate);
  229.     }
  230.  
  231.     public String getEndTime() {
  232.         Calendar calendar = Calendar.getInstance();
  233.         TIME_FORMAT.setTimeZone(calendar.getTimeZone());
  234.         return TIME_FORMAT.format(endDate);
  235.     }
  236.  
  237.     public String getOnlyStartDate() {
  238.         return DateUtils.formatDate(startDate);
  239.     }
  240.     public byte getLostStuffCounter() {
  241.         return lostStuffCounter;
  242.     }
  243.  
  244.     public void setLostStuffCounter(byte lostStuffCounter) {
  245.         this.lostStuffCounter = lostStuffCounter;
  246.     }
  247.  
  248.     public Date getStartDate() {
  249.         return startDate;
  250.     }
  251.  
  252.     public Date getEndDate() {
  253.         return endDate;
  254.     }
  255.  
  256.     public int getTotal() {
  257.         return total;
  258.     }
  259.  
  260.     public int getCarClass() {
  261.         return carClass;
  262.     }
  263.  
  264.     public int getCarCapacity() {
  265.         return carCapacity;
  266.     }
  267.  
  268.  
  269.     public OrderStatus getState() {
  270.         return state;
  271.     }
  272.  
  273.     public OrderSubStatus getSubState() {
  274.         return subState;
  275.     }
  276.     public boolean isCancelled() {
  277.         return subState == OrderSubStatus.CUSTOMER_CANCEL_BEFORE_TRIP || subState == OrderSubStatus.CUSTOMER_CANCEL_BEFORE_ARRIVE;
  278.     }
  279. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement