Commit 782a1cf3 authored by jyx's avatar jyx

代码优化

parent 94b1fd50
package com.mints.goodmoney.ad.express
import android.widget.FrameLayout
import com.mints.goodmoney.MintsApplication
import com.qq.e.ads.nativ.NativeExpressADView
object PreLoadExpressManager {
object PreLoadExpressManager : TTADLoadSuccessListener, YLHADLoadSuccessListener {
// 是否是穿山甲信息流
@Volatile
......@@ -11,39 +13,51 @@ object PreLoadExpressManager {
@Volatile
private var mAdFrameLayout: FrameLayout? = null
// init {
// YlhPreLoadExpressManager.setListener(this)
// }
init {
mAdFrameLayout = FrameLayout(MintsApplication.getContext())
YlhPreLoadExpressManager.setListener(this)
TTPreLoadExpressManager.getInstance().setListener(this)
}
fun loadADFrameLayout() {
mAdFrameLayout?.removeAllViews()
if (isTTExpressAd) {
TTPreLoadExpressManager.getInstance().loadTtFrameLayout()
TTPreLoadExpressManager.getInstance().loadTtFrameLayout(mAdFrameLayout)
} else {
YlhPreLoadExpressManager.loadYlhFrameLayout()
}
}
fun getADFrameLayout(): FrameLayout? {
mAdFrameLayout = if (isTTExpressAd) {
TTPreLoadExpressManager.getInstance().ttFrameLayout
} else {
YlhPreLoadExpressManager.getYlhFrameLayout()
}
// 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
// }
fun onDestroy() {
TTPreLoadExpressManager.getInstance().onDestroy()
YlhPreLoadExpressManager.onDestroy()
}
override fun onTTAdLoadSuc(adFrameLayout: FrameLayout?) {
mAdFrameLayout = adFrameLayout
}
override fun onYlhAdLoadSuc(adFrameLayout: NativeExpressADView?) {
mAdFrameLayout?.addView(adFrameLayout)
}
}
interface ADLoadSuccessListener {
interface TTADLoadSuccessListener {
fun onTTAdLoadSuc(adFrameLayout: FrameLayout?)
fun onYlhAdLoadSuc(adFrameLayout: FrameLayout?)
}
interface YLHADLoadSuccessListener {
fun onYlhAdLoadSuc(view: NativeExpressADView?)
}
\ No newline at end of file
package com.mints.goodmoney.ad.express;
import android.content.Context;
import android.widget.FrameLayout;
import com.mints.goodmoney.MintsApplication;
import com.mints.goodmoney.manager.TTNativeExpressManager;
import com.mints.goodmoney.manager.TtCsjAdManager;
......@@ -11,7 +9,7 @@ public class TTPreLoadExpressManager {
private static TTPreLoadExpressManager _inst;
private FrameLayout ttFrameLayout;
// private FrameLayout ttFrameLayout;
private TTNativeExpressManager ttNativeExpressManager;
public static TTPreLoadExpressManager getInstance() {
......@@ -33,32 +31,47 @@ public class TTPreLoadExpressManager {
}
}
public FrameLayout getTtFrameLayout() {
return ttFrameLayout;
// public FrameLayout getTtFrameLayout() {
// return ttFrameLayout;
// }
private TTADLoadSuccessListener mADLoadSuccessListener;
public void setListener(TTADLoadSuccessListener adLoadSuccessListener) {
mADLoadSuccessListener = adLoadSuccessListener;
}
/**
* 预加载 信息流
*/
public void loadTtFrameLayout() {
public void loadTtFrameLayout(FrameLayout adFrameLayout) {
init();
Context context = MintsApplication.getContext();
ttFrameLayout = null;
// Context context = MintsApplication.getContext();
// ttFrameLayout = null;
try {
ttFrameLayout = new FrameLayout(context);
ttNativeExpressManager.getNativeExpressInit(TtCsjAdManager.TT_AD_NATIVEEXPRESS_AWARD, ttFrameLayout, 310, 0);
// FrameLayout ttFrameLayout = new FrameLayout(context);
ttNativeExpressManager.getNativeExpressInit(TtCsjAdManager.TT_AD_NATIVEEXPRESS_AWARD, adFrameLayout, 310, 0);
ttNativeExpressManager.setTTNativeExpressManagerListener(view -> {
if (view == null) {
ttFrameLayout = null;
} else {
try {
ttFrameLayout = view;
} catch (Exception e) {
e.printStackTrace();
ttFrameLayout = null;
// if (view == null) {
// ttFrameLayout = null;
// } else {
//
// try {
// ttFrameLayout = view;
// } catch (Exception e) {
// e.printStackTrace();
// ttFrameLayout = null;
// }
// }
try {
if (view != null) {
if (mADLoadSuccessListener != null) {
mADLoadSuccessListener.onTTAdLoadSuc(view);
}
}
} catch (Exception e) {
e.printStackTrace();
}
});
......
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
......@@ -11,27 +9,27 @@ import com.qq.e.comm.util.AdError
object YlhPreLoadExpressManager {
private var ylhFrameLayout: FrameLayout? = null
// 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
// }
private var mADLoadSuccessListener: YLHADLoadSuccessListener? = null
fun getYlhFrameLayout(): FrameLayout? {
return ylhFrameLayout
fun setListener(adLoadSuccessListener: YLHADLoadSuccessListener?) {
mADLoadSuccessListener = adLoadSuccessListener
}
// fun getYlhFrameLayout(): FrameLayout? {
// return ylhFrameLayout
// }
fun loadYlhFrameLayout() {
val context = MintsApplication.getContext()
// val context = MintsApplication.getContext()
try {
ylhFrameLayout = FrameLayout(context)
// ylhFrameLayout = FrameLayout(context)
nativeExpressAD = NativeExpressAD(MintsApplication.getContext(), ADSize(320, ADSize.AUTO_HEIGHT), YlhAdManager.YLH_AD_NATIVEEXPRESS_AWARD, object : NativeExpressAD.NativeExpressADListener {
nativeExpressAD = NativeExpressAD(MintsApplication.getContext(), ADSize(ADSize.FULL_WIDTH, ADSize.AUTO_HEIGHT), YlhAdManager.YLH_AD_NATIVEEXPRESS_AWARD, object : NativeExpressAD.NativeExpressADListener {
override fun onNoAD(p0: AdError?) {
}
......@@ -55,17 +53,16 @@ object YlhPreLoadExpressManager {
nativeExpressADView?.destroy()
nativeExpressADView = p0?.get(0)
if (ylhFrameLayout!!.childCount > 0) {
ylhFrameLayout!!.removeAllViews()
}
// val frameLayout = FrameLayout(context)
// mADLoadSuccessListener?.onYlhAdLoadSuc(frameLayout)
//
// if (ylhFrameLayout!!.childCount > 0) {
// ylhFrameLayout!!.removeAllViews()
// }
// 广告可见才会产生曝光,否则将无法产生收益。
ylhFrameLayout!!.addView(nativeExpressADView)
nativeExpressADView!!.render()
mADLoadSuccessListener?.onYlhAdLoadSuc(nativeExpressADView)
// ylhFrameLayout!!.addView(nativeExpressADView)
nativeExpressADView?.render()
}
override fun onADOpenOverlay(p0: NativeExpressADView?) {
......
......@@ -10,8 +10,6 @@ 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
......@@ -335,9 +333,8 @@ class AwardActivity : BaseActivity(), AwardView, View.OnClickListener {
}
SoundPoolUtil.getInstance().onDestory()
PreLoadExpressManager.onDestroy()
TTPreLoadExpressManager.getInstance().onDestroy()
YlhPreLoadExpressManager.onDestroy()
flAwardAd?.removeAllViews()
vedioAdingManager.setVedioAdingListener(null)
vedioAdingManager.onDestory()
......
......@@ -114,7 +114,8 @@
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="@+id/textView4"
app:layout_constraintStart_toStartOf="@+id/tvDrawWechat" />
app:layout_constraintStart_toStartOf="@+id/tvDrawWechat"
app:layout_constraintTop_toTopOf="@id/textView4" />
<TextView
android:id="@+id/textView4"
......
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