|
@@ -42,6 +42,7 @@ import com.usai.redant.CommonEditor.CommonEditor.CommonEditorSignatureCellHolder
|
|
|
import com.usai.redant.CommonEditor.CommonEditor.CommonEditorSwitchCellHolder;
|
|
import com.usai.redant.CommonEditor.CommonEditor.CommonEditorSwitchCellHolder;
|
|
|
import com.usai.redant.CommonEditor.CommonEditor.CommonEditorTextViewCellHolder;
|
|
import com.usai.redant.CommonEditor.CommonEditor.CommonEditorTextViewCellHolder;
|
|
|
import com.usai.redant.redantmobile.R;
|
|
import com.usai.redant.redantmobile.R;
|
|
|
|
|
+import com.usai.redant.util.Network;
|
|
|
|
|
|
|
|
import org.json.JSONArray;
|
|
import org.json.JSONArray;
|
|
|
import org.json.JSONObject;
|
|
import org.json.JSONObject;
|
|
@@ -80,11 +81,29 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public JSONObject request_editor(String request_url,Bundle params) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public static class subitem_data {
|
|
public static class subitem_data {
|
|
|
public JSONObject params;
|
|
public JSONObject params;
|
|
|
public JSONArray missingfields;
|
|
public JSONArray missingfields;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private ProgressDialog showProgressAlert(String title,String msg) {
|
|
|
|
|
+ ProgressDialog pd = new ProgressDialog(this);
|
|
|
|
|
+ pd.setTitle(title);
|
|
|
|
|
+ pd.setMessage(msg);
|
|
|
|
|
+ /**
|
|
|
|
|
+ * false,表示 ProgressDialog 是不能通过 Back 键取消
|
|
|
|
|
+ * 数据加载完成后必须要调用 ProgressDialog 的 dismiss() 方法来关闭对话框
|
|
|
|
|
+ * */
|
|
|
|
|
+ pd.setCancelable(false);
|
|
|
|
|
+ pd.show();
|
|
|
|
|
+
|
|
|
|
|
+ return pd;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
getMenuInflater().inflate(R.menu.action_bar_menu,menu);
|
|
getMenuInflater().inflate(R.menu.action_bar_menu,menu);
|
|
@@ -113,14 +132,21 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
|
|
|
if (content_data_download != null) {
|
|
if (content_data_download != null) {
|
|
|
outState.putString("download_content",content_data_download.toString());
|
|
outState.putString("download_content",content_data_download.toString());
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ if (service_url != null) {
|
|
|
|
|
+ outState.putString("request_url",service_url);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ outState.putInt("url_type",url_type);
|
|
|
|
|
+ outState.putBundle("params",selfParams);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
super.onCreate(savedInstanceState);
|
|
|
- setContentView(R.layout.activity_main);
|
|
|
|
|
|
|
+ setContentView(R.layout.activity_common_editor);
|
|
|
|
|
|
|
|
- service_url = "http://192.168.0.133:8080/site/isales/getAddCustomer.htm";
|
|
|
|
|
|
|
+// service_url = "http://192.168.0.133:8080/site/isales/getAddCustomer.htm";
|
|
|
|
|
|
|
|
listView = (ExpandableListView)findViewById(R.id.list_view);
|
|
listView = (ExpandableListView)findViewById(R.id.list_view);
|
|
|
|
|
|
|
@@ -147,7 +173,6 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
|
|
|
|
|
|
|
|
listView.setAdapter(adapter);
|
|
listView.setAdapter(adapter);
|
|
|
|
|
|
|
|
-// loadData();
|
|
|
|
|
|
|
|
|
|
if (savedInstanceState != null) {
|
|
if (savedInstanceState != null) {
|
|
|
String control_str = savedInstanceState.getString("control_content");
|
|
String control_str = savedInstanceState.getString("control_content");
|
|
@@ -165,16 +190,101 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
|
|
|
content_data_download = null;
|
|
content_data_download = null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ service_url = savedInstanceState.getString("request_url");
|
|
|
|
|
+ url_type = savedInstanceState.getInt("url_type");
|
|
|
|
|
+ selfParams = savedInstanceState.getBundle("params");
|
|
|
|
|
|
|
|
- if (content_data_download == null || content_data_control == null) {
|
|
|
|
|
- JSONObject obj = Utils.testJson(true);
|
|
|
|
|
- if (obj != null) {
|
|
|
|
|
- handleJson(obj);
|
|
|
|
|
|
|
+ } else {
|
|
|
|
|
+ service_url = getIntent().getStringExtra("request_url");
|
|
|
|
|
+ url_type = getIntent().getIntExtra("url_type",URL_REMOTE);
|
|
|
|
|
+
|
|
|
|
|
+ Bundle params = getIntent().getBundleExtra("params");
|
|
|
|
|
+ if (params != null) {
|
|
|
|
|
+ selfParams = params;
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
|
|
+ final ProgressDialog pd = showProgressAlert("Loading","Please wait");
|
|
|
|
|
+ new Thread(new Runnable() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void run() {
|
|
|
|
|
+
|
|
|
|
|
+ if (url_type == URL_REMOTE) {
|
|
|
|
|
+ final JSONObject obj = request_editor(service_url,selfParams);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ runOnUiThread(new Runnable() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void run() {
|
|
|
|
|
+
|
|
|
|
|
+ pd.dismiss();
|
|
|
|
|
+
|
|
|
|
|
+ if (obj != null) {
|
|
|
|
|
+
|
|
|
|
|
+ int result = obj.optInt("result");
|
|
|
|
|
+ if (result == 2) {
|
|
|
|
|
+
|
|
|
|
|
+ content_data_download = copyDirtyTo(content_data_download,obj);
|
|
|
|
|
+ content_data_control = translateChange(content_data_download,changed_data);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ download_success();
|
|
|
|
|
+ defaulExpandSections();
|
|
|
|
|
+ adapter.notifyDataSetChanged();
|
|
|
|
|
+
|
|
|
|
|
+ } else {
|
|
|
|
|
+ Utils.message_alert(mCtx,"Warning","Error");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } else {
|
|
|
|
|
+ Utils.message_alert(mCtx,"Warning","Error");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ } else {
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+
|
|
|
|
|
+ InputStreamReader isr = new InputStreamReader(getAssets().open(service_url + ".json"),"UTF-8");
|
|
|
|
|
+ BufferedReader br = new BufferedReader(isr);
|
|
|
|
|
+ String line;
|
|
|
|
|
+ StringBuilder builder = new StringBuilder();
|
|
|
|
|
+ while((line = br.readLine()) != null){
|
|
|
|
|
+ builder.append(line);
|
|
|
|
|
+ }
|
|
|
|
|
+ br.close();
|
|
|
|
|
+ isr.close();
|
|
|
|
|
+ content_data_download = new JSONObject(builder.toString());//builder读取了JSON中的数据。
|
|
|
|
|
+
|
|
|
|
|
+ request_fill();
|
|
|
|
|
+
|
|
|
|
|
+ content_data_control = translateChange(content_data_download,changed_data);
|
|
|
|
|
+
|
|
|
|
|
+ runOnUiThread(new Runnable() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void run() {
|
|
|
|
|
+ pd.dismiss();
|
|
|
|
|
+ adapter.notifyDataSetChanged();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ runOnUiThread(new Runnable() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void run() {
|
|
|
|
|
+ pd.dismiss();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }).start();
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -726,99 +836,7 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- public void loadData() {
|
|
|
|
|
-
|
|
|
|
|
- if (service_url == null || service_url.isEmpty()) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- new Thread(new Runnable() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void run() {
|
|
|
|
|
- HttpURLConnection connection = null;
|
|
|
|
|
- try {
|
|
|
|
|
-
|
|
|
|
|
- URL url = new URL(service_url);
|
|
|
|
|
- connection = (HttpURLConnection)url.openConnection();
|
|
|
|
|
- connection.setRequestMethod("POST");
|
|
|
|
|
- connection.setConnectTimeout(1500);
|
|
|
|
|
- connection.setReadTimeout(1500);
|
|
|
|
|
- connection.setUseCaches(false);
|
|
|
|
|
- connection.setDoInput(true);
|
|
|
|
|
- connection.setDoOutput(true);
|
|
|
|
|
- connection.setRequestProperty("Content-Type","multipart/form-data; boundary=AaB03x");
|
|
|
|
|
- connection.setRequestProperty("Connection","close");
|
|
|
|
|
-
|
|
|
|
|
- OutputStreamWriter outputStreamWriter = new OutputStreamWriter(connection.getOutputStream());
|
|
|
|
|
- outputStreamWriter.write("password=123456&app_ver=170814&idfv=D3CE97F6-3586-4804-B7E6-7C7AB027A235&ipad_perm={\"submit_order_logout\":\"true\",\"can_submit_order\":\"true\",\"can_set_tearsheet_price\":\"true\",\"can_update_contact_info\":\"true\",\"can_see_price\":\"true\",\"alert_sold_in_quantities\":\"true\",\"can_show_price\":\"true\",\"can_create_portfolio\":\"true\",\"can_set_cart_price\":\"true\",\"save_order_logout\":\"true\",\"can_create_order\":\"true\"}&app_short_ver=1.90&user=Admin");
|
|
|
|
|
-
|
|
|
|
|
- InputStream inputStream = connection.getInputStream();
|
|
|
|
|
- readInputStream(inputStream);
|
|
|
|
|
-
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }).start();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
JSONObject changed_data;
|
|
JSONObject changed_data;
|
|
|
- private void readInputStream(InputStream inputStream) {
|
|
|
|
|
- try {
|
|
|
|
|
- // 对获取到到输入流读取
|
|
|
|
|
- BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
|
|
|
|
|
- StringBuilder response = new StringBuilder();
|
|
|
|
|
- String line;
|
|
|
|
|
- while ((line = reader.readLine()) != null) {
|
|
|
|
|
- response.append(line);
|
|
|
|
|
- }
|
|
|
|
|
- JSONObject object = new JSONObject(response.toString());
|
|
|
|
|
-
|
|
|
|
|
- int result = object.optInt("result");
|
|
|
|
|
- if (result == 2) {
|
|
|
|
|
-
|
|
|
|
|
- content_data_download = copyDirtyTo(content_data_download,object);
|
|
|
|
|
- content_data_control = translateChange(content_data_download,changed_data);
|
|
|
|
|
-
|
|
|
|
|
- download_success();
|
|
|
|
|
- adapter.notifyDataSetChanged();
|
|
|
|
|
-
|
|
|
|
|
- } else {
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private void handleJson(final JSONObject object) {
|
|
|
|
|
- new Thread(new Runnable() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void run() {
|
|
|
|
|
- int result = object.optInt("result");
|
|
|
|
|
- if (result == 2) {
|
|
|
|
|
-
|
|
|
|
|
- content_data_download = copyDirtyTo(content_data_download,object);
|
|
|
|
|
- content_data_control = translateChange(content_data_download,changed_data);
|
|
|
|
|
-
|
|
|
|
|
- download_success();
|
|
|
|
|
- runOnUiThread(new Runnable() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void run() {
|
|
|
|
|
- defaulExpandSections();
|
|
|
|
|
- adapter.notifyDataSetChanged();
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- } else {
|
|
|
|
|
- Utils.message_alert(mCtx,"Warning","Error");
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }).start();
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
public JSONObject copyDirtyTo(JSONObject dirty, JSONObject to) {
|
|
public JSONObject copyDirtyTo(JSONObject dirty, JSONObject to) {
|
|
|
|
|
|
|
@@ -980,12 +998,14 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
|
|
|
if (lastEditText != null) {
|
|
if (lastEditText != null) {
|
|
|
endEditting();
|
|
endEditting();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ final ProgressDialog pd = showProgressAlert("Loading","Please wait");
|
|
|
|
|
+
|
|
|
if (url_type == URL_REMOTE) {
|
|
if (url_type == URL_REMOTE) {
|
|
|
|
|
|
|
|
- final ProgressDialog pd = Utils.waiting_alert(mCtx,"loading","please wait");
|
|
|
|
|
if (trigger != null) {
|
|
if (trigger != null) {
|
|
|
try {
|
|
try {
|
|
|
- selfParams.put("refresh_trigger",trigger);
|
|
|
|
|
|
|
+ selfParams.putString("refresh_trigger",trigger);
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
}
|
|
}
|
|
@@ -999,13 +1019,13 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
|
|
|
String key = iterator.next();
|
|
String key = iterator.next();
|
|
|
String obj_str = "" + refresh_params.optString(key);
|
|
String obj_str = "" + refresh_params.optString(key);
|
|
|
try {
|
|
try {
|
|
|
- selfParams.put(key,obj_str);
|
|
|
|
|
|
|
+ selfParams.putString(key,obj_str);
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- final JSONObject editor_json = Utils.request_editor(service_url,selfParams);
|
|
|
|
|
|
|
+ final JSONObject editor_json = request_editor(service_url,selfParams);
|
|
|
|
|
|
|
|
runOnUiThread(new Runnable() {
|
|
runOnUiThread(new Runnable() {
|
|
|
@Override
|
|
@Override
|
|
@@ -1052,15 +1072,16 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
|
|
|
|
|
|
|
|
content_data_control = translateChange(content_data_download,changed_data);
|
|
content_data_control = translateChange(content_data_download,changed_data);
|
|
|
adapter.notifyDataSetChanged();
|
|
adapter.notifyDataSetChanged();
|
|
|
-
|
|
|
|
|
|
|
+ pd.dismiss();
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
|
|
+ pd.dismiss();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public JSONObject selfParams = new JSONObject();
|
|
|
|
|
|
|
+ public Bundle selfParams = new Bundle();
|
|
|
public JSONObject get_refresh_param() {
|
|
public JSONObject get_refresh_param() {
|
|
|
try {
|
|
try {
|
|
|
JSONObject params = new JSONObject();
|
|
JSONObject params = new JSONObject();
|
|
@@ -1069,7 +1090,7 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
|
|
|
for (int pc = 0; pc < param_count; pc++) {
|
|
for (int pc = 0; pc < param_count; pc++) {
|
|
|
String param_name = param_names.optString("val_" + pc);
|
|
String param_name = param_names.optString("val_" + pc);
|
|
|
String param_val = getValue(param_name);
|
|
String param_val = getValue(param_name);
|
|
|
- selfParams.put(param_name,param_val);
|
|
|
|
|
|
|
+ selfParams.putString(param_name,param_val);
|
|
|
}
|
|
}
|
|
|
return params;
|
|
return params;
|
|
|
|
|
|
|
@@ -2423,7 +2444,7 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
|
|
|
holder.startMark.setVisibility(View.INVISIBLE);
|
|
holder.startMark.setVisibility(View.INVISIBLE);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (cancommit == false && required.equals("true") && (value == null || value.length() == 0)) {
|
|
|
|
|
|
|
+ if (cancommit == false && required != null && required.equals("true") && (value == null || value.length() == 0)) {
|
|
|
// 阴影 red
|
|
// 阴影 red
|
|
|
} else {
|
|
} else {
|
|
|
// 无阴影
|
|
// 无阴影
|
|
@@ -3126,10 +3147,10 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- static int URL_REMOTE = 1;
|
|
|
|
|
- static int URL_LOCAL = 0;
|
|
|
|
|
- static int URL_NONE = 2;
|
|
|
|
|
- static int URL_RESTORE = 3;
|
|
|
|
|
|
|
+ public static int URL_REMOTE = 1;
|
|
|
|
|
+ public static int URL_LOCAL = 0;
|
|
|
|
|
+ public static int URL_NONE = 2;
|
|
|
|
|
+ public static int URL_RESTORE = 3;
|
|
|
// 如何处理commoneditor action 类型调用的返回值
|
|
// 如何处理commoneditor action 类型调用的返回值
|
|
|
static int ACTION_SAVE_DATA = 0;
|
|
static int ACTION_SAVE_DATA = 0;
|
|
|
static int ACTION_FILL_SECTION = 1;
|
|
static int ACTION_FILL_SECTION = 1;
|