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
126e5240
Commit
126e5240
authored
Jun 13, 2025
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[商业化]优化广告事件上报链
parent
e18d1f4d
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
128 additions
and
49 deletions
+128
-49
AdState.kt
app/src/main/java/com/base/appzxhy/business/ads/AdState.kt
+14
-1
AdsMgr.kt
app/src/main/java/com/base/appzxhy/business/ads/AdsMgr.kt
+2
-3
AdInterMgr.kt
...in/java/com/base/appzxhy/business/ads/admob/AdInterMgr.kt
+51
-17
AdOpenMgr.kt
...ain/java/com/base/appzxhy/business/ads/admob/AdOpenMgr.kt
+49
-19
AdmobEvent.kt
...in/java/com/base/appzxhy/business/ads/admob/AdmobEvent.kt
+0
-1
MaxInsertMgr.kt
...va/com/base/appzxhy/business/ads/applovin/MaxInsertMgr.kt
+1
-1
MaxOpenMgr.kt
...java/com/base/appzxhy/business/ads/applovin/MaxOpenMgr.kt
+1
-1
GuideCleanActivity.kt
...main/java/com/base/appzxhy/ui/guide/GuideCleanActivity.kt
+8
-4
LanguageActivity.kt
...ain/java/com/base/appzxhy/ui/language/LanguageActivity.kt
+1
-1
SplashActivity.kt
...rc/main/java/com/base/appzxhy/ui/splash/SplashActivity.kt
+1
-1
No files found.
app/src/main/java/com/base/appzxhy/business/ads/AdState.kt
View file @
126e5240
...
...
@@ -16,6 +16,11 @@ class AdState<T>() {
*/
var
currentAd
:
T
?
=
null
/**
* 当前缓存广告对应的event
*/
var
currentAdEvent
:
AdEvent
?
=
null
/**
* 是否正在缓存加载广告
*/
...
...
@@ -43,6 +48,7 @@ class AdState<T>() {
*/
fun
onAdDisplayed
()
{
currentAd
=
null
currentAdEvent
=
null
activityRef
=
null
adDialog
?.
dismiss
()
...
...
@@ -63,14 +69,18 @@ class AdState<T>() {
adDialog
=
null
currentAd
=
null
currentAdEvent
=
null
activityRef
=
null
}
fun
onAdLoaded
(
ad
:
T
?)
{
fun
onAdLoaded
(
ad
:
T
?
,
adEvent
:
AdEvent
?
)
{
//这里可能提前设置,所有可以不设置,max回调的类型可能不同
if
(
ad
!=
null
)
{
currentAd
=
ad
}
if
(
adEvent
!=
null
)
{
currentAdEvent
=
adEvent
}
loadingAd
=
false
lastLoadTime
=
System
.
currentTimeMillis
()
}
...
...
@@ -82,4 +92,7 @@ class AdState<T>() {
}
fun
adAvailable
()
=
currentAd
!=
null
||
((
System
.
currentTimeMillis
()
-
lastLoadTime
)
/
1000
/
60
).
toInt
()
<
30
}
app/src/main/java/com/base/appzxhy/business/ads/AdsMgr.kt
View file @
126e5240
...
...
@@ -183,13 +183,12 @@ object AdsMgr {
val
from
=
activity
::
class
.
java
.
simpleName
if
(
adsConfigBean
.
adSwitch
)
{
val
admobEvent
=
AdmobEvent
(
"openAd"
,
from
)
admobEvent
.
isUnLimit
=
isUnLimit
if
(
isAdmobInit
)
{
adOpenMgr
.
show
(
activity
,
admobEvent
,
showCallBack
)
adOpenMgr
.
show
(
activity
,
isUnLimit
,
admobEvent
,
showCallBack
)
}
else
{
admobInitCallBack
=
{
}
adOpenMgr
.
show
(
activity
,
admobEvent
,
showCallBack
)
adOpenMgr
.
show
(
activity
,
isUnLimit
,
admobEvent
,
showCallBack
)
}
}
else
{
if
(
isMaxInit
)
{
...
...
app/src/main/java/com/base/appzxhy/business/ads/admob/AdInterMgr.kt
View file @
126e5240
...
...
@@ -26,10 +26,13 @@ import java.lang.ref.WeakReference
*/
class
AdInterMgr
{
private
val
TAG
=
"AdInterMgr"
private
val
TAG
=
"AdInterMgr"
private
var
adState
=
AdState
<
InterstitialAd
>()
private
var
showCallBack
:
AdsShowCallBack
?
=
null
//正在加载回调
private
var
loadingCallBack
:
(()
->
Unit
)?
=
null
fun
show
(
activity
:
Activity
,
isUnLimit
:
Boolean
,
...
...
@@ -43,39 +46,56 @@ class AdInterMgr {
return
}
if
(!
isUnLimit
)
{
if
(!
LimitUtils
.
isAdShow
(
AdsType
.
INSERT
,
adEvent
))
{
val
nowAdEvent
=
adState
.
currentAdEvent
?:
adEvent
nowAdEvent
.
from
=
adEvent
.
from
nowAdEvent
.
isUnLimit
=
isUnLimit
if
(!
nowAdEvent
.
isUnLimit
)
{
if
(!
LimitUtils
.
isAdShow
(
AdsType
.
INSERT
,
nowAdEvent
))
{
showCallBack
?.
failed
(
2
)
return
}
if
(
LimitUtils
.
isIntervalLimited
(
a
dEvent
))
{
if
(
LimitUtils
.
isIntervalLimited
(
nowA
dEvent
))
{
showCallBack
?.
failed
(
3
)
return
}
}
adEvent
.
adPrepareShow
()
val
needLoad
=
!
adState
.
adAvailable
()
adState
.
activityRef
=
WeakReference
(
activity
)
this
.
showCallBack
=
showCallBack
if
(
adState
.
adDialog
==
null
)
{
adState
.
adDialog
=
activity
.
showAdCountDownDialog
()
}
else
{
adState
.
adDialog
?.
dismiss
()
}
val
needLoad
=
adState
.
currentAd
==
null
||
!
adAvailable
()
nowAdEvent
.
adPrepareShow
()
LogEx
.
logDebug
(
adEvent
.
TAG
,
"needLoad=$needLoad"
)
if
(
needLoad
)
{
if
(!
adState
.
loadingAd
)
{
loadAd
(
activity
,
adEvent
,
isUnLimit
)
{
showReadyAd
(
adEvent
)
LogEx
.
logDebug
(
adEvent
.
TAG
,
"inter adState !loadingAd"
)
loadAd
(
activity
,
adEvent
)
{
showReadyAd
()
}
}
else
{
LogEx
.
logDebug
(
adEvent
.
TAG
,
"inter adState is loadingAd"
)
loadingCallBack
=
{
showReadyAd
()
}
}
}
else
{
showReadyAd
(
adEvent
)
LogEx
.
logDebug
(
adEvent
.
TAG
,
"inter ad ready"
)
showReadyAd
()
}
}
private
fun
showReadyAd
(
adEvent
:
AdEvent
)
{
private
fun
showReadyAd
()
{
val
ac
=
adState
.
activityRef
?.
get
()
if
(
ac
==
null
||
ac
.
isFinishing
||
ac
.
isDestroyed
)
{
...
...
@@ -83,12 +103,15 @@ class AdInterMgr {
return
}
adState
.
currentAd
?.
run
{
val
adEvent
=
(
adState
.
currentAdEvent
as
AdmobEvent
?)
fullScreenContentCallback
=
object
:
FullScreenContentCallback
()
{
override
fun
onAdShowedFullScreenContent
()
{
super
.
onAdShowedFullScreenContent
()
val
ac
=
adState
.
activityRef
?.
get
()
(
adEvent
as
AdmobEvent
)
.
showAd
(
responseInfo
,
ac
)
adEvent
?
.
showAd
(
responseInfo
,
ac
)
adState
.
onAdDisplayed
()
showCallBack
?.
show
()
...
...
@@ -103,7 +126,7 @@ class AdInterMgr {
showCallBack
?.
adFailed
()
showCallBack
=
null
adEvent
.
adShowError
(
adError
)
adEvent
?
.
adShowError
(
adError
)
}
override
fun
onAdDismissedFullScreenContent
()
{
...
...
@@ -118,7 +141,7 @@ class AdInterMgr {
override
fun
onAdClicked
()
{
super
.
onAdClicked
()
(
adEvent
as
AdmobEvent
)
.
clickAd
(
responseInfo
)
adEvent
?
.
clickAd
(
responseInfo
)
//计数
LimitUtils
.
addClickNum
()
}
...
...
@@ -135,10 +158,9 @@ class AdInterMgr {
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
...
...
@@ -147,14 +169,27 @@ class AdInterMgr {
}
}
//避免无效预加载
if
(
adState
.
loadingAd
&&
loadCallBack
==
null
&&
loadingCallBack
==
null
)
{
//容错机制
adState
.
loadingAd
=
false
return
}
adState
.
loadingAd
=
true
adState
.
currentAdEvent
=
adEvent
adEvent
.
adPulStart
()
InterstitialAd
.
load
(
context
,
GlobalConfig
.
ID_ADMOB_INTER
,
AdRequest
.
Builder
().
build
(),
object
:
InterstitialAdLoadCallback
()
{
override
fun
onAdLoaded
(
ad
:
InterstitialAd
)
{
adState
.
onAdLoaded
(
ad
)
adState
.
onAdLoaded
(
ad
,
adEvent
)
loadCallBack
?.
invoke
()
loadingCallBack
?.
invoke
()
loadingCallBack
=
null
(
adEvent
as
AdmobEvent
).
pullAd
(
ad
.
responseInfo
)
LimitUtils
.
addRequestNum
()
ad
.
onPaidEventListener
=
AdmobOnPaidEventListener
(
adEvent
.
scope
)
...
...
@@ -172,5 +207,4 @@ class AdInterMgr {
}
private
fun
adAvailable
()
=
((
System
.
currentTimeMillis
()
-
adState
.
lastLoadTime
)
/
1000
/
60
).
toInt
()
<
30
}
\ No newline at end of file
app/src/main/java/com/base/appzxhy/business/ads/admob/AdOpenMgr.kt
View file @
126e5240
...
...
@@ -27,43 +27,58 @@ class AdOpenMgr {
private
val
adState
=
AdState
<
AppOpenAd
>()
private
var
showCallBack
:
AdsShowCallBack
?
=
null
//正在加载回调
private
var
loadingCallBack
:
(()
->
Unit
)?
=
null
fun
show
(
activity
:
Activity
,
adEvent
:
AdEvent
,
showCallBack
:
AdsShowCallBack
?)
{
fun
show
(
activity
:
Activity
,
isUnLimit
:
Boolean
,
adEvent
:
AdEvent
,
showCallBack
:
AdsShowCallBack
?
)
{
if
(
activity
.
isFinishing
||
activity
.
isDestroyed
)
{
return
}
if
(!
adEvent
.
isUnLimit
)
{
if
(!
LimitUtils
.
isAdShow
(
AdsType
.
OPEN
,
adEvent
))
{
val
nowAdEvent
=
adState
.
currentAdEvent
?:
adEvent
nowAdEvent
.
from
=
adEvent
.
from
nowAdEvent
.
isUnLimit
=
isUnLimit
if
(!
nowAdEvent
.
isUnLimit
)
{
if
(!
LimitUtils
.
isAdShow
(
AdsType
.
OPEN
,
nowAdEvent
))
{
showCallBack
?.
failed
()
return
}
if
(
LimitUtils
.
isIntervalLimited
(
a
dEvent
))
{
if
(
LimitUtils
.
isIntervalLimited
(
nowA
dEvent
))
{
showCallBack
?.
failed
()
return
}
}
adEvent
.
adPrepareShow
()
val
needLoad
=
!
adState
.
adAvailable
()
adState
.
activityRef
=
WeakReference
(
activity
)
this
.
showCallBack
=
showCallBack
// if (adState.adDialog == null) {
// adState.adDialog = activity.showAdPreparingDialog(1)
// } else {
// adState.adDialog?.dismiss()
// }
val
needLoad
=
adState
.
currentAd
==
null
||
!
adAvailable
()
nowAdEvent
.
adPrepareShow
()
if
(
needLoad
)
{
if
(!
adState
.
loadingAd
)
{
LogEx
.
logDebug
(
adEvent
.
TAG
,
"open adState !loadingAd"
)
loadAd
(
activity
,
adEvent
)
{
showReadyAd
(
adEvent
)
showReadyAd
()
}
}
else
{
LogEx
.
logDebug
(
adEvent
.
TAG
,
"open adState is loadingAd"
)
loadingCallBack
=
{
showReadyAd
()
}
}
}
else
{
showReadyAd
(
adEvent
)
LogEx
.
logDebug
(
adEvent
.
TAG
,
"open ad ready"
)
showReadyAd
()
}
}
private
fun
showReadyAd
(
adEvent
:
AdEvent
)
{
private
fun
showReadyAd
()
{
val
ac
=
adState
.
activityRef
?.
get
()
if
(
ac
==
null
||
ac
.
isFinishing
||
ac
.
isDestroyed
)
{
...
...
@@ -72,10 +87,13 @@ class AdOpenMgr {
}
adState
.
currentAd
?.
run
{
val
adEvent
=
adState
.
currentAdEvent
as
AdmobEvent
?
fullScreenContentCallback
=
object
:
FullScreenContentCallback
()
{
override
fun
onAdShowedFullScreenContent
()
{
(
adEvent
as
AdmobEvent
)
.
showAd
(
this
@run
.
responseInfo
,
ac
)
adEvent
?
.
showAd
(
this
@run
.
responseInfo
,
ac
)
showCallBack
?.
show
()
...
...
@@ -92,7 +110,7 @@ class AdOpenMgr {
showCallBack
=
null
adState
.
onAdDisplayFailed
()
(
adEvent
as
AdmobEvent
)
.
adShowError
(
adError
)
adEvent
?
.
adShowError
(
adError
)
}
...
...
@@ -110,7 +128,7 @@ class AdOpenMgr {
}
override
fun
onAdClicked
()
{
(
adEvent
as
AdmobEvent
)
.
clickAd
(
this
@run
.
responseInfo
)
adEvent
?
.
clickAd
(
this
@run
.
responseInfo
)
//计数
LimitUtils
.
addClickNum
()
}
...
...
@@ -135,6 +153,15 @@ class AdOpenMgr {
}
}
//避免无效预加载
if
(
adState
.
loadingAd
&&
loadCallBack
==
null
&&
loadingCallBack
==
null
)
{
//容错机制
adState
.
loadingAd
=
false
return
}
adState
.
loadingAd
=
true
adState
.
currentAdEvent
=
adEvent
adEvent
.
adPulStart
()
AppOpenAd
.
load
(
...
...
@@ -143,8 +170,12 @@ class AdOpenMgr {
AdRequest
.
Builder
().
build
(),
object
:
AppOpenAd
.
AppOpenAdLoadCallback
()
{
override
fun
onAdLoaded
(
appOpenAd
:
AppOpenAd
)
{
adState
.
onAdLoaded
(
appOpenAd
)
adState
.
onAdLoaded
(
appOpenAd
,
adEvent
)
loadCallBack
?.
invoke
()
loadingCallBack
?.
invoke
()
loadingCallBack
=
null
(
adEvent
as
AdmobEvent
).
pullAd
(
appOpenAd
.
responseInfo
)
appOpenAd
.
onPaidEventListener
=
AdmobOnPaidEventListener
(
appOpenAd
,
adEvent
.
scope
)
LimitUtils
.
addRequestNum
()
...
...
@@ -160,5 +191,4 @@ class AdOpenMgr {
)
}
private
fun
adAvailable
()
=
((
System
.
currentTimeMillis
()
-
adState
.
lastLoadTime
)
/
1000
/
60
).
toInt
()
<
30
}
\ No newline at end of file
app/src/main/java/com/base/appzxhy/business/ads/admob/AdmobEvent.kt
View file @
126e5240
...
...
@@ -27,7 +27,6 @@ import com.google.firebase.analytics.ktx.analytics
import
com.google.firebase.ktx.Firebase
import
kotlinx.coroutines.CoroutineScope
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.MainScope
import
kotlinx.coroutines.SupervisorJob
import
kotlinx.coroutines.launch
import
org.json.JSONObject
...
...
app/src/main/java/com/base/appzxhy/business/ads/applovin/MaxInsertMgr.kt
View file @
126e5240
...
...
@@ -145,7 +145,7 @@ class MaxInsertMgr {
override
fun
onAdDisplayFailed
(
p0
:
MaxAd
,
p1
:
MaxError
)
=
Unit
override
fun
onAdLoaded
(
ad
:
MaxAd
)
{
adState
.
onAdLoaded
(
null
)
adState
.
onAdLoaded
(
null
,
adEvent
)
val
ac
=
adState
.
activityRef
?.
get
()
if
(
ac
!=
null
)
{
show
(
ac
,
isUnLimit
,
adEvent
,
null
)
...
...
app/src/main/java/com/base/appzxhy/business/ads/applovin/MaxOpenMgr.kt
View file @
126e5240
...
...
@@ -126,7 +126,7 @@ class MaxOpenMgr {
adState
.
currentAd
=
MaxAppOpenAd
(
GlobalConfig
.
ID_MAX_OPEN
,
context
)
adState
.
currentAd
?.
setListener
(
object
:
MaxAdListener
{
override
fun
onAdLoaded
(
ad
:
MaxAd
)
{
adState
.
onAdLoaded
(
null
)
adState
.
onAdLoaded
(
null
,
adEvent
)
val
ac
=
adState
.
activityRef
?.
get
()
if
(
ac
!=
null
)
{
show
(
ac
,
isUnLimit
,
adEvent
,
null
)
...
...
app/src/main/java/com/base/appzxhy/ui/guide/GuideCleanActivity.kt
View file @
126e5240
...
...
@@ -11,12 +11,14 @@ class GuideCleanActivity : BaseActivity<ActivityGuideCleanBinding>(ActivityGuide
override
fun
initView
()
{
super
.
initView
()
changeLanguage
(
this
)
val
flag
=
changeLanguage
(
this
)
if
(!
flag
)
{
changeNative
()
}
}
override
fun
initListener
()
{
super
.
initListener
()
changeNative
()
binding
.
llPhoto
.
setOnClickListener
{
binding
.
iv1
.
isSelected
=
!
binding
.
iv1
.
isSelected
changeNative
()
...
...
@@ -48,8 +50,10 @@ class GuideCleanActivity : BaseActivity<ActivityGuideCleanBinding>(ActivityGuide
private
fun
changeNative
()
{
AdsMgr
.
showNative
(
binding
.
flAd
,
R
.
layout
.
layout_admob_native_custom
)
{
binding
.
flAd
.
removeAllViews
()
binding
.
flAd
.
visibility
=
View
.
VISIBLE
if
(
it
==
null
)
{
binding
.
flAd
.
removeAllViews
()
binding
.
flAd
.
visibility
=
View
.
VISIBLE
}
}
}
}
\ No newline at end of file
app/src/main/java/com/base/appzxhy/ui/language/LanguageActivity.kt
View file @
126e5240
...
...
@@ -71,7 +71,7 @@ class LanguageActivity : BaseActivity<ActivityLanguageBinding>(ActivityLanguageB
appLanguageSp
=
selectLanguageBean
.
language
appLanguageCountrySp
=
selectLanguageBean
.
country
AdsMgr
.
showInsert
(
this
,
showCallBack
=
object
:
AdsShowCallBack
()
{
AdsMgr
.
showInsert
(
this
,
true
,
showCallBack
=
object
:
AdsShowCallBack
()
{
override
fun
next
()
{
goToAc
(
GuideCleanActivity
::
class
.
java
)
finish
()
...
...
app/src/main/java/com/base/appzxhy/ui/splash/SplashActivity.kt
View file @
126e5240
...
...
@@ -92,7 +92,7 @@ class SplashActivity : BaseActivity<ActivitySplashBinding>(ActivitySplashBinding
jumpNext
()
}
viewModel
.
onTick
=
{
s
,
t
,
p
->
Log
.
e
(
TAG
,
"onTick $s $t"
)
//
Log.e(TAG, "onTick $s $t")
binding
.
progressBar
.
setProgress
(
p
.
toInt
(),
false
)
}
}
...
...
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