Commit b8430428 authored by jyx's avatar jyx

添加首页信息流广告

parent 0705b50c
......@@ -66,6 +66,7 @@ android {
buildConfigField "String", "GROMORE_VIDEO_CODE", GROMORE_VIDEO_CODE
buildConfigField "String", "GROMORE_DRAW_CODE", GROMORE_DRAW_CODE
buildConfigField "String", "GROMORE_EXPRESS_CODE", GROMORE_EXPRESS_CODE
buildConfigField "String", "GROMORE_MAIN_EXPRESS_CODE", GROMORE_MAIN_EXPRESS_CODE
buildConfigField "String", "GROMORE_BANNER_CODE", GROMORE_BANNER_CODE
buildConfigField "String", "WEIXIN_APP_PAY_ID", WEIXIN_APP_PAY_ID
......@@ -88,6 +89,7 @@ android {
buildConfigField "String", "GROMORE_VIDEO_CODE", GROMORE_VIDEO_CODE
buildConfigField "String", "GROMORE_DRAW_CODE", GROMORE_DRAW_CODE
buildConfigField "String", "GROMORE_EXPRESS_CODE", GROMORE_EXPRESS_CODE
buildConfigField "String", "GROMORE_MAIN_EXPRESS_CODE", GROMORE_MAIN_EXPRESS_CODE
buildConfigField "String", "GROMORE_BANNER_CODE", GROMORE_BANNER_CODE
buildConfigField "String", "WEIXIN_APP_PAY_ID", WEIXIN_APP_PAY_ID
......
package com.mints.helivideo.mvp.model
import android.widget.FrameLayout
import com.chad.library.adapter.base.entity.MultiItemEntity
import com.mints.helivideo.video.tx.VideoModel
......@@ -18,3 +19,9 @@ data class VideoMultiItemEntity2(
var video: VedioBean?,
var videoModel: VideoModel?
) : MultiItemEntity, java.io.Serializable
data class VideoMultiItemEntity3(
override val itemType: Int,
var video: VedioBean?,
var adView: FrameLayout?
) : MultiItemEntity, java.io.Serializable
package com.mints.helivideo.ui.adapter
import com.chad.library.adapter.base.BaseQuickAdapter
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.VedioBean
import com.mints.helivideo.mvp.model.*
import com.mints.helivideo.utils.UIUtils
class NewHotStyleAdapter : BaseQuickAdapter<VedioBean, BaseViewHolder>(R.layout.item_hot_style) {
override fun convert(holder: BaseViewHolder, item: VedioBean) {
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,
......@@ -27,7 +56,6 @@ class NewHotStyleAdapter : BaseQuickAdapter<VedioBean, BaseViewHolder>(R.layout.
holder.getView(R.id.ivVedioItem)
)
}
}
}
\ No newline at end of file
......@@ -2,24 +2,23 @@ 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.GridLayoutManager
import com.mints.wisdomclean.ui.adapter.HotStyleAdapter
import com.mints.helivideo.R
import com.mints.helivideo.ad.express.ExpressAdCallback
import com.mints.helivideo.ad.express.MainExpressManager
import com.mints.helivideo.common.Constant
import com.mints.helivideo.manager.LocalVedioManager
import com.mints.helivideo.mvp.model.*
import com.mints.helivideo.mvp.presenters.PicContentPresenter
import com.mints.helivideo.mvp.views.PicContentView
import com.mints.helivideo.ui.adapter.NewHotStyleAdapter
import com.mints.helivideo.ui.fragment.base.LazyLoadBaseFragment
import com.scwang.smartrefresh.layout.api.RefreshLayout
import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener
import com.mints.helivideo.common.AppConfig
import com.mints.helivideo.ui.adapter.NewHotStyle2Adapter
import com.mints.helivideo.ui.widgets.MyGridLayoutManager
import kotlinx.android.synthetic.main.fragment_movie.*
import java.util.*
class MovieFragment : LazyLoadBaseFragment(), PicContentView, OnLoadMoreListener {
......@@ -43,9 +42,8 @@ class MovieFragment : LazyLoadBaseFragment(), PicContentView, OnLoadMoreListener
private val picContentPresenter by lazy { PicContentPresenter() }
private var hotPage = 1 // 分页
private val hotList: ArrayList<VedioBean> = arrayListOf()
private lateinit var hotStyleAdapter: NewHotStyleAdapter
// private lateinit var hotStyleAdapter: HotStyleAdapter
private lateinit var hotStyleAdapter: NewHotStyle2Adapter
override fun getContentViewLayoutID() = R.layout.fragment_movie
......@@ -75,8 +73,10 @@ class MovieFragment : LazyLoadBaseFragment(), PicContentView, OnLoadMoreListener
if (AppConfig.fragmentClickFlag == Constant.FRAGMENT_CLICK_ONE) {
println("mcg _______")
hotPage = 1
// hotList.clear()
srlMainPage.resetNoMoreData()
MainExpressManager.instance.destroy()
loadAd()
picContentPresenter.getHomePageImageList(mType, hotPage, Constant.PAGE_SIZE)
}
......@@ -84,6 +84,7 @@ class MovieFragment : LazyLoadBaseFragment(), PicContentView, OnLoadMoreListener
override fun onLoadMore(refreshLayout: RefreshLayout) {
hotPage = ++hotPage
loadAd()
picContentPresenter.getHomePageImageList(mType, hotPage, Constant.PAGE_SIZE)
}
......@@ -94,19 +95,16 @@ class MovieFragment : LazyLoadBaseFragment(), PicContentView, OnLoadMoreListener
}
if (::hotStyleAdapter.isInitialized) {
// hotList.addAll(data.list)
if (hotPage == 1) {
srlMainPage.finishRefresh(true)
hotStyleAdapter.setNewInstance(data.list)
// hotStyleAdapter.notifyDataSetChanged()
hotStyleAdapter.setNewInstance(getAdapterData(data.list))
} else {
if (data.list.size < Constant.PAGE_SIZE) {
srlMainPage.finishLoadMoreWithNoMoreData()
} else {
srlMainPage.finishLoadMore()
}
// hotStyleAdapter.notifyItemChanged(data.list.size)
hotStyleAdapter.addData(data.list)
hotStyleAdapter.addData(getAdapterData(data.list))
}
}
}
......@@ -117,35 +115,19 @@ class MovieFragment : LazyLoadBaseFragment(), PicContentView, OnLoadMoreListener
private fun initView() {
val gridLayoutManager = MyGridLayoutManager(context, 3)
rv_pic_list.layoutManager = gridLayoutManager
hotStyleAdapter = NewHotStyleAdapter()
hotStyleAdapter = NewHotStyle2Adapter()
rv_pic_list.adapter = hotStyleAdapter
val emptyView =
LayoutInflater.from(requireContext()).inflate(R.layout.item_empty_data, null)
hotStyleAdapter.setEmptyView(emptyView)
// hotStyleAdapter.setNewInstance(hotList)
hotStyleAdapter.setOnItemClickListener { adapter, view, position ->
// if (hotList.size > 0) {
if (hotStyleAdapter.data[position].itemType == MULTI_ITEM_1) {
LocalVedioManager.startVedioDetailActivityForType(
requireActivity(),
hotStyleAdapter.data.get(position)
hotStyleAdapter.data[position].video
)
// }
}
}
// val gridLayoutManager = GridLayoutManager(context, 3)
// rv_pic_list.layoutManager = gridLayoutManager
// hotStyleAdapter = HotStyleAdapter(requireContext(), hotList)
// rv_pic_list.adapter = hotStyleAdapter
// hotStyleAdapter.setOnItemClickListener(object : HotStyleAdapter.OnItemClickListener {
// override fun onItemClick(position: Int) {
// if (hotList!=null&&hotList!!.size > 0) {
// LocalVedioManager.startVedioDetailActivityForType(
// requireActivity(),
// hotList!!.get(position)
// )
// }
// }
// })
}
private fun initListener() {
......@@ -153,4 +135,51 @@ class MovieFragment : LazyLoadBaseFragment(), PicContentView, OnLoadMoreListener
srlMainPage.setOnLoadMoreListener(this)
}
private fun getAdapterData(list: List<VedioBean>): MutableList<VideoMultiItemEntity3> {
val data = mutableListOf<VideoMultiItemEntity3>()
for (item in list) {
data.add(VideoMultiItemEntity3(MULTI_ITEM_1, item, null))
}
return data
}
private fun loadAd() {
MainExpressManager.instance.loadAd(object : ExpressAdCallback {
override fun loadSuccess(adView: FrameLayout?) {
}
override fun renderSuccess(adView: FrameLayout?): Boolean {
adView?.let { addAdView(it) }
return false
}
override fun loadFail() {
}
})
}
private fun addAdView(adView: FrameLayout) {
// 默认每各4个加1个
var insertIndex = 3
val itemEntity3s = hotStyleAdapter.data
for (i in 0 until itemEntity3s.size) {
if (itemEntity3s[i].itemType == MULTI_ITEM_3) {
insertIndex += 4
}
}
if (insertIndex >= itemEntity3s.size - 1) {
insertIndex = itemEntity3s.size - 1
}
val data = VideoMultiItemEntity3(MULTI_ITEM_3, null, adView)
hotStyleAdapter.addData(insertIndex, data)
}
override fun onDestroyView() {
super.onDestroyView()
MainExpressManager.instance.destroy()
}
}
\ No newline at end of file
......@@ -291,6 +291,10 @@ public class UIUtils {
return getScreenWidth(context) - dp2px(60);
}
public static float getAdWidth3(Context context) {
return (getScreenWidth(context) - dp2px(50)) / 3f;
}
public static float getAdWidth2(Context context) {
return getScreenWidth(context) - dp2px(30);
}
......
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/draw_view"
android:layout_width="match_parent"
android:layout_height="192dp">
<com.mints.helivideo.ui.widgets.RoundRectLayout
android:id="@+id/fl_ad"
android:layout_width="match_parent"
android:layout_height="192dp" />
</FrameLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/rlVedioItemRoot"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="192dp"
android:layout_marginTop="4dp"
android:layout_marginBottom="6dp"
android:orientation="vertical"
......
......@@ -47,5 +47,6 @@ GROMORE_APP_ID="5412556"
GROMORE_SPLASH_CODE="102398740"
GROMORE_VIDEO_CODE="102398300"
GROMORE_EXPRESS_CODE="102405261"
GROMORE_MAIN_EXPRESS_CODE="102413160"
GROMORE_DRAW_CODE="102405069"
GROMORE_BANNER_CODE="102405532"
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