Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
E
Easy Cleaner Junk
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
Easy Cleaner Junk
Commits
5e915ed4
Commit
5e915ed4
authored
Jul 02, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
17c92327
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
83 additions
and
75 deletions
+83
-75
AdmobUtils.kt
...ava/com/test/easy/easycleanerjunk/helps/ads/AdmobUtils.kt
+83
-75
No files found.
app/src/main/java/com/test/easy/easycleanerjunk/helps/ads/AdmobUtils.kt
View file @
5e915ed4
...
...
@@ -61,24 +61,24 @@ object AdmobUtils {
obj
.
put
(
"ad_type"
,
"openAd"
)
EventUtils
.
event
(
"ad_pull_start"
,
ext
=
obj
)
AppOpenAd
.
load
(
BaseApplication
.
context
,
ConfigHelper
.
openAdmobId
,
mRequest
,
object
:
AppOpenAd
.
AppOpenAdLoadCallback
()
{
override
fun
onAdLoaded
(
ad
:
AppOpenAd
)
{
openLoadTime
=
System
.
currentTimeMillis
()
mOpenAd
=
ad
onLoad
?.
invoke
()
pull
(
ad
.
responseInfo
,
"openAd"
,
reqId
=
reqId
)
ad
.
onPaidEventListener
=
EventOnPaidEventListener
(
ad
)
}
BaseApplication
.
context
,
ConfigHelper
.
openAdmobId
,
mRequest
,
object
:
AppOpenAd
.
AppOpenAdLoadCallback
()
{
override
fun
onAdLoaded
(
ad
:
AppOpenAd
)
{
openLoadTime
=
System
.
currentTimeMillis
()
mOpenAd
=
ad
onLoad
?.
invoke
()
pull
(
ad
.
responseInfo
,
"openAd"
,
reqId
=
reqId
)
ad
.
onPaidEventListener
=
EventOnPaidEventListener
(
ad
)
}
override
fun
onAdFailedToLoad
(
p0
:
LoadAdError
)
{
mOpenAd
=
null
onLoad
?.
invoke
()
pull
(
p0
.
responseInfo
,
"openAd"
,
p0
.
message
,
reqId
=
reqId
)
}
})
override
fun
onAdFailedToLoad
(
p0
:
LoadAdError
)
{
mOpenAd
=
null
onLoad
?.
invoke
()
pull
(
p0
.
responseInfo
,
"openAd"
,
p0
.
message
,
reqId
=
reqId
)
}
})
}
fun
isOpenAdLoaded
()
=
mOpenAd
!=
null
...
...
@@ -202,7 +202,7 @@ object AdmobUtils {
obj
.
put
(
"ad_type"
,
"nativeAd"
)
val
adLoader
=
AdLoader
.
Builder
(
BaseApplication
.
context
,
ConfigHelper
.
nativeAdmobId
BaseApplication
.
context
,
ConfigHelper
.
nativeAdmobId
).
forNativeAd
{
nativeLoadTime
=
System
.
currentTimeMillis
()
nativeAd
=
it
...
...
@@ -244,32 +244,32 @@ object AdmobUtils {
obj
.
put
(
"from"
,
activity
.
javaClass
.
simpleName
)
EventUtils
.
event
(
"ad_pull_start"
,
ext
=
obj
)
InterstitialAd
.
load
(
activity
,
ConfigHelper
.
interAdmobId
,
mRequest
,
object
:
InterstitialAdLoadCallback
()
{
override
fun
onAdFailedToLoad
(
p0
:
LoadAdError
)
{
interAd
=
null
onLoad
?.
invoke
()
pull
(
p0
.
responseInfo
,
"interAd"
,
p0
.
message
,
reqId
=
reqId
)
if
(
BuildConfig
.
DEBUG
)
{
Toast
.
makeText
(
BaseApplication
.
context
,
"拉取失败"
+
p0
.
message
,
Toast
.
LENGTH_SHORT
).
show
()
}
activity
,
ConfigHelper
.
interAdmobId
,
mRequest
,
object
:
InterstitialAdLoadCallback
()
{
override
fun
onAdFailedToLoad
(
p0
:
LoadAdError
)
{
interAd
=
null
onLoad
?.
invoke
()
pull
(
p0
.
responseInfo
,
"interAd"
,
p0
.
message
,
reqId
=
reqId
)
if
(
BuildConfig
.
DEBUG
)
{
Toast
.
makeText
(
BaseApplication
.
context
,
"拉取失败"
+
p0
.
message
,
Toast
.
LENGTH_SHORT
).
show
()
}
override
fun
onAdLoaded
(
ad
:
InterstitialAd
)
{
interAd
=
ad
onLoad
?.
invoke
()
interLoadTime
=
System
.
currentTimeMillis
()
pull
(
ad
.
responseInfo
,
"interAd"
,
reqId
=
reqId
)
ad
.
onPaidEventListener
=
EventOnPaidEventListener
(
ad
)
}
})
}
override
fun
onAdLoaded
(
ad
:
InterstitialAd
)
{
interAd
=
ad
onLoad
?.
invoke
()
interLoadTime
=
System
.
currentTimeMillis
()
pull
(
ad
.
responseInfo
,
"interAd"
,
reqId
=
reqId
)
ad
.
onPaidEventListener
=
EventOnPaidEventListener
(
ad
)
}
})
}
private
fun
isAdExpired
():
Boolean
{
...
...
@@ -280,10 +280,10 @@ object AdmobUtils {
var
adLastDisplayTime
:
Long
=
0
fun
showInterstitialAd
(
activity
:
Activity
,
isLoadAdNow
:
Boolean
=
false
,
isShowInterVal
:
Boolean
=
true
,
onHidden
:
(()
->
Unit
)?
=
null
activity
:
Activity
,
isLoadAdNow
:
Boolean
=
false
,
isShowInterVal
:
Boolean
=
true
,
onHidden
:
(()
->
Unit
)?
=
null
)
{
if
(
activity
.
isFinishing
||
activity
.
isDestroyed
)
{
return
...
...
@@ -308,16 +308,22 @@ object AdmobUtils {
}
val
interval
=
isTimeElapsed
()
if
(
interval
<=
0
||
!
isShowInterVal
)
{
showCachedInterstitialAd
(
activity
,
isLoadAdNow
,
onHidden
)
if
(
interval
<=
0
||
!
isShowInterVal
)
{
showCachedInterstitialAd
(
activity
,
isLoadAdNow
,
isShowInterVal
,
onHidden
)
}
else
{
showIntervalDialogAndShowAd
(
activity
,
isLoadAdNow
,
onHidden
,
interval
)
showIntervalDialogAndShowAd
(
activity
,
isLoadAdNow
,
isShowInterVal
,
onHidden
,
interval
)
}
}
private
var
customDialog
:
CustomDialog
?
=
null
private
fun
showIntervalDialogAndShowAd
(
activity
:
Activity
,
isLoadAdNow
:
Boolean
,
onHidden
:
(()
->
Unit
)?,
interval
:
Int
)
{
private
fun
showIntervalDialogAndShowAd
(
activity
:
Activity
,
isLoadAdNow
:
Boolean
,
isShowInterVal
:
Boolean
,
onHidden
:
(()
->
Unit
)?,
interval
:
Int
)
{
if
(
customDialog
!=
null
&&
customDialog
?.
isShowing
==
true
)
{
return
// 如果对话框已经显示,则不再显示
}
...
...
@@ -331,7 +337,7 @@ object AdmobUtils {
}
override
fun
onFinish
()
{
showCachedInterstitialAd
(
activity
,
isLoadAdNow
,
onHidden
)
showCachedInterstitialAd
(
activity
,
isLoadAdNow
,
isShowInterVal
,
onHidden
)
customDialog
?.
dismiss
()
customDialog
=
null
}
...
...
@@ -342,14 +348,15 @@ object AdmobUtils {
private
fun
showCachedInterstitialAd
(
activity
:
Activity
,
isLoadAdNow
:
Boolean
,
onHidden
:
(()
->
Unit
)?
activity
:
Activity
,
isLoadAdNow
:
Boolean
,
isShowInterVal
:
Boolean
=
true
,
onHidden
:
(()
->
Unit
)?
)
{
if
(
interAd
!=
null
)
{
displayInterstitialAd
(
activity
,
onHidden
)
}
else
{
showAdDialogAndLoadInterstitial
(
activity
,
isLoadAdNow
,
onHidden
)
showAdDialogAndLoadInterstitial
(
activity
,
isLoadAdNow
,
isShowInterVal
,
onHidden
)
}
}
...
...
@@ -361,9 +368,10 @@ object AdmobUtils {
private
fun
showAdDialogAndLoadInterstitial
(
activity
:
Activity
,
isLoadAdNow
:
Boolean
,
onHidden
:
(()
->
Unit
)?
activity
:
Activity
,
isLoadAdNow
:
Boolean
,
isShowInterVal
:
Boolean
,
onHidden
:
(()
->
Unit
)?
)
{
var
mDialog
:
Dialog
?
=
null
if
(!
activity
.
isFinishing
&&
!
activity
.
isDestroyed
)
{
...
...
@@ -376,7 +384,7 @@ object AdmobUtils {
loadInterstitialAd
(
activity
)
{
mDialog
?.
dismiss
()
if
(!
isLoadAdNow
)
{
showInterstitialAd
(
activity
,
true
)
{
showInterstitialAd
(
activity
,
true
,
isShowInterVal
)
{
onHidden
?.
invoke
()
}
}
...
...
@@ -429,7 +437,7 @@ object AdmobUtils {
multiClick
++
if
(
multiClick
>=
maxMultiClick
)
{
AdDisplayUtils
.
getInstance
()
.
setAdClickCount
(
AdDisplayUtils
.
getInstance
().
maxAdClickCount
)
.
setAdClickCount
(
AdDisplayUtils
.
getInstance
().
maxAdClickCount
)
ActivityManagerUtils
.
getInstance
().
finishAllActivity
()
return
}
...
...
@@ -442,10 +450,10 @@ object AdmobUtils {
}
private
fun
pull
(
responseInfo
:
ResponseInfo
?,
adUnit
:
String
,
error
:
String
?
=
null
,
reqId
:
String
?
=
null
responseInfo
:
ResponseInfo
?,
adUnit
:
String
,
error
:
String
?
=
null
,
reqId
:
String
?
=
null
)
{
val
obj
=
JSONObject
()
if
(
responseInfo
!=
null
)
{
...
...
@@ -454,9 +462,9 @@ object AdmobUtils {
obj
.
put
(
"source"
,
response
.
adSourceName
)
val
credentials
=
mapOf
(
"placementid"
to
response
.
credentials
.
get
(
"placementid"
),
"appid"
to
response
.
credentials
.
get
(
"appid"
),
"pubid"
to
response
.
credentials
.
get
(
"pubid"
)
"placementid"
to
response
.
credentials
.
get
(
"placementid"
),
"appid"
to
response
.
credentials
.
get
(
"appid"
),
"pubid"
to
response
.
credentials
.
get
(
"pubid"
)
)
obj
.
put
(
"credentials"
,
credentials
.
toString
())
}
...
...
@@ -481,9 +489,9 @@ object AdmobUtils {
obj
.
put
(
"ad_unit"
,
adUnit
)
obj
.
put
(
"networkname"
,
responseInfo
?.
mediationAdapterClassName
)
val
credentials
=
mapOf
(
"placementid"
to
response
?.
credentials
?.
get
(
"placementid"
),
"appid"
to
response
?.
credentials
?.
get
(
"appid"
),
"pubid"
to
response
?.
credentials
?.
get
(
"pubid"
)
"placementid"
to
response
?.
credentials
?.
get
(
"placementid"
),
"appid"
to
response
?.
credentials
?.
get
(
"appid"
),
"pubid"
to
response
?.
credentials
?.
get
(
"pubid"
)
)
obj
.
put
(
"credentials"
,
credentials
.
toString
())
obj
.
put
(
"session_id"
,
responseInfo
?.
responseId
)
...
...
@@ -505,9 +513,9 @@ object AdmobUtils {
obj
.
put
(
"ad_unit"
,
adUnit
)
val
credentials
=
mapOf
(
"placementid"
to
response
?.
credentials
?.
get
(
"placementid"
),
"appid"
to
response
?.
credentials
?.
get
(
"appid"
),
"pubid"
to
response
?.
credentials
?.
get
(
"pubid"
)
"placementid"
to
response
?.
credentials
?.
get
(
"placementid"
),
"appid"
to
response
?.
credentials
?.
get
(
"appid"
),
"pubid"
to
response
?.
credentials
?.
get
(
"pubid"
)
)
obj
.
put
(
"credentials"
,
credentials
.
toString
())
obj
.
put
(
"session_id"
,
responseInfo
?.
responseId
)
...
...
@@ -560,8 +568,8 @@ object AdmobUtils {
if
(
currentTaichiTroasCache
>=
0.01
)
{
//如果超过0.01就触发一次tROAS taichi事件
val
roasbundle
=
Bundle
()
roasbundle
.
putDouble
(
FirebaseAnalytics
.
Param
.
VALUE
,
currentTaichiTroasCache
.
toDouble
()
FirebaseAnalytics
.
Param
.
VALUE
,
currentTaichiTroasCache
.
toDouble
()
)
roasbundle
.
putString
(
FirebaseAnalytics
.
Param
.
CURRENCY
,
"USD"
)
Firebase
.
analytics
.
logEvent
(
"Total_Ads_Revenue_001"
,
roasbundle
)
...
...
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