Commit 94b1fd50 authored by jyx's avatar jyx

添加信息流广告互换逻辑

parent aada2af8
package com.mints.goodmoney.ad.express
import android.widget.FrameLayout
object PreLoadExpressManager {
// 是否是穿山甲信息流
@Volatile
private var isTTExpressAd = false
@Volatile
private var mAdFrameLayout: FrameLayout? = null
// init {
// YlhPreLoadExpressManager.setListener(this)
// }
fun loadADFrameLayout() {
if (isTTExpressAd) {
TTPreLoadExpressManager.getInstance().loadTtFrameLayout()
} else {
YlhPreLoadExpressManager.loadYlhFrameLayout()
}
}
fun getADFrameLayout(): FrameLayout? {
mAdFrameLayout = if (isTTExpressAd) {
TTPreLoadExpressManager.getInstance().ttFrameLayout
} else {
YlhPreLoadExpressManager.getYlhFrameLayout()
}
isTTExpressAd = !isTTExpressAd
return mAdFrameLayout
}
// override fun onTTAdLoadSuc(adFrameLayout: FrameLayout?) {
// mAdFrameLayout = adFrameLayout
// }
//
// override fun onYlhAdLoadSuc(adFrameLayout: FrameLayout?) {
// mAdFrameLayout = adFrameLayout
// }
}
interface ADLoadSuccessListener {
fun onTTAdLoadSuc(adFrameLayout: FrameLayout?)
fun onYlhAdLoadSuc(adFrameLayout: FrameLayout?)
}
\ No newline at end of file
......@@ -21,19 +21,17 @@ public class TTPreLoadExpressManager {
return _inst;
}
private TTPreLoadExpressManager() {
// init();
}
private void init() {
ttNativeExpressManager = new TTNativeExpressManager();
ttNativeExpressManager.initTTAd(false);
}
public void onDestroy(){
public void onDestroy() {
if (ttNativeExpressManager != null) {
ttNativeExpressManager.onTTAdDestroy();
ttNativeExpressManager = null;
}
}
public FrameLayout getTtFrameLayout() {
return ttFrameLayout;
......
package com.mints.goodmoney.ad.express;
import android.content.Context;
import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.Toast;
import com.mints.goodmoney.MintsApplication;
import com.mints.goodmoney.common.AppConfig;
import com.mints.goodmoney.manager.TTNativeExpressManager;
import com.mints.goodmoney.manager.TtCsjAdManager;
import com.mints.goodmoney.manager.YlhAdManager;
import com.mints.goodmoney.utils.LogUtil;
import com.qq.e.ads.cfg.VideoOption;
import com.qq.e.ads.nativ.ADSize;
import com.qq.e.ads.nativ.NativeExpressAD;
import com.qq.e.ads.nativ.NativeExpressADView;
import com.qq.e.comm.constants.AdPatternType;
import com.qq.e.comm.util.AdError;
import java.util.List;
/**
* 优量汇信息流
*/
public class YlhPreLoadExpressManager implements NativeExpressAD.NativeExpressADListener {
private static YlhPreLoadExpressManager _inst;
private NativeExpressAD nativeExpressAD;
private NativeExpressADView nativeExpressADView;
public static YlhPreLoadExpressManager getInstance() {
if (_inst == null) {
_inst = new YlhPreLoadExpressManager();
}
return _inst;
}
private YlhPreLoadExpressManager() {
init();
}
private void init() {
}
public void onDestroy() {
// 使用完了每一个NativeExpressADView之后都要释放掉资源
if (nativeExpressADView != null) {
nativeExpressADView.destroy();
}
}
private void refreshAd() {
try {
nativeExpressAD = new NativeExpressAD(MintsApplication.getContext(), getMyADSize(), YlhAdManager.INSTANCE.YLH_AD_APPID, YlhAdManager.INSTANCE.getYLH_AD_NATIVEEXPRESS_AWARD(), this); // 这里的Context必须为Activity
nativeExpressAD.loadAD(1);
} catch (NumberFormatException e) {
LogUtil.d("YlhPreLoadExpressManager", "ad size invalid.");
}
}
private ADSize getMyADSize() {
int w = ADSize.FULL_WIDTH;
int h = ADSize.AUTO_HEIGHT;
return new ADSize(w, h);
}
@Override
public void onADClicked(NativeExpressADView nativeExpressADView) {
}
@Override
public void onADCloseOverlay(NativeExpressADView nativeExpressADView) {
}
@Override
public void onADClosed(NativeExpressADView nativeExpressADView) {
}
@Override
public void onADExposure(NativeExpressADView nativeExpressADView) {
}
@Override
public void onADLeftApplication(NativeExpressADView nativeExpressADView) {
}
@Override
public void onADLoaded(List<NativeExpressADView> adList) {
// 释放前一个展示的NativeExpressADView的资源
if (nativeExpressADView != null) {
nativeExpressADView.destroy();
}
nativeExpressADView = adList.get(0);
// 广告可见才会产生曝光,否则将无法产生收益。
// container.addView(nativeExpressADView);
nativeExpressADView.render();
}
@Override
public void onADOpenOverlay(NativeExpressADView nativeExpressADView) {
}
@Override
public void onRenderFail(NativeExpressADView nativeExpressADView) {
}
@Override
public void onRenderSuccess(NativeExpressADView nativeExpressADView) {
}
@Override
public void onNoAD(AdError adError) {
}
}
package com.mints.goodmoney.ad.express
import android.widget.FrameLayout
import com.mints.goodmoney.MintsApplication
import com.mints.goodmoney.manager.YlhAdManager
import com.mints.goodmoney.utils.LogUtil
import com.qq.e.ads.nativ.ADSize
import com.qq.e.ads.nativ.NativeExpressAD
import com.qq.e.ads.nativ.NativeExpressADView
import com.qq.e.comm.util.AdError
object YlhPreLoadExpressManager {
private var ylhFrameLayout: FrameLayout? = null
private var nativeExpressAD: NativeExpressAD? = null
private var nativeExpressADView: NativeExpressADView? = null
// private var mADLoadSuccessListener: ADLoadSuccessListener? = null
//
// fun setListener(adLoadSuccessListener: ADLoadSuccessListener) {
// mADLoadSuccessListener = adLoadSuccessListener
// }
fun getYlhFrameLayout(): FrameLayout? {
return ylhFrameLayout
}
fun loadYlhFrameLayout() {
val context = MintsApplication.getContext()
try {
ylhFrameLayout = FrameLayout(context)
nativeExpressAD = NativeExpressAD(MintsApplication.getContext(), ADSize(320, ADSize.AUTO_HEIGHT), YlhAdManager.YLH_AD_NATIVEEXPRESS_AWARD, object : NativeExpressAD.NativeExpressADListener {
override fun onNoAD(p0: AdError?) {
}
override fun onADClicked(p0: NativeExpressADView?) {
}
override fun onADCloseOverlay(p0: NativeExpressADView?) {
}
override fun onADClosed(p0: NativeExpressADView?) {
}
override fun onADExposure(p0: NativeExpressADView?) {
}
override fun onADLeftApplication(p0: NativeExpressADView?) {
}
override fun onADLoaded(p0: MutableList<NativeExpressADView>?) {
// 释放前一个展示的NativeExpressADView的资源
nativeExpressADView?.destroy()
nativeExpressADView = p0?.get(0)
if (ylhFrameLayout!!.childCount > 0) {
ylhFrameLayout!!.removeAllViews()
}
// val frameLayout = FrameLayout(context)
// mADLoadSuccessListener?.onYlhAdLoadSuc(frameLayout)
// 广告可见才会产生曝光,否则将无法产生收益。
ylhFrameLayout!!.addView(nativeExpressADView)
nativeExpressADView!!.render()
}
override fun onADOpenOverlay(p0: NativeExpressADView?) {
}
override fun onRenderFail(p0: NativeExpressADView?) {
}
override fun onRenderSuccess(p0: NativeExpressADView?) {
}
})
nativeExpressAD?.loadAD(1)
} catch (e: Exception) {
e.printStackTrace()
}
}
/**
* 在页面销毁时调用 destroy
*/
fun onDestroy() {
// 使用完了每一个NativeExpressADView之后都要释放掉资源
nativeExpressADView?.destroy()
}
}
\ No newline at end of file
......@@ -5,11 +5,13 @@ import android.text.TextUtils
import android.view.KeyEvent
import android.view.View
import com.mints.goodmoney.R
import com.mints.goodmoney.ad.express.PreLoadExpressManager
import com.mints.goodmoney.ad.video.VedioAdingManager
import com.mints.goodmoney.common.AppConfig
import com.mints.goodmoney.common.Constant
import com.mints.goodmoney.common.DeviceInfo.Companion.instance
import com.mints.goodmoney.ad.express.TTPreLoadExpressManager
import com.mints.goodmoney.ad.express.YlhPreLoadExpressManager
import com.mints.goodmoney.manager.UserManager
import com.mints.goodmoney.mvp.model.VedioAdingBean
import com.mints.goodmoney.mvp.presenters.AwardPresenter
......@@ -326,7 +328,8 @@ class AwardActivity : BaseActivity(), AwardView, View.OnClickListener {
mTimer = null
try {
TTPreLoadExpressManager.getInstance().loadTtFrameLayout()
// TTPreLoadExpressManager.getInstance().loadTtFrameLayout()
PreLoadExpressManager.loadADFrameLayout()
} catch (e: java.lang.Exception) {
e.printStackTrace()
}
......@@ -334,6 +337,7 @@ class AwardActivity : BaseActivity(), AwardView, View.OnClickListener {
SoundPoolUtil.getInstance().onDestory()
TTPreLoadExpressManager.getInstance().onDestroy()
YlhPreLoadExpressManager.onDestroy()
flAwardAd?.removeAllViews()
vedioAdingManager.setVedioAdingListener(null)
vedioAdingManager.onDestory()
......@@ -504,7 +508,7 @@ class AwardActivity : BaseActivity(), AwardView, View.OnClickListener {
try {
if (flAwardAd != null) {
flAwardAd.removeAllViews()
flAwardAd.addView(TTPreLoadExpressManager.getInstance().ttFrameLayout)
flAwardAd.addView(PreLoadExpressManager.getADFrameLayout())
}
} catch (e: Exception) {
......
......@@ -14,6 +14,7 @@ import com.daimajia.androidanimations.library.YoYo
import com.daimajia.androidanimations.library.YoYo.YoYoString
import com.mints.goodmoney.MintsApplication
import com.mints.goodmoney.R
import com.mints.goodmoney.ad.express.PreLoadExpressManager
import com.mints.goodmoney.ad.express.TTPreLoadExpressManager
import com.mints.goodmoney.ad.express.TTPreLoadExpressXmlyManager
import com.mints.goodmoney.ad.video.VedioAdingManager
......@@ -90,7 +91,8 @@ class MainFragment : BaseFragment(), HomeView, View.OnClickListener {
vedioAdingManager = VedioAdingManager.getInstance(activity)
// 奖励页预加载 信息流广告
TTPreLoadExpressManager.getInstance().loadTtFrameLayout()
// TTPreLoadExpressManager.getInstance().loadTtFrameLayout()
PreLoadExpressManager.loadADFrameLayout()
// 刷新喜马拉雅信息流
TTPreLoadExpressXmlyManager.getInstance().loadTtFrameLayout()
......
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