|
|
@@ -11,6 +11,7 @@ import android.widget.Toast;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.alipay.sdk.app.EnvUtils;
|
|
|
import com.common.LogUtil;
|
|
|
import com.common.config.BaseConfig;
|
|
|
import com.common.data.JSONUtil;
|
|
|
@@ -19,6 +20,7 @@ import com.core.app.Constants;
|
|
|
import com.core.base.BaseActivity;
|
|
|
import com.core.utils.IntentUtils;
|
|
|
import com.core.utils.ToastUtil;
|
|
|
+import com.core.widget.EmptyLayout;
|
|
|
import com.core.widget.VoiceSearchView;
|
|
|
import com.core.widget.listener.EditChangeListener;
|
|
|
import com.handmark.pulltorefresh.library.PullToRefreshListView;
|
|
|
@@ -26,18 +28,25 @@ import com.me.network.app.http.HttpClient;
|
|
|
import com.me.network.app.http.Method;
|
|
|
import com.me.network.app.http.rx.ResultListener;
|
|
|
import com.me.network.app.http.rx.ResultSubscriber;
|
|
|
+import com.modular.apputils.listener.OnPlayListener;
|
|
|
+import com.modular.apputils.utils.playsdk.AliPlay;
|
|
|
import com.uas.appworks.OA.platform.adapter.ActivityAdapter;
|
|
|
import com.uas.appworks.OA.platform.adapter.CharitableAdapter;
|
|
|
+import com.uas.appworks.OA.platform.model.CharitActModel;
|
|
|
import com.uas.appworks.OA.platform.model.CharitModel;
|
|
|
import com.uas.appworks.OA.platform.model.TestString;
|
|
|
import com.uas.appworks.R;
|
|
|
+import com.uas.appworks.widget.SelectPlayPop;
|
|
|
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
-public class CharitSearchActivity extends BaseActivity {
|
|
|
+public class CharitSearchActivity extends BaseActivity implements OnPlayListener {
|
|
|
private HttpClient httpClient = new HttpClient.Builder(Constants.charitBaseUrl()).isDebug(true).build();
|
|
|
|
|
|
private PullToRefreshListView refreshListView;
|
|
|
+ private EmptyLayout mEmptyLayout;
|
|
|
private int type;
|
|
|
|
|
|
@Override
|
|
|
@@ -59,6 +68,10 @@ public class CharitSearchActivity extends BaseActivity {
|
|
|
type = 1;
|
|
|
}
|
|
|
refreshListView = (PullToRefreshListView) findViewById(R.id.refreshListView);
|
|
|
+ mEmptyLayout = new EmptyLayout(this, refreshListView.getRefreshableView());
|
|
|
+ mEmptyLayout.setShowLoadingButton(false);
|
|
|
+ mEmptyLayout.setShowEmptyButton(false);
|
|
|
+ mEmptyLayout.setShowErrorButton(false);
|
|
|
VoiceSearchView voiceSearchView = (VoiceSearchView) findViewById(R.id.voiceSearchView);
|
|
|
refreshListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
@Override
|
|
|
@@ -66,9 +79,19 @@ public class CharitSearchActivity extends BaseActivity {
|
|
|
LogUtil.i("i==" + i);
|
|
|
LogUtil.i("l==" + l);
|
|
|
if (type == 1) {
|
|
|
- IntentUtils.linkCommonWeb(ct, Constants.BASE_CHARIT_PROJECT_URL);
|
|
|
+ if (charitableAdapter != null) {
|
|
|
+ CharitModel model = charitableAdapter.getModels(i);
|
|
|
+ if (model != null) {
|
|
|
+ IntentUtils.linkCommonWeb(ct, Constants.BASE_CHARIT_PROJECT_URL + "/" + model.getId(), model.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
} else {
|
|
|
- IntentUtils.linkCommonWeb(ct, Constants.BASE_CHARIT_ACTIVITY_URL);
|
|
|
+ if (activityAdapter != null && ListUtils.getSize(activityAdapter.getModels()) > i) {
|
|
|
+ CharitActModel model = activityAdapter.getModels().get(i);
|
|
|
+ if (model != null) {
|
|
|
+ IntentUtils.linkCommonWeb(ct, Constants.BASE_CHARIT_ACTIVITY_URL + "/" + model.getId(), model.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
@@ -104,7 +127,7 @@ public class CharitSearchActivity extends BaseActivity {
|
|
|
public void onResponse(Object o) {
|
|
|
if (!keyWork.equals(lastKeyWork)) return;
|
|
|
try {
|
|
|
- if (o != null && !BaseConfig.isDebug()) {
|
|
|
+ if (o != null) {
|
|
|
handlerData(o.toString());
|
|
|
} else {
|
|
|
handlerData(TestString.PROJECTS_DATA);
|
|
|
@@ -133,7 +156,7 @@ public class CharitSearchActivity extends BaseActivity {
|
|
|
if (!keyWork.equals(lastKeyWork)) return;
|
|
|
|
|
|
try {
|
|
|
- if (o != null && !BaseConfig.isDebug()) {
|
|
|
+ if (o != null) {
|
|
|
handlerProjects(o.toString());
|
|
|
} else {
|
|
|
handlerProjects(TestString.PROJECTS_DATA);
|
|
|
@@ -148,8 +171,28 @@ public class CharitSearchActivity extends BaseActivity {
|
|
|
}
|
|
|
|
|
|
private void handlerData(String message) throws Exception {
|
|
|
- LogUtil.i("handlerData");
|
|
|
- refreshListView.setAdapter(new ActivityAdapter(ct, null));
|
|
|
+ if (JSONUtil.validateJSONObject(message)) {
|
|
|
+ JSONObject object = JSON.parseObject(message);
|
|
|
+ JSONArray array = JSONUtil.getJSONArray(object, "activityList");
|
|
|
+ List<CharitActModel> allModels = JSON.parseArray(array.toString(), CharitActModel.class);
|
|
|
+ setAdapter(allModels);
|
|
|
+ } else {
|
|
|
+ setAdapter(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private ActivityAdapter activityAdapter;
|
|
|
+
|
|
|
+ private void setAdapter(List<CharitActModel> models) {
|
|
|
+ if (activityAdapter == null) {
|
|
|
+ activityAdapter = new ActivityAdapter(ct, models);
|
|
|
+ refreshListView.setAdapter(activityAdapter);
|
|
|
+ } else {
|
|
|
+ activityAdapter.setModels(models);
|
|
|
+ }
|
|
|
+ if (ListUtils.isEmpty(models)) {
|
|
|
+ mEmptyLayout.showEmpty();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private void handlerProjects(String message) throws Exception {
|
|
|
@@ -161,15 +204,72 @@ public class CharitSearchActivity extends BaseActivity {
|
|
|
projectList = JSONUtil.getJSONArray(message, "projectList");
|
|
|
}
|
|
|
List<CharitModel> models = JSON.parseArray(projectList.toJSONString(), CharitModel.class);
|
|
|
- LogUtil.i("models=" + models.size());
|
|
|
- refreshListView.setAdapter(new CharitableAdapter(ct, models, mListener));
|
|
|
+ setProjectsAdapter(models);
|
|
|
+ }
|
|
|
+
|
|
|
+ private CharitableAdapter charitableAdapter = null;
|
|
|
+
|
|
|
+ private void setProjectsAdapter(List<CharitModel> models) {
|
|
|
+ if (charitableAdapter == null) {
|
|
|
+ refreshListView.setAdapter(charitableAdapter = new CharitableAdapter(ct, models, mListener));
|
|
|
+ } else {
|
|
|
+ charitableAdapter.setModels(models);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
private CharitableAdapter.MyClickListener mListener = new CharitableAdapter.MyClickListener() {
|
|
|
@Override
|
|
|
public void myOnClick(int position, View v) {
|
|
|
- ToastUtil.showToast(ct, "付款付款付款付款付款付款付款");
|
|
|
+ SelectPlayPop.showPlay(CharitSearchActivity.this, charitableAdapter.getModels(position), new SelectPlayPop.OnSureListener() {
|
|
|
+ @Override
|
|
|
+ public void sure(double num, int type, CharitModel model) {
|
|
|
+ if (type == 1) {
|
|
|
+ LogUtil.i("选择了微信支付");
|
|
|
+ } else {
|
|
|
+ LogUtil.i("选择了支付宝支付");
|
|
|
+ }
|
|
|
+ loadOrderInfo(num, model);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
};
|
|
|
+
|
|
|
+
|
|
|
+ private void loadOrderInfo(Double amount, CharitModel model) {
|
|
|
+ progressDialog.show();
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("projectName", model.getName());
|
|
|
+ map.put("amount", amount);
|
|
|
+ map.put("proId", model.getId());
|
|
|
+ String json = JSON.toJSONString(map);
|
|
|
+ LogUtil.i("json=" + json);
|
|
|
+ new HttpClient.Builder("http://lj.ubtob.com/alipay/")
|
|
|
+ .isDebug(BaseConfig.isDebug())
|
|
|
+ .build()
|
|
|
+ .Api()
|
|
|
+ .send(new HttpClient.Builder()
|
|
|
+ .url("appPay")
|
|
|
+ .add("jsonStr", json)
|
|
|
+ .method(Method.GET)
|
|
|
+ .build(), new ResultSubscriber<>(new ResultListener<Object>() {
|
|
|
+ @Override
|
|
|
+ public void onResponse(Object o) {
|
|
|
+ String message = o.toString();
|
|
|
+ LogUtil.i("message=" + message);
|
|
|
+ AliPlay.api().alipay(CharitSearchActivity.this, message, CharitSearchActivity.this);
|
|
|
+ progressDialog.dismiss();
|
|
|
+ }
|
|
|
+ }));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onSuccess(String resultStatus, String resultInfo) {
|
|
|
+ ToastUtil.showToast(ct, "支付成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFailure(String resultStatus, String resultInfo) {
|
|
|
+ ToastUtil.showToast(ct, "支付失败");
|
|
|
+ }
|
|
|
}
|