diff --git a/app/src/main/java/com/gamedog/vididin/features/withdraw/WithDrawActivity.kt b/app/src/main/java/com/gamedog/vididin/features/withdraw/WithDrawActivity.kt index da6981e..56338d5 100644 --- a/app/src/main/java/com/gamedog/vididin/features/withdraw/WithDrawActivity.kt +++ b/app/src/main/java/com/gamedog/vididin/features/withdraw/WithDrawActivity.kt @@ -42,20 +42,28 @@ import com.viddin.videos.free.databinding.ActivityWithdrawBinding as ViewBinding +/** + * 提现主页面 Activity + * 负责展示可提现金额列表、处理提现逻辑、显示提现结果弹窗及新手引导 + */ @AndroidEntryPoint class WithDrawActivity : AppViewsEmptyViewModelActivity() { + // 存储提现选项视图的列表 private val mItemViewList: MutableList = mutableListOf() override fun inflateViewBinding(inflater: LayoutInflater) = ViewBinding.inflate(inflater) override fun ViewBinding.initWindowInsets() { + // 设置沉浸式状态栏 setImmerseRootView(contentRoot) } override fun ViewBinding.initViews() { + // 设置标题栏文字 titlebar.setTitleText(R.string.sacar) + // 初始化提现选项列表 mItemViewList.add(withdraw01) mItemViewList.add(withdraw1) mItemViewList.add(withdraw10) @@ -64,6 +72,7 @@ class WithDrawActivity : AppViewsEmptyViewModelActivity() { mItemViewList.add(withdraw100) mItemViewList.add(withdraw300) + // 为每个提现选项设置金额和点击回调 withdraw01.setNumAndAction(0, 0.1, { itemIndex-> handleGotoWithdraw(itemIndex) @@ -99,60 +108,84 @@ class WithDrawActivity : AppViewsEmptyViewModelActivity() { handleGotoWithdraw(itemIndex) }) + // 设置提现方式(如 PIX)的图标和点击事件 withdrawPix2.setIconAndText(R.mipmap.pix2_big, R.string.pix2, { + // 点击显示绑定银行卡对话框 WithdrawBindBankDialog(this@WithDrawActivity, null).setWithDrawCashNum(0.0).show() }) withdrawPix2.setSelectedState(true) + // 设置点击事件监听 setOnClickBatch(withdrawRecord) { when(this) { withdrawRecord -> { + // 跳转到提现记录页面 Router.WithdrawRecord.startActivity(this@WithDrawActivity) } } } + // 更新总金额 UI updateUICashTotal() + // 判断 0.1 元新人提现是否已完成,若完成则隐藏该选项 // TaskManager.instance().newbieFirstWithdrawStatus().getStatusBean().hasWithdrawed if (WithdrawManager.instance().getItemState(0, 0) == STATE_WITHDRAW_SUCCESS || TaskManager.instance().newbieFirstWithdrawStatus().smallCashHasWithdrawed()) { withdraw01.isVisible = false } + // 上报提现页面展示事件 StatisticUtil.reportEvents(StatisticUtil.KEY_Withdrawal_Show) } + /** + * 处理提现点击逻辑 + * @param itemIndex 提现选项的索引 + */ private fun handleGotoWithdraw(itemIndex: Int) { val cashNum = mItemViewList.get(itemIndex).getCashNum() if (cashNum >= 1.0) { + // 金额大于等于 1.0,标记开始提现并进入二级提现页面 WithdrawManager.instance().setItemStarted(itemIndex) gotoWithdrawSubActivity(itemIndex) } else { + // 小额提现(0.1元)逻辑 val hasBindBank = AccountManager.hasValidBankInfo() if (!hasBindBank) { + // 未绑定银行卡,显示绑定弹窗 WithdrawBindBankDialog(this@WithDrawActivity, ::startRealWithdraw ).setWithDrawCashNum(cashNum).show() } else { if (WithdrawManager.instance().getItemState(0, 0) == STATE_COULD_WITHDRAW) { + // 已满足提现条件,显示信息确认弹窗 WithdrawInfoConfirmDialog(this@WithDrawActivity, ::startRealWithdraw).setWithDrawCashNum(cashNum).show() } else { + // 不满足条件(通常是需要看广告),显示看广告提现弹窗 WithdrawWatchAdDialog(this@WithDrawActivity, cashNum, ::startRealWithdraw).show() } } } + // 上报点击提现选项事件 StatisticUtil.reportEvents(StatisticUtil.KEY_Withdrawal_finsh, mapOf("Withdrawal_Position" to cashNum)) } + /** + * 发起真实的提现请求 + * @param cashNum 提现金额 + */ private fun startRealWithdraw(cashNum: Double) { // payCashNum: Double, payItemId: Int, paySubItemId: Int, payItemLoopIndex: Int WithdrawManager.instance().startWithdrawReal(cashNum, 0, 0, 1) WithdrawManager.instance().setItemStarted(0) } + /** + * 更新 UI 上的总现金数和已提现成功总额 + */ private fun updateUICashTotal() { binding.tvCashTotal.text = String.format("%.2f", AccountManager.getCash()) binding.tvAllCashHasWithdrawed.text = buildString { @@ -162,11 +195,15 @@ class WithDrawActivity : AppViewsEmptyViewModelActivity() { } } + /** + * 更新提现列表项的 UI 状态(进度、按钮等) + */ private fun updateItemListUI() { mItemViewList.forEach { it.updateProgressAndButUI() } + // 检查是否需要隐藏 0.1 元提现选项 if (WithdrawManager.instance().getItemState(0, 0) == STATE_WITHDRAW_SUCCESS || TaskManager.instance().newbieFirstWithdrawStatus().smallCashHasWithdrawed()) { binding.withdraw01.isVisible = false @@ -175,22 +212,27 @@ class WithDrawActivity : AppViewsEmptyViewModelActivity() { override fun ViewBinding.initListeners() { + // 注册事件总线监听 registerEvents({ data-> when (data?.mEventType) { VididinEvents.Event_Account_Cash_Changed -> { + // 现金余额发生变化 updateUICashTotal() } VididinEvents.EVENT_AD_WATCHED_FOR_WITHDRAW_SMALL -> { + // 小额提现看广告奖励 val adNotifyBean = data.mData as WatchAdNotifyBean WithdrawManager.instance().addAdEarnForSubBean(0, 0, adNotifyBean.earnMoneyNum * VidiConst.WITHDRAW_REWARD_AD_REVENUE_PERCENT) } VididinEvents.EVENT_WITHDRAW_RESULT_UPDATED -> { + // 提现结果更新 try { val record = data.mData as RecordCash if (record.withdrawItemIndex == 0) { + // 如果是当前小额提现的结果,显示结果弹窗 showTransactionResultDialog(record) } updateUICashTotal() @@ -201,18 +243,22 @@ class WithDrawActivity : AppViewsEmptyViewModelActivity() { } VididinEvents.EVENT_WITHDRAW_ITEM_LIST_CHANGED -> { + // 提现列表整体发生变化 updateItemListUI() } VididinEvents.EVENT_BANK_INFO_CHANGED -> { + // 银行卡绑定信息变化 withdrawPix2.updateBankAccountInfo() } VididinEvents.EVENT_WITHDRAW_SUB_ITEM_PROGRESS_UPDATED -> { + // 二级提现项进度更新 updateItemListUI() } VididinEvents.EVENT_WITHDRAW_SMALL_AD_FINISHED -> { + // 小额提现相关广告观看完成 handleGotoWithdraw(0) } } @@ -225,8 +271,10 @@ class WithDrawActivity : AppViewsEmptyViewModelActivity() { VididinEvents.EVENT_WITHDRAW_SUB_ITEM_PROGRESS_UPDATED, VididinEvents.EVENT_WITHDRAW_SMALL_AD_FINISHED) + // 读取本地提现记录并展示未通知的结果 readTransactionsAndShowResult() + // 检查并展示新手引导 if (needShowGuide()) { binding.tvCashTotal.postDelayed({ showGuide() @@ -239,22 +287,34 @@ class WithDrawActivity : AppViewsEmptyViewModelActivity() { //TODO("Not yet implemented") } + /** + * 显示提现成功弹窗 + */ private fun showSuccessDialog(cashNum: Double) { WithdrawSuccessDialog(this@WithDrawActivity, cashNum).show() } + /** + * 显示提现失败弹窗 + */ private fun showFailDialog(failHintRes: Int) { WithdrawFailDialog(this@WithDrawActivity, failHintRes).show() } + /** + * 跳转到提现二级详情页面 + */ private fun gotoWithdrawSubActivity(selectedIndex: Int) { Router.WithdrawSub.startActivity(this, selectedIndex) } - // ------------------------ new added -------------------------// + // ------------------------ 新增处理逻辑 -------------------------// + /** + * 读取并处理本地提现记录 + */ private fun readTransactionsAndShowResult() { val recordList = WithdrawManager.instance().getClonedRecordList() recordList.forEach { @@ -262,7 +322,11 @@ class WithDrawActivity : AppViewsEmptyViewModelActivity() { } } + /** + * 根据提现记录状态显示对应的结果弹窗 + */ private fun showTransactionResultDialog(record: RecordCash) { + // 如果未展示过结果弹窗且提现状态不是“进行中”,则展示结果 if (!record.hasShowResultDialog && record.withdrawState != TRANSACTION_STATE_ONGOING) { WithdrawManager.instance().updateRecordHasNotifyState(record.uuid) when (record.withdrawState) { @@ -277,10 +341,16 @@ class WithDrawActivity : AppViewsEmptyViewModelActivity() { } } + /** + * 判断是否需要显示引导 + */ private fun needShowGuide(): Boolean { return GuideManager.instance().getCurGuideIndex() == VidiConst.GUIDE_INDEX_CASH_GOLD } + /** + * 保存引导状态,标记当前步骤已完成 + */ private fun saveGuideState() { GuideManager.instance().setGuideIndex(VidiConst.GUIDE_INDEX_WITHDRAW) } @@ -289,6 +359,9 @@ class WithDrawActivity : AppViewsEmptyViewModelActivity() { super.onDestroy() } + /** + * 执行新手引导展示 + */ private fun showGuide() { HighlightPro.with(this@WithDrawActivity) .setHighlightParameter { @@ -307,18 +380,23 @@ class WithDrawActivity : AppViewsEmptyViewModelActivity() { } .setOnDismissCallback { + // 引导消失后保存状态并触发点击 0.1 元提现 saveGuideState() handleGotoWithdraw(0) } .interceptBackPressed(true) .show() + // 上报引导埋点 StatisticUtil.reportEvents(StatisticUtil.KEY_Guide, mapOf("Guide" to 3)) } companion object { + /** + * 启动 WithDrawActivity + */ internal fun startActivity(activity: Activity) { activity.startActivity(Intent(activity.applicationContext, WithDrawActivity::class.java)) } diff --git a/app/src/main/java/com/gamedog/vididin/features/zero/ZeroBuyViewModel.kt b/app/src/main/java/com/gamedog/vididin/features/zero/ZeroBuyViewModel.kt index db73e5f..3467cd8 100644 --- a/app/src/main/java/com/gamedog/vididin/features/zero/ZeroBuyViewModel.kt +++ b/app/src/main/java/com/gamedog/vididin/features/zero/ZeroBuyViewModel.kt @@ -39,13 +39,13 @@ class ZeroBuyViewModel : ViewModel() { val curTimeSec = System.currentTimeMillis()/1000 val signStr = RequestUtil.getZeroBuyRequestSign(curTimeSec, operationVal) val requestHeaders = mapOf("Operation" to operationVal.toString(), "Timestamp" to curTimeSec.toString(), "Sign" to signStr) - val requestParams: MutableMap = mutableMapOf("AppId" to AndroidUtil.getPackageId(), "DeviceId" to DeviceUtil.generateDeviceId()) + val requestParams: MutableMap = mutableMapOf("app_id" to AndroidUtil.getPackageId(), "device_id" to DeviceUtil.generateDeviceId()) val userId = AccountManager.getAccount()?.userId?: 0 if (userId > 0) { - requestParams.put("UserId", userId.toString()) + requestParams.put("user_id", userId.toString()) } val joinZeroBuyItemIds = SpUtil.instance().getList(SpUtil.KEY_ZEROBUY_JOINED_ACTIVITY_IDS) - requestParams.put("ActivityId", itemId.toString()) + requestParams.put("activity_id", itemId.toString()) val result = NetworkUtil.post("${VidiConst.URL_ZERO_BUY}/any", requestHeaders, requestParams, joinZeroBuyItemIds) @@ -88,10 +88,10 @@ class ZeroBuyViewModel : ViewModel() { val curTimeSec = System.currentTimeMillis()/1000 val signStr = RequestUtil.getZeroBuyRequestSign(curTimeSec, operationVal) val requestHeaders = mapOf("Operation" to operationVal.toString(), "Timestamp" to curTimeSec.toString(), "Sign" to signStr) - val requestParams: MutableMap = mutableMapOf("AppId" to AndroidUtil.getPackageId(), "DeviceId" to DeviceUtil.generateDeviceId()) + val requestParams: MutableMap = mutableMapOf("app_id" to AndroidUtil.getPackageId(), "device_id" to DeviceUtil.generateDeviceId()) val userId = AccountManager.getAccount()?.userId?: 0 if (userId > 0) { - requestParams.put("UserId", userId.toString()) + requestParams.put("user_id", userId.toString()) } val joinZeroBuyItemIds = SpUtil.instance().getList(SpUtil.KEY_ZEROBUY_JOINED_ACTIVITY_IDS) val result = NetworkUtil.post("${VidiConst.URL_ZERO_BUY}/any", requestHeaders, requestParams, joinZeroBuyItemIds) diff --git a/app/src/main/java/com/gamedog/vididin/manager/ZeroManager.kt b/app/src/main/java/com/gamedog/vididin/manager/ZeroManager.kt index 5a44359..bace556 100644 --- a/app/src/main/java/com/gamedog/vididin/manager/ZeroManager.kt +++ b/app/src/main/java/com/gamedog/vididin/manager/ZeroManager.kt @@ -153,25 +153,25 @@ class ZeroManager private constructor() { val requestHeaders = mapOf("Operation" to operationVal.toString(), "Timestamp" to curTimeSec.toString(), "Sign" to signStr) // body param - val requestParams: MutableMap = mutableMapOf("AppId" to AndroidUtil.getPackageId(), "DeviceId" to DeviceUtil.generateDeviceId()) + val requestParams: MutableMap = mutableMapOf("app_id" to AndroidUtil.getPackageId(), "device_id" to DeviceUtil.generateDeviceId()) val userId = AccountManager.getAccount().userId if (userId > 0) { - requestParams.put("UserId", userId.toString()) + requestParams.put("user_id", userId.toString()) } val joinZeroBuyItemIds = SpUtil.instance().getList(SpUtil.KEY_ZEROBUY_JOINED_ACTIVITY_IDS) - requestParams.put("ActivityId", zeroWithdrawItem.purchase_id.toString()) + requestParams.put("activity_id", zeroWithdrawItem.purchase_id.toString()) // withdraw 相关参数: val bankCPFAccount = AccountManager.getAccount().bankInfo?.bankAccount!! val accountType = "CPF" - requestParams.put("Account", bankCPFAccount) - requestParams.put("AccountType", accountType) - requestParams.put("Country", Country.BR.name) - requestParams.put("DocumentType", accountType) - requestParams.put("DocumentId", bankCPFAccount) - requestParams.put("BankCode", AccountManager.getAccount().bankInfo?.bankAccount!!) + requestParams.put("account", bankCPFAccount) + requestParams.put("account_type", accountType) + requestParams.put("country", Country.BR.name) + requestParams.put("document_type", accountType) + requestParams.put("document_id", bankCPFAccount) + requestParams.put("bank_code", AccountManager.getAccount().bankInfo?.bankAccount!!) val signOriginStr = "${zeroWithdrawItem.purchase_id}-${userId}-${bankCPFAccount}-${accountType}-${bankCPFAccount}-${accountType}-${ZEROBUY_SECRET}" - requestParams.put("Sign", MD5Util.md5(signOriginStr)!!) + requestParams.put("sign", MD5Util.md5(signOriginStr)!!) val result = NetworkUtil.post("${VidiConst.URL_ZERO_BUY}/any", requestHeaders, requestParams, joinZeroBuyItemIds) @@ -215,19 +215,16 @@ class ZeroManager private constructor() { val requestHeaders = mapOf("Operation" to operationVal.toString(), "Timestamp" to curTimeSec.toString(), "Sign" to signStr) // body param - val requestParams: MutableMap = mutableMapOf("AppId" to AndroidUtil.getPackageId()) + val requestParams: MutableMap = mutableMapOf("app_id" to AndroidUtil.getPackageId()) val userId = AccountManager.getAccount().userId if (userId > 0) { - requestParams.put("UserId", userId.toString()) + requestParams.put("user_id", userId.toString()) } - requestParams.put("ActivityId", zeroWithdrawItem.purchase_id.toString()) + requestParams.put("activity_id", zeroWithdrawItem.purchase_id.toString()) // withdraw check result 相关参数: - requestParams.put("device_id", zeroWithdrawItem.orderId) requestParams.put("order_id", zeroWithdrawItem.orderId) - requestParams.put("record_id", zeroWithdrawItem.orderId) - requestParams.put("recordId", zeroWithdrawItem.orderId) val result = NetworkUtil.post("${VidiConst.URL_ZERO_BUY}/any", requestHeaders, requestParams)