feat: 完成穿山甲广告SDK接入 https://jira.shanqu.cc/browse/GHZS-2940

This commit is contained in:
chenjuntao
2023-07-18 14:45:17 +08:00
parent 96f9e8aceb
commit fb937e8ced
20 changed files with 481 additions and 88 deletions

View File

@ -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) {