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 {
...
@@ -61,24 +61,24 @@ object AdmobUtils {
obj
.
put
(
"ad_type"
,
"openAd"
)
obj
.
put
(
"ad_type"
,
"openAd"
)
EventUtils
.
event
(
"ad_pull_start"
,
ext
=
obj
)
EventUtils
.
event
(
"ad_pull_start"
,
ext
=
obj
)
AppOpenAd
.
load
(
AppOpenAd
.
load
(
BaseApplication
.
context
,
BaseApplication
.
context
,
ConfigHelper
.
openAdmobId
,
ConfigHelper
.
openAdmobId
,
mRequest
,
mRequest
,
object
:
AppOpenAd
.
AppOpenAdLoadCallback
()
{
object
:
AppOpenAd
.
AppOpenAdLoadCallback
()
{
override
fun
onAdLoaded
(
ad
:
AppOpenAd
)
{
override
fun
onAdLoaded
(
ad
:
AppOpenAd
)
{
openLoadTime
=
System
.
currentTimeMillis
()
openLoadTime
=
System
.
currentTimeMillis
()
mOpenAd
=
ad
mOpenAd
=
ad
onLoad
?.
invoke
()
onLoad
?.
invoke
()
pull
(
ad
.
responseInfo
,
"openAd"
,
reqId
=
reqId
)
pull
(
ad
.
responseInfo
,
"openAd"
,
reqId
=
reqId
)
ad
.
onPaidEventListener
=
EventOnPaidEventListener
(
ad
)
ad
.
onPaidEventListener
=
EventOnPaidEventListener
(
ad
)
}
}
override
fun
onAdFailedToLoad
(
p0
:
LoadAdError
)
{
override
fun
onAdFailedToLoad
(
p0
:
LoadAdError
)
{
mOpenAd
=
null
mOpenAd
=
null
onLoad
?.
invoke
()
onLoad
?.
invoke
()
pull
(
p0
.
responseInfo
,
"openAd"
,
p0
.
message
,
reqId
=
reqId
)
pull
(
p0
.
responseInfo
,
"openAd"
,
p0
.
message
,
reqId
=
reqId
)
}
}
})
})
}
}
fun
isOpenAdLoaded
()
=
mOpenAd
!=
null
fun
isOpenAdLoaded
()
=
mOpenAd
!=
null
...
@@ -202,7 +202,7 @@ object AdmobUtils {
...
@@ -202,7 +202,7 @@ object AdmobUtils {
obj
.
put
(
"ad_type"
,
"nativeAd"
)
obj
.
put
(
"ad_type"
,
"nativeAd"
)
val
adLoader
=
AdLoader
.
Builder
(
val
adLoader
=
AdLoader
.
Builder
(
BaseApplication
.
context
,
ConfigHelper
.
nativeAdmobId
BaseApplication
.
context
,
ConfigHelper
.
nativeAdmobId
).
forNativeAd
{
).
forNativeAd
{
nativeLoadTime
=
System
.
currentTimeMillis
()
nativeLoadTime
=
System
.
currentTimeMillis
()
nativeAd
=
it
nativeAd
=
it
...
@@ -244,32 +244,32 @@ object AdmobUtils {
...
@@ -244,32 +244,32 @@ object AdmobUtils {
obj
.
put
(
"from"
,
activity
.
javaClass
.
simpleName
)
obj
.
put
(
"from"
,
activity
.
javaClass
.
simpleName
)
EventUtils
.
event
(
"ad_pull_start"
,
ext
=
obj
)
EventUtils
.
event
(
"ad_pull_start"
,
ext
=
obj
)
InterstitialAd
.
load
(
InterstitialAd
.
load
(
activity
,
activity
,
ConfigHelper
.
interAdmobId
,
ConfigHelper
.
interAdmobId
,
mRequest
,
mRequest
,
object
:
InterstitialAdLoadCallback
()
{
object
:
InterstitialAdLoadCallback
()
{
override
fun
onAdFailedToLoad
(
p0
:
LoadAdError
)
{
override
fun
onAdFailedToLoad
(
p0
:
LoadAdError
)
{
interAd
=
null
interAd
=
null
onLoad
?.
invoke
()
onLoad
?.
invoke
()
pull
(
p0
.
responseInfo
,
"interAd"
,
p0
.
message
,
reqId
=
reqId
)
pull
(
p0
.
responseInfo
,
"interAd"
,
p0
.
message
,
reqId
=
reqId
)
if
(
BuildConfig
.
DEBUG
)
{
if
(
BuildConfig
.
DEBUG
)
{
Toast
.
makeText
(
Toast
.
makeText
(
BaseApplication
.
context
,
BaseApplication
.
context
,
"拉取失败"
+
p0
.
message
,
"拉取失败"
+
p0
.
message
,
Toast
.
LENGTH_SHORT
Toast
.
LENGTH_SHORT
).
show
()
).
show
()
}
}
}
override
fun
onAdLoaded
(
ad
:
InterstitialAd
)
{
}
interAd
=
ad
onLoad
?.
invoke
()
override
fun
onAdLoaded
(
ad
:
InterstitialAd
)
{
interLoadTime
=
System
.
currentTimeMillis
()
interAd
=
ad
pull
(
ad
.
responseInfo
,
"interAd"
,
reqId
=
reqId
)
onLoad
?.
invoke
()
ad
.
onPaidEventListener
=
EventOnPaidEventListener
(
ad
)
interLoadTime
=
System
.
currentTimeMillis
()
}
pull
(
ad
.
responseInfo
,
"interAd"
,
reqId
=
reqId
)
})
ad
.
onPaidEventListener
=
EventOnPaidEventListener
(
ad
)
}
})
}
}
private
fun
isAdExpired
():
Boolean
{
private
fun
isAdExpired
():
Boolean
{
...
@@ -280,10 +280,10 @@ object AdmobUtils {
...
@@ -280,10 +280,10 @@ object AdmobUtils {
var
adLastDisplayTime
:
Long
=
0
var
adLastDisplayTime
:
Long
=
0
fun
showInterstitialAd
(
fun
showInterstitialAd
(
activity
:
Activity
,
activity
:
Activity
,
isLoadAdNow
:
Boolean
=
false
,
isLoadAdNow
:
Boolean
=
false
,
isShowInterVal
:
Boolean
=
true
,
isShowInterVal
:
Boolean
=
true
,
onHidden
:
(()
->
Unit
)?
=
null
onHidden
:
(()
->
Unit
)?
=
null
)
{
)
{
if
(
activity
.
isFinishing
||
activity
.
isDestroyed
)
{
if
(
activity
.
isFinishing
||
activity
.
isDestroyed
)
{
return
return
...
@@ -308,16 +308,22 @@ object AdmobUtils {
...
@@ -308,16 +308,22 @@ object AdmobUtils {
}
}
val
interval
=
isTimeElapsed
()
val
interval
=
isTimeElapsed
()
if
(
interval
<=
0
||
!
isShowInterVal
)
{
if
(
interval
<=
0
||
!
isShowInterVal
)
{
showCachedInterstitialAd
(
activity
,
isLoadAdNow
,
onHidden
)
showCachedInterstitialAd
(
activity
,
isLoadAdNow
,
isShowInterVal
,
onHidden
)
}
else
{
}
else
{
showIntervalDialogAndShowAd
(
activity
,
isLoadAdNow
,
onHidden
,
interval
)
showIntervalDialogAndShowAd
(
activity
,
isLoadAdNow
,
isShowInterVal
,
onHidden
,
interval
)
}
}
}
}
private
var
customDialog
:
CustomDialog
?
=
null
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
)
{
if
(
customDialog
!=
null
&&
customDialog
?.
isShowing
==
true
)
{
return
// 如果对话框已经显示,则不再显示
return
// 如果对话框已经显示,则不再显示
}
}
...
@@ -331,7 +337,7 @@ object AdmobUtils {
...
@@ -331,7 +337,7 @@ object AdmobUtils {
}
}
override
fun
onFinish
()
{
override
fun
onFinish
()
{
showCachedInterstitialAd
(
activity
,
isLoadAdNow
,
onHidden
)
showCachedInterstitialAd
(
activity
,
isLoadAdNow
,
isShowInterVal
,
onHidden
)
customDialog
?.
dismiss
()
customDialog
?.
dismiss
()
customDialog
=
null
customDialog
=
null
}
}
...
@@ -342,14 +348,15 @@ object AdmobUtils {
...
@@ -342,14 +348,15 @@ object AdmobUtils {
private
fun
showCachedInterstitialAd
(
private
fun
showCachedInterstitialAd
(
activity
:
Activity
,
activity
:
Activity
,
isLoadAdNow
:
Boolean
,
isLoadAdNow
:
Boolean
,
onHidden
:
(()
->
Unit
)?
isShowInterVal
:
Boolean
=
true
,
onHidden
:
(()
->
Unit
)?
)
{
)
{
if
(
interAd
!=
null
)
{
if
(
interAd
!=
null
)
{
displayInterstitialAd
(
activity
,
onHidden
)
displayInterstitialAd
(
activity
,
onHidden
)
}
else
{
}
else
{
showAdDialogAndLoadInterstitial
(
activity
,
isLoadAdNow
,
onHidden
)
showAdDialogAndLoadInterstitial
(
activity
,
isLoadAdNow
,
isShowInterVal
,
onHidden
)
}
}
}
}
...
@@ -361,9 +368,10 @@ object AdmobUtils {
...
@@ -361,9 +368,10 @@ object AdmobUtils {
private
fun
showAdDialogAndLoadInterstitial
(
private
fun
showAdDialogAndLoadInterstitial
(
activity
:
Activity
,
activity
:
Activity
,
isLoadAdNow
:
Boolean
,
isLoadAdNow
:
Boolean
,
onHidden
:
(()
->
Unit
)?
isShowInterVal
:
Boolean
,
onHidden
:
(()
->
Unit
)?
)
{
)
{
var
mDialog
:
Dialog
?
=
null
var
mDialog
:
Dialog
?
=
null
if
(!
activity
.
isFinishing
&&
!
activity
.
isDestroyed
)
{
if
(!
activity
.
isFinishing
&&
!
activity
.
isDestroyed
)
{
...
@@ -376,7 +384,7 @@ object AdmobUtils {
...
@@ -376,7 +384,7 @@ object AdmobUtils {
loadInterstitialAd
(
activity
)
{
loadInterstitialAd
(
activity
)
{
mDialog
?.
dismiss
()
mDialog
?.
dismiss
()
if
(!
isLoadAdNow
)
{
if
(!
isLoadAdNow
)
{
showInterstitialAd
(
activity
,
true
)
{
showInterstitialAd
(
activity
,
true
,
isShowInterVal
)
{
onHidden
?.
invoke
()
onHidden
?.
invoke
()
}
}
}
}
...
@@ -429,7 +437,7 @@ object AdmobUtils {
...
@@ -429,7 +437,7 @@ object AdmobUtils {
multiClick
++
multiClick
++
if
(
multiClick
>=
maxMultiClick
)
{
if
(
multiClick
>=
maxMultiClick
)
{
AdDisplayUtils
.
getInstance
()
AdDisplayUtils
.
getInstance
()
.
setAdClickCount
(
AdDisplayUtils
.
getInstance
().
maxAdClickCount
)
.
setAdClickCount
(
AdDisplayUtils
.
getInstance
().
maxAdClickCount
)
ActivityManagerUtils
.
getInstance
().
finishAllActivity
()
ActivityManagerUtils
.
getInstance
().
finishAllActivity
()
return
return
}
}
...
@@ -442,10 +450,10 @@ object AdmobUtils {
...
@@ -442,10 +450,10 @@ object AdmobUtils {
}
}
private
fun
pull
(
private
fun
pull
(
responseInfo
:
ResponseInfo
?,
responseInfo
:
ResponseInfo
?,
adUnit
:
String
,
adUnit
:
String
,
error
:
String
?
=
null
,
error
:
String
?
=
null
,
reqId
:
String
?
=
null
reqId
:
String
?
=
null
)
{
)
{
val
obj
=
JSONObject
()
val
obj
=
JSONObject
()
if
(
responseInfo
!=
null
)
{
if
(
responseInfo
!=
null
)
{
...
@@ -454,9 +462,9 @@ object AdmobUtils {
...
@@ -454,9 +462,9 @@ object AdmobUtils {
obj
.
put
(
"source"
,
response
.
adSourceName
)
obj
.
put
(
"source"
,
response
.
adSourceName
)
val
credentials
=
mapOf
(
val
credentials
=
mapOf
(
"placementid"
to
response
.
credentials
.
get
(
"placementid"
),
"placementid"
to
response
.
credentials
.
get
(
"placementid"
),
"appid"
to
response
.
credentials
.
get
(
"appid"
),
"appid"
to
response
.
credentials
.
get
(
"appid"
),
"pubid"
to
response
.
credentials
.
get
(
"pubid"
)
"pubid"
to
response
.
credentials
.
get
(
"pubid"
)
)
)
obj
.
put
(
"credentials"
,
credentials
.
toString
())
obj
.
put
(
"credentials"
,
credentials
.
toString
())
}
}
...
@@ -481,9 +489,9 @@ object AdmobUtils {
...
@@ -481,9 +489,9 @@ object AdmobUtils {
obj
.
put
(
"ad_unit"
,
adUnit
)
obj
.
put
(
"ad_unit"
,
adUnit
)
obj
.
put
(
"networkname"
,
responseInfo
?.
mediationAdapterClassName
)
obj
.
put
(
"networkname"
,
responseInfo
?.
mediationAdapterClassName
)
val
credentials
=
mapOf
(
val
credentials
=
mapOf
(
"placementid"
to
response
?.
credentials
?.
get
(
"placementid"
),
"placementid"
to
response
?.
credentials
?.
get
(
"placementid"
),
"appid"
to
response
?.
credentials
?.
get
(
"appid"
),
"appid"
to
response
?.
credentials
?.
get
(
"appid"
),
"pubid"
to
response
?.
credentials
?.
get
(
"pubid"
)
"pubid"
to
response
?.
credentials
?.
get
(
"pubid"
)
)
)
obj
.
put
(
"credentials"
,
credentials
.
toString
())
obj
.
put
(
"credentials"
,
credentials
.
toString
())
obj
.
put
(
"session_id"
,
responseInfo
?.
responseId
)
obj
.
put
(
"session_id"
,
responseInfo
?.
responseId
)
...
@@ -505,9 +513,9 @@ object AdmobUtils {
...
@@ -505,9 +513,9 @@ object AdmobUtils {
obj
.
put
(
"ad_unit"
,
adUnit
)
obj
.
put
(
"ad_unit"
,
adUnit
)
val
credentials
=
mapOf
(
val
credentials
=
mapOf
(
"placementid"
to
response
?.
credentials
?.
get
(
"placementid"
),
"placementid"
to
response
?.
credentials
?.
get
(
"placementid"
),
"appid"
to
response
?.
credentials
?.
get
(
"appid"
),
"appid"
to
response
?.
credentials
?.
get
(
"appid"
),
"pubid"
to
response
?.
credentials
?.
get
(
"pubid"
)
"pubid"
to
response
?.
credentials
?.
get
(
"pubid"
)
)
)
obj
.
put
(
"credentials"
,
credentials
.
toString
())
obj
.
put
(
"credentials"
,
credentials
.
toString
())
obj
.
put
(
"session_id"
,
responseInfo
?.
responseId
)
obj
.
put
(
"session_id"
,
responseInfo
?.
responseId
)
...
@@ -560,8 +568,8 @@ object AdmobUtils {
...
@@ -560,8 +568,8 @@ object AdmobUtils {
if
(
currentTaichiTroasCache
>=
0.01
)
{
//如果超过0.01就触发一次tROAS taichi事件
if
(
currentTaichiTroasCache
>=
0.01
)
{
//如果超过0.01就触发一次tROAS taichi事件
val
roasbundle
=
Bundle
()
val
roasbundle
=
Bundle
()
roasbundle
.
putDouble
(
roasbundle
.
putDouble
(
FirebaseAnalytics
.
Param
.
VALUE
,
FirebaseAnalytics
.
Param
.
VALUE
,
currentTaichiTroasCache
.
toDouble
()
currentTaichiTroasCache
.
toDouble
()
)
)
roasbundle
.
putString
(
FirebaseAnalytics
.
Param
.
CURRENCY
,
"USD"
)
roasbundle
.
putString
(
FirebaseAnalytics
.
Param
.
CURRENCY
,
"USD"
)
Firebase
.
analytics
.
logEvent
(
"Total_Ads_Revenue_001"
,
roasbundle
)
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