|
@@ -21,6 +21,7 @@ import android.util.Log;
|
|
|
import android.view.LayoutInflater;
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.Menu;
|
|
import android.view.Menu;
|
|
|
import android.view.MenuItem;
|
|
import android.view.MenuItem;
|
|
|
|
|
+import android.view.View;
|
|
|
import android.widget.ExpandableListView;
|
|
import android.widget.ExpandableListView;
|
|
|
|
|
|
|
|
import com.usai.redant.apexdrivers.ApexDriverApplication;
|
|
import com.usai.redant.apexdrivers.ApexDriverApplication;
|
|
@@ -54,6 +55,7 @@ public class UpdateActivity extends AppCompatActivity implements UpdateAdapter.U
|
|
|
private final static String OrderIDKey = "OrderID";
|
|
private final static String OrderIDKey = "OrderID";
|
|
|
private final static String ActionIDKey = "ActionID";
|
|
private final static String ActionIDKey = "ActionID";
|
|
|
private final static String ActionTitleKey = "ActionTitle";
|
|
private final static String ActionTitleKey = "ActionTitle";
|
|
|
|
|
+ private final static String SaveDataKey = "UpdateSavedJson";
|
|
|
|
|
|
|
|
private final static int REQUEST_SCANNER_CODE = 0;
|
|
private final static int REQUEST_SCANNER_CODE = 0;
|
|
|
private final static int REQUEST_CAMERA_CODE = 1;
|
|
private final static int REQUEST_CAMERA_CODE = 1;
|
|
@@ -80,7 +82,6 @@ public class UpdateActivity extends AppCompatActivity implements UpdateAdapter.U
|
|
|
private Context mCtx = this;
|
|
private Context mCtx = this;
|
|
|
private UpdateActivity self = this;
|
|
private UpdateActivity self = this;
|
|
|
private UpdateHandler mHandler;
|
|
private UpdateHandler mHandler;
|
|
|
- private JSONObject mJson;
|
|
|
|
|
private ArrayList<UpdateSectionModel> mSectionArray = new ArrayList<>();
|
|
private ArrayList<UpdateSectionModel> mSectionArray = new ArrayList<>();
|
|
|
private UpdateAdapter mAdapter;
|
|
private UpdateAdapter mAdapter;
|
|
|
|
|
|
|
@@ -118,6 +119,12 @@ public class UpdateActivity extends AppCompatActivity implements UpdateAdapter.U
|
|
|
|
|
|
|
|
mListView.setGroupIndicator(null);
|
|
mListView.setGroupIndicator(null);
|
|
|
mListView.setAdapter(mAdapter);
|
|
mListView.setAdapter(mAdapter);
|
|
|
|
|
+ mListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
|
|
|
|
|
+ return true; // 不允许GroupView点击
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
mRefresh = findViewById(R.id.update_refresh);
|
|
mRefresh = findViewById(R.id.update_refresh);
|
|
|
mRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
|
mRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
|
@@ -127,13 +134,42 @@ public class UpdateActivity extends AppCompatActivity implements UpdateAdapter.U
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- loadData();
|
|
|
|
|
|
|
+ if (savedInstanceState != null) {
|
|
|
|
|
+
|
|
|
|
|
+ String jsonStr = savedInstanceState.getString(SaveDataKey);
|
|
|
|
|
+ if (jsonStr != null) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ JSONObject json = new JSONObject(jsonStr);
|
|
|
|
|
+
|
|
|
|
|
+ handleJSON(json);
|
|
|
|
|
+ changeData();
|
|
|
|
|
+
|
|
|
|
|
+ } catch (JSONException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } else {
|
|
|
|
|
+ loadData();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
protected void onSaveInstanceState(Bundle outState) {
|
|
protected void onSaveInstanceState(Bundle outState) {
|
|
|
super.onSaveInstanceState(outState);
|
|
super.onSaveInstanceState(outState);
|
|
|
|
|
|
|
|
|
|
+ JSONObject json = prepareSavedJson();
|
|
|
|
|
+ if (json != null) {
|
|
|
|
|
+ outState.putString(SaveDataKey,json.toString());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void onStop() {
|
|
|
|
|
+ super.onStop();
|
|
|
|
|
+
|
|
|
|
|
+ dismissProgressDialog();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -260,6 +296,42 @@ public class UpdateActivity extends AppCompatActivity implements UpdateAdapter.U
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private void handleJSON(JSONObject json) {
|
|
|
|
|
+
|
|
|
|
|
+ JSONArray sectionArr = json.optJSONArray("sections");
|
|
|
|
|
+ if (sectionArr != null) {
|
|
|
|
|
+
|
|
|
|
|
+ mSectionArray.clear();
|
|
|
|
|
+ try {
|
|
|
|
|
+ for (int i = 0; i < sectionArr.length(); i++) {
|
|
|
|
|
+
|
|
|
|
|
+ JSONObject section = sectionArr.getJSONObject(i);
|
|
|
|
|
+ UpdateSectionModel sectionModel = new UpdateSectionModel();
|
|
|
|
|
+ sectionModel.title = section.optString("title");
|
|
|
|
|
+ sectionModel.setItems(section.optJSONArray("items"));
|
|
|
|
|
+
|
|
|
|
|
+ mSectionArray.add(sectionModel);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (JSONException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void changeData() {
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 手动调用打开/关闭 Group,否则默认关闭
|
|
|
|
|
+ * */
|
|
|
|
|
+ if (mSectionArray.size() > 0) {
|
|
|
|
|
+ for (int i = 0; i < mSectionArray.size(); i++) {
|
|
|
|
|
+ mListView.expandGroup(i);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ mAdapter.notifyDataSetChanged();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private void update() {
|
|
private void update() {
|
|
|
|
|
|
|
|
showProgressDialog();
|
|
showProgressDialog();
|
|
@@ -497,7 +569,7 @@ public class UpdateActivity extends AppCompatActivity implements UpdateAdapter.U
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
mPhotoModel = model;
|
|
mPhotoModel = model;
|
|
|
- if (model.photoPath == null) {
|
|
|
|
|
|
|
+ if (model.photoPath == null || model.photoPath.length() == 0) {
|
|
|
|
|
|
|
|
startCamera();
|
|
startCamera();
|
|
|
} else {
|
|
} else {
|
|
@@ -630,22 +702,8 @@ public class UpdateActivity extends AppCompatActivity implements UpdateAdapter.U
|
|
|
|
|
|
|
|
int restul = json.getInt("result");
|
|
int restul = json.getInt("result");
|
|
|
if (restul == RESULT_TRUE) {
|
|
if (restul == RESULT_TRUE) {
|
|
|
- activity.mJson = json;
|
|
|
|
|
- JSONArray sectionArr = json.optJSONArray("sections");
|
|
|
|
|
- if (sectionArr != null) {
|
|
|
|
|
-
|
|
|
|
|
- activity.mSectionArray.clear();
|
|
|
|
|
- for (int i = 0; i < sectionArr.length(); i++) {
|
|
|
|
|
-
|
|
|
|
|
- JSONObject section = sectionArr.getJSONObject(i);
|
|
|
|
|
- UpdateSectionModel sectionModel = new UpdateSectionModel();
|
|
|
|
|
- sectionModel.title = section.optString("title");
|
|
|
|
|
- sectionModel.setItems(section.optJSONArray("items"));
|
|
|
|
|
|
|
|
|
|
- activity.mSectionArray.add(sectionModel);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ activity.handleJSON(json);
|
|
|
|
|
|
|
|
} else {
|
|
} else {
|
|
|
// error
|
|
// error
|
|
@@ -667,16 +725,8 @@ public class UpdateActivity extends AppCompatActivity implements UpdateAdapter.U
|
|
|
String errMsg = "Sorry,there is something wrong";
|
|
String errMsg = "Sorry,there is something wrong";
|
|
|
activity.showWarningMsg(errMsg);
|
|
activity.showWarningMsg(errMsg);
|
|
|
}
|
|
}
|
|
|
- /**
|
|
|
|
|
- * 手动调用打开/关闭 Group,否则默认关闭
|
|
|
|
|
- * */
|
|
|
|
|
- if (activity.mSectionArray.size() > 0) {
|
|
|
|
|
- for (int i = 0; i < activity.mSectionArray.size(); i++) {
|
|
|
|
|
- activity.mListView.expandGroup(i);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- activity.mAdapter.notifyDataSetChanged();
|
|
|
|
|
|
|
+ activity.changeData();
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|
|
@@ -687,6 +737,26 @@ public class UpdateActivity extends AppCompatActivity implements UpdateAdapter.U
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- *
|
|
|
|
|
|
|
+ * Save
|
|
|
* */
|
|
* */
|
|
|
|
|
+
|
|
|
|
|
+ private JSONObject prepareSavedJson() {
|
|
|
|
|
+
|
|
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
|
|
+ JSONArray sections = new JSONArray();
|
|
|
|
|
+ try {
|
|
|
|
|
+ for (int i = 0; i < mSectionArray.size(); i++) {
|
|
|
|
|
+
|
|
|
|
|
+ UpdateSectionModel sectionModel = mSectionArray.get(i);
|
|
|
|
|
+ JSONObject sectionJson = sectionModel.sectionModel2Json();
|
|
|
|
|
+ if (sectionJson != null) {
|
|
|
|
|
+ sections.put(sectionJson);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ json.put("sections",sections);
|
|
|
|
|
+ } catch (JSONException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ return json;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|