Commit fd0785a0 authored by jyx's avatar jyx

代码优化

parent 13e303fd
......@@ -172,7 +172,7 @@
android:theme="@style/TransparentTheme" />
<activity
android:name=".video.DramaApiDetailActivity"
android:name=".video.csj.DramaApiDetailActivity"
android:exported="false"
android:screenOrientation="portrait" />
......@@ -182,7 +182,13 @@
android:screenOrientation="portrait" />
<activity
android:name=".video.TxVideoActivity"
android:name=".video.tx.TxVideoActivity"
android:exported="false"
android:hardwareAccelerated="true"
android:screenOrientation="portrait" />
<activity
android:name=".video.tx.NewTxVideoActivity"
android:exported="false"
android:hardwareAccelerated="true"
android:screenOrientation="portrait" />
......
......@@ -14,8 +14,8 @@ import com.mints.helivideo.mvp.model.VedioBean
import com.mints.helivideo.ui.activitys.RecommendActivity
import com.mints.helivideo.utils.AppPreferencesManager
import com.mints.helivideo.utils.ToastUtil
import com.mints.helivideo.video.DramaApiDetailActivity
import com.mints.helivideo.video.TxVideoActivity
import com.mints.helivideo.video.csj.DramaApiDetailActivity
import com.mints.helivideo.video.tx.TxVideoActivity
/**
* 本地视频缓存管理
......
......@@ -21,7 +21,7 @@ import com.mints.helivideo.ui.fragment.MyFragment
import com.mints.helivideo.ui.fragment.RecommendFragment
import com.mints.helivideo.ui.widgets.DialogListener
import com.mints.helivideo.ui.widgets.PhoneDialog
import com.mints.helivideo.video.DPHolderManager
import com.mints.helivideo.video.csj.DPHolderManager
import kotlinx.android.synthetic.main.activity_main.*
/**
......
......@@ -8,6 +8,9 @@ import com.mints.helivideo.R
import com.mints.helivideo.common.Constant
import com.mints.helivideo.mvp.model.VedioBean
import com.mints.helivideo.ui.activitys.base.BaseActivity
import com.mints.helivideo.utils.LogUtil
import com.mints.helivideo.video.tx.TXVodPlayerWrapper
import com.mints.helivideo.video.tx.VideoModel
import com.mints.library.utils.nodoubleclick.AntiShake
import kotlinx.android.synthetic.main.activity_recommend.*
......@@ -41,12 +44,27 @@ class RecommendActivity : BaseActivity(), View.OnClickListener {
}
private fun initView() {
val videoModel = VideoModel(mVedioBean!!.recommendUrl)
val txVodPlayerWrapper = TXVodPlayerWrapper(mContext)
txVodPlayerWrapper.preStartPlay(videoModel)
baseItemView.setTXVodPlayer(txVodPlayerWrapper)
baseItemView.startPlay()
}
private fun initListener() {
ic_recommend_quit.setOnClickListener(this)
}
override fun onResume() {
super.onResume()
baseItemView.startPlay()
}
override fun onPause() {
super.onPause()
baseItemView.pausePlayer()
}
override fun finish() {
super.finish()
overridePendingTransition(0, R.anim.scale_out)
......
......@@ -14,7 +14,7 @@ import com.mints.helivideo.manager.UserManager
import com.mints.helivideo.ui.activitys.MainActivity
import com.mints.helivideo.ui.adapter.RecommendPageAdapter
import com.mints.helivideo.ui.fragment.base.BaseFragment
import com.mints.helivideo.video.DramaTabFragment
import com.mints.helivideo.video.csj.DramaTabFragment
import com.mints.helivideo.video.tx.TxVideoFragment
import com.mints.library.utils.nodoubleclick.AntiShake
import kotlinx.android.synthetic.main.fragment_recommend.*
......
package com.mints.helivideo.video
package com.mints.helivideo.video.csj
import android.content.Context
import android.util.Log
......
package com.mints.helivideo.video
package com.mints.helivideo.video.csj
import android.app.Dialog
import android.os.Bundle
......
package com.mints.helivideo.video
package com.mints.helivideo.video.csj
import android.content.Context
import android.view.View
......
package com.mints.helivideo.video.tx
import android.app.Dialog
import android.os.Bundle
import android.view.View
import com.google.gson.Gson
import com.mints.helivideo.R
import com.mints.helivideo.ad.express.ExpressManager
import com.mints.helivideo.common.Constant
import com.mints.helivideo.manager.LocalVedioManager
import com.mints.helivideo.manager.UserManager
import com.mints.helivideo.mvp.model.*
import com.mints.helivideo.mvp.model.IndexList.VedioEpisodeBean
import com.mints.helivideo.mvp.presenters.VideoPresenter
import com.mints.helivideo.mvp.views.VideoView
import com.mints.helivideo.ui.activitys.VipActivity
import com.mints.helivideo.ui.activitys.base.BaseActivity
import com.mints.helivideo.ui.adapter.VideoEpisodeAdapter
import com.mints.helivideo.ui.widgets.DialogListener
import com.mints.helivideo.ui.widgets.VideoEpisodeDialog
import com.mints.helivideo.video.tx.adapter.TxVideoAdapter
import com.mints.library.utils.nodoubleclick.AntiShake
import kotlinx.android.synthetic.main.activity_new_tx_video.*
class NewTxVideoActivity : BaseActivity(), View.OnClickListener, VideoView,
VideoEpisodeAdapter.OnEpisodeClickListener, TxVideoAdapter.OnCustomChildClickListener {
private var mVipFlag = UserManager.getInstance().vipFlag
private var videos = ArrayList<VedioEpisodeBean>()
private var dialog: VideoEpisodeDialog? = null
private val videoPresenter by lazy { VideoPresenter() }
private var mVedioBean: VedioBean? = null
private var indexBean: IndexList? = null
private var tipList: ArrayList<String>? = null
private var orderTagsList: ArrayList<String>? = null
private var isPlayNext = false
private var playIndex = 1
override fun getContentViewLayoutID() = R.layout.activity_new_tx_video
override fun initViewsAndEvents() {
videoPresenter.attachView(this)
mVedioBean?.let { videoPresenter.getIndexList("" + it.vedioId) }
initView()
}
override fun getBundleExtras(extras: Bundle?) {
val json = extras?.getString(Constant.VEDIO_BEAN)
isPlayNext = extras?.getBoolean(Constant.VEDIO_NEXT, false) == true
mVedioBean = Gson().fromJson(json, VedioBean::class.java)
orderTagsList = mVedioBean?.orderTags
if (isPlayNext) {
mVedioBean?.let {
it.recommendIndex = it.recommendIndex + 1
}
}
super.getBundleExtras(extras)
}
override fun isApplyKitKatTranslucency() = false
override fun onResume() {
super.onResume()
super_short_video_view.resume()
videoPresenter.showTurn()
if (mVipFlag != UserManager.getInstance().vipFlag && UserManager.getInstance().vipFlag) {
// 重置状态
isPlayNext = false
playIndex = super_short_video_view.currentPosition
mVedioBean?.let { videoPresenter.getIndexList("" + it.vedioId) }
}
}
override fun onPause() {
super.onPause()
super_short_video_view.pause()
}
override fun onDestroy() {
super_short_video_view.onDestroy()
super.onDestroy()
super_short_video_view.releasePlayer()
ExpressManager.instance.destroy()
videoPresenter.detachView()
}
private fun initView() {
if (!UserManager.getInstance().vipFlag) {
ExpressManager.instance.preLoadAd()
}
episode_tv.text = String.format(
"共%d集 %s",
mVedioBean?.vedioTotal,
if (mVedioBean?.completeStatus == 0) "已完结" else "更新中"
)
super_short_video_view.setOnCustomChildClickListener(this)
super_short_video_view.setOnPageChangeListener {
if (super_short_video_view.isAdPosition(it) || super_short_video_view.isLuckPosition(it)) {
fm_bottom.visibility = View.GONE
super_short_video_view.pause()
return@setOnPageChangeListener
}
fm_bottom.visibility = View.VISIBLE
// videoIndex -> seeIndex
val data = super_short_video_view.data
if (data.size > it && data[it].itemType == MULTI_ITEM_1) {
mVedioBean!!.seeIndex = data[it].video!!.vedioIndex
mVedioBean!!.orderTags = orderTagsList
mVedioBean!!.isRecommendVedio = true
LocalVedioManager.commitVedio(mVedioBean!!)
}
}
fm_bottom.setOnClickListener(this)
close_iv.setOnClickListener(this)
}
override fun onClick(v: View?) {
if (AntiShake.check(v?.id)) return
when (v?.id) {
R.id.close_iv -> {
finish()
}
R.id.fm_bottom -> {
showEpisodeDialog()
}
else -> {}
}
}
private fun showEpisodeDialog() {
if (dialog != null && dialog!!.isShowing) return
dialog = VideoEpisodeDialog(this, mVedioBean, object : DialogListener() {
override fun onClick(dialog: Dialog?, v: View?) {
super.onClick(dialog, v)
dialog?.dismiss()
}
})
dialog?.setCurrentIndex(super_short_video_view.realSeeIndex)
dialog?.setOnEpisodeClickListener(this)
dialog?.show()
}
override fun getIndexListSuc(indexList: IndexList) {
// 处理推荐页跳转自动播放下一集逻辑
if (isPlayNext) {
playIndex = mVedioBean!!.recommendIndex - 1
if (playIndex >= mVedioBean!!.unlockIndex - 1) {
playIndex = mVedioBean!!.unlockIndex - 1
}
} else {
playIndex = mVedioBean!!.seeIndex - 1
}
if (playIndex > mVedioBean!!.vedioTotal || playIndex <= 0) playIndex = 0
tipList = indexList.tip
mVedioBean = indexList.vedioMsg
indexBean = indexList
videos.clear()
videos.addAll(indexList.list)
super_short_video_view.loadData(mVedioBean, getAdapterData(), playIndex)
}
override fun getIndexListFail() {
}
override fun collectSuc() {
mVedioBean!!.collect = 1
}
override fun collectFail() {
}
override fun cancelCollectSuc() {
mVedioBean!!.collect = 0
}
override fun cancelCollectFail() {
}
override fun unlockSuc(indexList: IndexList) {
videos.addAll(indexList.list)
mVedioBean!!.unlockIndex = videos.size
super_short_video_view.loadMoreData(getAdapterData())
}
override fun unlockFail() {
}
override fun showTurnSuc(data: NineShowBean) {
}
override fun onEpisodeClick(position: Int) {
dialog?.dismiss()
val data = super_short_video_view.data
if (position >= mVedioBean!!.unlockIndex) {
super_short_video_view.onItemClick(data.size - 1)
return
}
val readPosition = getRealPosition(position + 1)
super_short_video_view.onItemClick(readPosition)
}
private fun getAdapterData(): MutableList<VideoMultiItemEntity> {
val data = mutableListOf<VideoMultiItemEntity>()
if (videos.size > 0) {
for (video in videos) {
val item = VideoMultiItemEntity(MULTI_ITEM_1, video, VideoModel(video.vedioUrl))
data.add(item)
}
if (mVedioBean!!.unlockIndex < mVedioBean!!.vedioTotal) {
val item =
VideoMultiItemEntity(MULTI_ITEM_2, videos[0], VideoModel(videos[0].vedioUrl))
data.add(item)
}
}
return data
}
override fun onCustomChildClick(view: View, position: Int) {
when (view.id) {
R.id.ll_collect -> {
// 收藏
mVedioBean?.let {
if (it.collect == 0) {
videoPresenter.collect("" + it.vedioId)
} else {
videoPresenter.cancelCollect("" + it.vedioId)
}
}
}
R.id.leave -> {
// 返回
finish()
}
R.id.unlock -> {
// 无看广告解锁
}
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 getRealPosition(position: Int): Int {
var readPosition = position
val data = super_short_video_view.data
if (data != null && data.size > 0) {
for (i in 0 until data.size) {
if (data[i].itemType == MULTI_ITEM_1) {
if (data[i].video!!.vedioIndex == position) {
readPosition = i
break
}
}
}
}
return readPosition
}
}
\ No newline at end of file
......@@ -18,7 +18,7 @@ import androidx.recyclerview.widget.RecyclerView;
import com.mints.helivideo.ad.draw.DrawExpressManager;
import com.mints.helivideo.manager.UserManager;
import com.mints.helivideo.mvp.model.VideoMultiItemEntity2;
import com.mints.helivideo.video.tx.adapter.TxRecommendVideo2Adapter;
import com.mints.helivideo.video.tx.adapter.TxRecommendVideoAdapter;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
import com.mints.helivideo.R;
......@@ -34,7 +34,7 @@ public class RecommendVideoView extends RelativeLayout {
private RecyclerView mRecyclerView;
private SmartRefreshLayout mSmartRefreshLayout;
private TxRecommendVideo2Adapter mAdapter;
private TxRecommendVideoAdapter mAdapter;
private LinearLayoutManager mLayoutManager;
private PagerSnapHelper mSnapHelper;
private int mLastPositionInIDLE = -1;
......@@ -82,7 +82,7 @@ public class RecommendVideoView extends RelativeLayout {
mSmartRefreshLayout.setEnableRefresh(false);
mSnapHelper = new PagerSnapHelper();
mSnapHelper.attachToRecyclerView(mRecyclerView);
mAdapter = new TxRecommendVideo2Adapter();
mAdapter = new TxRecommendVideoAdapter();
mAdapter.setNewInstance(getAdapterData(null));
mLayoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false) {
@Override
......@@ -236,7 +236,7 @@ public class RecommendVideoView extends RelativeLayout {
this.mOnPageChangeListener = onPageChangeListener;
}
public void setOnCustomChildClickListener(TxRecommendVideo2Adapter.OnCustomChildClickListener onCustomChildClickListener) {
public void setOnCustomChildClickListener(TxRecommendVideoAdapter.OnCustomChildClickListener onCustomChildClickListener) {
mAdapter.setOnCustomChildClickListener(onCustomChildClickListener);
}
......
package com.mints.helivideo.video
package com.mints.helivideo.video.tx
import android.app.Dialog
import android.os.Bundle
......@@ -26,7 +26,6 @@ import com.mints.helivideo.ui.widgets.VideoEpisodeDialog
import com.mints.helivideo.ui.widgets.VipCountDialog
import com.mints.helivideo.utils.AppPreferencesManager
import com.mints.helivideo.utils.SpanUtils
import com.mints.helivideo.video.tx.VideoModel
import com.mints.helivideo.video.tx.adapter.TxVideoAdapter
import com.mints.library.utils.nodoubleclick.AntiShake
import kotlinx.android.synthetic.main.activity_tx_video.*
......
......@@ -13,7 +13,7 @@ import com.mints.helivideo.mvp.model.BannerList
import com.mints.helivideo.mvp.presenters.RecommendPresenter
import com.mints.helivideo.mvp.views.RecommendView
import com.mints.helivideo.ui.fragment.base.BaseFragment
import com.mints.helivideo.video.tx.adapter.TxRecommendVideo2Adapter
import com.mints.helivideo.video.tx.adapter.TxRecommendVideoAdapter
import kotlinx.android.synthetic.main.fragment_tx_video.*
/**
......@@ -57,7 +57,7 @@ class TxVideoFragment : BaseFragment(), RecommendView {
)
}
recommend_view.setOnCustomChildClickListener(object :
TxRecommendVideo2Adapter.OnCustomChildClickListener {
TxRecommendVideoAdapter.OnCustomChildClickListener {
override fun onCustomChildClick(view: View, position: Int) {
when (view.id) {
R.id.ll_bottom -> {
......
package com.mints.helivideo.video.tx.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;
public abstract class AbsPlayerRecyclerViewAdapter<T, K extends AbsViewHolder> extends RecyclerView.Adapter<K> {
private List<T> mList;
public Context mContext;
public AbsPlayerRecyclerViewAdapter(List<T> list) {
this.mList = list;
}
@Override
public K onCreateViewHolder(ViewGroup parent, int viewType) {
mContext = parent.getContext();
K holder = onCreateHolder(parent);
return holder;
}
@Override
public void onBindViewHolder(K holder, int position) {
onHolder(holder, mList.get(position), position);
}
@Override
public int getItemViewType(int position) {
return position;
}
@Override
public int getItemCount() {
return mList == null ? 0 : mList.size();
}
public abstract void onHolder(K holder, T bean, int position);
public abstract K onCreateHolder(ViewGroup parent);
public View getViewByRes(int res, ViewGroup parent) {
return LayoutInflater.from(mContext).inflate(res, parent, false);
}
}
package com.mints.helivideo.video.tx.adapter;
import android.view.View;
import androidx.recyclerview.widget.RecyclerView;
public abstract class AbsViewHolder extends RecyclerView.ViewHolder {
public AbsViewHolder(View itemView) {
super(itemView);
}
}
package com.mints.helivideo.video.tx.adapter
import android.view.View
import android.widget.FrameLayout
import com.airbnb.lottie.LottieAnimationView
import com.airbnb.lottie.LottieComposition
import com.airbnb.lottie.LottieCompositionFactory
import com.airbnb.lottie.LottieDrawable
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.mints.helivideo.R
import com.mints.helivideo.ad.draw.DrawExpressManager
import com.mints.helivideo.ad.express.ExpressAdCallback
import com.mints.helivideo.mvp.model.*
import com.mints.helivideo.utils.UIUtils
import com.mints.helivideo.video.tx.TXVideoBaseView
class TxRecommendVideo2Adapter :
BaseMultiItemQuickAdapter<VideoMultiItemEntity2, BaseViewHolder>() {
private var mCurrentPosition = 0
init {
addItemType(MULTI_ITEM_1, R.layout.item_tx_video)
addItemType(MULTI_ITEM_3, R.layout.item_draw_ad)
}
override fun convert(holder: BaseViewHolder, item: VideoMultiItemEntity2) {
if (holder.itemViewType == MULTI_ITEM_1) {
initVideoHolder(holder, item.video)
} else {
initAdHolder(holder)
}
}
private fun initVideoHolder(holder: BaseViewHolder, item: VedioBean?) {
if (item?.completeStatus == 0) {
holder.setText(R.id.episode_tv, "共" + item.vedioTotal + "集 已完结")
} else {
holder.setText(R.id.episode_tv, "共" + item?.vedioTotal + "集 更新中")
}
//用户名
holder.setText(R.id.username_tv, item?.title)
//标题
holder.setText(R.id.usertitle_tv, "第" + item?.recommendIndex + "集")
//缩略图
Glide.with(context).load(item?.coverImage)
.skipMemoryCache(true)
.diskCacheStrategy(DiskCacheStrategy.ALL).centerCrop()
.into(holder.getView<TXVideoBaseView>(R.id.baseItemView).findViewById(R.id.iv_cover))
if (item?.collect == 0) {
// 未收藏
setCollectImage(holder.getView(R.id.iv_collect))
} else {
// 已收藏
setCancelCollectImage(holder.getView(R.id.iv_collect))
}
// 热度
holder.setText(R.id.tv_collect_num, item?.hot)
holder.getView<View>(R.id.ll_collect).setOnClickListener {
if (item?.collect == 0) {
playCollectAnim(holder.getView(R.id.iv_collect))
} else {
playCancelCollectAnim(holder.getView(R.id.iv_collect))
}
mOnCustomChildClickListener?.onCustomChildClick(it, holder.adapterPosition)
}
holder.getView<View>(R.id.ll_bottom).setOnClickListener {
mOnCustomChildClickListener?.onCustomChildClick(it, holder.adapterPosition)
}
holder.getView<TXVideoBaseView>(R.id.baseItemView)
.setOnVideoEndListener(mOnVideoEndListener)
}
private fun initAdHolder(holder: BaseViewHolder) {
DrawExpressManager.instance.getAdView(object : ExpressAdCallback {
override fun loadSuccess(adView: FrameLayout?) {
adView?.let {
UIUtils.removeFromParent(it)
val fmAd = holder.getView<FrameLayout>(R.id.fl_ad)
fmAd.removeAllViews()
fmAd.addView(it)
}
DrawExpressManager.instance.preLoadAd()
}
override fun renderSuccess(adView: FrameLayout?): Boolean {
return false
}
override fun loadFail() {
}
})
}
override fun onViewDetachedFromWindow(holder: BaseViewHolder) {
super.onViewDetachedFromWindow(holder)
if (holder.itemViewType == MULTI_ITEM_1) {
val tXVideoBaseView = holder.getView<TXVideoBaseView>(R.id.baseItemView)
if (data[mCurrentPosition].itemType == MULTI_ITEM_1 && tXVideoBaseView.player != null) {
if (tXVideoBaseView.player.url != data[mCurrentPosition].video!!.recommendUrl) {
tXVideoBaseView.stopForPlaying()
}
} else {
tXVideoBaseView.stopForPlaying()
}
}
}
override fun onViewRecycled(holder: BaseViewHolder) {
super.onViewRecycled(holder)
if (holder.itemViewType == MULTI_ITEM_1) {
Glide.with(context).clear(holder.getView<View>(R.id.iv_cover))
}
}
private fun setCollectImage(view: LottieAnimationView) {
val lottieDrawable = LottieDrawable()
LottieCompositionFactory.fromAsset(context, "home_collect.json")
.addListener { result: LottieComposition? ->
lottieDrawable.setImagesAssetsFolder("images/")
lottieDrawable.composition = result
}
view.setImageDrawable(lottieDrawable)
}
private fun setCancelCollectImage(view: LottieAnimationView) {
val lottieDrawable = LottieDrawable()
LottieCompositionFactory.fromAsset(context, "home_cancel_collect.json")
.addListener { result: LottieComposition? ->
lottieDrawable.setImagesAssetsFolder("images/")
lottieDrawable.composition = result
}
view.setImageDrawable(lottieDrawable)
}
private fun playCollectAnim(view: LottieAnimationView) {
view.setImageDrawable(null)
val lottieDrawable = LottieDrawable()
LottieCompositionFactory.fromAsset(context, "home_collect.json")
.addListener { result: LottieComposition? ->
lottieDrawable.setImagesAssetsFolder("images/")
lottieDrawable.composition = result
lottieDrawable.loop(false)
lottieDrawable.playAnimation()
}
view.setImageDrawable(lottieDrawable)
}
private fun playCancelCollectAnim(view: LottieAnimationView) {
view.setImageDrawable(null)
val lottieDrawable = LottieDrawable()
LottieCompositionFactory.fromAsset(context, "home_cancel_collect.json")
.addListener { result: LottieComposition? ->
lottieDrawable.setImagesAssetsFolder("images/")
lottieDrawable.composition = result
lottieDrawable.loop(false)
lottieDrawable.playAnimation()
}
view.setImageDrawable(lottieDrawable)
}
fun setCurrentPosition(currentPosition: Int) {
this.mCurrentPosition = currentPosition
}
private var mOnVideoEndListener: TXVideoBaseView.OnVideoEndListener? = null
fun setOnVideoEndListener(onVideoEndListener: TXVideoBaseView.OnVideoEndListener) {
this.mOnVideoEndListener = onVideoEndListener
}
private var mOnCustomChildClickListener: OnCustomChildClickListener? = null
fun setOnCustomChildClickListener(onCustomChildClickListener: OnCustomChildClickListener) {
this.mOnCustomChildClickListener = onCustomChildClickListener
}
interface OnCustomChildClickListener {
fun onCustomChildClick(view: View, position: Int)
}
}
\ No newline at end of file
package com.mints.helivideo.video.tx.adapter
import android.view.View
import android.widget.FrameLayout
import com.airbnb.lottie.LottieAnimationView
import com.airbnb.lottie.LottieComposition
import com.airbnb.lottie.LottieCompositionFactory
import com.airbnb.lottie.LottieDrawable
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.mints.helivideo.R
import com.mints.helivideo.mvp.model.VedioBean
import com.mints.helivideo.ad.draw.DrawExpressManager
import com.mints.helivideo.ad.express.ExpressAdCallback
import com.mints.helivideo.mvp.model.*
import com.mints.helivideo.utils.UIUtils
import com.mints.helivideo.video.tx.TXVideoBaseView
class TxRecommendVideoAdapter :
BaseQuickAdapter<VedioBean, BaseViewHolder>(R.layout.item_tx_video) {
BaseMultiItemQuickAdapter<VideoMultiItemEntity2, BaseViewHolder>() {
override fun convert(holder: BaseViewHolder, item: VedioBean) {
if (item.completeStatus == 0) {
private var mCurrentPosition = 0
init {
addItemType(MULTI_ITEM_1, R.layout.item_tx_video)
addItemType(MULTI_ITEM_3, R.layout.item_draw_ad)
}
override fun convert(holder: BaseViewHolder, item: VideoMultiItemEntity2) {
if (holder.itemViewType == MULTI_ITEM_1) {
initVideoHolder(holder, item.video)
} else {
initAdHolder(holder)
}
}
private fun initVideoHolder(holder: BaseViewHolder, item: VedioBean?) {
if (item?.completeStatus == 0) {
holder.setText(R.id.episode_tv, "共" + item.vedioTotal + "集 已完结")
} else {
holder.setText(R.id.episode_tv, "共" + item.vedioTotal + "集 更新中")
holder.setText(R.id.episode_tv, "共" + item?.vedioTotal + "集 更新中")
}
//用户名
holder.setText(R.id.username_tv, item.title)
holder.setText(R.id.username_tv, item?.title)
//标题
holder.setText(R.id.usertitle_tv, "第" + item.recommendIndex + "集")
holder.setText(R.id.usertitle_tv, "第" + item?.recommendIndex + "集")
//缩略图
Glide.with(context).load(item.coverImage)
Glide.with(context).load(item?.coverImage)
.skipMemoryCache(true)
.diskCacheStrategy(DiskCacheStrategy.ALL).centerCrop()
.into(holder.getView<TXVideoBaseView>(R.id.baseItemView).findViewById(R.id.iv_cover))
if (item.collect == 0) {
if (item?.collect == 0) {
// 未收藏
setCollectImage(holder.getView(R.id.iv_collect))
} else {
......@@ -40,11 +59,10 @@ class TxRecommendVideoAdapter :
setCancelCollectImage(holder.getView(R.id.iv_collect))
}
// 热度
holder.setText(R.id.tv_collect_num, item.hot)
holder.setText(R.id.tv_collect_num, item?.hot)
holder.getView<View>(R.id.ll_collect).setOnClickListener {
if (item.collect == 0) {
if (item?.collect == 0) {
playCollectAnim(holder.getView(R.id.iv_collect))
} else {
playCancelCollectAnim(holder.getView(R.id.iv_collect))
......@@ -57,17 +75,48 @@ class TxRecommendVideoAdapter :
holder.getView<TXVideoBaseView>(R.id.baseItemView)
.setOnVideoEndListener(mOnVideoEndListener)
}
private fun initAdHolder(holder: BaseViewHolder) {
DrawExpressManager.instance.getAdView(object : ExpressAdCallback {
override fun loadSuccess(adView: FrameLayout?) {
adView?.let {
UIUtils.removeFromParent(it)
val fmAd = holder.getView<FrameLayout>(R.id.fl_ad)
fmAd.removeAllViews()
fmAd.addView(it)
}
DrawExpressManager.instance.preLoadAd()
}
override fun renderSuccess(adView: FrameLayout?): Boolean {
return false
}
override fun loadFail() {
}
})
}
override fun onViewDetachedFromWindow(holder: BaseViewHolder) {
super.onViewDetachedFromWindow(holder)
holder.getView<TXVideoBaseView>(R.id.baseItemView).stopForPlaying()
if (holder.itemViewType == MULTI_ITEM_1) {
val tXVideoBaseView = holder.getView<TXVideoBaseView>(R.id.baseItemView)
if (data[mCurrentPosition].itemType == MULTI_ITEM_1 && tXVideoBaseView.player != null) {
if (tXVideoBaseView.player.url != data[mCurrentPosition].video!!.recommendUrl) {
tXVideoBaseView.stopForPlaying()
}
} else {
tXVideoBaseView.stopForPlaying()
}
}
}
override fun onViewRecycled(holder: BaseViewHolder) {
super.onViewRecycled(holder)
Glide.with(context).clear(holder.getView<View>(R.id.iv_cover))
if (holder.itemViewType == MULTI_ITEM_1) {
Glide.with(context).clear(holder.getView<View>(R.id.iv_cover))
}
}
private fun setCollectImage(view: LottieAnimationView) {
......@@ -116,6 +165,10 @@ class TxRecommendVideoAdapter :
view.setImageDrawable(lottieDrawable)
}
fun setCurrentPosition(currentPosition: Int) {
this.mCurrentPosition = currentPosition
}
private var mOnVideoEndListener: TXVideoBaseView.OnVideoEndListener? = null
fun setOnVideoEndListener(onVideoEndListener: TXVideoBaseView.OnVideoEndListener) {
......@@ -131,6 +184,8 @@ class TxRecommendVideoAdapter :
interface OnCustomChildClickListener {
fun onCustomChildClick(view: View, position: Int)
}
}
\ No newline at end of file
......@@ -82,6 +82,15 @@ class TxVideoAdapter : BaseMultiItemQuickAdapter<VideoMultiItemEntity, BaseViewH
vipBtn.visibility = View.GONE
}
val adBtn = holder.getView<View>(R.id.unlock)
vedioBean?.let {
if (it.isRecommendVedio) {
adBtn.visibility = View.GONE
} else {
adBtn.visibility = View.VISIBLE
}
}
vedioBean?.let {
holder.getView<TextView>(R.id.tv_title).text = String.format(
"解锁%s·第%d-%d集",
......@@ -133,29 +142,38 @@ class TxVideoAdapter : BaseMultiItemQuickAdapter<VideoMultiItemEntity, BaseViewH
holder.setText(R.id.title_tv, vedioBean?.title)
//集数
holder.setText(R.id.info_tv, "第" + item?.vedioIndex + "集")
//收藏数量
holder.setText(R.id.zan_num_tv, "" + vedioBean?.hot)
//缩略图
Glide.with(context).load(vedioBean?.coverImage)
.skipMemoryCache(true)
.diskCacheStrategy(DiskCacheStrategy.ALL).centerCrop()
.into(holder.getView<TXVideoBaseView>(R.id.baseItemView).findViewById(R.id.iv_cover))
holder.getView<LinearLayout>(R.id.ll_collect).setOnClickListener {
mOnCustomChildClickListener?.onCustomChildClick(it, holder.adapterPosition)
if (vedioBean?.collect == 0) {
playCollectAnim(holder.getView(R.id.zan_iv))
vedioBean?.let {
if (it.isRecommendVedio) {
holder.getView<LinearLayout>(R.id.ll_collect).visibility = View.GONE
} else {
playCancelCollectAnim(holder.getView(R.id.zan_iv))
}
}
holder.getView<LinearLayout>(R.id.ll_collect).visibility = View.VISIBLE
//收藏数量
holder.setText(R.id.zan_num_tv, "" + it.hot)
if (vedioBean?.collect == 0) {
// 未收藏
setCollectImage(holder.getView(R.id.zan_iv))
} else {
// 已收藏
setCancelCollectImage(holder.getView(R.id.zan_iv))
}
if (vedioBean?.collect == 0) {
// 未收藏
setCollectImage(holder.getView(R.id.zan_iv))
} else {
// 已收藏
setCancelCollectImage(holder.getView(R.id.zan_iv))
holder.getView<LinearLayout>(R.id.ll_collect).setOnClickListener { it2 ->
mOnCustomChildClickListener?.onCustomChildClick(it2, holder.adapterPosition)
if (it.collect == 0) {
playCollectAnim(holder.getView(R.id.zan_iv))
} else {
playCancelCollectAnim(holder.getView(R.id.zan_iv))
}
}
}
}
holder.getView<TXVideoBaseView>(R.id.baseItemView)
......
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black"
android:orientation="vertical">
<com.mints.helivideo.video.tx.SuperShortVideoView
android:id="@+id/super_short_video_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageView
android:id="@+id/close_iv"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginTop="20dp"
android:padding="10dp"
android:src="@mipmap/ic_arrow_white" />
<FrameLayout
android:id="@+id/fm_bottom"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="bottom">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/dp_40"
android:layout_gravity="center"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:background="@drawable/shape_half_trans"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingStart="@dimen/dp_10"
android:paddingEnd="@dimen/dp_10">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:src="@mipmap/ic_video_epsiode" />
<TextView
android:id="@+id/episode_tv"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_weight="1"
android:text="共100集 已完结"
android:textColor="@color/white" />
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:src="@mipmap/ic_arrow_top" />
</LinearLayout>
</FrameLayout>
</FrameLayout>
\ No newline at end of file
......@@ -10,20 +10,23 @@
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:layout_marginLeft="30dp"
android:background="#0f0"
android:layout_marginTop="40dp"
android:layout_marginRight="30dp"
android:layout_marginBottom="40dp">
<com.mints.helivideo.video.tx.TXVideoBaseView
android:id="@+id/baseItemView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageView
android:id="@+id/ic_recommend_quit"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_alignParentRight="true"
android:layout_gravity="right"
android:layout_alignParentEnd="true"
android:layout_gravity="end"
android:layout_marginTop="2dp"
android:layout_marginRight="10dp"
android:layout_marginEnd="10dp"
android:padding="10dp"
android:scaleType="centerCrop"
android:src="@mipmap/ic_quit_yuan" />
......
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