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
1d1246a4
Commit
1d1246a4
authored
Jul 02, 2024
by
leichao.gao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
广告dialog优化
parent
aac77a51
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
86 additions
and
80 deletions
+86
-80
AdmobUtils.kt
...ava/com/test/easy/easycleanerjunk/helps/ads/AdmobUtils.kt
+86
-80
No files found.
app/src/main/java/com/test/easy/easycleanerjunk/helps/ads/AdmobUtils.kt
View file @
1d1246a4
...
@@ -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
)
{
override
fun
onAdLoaded
(
ad
:
InterstitialAd
)
{
interAd
=
ad
interAd
=
ad
onLoad
?.
invoke
()
onLoad
?.
invoke
()
interLoadTime
=
System
.
currentTimeMillis
()
interLoadTime
=
System
.
currentTimeMillis
()
pull
(
ad
.
responseInfo
,
"interAd"
,
reqId
=
reqId
)
pull
(
ad
.
responseInfo
,
"interAd"
,
reqId
=
reqId
)
ad
.
onPaidEventListener
=
EventOnPaidEventListener
(
ad
)
ad
.
onPaidEventListener
=
EventOnPaidEventListener
(
ad
)
}
}
})
})
}
}
private
fun
isAdExpired
():
Boolean
{
private
fun
isAdExpired
():
Boolean
{
...
@@ -280,9 +280,9 @@ object AdmobUtils {
...
@@ -280,9 +280,9 @@ object AdmobUtils {
var
adLastDisplayTime
:
Long
=
0
var
adLastDisplayTime
:
Long
=
0
fun
showInterstitialAd
(
fun
showInterstitialAd
(
activity
:
Activity
,
activity
:
Activity
,
isLoadAdNow
:
Boolean
=
false
,
isLoadAdNow
:
Boolean
=
false
,
onHidden
:
(()
->
Unit
)?
=
null
onHidden
:
(()
->
Unit
)?
=
null
)
{
)
{
if
(
activity
.
isFinishing
||
activity
.
isDestroyed
)
{
if
(
activity
.
isFinishing
||
activity
.
isDestroyed
)
{
return
return
...
@@ -314,34 +314,36 @@ object AdmobUtils {
...
@@ -314,34 +314,36 @@ object AdmobUtils {
}
}
}
}
private
fun
showIntervalDialogAndShowAd
(
private
var
customDialog
:
CustomDialog
?
=
null
activity
:
Activity
,
isLoadAdNow
:
Boolean
,
private
fun
showIntervalDialogAndShowAd
(
activity
:
Activity
,
isLoadAdNow
:
Boolean
,
onHidden
:
(()
->
Unit
)?,
interval
:
Int
)
{
onHidden
:
(()
->
Unit
)?,
if
(
customDialog
!=
null
&&
customDialog
?.
isShowing
==
true
)
{
interval
:
Int
return
// 如果对话框已经显示,则不再显示
)
{
}
val
customDialog
=
CustomDialog
(
activity
,
R
.
layout
.
dialog_ad_loading
)
customDialog
.
setCountdownText
(
R
.
id
.
dialog_ad_loading_text
)
customDialog
=
CustomDialog
(
activity
,
R
.
layout
.
dialog_ad_loading
)
customDialog
?.
setCountdownText
(
R
.
id
.
dialog_ad_loading_text
)
val
countdownTimer
=
object
:
CountDownTimer
((
interval
*
1000
).
toLong
(),
1000
)
{
val
countdownTimer
=
object
:
CountDownTimer
((
interval
*
1000
).
toLong
(),
1000
)
{
override
fun
onTick
(
millisUntilFinished
:
Long
)
{
override
fun
onTick
(
millisUntilFinished
:
Long
)
{
val
seconds
=
(
millisUntilFinished
/
1000
).
toInt
()
val
seconds
=
(
millisUntilFinished
/
1000
).
toInt
()
customDialog
.
updateCountdownText
(
"Advertising in preparation ($seconds"
+
"s)..."
)
customDialog
?
.
updateCountdownText
(
"Advertising in preparation ($seconds"
+
"s)..."
)
}
}
override
fun
onFinish
()
{
override
fun
onFinish
()
{
showCachedInterstitialAd
(
activity
,
isLoadAdNow
,
onHidden
)
showCachedInterstitialAd
(
activity
,
isLoadAdNow
,
onHidden
)
customDialog
?.
dismiss
()
customDialog
?.
dismiss
()
customDialog
.
dismiss
()
customDialog
=
null
}
}
}
}
countdownTimer
.
start
()
countdownTimer
.
start
()
customDialog
.
show
()
customDialog
?
.
show
()
}
}
private
fun
showCachedInterstitialAd
(
private
fun
showCachedInterstitialAd
(
activity
:
Activity
,
activity
:
Activity
,
isLoadAdNow
:
Boolean
,
isLoadAdNow
:
Boolean
,
onHidden
:
(()
->
Unit
)?
onHidden
:
(()
->
Unit
)?
)
{
)
{
if
(
interAd
!=
null
)
{
if
(
interAd
!=
null
)
{
displayInterstitialAd
(
activity
,
onHidden
)
displayInterstitialAd
(
activity
,
onHidden
)
...
@@ -358,13 +360,17 @@ object AdmobUtils {
...
@@ -358,13 +360,17 @@ object AdmobUtils {
private
fun
showAdDialogAndLoadInterstitial
(
private
fun
showAdDialogAndLoadInterstitial
(
activity
:
Activity
,
activity
:
Activity
,
isLoadAdNow
:
Boolean
,
isLoadAdNow
:
Boolean
,
onHidden
:
(()
->
Unit
)?
onHidden
:
(()
->
Unit
)?
)
{
)
{
var
mDialog
:
Dialog
?
=
null
var
mDialog
:
Dialog
?
=
null
mDialog
=
CustomDialog
(
activity
,
R
.
layout
.
dialog_ad_loading
)
if
(!
activity
.
isFinishing
&&
!
activity
.
isDestroyed
)
{
mDialog
.
show
()
mDialog
=
CustomDialog
(
activity
,
R
.
layout
.
dialog_ad_loading
)
// 设置对话框的样式和内容
mDialog
?.
show
()
}
loadInterstitialAd
(
activity
)
{
loadInterstitialAd
(
activity
)
{
mDialog
?.
dismiss
()
mDialog
?.
dismiss
()
...
@@ -422,7 +428,7 @@ object AdmobUtils {
...
@@ -422,7 +428,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
}
}
...
@@ -435,10 +441,10 @@ object AdmobUtils {
...
@@ -435,10 +441,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
)
{
...
@@ -447,9 +453,9 @@ object AdmobUtils {
...
@@ -447,9 +453,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
())
}
}
...
@@ -474,9 +480,9 @@ object AdmobUtils {
...
@@ -474,9 +480,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
)
...
@@ -498,9 +504,9 @@ object AdmobUtils {
...
@@ -498,9 +504,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
)
...
@@ -553,8 +559,8 @@ object AdmobUtils {
...
@@ -553,8 +559,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