332 lines
11 KiB
Java
332 lines
11 KiB
Java
package com.example.modulevocal.activity;
|
|
|
|
import android.content.Intent;
|
|
import android.graphics.Color;
|
|
import android.os.CountDownTimer;
|
|
import android.text.Editable;
|
|
import android.text.InputFilter;
|
|
import android.text.TextUtils;
|
|
import android.text.TextWatcher;
|
|
import android.text.method.DigitsKeyListener;
|
|
import android.view.View;
|
|
import android.widget.EditText;
|
|
import android.widget.ImageView;
|
|
import android.widget.TextView;
|
|
|
|
import androidx.appcompat.app.AlertDialog;
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
|
import com.alibaba.android.arouter.facade.annotation.Route;
|
|
import com.alibaba.android.arouter.launcher.ARouter;
|
|
import com.example.modulevocal.R;
|
|
import com.qxcm.moduleutil.adapter.PayMethodAdapter;
|
|
import com.example.modulevocal.conacts.WithdrawalConacts;
|
|
import com.example.modulevocal.databinding.ActivityWithdrawalBinding;
|
|
import com.example.modulevocal.presenter.WithdrawalPresenter;
|
|
import com.google.android.material.textfield.TextInputEditText;
|
|
import com.hjq.toast.ToastUtils;
|
|
import com.qxcm.moduleutil.activity.BaseMvpActivity;
|
|
import com.qxcm.moduleutil.base.CommonAppContext;
|
|
import com.qxcm.moduleutil.bean.BindType;
|
|
import com.qxcm.moduleutil.bean.WalletBean;
|
|
import com.qxcm.moduleutil.bean.WalletConfig;
|
|
import com.qxcm.moduleutil.bean.WithdrawalBean;
|
|
import com.qxcm.moduleutil.utils.ARouteConstants;
|
|
import com.qxcm.moduleutil.utils.SpUtil;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* @author qx
|
|
* @data 2025/5/21
|
|
* @description: 提现
|
|
*/
|
|
|
|
@Route(path = ARouteConstants.WITHDRAWAL_ACTIVITY)
|
|
public class WithdrawalActivity extends BaseMvpActivity<WithdrawalPresenter, ActivityWithdrawalBinding> implements WithdrawalConacts.View {
|
|
WalletBean walletBean;
|
|
private PayMethodAdapter bindTypeAdapter;
|
|
private BindType.AllData selectedItem;
|
|
|
|
@Override
|
|
protected void initData() {
|
|
mBinding.topBar.setTitle("提现");
|
|
mBinding.topBar.setRightTxtVisible(true);
|
|
mBinding.topBar.setRightText("提现记录");
|
|
mBinding.topBar.setRightColor(Color.parseColor("#FF8ACC"));
|
|
mBinding.topBar.getTvRight().setOnClickListener(v -> {
|
|
startActivity(new Intent(this, WithdrawalListActivity.class));
|
|
});
|
|
|
|
mBinding.recycleView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
|
|
bindTypeAdapter = new PayMethodAdapter(com.qxcm.moduleutil.R.layout.item_bind_type);
|
|
mBinding.recycleView.setAdapter(bindTypeAdapter);
|
|
|
|
bindTypeAdapter.setOnItemClickListener((adapter, view, position) -> {
|
|
// 更新选中项
|
|
bindTypeAdapter.setSelectedPosition(position);
|
|
|
|
// 获取当前选中的数据
|
|
selectedItem = bindTypeAdapter.getItem(position);
|
|
// 可以在这里处理选中逻辑,比如保存到变量或触发支付
|
|
|
|
});
|
|
|
|
mBinding.tvPayment.setOnClickListener(v -> {
|
|
if (!mBinding.cbPrivacy.isChecked()) {
|
|
ToastUtils.show("请先阅读就业协议并同意协议");
|
|
return;
|
|
}
|
|
if (mBinding.etCustomAmount.getText().toString().isEmpty()) {
|
|
ToastUtils.show("请输入提现金额");
|
|
return;
|
|
}
|
|
if (selectedItem == null) {
|
|
ToastUtils.show("请选择提现方式");
|
|
return;
|
|
}
|
|
showSecondaryVerificationDialog();
|
|
});
|
|
|
|
mBinding.t5.setOnClickListener(v -> {
|
|
String earnings = truncateToFirstDecimalPlace(walletBean.getEarnings());
|
|
mBinding.etCustomAmount.setText(earnings);
|
|
});
|
|
|
|
mBinding.tvLhjy.setOnClickListener(v -> {
|
|
ARouter.getInstance().build(ARouteConstants.H5).withString("url",walletBean.getUrl()).withString("title", walletBean.getTitle()).navigation();
|
|
|
|
});
|
|
|
|
TextInputEditText etCustomAmount = mBinding.etCustomAmount;
|
|
|
|
// 限制只能输入数字和小数点后一位
|
|
etCustomAmount.setKeyListener(DigitsKeyListener.getInstance("0123456789."));
|
|
etCustomAmount.setFilters(new InputFilter[]{(source, start, end, dest, dstart, dend) -> {
|
|
// 防止输入负号
|
|
if (source.toString().contains("-")) {
|
|
return "";
|
|
}
|
|
|
|
String newText = dest.toString().substring(0, dstart) + source.toString() + dest.toString().substring(dend);
|
|
|
|
// 检查小数点
|
|
if (newText.contains(".")) {
|
|
String[] splitResult = newText.split("\\.");
|
|
if (splitResult.length > 1 && splitResult[1].length() > 1) {
|
|
// 小数点后只能有一位
|
|
return "";
|
|
}
|
|
}
|
|
|
|
// 可选:限制最大长度
|
|
if (newText.length() > 10) {
|
|
return "";
|
|
}
|
|
|
|
return null;
|
|
}});
|
|
|
|
// 可选:添加 TextWatcher 来监听输入内容变化
|
|
etCustomAmount.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) {
|
|
}
|
|
|
|
@Override
|
|
public void afterTextChanged(Editable s) {
|
|
// 如果以小数点开头,自动补 0
|
|
if (s.toString().startsWith(".")) {
|
|
s.insert(0, "0");
|
|
}
|
|
// 如果以多个 0 开头,只保留一个
|
|
if (s.toString().startsWith("0") && s.toString().length() > 1 && s.toString().charAt(1) != '.') {
|
|
s.delete(0, 1);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
private String truncateToFirstDecimalPlace(String value) {
|
|
if (TextUtils.isEmpty(value)) return "0.0";
|
|
|
|
int dotIndex = value.indexOf('.');
|
|
if (dotIndex == -1) {
|
|
return value + ".0"; // 没有小数点,默认加 .0
|
|
}
|
|
|
|
String integerPart = value.substring(0, dotIndex);
|
|
String decimalPart = value.substring(dotIndex + 1);
|
|
|
|
if (decimalPart.length() >= 1) {
|
|
return integerPart + "." + decimalPart.charAt(0); // 只取小数点后一位
|
|
} else {
|
|
return integerPart + ".0"; // 小数点后为空,默认加 0
|
|
}
|
|
}
|
|
|
|
private void showSecondaryVerificationDialog() {
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
View dialogView = getLayoutInflater().inflate(R.layout.dialog_secondary_verification, null);
|
|
builder.setView(dialogView);
|
|
|
|
final EditText etVerificationCode = dialogView.findViewById(R.id.ed_password);
|
|
final ImageView tvGetCode = dialogView.findViewById(R.id.tv_get_code);
|
|
final TextView tvCancel = dialogView.findViewById(R.id.tv_send_code);
|
|
|
|
final AlertDialog dialog = builder.create();
|
|
dialog.setCancelable(false);
|
|
dialog.show();
|
|
|
|
tvCancel.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
public void onClick(View v) {
|
|
MvpPre.sendCode(SpUtil.getUserBean().getMobile(), 6);
|
|
ToastUtils.show("验证码已发送");
|
|
tvCancel.setEnabled(false);
|
|
startCountDown(tvCancel);
|
|
}
|
|
});
|
|
|
|
tvGetCode.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View v) {
|
|
// 模拟发送验证码逻辑
|
|
dialog.dismiss();
|
|
}
|
|
});
|
|
|
|
// // 验证码输入完成时的处理
|
|
// etVerificationCode.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
|
// @Override
|
|
// public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
|
// String code = etVerificationCode.getText().toString().trim();
|
|
// if (!TextUtils.isEmpty(code)) {
|
|
// // 验证码验证逻辑
|
|
// MvpPre.withdrawal(mBinding.etCustomAmount.getText().toString(), selectedItem.getType(), code);
|
|
// dialog.dismiss();
|
|
// } else {
|
|
//
|
|
// }
|
|
// return true;
|
|
// }
|
|
// });
|
|
|
|
etVerificationCode.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) {
|
|
|
|
}
|
|
|
|
@Override
|
|
public void afterTextChanged(Editable s) {
|
|
if (s.length() == 4) {
|
|
String code = etVerificationCode.getText().toString().trim();
|
|
if (!TextUtils.isEmpty(code)) {
|
|
// 验证码验证逻辑
|
|
MvpPre.withdrawal(mBinding.etCustomAmount.getText().toString(), selectedItem.getType(), code);
|
|
dialog.dismiss();
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
private void startCountDown(final TextView tvGetCode) {
|
|
final int[] count = {60};
|
|
tvGetCode.setText("重新发送(" + count[0] + ")");
|
|
new CountDownTimer(60000, 1000) {
|
|
public void onTick(long millisUntilFinished) {
|
|
tvGetCode.setText("重新发送(" + (count[0]--) + ")");
|
|
}
|
|
|
|
public void onFinish() {
|
|
tvGetCode.setText("获取验证码");
|
|
tvGetCode.setEnabled(true);
|
|
}
|
|
}.start();
|
|
}
|
|
|
|
|
|
@Override
|
|
protected void onResume() {
|
|
super.onResume();
|
|
MvpPre.wallet();
|
|
MvpPre.bindType(SpUtil.getUserId() + "");
|
|
MvpPre.getWalletConfig();
|
|
}
|
|
|
|
@Override
|
|
protected int getLayoutId() {
|
|
return R.layout.activity_withdrawal;
|
|
}
|
|
|
|
@Override
|
|
protected WithdrawalPresenter bindPresenter() {
|
|
return new WithdrawalPresenter(this, this);
|
|
}
|
|
|
|
@Override
|
|
public void wallet(WalletBean walletBean) {
|
|
this.walletBean = walletBean;
|
|
mBinding.tvJb.setText(walletBean.getEarnings());
|
|
if (walletBean.getTitle() != null) {
|
|
mBinding.tvLhjy.setText(walletBean.getTitle());
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void bindType(BindType bindType) {
|
|
List<BindType.AllData> allData = new ArrayList<>();
|
|
if (bindType.getAli().getIs_with_draw_open().equals("1")) {
|
|
allData.add(bindType.getAli());
|
|
}
|
|
if (bindType.getWx().getIs_with_draw_open().equals("1")) {
|
|
allData.add(bindType.getWx());
|
|
}
|
|
if (bindType.getBank().getIs_with_draw_open().equals("1")) {
|
|
allData.add(bindType.getBank());
|
|
}
|
|
if (bindType.getAli_tl().getIs_with_draw_open().equals("1")) {
|
|
allData.add(bindType.getAli_tl());
|
|
}
|
|
if (bindType.getWx_tl().getIs_with_draw_open().equals("1")) {
|
|
allData.add(bindType.getWx_tl());
|
|
}
|
|
|
|
bindTypeAdapter.setNewData(allData);
|
|
}
|
|
|
|
@Override
|
|
public void getWalletConfig(WalletConfig walletConfig) {
|
|
mBinding.t3.setText("提现扣除服务费:" + walletConfig.getWithdrawal_service_fee() + "%");
|
|
}
|
|
|
|
@Override
|
|
public void bind() {
|
|
|
|
}
|
|
|
|
@Override
|
|
public void withdrawal(String S) {
|
|
ToastUtils.show(S);
|
|
MvpPre.wallet();
|
|
}
|
|
|
|
@Override
|
|
public void withdrawalList(List<WithdrawalBean> list) {
|
|
|
|
}
|
|
} |