369 lines
12 KiB
Kotlin
369 lines
12 KiB
Kotlin
package com.xscm.modulemain.dialog
|
|
|
|
import android.annotation.SuppressLint
|
|
import android.content.Context
|
|
import android.os.Bundle
|
|
import android.view.Gravity
|
|
import android.view.View
|
|
import androidx.fragment.app.FragmentManager
|
|
import com.blankj.utilcode.util.ActivityUtils
|
|
import com.blankj.utilcode.util.ToastUtils
|
|
import com.chad.library.adapter.base.BaseQuickAdapter
|
|
import com.chad.library.adapter.base.BaseViewHolder
|
|
import com.opensource.svgaplayer.SVGACallback
|
|
import com.opensource.svgaplayer.SVGAParser
|
|
import com.opensource.svgaplayer.SVGAVideoEntity
|
|
import com.scwang.smartrefresh.layout.api.RefreshLayout
|
|
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener
|
|
import com.xscm.modulemain.R
|
|
import com.xscm.modulemain.databinding.DialogLoveStationDrawLayoutBinding
|
|
import com.xscm.moduleutil.bean.GiftBean
|
|
import com.xscm.moduleutil.bean.WalletBean
|
|
import com.xscm.moduleutil.bean.blindboxwheel.BlindBoxBean
|
|
import com.xscm.moduleutil.bean.blindboxwheel.BlindReslutBean
|
|
import com.xscm.moduleutil.dialog.giftLottery.GiftLotteryDialogFragment
|
|
import com.xscm.moduleutil.dialog.giftLottery.PrizePoolDialog
|
|
import com.xscm.moduleutil.http.BaseObserver
|
|
import com.xscm.moduleutil.http.RetrofitClient
|
|
import com.xscm.moduleutil.utils.ImageUtils
|
|
import com.xscm.moduleutil.widget.dialog.BaseDialog
|
|
import io.reactivex.disposables.Disposable
|
|
|
|
class DialogLoveStationDraw(context: Context,val fragmentManager: FragmentManager) :
|
|
BaseDialog<DialogLoveStationDrawLayoutBinding>(context) {
|
|
|
|
init {
|
|
window?.apply {
|
|
setGravity(Gravity.BOTTOM)
|
|
}
|
|
|
|
setCancelable(false)
|
|
setCanceledOnTouchOutside(false)
|
|
}
|
|
|
|
private var isLottery = false
|
|
|
|
private var mRoomId: String = ""
|
|
private var mGiftBagId: String = ""
|
|
|
|
private var itemAdapter: ItemAdapter? = null
|
|
private var itemRecord: ItemRecordAdapter? = null
|
|
private var httpError = false
|
|
|
|
private var currLottery = 1
|
|
|
|
private var resultList: MutableList<BlindReslutBean.ReslutList> = mutableListOf()
|
|
|
|
override fun getLayoutId(): Int {
|
|
return R.layout.dialog_love_station_draw_layout
|
|
}
|
|
|
|
override fun initView() {
|
|
mBinding.ivClose.setOnClickListener {
|
|
dismiss()
|
|
}
|
|
|
|
mBinding.iv1.setOnClickListener {
|
|
lottery(1)
|
|
}
|
|
|
|
mBinding.iv10.setOnClickListener {
|
|
lottery(10)
|
|
}
|
|
|
|
mBinding.iv20.setOnClickListener {
|
|
lottery(20)
|
|
}
|
|
mBinding.ivOnOrOff.tag = 1
|
|
mBinding.ivOnOrOff.setOnClickListener {
|
|
if (mBinding.ivOnOrOff.tag == 1) {
|
|
mBinding.ivOnOrOff.tag = 0
|
|
mBinding.ivOnOrOff.setImageResource(R.mipmap.prize_call_box_gift_anim_on)
|
|
} else {
|
|
mBinding.ivOnOrOff.tag = 1
|
|
mBinding.ivOnOrOff.setImageResource(R.mipmap.prize_call_box_gift_anim_off)
|
|
}
|
|
}
|
|
|
|
itemAdapter = ItemAdapter()
|
|
mBinding.recycleView.adapter = itemAdapter
|
|
|
|
itemRecord = ItemRecordAdapter()
|
|
itemRecord?.setNewData(resultMyRecordList)
|
|
mBinding.recyclerMyRecord.adapter = itemRecord
|
|
|
|
|
|
mBinding.ivRule.setOnClickListener {
|
|
//规则
|
|
val bundle = Bundle()
|
|
bundle.putString("url", ruleUrl)
|
|
bundle.putInt("type", type)
|
|
val dialog = WebViewDialog(ActivityUtils.getTopActivity(), bundle)
|
|
dialog.show()
|
|
}
|
|
|
|
mBinding.ivPrizePool.setOnClickListener {
|
|
//奖池
|
|
val prizePoolDialog = PrizePoolDialog(ActivityUtils.getTopActivity())
|
|
prizePoolDialog.updateData(prizePoolList, type)
|
|
prizePoolDialog.show()
|
|
}
|
|
|
|
mBinding.ivMyRecord.setOnClickListener {
|
|
//记录
|
|
val giftLotteryDialogFragment = GiftLotteryDialogFragment.newInstance(mGiftBagId)
|
|
giftLotteryDialogFragment.show(fragmentManager, "GiftLotteryDialogFragment")
|
|
}
|
|
|
|
|
|
|
|
mBinding.smartRefresh.setOnLoadMoreListener(object : OnRefreshLoadMoreListener {
|
|
override fun onRefresh(refreshLayout: RefreshLayout) {
|
|
page = 1
|
|
getMyRecord()
|
|
}
|
|
|
|
override fun onLoadMore(refreshLayout: RefreshLayout) {
|
|
page++
|
|
getMyRecord()
|
|
}
|
|
})
|
|
|
|
}
|
|
|
|
private fun lottery(count: Int) {
|
|
if (isLottery) {
|
|
ToastUtils.showShort("正在抽取中...")
|
|
return
|
|
}
|
|
isLottery = true
|
|
|
|
if (mBinding.ivOnOrOff.tag == 1) {
|
|
startAnim()
|
|
}
|
|
currLottery = count
|
|
startLottery(mRoomId, mGiftBagId, count.toString())
|
|
}
|
|
|
|
override fun initData() {
|
|
|
|
}
|
|
|
|
|
|
fun show(roomId: String, giftBagId: String) {
|
|
super.show()
|
|
mRoomId = roomId
|
|
mGiftBagId = giftBagId
|
|
getUserWallet()
|
|
startAnimDefault()
|
|
getLottery()
|
|
}
|
|
|
|
private fun startAnimDefault() {
|
|
mBinding.svgaAnimDefault.visibility = View.VISIBLE
|
|
// 停止并清除当前动画
|
|
mBinding.svgaAnimDefault.stopAnimation()
|
|
mBinding.svgaAnimDefault.clear()
|
|
// 使用SVGAParser重新解析
|
|
val parser = SVGAParser(context)
|
|
parser.decodeFromAssets("prize_call_box_default.svga",
|
|
object : SVGAParser.ParseCompletion {
|
|
override fun onComplete(videoItem: SVGAVideoEntity) {
|
|
mBinding.svgaAnimDefault.setVideoItem(videoItem)
|
|
mBinding.svgaAnimDefault.clearsAfterStop = true
|
|
|
|
// 开始动画
|
|
mBinding.svgaAnimDefault.startAnimation()
|
|
}
|
|
|
|
override fun onError() {
|
|
// 处理错误
|
|
}
|
|
})
|
|
}
|
|
|
|
|
|
private fun startAnim() {
|
|
mBinding.svgaAnim.visibility = View.VISIBLE
|
|
// 停止并清除当前动画
|
|
mBinding.svgaAnim.stopAnimation()
|
|
mBinding.svgaAnim.clear()
|
|
|
|
// 使用SVGAParser重新解析
|
|
val parser = SVGAParser(context)
|
|
parser.decodeFromAssets("prize_call_open_box.svga",
|
|
object : SVGAParser.ParseCompletion {
|
|
override fun onComplete(videoItem: SVGAVideoEntity) {
|
|
mBinding.svgaAnim.setVideoItem(videoItem)
|
|
mBinding.svgaAnim.clearsAfterStop = true
|
|
|
|
// 设置回调
|
|
mBinding.svgaAnim.callback = object : SVGACallback {
|
|
override fun onFinished() {
|
|
isLottery = false
|
|
mBinding.svgaAnimDefault.startAnimation()
|
|
if (resultList.isNotEmpty()) {
|
|
// mBinding.recycleView.visibility = View.VISIBLE
|
|
// itemAdapter?.setNewData(resultList)
|
|
DialogLoveStationResult(context).show(mRoomId,mGiftBagId,currLottery, resultList, object : DialogLoveStationResult.OnResultListener {
|
|
override fun onLottery() {
|
|
getUserWallet()
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
override fun onPause() {}
|
|
override fun onRepeat() {}
|
|
override fun onStep(frame: Int, percentage: Double) {
|
|
if (frame == 1) {
|
|
mBinding.svgaAnimDefault.stopAnimation()
|
|
}
|
|
}
|
|
}
|
|
if (httpError)
|
|
return
|
|
// 开始动画
|
|
mBinding.svgaAnim.startAnimation()
|
|
}
|
|
|
|
override fun onError() {
|
|
// 处理错误
|
|
}
|
|
})
|
|
}
|
|
|
|
|
|
class ItemAdapter :
|
|
BaseQuickAdapter<BlindReslutBean.ReslutList, BaseViewHolder>(R.layout.item_lottery_gift_layout) {
|
|
override fun convert(helper: BaseViewHolder, item: BlindReslutBean.ReslutList) {
|
|
helper.setText(R.id.tv_name, item.gift_name + "x" + item.count)
|
|
helper.setText(R.id.tv_price, item.gift_price)
|
|
ImageUtils.loadHead(item.base_image, helper.getView(R.id.iv_gift))
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private fun startLottery(roomId: String, giftBagId: String, num: String) {
|
|
RetrofitClient.getInstance().drawGiftList(
|
|
giftBagId,
|
|
"",
|
|
roomId,
|
|
num,
|
|
"",
|
|
"",
|
|
object : BaseObserver<BlindReslutBean>() {
|
|
override fun onSubscribe(d: Disposable) {
|
|
|
|
}
|
|
|
|
override fun onNext(t: BlindReslutBean) {
|
|
getUserWallet()
|
|
resultList.clear()
|
|
if (t.reslut_list == null) {
|
|
isLottery = false
|
|
httpError = true
|
|
if (mBinding.svgaAnim.isAnimating) {
|
|
mBinding.svgaAnim.stopAnimation()
|
|
}
|
|
return
|
|
}
|
|
httpError = false
|
|
resultList.addAll(t.reslut_list)
|
|
if (mBinding.ivOnOrOff.tag != 1) {
|
|
isLottery = false
|
|
// mBinding.recycleView.visibility = View.VISIBLE
|
|
// itemAdapter?.setNewData(resultList)
|
|
DialogLoveStationResult(context).show(mRoomId,mGiftBagId,currLottery, resultList, object : DialogLoveStationResult.OnResultListener {
|
|
override fun onLottery() {
|
|
getUserWallet()
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
})
|
|
}
|
|
|
|
private var ruleUrl = ""
|
|
private var type = 38
|
|
private var prizePoolList:MutableList<GiftBean>? = null
|
|
|
|
private fun getUserWallet() {
|
|
RetrofitClient.getInstance().wallet(object : BaseObserver<WalletBean>() {
|
|
override fun onSubscribe(d: Disposable) {
|
|
|
|
}
|
|
|
|
override fun onNext(t: WalletBean) {
|
|
mBinding.tvCount.text = t.coin
|
|
}
|
|
})
|
|
}
|
|
|
|
private var page = 1
|
|
private var pageSize = 30
|
|
private var resultMyRecordList: MutableList<GiftBean> = mutableListOf()
|
|
|
|
|
|
private fun getMyRecord() {
|
|
RetrofitClient.getInstance().getMyRecord(
|
|
mGiftBagId,
|
|
page.toString(),
|
|
pageSize.toString(),
|
|
object : BaseObserver<List<GiftBean>>() {
|
|
override fun onSubscribe(d: Disposable) {
|
|
|
|
}
|
|
|
|
override fun onNext(giftBean: List<GiftBean>) {
|
|
mBinding.smartRefresh.finishRefresh()
|
|
mBinding.smartRefresh.finishLoadMore()
|
|
|
|
if (giftBean.isNotEmpty()){
|
|
return
|
|
}
|
|
|
|
if (page == 1) {
|
|
resultMyRecordList.clear()
|
|
itemRecord?.setNewData(resultMyRecordList)
|
|
}
|
|
resultMyRecordList.addAll(giftBean)
|
|
itemRecord?.notifyDataSetChanged()
|
|
}
|
|
})
|
|
}
|
|
|
|
class ItemRecordAdapter :
|
|
BaseQuickAdapter<GiftBean, BaseViewHolder>(R.layout.item_lottery_gift_layout) {
|
|
override fun convert(helper: BaseViewHolder, item: GiftBean) {
|
|
helper.setText(R.id.tv_name, item.gift_name + "x" + item.count)
|
|
helper.setText(R.id.tv_price, item.gift_price)
|
|
ImageUtils.loadHead(item.base_image, helper.getView(R.id.iv_gift))
|
|
}
|
|
}
|
|
|
|
|
|
private fun getLottery(){
|
|
RetrofitClient.getInstance().getBoxGiftList(mGiftBagId, mRoomId, object : BaseObserver<BlindBoxBean?>() {
|
|
override fun onSubscribe(d: Disposable) {
|
|
|
|
}
|
|
|
|
@SuppressLint("SetTextI18n")
|
|
override fun onNext(blindBoxBeans: BlindBoxBean) {
|
|
val oneLottery = blindBoxBeans.box_price
|
|
|
|
ruleUrl = blindBoxBeans.rule_url
|
|
prizePoolList = blindBoxBeans.gift_list
|
|
|
|
mBinding.tv1.text = oneLottery.toString()
|
|
mBinding.tv10.text = (oneLottery * 10).toString()
|
|
mBinding.tv20.text = (oneLottery * 20).toString()
|
|
}
|
|
})
|
|
}
|
|
|
|
|
|
} |