Commit 95e8b401 authored by mengcuiguang's avatar mengcuiguang

优化好兔广告监听

parent bd3f4c28
......@@ -14,6 +14,7 @@ import com.mints.goodmoney.mvp.presenters.HorizChannelPresenter
import com.mints.goodmoney.mvp.views.HorizChannelView
import com.mints.goodmoney.ui.activitys.AwardActivity
import com.mints.goodmoney.ui.fragment.base.BaseFragment
import com.mints.goodmoney.utils.LogUtil
import com.yilan.sdk.player.ylplayer.YLPlayerConfig
import com.yilan.sdk.player.ylplayer.callback.OnPlayerCallBack
import com.yilan.sdk.ui.category.ChannelFragment
......@@ -23,6 +24,8 @@ import net.grandcentrix.tray.AppPreferences
class HorizChannelFragment : BaseFragment(), HorizChannelView, View.OnClickListener {
private val TAG = HorizChannelFragment::class.java.simpleName
private val horizChannelPresenter by lazy { HorizChannelPresenter() }
private val ps by lazy { AppPreferences(context) }
......@@ -79,58 +82,61 @@ class HorizChannelFragment : BaseFragment(), HorizChannelView, View.OnClickListe
val transaction: FragmentTransaction = childFragmentManager.beginTransaction()
if (channelFragment == null) {
// 设置点击的item播放状态,callback返回true标识用户已经处理了event,返回false,标识使用播放器内部逻辑处理event。
YLPlayerConfig.config().registerPlayerCallBack(object : OnPlayerCallBack {
override fun onStart(p0: String?, videoid: String, p2: String?) {
// 防止网络异常时, 第一次加载倒计时红包
if (isFirstLoadVideo) {
isFirstLoadVideo = false
initTimeView()
} else {
resumeDownloadTime(videoid)
}
}
channelFragment = ChannelFragment()
transaction.add(R.id.yilan_fragment_frame_container, channelFragment!!, ChannelFragment::class.java.simpleName)
} else {
transaction.show(channelFragment!!)
}
transaction.commitAllowingStateLoss()
override fun onPause(p0: String?, p1: String?, p2: String?) {
pauseDownloadTime()
}
}
private fun registerPlayerCallBack() {
// 设置点击的item播放状态,callback返回true标识用户已经处理了event,返回false,标识使用播放器内部逻辑处理event。
YLPlayerConfig.config().registerPlayerCallBack(object : OnPlayerCallBack {
override fun onResume(p0: String?, videoid: String, p2: String?) {
override fun onStart(p0: String?, videoid: String, p2: String?) {
// 防止网络异常时, 第一次加载倒计时红包
if (isFirstLoadVideo) {
isFirstLoadVideo = false
initTimeView()
} else {
resumeDownloadTime(videoid)
}
}
override fun onComplete(p0: String?, videoid: String, p2: String?) {
override fun onPause(p0: String?, p1: String?, p2: String?) {
LogUtil.d(TAG, "onPause pager:${p0}")
pauseDownloadTime()
}
}
override fun onResume(p0: String?, videoid: String, p2: String?) {
resumeDownloadTime(videoid)
}
override fun onLoopComplete(pager: String?, videoID: String, taskID: String?, num: Int) {
addVedioIdList(videoID)
pauseDownloadTime()
}
override fun onComplete(p0: String?, videoid: String, p2: String?) {
override fun onStuckStart(p0: String?, p1: String?, p2: String?) {
}
}
override fun onStuckEnd(p0: String?, p1: String?, p2: String?) {
}
override fun onLoopComplete(pager: String?, videoID: String, taskID: String?, num: Int) {
addVedioIdList(videoID)
pauseDownloadTime()
}
override fun onError(p0: String?, p1: String?, p2: String?) {
pauseDownloadTime()
}
override fun onStuckStart(p0: String?, p1: String?, p2: String?) {
}
override fun onStop(p0: String?, p1: String?, p2: String?) {
pauseDownloadTime()
}
})
override fun onStuckEnd(p0: String?, p1: String?, p2: String?) {
}
channelFragment = ChannelFragment()
transaction.add(R.id.yilan_fragment_frame_container, channelFragment!!, ChannelFragment::class.java.simpleName)
} else {
transaction.show(channelFragment!!)
}
transaction.commitAllowingStateLoss()
override fun onError(p0: String?, p1: String?, p2: String?) {
pauseDownloadTime()
}
override fun onStop(p0: String?, p1: String?, p2: String?) {
pauseDownloadTime()
}
})
}
override fun getContentViewLayoutID() = R.layout.fragment_horiz_channel
......@@ -174,13 +180,16 @@ class HorizChannelFragment : BaseFragment(), HorizChannelView, View.OnClickListe
// 调用金币视频信息接口
horizChannelPresenter.getSmallHomeVedioBaseMsg()
registerPlayerCallBack()
channelFragment?.onResume()
}
}
override fun onPause() {
super.onPause()
if (AppConfig.fragmentClickFlag == Constant.FRAGMENT_CLICK_CHANNEL) {
YLPlayerConfig.config().unRegisterPlayerCallback()
}
channelFragment?.onPause()
// pauseDownloadTime()
}
......@@ -257,7 +266,6 @@ class HorizChannelFragment : BaseFragment(), HorizChannelView, View.OnClickListe
cdvvYilanTime?.setCountDownVedioListener(null)
horizChannelPresenter.detachView()
YLPlayerConfig.config().unRegisterPlayerCallback()
}
}
\ No newline at end of file
......@@ -104,6 +104,7 @@ class MainFragment : BaseFragment(), HomeView, View.OnClickListener {
homePresenter.userLogin()
}
registerPlayerCallBack()
littleVideoFragment?.onResume()
}
}
......@@ -116,7 +117,9 @@ class MainFragment : BaseFragment(), HomeView, View.OnClickListener {
override fun onPause() {
super.onPause()
if (AppConfig.fragmentClickFlag == Constant.FRAGMENT_CLICK_MAIN) {
YLPlayerConfig.config().unRegisterPlayerCallback()
}
littleVideoFragment?.onPause()
}
......@@ -129,7 +132,6 @@ class MainFragment : BaseFragment(), HomeView, View.OnClickListener {
super.onDestroy()
cdvvYilanTime?.setCountDownVedioListener(null)
YLPlayerConfig.config().unRegisterPlayerCallback()
homePresenter.detachView()
}
......@@ -222,8 +224,17 @@ class MainFragment : BaseFragment(), HomeView, View.OnClickListener {
if (littleVideoFragment == null) {
littleVideoFragment = YLLittleVideoFragment.newInstance()
transaction.add(R.id.yilan_fragment_frame_container, littleVideoFragment!!, YLLittleVideoFragment::class.java.simpleName)
YLPlayerConfig.config().registerPlayerCallBack(object : OnPlayerCallBack {
override fun onStart(p0: String?, videoid: String, p2: String?) {
} else {
transaction.show(littleVideoFragment!!)
}
transaction.commitAllowingStateLoss()
}
private fun registerPlayerCallBack() {
YLPlayerConfig.config().registerPlayerCallBack(object : OnPlayerCallBack {
override fun onStart(pager: String, videoid: String, p2: String?) {
if (TextUtils.equals(YLPlayerConfig.PAGE_LITTLE, "PAGE_LITTLE")) {
// 防止网络异常时, 第一次加载倒计时红包
if (isFirstLoadVedio) {
isFirstLoadVedio = false
......@@ -233,44 +244,56 @@ class MainFragment : BaseFragment(), HomeView, View.OnClickListener {
}
LogUtil.d(TAG, "onStart videoid:${videoid}")
}
}
override fun onPause(p0: String?, p1: String?, p2: String?) {
override fun onPause(pager: String, p1: String?, p2: String?) {
LogUtil.d(TAG, "onPause pager:${pager}")
if (TextUtils.equals(YLPlayerConfig.PAGE_LITTLE, "PAGE_LITTLE")) {
pauseDownloadTime()
}
}
override fun onResume(pager: String, videoid: String, p2: String?) {
if (TextUtils.equals(YLPlayerConfig.PAGE_LITTLE, "PAGE_LITTLE")) {
override fun onResume(p0: String?, videoid: String, p2: String?) {
resumeDownloadTime(videoid)
}
}
override fun onComplete(p0: String?, videoid: String, p2: String?) {
override fun onComplete(pager: String, videoid: String, p2: String?) {
}
override fun onLoopComplete(pager: String?, videoID: String, taskID: String?, num: Int) {
if (TextUtils.equals(YLPlayerConfig.PAGE_LITTLE, "PAGE_LITTLE")) {
}
override fun onLoopComplete(pager: String?, videoID: String, taskID: String?, num: Int) {
addVedioIdList(videoID)
pauseDownloadTime()
LogUtil.d(TAG, "onLoopComplete pager:${pager} videoID:${videoID} taskID:${taskID} num:${num}")
}
}
override fun onStuckStart(p0: String?, p1: String?, p2: String?) {
}
override fun onStuckStart(pager: String, p1: String?, p2: String?) {
}
override fun onStuckEnd(p0: String?, p1: String?, p2: String?) {
}
override fun onStuckEnd(pager: String, p1: String?, p2: String?) {
}
override fun onError(pager: String, p1: String?, p2: String?) {
if (TextUtils.equals(YLPlayerConfig.PAGE_LITTLE, "PAGE_LITTLE")) {
override fun onError(p0: String?, p1: String?, p2: String?) {
pauseDownloadTime()
}
}
override fun onStop(pager: String, p1: String?, p2: String?) {
if (TextUtils.equals(YLPlayerConfig.PAGE_LITTLE, "PAGE_LITTLE")) {
override fun onStop(p0: String?, p1: String?, p2: String?) {
pauseDownloadTime()
}
})
} else {
transaction.show(littleVideoFragment!!)
}
transaction.commitAllowingStateLoss()
}
})
}
/**
......
......@@ -86,6 +86,13 @@ class MoneyFragment : BaseFragment(), XTabLayout.OnTabSelectedListener {
vpFragmentMoney.currentItem = if (curPosition == 1) 0 else curPosition
return
}
// if (tab.position == 1) {
// vpFragmentMoney.setCanScroll(false)
// } else {
// vpFragmentMoney.setCanScroll(true)
// }
curPosition = tab.position
}
}
\ No newline at end of file
package com.mints.goodmoney.ui.widgets;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import androidx.viewpager.widget.ViewPager;
public class MyViewPager extends ViewPager
{
public MyViewPager(Context context)
{
super(context);
}
public MyViewPager(Context context, AttributeSet attrs)
{
super(context, attrs);
// TODO Auto-generated constructor stub
}
private boolean isCanScroll = true;
public void setCanScroll(boolean isCanScroll)
{
this.isCanScroll = isCanScroll;
}
@Override
public boolean onTouchEvent(MotionEvent arg0)
{
if (isCanScroll)
{
return super.onTouchEvent(arg0);
}
else
{
return false;
}
}
@Override
public boolean onInterceptTouchEvent(MotionEvent arg0)
{
if (isCanScroll)
{
return super.onInterceptTouchEvent(arg0);
}
else
{
return false;
}
}
}
......@@ -10,13 +10,18 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
<TextView
android:id="@+id/ivDhBack"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:src="@mipmap/ic_arrow_back" />
android:gravity="center_vertical"
android:layout_marginLeft="20dp"
android:text="返回"
android:drawablePadding="2dp"
android:textColor="@color/black"
android:textSize="16sp"
android:drawableLeft="@mipmap/ic_arrow_back" />
<TextView
android:id="@+id/tvDhRefresh"
......@@ -28,6 +33,7 @@
android:paddingRight="30dp"
android:text="重新加载"
android:textColor="@color/black"
android:layout_marginLeft="20dp"
android:textSize="16sp" />
</RelativeLayout>
......
......@@ -20,7 +20,7 @@
app:xTabIndicatorWidth="10dp"
app:xTabTextSize="15sp" />
<androidx.viewpager.widget.ViewPager
<com.mints.goodmoney.ui.widgets.MyViewPager
android:id="@+id/vpFragmentMoney"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
......
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