|
|
@@ -15,10 +15,12 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baidu.cyberplayer.utils.G;
|
|
|
import com.common.LogUtil;
|
|
|
import com.common.config.BaseConfig;
|
|
|
+import com.common.data.DateFormatUtil;
|
|
|
import com.common.data.JSONUtil;
|
|
|
import com.common.data.ListUtils;
|
|
|
import com.common.data.StringUtil;
|
|
|
import com.common.data.TextUtil;
|
|
|
+import com.common.preferences.PreferenceUtils;
|
|
|
import com.core.app.Constants;
|
|
|
import com.core.app.MyApplication;
|
|
|
import com.core.base.BaseActivity;
|
|
|
@@ -110,9 +112,9 @@ public class CharitSearchActivity extends BaseActivity implements OnPlayListener
|
|
|
voiceSearchView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
|
|
@Override
|
|
|
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
|
|
- if (TextUtils.isEmpty( v.getText())){
|
|
|
- loadData( v.getText().toString());
|
|
|
- }
|
|
|
+ if (TextUtils.isEmpty(v.getText())) {
|
|
|
+ loadData(v.getText().toString());
|
|
|
+ }
|
|
|
return false;
|
|
|
}
|
|
|
});
|
|
|
@@ -136,6 +138,15 @@ public class CharitSearchActivity extends BaseActivity implements OnPlayListener
|
|
|
ToastUtil.showToast(ct, R.string.networks_out);
|
|
|
return;
|
|
|
}
|
|
|
+ if (StringUtil.isEmpty(keyWork)) {
|
|
|
+ String activitys = PreferenceUtils.getString("activitys");
|
|
|
+ try {
|
|
|
+ handlerData(activitys);
|
|
|
+ } catch (Exception e) {
|
|
|
+ progressDialog.dismiss();
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
httpClient.Api().send(new HttpClient.Builder()
|
|
|
.url("activities")
|
|
|
.add("keyWork", keyWork)
|
|
|
@@ -151,6 +162,7 @@ public class CharitSearchActivity extends BaseActivity implements OnPlayListener
|
|
|
handlerData(o.toString());
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
+ progressDialog.dismiss();
|
|
|
if (e != null) {
|
|
|
LogUtil.i("e=" + e.getMessage());
|
|
|
}
|
|
|
@@ -184,27 +196,57 @@ public class CharitSearchActivity extends BaseActivity implements OnPlayListener
|
|
|
}
|
|
|
|
|
|
private void handlerData(String message) throws Exception {
|
|
|
+ if (JSONUtil.validateJSONObject(message)) {
|
|
|
+ handlerDataThread(message);
|
|
|
+ } else if (JSONUtil.validateJSONArray(message)) {
|
|
|
+ handlerDataThread2(message);
|
|
|
+ } else {
|
|
|
+ setAdapter(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void handlerDataThread(String message) throws Exception {
|
|
|
+ List<CharitActModel> allModels = new ArrayList<>();
|
|
|
if (JSONUtil.validateJSONObject(message)) {
|
|
|
JSONObject object = JSON.parseObject(message);
|
|
|
JSONArray array = JSONUtil.getJSONArray(object, "activityList");
|
|
|
- List<CharitActModel> allModels = JSON.parseArray(array.toString(), CharitActModel.class);
|
|
|
-
|
|
|
- List<CharitActModel> showModels = null;
|
|
|
- if (StringUtil.isEmpty(lastKeyWork)) {
|
|
|
- showModels = allModels;
|
|
|
- } else {
|
|
|
- showModels = new ArrayList<>();
|
|
|
- for (CharitActModel e : allModels) {
|
|
|
- if (e.getStage().toLowerCase().contains(lastKeyWork) ||
|
|
|
- e.getName().toLowerCase().contains(lastKeyWork)) {
|
|
|
- showModels.add(e);
|
|
|
- }
|
|
|
+ for (int i = 0; i < array.size(); i++) {
|
|
|
+ JSONObject o = array.getJSONObject(i);
|
|
|
+ CharitActModel e = new CharitActModel();
|
|
|
+ e.setActImg(JSONUtil.getText(o, "actImg"));
|
|
|
+ e.setId(JSONUtil.getInt(o, "id"));
|
|
|
+ e.setName(JSONUtil.getText(o, "name"));
|
|
|
+ e.setStage(JSONUtil.getText(o, "stage"));
|
|
|
+ JSONArray awards = JSONUtil.getJSONArray(o, "awards");
|
|
|
+ StringBuilder builder = new StringBuilder();
|
|
|
+ for (int j = 0; j < awards.size(); j++) {
|
|
|
+ String awardLevel = JSONUtil.getText(awards.getJSONObject(j), "awardLevel");
|
|
|
+ String awardName = JSONUtil.getText(awards.getJSONObject(j), "awardName");
|
|
|
+ builder.append(awardLevel + ":" + awardName + "\n");
|
|
|
}
|
|
|
+ e.setSubTitle(builder.toString());
|
|
|
+ allModels.add(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ setAdapter(allModels);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void handlerDataThread2(String message) throws Exception {
|
|
|
+ List<CharitActModel> allModels = new ArrayList<>();
|
|
|
+ if (JSONUtil.validateJSONArray(message)) {
|
|
|
+ JSONArray array = JSON.parseArray(message);
|
|
|
+ for (int i = 0; i < array.size(); i++) {
|
|
|
+ JSONObject o = array.getJSONObject(i);
|
|
|
+ CharitActModel e = new CharitActModel();
|
|
|
+ e.setActImg(JSONUtil.getText(o, "actImg"));
|
|
|
+ e.setId(JSONUtil.getInt(o, "id"));
|
|
|
+ e.setName(JSONUtil.getText(o, "name"));
|
|
|
+ e.setStage(JSONUtil.getText(o, "stage"));
|
|
|
+ e.setSubTitle(JSONUtil.getText(o, "subTitle"));
|
|
|
+ allModels.add(e);
|
|
|
}
|
|
|
- setAdapter(showModels);
|
|
|
- } else {
|
|
|
- setAdapter(null);
|
|
|
}
|
|
|
+ setAdapter(allModels);
|
|
|
}
|
|
|
|
|
|
private ActivityAdapter activityAdapter;
|
|
|
@@ -218,6 +260,7 @@ public class CharitSearchActivity extends BaseActivity implements OnPlayListener
|
|
|
activityAdapter.setKeyWork(lastKeyWork);
|
|
|
activityAdapter.setModels(models);
|
|
|
}
|
|
|
+ progressDialog.dismiss();
|
|
|
showModels(models);
|
|
|
}
|
|
|
|