feat: 完成穿山甲广告SDK接入 https://jira.shanqu.cc/browse/GHZS-2940
This commit is contained in:
72
app/src/main/java/com/gh/ad/AdDelegateHelper.kt
Normal file
72
app/src/main/java/com/gh/ad/AdDelegateHelper.kt
Normal file
@ -0,0 +1,72 @@
|
||||
package com.gh.ad
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.FrameLayout
|
||||
import com.alibaba.android.arouter.launcher.ARouter
|
||||
import com.gh.gamecenter.common.constant.RouteConsts
|
||||
import com.gh.gamecenter.core.provider.IAdProvider
|
||||
|
||||
/**
|
||||
* 广告代理类
|
||||
*
|
||||
* 由它来分发功能实现到具体的 SDK
|
||||
*/
|
||||
object AdDelegateHelper {
|
||||
|
||||
private var mActivatedSdkType = 1
|
||||
private var mAdImpl: IAdProvider? = null
|
||||
|
||||
// TODO 记录广告相关的 config
|
||||
|
||||
private const val TYPE_BEIZI = 0
|
||||
private const val TYPE_CSJ = 1
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
*/
|
||||
fun init(context: Context) {
|
||||
mAdImpl = when (mActivatedSdkType) {
|
||||
TYPE_BEIZI -> ARouter.getInstance().build(RouteConsts.provider.beiziAd).navigation() as? IAdProvider
|
||||
|
||||
TYPE_CSJ -> ARouter.getInstance().build(RouteConsts.provider.csjAd).navigation() as? IAdProvider
|
||||
|
||||
else -> null
|
||||
}
|
||||
mAdImpl?.initSDK(context)
|
||||
}
|
||||
|
||||
fun shouldShowStartUpAd(): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun requestStartUpAd(
|
||||
activity: Activity,
|
||||
slotId: String,
|
||||
adViewWidthInPx: Int,
|
||||
adViewHeightInPx: Int,
|
||||
adViewWidthInDp: Float,
|
||||
adViewHeightInDp: Float,
|
||||
startAdContainer: ViewGroup,
|
||||
hideCallback: () -> Unit
|
||||
) {
|
||||
mAdImpl?.requestStartUpAd(
|
||||
activity,
|
||||
slotId,
|
||||
adViewWidthInPx,
|
||||
adViewHeightInPx,
|
||||
adViewWidthInDp,
|
||||
adViewHeightInDp,
|
||||
startAdContainer,
|
||||
hideCallback
|
||||
)
|
||||
}
|
||||
|
||||
fun cancelStartUpAd(context: Context) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -33,6 +33,7 @@ import android.text.Html;
|
||||
import android.text.TextUtils;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
@ -43,8 +44,8 @@ import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProviders;
|
||||
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.gh.ad.AdDelegateHelper;
|
||||
import com.gh.common.DefaultUrlHandler;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.exposure.ExposureManager;
|
||||
@ -77,7 +78,6 @@ import com.gh.gamecenter.common.base.fragment.ToolbarFragment;
|
||||
import com.gh.gamecenter.common.constant.CommonConsts;
|
||||
import com.gh.gamecenter.common.constant.Constants;
|
||||
import com.gh.gamecenter.common.constant.EntranceConsts;
|
||||
import com.gh.gamecenter.common.constant.RouteConsts;
|
||||
import com.gh.gamecenter.common.entity.LinkEntity;
|
||||
import com.gh.gamecenter.common.entity.NotificationUgc;
|
||||
import com.gh.gamecenter.common.entity.SuggestType;
|
||||
@ -92,7 +92,7 @@ import com.gh.gamecenter.common.utils.ImageUtils;
|
||||
import com.gh.gamecenter.common.utils.NotificationHelper;
|
||||
import com.gh.gamecenter.common.utils.ShareUtils;
|
||||
import com.gh.gamecenter.core.AppExecutor;
|
||||
import com.gh.gamecenter.core.provider.IStartUpAdProvider;
|
||||
import com.gh.gamecenter.core.provider.IAdProvider;
|
||||
import com.gh.gamecenter.core.utils.ClassUtils;
|
||||
import com.gh.gamecenter.core.utils.DisplayUtils;
|
||||
import com.gh.gamecenter.core.utils.GsonUtils;
|
||||
@ -192,8 +192,6 @@ public class MainActivity extends BaseActivity {
|
||||
private final Handler handler = new Handler();
|
||||
public boolean showAd = false; // 是否显示广告
|
||||
|
||||
private IStartUpAdProvider mStartUpAdProvider;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
showAd = getIntent().getBooleanExtra(SHOW_AD, false) && savedInstanceState == null;
|
||||
@ -475,7 +473,7 @@ public class MainActivity extends BaseActivity {
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
if (mStartUpAdProvider != null) mStartUpAdProvider.cancelStartUpAd(this);
|
||||
AdDelegateHelper.INSTANCE.cancelStartUpAd(this);
|
||||
|
||||
handler.removeCallbacksAndMessages(null);
|
||||
releaseExoSourceCache();
|
||||
@ -518,8 +516,7 @@ public class MainActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
private void initStartUpAd() {
|
||||
mStartUpAdProvider = (IStartUpAdProvider) ARouter.getInstance().build(RouteConsts.provider.adSdk).navigation();
|
||||
if (mStartUpAdProvider != null && mStartUpAdProvider.shouldEnableSDK(HaloApp.getInstance().getChannel())) {
|
||||
if (AdDelegateHelper.INSTANCE.shouldShowStartUpAd()) {
|
||||
initSDKStartUpAd();
|
||||
} else {
|
||||
observeStartUpAd();
|
||||
@ -618,7 +615,7 @@ public class MainActivity extends BaseActivity {
|
||||
if (startSdkAdContainer != null) {
|
||||
startSdkAdContainer.setVisibility(View.GONE);
|
||||
ExtensionsKt.removeFromParent(startSdkAdContainer);
|
||||
if (mStartUpAdProvider != null) mStartUpAdProvider.cancelStartUpAd(this);
|
||||
AdDelegateHelper.INSTANCE.cancelStartUpAd(this);
|
||||
}
|
||||
checkDialog();
|
||||
}
|
||||
@ -678,15 +675,27 @@ public class MainActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
private void initSDKStartUpAd() {
|
||||
View startAdContainer = findViewById(R.id.sdkStartAdContainer);
|
||||
ViewGroup startAdContainer = findViewById(R.id.sdkStartAdContainer);
|
||||
startAdContainer.setVisibility(View.VISIBLE);
|
||||
FrameLayout adsFl = findViewById(R.id.adsFl);
|
||||
if (mStartUpAdProvider != null) {
|
||||
mStartUpAdProvider.initStartUpAd(startAdContainer, adsFl, showAd, () -> {
|
||||
hideStartUpAd();
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
float screenWidthInDp = DisplayUtils.getScreenWidth(this);
|
||||
float screenHeightInDp = DisplayUtils.getScreenHeight(this);
|
||||
int screenWidthInPx = DisplayUtils.px2dip(this, screenWidthInDp);
|
||||
int screenHeightInPx = DisplayUtils.px2dip(this, screenHeightInDp);
|
||||
|
||||
AdDelegateHelper.requestStartUpAd(
|
||||
this,
|
||||
"888381490",
|
||||
screenWidthInPx,
|
||||
screenHeightInPx,
|
||||
screenWidthInDp,
|
||||
screenHeightInDp,
|
||||
startAdContainer,
|
||||
() -> {
|
||||
hideStartUpAd();
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
private void showStartUp(StartupAdEntity ad) {
|
||||
|
||||
@ -19,6 +19,7 @@ import androidx.viewpager.widget.ViewPager
|
||||
import com.alibaba.android.arouter.facade.annotation.Route
|
||||
import com.alibaba.android.arouter.launcher.ARouter
|
||||
import com.g00fy2.versioncompare.Version
|
||||
import com.gh.ad.AdDelegateHelper
|
||||
import com.gh.common.dialog.NewPrivacyPolicyDialogFragment
|
||||
import com.gh.common.util.*
|
||||
import com.gh.common.util.GameSubstituteRepositoryHelper.updateGameSubstituteRepository
|
||||
@ -33,7 +34,6 @@ import com.gh.gamecenter.common.tracker.TrackerLogger
|
||||
import com.gh.gamecenter.common.utils.*
|
||||
import com.gh.gamecenter.core.provider.IAppProvider
|
||||
import com.gh.gamecenter.core.provider.IPackageUtilsProvider
|
||||
import com.gh.gamecenter.core.provider.IStartUpAdProvider
|
||||
import com.gh.gamecenter.core.runOnIoThread
|
||||
import com.gh.gamecenter.core.utils.*
|
||||
import com.gh.gamecenter.entity.PrivacyPolicyEntity
|
||||
@ -64,9 +64,6 @@ class SplashScreenActivity : BaseActivity() {
|
||||
private var mStartMainActivityDirectly = false // 是否不需要用户点击立即体验就直接跳转首页
|
||||
private var mViewModel: SplashScreenViewModel? = null
|
||||
private var mShouldPrefetchData = true
|
||||
private val mStartUpAdProvider by lazy {
|
||||
ARouter.getInstance().build(RouteConsts.provider.adSdk).navigation() as? IStartUpAdProvider
|
||||
}
|
||||
|
||||
private val mPermissions = arrayOf(
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
||||
@ -289,7 +286,8 @@ class SplashScreenActivity : BaseActivity() {
|
||||
overridePendingTransition(0, 0)
|
||||
startActivity(intent)
|
||||
doFlavorInit()
|
||||
initStartUpAdSDK()
|
||||
// 初始化广告 SDK
|
||||
AdDelegateHelper.init(HaloApp.getInstance())
|
||||
logAppLaunch()
|
||||
finish()
|
||||
}
|
||||
@ -302,14 +300,6 @@ class SplashScreenActivity : BaseActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun initStartUpAdSDK() {
|
||||
mStartUpAdProvider?.run {
|
||||
if (shouldEnableSDK(HaloApp.getInstance().channel)) {
|
||||
initSDK(applicationContext)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getGitLogString(): String {
|
||||
if (com.gh.gamecenter.common.BuildConfig.BUILD_TIME != 0L) {
|
||||
val stringBuilder = StringBuilder()
|
||||
|
||||
@ -27,7 +27,7 @@ import com.gh.gamecenter.common.utils.viewModelProviderFromParent
|
||||
import com.gh.gamecenter.common.view.OffsetLinearLayoutManager
|
||||
import com.gh.gamecenter.core.AppExecutor
|
||||
import com.gh.gamecenter.core.provider.IFloatingWindowProvider
|
||||
import com.gh.gamecenter.core.provider.IStartUpAdProvider
|
||||
import com.gh.gamecenter.core.provider.IAdProvider
|
||||
import com.gh.gamecenter.core.utils.MD5Utils
|
||||
import com.gh.gamecenter.core.utils.MtaHelper
|
||||
import com.gh.gamecenter.core.utils.SPUtils
|
||||
@ -105,7 +105,7 @@ class HomeFragment : LazyFragment() {
|
||||
}
|
||||
mListAdapter.setLoadStatus(it)
|
||||
val startUpAdProvider =
|
||||
ARouter.getInstance().build(RouteConsts.provider.adSdk).navigation() as? IStartUpAdProvider
|
||||
ARouter.getInstance().build(RouteConsts.provider.beiziAd).navigation() as? IAdProvider
|
||||
val startAdContainerView =
|
||||
requireActivity().findViewById<View>(if (startUpAdProvider != null) R.id.sdkStartAdContainer else R.id.startAdContainer)
|
||||
if (it == LoadStatus.INIT_LOADED && startAdContainerView == null) {
|
||||
@ -224,7 +224,7 @@ class HomeFragment : LazyFragment() {
|
||||
*/
|
||||
private fun listenStartAdViewRemoved() {
|
||||
val startUpAdProvider =
|
||||
ARouter.getInstance().build(RouteConsts.provider.adSdk).navigation() as? IStartUpAdProvider
|
||||
ARouter.getInstance().build(RouteConsts.provider.beiziAd).navigation() as? IAdProvider
|
||||
val startAdContainerView =
|
||||
requireActivity().findViewById<View>(if (startUpAdProvider != null) R.id.sdkStartAdContainer else R.id.startAdContainer)
|
||||
val parentView = startAdContainerView?.parent as? ViewGroup
|
||||
|
||||
Reference in New Issue
Block a user