yang_div пре 8 година
родитељ
комит
410fbf91d3

+ 62 - 13
app/src/main/java/com/sheep/gamegroup/view/activity/RechargeAct.java

@@ -1,7 +1,12 @@
 package com.sheep.gamegroup.view.activity;
 
+import android.os.Bundle;
+import android.text.Editable;
+import android.text.TextUtils;
+import android.text.TextWatcher;
 import android.view.View;
 import android.widget.AdapterView;
+import android.widget.EditText;
 
 import com.alibaba.fastjson.JSONObject;
 import com.alipay.sdk.app.PayTask;
@@ -10,6 +15,7 @@ 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.entity.RechargeQEntity;
 import com.sheep.gamegroup.model.util.SheepSubscriber;
 import com.sheep.gamegroup.util.Jump2View;
 import com.sheep.gamegroup.util.MyGridview;
@@ -24,6 +30,7 @@ import java.util.ArrayList;
 import java.util.List;
 
 import butterknife.BindView;
+import butterknife.ButterKnife;
 import butterknife.OnClick;
 import rx.android.schedulers.AndroidSchedulers;
 import rx.schedulers.Schedulers;
@@ -48,6 +55,8 @@ public class RechargeAct extends BaseActivity {
     int select = -1;
 
     RechargeAdapter rechargeAdapter;
+    @BindView(R.id.et_recharge_price)
+    EditText etRechargePrice;
 
 
     @Override
@@ -69,6 +78,9 @@ public class RechargeAct extends BaseActivity {
     @Override
     public void initData() {
         addDatas();
+        /**
+         * 支付金额选择
+         */
         rechargePriceAdapter = new RechargePriceAdapter(RechargeAct.this, mPriceEntityList);
         rechargeprice_greidview.setVerticalSpacing(20);
         rechargeprice_greidview.setAdapter(rechargePriceAdapter);
@@ -76,33 +88,67 @@ public class RechargeAct extends BaseActivity {
             @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);
-
                     }
-                    rechargePriceAdapter.notifyDataSetChanged();
                 }
+                rechargePriceAdapter.notifyDataSetChanged();
+
             }
         });
 
 
+        /**
+         * 支付方式选择
+         */
         rechargeAdapter = new RechargeAdapter(RechargeAct.this);
-
         rechargeGreidview.setVerticalSpacing(40);
         rechargeGreidview.setAdapter(rechargeAdapter);
         rechargeGreidview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
             @Override
             public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
-                RechargeEntity  rechargeEntity = (RechargeEntity) parent.getItemAtPosition(position);
+                RechargeEntity rechargeEntity = (RechargeEntity) parent.getItemAtPosition(position);
                 mPayType = rechargeEntity.getId();
                 rechargeAdapter.setSelect(position);
                 rechargeAdapter.notifyDataSetChanged();
             }
         });
 
+//        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) {
+//
+//            }
+//        });
+
 
         showProgress();
         getRechargePayway();
@@ -153,7 +199,6 @@ public class RechargeAct extends BaseActivity {
 
     @OnClick({R.id.tv_recharge_pay})
     public void onViewClicked(View view) {
-        RechargeEntity rechargeEntity;
         switch (view.getId()) {
 
             case R.id.tv_recharge_pay:
@@ -161,11 +206,14 @@ public class RechargeAct extends BaseActivity {
                     G.showToast("请选择支付方式");
                     return;
                 }
-                if (select == -1) {
+
+                mAmount = etRechargePrice.getText().toString().trim();
+                if(android.text.TextUtils.isEmpty(mAmount)){
                     G.showToast("请选择充值金额");
                     return;
                 }
-                mAmount = String.valueOf(mPriceEntityList.get(select).getPrice());
+
+
                 showProgress();
                 getRechargeBalance();
                 break;
@@ -209,11 +257,12 @@ public class RechargeAct extends BaseActivity {
     }
 
     private void addDatas() {
-        mPriceEntityList.add(new RechargePriceEntity(false, "10元", 10));
-        mPriceEntityList.add(new RechargePriceEntity(false, "20元", 20));
-        mPriceEntityList.add(new RechargePriceEntity(false, "50元", 50));
-        mPriceEntityList.add(new RechargePriceEntity(false, "100元", 100));
-        mPriceEntityList.add(new RechargePriceEntity(false, "200元", 200));
-        mPriceEntityList.add(new RechargePriceEntity(false, "500元", 500));
+        mPriceEntityList.add(new RechargePriceEntity(false,"10元", 10));
+        mPriceEntityList.add(new RechargePriceEntity(false,"20元", 20));
+        mPriceEntityList.add(new RechargePriceEntity(false,"50元", 50));
+        mPriceEntityList.add(new RechargePriceEntity(false,"100元", 100));
+        mPriceEntityList.add(new RechargePriceEntity(false,"200元", 200));
+        mPriceEntityList.add(new RechargePriceEntity(false,"500元", 500));
     }
+
 }

+ 3 - 38
app/src/main/java/com/sheep/gamegroup/view/activity/RechargeQAct.java

@@ -14,9 +14,7 @@ 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;
@@ -197,7 +195,9 @@ public class RechargeQAct extends BaseActivity implements RechargeQContract.View
     @Override
     public void succRechargeQ(BaseMessage o) {
         hideProgress();
-        pay(o.getData().toString());
+//   "模拟支付宝成功,因为支付宝支持成功返回9000,跳转到统一界面"
+        Jump2View.getInstance().goRechargeResultAct(RechargeQAct.this, "9000");
+        finish();
     }
 
     @Override
@@ -206,41 +206,6 @@ 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折优惠)");

+ 1 - 1
app/src/main/java/com/sheep/gamegroup/view/adapter/RechargeAdapter.java

@@ -51,7 +51,7 @@ public class RechargeAdapter extends BaseAdapter {
 
     @Override
     public long getItemId(int position) {
-        return 0;
+        return position;
     }
 
     @Override

+ 15 - 4
app/src/main/java/com/sheep/gamegroup/view/adapter/RechargePriceAdapter.java

@@ -22,12 +22,18 @@ import java.util.List;
 public class RechargePriceAdapter extends BaseAdapter {
     private Context context;
     private List<RechargePriceEntity> listData;
+    private  boolean inPut = false;
 
     public RechargePriceAdapter(Context context, List<RechargePriceEntity> listData) {
         this.context = context;
         this.listData = listData;
     }
 
+    public void setInPut(boolean inPut) {
+        this.inPut = inPut;
+        notifyDataSetChanged();
+    }
+
     @Override
     public int getCount() {
         return listData.size();
@@ -63,12 +69,17 @@ public class RechargePriceAdapter extends BaseAdapter {
             holder = (ViewHolder) convertView.getTag();
         }
         RechargePriceEntity priceShow = getItem(position);
-        if (priceShow.isSelectState()){
-            convertView.setBackground(context.getResources().getDrawable(R.drawable.recharge_bg_angle_blue_hold));
-            holder.item_tv_y.setTextColor(ContextCompat.getColor(context,R.color.white));
-        }else{
+        if(inPut){
             convertView.setBackground(context.getResources().getDrawable(R.drawable.recharge_bg_angle_blue_normal));
             holder.item_tv_y.setTextColor(ContextCompat.getColor(context,R.color.blue_end));
+        }else{
+            if (priceShow.isSelectState()){
+                convertView.setBackground(context.getResources().getDrawable(R.drawable.recharge_bg_angle_blue_hold));
+                holder.item_tv_y.setTextColor(ContextCompat.getColor(context,R.color.white));
+            }else{
+                convertView.setBackground(context.getResources().getDrawable(R.drawable.recharge_bg_angle_blue_normal));
+                holder.item_tv_y.setTextColor(ContextCompat.getColor(context,R.color.blue_end));
+            }
         }
 
         holder.item_tv_y.setText(priceShow.getValue());

+ 3 - 0
app/src/main/res/layout/recharge_act_layout.xml

@@ -55,11 +55,14 @@
                         android:visibility="visible" />
 
                     <EditText
+                        android:id="@+id/et_recharge_price"
                         android:layout_width="match_parent"
                         android:layout_height="40dp"
                         android:layout_marginTop="@dimen/content_padding_10"
                         android:background="@null"
                         android:hint="请输入充值金额"
+                        android:inputType="number"
+                        android:maxLength="5"
                         android:paddingLeft="@dimen/content_padding_big"
                         android:textColor="@color/black_444444"
                         android:textColorHint="@color/disenable_color"