|
|
@@ -2,16 +2,21 @@ package com.sheep.gamegroup.view.activity;
|
|
|
|
|
|
import android.app.Activity;
|
|
|
import android.graphics.Color;
|
|
|
+import android.text.Editable;
|
|
|
import android.text.SpannableString;
|
|
|
import android.text.Spanned;
|
|
|
import android.text.TextUtils;
|
|
|
+import android.text.TextWatcher;
|
|
|
import android.text.style.ForegroundColorSpan;
|
|
|
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.sheep.gamegroup.absBase.BaseActivity;
|
|
|
+import com.sheep.gamegroup.alipay.PayResult;
|
|
|
import com.sheep.gamegroup.di.components.DaggerRechargeQComponent;
|
|
|
import com.sheep.gamegroup.di.modules.RechargeQModule;
|
|
|
import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
|
@@ -59,7 +64,7 @@ public class RechargeQAct extends BaseActivity implements RechargeQContract.View
|
|
|
TextView rechargeqSure;
|
|
|
private List<RechargeQEntity> wlLists = new ArrayList<>();
|
|
|
private RechargeQAdapter adapter;
|
|
|
- private int select;
|
|
|
+ private int select = -1;
|
|
|
|
|
|
String text_qq;//充值QQ号
|
|
|
String text_QBNumber;//充值金额
|
|
|
@@ -81,7 +86,7 @@ public class RechargeQAct extends BaseActivity implements RechargeQContract.View
|
|
|
.rechargeQModule(new RechargeQModule(this))
|
|
|
.build()
|
|
|
.inject(this);
|
|
|
- tests();//测试代码------------------测试代码----------------测试代码--------------------测试代码----------------------------
|
|
|
+ initRechargeDatas();
|
|
|
adapter = new RechargeQAdapter(activity, wlLists);
|
|
|
rechargeqGreidview.setVerticalSpacing(20);
|
|
|
rechargeqGreidview.setAdapter(adapter);
|
|
|
@@ -89,6 +94,7 @@ public class RechargeQAct extends BaseActivity implements RechargeQContract.View
|
|
|
rechargeqGreidview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
@Override
|
|
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
|
|
+ etQbNumber.setText("");
|
|
|
select = position;
|
|
|
RechargeQEntity rechargeQEntity = (RechargeQEntity) parent.getItemAtPosition(position);
|
|
|
for (int i = 0; i < wlLists.size(); i++) {
|
|
|
@@ -96,26 +102,56 @@ public class RechargeQAct extends BaseActivity implements RechargeQContract.View
|
|
|
wlLists.get(i).setSelectState(true);
|
|
|
} else {
|
|
|
wlLists.get(i).setSelectState(false);
|
|
|
-
|
|
|
}
|
|
|
- adapter.notifyDataSetChanged();
|
|
|
}
|
|
|
+ adapter.notifyDataSetChanged();
|
|
|
text_QBNumber = rechargeQEntity.getPrice();
|
|
|
- tvMybNumber.setText(String.format(getString(R.string.rechargeq_amount),rechargeQEntity.getPrice()));
|
|
|
+ tvMybNumber.setText(String.format(getString(R.string.rechargeq_amount),text_QBNumber));
|
|
|
}
|
|
|
});
|
|
|
|
|
|
tvZk.setText(getSpannableString());
|
|
|
|
|
|
+
|
|
|
+ etQbNumber.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)){
|
|
|
+ adapter.setInPut(false);
|
|
|
+ if(select != -1 ){
|
|
|
+ RechargeQEntity rechargeQEntity = adapter.getItem(select);
|
|
|
+ text_QBNumber = rechargeQEntity.getPrice();
|
|
|
+ tvMybNumber.setText(String.format(getString(R.string.rechargeq_amount),text_QBNumber));
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ adapter.setInPut(true);
|
|
|
+ tvMybNumber.setText(String.format(getString(R.string.rechargeq_amount),s.toString()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void afterTextChanged(Editable s) {
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- private void tests(){
|
|
|
- wlLists.add(new RechargeQEntity(true,"9.5","10QB"));
|
|
|
- wlLists.add(new RechargeQEntity(true,"19","20QB"));
|
|
|
- wlLists.add(new RechargeQEntity(true,"47.5","50QB"));
|
|
|
- wlLists.add(new RechargeQEntity(true,"95","100QB"));
|
|
|
- wlLists.add(new RechargeQEntity(true,"190","200QB"));
|
|
|
- wlLists.add(new RechargeQEntity(true,"475","500QB"));
|
|
|
+ /**
|
|
|
+ * 初始化写死充值数据
|
|
|
+ */
|
|
|
+ private void initRechargeDatas(){
|
|
|
+ wlLists.add(new RechargeQEntity(false,"10","10QB"));
|
|
|
+ wlLists.add(new RechargeQEntity(false,"20","20QB"));
|
|
|
+ wlLists.add(new RechargeQEntity(false,"50","50QB"));
|
|
|
+ wlLists.add(new RechargeQEntity(false,"100","100QB"));
|
|
|
+ wlLists.add(new RechargeQEntity(false,"200","200QB"));
|
|
|
+ wlLists.add(new RechargeQEntity(false,"500","500QB"));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -150,7 +186,10 @@ public class RechargeQAct extends BaseActivity implements RechargeQContract.View
|
|
|
}
|
|
|
|
|
|
showProgress();
|
|
|
- presenter.goRechargeQ(null);
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("amount",Integer.valueOf(text_QBNumber));
|
|
|
+ jsonObject.put("qq",text_qq);
|
|
|
+ presenter.goRechargeQ(jsonObject);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
@@ -158,6 +197,7 @@ public class RechargeQAct extends BaseActivity implements RechargeQContract.View
|
|
|
@Override
|
|
|
public void succRechargeQ(BaseMessage o) {
|
|
|
hideProgress();
|
|
|
+ pay(o.getData().toString());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -166,6 +206,42 @@ public class RechargeQAct extends BaseActivity implements RechargeQContract.View
|
|
|
G.showToast(o.getMsg());
|
|
|
}
|
|
|
|
|
|
+ private void pay(final String payInfo) {
|
|
|
+ Runnable payRunnable = new Runnable() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ // 构造PayTask 对象
|
|
|
+ PayTask alipay = new PayTask(RechargeQAct.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();
|
|
|
+ Jump2View.getInstance().goRechargeResultAct(RechargeQAct.this, resultStatus);
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ // 必须异步调用
|
|
|
+ Thread payThread = new Thread(payRunnable);
|
|
|
+ payThread.start();
|
|
|
+ }
|
|
|
+
|
|
|
private SpannableString getSpannableString(){
|
|
|
SpannableString spannableString = new SpannableString("(使用绵羊币充值享95折优惠)");
|
|
|
ForegroundColorSpan colorSpan = new ForegroundColorSpan(Color.parseColor("#ff0006"));
|