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
2aadf2c5
Commit
2aadf2c5
authored
Jun 30, 2025
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[迭代]迭代广告
parent
32caa541
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
42 deletions
+51
-42
AdEvent.kt
app/src/main/java/com/rgt/superr/business/ads/AdEvent.kt
+6
-2
AdOpenMgr.kt
.../main/java/com/rgt/superr/business/ads/admob/AdOpenMgr.kt
+45
-38
AdmobEvent.kt
...main/java/com/rgt/superr/business/ads/admob/AdmobEvent.kt
+0
-2
No files found.
app/src/main/java/com/rgt/superr/business/ads/AdEvent.kt
View file @
2aadf2c5
...
...
@@ -3,6 +3,9 @@ package com.rgt.superr.business.ads
import
com.rgt.superr.MyApplication
import
com.rgt.superr.business.helper.EventUtils
import
com.rgt.superr.utils.LogEx
import
kotlinx.coroutines.CoroutineScope
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.SupervisorJob
import
org.json.JSONObject
import
java.util.UUID
...
...
@@ -25,6 +28,7 @@ abstract class AdEvent {
var
from
:
String
=
""
var
reqId
=
UUID
.
randomUUID
().
toString
()
var
isUnLimit
:
Boolean
=
false
val
scope
=
CoroutineScope
(
SupervisorJob
()
+
Dispatchers
.
IO
)
fun
adPrepareShow
()
{
...
...
@@ -49,8 +53,8 @@ abstract class AdEvent {
fun
adShowError
(
reason
:
Any
)
{
val
obj
=
JSONObject
()
obj
.
put
(
"ad_unit"
,
adUnit
)
obj
.
put
(
"req_id"
,
reqId
)
obj
.
put
(
"from"
,
from
)
obj
.
put
(
"req_id"
,
reqId
)
obj
.
put
(
"reason"
,
reason
.
toString
())
EventUtils
.
event
(
"ad_show_error"
,
ext
=
obj
)
LogEx
.
logDebug
(
TAG
,
"ad_show_error_$adUnit $obj"
)
...
...
@@ -59,8 +63,8 @@ abstract class AdEvent {
fun
adLimited
(
value
:
String
)
{
val
obj
=
JSONObject
()
obj
.
put
(
"ad_unit"
,
adUnit
)
obj
.
put
(
"req_id"
,
reqId
)
obj
.
put
(
"from"
,
from
)
obj
.
put
(
"req_id"
,
reqId
)
EventUtils
.
event
(
"ad_limit"
,
value
,
obj
)
LogEx
.
logDebug
(
TAG
,
"ad_limit_$adUnit $obj"
)
}
...
...
app/src/main/java/com/rgt/superr/business/ads/admob/AdOpenMgr.kt
View file @
2aadf2c5
...
...
@@ -15,6 +15,7 @@ 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
com.rgt.superr.business.ads.AdsType.Companion.OPEN
/**
...
...
@@ -27,7 +28,7 @@ class AdOpenMgr {
private
var
showCallBack
:
AdsShowCallBack
?
=
null
//正在加载回调
private
var
loadingCallBack
:
(()
->
Unit
)?
=
null
private
var
loadingCallBack
:
((
flag
:
Boolean
)
->
Unit
)?
=
null
fun
show
(
activity
:
Activity
,
...
...
@@ -38,65 +39,70 @@ class AdOpenMgr {
return
}
val
nowAdEvent
=
adEvent
adState
.
currentAdEvent
?.
let
{
nowAdEvent
.
reqId
=
it
.
reqId
}
adState
.
currentAdEvent
?.
let
{
adEvent
.
reqId
=
it
.
reqId
}
if
(!
nowA
dEvent
.
isUnLimit
)
{
if
(!
LimitUtils
.
isAdShow
(
AdsType
.
OPEN
,
nowA
dEvent
))
{
if
(!
a
dEvent
.
isUnLimit
)
{
if
(!
LimitUtils
.
isAdShow
(
AdsType
.
OPEN
,
a
dEvent
))
{
showCallBack
?.
failed
()
return
}
if
(
LimitUtils
.
isInterval
Limited
(
nowA
dEvent
))
{
if
(
LimitUtils
.
isInterval
OpenLimit
(
a
dEvent
))
{
showCallBack
?.
failed
()
return
}
}
val
needLoad
=
!
adState
.
needLoad
()
val
needLoad
=
adState
.
needLoad
()
this
.
showCallBack
=
showCallBack
nowA
dEvent
.
adPrepareShow
()
a
dEvent
.
adPrepareShow
()
if
(
needLoad
)
{
if
(!
adState
.
loadingAd
)
{
LogEx
.
logDebug
(
adEvent
.
TAG
,
"open adState !loadingAd"
)
loadAd
(
activity
,
adEvent
)
{
showReadyAd
(
activity
)
if
(
it
)
{
showReadyAd
(
activity
,
adEvent
)
}
else
{
showCallBack
?.
adFailed
()
}
}
}
else
{
LogEx
.
logDebug
(
adEvent
.
TAG
,
"open adState is loadingAd"
)
loadingCallBack
=
{
showReadyAd
(
activity
)
if
(
it
)
{
showReadyAd
(
activity
,
adEvent
)
}
else
{
showCallBack
?.
adFailed
()
}
}
}
}
else
{
LogEx
.
logDebug
(
adEvent
.
TAG
,
"open ad ready"
)
showReadyAd
(
activity
)
showReadyAd
(
activity
,
adEvent
)
}
}
private
fun
showReadyAd
(
ac
:
Activity
)
{
private
fun
showReadyAd
(
ac
:
Activity
,
adEvent
:
AdEvent
)
{
val
admobEvent
=
(
adEvent
as
AdmobEvent
)
// val ac = adState.activityRef?.get()
if
(
ac
.
isFinishing
||
ac
.
isDestroyed
||
adState
.
currentAd
==
null
)
{
LogEx
.
logDebug
(
TAG
,
"
showReadyAd ac=null isFinishing isDestroyed"
)
LogEx
.
logDebug
(
adEvent
.
TAG
,
"open
showReadyAd ac=null isFinishing isDestroyed"
)
return
}
adState
.
currentAd
?.
run
{
val
adEvent
=
adState
.
currentAdEvent
as
AdmobEvent
?
fullScreenContentCallback
=
object
:
FullScreenContentCallback
()
{
override
fun
onAdShowedFullScreenContent
()
{
adEvent
?.
showAd
(
this
@run
.
responseInfo
,
ac
)
adState
.
onAdDisplayed
(
OPEN
)
showCallBack
?.
show
()
adState
.
onAdDisplayed
()
//计数
LimitUtils
.
addDisplayNum
()
admobEvent
.
showAd
(
this
@run
.
responseInfo
,
ac
)
}
override
fun
onAdFailedToShowFullScreenContent
(
adError
:
AdError
)
{
...
...
@@ -106,25 +112,24 @@ class AdOpenMgr {
showCallBack
=
null
adState
.
onAdDisplayFailed
()
ad
Event
?
.
adShowError
(
adError
)
ad
mobEvent
.
adShowError
(
adError
)
}
override
fun
onAdDismissedFullScreenContent
()
{
super
.
onAdDismissedFullScreenContent
()
adState
.
onAdHidden
(
OPEN
)
showCallBack
?.
close
()
showCallBack
=
null
adState
.
onAdHidden
()
//预加载,“Timeout for show call succeed.”预加载的广告大概率,
loadAd
(
MyApplication
.
appContext
,
AdmobEvent
(
"openAd"
,
"preload"
))
}
override
fun
onAdClicked
()
{
ad
Event
?
.
clickAd
(
this
@run
.
responseInfo
)
ad
mobEvent
.
clickAd
(
this
@run
.
responseInfo
)
//计数
LimitUtils
.
addClickNum
()
}
...
...
@@ -136,7 +141,7 @@ class AdOpenMgr {
fun
loadAd
(
context
:
Context
,
adEvent
:
AdEvent
,
loadCallBack
:
(()
->
Unit
)?
=
null
loadCallBack
:
((
flag
:
Boolean
)
->
Unit
)?
=
null
)
{
if
(!
adEvent
.
isUnLimit
)
{
...
...
@@ -149,14 +154,12 @@ class AdOpenMgr {
}
//避免无效预加载
if
(
adState
.
loadingAd
&&
loadCallBack
==
null
&&
loadingCallBack
==
null
)
{
//容错机制
adState
.
loadingAd
=
false
if
(
adState
.
loadingAd
)
{
return
}
adState
.
loadingAd
=
true
adEvent
.
adPulStart
()
adState
.
loadStart
(
adEvent
)
AppOpenAd
.
load
(
context
,
...
...
@@ -164,27 +167,31 @@ class AdOpenMgr {
AdRequest
.
Builder
().
build
(),
object
:
AppOpenAd
.
AppOpenAdLoadCallback
()
{
override
fun
onAdLoaded
(
appOpenAd
:
AppOpenAd
)
{
val
event
=
(
adEvent
as
AdmobEvent
)
appOpenAd
.
onPaidEventListener
=
AdmobOnPaidEventListener
(
appOpenAd
,
adEvent
.
scope
)
LogEx
.
logDebug
(
adEvent
.
TAG
,
"open onAdLoaded loadAd"
)
adState
.
onAdLoaded
(
appOpenAd
,
adEvent
)
appOpenAd
.
onPaidEventListener
=
AdmobOnPaidEventListener
(
appOpenAd
,
adEvent
.
scope
)
adState
.
onAdLoaded
(
appOpenAd
)
loadCallBack
?.
invoke
()
loadingCallBack
?.
invoke
()
loadCallBack
?.
invoke
(
true
)
loadingCallBack
?.
invoke
(
true
)
loadingCallBack
=
null
LimitUtils
.
addRequestNum
()
event
.
pullAd
(
appOpenAd
.
responseInfo
)
(
adEvent
as
AdmobEvent
)
.
pullAd
(
appOpenAd
.
responseInfo
)
}
override
fun
onAdFailedToLoad
(
loadAdError
:
LoadAdError
)
{
showCallBack
?.
adFailed
()
showCallBack
=
null
LogEx
.
logDebug
(
adEvent
.
TAG
,
"open onAdFailedToLoad loadAd"
)
adState
.
onAdLoadFailed
()
loadCallBack
?.
invoke
(
false
)
loadingCallBack
?.
invoke
(
false
)
loadingCallBack
=
null
(
adEvent
as
AdmobEvent
).
pullAd
(
loadAdError
.
responseInfo
,
loadAdError
)
}
}
)
}
}
\ No newline at end of file
}
app/src/main/java/com/rgt/superr/business/ads/admob/AdmobEvent.kt
View file @
2aadf2c5
...
...
@@ -38,8 +38,6 @@ class AdmobEvent : AdEvent {
override
val
TAG
:
String
=
"AdmobEvent"
val
scope
=
CoroutineScope
(
SupervisorJob
()
+
Dispatchers
.
IO
)
constructor
(
adUnit
:
String
,
from
:
String
)
:
super
()
{
this
.
adUnit
=
adUnit
this
.
from
=
from
...
...
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