|
|
@@ -4,11 +4,10 @@ import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
import android.os.Bundle;
|
|
|
import android.text.TextUtils;
|
|
|
-import android.util.Log;
|
|
|
+
|
|
|
|
|
|
import com.usai.redant.apexdrivers.ApexDriverApplication;
|
|
|
import com.usai.redant.apexdrivers.R;
|
|
|
-import com.usai.redant.apexdrivers.detail.model.DetailActionModel;
|
|
|
import com.usai.redant.apexdrivers.detail.model.DetailBaseModel;
|
|
|
import com.usai.redant.apexdrivers.home.HomeOrderModel;
|
|
|
import com.usai.redant.apexdrivers.update.model.UpdateImageBaseModel;
|
|
|
@@ -20,26 +19,23 @@ import org.json.JSONArray;
|
|
|
import org.json.JSONException;
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
-import java.io.BufferedInputStream;
|
|
|
-import java.io.BufferedOutputStream;
|
|
|
import java.io.File;
|
|
|
-import java.io.FileNotFoundException;
|
|
|
-import java.io.FileOutputStream;
|
|
|
-import java.io.InputStream;
|
|
|
-import java.io.OutputStream;
|
|
|
-import java.io.UnsupportedEncodingException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
-import java.util.Enumeration;
|
|
|
import java.util.Locale;
|
|
|
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
|
|
-import java.util.zip.ZipEntry;
|
|
|
-import java.util.zip.ZipFile;
|
|
|
-import java.util.zip.ZipOutputStream;
|
|
|
+
|
|
|
+
|
|
|
+import net.lingala.zip4j.core.ZipFile;
|
|
|
+import net.lingala.zip4j.exception.ZipException;
|
|
|
+import net.lingala.zip4j.model.FileHeader;
|
|
|
+import net.lingala.zip4j.model.ZipParameters;
|
|
|
+import net.lingala.zip4j.util.Zip4jConstants;
|
|
|
|
|
|
import static com.usai.redant.apexdrivers.detail.model.DetailSubActionModel.DetailActionSubType.DetailActionSubTypeAccept;
|
|
|
import static com.usai.redant.apexdrivers.network.Network.URL_UPLOAD;
|
|
|
+import static com.usai.redant.rautils.utils.Network.RESULT_TRUE;
|
|
|
|
|
|
public class OfflineHandler {
|
|
|
|
|
|
@@ -166,37 +162,22 @@ public class OfflineHandler {
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
- ZipFile zfile=new ZipFile(file.getAbsolutePath());
|
|
|
-
|
|
|
- Enumeration zList=zfile.entries();
|
|
|
-
|
|
|
- ZipEntry ze=null;
|
|
|
-
|
|
|
- byte[] buf=new byte[1024];
|
|
|
- while(zList.hasMoreElements()){
|
|
|
- ze=(ZipEntry)zList.nextElement();
|
|
|
- if(ze.isDirectory()){
|
|
|
-
|
|
|
- String zeDir = dir + ze.getName();
|
|
|
|
|
|
- File f=new File(zeDir);
|
|
|
-
|
|
|
- f.mkdir();
|
|
|
- continue;
|
|
|
- }
|
|
|
+ ZipFile zipFile = new ZipFile(file);
|
|
|
+ if (!zipFile.isValidZipFile()) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (zipFile.isEncrypted()) {
|
|
|
+ zipFile.setPassword(getZipPassword());
|
|
|
+ }
|
|
|
|
|
|
- File toFile = new File(dir + File.separator + ze.getName());
|
|
|
- OutputStream os=new BufferedOutputStream(new FileOutputStream(toFile));
|
|
|
- InputStream is=new BufferedInputStream(zfile.getInputStream(ze));
|
|
|
+ File dirF = new File(dir);
|
|
|
+ if (dirF.exists() && dirF.isDirectory()) {
|
|
|
|
|
|
- int readLen=0;
|
|
|
- while ((readLen=is.read(buf, 0, 1024))!=-1) {
|
|
|
- os.write(buf, 0, readLen);
|
|
|
- }
|
|
|
- is.close();
|
|
|
- os.close();
|
|
|
+ } else {
|
|
|
+ dirF.mkdirs();
|
|
|
}
|
|
|
- zfile.close();
|
|
|
+ zipFile.extractAll(dir);
|
|
|
|
|
|
return true;
|
|
|
|
|
|
@@ -204,73 +185,53 @@ public class OfflineHandler {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- private static void ZipFiles(String folderString, String fileString, java.util.zip.ZipOutputStream zipOutputSteam)throws Exception{
|
|
|
+ public File zipFile(String src, String dest) {
|
|
|
|
|
|
-
|
|
|
- if(zipOutputSteam == null)
|
|
|
- return;
|
|
|
-
|
|
|
- java.io.File file = new java.io.File(folderString+fileString);
|
|
|
-
|
|
|
- //判断是不是文件
|
|
|
- if (file.isFile()) {
|
|
|
-
|
|
|
- java.util.zip.ZipEntry zipEntry = new java.util.zip.ZipEntry(fileString);
|
|
|
- java.io.FileInputStream inputStream = new java.io.FileInputStream(file);
|
|
|
- zipOutputSteam.putNextEntry(zipEntry);
|
|
|
-
|
|
|
- int len;
|
|
|
- byte[] buffer = new byte[4096];
|
|
|
-
|
|
|
- while((len=inputStream.read(buffer)) != -1)
|
|
|
- {
|
|
|
- zipOutputSteam.write(buffer, 0, len);
|
|
|
- }
|
|
|
-
|
|
|
- zipOutputSteam.closeEntry();
|
|
|
+ if (TextUtils.isEmpty(src) || TextUtils.isEmpty(dest)) {
|
|
|
+ return null;
|
|
|
}
|
|
|
- else {
|
|
|
|
|
|
- //文件夹的方式,获取文件夹下的子文件
|
|
|
- String fileList[] = file.list();
|
|
|
+ File srcF = new File(src);
|
|
|
|
|
|
- //如果没有子文件, 则添加进去即可
|
|
|
- if (fileList.length <= 0) {
|
|
|
- java.util.zip.ZipEntry zipEntry = new java.util.zip.ZipEntry(fileString+java.io.File.separator);
|
|
|
- zipOutputSteam.putNextEntry(zipEntry);
|
|
|
- zipOutputSteam.closeEntry();
|
|
|
- }
|
|
|
-
|
|
|
- //如果有子文件, 遍历子文件
|
|
|
- for (int i = 0; i < fileList.length; i++) {
|
|
|
- ZipFiles(folderString, fileString+java.io.File.separator+fileList[i], zipOutputSteam);
|
|
|
- } // for
|
|
|
+ if (!srcF.exists()) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
|
|
|
- } //if
|
|
|
+ File destF = new File(dest);
|
|
|
+ if (destF.exists() && destF.isFile()) {
|
|
|
+ FileManager.deleteFile(destF);
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
|
|
|
- private File zipFolder(String folder, String dest) throws Exception {
|
|
|
+ try {
|
|
|
|
|
|
- ZipOutputStream outZip = null;
|
|
|
+ ZipFile zipFile = new ZipFile(dest);
|
|
|
|
|
|
- //创建Zip包
|
|
|
- outZip = new ZipOutputStream(new FileOutputStream(dest));
|
|
|
+ ZipParameters parameters = new ZipParameters();
|
|
|
+ parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
|
|
|
+ parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
|
|
|
|
|
|
- //打开要输出的文件
|
|
|
- File file = new File(folder);
|
|
|
+ parameters.setEncryptFiles(true);
|
|
|
+ parameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_STANDARD);
|
|
|
+ parameters.setPassword(getZipPassword());
|
|
|
|
|
|
- //压缩
|
|
|
- ZipFiles(file.getParent()+java.io.File.separator, file.getName(), outZip);
|
|
|
+ if (srcF.isDirectory()) {
|
|
|
+ zipFile.addFolder(srcF,parameters);
|
|
|
+ } else {
|
|
|
+ zipFile.addFile(srcF,parameters);
|
|
|
+ }
|
|
|
|
|
|
- outZip.finish();
|
|
|
- outZip.close();
|
|
|
+ return destF;
|
|
|
|
|
|
- return new File(dest);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
private boolean moveFile(String src, String destDir) {
|
|
|
@@ -282,25 +243,46 @@ public class OfflineHandler {
|
|
|
if (!srcFile.exists()) {
|
|
|
return false;
|
|
|
}
|
|
|
- File destFile = new File(destDir);
|
|
|
- if (destFile.exists() && destFile.isDirectory()) {
|
|
|
+
|
|
|
+ String name = srcFile.getName();
|
|
|
+
|
|
|
+ if (srcFile.isDirectory()) {
|
|
|
+
|
|
|
+ String destFolder = destDir + File.separator + name;
|
|
|
+ File destFolderF = new File(destFolder);
|
|
|
+ destFolderF.mkdirs();
|
|
|
+
|
|
|
+ File[] contents = srcFile.listFiles();
|
|
|
+ boolean success = true;
|
|
|
+ for (File f : contents) {
|
|
|
+ success = success && moveFile(f.getAbsolutePath(), destFolder);
|
|
|
+ }
|
|
|
+
|
|
|
+ return success;
|
|
|
|
|
|
} else {
|
|
|
- destFile.mkdirs();
|
|
|
- }
|
|
|
|
|
|
- String[] nodes = src.split(File.separator);
|
|
|
- String name = nodes[nodes.length - 1];
|
|
|
+ File destFile = new File(destDir);
|
|
|
+ if (destFile.exists() && destFile.isDirectory()) {
|
|
|
+
|
|
|
+ } else {
|
|
|
+ destFile.mkdirs();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ String destPath = destDir + File.separator + name;
|
|
|
+ File dest = new File(destPath);
|
|
|
+ if (dest.exists()) {
|
|
|
+ FileManager.deleteFile(dest);
|
|
|
+ }
|
|
|
+
|
|
|
+ boolean move = srcFile.renameTo(dest);
|
|
|
+
|
|
|
+ return move;
|
|
|
|
|
|
- String destPath = destDir + File.separator + name;
|
|
|
- File dest = new File(destPath);
|
|
|
- if (dest.exists()) {
|
|
|
- dest.delete();
|
|
|
}
|
|
|
|
|
|
- boolean move = srcFile.renameTo(dest);
|
|
|
|
|
|
- return move;
|
|
|
}
|
|
|
|
|
|
private boolean moveFile2Path(File src, String path) {
|
|
|
@@ -310,7 +292,7 @@ public class OfflineHandler {
|
|
|
|
|
|
File dest = new File(path);
|
|
|
if (dest.exists()) {
|
|
|
- dest.delete();
|
|
|
+ FileManager.deleteFile(dest);
|
|
|
}
|
|
|
|
|
|
boolean move = src.renameTo(dest);
|
|
|
@@ -392,7 +374,7 @@ public class OfflineHandler {
|
|
|
if (fp.equals(getOfflineTmpDir()) || fp.equals(getOfflineUploadDir()) || fp.endsWith("finish")) {
|
|
|
|
|
|
} else {
|
|
|
- f.delete();
|
|
|
+ FileManager.deleteFile(f);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
@@ -429,7 +411,7 @@ public class OfflineHandler {
|
|
|
Bundle params = new Bundle();
|
|
|
prepareParams(params);
|
|
|
|
|
|
- String url = "";
|
|
|
+ String url = "http://192.168.0.130/fake_offline.zip";
|
|
|
|
|
|
rwl.writeLock().lock();
|
|
|
|
|
|
@@ -447,7 +429,18 @@ public class OfflineHandler {
|
|
|
return action;
|
|
|
}
|
|
|
|
|
|
- private JSONObject filterateActionForDetail(JSONObject json, int action) {
|
|
|
+ public int lastActionIndexForOrder(String orderId) {
|
|
|
+
|
|
|
+ rwl.readLock().lock();
|
|
|
+
|
|
|
+ int action = _lastActionIndexForOrder(orderId);
|
|
|
+
|
|
|
+ rwl.readLock().unlock();
|
|
|
+
|
|
|
+ return action;
|
|
|
+ }
|
|
|
+
|
|
|
+ public JSONObject filterateActionForDetail(JSONObject json, int action) {
|
|
|
|
|
|
if (json == null) {
|
|
|
return null;
|
|
|
@@ -510,6 +503,28 @@ public class OfflineHandler {
|
|
|
return json;
|
|
|
}
|
|
|
|
|
|
+ private String getStatusTitleForActionIndex(int actionIndex) {
|
|
|
+
|
|
|
+ String path = getOfflineDir() + File.separator + "status_title.json";
|
|
|
+ JSONObject json = _getofflineJson(path);
|
|
|
+
|
|
|
+ if (json != null) {
|
|
|
+ return json.optString(String.format("%d", actionIndex),"");
|
|
|
+ }
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getHomeSectionTitleForStatus(int status) {
|
|
|
+
|
|
|
+ String path = getOfflineDir() + File.separator + "home_section_title.json";
|
|
|
+ JSONObject json = _getofflineJson(path);
|
|
|
+
|
|
|
+ if (json != null) {
|
|
|
+ return json.optString(String.format("%d", status),"");
|
|
|
+ }
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Request Data
|
|
|
* */
|
|
|
@@ -613,7 +628,7 @@ public class OfflineHandler {
|
|
|
rwl.writeLock().unlock();
|
|
|
}
|
|
|
|
|
|
- private void updateLastActionForOrder(String orderId, int actionIdx) {
|
|
|
+ public void updateLastActionForOrder(String orderId, int actionIdx) {
|
|
|
if (TextUtils.isEmpty(orderId)) {
|
|
|
return;
|
|
|
}
|
|
|
@@ -649,12 +664,45 @@ public class OfflineHandler {
|
|
|
|
|
|
File f = new File(editPath);
|
|
|
if (f.exists()) {
|
|
|
- f.delete();
|
|
|
+ FileManager.deleteFile(f);
|
|
|
}
|
|
|
|
|
|
rwl.writeLock().unlock();
|
|
|
}
|
|
|
|
|
|
+ private void homeSectionAddOrder(JSONObject section, JSONObject curOrder, int actionIdx) {
|
|
|
+
|
|
|
+ JSONArray orders = section.optJSONArray("orders");
|
|
|
+
|
|
|
+ if (orders == null) {
|
|
|
+ orders = new JSONArray();
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ curOrder.put("status", HomeOrderModel.OrderStatusProcessing);
|
|
|
+ curOrder.put("backendFlag",false);
|
|
|
+ curOrder.put("title",getStatusTitleForActionIndex(actionIdx));
|
|
|
+
|
|
|
+// orders.put(0,curOrder);// 会将原本位置到对象替换,并非插入
|
|
|
+
|
|
|
+ JSONArray tmpOrders = new JSONArray();
|
|
|
+ tmpOrders.put(curOrder);
|
|
|
+
|
|
|
+ for (int q = 0; q < orders.length(); q++) {
|
|
|
+
|
|
|
+ JSONObject order = orders.optJSONObject(q);
|
|
|
+ if (order != null) {
|
|
|
+ tmpOrders.put(order);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ section.put("orders",tmpOrders);
|
|
|
+
|
|
|
+ } catch (JSONException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
public JSONObject reportOrderAction(String orderId, int orderType, int actionType, int actionIdx, String actionName, String url, Bundle params) {
|
|
|
|
|
|
@@ -738,6 +786,7 @@ public class OfflineHandler {
|
|
|
|
|
|
if (actionType == DetailActionSubTypeAccept) {
|
|
|
|
|
|
+ boolean findSection = false;
|
|
|
for (int i = 0; i < sections.length(); i++) {
|
|
|
|
|
|
JSONObject section = sections.optJSONObject(i);
|
|
|
@@ -747,19 +796,33 @@ public class OfflineHandler {
|
|
|
|
|
|
if (type == HomeOrderModel.OrderStatusProcessing) {
|
|
|
|
|
|
- JSONArray orders = section.optJSONArray("orders");
|
|
|
- try {
|
|
|
- curOrder.put("status", HomeOrderModel.OrderStatusProcessing);
|
|
|
- orders.put(0,curOrder);
|
|
|
- } catch (JSONException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
+ homeSectionAddOrder(section,curOrder,actionIdx);
|
|
|
|
|
|
+ findSection = true;
|
|
|
break;
|
|
|
} // processing
|
|
|
}
|
|
|
} // for
|
|
|
|
|
|
+ if (!findSection) {
|
|
|
+
|
|
|
+ try {
|
|
|
+ JSONObject section = new JSONObject();
|
|
|
+
|
|
|
+ section.put("type",HomeOrderModel.OrderStatusProcessing);
|
|
|
+ section.put("totalCount",0);
|
|
|
+ section.put("backendFlagCount",0);
|
|
|
+ section.put("title",getHomeSectionTitleForStatus(HomeOrderModel.OrderStatusProcessing));
|
|
|
+
|
|
|
+ homeSectionAddOrder(section,curOrder,actionIdx);
|
|
|
+
|
|
|
+ sections.put(section);
|
|
|
+
|
|
|
+ } catch (JSONException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
} // Accept
|
|
|
|
|
|
}
|
|
|
@@ -781,30 +844,88 @@ public class OfflineHandler {
|
|
|
return json;
|
|
|
}
|
|
|
|
|
|
- private boolean isLastActionForOrder(String orderId) {
|
|
|
+ private boolean isLastActionForOrder(String orderId, int actionIndex) {
|
|
|
|
|
|
if (TextUtils.isEmpty(orderId)) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
JSONObject detail = requestOfflineOrderDetailWithType(orderId, HomeOrderModel.OrderStatusProcessing);
|
|
|
+ if (detail == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ int result = detail.optInt("result");
|
|
|
+ if (result != RESULT_TRUE) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
+ JSONArray sections = detail.optJSONArray("sections");
|
|
|
+ if (sections != null) {
|
|
|
+
|
|
|
+ for (int i = 0; i < sections.length(); i++) {
|
|
|
+
|
|
|
+ JSONObject section = sections.optJSONObject(i);
|
|
|
+ if (section != null) {
|
|
|
+
|
|
|
+ JSONArray values = section.optJSONArray("values");
|
|
|
+ if (values != null) {
|
|
|
+
|
|
|
+ for (int j = 0; j < values.length(); j++) {
|
|
|
+
|
|
|
+ JSONObject value = values.optJSONObject(j);
|
|
|
+ if (value != null) {
|
|
|
+
|
|
|
+ int type = value.optInt("type");
|
|
|
+ if (type == DetailBaseModel.OrderDetailValueType.OderDetailValueTypeAction) {
|
|
|
+
|
|
|
+ JSONArray actions = value.optJSONArray("actions");
|
|
|
+ if (actions != null) {
|
|
|
+
|
|
|
+ int maxActionIndex = -1;
|
|
|
+ for (int k = 0; k < actions.length(); k++) {
|
|
|
+ JSONObject obj = actions.optJSONObject(k);
|
|
|
+ if (obj != null) {
|
|
|
+ int idx = obj.optInt("index", -1);
|
|
|
+ maxActionIndex = Math.max(maxActionIndex, idx);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if (actionIndex >= maxActionIndex) {
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
public JSONObject updateOrder(String orderId, int actionId, String actionTile, int actionIdx, Bundle params, ArrayList<UpdateImageBaseModel> photos) {
|
|
|
|
|
|
- rwl.writeLock().lock();
|
|
|
-
|
|
|
- String upDir = getOfflineUploadDir() + File.separator + orderId + "_" + actionIdx;
|
|
|
- File upDirF = new File(upDir);
|
|
|
- upDirF.mkdirs();
|
|
|
-
|
|
|
prepareParams(params);
|
|
|
|
|
|
+ File zipF = null;
|
|
|
if (photos!= null && photos.size() > 0) {
|
|
|
|
|
|
+ rwl.writeLock().lock();
|
|
|
+
|
|
|
+ String upDir = getOfflineUploadDir() + File.separator + orderId + "_" + actionIdx;
|
|
|
+ File upDirF = new File(upDir);
|
|
|
+ upDirF.mkdirs();
|
|
|
+
|
|
|
String imgDir = upDir + File.separator + "images";
|
|
|
File imgDirF = new File(imgDir);
|
|
|
imgDirF.mkdirs();
|
|
|
@@ -837,23 +958,25 @@ public class OfflineHandler {
|
|
|
|
|
|
}
|
|
|
}
|
|
|
- } // Photo
|
|
|
|
|
|
+ try {
|
|
|
|
|
|
- File zipF = null;
|
|
|
- try {
|
|
|
+ File zip = zipFile(upDir, upDir + ".zip");
|
|
|
|
|
|
- File zip = zipFolder(upDir, upDir + ".zip");
|
|
|
+// upDirF.delete();
|
|
|
|
|
|
- upDirF.delete();
|
|
|
+ FileManager.deleteFile(upDirF);
|
|
|
|
|
|
- zipF = zip;
|
|
|
+ zipF = zip;
|
|
|
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ rwl.writeLock().unlock();
|
|
|
+
|
|
|
+ } // Photo
|
|
|
|
|
|
- rwl.writeLock().unlock();
|
|
|
|
|
|
String time = currentDate();
|
|
|
Bundle task = new Bundle();
|
|
|
@@ -879,42 +1002,46 @@ public class OfflineHandler {
|
|
|
deleteEditJsonForOrderWithActionIndex(orderId,actionIdx);
|
|
|
|
|
|
// 判断是否是最后一步
|
|
|
- boolean isFinish = isLastActionForOrder(orderId);
|
|
|
- if (isFinish) {
|
|
|
+ boolean isFinish = isLastActionForOrder(orderId,actionIdx);
|
|
|
|
|
|
- JSONObject home = requestOfflineHome();
|
|
|
- if (home != null) {
|
|
|
-
|
|
|
- JSONArray sections = home.optJSONArray("sections");
|
|
|
- if (sections != null) {
|
|
|
+ JSONObject home = requestOfflineHome();
|
|
|
+ if (home != null) {
|
|
|
|
|
|
- int rmSectionIdx = -1;
|
|
|
- for (int i = 0; i < sections.length(); i++) {
|
|
|
+ JSONArray sections = home.optJSONArray("sections");
|
|
|
+ if (sections != null) {
|
|
|
|
|
|
- JSONObject section = sections.optJSONObject(i);
|
|
|
+ int rmSectionIdx = -1;
|
|
|
+ for (int i = 0; i < sections.length(); i++) {
|
|
|
|
|
|
- if (section != null) {
|
|
|
- int type = section.optInt("type");
|
|
|
+ JSONObject section = sections.optJSONObject(i);
|
|
|
|
|
|
- if (type == HomeOrderModel.OrderStatusProcessing) {
|
|
|
+ if (section != null) {
|
|
|
+ int type = section.optInt("type");
|
|
|
|
|
|
- JSONArray orders = section.optJSONArray("orders");
|
|
|
+ if (type == HomeOrderModel.OrderStatusProcessing) {
|
|
|
|
|
|
- int rmOrderIdx = -1;
|
|
|
- for (int j = 0; j < orders.length(); j++) {
|
|
|
+ JSONArray orders = section.optJSONArray("orders");
|
|
|
|
|
|
- JSONObject value = orders.optJSONObject(j);
|
|
|
- if (value != null) {
|
|
|
+ int rmOrderIdx = -1;
|
|
|
+ JSONObject curOrder = null;
|
|
|
+ for (int j = 0; j < orders.length(); j++) {
|
|
|
|
|
|
- String orderID = value.optString("orderID");
|
|
|
- if (orderID.equals(orderId)) {
|
|
|
- rmOrderIdx = j;
|
|
|
- break;
|
|
|
- }
|
|
|
+ JSONObject value = orders.optJSONObject(j);
|
|
|
+ if (value != null) {
|
|
|
|
|
|
+ String orderID = value.optString("orderID");
|
|
|
+ if (orderID.equals(orderId)) {
|
|
|
+ curOrder = value;
|
|
|
+ rmOrderIdx = j;
|
|
|
+ break;
|
|
|
}
|
|
|
|
|
|
- } // for j
|
|
|
+ }
|
|
|
+
|
|
|
+ } // for j
|
|
|
+
|
|
|
+ if (isFinish) {
|
|
|
+
|
|
|
if (rmOrderIdx >= 0) {
|
|
|
orders.remove(rmOrderIdx);
|
|
|
}
|
|
|
@@ -923,23 +1050,36 @@ public class OfflineHandler {
|
|
|
rmSectionIdx = i;
|
|
|
}
|
|
|
|
|
|
- break;
|
|
|
- } // processing
|
|
|
+ } else {
|
|
|
|
|
|
- } // section not null
|
|
|
+ try {
|
|
|
+ if (curOrder != null) {
|
|
|
+ curOrder.put("backendFlag",false);
|
|
|
+ curOrder.put("title",getStatusTitleForActionIndex(actionIdx));
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- } // for i
|
|
|
+ break;
|
|
|
+ } // processing
|
|
|
|
|
|
- if (rmSectionIdx >= 0) {
|
|
|
- sections.remove(rmSectionIdx);
|
|
|
- }
|
|
|
+ } // section not null
|
|
|
|
|
|
- } // sections
|
|
|
+ } // for i
|
|
|
|
|
|
- updateHome(home);
|
|
|
+ if (rmSectionIdx >= 0) {
|
|
|
+ sections.remove(rmSectionIdx);
|
|
|
+ }
|
|
|
|
|
|
- } // home != null
|
|
|
- }
|
|
|
+ } // sections
|
|
|
+
|
|
|
+ updateHome(home);
|
|
|
+
|
|
|
+ } // home != null
|
|
|
+
|
|
|
+ updateLastActionForOrder(orderId,actionIdx);
|
|
|
|
|
|
JSONObject json = new JSONObject();
|
|
|
try {
|