Commit 782a1cf3 authored by jyx's avatar jyx

代码优化

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