|
@@ -1,6 +1,5 @@
|
|
package com.jixin.im.ui.me;
|
|
package com.jixin.im.ui.me;
|
|
|
|
|
|
-import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
import androidx.recyclerview.widget.GridLayoutManager;
|
|
import androidx.recyclerview.widget.GridLayoutManager;
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
|
@@ -9,22 +8,36 @@ import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.View;
|
|
import android.widget.ImageView;
|
|
import android.widget.ImageView;
|
|
import android.widget.LinearLayout;
|
|
import android.widget.LinearLayout;
|
|
|
|
+import android.widget.TableRow;
|
|
import android.widget.TextView;
|
|
import android.widget.TextView;
|
|
|
|
|
|
import com.chad.library.adapter.base.BaseQuickAdapter;
|
|
import com.chad.library.adapter.base.BaseQuickAdapter;
|
|
import com.chad.library.adapter.base.BaseViewHolder;
|
|
import com.chad.library.adapter.base.BaseViewHolder;
|
|
import com.jixin.im.R;
|
|
import com.jixin.im.R;
|
|
|
|
+import com.jixin.im.bean.GiftBalanceConfigBean;
|
|
|
|
+import com.jixin.im.bean.RechargeCoinBean;
|
|
|
|
+import com.jixin.im.helper.DialogHelper;
|
|
import com.jixin.im.ui.base.BaseActivity;
|
|
import com.jixin.im.ui.base.BaseActivity;
|
|
|
|
+import com.jixin.im.ui.base.EasyFragment;
|
|
import com.jixin.im.util.StringUtils;
|
|
import com.jixin.im.util.StringUtils;
|
|
|
|
+import com.jixin.im.util.ToastUtil;
|
|
|
|
+import com.xuan.xuanhttplibrary.okhttp.HttpUtils;
|
|
|
|
+import com.xuan.xuanhttplibrary.okhttp.callback.BaseCallback;
|
|
|
|
+import com.xuan.xuanhttplibrary.okhttp.result.ObjectResult;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
|
+import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+
|
|
|
|
+import okhttp3.Call;
|
|
|
|
|
|
public class JunYouCoinRechargeActivity extends BaseActivity {
|
|
public class JunYouCoinRechargeActivity extends BaseActivity {
|
|
|
|
|
|
private RecyclerView mRecyclerViewRecharge;
|
|
private RecyclerView mRecyclerViewRecharge;
|
|
private RechargeAdapter mRechargeAdapter;
|
|
private RechargeAdapter mRechargeAdapter;
|
|
private TextView mJunYouBalanceTv;
|
|
private TextView mJunYouBalanceTv;
|
|
|
|
+ private final double[] sRechargeMoneyArray = new double[]{10, 30, 80, 120, 200, 800};
|
|
|
|
|
|
@Override
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
@@ -33,7 +46,7 @@ public class JunYouCoinRechargeActivity extends BaseActivity {
|
|
initActionBar();
|
|
initActionBar();
|
|
mRecyclerViewRecharge = findViewById(R.id.recycler_view_recharge);
|
|
mRecyclerViewRecharge = findViewById(R.id.recycler_view_recharge);
|
|
initRecyclerView();
|
|
initRecyclerView();
|
|
- test();
|
|
|
|
|
|
+ getDataAsyn();
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -48,19 +61,108 @@ public class JunYouCoinRechargeActivity extends BaseActivity {
|
|
mRecyclerViewRecharge.setAdapter(mRechargeAdapter);
|
|
mRecyclerViewRecharge.setAdapter(mRechargeAdapter);
|
|
mRechargeAdapter.bindToRecyclerView(mRecyclerViewRecharge);
|
|
mRechargeAdapter.bindToRecyclerView(mRecyclerViewRecharge);
|
|
mRechargeAdapter.setOnItemClickListener((adapter, view, position) -> {
|
|
mRechargeAdapter.setOnItemClickListener((adapter, view, position) -> {
|
|
- mRechargeAdapter.mSelectedPosition= position;
|
|
|
|
- mRechargeAdapter.notifyDataSetChanged();
|
|
|
|
|
|
+ mRechargeAdapter.mSelectedPosition = position;
|
|
|
|
+ mRechargeAdapter.notifyDataSetChanged();
|
|
|
|
|
|
}
|
|
}
|
|
);
|
|
);
|
|
|
|
+ mRechargeAdapter.setOnItemChildClickListener(((adapter, view, position) -> {
|
|
|
|
+ if (view.getId() ==R.id.tv_buy_coin){
|
|
|
|
+ mRechargeAdapter.mSelectedPosition = position;
|
|
|
|
+ mRechargeAdapter.notifyDataSetChanged();
|
|
|
|
+ RechargeCoinBean bean = mRechargeAdapter.getItem(position);
|
|
|
|
+ buyGiftBalance(bean.getRechargeMoney());
|
|
|
|
+ }
|
|
|
|
+ }));
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private void buyGiftBalance(String money){
|
|
|
|
+ Map<String, String> params = new HashMap<>();
|
|
|
|
+ params.put("access_token", coreManager.getSelfStatus().accessToken);
|
|
|
|
+ params.put("money", money);
|
|
|
|
+ String url = coreManager.getConfig().BUY_GIFT_BALANCE;
|
|
|
|
+ DialogHelper.showDefaulteMessageProgressDialog(this);
|
|
|
|
+ HttpUtils.post().url(url)
|
|
|
|
+ .params(params)
|
|
|
|
+ .build()
|
|
|
|
+ .execute(new BaseCallback<Double>(Double.class) {
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onResponse(ObjectResult<Double> result) {
|
|
|
|
+ DialogHelper.dismissProgressDialog();
|
|
|
|
+ if (result != null && result.getResultCode() ==1) {
|
|
|
|
+ double balance = mGiftBalanceConfigBean.getGiftBalance()+Double.parseDouble(money);
|
|
|
|
+ mJunYouBalanceTv.setText(StringUtils.getMoney(balance));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onError(Call call, Exception e) {
|
|
|
|
+ DialogHelper.dismissProgressDialog();
|
|
|
|
+ ToastUtil.showToast(getApplicationContext(),e.getMessage());
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private void getDataAsyn() {
|
|
|
|
+ Map<String, String> params = new HashMap<>();
|
|
|
|
+ params.put("access_token", coreManager.getSelfStatus().accessToken);
|
|
|
|
+ String url = coreManager.getConfig().GET_GIFT_BALANCE_CONFIG;
|
|
|
|
+ DialogHelper.showDefaulteMessageProgressDialog(this);
|
|
|
|
+ HttpUtils.post().url(url)
|
|
|
|
+ .params(params)
|
|
|
|
+ .build()
|
|
|
|
+ .execute(new BaseCallback<GiftBalanceConfigBean>(GiftBalanceConfigBean.class) {
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onResponse(ObjectResult<GiftBalanceConfigBean> result) {
|
|
|
|
+ DialogHelper.dismissProgressDialog();
|
|
|
|
+ if (result != null && result.getData() != null) {
|
|
|
|
+ updateUI(result.getData());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onError(Call call, Exception e) {
|
|
|
|
+ DialogHelper.dismissProgressDialog();
|
|
|
|
+ ToastUtil.showToast(getApplicationContext(), e.getMessage());
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
|
|
}
|
|
}
|
|
- private void setItemView(View itemView,boolean isSelected){
|
|
|
|
- if (itemView!=null){
|
|
|
|
- View bgView = itemView.findViewById(R.id.ll_jun_you);
|
|
|
|
- bgView.setBackgroundResource(isSelected?R.mipmap.img_bg_green_radius_15:R.mipmap.img_bg_frame_white_radius_15);
|
|
|
|
- mRechargeAdapter.notifyDataSetChanged();
|
|
|
|
|
|
|
|
|
|
+ private GiftBalanceConfigBean mGiftBalanceConfigBean;
|
|
|
|
+ private void updateUI(GiftBalanceConfigBean giftBalanceConfigBean) {
|
|
|
|
+ mGiftBalanceConfigBean = giftBalanceConfigBean;
|
|
|
|
+ if (giftBalanceConfigBean != null) {
|
|
|
|
+ String balance = StringUtils.getMoney(giftBalanceConfigBean.getGiftBalance());
|
|
|
|
+ mJunYouBalanceTv.setText(balance);
|
|
|
|
+ int length = sRechargeMoneyArray.length;
|
|
|
|
+ int position = 0;
|
|
|
|
+
|
|
|
|
+ String money;
|
|
|
|
+ int coin;
|
|
|
|
+ List<RechargeCoinBean> list = new ArrayList<>();
|
|
|
|
+ while (position < length) {
|
|
|
|
+ RechargeCoinBean bean = new RechargeCoinBean();
|
|
|
|
+ money = StringUtils.getMoney(sRechargeMoneyArray[position]);
|
|
|
|
+ bean.setRechargeMoney(money);
|
|
|
|
+ bean.setBuyRatio(giftBalanceConfigBean.getBuyRatio());
|
|
|
|
+ coin = (int) (sRechargeMoneyArray[position] * giftBalanceConfigBean.getBuyRatio());
|
|
|
|
+ bean.setJunYouCoin(coin);
|
|
|
|
+ list.add(bean);
|
|
|
|
+ position++;
|
|
|
|
+ }
|
|
|
|
+ mRechargeAdapter.setNewData(list);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
@@ -69,44 +171,39 @@ public class JunYouCoinRechargeActivity extends BaseActivity {
|
|
private void initActionBar() {
|
|
private void initActionBar() {
|
|
getSupportActionBar().hide();
|
|
getSupportActionBar().hide();
|
|
findViewById(R.id.iv_title_left).setOnClickListener(v -> finish());
|
|
findViewById(R.id.iv_title_left).setOnClickListener(v -> finish());
|
|
- TextView tvTitle = (TextView) findViewById(R.id.tv_title_center);
|
|
|
|
|
|
+ TextView tvTitle = findViewById(R.id.tv_title_center);
|
|
tvTitle.setText("购买");
|
|
tvTitle.setText("购买");
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- private void test() {
|
|
|
|
- List<Object> list = new ArrayList<>();
|
|
|
|
- for (int index = 0; index < 10; index++) {
|
|
|
|
- list.add(new Object());
|
|
|
|
- }
|
|
|
|
- mRechargeAdapter.setNewData(list);
|
|
|
|
- }
|
|
|
|
|
|
|
|
- private static final class RechargeAdapter extends BaseQuickAdapter<Object, BaseViewHolder> {
|
|
|
|
|
|
+
|
|
|
|
+ private static final class RechargeAdapter extends BaseQuickAdapter<RechargeCoinBean, BaseViewHolder> {
|
|
|
|
|
|
public RechargeAdapter() {
|
|
public RechargeAdapter() {
|
|
super(R.layout.adapter_jun_you_coin_recharge);
|
|
super(R.layout.adapter_jun_you_coin_recharge);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- protected void convert(BaseViewHolder helper, Object item) {
|
|
|
|
|
|
+ protected void convert(BaseViewHolder helper, RechargeCoinBean item) {
|
|
int currentPosition = helper.getAdapterPosition();
|
|
int currentPosition = helper.getAdapterPosition();
|
|
- LinearLayout linearLayout = getHeaderLayout();
|
|
|
|
- if (linearLayout!=null){
|
|
|
|
- currentPosition--;
|
|
|
|
- }
|
|
|
|
- LinearLayout llJunYou = helper.itemView.findViewById(R.id.ll_jun_you);
|
|
|
|
|
|
+ LinearLayout linearLayout = getHeaderLayout();
|
|
|
|
+ if (linearLayout != null) {
|
|
|
|
+ currentPosition--;
|
|
|
|
+ }
|
|
|
|
+ LinearLayout llJunYou = helper.itemView.findViewById(R.id.ll_jun_you);
|
|
ImageView ivCoin = helper.itemView.findViewById(R.id.iv_coin);
|
|
ImageView ivCoin = helper.itemView.findViewById(R.id.iv_coin);
|
|
- if (currentPosition== mSelectedPosition){
|
|
|
|
|
|
+ if (currentPosition == mSelectedPosition) {
|
|
llJunYou.setBackgroundResource(R.mipmap.img_bg_green_radius_15);
|
|
llJunYou.setBackgroundResource(R.mipmap.img_bg_green_radius_15);
|
|
ivCoin.setImageResource(R.mipmap.me_jyb_gm_jb_sel);
|
|
ivCoin.setImageResource(R.mipmap.me_jyb_gm_jb_sel);
|
|
- }else {
|
|
|
|
|
|
+ } else {
|
|
llJunYou.setBackgroundResource(R.mipmap.img_bg_frame_white_radius_15);
|
|
llJunYou.setBackgroundResource(R.mipmap.img_bg_frame_white_radius_15);
|
|
ivCoin.setImageResource(R.mipmap.me_jyb_gm_jb_no);
|
|
ivCoin.setImageResource(R.mipmap.me_jyb_gm_jb_no);
|
|
}
|
|
}
|
|
- String rechargeRMB = StringUtils.getMoney(10.0) + "(元)";
|
|
|
|
|
|
+ String rechargeRMB = item.getRechargeMoney() + "(元)";
|
|
helper.setText(R.id.tv_recharge_rmb, rechargeRMB);
|
|
helper.setText(R.id.tv_recharge_rmb, rechargeRMB);
|
|
- helper.setText(R.id.tv_jun_you_coin, "420俊友币");
|
|
|
|
|
|
+ helper.addOnClickListener(R.id.tv_buy_coin);
|
|
|
|
+ helper.setText(R.id.tv_jun_you_coin, item.getJunYouCoin() + "俊友币");
|
|
}
|
|
}
|
|
|
|
|
|
private int mSelectedPosition = -1;
|
|
private int mSelectedPosition = -1;
|