|
|
@@ -1,22 +1,31 @@
|
|
|
package com.sheep.gamegroup.view.activity;
|
|
|
|
|
|
+import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
+import android.support.v4.content.ContextCompat;
|
|
|
+import android.support.v7.widget.LinearLayoutManager;
|
|
|
+import android.support.v7.widget.RecyclerView;
|
|
|
import android.view.View;
|
|
|
-import android.widget.AdapterView;
|
|
|
import android.widget.EditText;
|
|
|
+import android.widget.TextView;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.alipay.sdk.app.PayTask;
|
|
|
+import com.chad.library.adapter.base.BaseQuickAdapter;
|
|
|
+import com.chad.library.adapter.base.BaseViewHolder;
|
|
|
+import com.sheep.gamegroup.absBase.AbsObserver;
|
|
|
import com.sheep.gamegroup.absBase.BaseActivity;
|
|
|
-import com.sheep.gamegroup.alipay.PayResult;
|
|
|
import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
|
import com.sheep.gamegroup.model.entity.RechargeEntity;
|
|
|
import com.sheep.gamegroup.model.entity.RechargePriceEntity;
|
|
|
import com.sheep.gamegroup.model.util.SheepSubscriber;
|
|
|
+import com.sheep.gamegroup.module.user.activity.ActVip;
|
|
|
+import com.sheep.gamegroup.util.ApiJSONUtil;
|
|
|
+import com.sheep.gamegroup.util.CommonUtil;
|
|
|
import com.sheep.gamegroup.util.Jump2View;
|
|
|
+import com.sheep.gamegroup.util.ListUtil;
|
|
|
import com.sheep.gamegroup.util.LogUtil;
|
|
|
import com.sheep.gamegroup.util.MyGridview;
|
|
|
-import com.sheep.gamegroup.view.adapter.RechargeAdapter;
|
|
|
+import com.sheep.gamegroup.util.ViewUtil;
|
|
|
import com.sheep.gamegroup.view.adapter.RechargePriceAdapter;
|
|
|
import com.sheep.jiuyan.samllsheep.R;
|
|
|
import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
@@ -25,6 +34,7 @@ import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.Locale;
|
|
|
|
|
|
import butterknife.BindView;
|
|
|
import butterknife.OnClick;
|
|
|
@@ -40,25 +50,23 @@ import static com.sheep.gamegroup.util.UMConfigUtils.Event.RECHARGE_PAY;
|
|
|
|
|
|
public class RechargeAct extends BaseActivity {
|
|
|
|
|
|
- int mPayType = -1;//选择支付方式的id
|
|
|
- String mAmount = null;//支付的金额
|
|
|
-
|
|
|
- private boolean forResult = false;
|
|
|
|
|
|
@BindView(R.id.rechargeprice_greidview)
|
|
|
MyGridview rechargeprice_greidview;
|
|
|
- @BindView(R.id.recharge_greidview)
|
|
|
- MyGridview rechargeGreidview;
|
|
|
-
|
|
|
- RechargePriceAdapter rechargePriceAdapter;
|
|
|
- List<RechargePriceEntity> mPriceEntityList = new ArrayList<>();
|
|
|
- int select = -1;
|
|
|
-
|
|
|
- RechargeAdapter rechargeAdapter;
|
|
|
+ @BindView(R.id.act_ral_pay_type_rv)
|
|
|
+ RecyclerView act_ral_pay_type_rv;
|
|
|
@BindView(R.id.et_recharge_price)
|
|
|
EditText etRechargePrice;
|
|
|
|
|
|
|
|
|
+ private RechargePriceAdapter rechargePriceAdapter;
|
|
|
+ private List<RechargePriceEntity> mPriceEntityList = new ArrayList<>();
|
|
|
+
|
|
|
+ private int mPayType = -1;//选择支付方式的id
|
|
|
+ private int payTypePosition = -1;//选择支付方式的位置
|
|
|
+ private String mAmount = null;//支付的金额
|
|
|
+ private boolean forResult = false;
|
|
|
+
|
|
|
@Override
|
|
|
protected int getLayoutId() {
|
|
|
return R.layout.recharge_act_layout;
|
|
|
@@ -88,76 +96,59 @@ public class RechargeAct extends BaseActivity {
|
|
|
rechargePriceAdapter = new RechargePriceAdapter(RechargeAct.this, mPriceEntityList);
|
|
|
rechargeprice_greidview.setVerticalSpacing(20);
|
|
|
rechargeprice_greidview.setAdapter(rechargePriceAdapter);
|
|
|
- rechargeprice_greidview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
- @Override
|
|
|
- public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
|
|
- select = position;
|
|
|
- rechargePriceAdapter.setInPut(false);
|
|
|
- RechargePriceEntity rechargePriceEntity = (RechargePriceEntity) parent.getItemAtPosition(position);
|
|
|
- etRechargePrice.setText("" + rechargePriceEntity.getPrice());
|
|
|
- for (int i = 0; i < mPriceEntityList.size(); i++) {
|
|
|
- if (position == i) {
|
|
|
- mPriceEntityList.get(i).setSelectState(true);
|
|
|
- } else {
|
|
|
- mPriceEntityList.get(i).setSelectState(false);
|
|
|
- }
|
|
|
+ rechargeprice_greidview.setOnItemClickListener((parent, view, position, id) -> {
|
|
|
+ rechargePriceAdapter.setInPut(false);
|
|
|
+ RechargePriceEntity rechargePriceEntity = (RechargePriceEntity) parent.getItemAtPosition(position);
|
|
|
+ ViewUtil.setText(etRechargePrice, rechargePriceEntity.getPrice());
|
|
|
+ for (int i = 0; i < mPriceEntityList.size(); i++) {
|
|
|
+ if (position == i) {
|
|
|
+ mPriceEntityList.get(i).setSelectState(true);
|
|
|
+ } else {
|
|
|
+ mPriceEntityList.get(i).setSelectState(false);
|
|
|
}
|
|
|
- rechargePriceAdapter.notifyDataSetChanged();
|
|
|
-
|
|
|
}
|
|
|
+ rechargePriceAdapter.notifyDataSetChanged();
|
|
|
+
|
|
|
});
|
|
|
|
|
|
|
|
|
/*
|
|
|
支付方式选择
|
|
|
*/
|
|
|
- rechargeAdapter = new RechargeAdapter(RechargeAct.this);
|
|
|
- rechargeGreidview.setVerticalSpacing(40);
|
|
|
- rechargeGreidview.setAdapter(rechargeAdapter);
|
|
|
- rechargeGreidview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
+ BaseQuickAdapter<RechargeEntity, BaseViewHolder> rechargeAdapter = new BaseQuickAdapter<RechargeEntity, BaseViewHolder>(R.layout.recharge_gridview_item, rechargeEntityList){
|
|
|
+
|
|
|
@Override
|
|
|
- public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
|
|
- RechargeEntity rechargeEntity = (RechargeEntity) parent.getItemAtPosition(position);
|
|
|
- mPayType = rechargeEntity.getId();
|
|
|
- rechargeAdapter.setSelect(position);
|
|
|
- rechargeAdapter.notifyDataSetChanged();
|
|
|
- }
|
|
|
- });
|
|
|
+ protected void convert(BaseViewHolder helper, RechargeEntity item) {
|
|
|
+ int position = helper.getAdapterPosition();
|
|
|
|
|
|
-// etRechargePrice.addTextChangedListener(new TextWatcher() {
|
|
|
-// @Override
|
|
|
-// public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
|
-//
|
|
|
-// }
|
|
|
-//
|
|
|
-// @Override
|
|
|
-// public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
|
-// if(TextUtils.isEmpty(s)){
|
|
|
-// rechargePriceAdapter.setInPut(false);
|
|
|
-// }else{
|
|
|
-// boolean input = true;
|
|
|
-// for(RechargePriceEntity priceEntityList : mPriceEntityList){
|
|
|
-// int price = Integer.valueOf(s.toString());
|
|
|
-// if(price == priceEntityList.getPrice()){
|
|
|
-// input = false;
|
|
|
-// break;
|
|
|
-// }
|
|
|
-// }
|
|
|
-// rechargePriceAdapter.setInPut(input);
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// @Override
|
|
|
-// public void afterTextChanged(Editable s) {
|
|
|
-//
|
|
|
-// }
|
|
|
-// });
|
|
|
+ TextView tv_pay = helper.getView(R.id.tv_pay);
|
|
|
|
|
|
+ ViewUtil.setText(tv_pay, item.getName());
|
|
|
+ Context context = SheepApp.getInstance();
|
|
|
+ if (position == payTypePosition){
|
|
|
+ tv_pay.setBackground(context.getResources().getDrawable(R.drawable.layer_list_check_rectgangle_small));
|
|
|
+ tv_pay.setTextColor(ContextCompat.getColor(context,R.color.main_tab_activated));
|
|
|
+ }else{
|
|
|
+ tv_pay.setBackground(context.getResources().getDrawable(R.drawable.btn_main_stroke_no_check_small));
|
|
|
+ tv_pay.setTextColor(ContextCompat.getColor(context,R.color.main_tab));
|
|
|
+
|
|
|
+ }
|
|
|
+ //这里点击
|
|
|
+ tv_pay.setOnClickListener(view -> {
|
|
|
+ payTypePosition = position;
|
|
|
+ mPayType = item.getId();
|
|
|
+ ViewUtil.notifyDataSetChanged(act_ral_pay_type_rv);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ };
|
|
|
+ act_ral_pay_type_rv.setLayoutManager(new LinearLayoutManager(SheepApp.getInstance()));
|
|
|
+ rechargeAdapter.bindToRecyclerView(act_ral_pay_type_rv);
|
|
|
|
|
|
showProgress();
|
|
|
getRechargePayway();
|
|
|
}
|
|
|
|
|
|
+ private List<RechargeEntity> rechargeEntityList = new ArrayList<>();
|
|
|
private void getRechargePayway() {
|
|
|
// 参数 1:没有绵羊币的,2:是全部
|
|
|
SheepApp.getInstance().getNetComponent().getApiService().getRechargePayway("1")
|
|
|
@@ -168,22 +159,19 @@ public class RechargeAct extends BaseActivity {
|
|
|
public void onNext(BaseMessage baseMessage) {
|
|
|
hideProgress();
|
|
|
List<RechargeEntity> list = baseMessage.getDatas(RechargeEntity.class);
|
|
|
- if (list != null && list.size() > 0) {
|
|
|
- mPayType = list.get(0).getId();
|
|
|
- rechargeAdapter.setSelect(0);
|
|
|
- }
|
|
|
- rechargeAdapter.addAll(list);
|
|
|
- if (!list.isEmpty()) {
|
|
|
- mPayType = list.get(0).getId();
|
|
|
- rechargeAdapter.setSelect(0);
|
|
|
- rechargeAdapter.notifyDataSetChanged();
|
|
|
+ if (!ListUtil.isEmpty(list)) {
|
|
|
+ payTypePosition = 0;
|
|
|
+ mPayType = list.get(payTypePosition).getId();
|
|
|
+ rechargeEntityList.clear();
|
|
|
+ rechargeEntityList.addAll(list);
|
|
|
+ ViewUtil.notifyDataSetChanged(act_ral_pay_type_rv);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onError(BaseMessage baseMessage) {
|
|
|
hideProgress();
|
|
|
- G.showToast(baseMessage.getMsg() + "");
|
|
|
+ G.showToast(baseMessage);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
@@ -199,7 +187,15 @@ public class RechargeAct extends BaseActivity {
|
|
|
@Override
|
|
|
public void onNext(BaseMessage baseMessage) {
|
|
|
hideProgress();
|
|
|
- pay(baseMessage.getData().toString());
|
|
|
+ String payInfo = baseMessage.getData().toString();
|
|
|
+ switch (mPayType){
|
|
|
+ case 1:
|
|
|
+ tryAliPay(payInfo);
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ tryWxPay(baseMessage);
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -210,6 +206,16 @@ public class RechargeAct extends BaseActivity {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ private void tryWxPay(BaseMessage baseMessage) {
|
|
|
+ JSONObject jsonObject = baseMessage.getData(JSONObject.class);
|
|
|
+ if(jsonObject == null){
|
|
|
+ G.showToast(R.string.please_contact_customer_service);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ CommonUtil.getInstance().wxpay(SheepApp.getInstance().getWxApi(), jsonObject);
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+
|
|
|
@OnClick({R.id.tv_recharge_pay})
|
|
|
public void onViewClicked(View view) {
|
|
|
switch (view.getId()) {
|
|
|
@@ -234,64 +240,87 @@ public class RechargeAct extends BaseActivity {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void pay(final String payInfo) {
|
|
|
- Runnable payRunnable = new Runnable() {
|
|
|
-
|
|
|
+ private void tryAliPay(final String payInfo) {
|
|
|
+ CommonUtil.getInstance().alipay(this, payInfo, true, new AbsObserver<String>() {
|
|
|
@Override
|
|
|
- public void run() {
|
|
|
- // 构造PayTask 对象
|
|
|
- PayTask alipay = new PayTask(RechargeAct.this);
|
|
|
- // 调用支付接口,获取支付结果
|
|
|
- final String result = alipay.pay(payInfo, true);
|
|
|
-
|
|
|
- runOnUiThread(new Runnable() {
|
|
|
-
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
-
|
|
|
- PayResult payResult = new PayResult(result);
|
|
|
- /*
|
|
|
- 同步返回的结果必须放置到服务端进行验证(验证的规则请看https://doc.open.alipay.com/doc2/
|
|
|
- detail.htm?spm=0.0.0.0.xdvAU6&treeId=59&articleId=103665&
|
|
|
- docType=1) 建议商户依赖异步通知
|
|
|
- */
|
|
|
-// String resultInfo = payResult.getResult();// 同步返回需要验证的信息
|
|
|
-
|
|
|
- String resultStatus = payResult.getResultStatus();
|
|
|
- if ("9000".equals(resultStatus)) {
|
|
|
- JSONObject json = new JSONObject();
|
|
|
- json.put("act", 4);
|
|
|
- SheepApp.getInstance().getNetComponent().getApiService()
|
|
|
- .missionExecute(json)
|
|
|
- .subscribeOn(Schedulers.io())
|
|
|
- .observeOn(AndroidSchedulers.mainThread())
|
|
|
- .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
|
|
|
- @Override
|
|
|
- public void onError(BaseMessage baseMessage) {
|
|
|
- LogUtil.logE(baseMessage.getErrorMsg() + " " + baseMessage.getMsg());
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onNext(BaseMessage baseMessage) {
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- if (forResult && "9000".equals(resultStatus)) {
|
|
|
- Intent intent = new Intent();
|
|
|
- intent.putExtra("amount", Integer.parseInt(mAmount));
|
|
|
- setResult(777, intent);
|
|
|
- } else {
|
|
|
- Jump2View.getInstance().goRechargeResultAct(RechargeAct.this, resultStatus);
|
|
|
- }
|
|
|
- finish();
|
|
|
- }
|
|
|
- });
|
|
|
+ public void onNext(String result) {
|
|
|
+ LogUtil.println(ActVip.class.getSimpleName(), String.format(Locale.CHINA, "alipay onNext('%s')", result));
|
|
|
+ if ("9000".equals(result)) {
|
|
|
+ ApiJSONUtil.missionExecute(4);
|
|
|
+ }
|
|
|
+ if (forResult && "9000".equals(result)) {
|
|
|
+ Intent intent = new Intent();
|
|
|
+ intent.putExtra("amount", Integer.parseInt(mAmount));
|
|
|
+ setResult(777, intent);
|
|
|
+ } else {
|
|
|
+ Jump2View.getInstance().goRechargeResultAct(RechargeAct.this, result);
|
|
|
+ }
|
|
|
+ finish();
|
|
|
}
|
|
|
- };
|
|
|
|
|
|
- // 必须异步调用
|
|
|
- Thread payThread = new Thread(payRunnable);
|
|
|
- payThread.start();
|
|
|
+ @Override
|
|
|
+ public void onError(Throwable e) {
|
|
|
+ G.showToast(e);
|
|
|
+ LogUtil.println(ActVip.class.getSimpleName(), String.format(Locale.CHINA, "alipay onError('%s')", e.getMessage()));
|
|
|
+ }
|
|
|
+ });
|
|
|
+// Runnable payRunnable = new Runnable() {
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public void run() {
|
|
|
+// // 构造PayTask 对象
|
|
|
+// PayTask alipay = new PayTask(RechargeAct.this);
|
|
|
+// // 调用支付接口,获取支付结果
|
|
|
+// final String result = alipay.tryAliPay(payInfo, true);
|
|
|
+//
|
|
|
+// runOnUiThread(new Runnable() {
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public void run() {
|
|
|
+//
|
|
|
+// PayResult payResult = new PayResult(result);
|
|
|
+// /*
|
|
|
+// 同步返回的结果必须放置到服务端进行验证(验证的规则请看https://doc.open.alipay.com/doc2/
|
|
|
+// detail.htm?spm=0.0.0.0.xdvAU6&treeId=59&articleId=103665&
|
|
|
+// docType=1) 建议商户依赖异步通知
|
|
|
+// */
|
|
|
+//// String resultInfo = payResult.getResult();// 同步返回需要验证的信息
|
|
|
+//
|
|
|
+// String resultStatus = payResult.getResultStatus();
|
|
|
+// if ("9000".equals(resultStatus)) {
|
|
|
+// JSONObject json = new JSONObject();
|
|
|
+// json.put("act", 4);
|
|
|
+// SheepApp.getInstance().getNetComponent().getApiService()
|
|
|
+// .missionExecute(json)
|
|
|
+// .subscribeOn(Schedulers.io())
|
|
|
+// .observeOn(AndroidSchedulers.mainThread())
|
|
|
+// .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
|
|
|
+// @Override
|
|
|
+// public void onError(BaseMessage baseMessage) {
|
|
|
+// LogUtil.logE(baseMessage.getErrorMsg() + " " + baseMessage.getMsg());
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public void onNext(BaseMessage baseMessage) {
|
|
|
+// }
|
|
|
+// });
|
|
|
+// }
|
|
|
+// if (forResult && "9000".equals(resultStatus)) {
|
|
|
+// Intent intent = new Intent();
|
|
|
+// intent.putExtra("amount", Integer.parseInt(mAmount));
|
|
|
+// setResult(777, intent);
|
|
|
+// } else {
|
|
|
+// Jump2View.getInstance().goRechargeResultAct(RechargeAct.this, resultStatus);
|
|
|
+// }
|
|
|
+// finish();
|
|
|
+// }
|
|
|
+// });
|
|
|
+// }
|
|
|
+// };
|
|
|
+//
|
|
|
+// // 必须异步调用
|
|
|
+// Thread payThread = new Thread(payRunnable);
|
|
|
+// payThread.start();
|
|
|
}
|
|
|
|
|
|
private void addDatas() {
|