Просмотр исходного кода

1.修改Android Apex Drivers位置上传参数。
2.修改Android Apex Drivers多图保存与恢复。

Pen Li 7 лет назад
Родитель
Сommit
cba2ed4d92

+ 15 - 21
ApexDrivers/apexdriverslib/src/main/java/com/usai/redant/apexdrivers/ApexDriverApplication.java

@@ -559,13 +559,13 @@ public class ApexDriverApplication extends Application {
         this.backgroundReportType = reportType;
     }
 
-    public void reportLocationForOrder(@Nullable final String location, final String orderId) {
+    public void reportLocationForOrder(@Nullable final Location location, final String orderId, final String locationId) {
 
         getNetworkQueue().addOperationTask(new OperationQueue.OperationBackgroundCallBack() {
             @Override
             public Object operationDoInBackground() {
 
-                Network.reportLocation(location,orderId);
+                Network.reportLocation(location,orderId,locationId);
 
                 return null;
             }
@@ -573,13 +573,13 @@ public class ApexDriverApplication extends Application {
 
     }
 
-    public void rejectReportLocation(final String reason, final String orderId) {
+    public void rejectReportLocation(final String reason, final String orderId, final String locationId) {
 
         getNetworkQueue().addOperationTask(new OperationQueue.OperationBackgroundCallBack() {
             @Override
             public Object operationDoInBackground() {
 
-                Network.rejectReportLocation(reason,orderId);
+                Network.rejectReportLocation(reason,orderId, locationId);
 
                 return null;
             }
@@ -587,7 +587,7 @@ public class ApexDriverApplication extends Application {
 
     }
 
-    public void reportLocationForOrder(final String orderId) {
+    public void handlLocationRequestForOrder(final String orderId, final String locationId) {
 
         switch (backgroundReportType) {
             case BackgroundReportTypeNone: {
@@ -597,7 +597,7 @@ public class ApexDriverApplication extends Application {
             case BackgroundReportTypeReject: {
 
                 String reason = "Driver " + user +" rejected to report location";
-                rejectReportLocation(reason,orderId);
+                rejectReportLocation(reason,orderId,locationId);
             }
             break;
             case BackgroundReportTypeAlways: {
@@ -610,8 +610,8 @@ public class ApexDriverApplication extends Application {
                                 @Override
                                 public void onClick(DialogInterface dialog, int which) {
 
-                                    String location = null;
-                                    reportLocationForOrder(location,orderId);
+                                    Location location = getCurrentLocation();
+                                    reportLocationForOrder(location,orderId,locationId);
                                 }
                             })
                             .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@@ -619,7 +619,7 @@ public class ApexDriverApplication extends Application {
                                 public void onClick(DialogInterface dialog, int which) {
 
                                     String reason = "Driver " + user +" cancel to report location";
-                                    rejectReportLocation(reason,orderId);
+                                    rejectReportLocation(reason,orderId,locationId);
                                 }
                             })
                             .show();
@@ -630,11 +630,8 @@ public class ApexDriverApplication extends Application {
             case BackgroundReportTypeAllow: {
 
                 Location location = getCurrentLocation();
-                String latlon = "-999,-999";
-                if (location != null) {
-                    latlon = location.getLatitude() + "," + location.getLongitude();
-                }
-                reportLocationForOrder(latlon,orderId);
+
+                reportLocationForOrder(location,orderId,locationId);
             }
             break;
         }
@@ -658,6 +655,7 @@ public class ApexDriverApplication extends Application {
 
                 int report_location = aps.optInt("report-location",0);
                 final String orderID = aps.optString("order-id");
+                final String locationId = aps.optString("location-id");
 
                 if (report_location != 0) {
 
@@ -667,22 +665,18 @@ public class ApexDriverApplication extends Application {
                         if (backgroundReportType == BackgroundReportTypeAllow) {
 
                             Location location = getCurrentLocation();
-                            String latlon = "-999,-999";
-                            if (location != null) {
-                                latlon = location.getLatitude() + "," + location.getLongitude();
-                            }
-                            reportLocationForOrder(latlon,orderID);
+                            reportLocationForOrder(location,orderID, locationId);
 
                         } else {
 
                             String reason = "Driver " + user +" rejected to report location";
-                            rejectReportLocation(reason,orderID);
+                            rejectReportLocation(reason,orderID, locationId);
                         }
 
                         return;
                     }
 
-                    reportLocationForOrder(orderID);
+                    handlLocationRequestForOrder(orderID,locationId);
 
                 } else {
 

+ 1 - 1
ApexDrivers/apexdriverslib/src/main/java/com/usai/redant/apexdrivers/MainActivity.java

@@ -414,7 +414,7 @@ public class MainActivity extends BasicActivity implements LoginFragment.LoginCa
             new AlertDialog.Builder(this)
                     .setTitle(getString(R.string.warning))
                     .setMessage(getString(R.string.notification_enable_msg))
-                    .setPositiveButton(getString(R.id.btn_ok), new DialogInterface.OnClickListener() {
+                    .setPositiveButton(getString(R.string.btn_ok), new DialogInterface.OnClickListener() {
                         @Override
                         public void onClick(DialogInterface dialog, int which) {
                             openSystemSetting();

+ 23 - 3
ApexDrivers/apexdriverslib/src/main/java/com/usai/redant/apexdrivers/network/Network.java

@@ -3,6 +3,7 @@ package com.usai.redant.apexdrivers.network;
 
 import android.app.Application;
 import android.content.Context;
+import android.location.Location;
 import android.os.Bundle;
 import android.text.TextUtils;
 
@@ -278,24 +279,39 @@ public class Network extends com.usai.redant.rautils.utils.Network {
         getJson(URL_LOGOUT,params);
     }
 
-    public static void reportLocation(String location, String orderId) {
+    public static void reportLocation(Location location, String orderId, final String locationId) {
 
         Bundle params = new Bundle();
+
+
+        String latlon = "-999,-999";
         if (location != null) {
-            params.putString("location",location);
+
+            if (location != null) {
+                latlon = location.getLatitude() + "," + location.getLongitude();
+            }
+
+            params.putLong("timestamp",location.getTime());
+            params.putFloat("speed",location.getSpeed());
         }
+        params.putString("location",latlon);
+
 
         if (orderId != null) {
             params.putString("orderID",orderId);
         }
 
+        if (locationId != null) {
+            params.putString("locationId",locationId);
+        }
+
         params.putInt("userOption",0);
 
         prepareParams(params);
         getJson(URL_REPORT_LOCATION,params);
     }
 
-    public static void rejectReportLocation(String reason, String orderId) {
+    public static void rejectReportLocation(String reason, String orderId, final String locationId) {
 
         Bundle params = new Bundle();
         if (reason != null) {
@@ -306,6 +322,10 @@ public class Network extends com.usai.redant.rautils.utils.Network {
             params.putString("orderID",orderId);
         }
 
+        if (locationId != null) {
+            params.putString("locationId",locationId);
+        }
+
         params.putInt("userOption",1);
 
         prepareParams(params);

+ 21 - 0
ApexDrivers/apexdriverslib/src/main/java/com/usai/redant/apexdrivers/photoCell/PhotoItemModel.java

@@ -9,6 +9,9 @@ import com.usai.redant.apexdrivers.base.BasicObject;
 import com.usai.redant.apexdrivers.utils.OperationQueue;
 import com.usai.redant.rautils.utils.ImageUtil;
 
+import org.json.JSONException;
+import org.json.JSONObject;
+
 import java.lang.ref.WeakReference;
 import java.net.URI;
 
@@ -103,4 +106,22 @@ public class PhotoItemModel extends BasicObject {
     public boolean isEmpty() {
         return photo == null;
     }
+
+    public JSONObject model2Json() {
+
+        try {
+
+            JSONObject json = new JSONObject();
+            if (url != null) {
+                json.put("url",url);
+            }
+            if (placeHolder != null) {
+                json.put("placeHolder",placeHolder);
+            }
+        }
+        catch (JSONException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
 }

+ 34 - 0
ApexDrivers/apexdriverslib/src/main/java/com/usai/redant/apexdrivers/photoCell/PhotoModel.java

@@ -3,6 +3,7 @@ package com.usai.redant.apexdrivers.photoCell;
 import com.usai.redant.apexdrivers.base.BasicObject;
 
 import org.json.JSONArray;
+import org.json.JSONException;
 import org.json.JSONObject;
 
 import java.lang.ref.WeakReference;
@@ -65,4 +66,37 @@ public class PhotoModel extends BasicObject {
         }
         return models;
     }
+
+    public JSONObject model2Json() {
+
+        try {
+            JSONObject json = new JSONObject();
+            json.put("type",type);
+            if (title != null) {
+                json.put("title",title);
+            }
+            if (key != null) {
+                json.put("key",key);
+            }
+            json.put("required",required);
+
+            JSONArray photos = new JSONArray();
+            if (photoArray != null && photoArray.size() > 0) {
+
+                for(PhotoItemModel model : photoArray) {
+                    JSONObject item = model.model2Json();
+                    if (item != null) {
+                        photos.put(item);
+                    }
+                }
+
+            }
+            json.put("photos",photos);
+
+            return json;
+        } catch (JSONException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
 }

+ 26 - 26
ApexDrivers/apexdriverslib/src/main/java/com/usai/redant/apexdrivers/receiver/ApexDriverAlarmReceiver.java

@@ -159,32 +159,32 @@ public class ApexDriverAlarmReceiver extends AlarmReceiver {
             @Override
             public void run() {
 
-//                if (ApexDriverApplication.sharedApplication().isLogin()) {
-//
-//                    JSONObject json = com.usai.redant.apexdrivers.network.Network.pullNotification();
-//
-//                    if (json != null) {
-//
-//                        int result = json.optInt("result",0);
-//                        if (result == RESULT_TRUE) {
-//
-//                            JSONArray notifications = json.optJSONArray("notifications");
-//                            if (notifications != null) {
-//
-//                                for (int i = 0; i < notifications.length(); i++) {
-//                                    JSONObject notification = notifications.optJSONObject(i);
-//                                    if (notification != null) {
-//                                        ApexDriverApplication.sharedApplication().receiveNotificationOnMainThread(notification);
-//                                    }
-//                                }
-//
-//                            }
-//
-//                        }
-//
-//                    }
-//
-//                }
+                if (ApexDriverApplication.sharedApplication().isLogin()) {
+
+                    JSONObject json = com.usai.redant.apexdrivers.network.Network.pullNotification();
+
+                    if (json != null) {
+
+                        int result = json.optInt("result",0);
+                        if (result == RESULT_TRUE) {
+
+                            JSONArray notifications = json.optJSONArray("notifications");
+                            if (notifications != null) {
+
+                                for (int i = 0; i < notifications.length(); i++) {
+                                    JSONObject notification = notifications.optJSONObject(i);
+                                    if (notification != null) {
+                                        ApexDriverApplication.sharedApplication().receiveNotificationOnMainThread(notification);
+                                    }
+                                }
+
+                            }
+
+                        }
+
+                    }
+
+                }
 
             }
         }).start();

+ 16 - 0
ApexDrivers/apexdriverslib/src/main/java/com/usai/redant/apexdrivers/update/model/UpdateBaseModel.java

@@ -62,6 +62,22 @@ public class UpdateBaseModel extends BasicObject {
             }
             json.put("required",required);
 
+            json.put("autofill",autofill);
+            if (expand != null) {
+
+                if (expand instanceof JSONObject) {
+
+                    json.put("expand",expand);
+                } else {
+
+                    UpdateBaseModel expandModel = (UpdateBaseModel)expand;
+                    JSONObject expandJson = expandModel.model2Json();
+                    if (expandJson != null) {
+                        json.put("expand",expandJson);
+                    }
+                }
+            }
+
             return json;
         } catch (JSONException e) {
             e.printStackTrace();

+ 22 - 0
ApexDrivers/apexdriverslib/src/main/java/com/usai/redant/apexdrivers/update/model/UpdateDateModel.java

@@ -1,5 +1,8 @@
 package com.usai.redant.apexdrivers.update.model;
 
+import org.json.JSONException;
+import org.json.JSONObject;
+
 import java.text.SimpleDateFormat;
 import java.util.Date;
 
@@ -52,4 +55,23 @@ public class UpdateDateModel extends UpdateBaseModel {
             weakDelegate.get().refresh();
         }
     }
+
+    @Override
+    public JSONObject model2Json() {
+        JSONObject json =  super.model2Json();
+
+        if (json != null) {
+            try {
+
+                json.put("format",format);
+                json.put("mode",mode);
+                json.put("editable",editable);
+
+
+            } catch (JSONException e) {
+                e.printStackTrace();
+            }
+        }
+        return json;
+    }
 }

+ 9 - 0
ApexDrivers/apexdriverslib/src/main/java/com/usai/redant/apexdrivers/update/model/UpdateMultPhotoModel.java

@@ -3,6 +3,7 @@ package com.usai.redant.apexdrivers.update.model;
 import com.usai.redant.apexdrivers.photoCell.PhotoItemModel;
 import com.usai.redant.apexdrivers.photoCell.PhotoModel;
 
+import org.json.JSONException;
 import org.json.JSONObject;
 
 import java.util.ArrayList;
@@ -65,4 +66,12 @@ public class UpdateMultPhotoModel extends UpdateBaseModel {
     public PhotoModel getMapModel() {
         return mapModel;
     }
+
+    @Override
+    public JSONObject model2Json() {
+        if (mapModel != null) {
+            return mapModel.model2Json();
+        }
+        return null;
+    }
 }

+ 1 - 0
ApexDrivers/apexdriverslib/src/main/res/layout/multiple_photo_item_cell.xml

@@ -11,6 +11,7 @@
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:layout_margin="1dp"
+        android:scaleType="centerCrop"
         />
 
 </com.usai.redant.apexdrivers.photoCell.PhotoItemCell>