Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
A
appzxhy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wanglei
appzxhy
Commits
0db1da16
Commit
0db1da16
authored
Jun 18, 2025
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[商业化]优化广告逻辑
parent
2d9b4206
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
50 additions
and
59 deletions
+50
-59
AdState.kt
app/src/main/java/com/base/appzxhy/business/ads/AdState.kt
+3
-3
AdsShowCallBack.kt
...ain/java/com/base/appzxhy/business/ads/AdsShowCallBack.kt
+6
-1
LimitUtils.kt
...src/main/java/com/base/appzxhy/business/ads/LimitUtils.kt
+1
-1
AdInterMgr.kt
...in/java/com/base/appzxhy/business/ads/admob/AdInterMgr.kt
+14
-19
AdOpenMgr.kt
...ain/java/com/base/appzxhy/business/ads/admob/AdOpenMgr.kt
+8
-11
MaxInsertMgr.kt
...va/com/base/appzxhy/business/ads/applovin/MaxInsertMgr.kt
+14
-18
MaxOpenMgr.kt
...java/com/base/appzxhy/business/ads/applovin/MaxOpenMgr.kt
+0
-5
SplashActivity.kt
...rc/main/java/com/base/appzxhy/ui/splash/SplashActivity.kt
+4
-1
No files found.
app/src/main/java/com/base/appzxhy/business/ads/AdState.kt
View file @
0db1da16
...
...
@@ -30,7 +30,7 @@ class AdState<T>() {
/**
* 用于保存引用现有页面,在此页面显示广告(因为要等待广告加载完毕)
*/
var
activityRef
:
WeakReference
<
Activity
>?
=
null
//
var activityRef: WeakReference<Activity>? = null
/**
* 上一次的缓存成功时间
...
...
@@ -49,7 +49,7 @@ class AdState<T>() {
fun
onAdDisplayed
()
{
currentAd
=
null
currentAdEvent
=
null
activityRef
=
null
//
activityRef = null
adDialog
?.
dismiss
()
adDialog
=
null
...
...
@@ -70,7 +70,7 @@ class AdState<T>() {
currentAd
=
null
currentAdEvent
=
null
activityRef
=
null
//
activityRef = null
}
fun
onAdLoaded
(
ad
:
T
?,
adEvent
:
AdEvent
?)
{
...
...
app/src/main/java/com/base/appzxhy/business/ads/AdsShowCallBack.kt
View file @
0db1da16
package
com.base.appzxhy.business.ads
abstract
class
AdsShowCallBack
{
var
adShowed
:
Boolean
=
false
var
nextCalled
:
Boolean
=
false
//展示广告时调用
open
fun
show
()
{
adShowed
=
true
}
//流程中非广告的失败时调用
open
fun
failed
(
where
:
Int
=
0
)
{
adShowed
=
false
if
(!
nextCalled
)
{
...
...
@@ -17,6 +21,7 @@ abstract class AdsShowCallBack {
}
}
//流程中广告本身时调用
open
fun
adFailed
(
where
:
Int
=
0
)
{
adShowed
=
false
if
(!
nextCalled
)
{
...
...
@@ -25,8 +30,8 @@ abstract class AdsShowCallBack {
}
}
//用户手动关闭广告时调用
open
fun
close
(
where
:
Int
=
0
)
{
adShowed
=
false
if
(!
nextCalled
)
{
nextCalled
=
true
next
()
...
...
app/src/main/java/com/base/appzxhy/business/ads/LimitUtils.kt
View file @
0db1da16
...
...
@@ -149,7 +149,7 @@ object LimitUtils {
fun
isIntervalLimited
(
adEvent
:
AdEvent
?):
Boolean
{
val
flag
=
((
System
.
currentTimeMillis
()
-
openInterLastShowTime
)
/
1000
).
toInt
()
<
(
AdConfigBean
.
adsConfigBean
.
timeInterval
)
if
(
flag
)
{
adEvent
?.
ad
ShowError
(
"ad in timeInterval"
)
adEvent
?.
ad
Limited
(
"ad in timeInterval"
)
}
return
flag
}
...
...
app/src/main/java/com/base/appzxhy/business/ads/admob/AdInterMgr.kt
View file @
0db1da16
...
...
@@ -19,7 +19,6 @@ import com.google.android.gms.ads.FullScreenContentCallback
import
com.google.android.gms.ads.LoadAdError
import
com.google.android.gms.ads.interstitial.InterstitialAd
import
com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback
import
java.lang.ref.WeakReference
/**
...
...
@@ -45,7 +44,7 @@ class AdInterMgr {
}
val
nowAdEvent
=
adEvent
//currentAdEvent!=null 有缓存广告,关联reqId
//currentAdEvent!=null
表示
有缓存广告,关联reqId
adState
.
currentAdEvent
?.
let
{
nowAdEvent
.
reqId
=
it
.
reqId
}
if
(!
nowAdEvent
.
isUnLimit
)
{
...
...
@@ -61,7 +60,7 @@ class AdInterMgr {
val
needLoad
=
!
adState
.
adAvailable
()
adState
.
activityRef
=
WeakReference
(
activity
)
//
adState.activityRef = WeakReference(activity)
this
.
showCallBack
=
showCallBack
if
(
adState
.
adDialog
==
null
)
{
...
...
@@ -70,7 +69,6 @@ class AdInterMgr {
adState
.
adDialog
?.
dismiss
()
}
nowAdEvent
.
adPrepareShow
()
LogEx
.
logDebug
(
adEvent
.
TAG
,
"needLoad=$needLoad"
)
...
...
@@ -78,30 +76,30 @@ class AdInterMgr {
if
(!
adState
.
loadingAd
)
{
LogEx
.
logDebug
(
adEvent
.
TAG
,
"inter adState !loadingAd"
)
loadAd
(
activity
,
nowAdEvent
)
{
showReadyAd
()
showReadyAd
(
activity
)
}
}
else
{
LogEx
.
logDebug
(
adEvent
.
TAG
,
"inter adState is loadingAd"
)
loadingCallBack
=
{
showReadyAd
()
showReadyAd
(
activity
)
}
}
}
else
{
LogEx
.
logDebug
(
adEvent
.
TAG
,
"inter ad ready"
)
showReadyAd
()
showReadyAd
(
activity
)
}
}
private
fun
showReadyAd
()
{
private
fun
showReadyAd
(
ac
:
Activity
)
{
val
adEvent
=
(
adState
.
currentAdEvent
as
AdmobEvent
?)
val
ac
=
adState
.
activityRef
?.
get
()
//
val ac = adState.activityRef?.get()
val
tag
=
adEvent
?.
TAG
?:
""
LogEx
.
logDebug
(
tag
,
"showReadyAd ac=$ac currentAd=${adState.currentAd}"
)
if
(
ac
==
null
||
ac
.
isFinishing
||
ac
.
isDestroyed
)
{
if
(
ac
.
isFinishing
||
ac
.
isDestroyed
||
adState
.
currentAd
==
null
)
{
LogEx
.
logDebug
(
tag
,
"showReadyAd ac=null isFinishing isDestroyed"
)
showCallBack
?.
failed
()
adState
.
onAdDisplayFailed
()
...
...
@@ -114,7 +112,6 @@ class AdInterMgr {
override
fun
onAdShowedFullScreenContent
()
{
super
.
onAdShowedFullScreenContent
()
val
ac
=
adState
.
activityRef
?.
get
()
adEvent
?.
showAd
(
responseInfo
,
ac
)
adState
.
onAdDisplayed
()
...
...
@@ -150,15 +147,13 @@ class AdInterMgr {
LimitUtils
.
addClickNum
()
}
}
val
activity
=
adState
.
activityRef
?.
get
()
activity
?.
let
{
// val activity = adState.activityRef?.get()
if
(
AdConfigBean
.
adsConfigBean
.
showCountdown
)
{
createUICountdownTimer
(
adState
.
adDialog
)
{
show
(
it
)
show
(
ac
)
}
}
else
{
show
(
it
)
}
show
(
ac
)
}
}
}
...
...
app/src/main/java/com/base/appzxhy/business/ads/admob/AdOpenMgr.kt
View file @
0db1da16
...
...
@@ -15,7 +15,6 @@ import com.google.android.gms.ads.AdRequest
import
com.google.android.gms.ads.FullScreenContentCallback
import
com.google.android.gms.ads.LoadAdError
import
com.google.android.gms.ads.appopen.AppOpenAd
import
java.lang.ref.WeakReference
/**
...
...
@@ -54,7 +53,6 @@ class AdOpenMgr {
}
val
needLoad
=
!
adState
.
adAvailable
()
adState
.
activityRef
=
WeakReference
(
activity
)
this
.
showCallBack
=
showCallBack
nowAdEvent
.
adPrepareShow
()
...
...
@@ -62,24 +60,24 @@ class AdOpenMgr {
if
(!
adState
.
loadingAd
)
{
LogEx
.
logDebug
(
adEvent
.
TAG
,
"open adState !loadingAd"
)
loadAd
(
activity
,
adEvent
)
{
showReadyAd
()
showReadyAd
(
activity
)
}
}
else
{
LogEx
.
logDebug
(
adEvent
.
TAG
,
"open adState is loadingAd"
)
loadingCallBack
=
{
showReadyAd
()
showReadyAd
(
activity
)
}
}
}
else
{
LogEx
.
logDebug
(
adEvent
.
TAG
,
"open ad ready"
)
showReadyAd
()
showReadyAd
(
activity
)
}
}
private
fun
showReadyAd
()
{
private
fun
showReadyAd
(
ac
:
Activity
)
{
val
ac
=
adState
.
activityRef
?.
get
()
if
(
ac
==
null
||
ac
.
isFinishing
||
ac
.
isDestroyed
)
{
//
val ac = adState.activityRef?.get()
if
(
ac
.
isFinishing
||
ac
.
isDestroyed
||
adState
.
currentAd
==
null
)
{
LogEx
.
logDebug
(
TAG
,
"showReadyAd ac=null isFinishing isDestroyed"
)
return
}
...
...
@@ -131,8 +129,7 @@ class AdOpenMgr {
LimitUtils
.
addClickNum
()
}
}
val
activity
=
adState
.
activityRef
?.
get
()
activity
?.
let
{
show
(
it
)
}
show
(
ac
)
}
}
...
...
@@ -144,7 +141,7 @@ class AdOpenMgr {
if
(!
adEvent
.
isUnLimit
)
{
if
(!
LimitUtils
.
isAdShow
(
AdsType
.
OPEN
,
adEvent
))
{
this
.
showCallBack
?.
close
()
this
.
showCallBack
?.
failed
()
this
.
showCallBack
=
null
adState
.
onAdLoadFailed
()
return
...
...
app/src/main/java/com/base/appzxhy/business/ads/applovin/MaxInsertMgr.kt
View file @
0db1da16
...
...
@@ -13,7 +13,6 @@ import com.base.appzxhy.business.ads.AdState
import
com.base.appzxhy.business.ads.AdsShowCallBack
import
com.base.appzxhy.business.ads.AdsType
import
com.base.appzxhy.business.ads.LimitUtils
import
java.lang.ref.WeakReference
/**
*插屏广告加载显示管理类
...
...
@@ -31,18 +30,9 @@ class MaxInsertMgr {
)
{
if
(
activity
.
isFinishing
||
activity
.
isDestroyed
)
{
showCallBack
?.
failed
(
1
)
return
}
if
(
showCallBack
!=
null
)
{
adState
.
activityRef
=
WeakReference
(
activity
)
this
.
showCallBack
=
showCallBack
if
(
adState
.
adDialog
==
null
)
{
adState
.
adDialog
=
activity
.
showAdCountDownDialog
()
}
adEvent
.
adPrepareShow
()
}
if
(!
adState
.
loadingAd
)
{
if
(!
isUnLimit
)
{
...
...
@@ -57,12 +47,21 @@ class MaxInsertMgr {
}
if
(!
adAvailable
()
||
adState
.
currentAd
==
null
)
{
loadAd
(
activity
,
adEvent
,
isUnLimit
)
loadAd
(
activity
,
adEvent
)
return
}
if
(
showCallBack
!=
null
)
{
this
.
showCallBack
=
showCallBack
if
(
adState
.
adDialog
==
null
)
{
adState
.
adDialog
=
activity
.
showAdCountDownDialog
()
}
adEvent
.
adPrepareShow
()
}
if
(
adState
.
currentAd
?.
isReady
==
false
)
{
loadAd
(
activity
,
adEvent
,
isUnLimit
)
loadAd
(
activity
,
adEvent
)
return
}
showReadyAd
(
adEvent
)
...
...
@@ -121,9 +120,9 @@ class MaxInsertMgr {
fun
loadAd
(
context
:
Context
,
adEvent
:
AdEvent
,
isUnLimit
:
Boolean
=
false
,
loadCallback
:
(()
->
Unit
)?
=
null
)
{
if
(!
isUnLimit
)
{
if
(!
adEvent
.
isUnLimit
)
{
if
(!
LimitUtils
.
isAdShow
(
AdsType
.
INSERT
,
adEvent
))
{
this
.
showCallBack
?.
close
(
4
)
this
.
showCallBack
=
null
...
...
@@ -146,10 +145,7 @@ class MaxInsertMgr {
override
fun
onAdLoaded
(
ad
:
MaxAd
)
{
adState
.
onAdLoaded
(
null
,
adEvent
)
val
ac
=
adState
.
activityRef
?.
get
()
if
(
ac
!=
null
)
{
show
(
ac
,
isUnLimit
,
adEvent
,
null
)
}
loadCallback
?.
invoke
()
(
adEvent
as
AdMaxEvent
).
pullAd
(
ad
)
LimitUtils
.
addRequestNum
()
...
...
app/src/main/java/com/base/appzxhy/business/ads/applovin/MaxOpenMgr.kt
View file @
0db1da16
...
...
@@ -29,7 +29,6 @@ class MaxOpenMgr {
if
(
showCallBack
!=
null
)
{
this
.
showCallBack
=
showCallBack
adState
.
activityRef
=
WeakReference
(
activity
)
adEvent
.
adPrepareShow
()
}
...
...
@@ -127,10 +126,6 @@ class MaxOpenMgr {
adState
.
currentAd
?.
setListener
(
object
:
MaxAdListener
{
override
fun
onAdLoaded
(
ad
:
MaxAd
)
{
adState
.
onAdLoaded
(
null
,
adEvent
)
val
ac
=
adState
.
activityRef
?.
get
()
if
(
ac
!=
null
)
{
show
(
ac
,
isUnLimit
,
adEvent
,
null
)
}
(
adEvent
as
AdMaxEvent
).
pullAd
(
ad
)
LimitUtils
.
addRequestNum
()
}
...
...
app/src/main/java/com/base/appzxhy/ui/splash/SplashActivity.kt
View file @
0db1da16
...
...
@@ -184,8 +184,10 @@ class SplashActivity : BaseActivity<ActivitySplashBinding>(ActivitySplashBinding
val
acAction
=
{
initUMP
{
LogEx
.
logDebug
(
TAG
,
"initUMP callback"
)
AdsMgr
.
showOpen
(
this
,
showCallBack
=
object
:
AdsShowCallBack
()
{
override
fun
show
()
{
super
.
show
()
viewModel
.
stopCountdown
()
binding
.
progressBar
.
setProgress
(
100
,
true
)
}
...
...
@@ -197,7 +199,8 @@ class SplashActivity : BaseActivity<ActivitySplashBinding>(ActivitySplashBinding
binding
.
progressBar
.
setProgress
(
100
,
true
)
binding
.
root
.
postDelayed
({
jumpNext
()
},
250
)
}
if
(
this
.
adShowed
)
{
LogEx
.
logDebug
(
"AdmobEvent"
,
"inter adShowed=${adShowed}"
)
if
(
adShowed
)
{
action
.
invoke
()
}
else
{
LogEx
.
logDebug
(
"AdmobEvent"
,
"inter open show inter"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment