修改名称。
This commit is contained in:
@@ -0,0 +1,267 @@
|
||||
package com.xscm.moduleutil.dialog;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.blankj.utilcode.util.ToastUtils;
|
||||
import com.xscm.moduleutil.R;
|
||||
import com.xscm.moduleutil.adapter.BalanceRechargeAdapter;
|
||||
import com.xscm.moduleutil.adapter.PayMethodAdapter;
|
||||
import com.xscm.moduleutil.base.BaseMvpDialogFragment;
|
||||
import com.xscm.moduleutil.base.CommonAppContext;
|
||||
import com.xscm.moduleutil.bean.AppPay;
|
||||
import com.xscm.moduleutil.bean.BindType;
|
||||
import com.xscm.moduleutil.bean.RechargeBean;
|
||||
import com.xscm.moduleutil.databinding.FragmentRechargeDialogBinding;
|
||||
import com.xscm.moduleutil.presenter.RechargeDialogContacts;
|
||||
import com.xscm.moduleutil.presenter.RechargeDialogPresenter;
|
||||
import com.xscm.moduleutil.utils.SpUtil;
|
||||
import com.xscm.moduleutil.widget.PaymentUtil;
|
||||
import com.tencent.mm.opensdk.openapi.IWXAPI;
|
||||
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/**
|
||||
*@author qx
|
||||
*@data 2025/6/12
|
||||
*@description: 充值弹框
|
||||
*/
|
||||
public class RechargeDialogFragment extends BaseMvpDialogFragment<RechargeDialogPresenter, FragmentRechargeDialogBinding> implements RechargeDialogContacts.View {
|
||||
private BalanceRechargeAdapter rechargeAdapter;
|
||||
private String money = "0";
|
||||
private String type ;
|
||||
private String coin;
|
||||
private BindType.AllData selectedItem;
|
||||
private PayMethodAdapter bindTypeAdapter;
|
||||
private String roomId;
|
||||
private String gift_bag_id="0";//默认0 类型id 传 gift_bag_id
|
||||
private String type_params="0"; //默认0 类型参数 1首充 2天降好礼 3新人好礼
|
||||
|
||||
public static RechargeDialogFragment show(String id, String type, FragmentManager fragmentManager,String gift_bag_id,String type_params) {
|
||||
RechargeDialogFragment dialogFragment = new RechargeDialogFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putString("roomId", id); //// 可选:传递参数
|
||||
args.putString("type", type);
|
||||
args.putString("gift_bag_id", gift_bag_id);
|
||||
args.putString("type_params", type_params);
|
||||
dialogFragment.setArguments(args);
|
||||
dialogFragment.show(fragmentManager, "RoomOnlineDialogFragment");
|
||||
return dialogFragment;
|
||||
}
|
||||
@Override
|
||||
protected void initDialogStyle(Window window) {
|
||||
super.initDialogStyle(window);
|
||||
window.setGravity(Gravity.BOTTOM);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(@NonNull Context context) {
|
||||
super.onAttach(context);
|
||||
roomId = getArguments().getString("roomId");
|
||||
type = getArguments().getString("type");
|
||||
gift_bag_id = getArguments().getString("gift_bag_id");
|
||||
type_params = getArguments().getString("type_params");
|
||||
if(type!=null){
|
||||
money=type;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RechargeDialogPresenter bindPresenter() {
|
||||
return new RechargeDialogPresenter(this, getContext());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void initData() {
|
||||
if (roomId!=null) {
|
||||
MvpPre.recharge();
|
||||
}
|
||||
MvpPre.bindType(SpUtil.getUserId() + "");
|
||||
|
||||
}
|
||||
private void onClick(View view) {
|
||||
if (view.getId() == R.id.tv_payment) {
|
||||
if (money.equals("0")) {
|
||||
money=mBinding.etCustomAmount.getText().toString().trim();
|
||||
if (TextUtils.isEmpty(money)) {
|
||||
ToastUtils.showShort("请选择充值金额");
|
||||
return;
|
||||
}
|
||||
}
|
||||
// if (Double.valueOf(money) < 6) {
|
||||
// ToastUtils.showShort("最低充值6元以上");
|
||||
// return;
|
||||
// }
|
||||
|
||||
if (selectedItem == null) {
|
||||
ToastUtils.showShort("请选择支付方式");
|
||||
return;
|
||||
}
|
||||
MvpPre.appPay(SpUtil.getUserId() + "", money, coin, selectedItem.getType(),type_params,gift_bag_id);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected void initView() {
|
||||
mBinding.tvPayment.setOnClickListener(this::onClick);
|
||||
mBinding.recycleView1.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
|
||||
bindTypeAdapter = new PayMethodAdapter(R.layout.item_bind_type);
|
||||
mBinding.recycleView1.setAdapter(bindTypeAdapter);
|
||||
|
||||
bindTypeAdapter.setOnItemClickListener((adapter, view, position) -> {
|
||||
// 更新选中项
|
||||
bindTypeAdapter.setSelectedPosition(position);
|
||||
|
||||
// 获取当前选中的数据
|
||||
selectedItem = bindTypeAdapter.getItem(position);
|
||||
// 可以在这里处理选中逻辑,比如保存到变量或触发支付
|
||||
});
|
||||
|
||||
if (type!=null){
|
||||
mBinding.r4.setVisibility(View.GONE);
|
||||
}else{
|
||||
mBinding.r4.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.fragment_recharge_dialog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRechargeData(List<RechargeBean> rechargeData) {
|
||||
// RechargeBean customItem = new RechargeBean();
|
||||
// customItem.setCoins("自定义");
|
||||
// customItem.setMoney("");
|
||||
// customItem.setItemViewType(1);
|
||||
// rechargeData.add(customItem);
|
||||
rechargeAdapter = new BalanceRechargeAdapter(rechargeData);
|
||||
rechargeAdapter.setNewData(rechargeData);
|
||||
rechargeAdapter.setListener(new BalanceRechargeAdapter.OnRechargeItemClickListener() {
|
||||
@Override
|
||||
public void onClick(RechargeBean rechargeBean) {
|
||||
money = rechargeBean.getMoney();
|
||||
// mBinding.tvPayment.setText(String.format("立即支付(%s元)", money));
|
||||
}
|
||||
});
|
||||
rechargeAdapter.setInputBoxVisibilityListener(new BalanceRechargeAdapter.InputBoxVisibilityListener() {
|
||||
@Override
|
||||
public void onInputBoxVisibilityChanged(boolean isVisible) {
|
||||
// 根据 isVisible 的值来显示或隐藏输入框
|
||||
mBinding.r4.setVisibility(isVisible ? View.VISIBLE : View.GONE);
|
||||
if (isVisible){
|
||||
money="0";
|
||||
}
|
||||
}
|
||||
});
|
||||
mBinding.rvComment.setLayoutManager(new GridLayoutManager(getContext(), 3));
|
||||
mBinding.rvComment.setAdapter(rechargeAdapter);
|
||||
mBinding.tvPayment.setText("立即支付");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void bindType(BindType bindType) {
|
||||
List<BindType.AllData> allData = new ArrayList<>();
|
||||
if (bindType.getAli().getIs_pay_open().equals("1")) {
|
||||
allData.add(bindType.getAli());
|
||||
}
|
||||
if (bindType.getWx().getIs_pay_open().equals("1")) {
|
||||
allData.add(bindType.getWx());
|
||||
}
|
||||
if (bindType.getBank().getIs_pay_open().equals("1")) {
|
||||
allData.add(bindType.getBank());
|
||||
}
|
||||
if (bindType.getAli_tl().getIs_pay_open().equals("1")) {
|
||||
allData.add(bindType.getAli_tl());
|
||||
}
|
||||
if (bindType.getWx_tl().getIs_pay_open().equals("1")) {
|
||||
allData.add(bindType.getWx_tl());
|
||||
}
|
||||
|
||||
bindTypeAdapter.setNewData(allData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appPay(AppPay appPay) {
|
||||
if (appPay.getAli()!=null) {
|
||||
PaymentUtil.payAlipay(getContext(), appPay.getAli());
|
||||
}else if (appPay.getWx()!=null){
|
||||
|
||||
IWXAPI wxapi = WXAPIFactory.createWXAPI(getContext(), CommonAppContext.getInstance().getCurrentEnvironment().getWxAppId());
|
||||
PaymentUtil.payWxMiniProgram2(wxapi,appPay);
|
||||
|
||||
}else if (appPay.getTl()!=null){
|
||||
if (appPay.getTl().getRemark().equals("5")) {//微信
|
||||
IWXAPI wxapi = WXAPIFactory.createWXAPI(getContext(), CommonAppContext.getInstance().getCurrentEnvironment().getWxAppId());
|
||||
try {
|
||||
String paramString = buildParamString(appPay.getTl());
|
||||
PaymentUtil.payWxMiniProgramWx(wxapi,paramString);
|
||||
android.util.Log.d("RequestParams", paramString); // 输出拼接后的参数
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else if (appPay.getTl().getRemark().equals("4")) {//支付宝
|
||||
String s= JSON.toJSONString(appPay.getTl());
|
||||
try {
|
||||
String query = URLEncoder.encode("payinfo=" + URLEncoder.encode(s, "UTF-8"), "UTF-8");
|
||||
String url = "alipays://platformapi/startapp?appId=2021001104615521&page=pages/orderDetail/orderDetail&thirdPartSchema="
|
||||
+ URLEncoder.encode("myziroom://myziroom/", "UTF-8") + "&query=" + query;
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
||||
startActivity(intent);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public static String buildParamString(Object obj) throws IllegalAccessException {
|
||||
Class<?> clazz = obj.getClass();
|
||||
Field[] fields = clazz.getDeclaredFields();
|
||||
TreeMap<String, String> paramMap = new TreeMap<>();
|
||||
|
||||
// 遍历字段并填充 TreeMap
|
||||
for (Field field : fields) {
|
||||
field.setAccessible(true); // 允许访问私有字段
|
||||
Object value = field.get(obj);
|
||||
if (value != null && !String.valueOf(value).isEmpty()) {
|
||||
paramMap.put(field.getName(), String.valueOf(value));
|
||||
}
|
||||
}
|
||||
|
||||
// 使用 StringBuilder 拼接参数字符串
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (Map.Entry<String, String> entry : paramMap.entrySet()) {
|
||||
if (builder.length() > 0) {
|
||||
builder.append("&");
|
||||
}
|
||||
builder.append(entry.getKey())
|
||||
.append("=")
|
||||
.append(entry.getValue());
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user