Commit 338b1c8e authored by jyx's avatar jyx

代码优化

parent b50a7c37
......@@ -52,8 +52,9 @@ class MainExpressManager {
* 2:如果是信息流模板广告,宽度设置为希望的宽度,高度设置为0(0为高度选择自适应参数)
*/
.setImageAcceptedSize(
UIUtils.getAdWidth3(MintsApplication.getContext()).toInt(),
UIUtils.dip2px(MintsApplication.getContext(), 192f)
UIUtils.getAdWidth2(MintsApplication.getContext()).toInt(),
// UIUtils.dip2px(MintsApplication.getContext(), 192f)
0
)
.setAdCount(2)//请求广告数量为1到3条 (优先采用平台配置的数量)
.build()
......@@ -173,6 +174,7 @@ class MainExpressManager {
for (ttFeedAd in mTTFeedAdList) {
ttFeedAd.destroy()
}
mTTFeedAdList.clear()
}
// private fun getSmallAdView(parent: ViewGroup?): View? {
......
......@@ -22,6 +22,6 @@ data class VideoMultiItemEntity2(
data class VideoMultiItemEntity3(
override val itemType: Int,
var video: VedioBean?,
var videos: List<VedioBean>?,
var adView: FrameLayout?
) : MultiItemEntity, java.io.Serializable
package com.mints.helivideo.ui.adapter
import android.widget.FrameLayout
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.mints.library.utils.GlideUtils
import com.mints.helivideo.R
import com.mints.helivideo.mvp.model.*
import com.mints.helivideo.utils.UIUtils
class NewHotStyle2Adapter :
BaseMultiItemQuickAdapter<VideoMultiItemEntity3, BaseViewHolder>() {
init {
addItemType(MULTI_ITEM_1, R.layout.item_hot_style)
addItemType(MULTI_ITEM_3, R.layout.item_express_ad)
}
override fun convert(holder: BaseViewHolder, item: VideoMultiItemEntity3) {
when (holder.itemViewType) {
MULTI_ITEM_1 -> {
initHolder(holder, item.video)
}
MULTI_ITEM_3 -> {
initAdHolder(holder, item.adView)
}
}
}
private fun initAdHolder(holder: BaseViewHolder, adView: FrameLayout?) {
adView?.let {
UIUtils.removeFromParent(it)
val fmAd = holder.getView<FrameLayout>(R.id.fl_ad)
fmAd.removeAllViews()
fmAd.addView(it)
}
}
private fun initHolder(holder: BaseViewHolder, item: VedioBean?) {
item?.let {
holder.setText(
R.id.tvVedioItemCount,
"${if (it.completeStatus == 0) "已完结" else "更新至${it.vedioTotal}"}"
)
holder.setText(
R.id.tvVedioItemTitle,
"${it.title}"
)
holder.setText(
R.id.tvVedioItemText,
"${it.vedioDesc}"
)
GlideUtils.loadImageViewGifForCenterCrop(
context,
it.coverImage,
holder.getView(R.id.ivVedioItem)
)
}
}
}
\ No newline at end of file
package com.mints.helivideo.ui.adapter
import android.view.View
import android.widget.FrameLayout
import android.widget.TextView
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.mints.library.utils.GlideUtils
import com.mints.helivideo.R
import com.mints.helivideo.mvp.model.*
import com.mints.helivideo.utils.UIUtils
class NewHotStyleAdapter :
BaseMultiItemQuickAdapter<VideoMultiItemEntity3, BaseViewHolder>() {
init {
addItemType(MULTI_ITEM_1, R.layout.item_hot_style_root)
addItemType(MULTI_ITEM_3, R.layout.item_express_ad)
}
override fun convert(holder: BaseViewHolder, item: VideoMultiItemEntity3) {
when (holder.itemViewType) {
MULTI_ITEM_1 -> {
initHolder(holder, item.videos)
}
MULTI_ITEM_3 -> {
initAdHolder(holder, item.adView)
}
}
}
private fun initAdHolder(holder: BaseViewHolder, adView: FrameLayout?) {
adView?.let {
UIUtils.removeFromParent(it)
val fmAd = holder.getView<FrameLayout>(R.id.fl_ad)
fmAd.removeAllViews()
fmAd.addView(it)
}
}
private fun initHolder(holder: BaseViewHolder, item: List<VedioBean>?) {
item?.let {
if (it.isEmpty()) {
holder.getView<View>(R.id.item1).visibility = View.INVISIBLE
holder.getView<View>(R.id.item2).visibility = View.INVISIBLE
holder.getView<View>(R.id.item3).visibility = View.INVISIBLE
return
}
holder.getView<View>(R.id.item1).visibility = View.VISIBLE
holder.getView<View>(R.id.item1)
.findViewById<TextView>(R.id.tvVedioItemCount)
.text = "${if (it[0].completeStatus == 0) "已完结" else "更新至${it[0].vedioTotal}"}"
holder.getView<View>(R.id.item1)
.findViewById<TextView>(R.id.tvVedioItemTitle)
.text = "${it[0].title}"
holder.getView<View>(R.id.item1)
.findViewById<TextView>(R.id.tvVedioItemText)
.text = "${it[0].vedioDesc}"
GlideUtils.loadImageViewGifForCenterCrop(
context,
it[0].coverImage,
holder.getView<View>(R.id.item1)
.findViewById(R.id.ivVedioItem)
)
holder.getView<View>(R.id.item1).setOnClickListener { it1 ->
mOnCustomChildClickListener?.onCustomChildClick(it1, it[0])
}
if (it.size < 2) {
holder.getView<View>(R.id.item2).visibility = View.INVISIBLE
holder.getView<View>(R.id.item3).visibility = View.INVISIBLE
return
}
holder.getView<View>(R.id.item2).visibility = View.VISIBLE
holder.getView<View>(R.id.item2)
.findViewById<TextView>(R.id.tvVedioItemCount)
.text = "${if (it[1].completeStatus == 0) "已完结" else "更新至${it[1].vedioTotal}"}"
holder.getView<View>(R.id.item2)
.findViewById<TextView>(R.id.tvVedioItemTitle)
.text = "${it[1].title}"
holder.getView<View>(R.id.item2)
.findViewById<TextView>(R.id.tvVedioItemText)
.text = "${it[1].vedioDesc}"
GlideUtils.loadImageViewGifForCenterCrop(
context,
it[1].coverImage,
holder.getView<View>(R.id.item2)
.findViewById(R.id.ivVedioItem)
)
holder.getView<View>(R.id.item2).setOnClickListener { it1 ->
mOnCustomChildClickListener?.onCustomChildClick(it1, it[1])
}
if (it.size < 3) {
holder.getView<View>(R.id.item3).visibility = View.INVISIBLE
return
}
holder.getView<View>(R.id.item3).visibility = View.VISIBLE
holder.getView<View>(R.id.item3)
.findViewById<TextView>(R.id.tvVedioItemCount)
.text = "${if (it[2].completeStatus == 0) "已完结" else "更新至${it[2].vedioTotal}"}"
holder.getView<View>(R.id.item3)
.findViewById<TextView>(R.id.tvVedioItemTitle)
.text = "${it[2].title}"
holder.getView<View>(R.id.item3)
.findViewById<TextView>(R.id.tvVedioItemText)
.text = "${it[2].vedioDesc}"
GlideUtils.loadImageViewGifForCenterCrop(
context,
it[2].coverImage,
holder.getView<View>(R.id.item3)
.findViewById(R.id.ivVedioItem)
)
holder.getView<View>(R.id.item3).setOnClickListener { it1 ->
mOnCustomChildClickListener?.onCustomChildClick(it1, it[2])
}
// for (vedio in it) {
// val itemView =
// LayoutInflater.from(context).inflate(R.layout.item_hot_style, null)
//
// itemView.findViewById<TextView>(R.id.tvVedioItemCount).text =
// "${if (vedio.completeStatus == 0) "已完结" else "更新至${vedio.vedioTotal}集"}"
// itemView.findViewById<TextView>(R.id.tvVedioItemTitle).text = "${vedio.title}"
// itemView.findViewById<TextView>(R.id.tvVedioItemText).text =
// "${vedio.vedioDesc}"
// GlideUtils.loadImageViewGifForCenterCrop(
// context,
// vedio.coverImage,
// itemView.findViewById(R.id.ivVedioItem)
// )
// mOnCustomChildClickListener?.onCustomChildClick(itemView, vedio)
// val layoutParams = LinearLayout.LayoutParams(
// LinearLayout.LayoutParams.MATCH_PARENT,
// LinearLayout.LayoutParams.MATCH_PARENT
// )
// layoutParams.weight = 1f
// itemView.layoutParams = layoutParams
// rootView.addView(itemView)
// }
}
// item?.let {
// holder.setText(
// R.id.tvVedioItemCount,
// "${if (it.completeStatus == 0) "已完结" else "更新至${it.vedioTotal}集"}"
// )
// holder.setText(
// R.id.tvVedioItemTitle,
// "${it.title}"
// )
// holder.setText(
// R.id.tvVedioItemText,
// "${it.vedioDesc}"
// )
// GlideUtils.loadImageViewGifForCenterCrop(
// context,
// it.coverImage,
// holder.getView(R.id.ivVedioItem)
// )
// }
}
private var mOnCustomChildClickListener: OnCustomChildClickListener? = null
fun setOnCustomChildClickListener(onCustomChildClickListener: OnCustomChildClickListener) {
this.mOnCustomChildClickListener = onCustomChildClickListener
}
interface OnCustomChildClickListener {
fun onCustomChildClick(view: View, vedioBean: VedioBean)
}
}
\ No newline at end of file
......@@ -2,8 +2,10 @@ package com.mints.helivideo.ui.fragment
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.widget.FrameLayout
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import com.mints.helivideo.R
import com.mints.helivideo.ad.express.ExpressAdCallback
import com.mints.helivideo.ad.express.MainExpressManager
......@@ -17,9 +19,8 @@ import com.scwang.smartrefresh.layout.api.RefreshLayout
import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener
import com.mints.helivideo.common.AppConfig
import com.mints.helivideo.manager.UserManager
import com.mints.helivideo.ui.adapter.NewHotStyle2Adapter
import com.mints.helivideo.ui.widgets.MyGridLayoutManager
import com.mints.helivideo.utils.LogUtil
import com.mints.helivideo.ui.adapter.NewHotStyleAdapter
import com.mints.helivideo.utils.CommonUtils
import kotlinx.android.synthetic.main.fragment_movie.*
class MovieFragment : LazyLoadBaseFragment(), PicContentView, OnLoadMoreListener {
......@@ -45,7 +46,7 @@ class MovieFragment : LazyLoadBaseFragment(), PicContentView, OnLoadMoreListener
private var hotPage = 1 // 分页
private lateinit var hotStyleAdapter: NewHotStyle2Adapter
private lateinit var hotStyleAdapter: NewHotStyleAdapter
override fun getContentViewLayoutID() = R.layout.fragment_movie
......@@ -77,8 +78,7 @@ class MovieFragment : LazyLoadBaseFragment(), PicContentView, OnLoadMoreListener
hotPage = 1
srlMainPage.resetNoMoreData()
MainExpressManager.instance.destroy()
// loadAd()
loadAd()
picContentPresenter.getHomePageImageList(mType, hotPage, Constant.PAGE_SIZE)
}
......@@ -103,7 +103,7 @@ class MovieFragment : LazyLoadBaseFragment(), PicContentView, OnLoadMoreListener
if (data.list.size < Constant.PAGE_SIZE) {
srlMainPage.finishLoadMoreWithNoMoreData()
} else {
// loadAd()
loadAd()
srlMainPage.finishLoadMore()
}
hotStyleAdapter.addData(getAdapterData(data.list))
......@@ -111,25 +111,25 @@ class MovieFragment : LazyLoadBaseFragment(), PicContentView, OnLoadMoreListener
}
}
override fun getHomePageImageListFail() {
}
override fun getHomePageImageListFail() {}
private fun initView() {
val gridLayoutManager = MyGridLayoutManager(context, 3)
rv_pic_list.layoutManager = gridLayoutManager
hotStyleAdapter = NewHotStyle2Adapter()
rv_pic_list.layoutManager = LinearLayoutManager(context)
hotStyleAdapter = NewHotStyleAdapter()
hotStyleAdapter.animationEnable = false
rv_pic_list.adapter = hotStyleAdapter
val emptyView =
LayoutInflater.from(requireContext()).inflate(R.layout.item_empty_data, null)
hotStyleAdapter.setEmptyView(emptyView)
hotStyleAdapter.setOnItemClickListener { adapter, view, position ->
if (hotStyleAdapter.data[position].itemType == MULTI_ITEM_1) {
hotStyleAdapter.setOnCustomChildClickListener(object :
NewHotStyleAdapter.OnCustomChildClickListener {
override fun onCustomChildClick(view: View, vedioBean: VedioBean) {
LocalVedioManager.startVedioDetailActivityForType(
requireActivity(),
hotStyleAdapter.data[position].video
vedioBean
)
}
}
})
}
private fun initListener() {
......@@ -139,8 +139,9 @@ class MovieFragment : LazyLoadBaseFragment(), PicContentView, OnLoadMoreListener
private fun getAdapterData(list: List<VedioBean>): MutableList<VideoMultiItemEntity3> {
val data = mutableListOf<VideoMultiItemEntity3>()
for (item in list) {
data.add(VideoMultiItemEntity3(MULTI_ITEM_1, item, null))
val subList = CommonUtils.getSubList(3, list)
for (itemEntity3s in subList) {
data.add(VideoMultiItemEntity3(MULTI_ITEM_1, itemEntity3s, null))
}
return data
}
......@@ -164,19 +165,21 @@ class MovieFragment : LazyLoadBaseFragment(), PicContentView, OnLoadMoreListener
}
private fun addAdView(adView: FrameLayout) {
// 默认每各4个加1个
var insertIndex = 3
// 默认每各6个加1个
var insertIndex = 2
val itemEntity3s = hotStyleAdapter.data
for (i in itemEntity3s.size - 1 downTo 0) {
if (itemEntity3s[i].itemType == MULTI_ITEM_3) {
insertIndex += 4
val allData = hotStyleAdapter.data
for (i in allData.size - 1 downTo 0) {
if (allData[i].itemType == MULTI_ITEM_3) {
insertIndex += 3
}
}
if (insertIndex >= itemEntity3s.size) {
insertIndex = itemEntity3s.size
if (insertIndex >= allData.size) {
insertIndex = allData.size
}
if (allData[allData.lastIndex].itemType == MULTI_ITEM_3) return
val data = VideoMultiItemEntity3(MULTI_ITEM_3, null, adView)
hotStyleAdapter.addData(insertIndex, data)
}
......
......@@ -2,11 +2,11 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/draw_view"
android:layout_width="match_parent"
android:layout_height="192dp">
android:layout_height="wrap_content">
<com.mints.helivideo.ui.widgets.RoundRectLayout
android:id="@+id/fl_ad"
android:layout_width="match_parent"
android:layout_height="192dp" />
android:layout_height="wrap_content" />
</FrameLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rlVedioItemRoot"
android:layout_width="match_parent"
android:layout_height="192dp"
android:layout_marginTop="4dp"
android:layout_marginBottom="6dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="5dp"
android:paddingRight="5dp">
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginBottom="6dp"
android:orientation="horizontal">
<include
android:id="@+id/item1"
layout="@layout/item_hot_style"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:visibility="invisible" />
<include
android:id="@+id/item2"
layout="@layout/item_hot_style"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:visibility="invisible" />
<include
android:id="@+id/item3"
layout="@layout/item_hot_style"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:visibility="invisible" />
</LinearLayout>
\ 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