Commit e2f9aea3 authored by mengcuiguang's avatar mengcuiguang

代码优化

parent 7b02cff9
......@@ -417,6 +417,7 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener,
//策略场景类调起支付方法开始支付,以及接收回调。
RxPay.pay(wxPay, this, wxPayInfoImpl, object : IPayCallback {
override fun success() {
AppConfig.showVipAdDialog = false
UserManager.getInstance().vipFlag = true
vipPresenter.queryVipOrder(wxParanBean.tid.toString(), true)
}
......@@ -454,6 +455,7 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener,
//策略场景类调起支付方法开始支付,以及接收回调。
RxPay.pay(aliPay, this, alipayInfoImpl, object : IPayCallback {
override fun success() {
AppConfig.showVipAdDialog = false
UserManager.getInstance().vipFlag = true
vipPresenter.queryVipOrder(wxParanBean.tid.toString(), true)
}
......
......@@ -2,6 +2,8 @@ package com.duben.xixiplaylet.video.csj
import android.app.Dialog
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.util.Log
import android.view.View
import android.widget.Button
......@@ -42,6 +44,7 @@ import com.duben.library.utils.GlideUtils
import com.duben.library.utils.nodoubleclick.AntiShake
import com.duben.xixiplaylet.common.AppConfig
import com.duben.xixiplaylet.mvp.model.VipBean
import com.duben.xixiplaylet.ui.widgets.DetailAdDialog
import kotlinx.android.synthetic.main.drama_activity_api_detail.*
import kotlinx.android.synthetic.main.drama_activity_api_detail.iv_lucky_gif
import kotlinx.android.synthetic.main.drama_activity_api_detail.ll_lucky
......@@ -109,6 +112,10 @@ class DramaApiDetailActivity : BaseActivity(), VideoEpisodeAdapter.OnEpisodeClic
private var mVedioBean: VedioBean? = null
private var mCurrentIndex = 0
private var currentDramaIndex = 0
private var detailAdDialog: DetailAdDialog? = null
override fun getBundleExtras(extras: Bundle?) {
val json = extras?.getString(Constant.VEDIO_BEAN)
......@@ -183,7 +190,8 @@ class DramaApiDetailActivity : BaseActivity(), VideoEpisodeAdapter.OnEpisodeClic
unlock.visibility = View.GONE
}
tv_title.text = if (AppConfig.firstVipPrice == 0.0) "解锁后续剧集" else "${AppConfig.firstVipPrice}元解锁后续剧集"
tv_title.text =
if (AppConfig.firstVipPrice == 0.0) "解锁后续剧集" else "${AppConfig.firstVipPrice}元解锁后续剧集"
if (mVedioBean!!.collect == 0) {
......@@ -220,6 +228,7 @@ class DramaApiDetailActivity : BaseActivity(), VideoEpisodeAdapter.OnEpisodeClic
val bundle = Bundle()
bundle.putString(VipActivity.VEDIO_ID, mVedioBean!!.vedioId.toString())
bundle.putString(VipActivity.THIRD_ID, mVedioBean!!.thirdId)
bundle.putBoolean(VipActivity.IS_DETAIL, true)
readyGo(VipActivity::class.java, bundle)
}
}
......@@ -266,6 +275,14 @@ class DramaApiDetailActivity : BaseActivity(), VideoEpisodeAdapter.OnEpisodeClic
// 重置状态
resetData()
}
// vip界面返回弹出广告弹窗
if (AppConfig.showVipAdDialog && !UserManager.getInstance().vipFlag) {
Handler(Looper.getMainLooper()).postDelayed({
adDialog()
AppConfig.showVipAdDialog = false
}, 300)
}
}
override fun onPause() {
......@@ -420,7 +437,7 @@ class DramaApiDetailActivity : BaseActivity(), VideoEpisodeAdapter.OnEpisodeClic
Log.d(TAG, "showAdIfNeeded:" + map?.toString())
blockView?.visibility = View.VISIBLE
unlockCallback = callback
currentDramaIndex = dpWidget?.currentDramaIndex!!
// 展示广告
......@@ -434,7 +451,8 @@ class DramaApiDetailActivity : BaseActivity(), VideoEpisodeAdapter.OnEpisodeClic
)
} else {
tv_title.text = if (AppConfig.firstVipPrice == 0.0) "解锁后续剧集" else "${AppConfig.firstVipPrice}元解锁后续剧集"
tv_title.text =
if (AppConfig.firstVipPrice == 0.0) "解锁后续剧集" else "${AppConfig.firstVipPrice}元解锁后续剧集"
}
......@@ -739,7 +757,13 @@ class DramaApiDetailActivity : BaseActivity(), VideoEpisodeAdapter.OnEpisodeClic
// 超过免费剧
if (position >= mVedioBean!!.freeIndex) {
ll_lucky.visibility = View.VISIBLE
context?.let { GlideUtils.loadRoundImageViewGif(it, R.drawable.ic_nine, iv_lucky_gif) }
context?.let {
GlideUtils.loadRoundImageViewGif(
it,
R.drawable.ic_nine,
iv_lucky_gif
)
}
} else {
ll_lucky.visibility = View.GONE
}
......@@ -837,4 +861,106 @@ class DramaApiDetailActivity : BaseActivity(), VideoEpisodeAdapter.OnEpisodeClic
})
}
private fun adDialog() {
detailAdDialog = DetailAdDialog(context, object : DialogListener() {
override fun onClick(v: View) {
// if (AntiShake.check(v.id)) return
when (v.id) {
R.id.iv_detail_ad_next -> {
val carrierType = Constant.CARRIERTYPE_CSJ_VEDIO
AdManager.instance.showAd(this@DramaApiDetailActivity, carrierType,
object : AdStatusListener {
var canFail = false
override fun adSuccess() {
canFail = true
}
override fun adFail() {
if (canFail) return
NoPreAdManager.loadVideoAd(
this@DramaApiDetailActivity,
carrierType, object : AdStatusListener {
override fun adFail() {
showToast("广告太火爆了,请稍候再试")
}
override fun adSuccess() {
}
override fun adClose(vo: HashMap<String, Any>?) {
vo?.let {
if (isThirdId) {
it["thirdId"] = "" + mVedioBean!!.thirdId
} else {
it["vedioId"] = "" + mVedioBean!!.vedioId
}
videoPresenter.unlock(it)
}
// 更新解锁集数
for (i in 1 until lockSet) {
val hasUnlockList: MutableList<Int> =
mHasUnlockIndexMap[drama?.id]
?: mutableListOf()
hasUnlockList.add(currentDramaIndex + i)
mHasUnlockIndexMap[drama!!.id] = hasUnlockList
}
mInitUnlockIndex =
mUnlockIndexMap[drama?.id]!! + lockSet
mUnlockIndexMap[drama!!.id] =
mUnlockIndexMap[drama!!.id]!! + lockSet
mVedioBean!!.unlockIndex = mInitUnlockIndex
// 播放当前集
mVedioBean!!.seeIndex = mCurrentIndex
mVedioBean!!.orderTags = orderTagsList
LocalVedioManager.commitVedio(mVedioBean!!)
blockView?.visibility = View.GONE
unlockCallback?.onDramaRewardArrived() // 解锁当前集
}
})
}
override fun adClose(vo: HashMap<String, Any>?) {
vo?.let {
if (isThirdId) {
it["thirdId"] = "" + mVedioBean!!.thirdId
} else {
it["vedioId"] = "" + mVedioBean!!.vedioId
}
videoPresenter.unlock(it)
}
// 更新解锁集数
for (i in 1 until lockSet) {
val hasUnlockList: MutableList<Int> =
mHasUnlockIndexMap[drama!!.id] ?: mutableListOf()
hasUnlockList.add(currentDramaIndex + i)
mHasUnlockIndexMap[drama!!.id] = hasUnlockList
}
mInitUnlockIndex = mUnlockIndexMap[drama!!.id]!! + lockSet
mUnlockIndexMap[drama!!.id] =
mUnlockIndexMap[drama!!.id]!! + lockSet
mVedioBean!!.unlockIndex = mInitUnlockIndex
blockView?.visibility = View.GONE
// 播放当前集
mVedioBean!!.seeIndex = mCurrentIndex
mVedioBean!!.orderTags = orderTagsList
LocalVedioManager.commitVedio(mVedioBean!!)
unlockCallback?.onDramaRewardArrived() // 解锁当前集
}
})
detailAdDialog?.dismiss()
}
}
}
})
detailAdDialog!!.show()
}
}
\ No newline at end of file
......@@ -94,7 +94,7 @@ class TxVideoActivity : BaseActivity(), View.OnClickListener, VideoView,
}
// vip界面返回弹出广告弹窗
if (AppConfig.showVipAdDialog) {
if (AppConfig.showVipAdDialog && !UserManager.getInstance().vipFlag) {
Handler(Looper.getMainLooper()).postDelayed({
adDialog()
AppConfig.showVipAdDialog = false
......
......@@ -2,6 +2,8 @@ package com.duben.xixiplaylet.video.tx.newrecommend
import android.app.Dialog
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.view.View
import androidx.core.content.ContextCompat
import com.google.gson.Gson
......@@ -27,6 +29,7 @@ import com.duben.xixiplaylet.video.tx.VideoModel
import com.duben.library.utils.GlideUtils
import com.duben.library.utils.nodoubleclick.AntiShake
import com.duben.xixiplaylet.common.AppConfig
import com.duben.xixiplaylet.ui.widgets.DetailAdDialog
import com.duben.xixiplaylet.ui.widgets.DialogListener
import com.duben.xixiplaylet.ui.widgets.VideoEpisodeDialog
import kotlinx.android.synthetic.main.activity_new_tx_video.*
......@@ -42,6 +45,7 @@ class NewTxVideoActivity : BaseActivity(), View.OnClickListener, VideoView,
private var mAllData = arrayListOf<VedioEpisodeBean>()
private var dialog: VideoEpisodeDialog? = null
private var detailAdDialog: DetailAdDialog? = null
private val videoPresenter by lazy { VideoPresenter() }
......@@ -81,6 +85,14 @@ class NewTxVideoActivity : BaseActivity(), View.OnClickListener, VideoView,
playIndex = new_super_short_video_view.currentPosition
mVedioBean?.let { videoPresenter.getIndexList("" + it.vedioId) }
}
// vip界面返回弹出广告弹窗
if (AppConfig.showVipAdDialog && !UserManager.getInstance().vipFlag) {
Handler(Looper.getMainLooper()).postDelayed({
adDialog()
AppConfig.showVipAdDialog = false
}, 300)
}
}
override fun onPause() {
......@@ -285,6 +297,23 @@ class NewTxVideoActivity : BaseActivity(), View.OnClickListener, VideoView,
}
R.id.unlock -> {
// 看广告解锁
showAd()
}
R.id.vip -> {
// 开通VIP
val bundle = Bundle()
bundle.putString(VipActivity.VEDIO_ID, mVedioBean!!.vedioId.toString())
bundle.putString(VipActivity.THIRD_ID, mVedioBean!!.thirdId)
bundle.putBoolean(VipActivity.IS_RECOMMEND, true)
bundle.putBoolean(VipActivity.IS_DETAIL, true)
readyGo(VipActivity::class.java, bundle)
}
else -> {}
}
}
private fun showAd() {
val carrierType = Constant.CARRIERTYPE_TX_VEDIO
AdManager.instance.showAd(this, carrierType,
object : AdStatusListener {
......@@ -317,18 +346,6 @@ class NewTxVideoActivity : BaseActivity(), View.OnClickListener, VideoView,
}
})
}
R.id.vip -> {
// 开通VIP
val bundle = Bundle()
bundle.putString(VipActivity.VEDIO_ID, mVedioBean!!.vedioId.toString())
bundle.putString(VipActivity.THIRD_ID, mVedioBean!!.thirdId)
bundle.putBoolean(VipActivity.IS_RECOMMEND, true)
readyGo(VipActivity::class.java, bundle)
}
else -> {}
}
}
private fun updateEpisodeData(position: Int, vo: HashMap<String, Any>?) {
vo?.let {
......@@ -358,4 +375,20 @@ class NewTxVideoActivity : BaseActivity(), View.OnClickListener, VideoView,
}
return readPosition
}
private fun adDialog() {
detailAdDialog = DetailAdDialog(context, object : DialogListener() {
override fun onClick(v: View) {
if (AntiShake.check(v.id)) return
when (v.id) {
R.id.iv_detail_ad_next -> {
showAd()
detailAdDialog?.dismiss()
}
}
}
})
detailAdDialog!!.show()
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment