|
|
@@ -3,11 +3,14 @@ package com.xzjmyk.pm.activity.ui.erp.activity.datainquiry.activity;
|
|
|
import android.os.Bundle;
|
|
|
import android.os.Handler;
|
|
|
import android.os.Message;
|
|
|
+import android.text.TextUtils;
|
|
|
import android.widget.ListView;
|
|
|
|
|
|
import com.common.LogUtil;
|
|
|
import com.core.app.Constants;
|
|
|
import com.core.utils.CommonUtil;
|
|
|
+import com.handmark.pulltorefresh.library.PullToRefreshBase;
|
|
|
+import com.handmark.pulltorefresh.library.PullToRefreshListView;
|
|
|
import com.xzjmyk.pm.activity.R;
|
|
|
import com.xzjmyk.pm.activity.ui.base.BaseActivity;
|
|
|
import com.xzjmyk.pm.activity.ui.erp.activity.datainquiry.adapter.DataInquiryMenuListAdapter;
|
|
|
@@ -30,7 +33,7 @@ import java.util.Map;
|
|
|
*/
|
|
|
public class DataInquiryActivity extends BaseActivity {
|
|
|
private final int GET_MENU_DATA = 0x08;
|
|
|
- private ListView mMenuListView;
|
|
|
+ private PullToRefreshListView mMenuListView;
|
|
|
private List<GridMenuDataInquiryBean> mGridMenuDataInquiryBeans;
|
|
|
private DataInquiryMenuListAdapter mDataInquiryMenuListAdapter;
|
|
|
|
|
|
@@ -40,16 +43,44 @@ public class DataInquiryActivity extends BaseActivity {
|
|
|
setContentView(R.layout.activity_data_inquiry);
|
|
|
getSupportActionBar().setTitle(R.string.select_query_service);
|
|
|
|
|
|
- mMenuListView = (ListView) findViewById(R.id.data_inquiry_menu_lv);
|
|
|
+ mMenuListView = (PullToRefreshListView) findViewById(R.id.data_inquiry_menu_lv);
|
|
|
mGridMenuDataInquiryBeans = new ArrayList<>();
|
|
|
mDataInquiryMenuListAdapter = new DataInquiryMenuListAdapter(this, mGridMenuDataInquiryBeans);
|
|
|
mMenuListView.setAdapter(mDataInquiryMenuListAdapter);
|
|
|
|
|
|
- if (!CommonUtil.isNetWorkConnected(this)) {
|
|
|
- ToastMessage(getString(R.string.networks_out));
|
|
|
+ String dataInquiryMenuCache = CommonUtil.getSharedPreferences(this, com.xzjmyk.pm.activity.ui.erp.activity.datainquiry.Constants.CONSTANT.DATA_INQUIRY_MENU_CACHE);
|
|
|
+ if (TextUtils.isEmpty(dataInquiryMenuCache)) {
|
|
|
+ if (!CommonUtil.isNetWorkConnected(this)) {
|
|
|
+ ToastMessage(getString(R.string.networks_out));
|
|
|
+ } else {
|
|
|
+ getMenuData();
|
|
|
+ }
|
|
|
} else {
|
|
|
- getMenuData();
|
|
|
+ analysisMenuData(dataInquiryMenuCache);
|
|
|
}
|
|
|
+
|
|
|
+ mMenuListView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ListView>() {
|
|
|
+ @Override
|
|
|
+ public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {
|
|
|
+ if (!CommonUtil.isNetWorkConnected(DataInquiryActivity.this)) {
|
|
|
+ ToastMessage(getString(R.string.networks_out));
|
|
|
+ if (mMenuListView.isRefreshing())
|
|
|
+ mMenuListView.postDelayed(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ mMenuListView.onRefreshComplete();
|
|
|
+ }
|
|
|
+ }, 500);
|
|
|
+ } else {
|
|
|
+ getMenuData();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
private void getMenuData() {
|
|
|
@@ -68,66 +99,77 @@ public class DataInquiryActivity extends BaseActivity {
|
|
|
switch (msg.what) {
|
|
|
case GET_MENU_DATA:
|
|
|
progressDialog.dismiss();
|
|
|
+ if (mMenuListView.isRefreshing())
|
|
|
+ mMenuListView.onRefreshComplete();
|
|
|
String result = msg.getData().getString("result");
|
|
|
- if (result != null) {
|
|
|
- LogUtil.prinlnLongMsg("menudata", result);
|
|
|
- try {
|
|
|
- JSONObject resultObject = new JSONObject(result);
|
|
|
- JSONArray dataArray = resultObject.optJSONArray("data");
|
|
|
- if (dataArray != null) {
|
|
|
- for (int i = 0; i < dataArray.length(); i++) {
|
|
|
- JSONObject dataObject = dataArray.optJSONObject(i);
|
|
|
- if (dataObject != null) {
|
|
|
- GridMenuDataInquiryBean gridMenuDataInquiryBean = new GridMenuDataInquiryBean();
|
|
|
- String modelName = optStringNotNull(dataObject, "modelName");
|
|
|
- gridMenuDataInquiryBean.setModelName(modelName);
|
|
|
- JSONArray listArray = dataObject.optJSONArray("list");
|
|
|
- if (listArray != null) {
|
|
|
- List<GridMenuDataInquiryBean.QueryScheme> querySchemes = new ArrayList<>();
|
|
|
- for (int j = 0; j < listArray.length(); j++) {
|
|
|
- JSONObject listObject = listArray.optJSONObject(j);
|
|
|
- if (listObject != null) {
|
|
|
- String title = optStringNotNull(listObject, "title");
|
|
|
- String caller = optStringNotNull(listObject, "caller");
|
|
|
- JSONArray schemeArray = listObject.optJSONArray("schemes");
|
|
|
- if (schemeArray != null) {
|
|
|
- for (int k = 0; k < schemeArray.length(); k++) {
|
|
|
- JSONObject schemeObject = schemeArray.optJSONObject(k);
|
|
|
- if (schemeObject != null) {
|
|
|
- String scheme = optStringNotNull(schemeObject, "scheme");
|
|
|
- String schemeId = optStringNotNull(schemeObject, "schemeId");
|
|
|
-
|
|
|
- GridMenuDataInquiryBean.QueryScheme queryScheme = new GridMenuDataInquiryBean.QueryScheme();
|
|
|
- queryScheme.setTitle(title);
|
|
|
- queryScheme.setCaller(caller);
|
|
|
- queryScheme.setScheme(scheme);
|
|
|
- queryScheme.setSchemeId(schemeId);
|
|
|
-
|
|
|
- querySchemes.add(queryScheme);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ if (result != null)
|
|
|
+ CommonUtil.setSharedPreferences(DataInquiryActivity.this, com.xzjmyk.pm.activity.ui.erp.activity.datainquiry.Constants.CONSTANT.DATA_INQUIRY_MENU_CACHE,
|
|
|
+ result);
|
|
|
+ analysisMenuData(result);
|
|
|
+ break;
|
|
|
+ case Constants.APP_SOCKETIMEOUTEXCEPTION:
|
|
|
+ progressDialog.dismiss();
|
|
|
+ if (mMenuListView.isRefreshing())
|
|
|
+ mMenuListView.onRefreshComplete();
|
|
|
+ ToastMessage(msg.getData().getString("result"));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ private void analysisMenuData(String result) {
|
|
|
+ if (result != null) {
|
|
|
+ LogUtil.prinlnLongMsg("menudata", result);
|
|
|
+ try {
|
|
|
+ JSONObject resultObject = new JSONObject(result);
|
|
|
+ JSONArray dataArray = resultObject.optJSONArray("data");
|
|
|
+ if (dataArray != null) {
|
|
|
+ for (int i = 0; i < dataArray.length(); i++) {
|
|
|
+ JSONObject dataObject = dataArray.optJSONObject(i);
|
|
|
+ if (dataObject != null) {
|
|
|
+ GridMenuDataInquiryBean gridMenuDataInquiryBean = new GridMenuDataInquiryBean();
|
|
|
+ String modelName = optStringNotNull(dataObject, "modelName");
|
|
|
+ gridMenuDataInquiryBean.setModelName(modelName);
|
|
|
+ JSONArray listArray = dataObject.optJSONArray("list");
|
|
|
+ if (listArray != null) {
|
|
|
+ List<GridMenuDataInquiryBean.QueryScheme> querySchemes = new ArrayList<>();
|
|
|
+ for (int j = 0; j < listArray.length(); j++) {
|
|
|
+ JSONObject listObject = listArray.optJSONObject(j);
|
|
|
+ if (listObject != null) {
|
|
|
+ String title = optStringNotNull(listObject, "title");
|
|
|
+ String caller = optStringNotNull(listObject, "caller");
|
|
|
+ JSONArray schemeArray = listObject.optJSONArray("schemes");
|
|
|
+ if (schemeArray != null) {
|
|
|
+ for (int k = 0; k < schemeArray.length(); k++) {
|
|
|
+ JSONObject schemeObject = schemeArray.optJSONObject(k);
|
|
|
+ if (schemeObject != null) {
|
|
|
+ String scheme = optStringNotNull(schemeObject, "scheme");
|
|
|
+ String schemeId = optStringNotNull(schemeObject, "schemeId");
|
|
|
+
|
|
|
+ GridMenuDataInquiryBean.QueryScheme queryScheme = new GridMenuDataInquiryBean.QueryScheme();
|
|
|
+ queryScheme.setTitle(title);
|
|
|
+ queryScheme.setCaller(caller);
|
|
|
+ queryScheme.setScheme(scheme);
|
|
|
+ queryScheme.setSchemeId(schemeId);
|
|
|
+
|
|
|
+ querySchemes.add(queryScheme);
|
|
|
}
|
|
|
}
|
|
|
- gridMenuDataInquiryBean.setQuerySchemes(querySchemes);
|
|
|
}
|
|
|
- mGridMenuDataInquiryBeans.add(gridMenuDataInquiryBean);
|
|
|
}
|
|
|
}
|
|
|
- mDataInquiryMenuListAdapter.notifyDataSetChanged();
|
|
|
+ gridMenuDataInquiryBean.setQuerySchemes(querySchemes);
|
|
|
}
|
|
|
- } catch (JSONException e) {
|
|
|
- e.printStackTrace();
|
|
|
+ mGridMenuDataInquiryBeans.add(gridMenuDataInquiryBean);
|
|
|
}
|
|
|
}
|
|
|
- break;
|
|
|
- case Constants.APP_SOCKETIMEOUTEXCEPTION:
|
|
|
- progressDialog.dismiss();
|
|
|
- ToastMessage(msg.getData().getString("result"));
|
|
|
- break;
|
|
|
+ mDataInquiryMenuListAdapter.notifyDataSetChanged();
|
|
|
+ }
|
|
|
+ } catch (JSONException e) {
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
|
|
|
public String optStringNotNull(JSONObject json, String key) {
|