Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
F
File Recovery RecycleBin
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
File Recovery RecycleBin
Commits
71863dc9
Commit
71863dc9
authored
Jul 16, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
插页广告
parent
12a612cd
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
85 additions
and
6 deletions
+85
-6
AdMaxInterstitialUtils.kt
.../filerecoveryrecyclebin/ads/max/AdMaxInterstitialUtils.kt
+85
-6
No files found.
app/src/main/java/com/base/filerecoveryrecyclebin/ads/max/AdMaxInterstitialUtils.kt
View file @
71863dc9
package
com.base.filerecoveryrecyclebin.ads.max
import
android.annotation.SuppressLint
import
android.app.Activity
import
android.app.Dialog
import
android.os.CountDownTimer
import
android.os.Handler
import
com.applovin.mediation.MaxAd
import
com.applovin.mediation.MaxAdListener
import
com.applovin.mediation.MaxError
import
com.applovin.mediation.ads.MaxInterstitialAd
import
com.base.filerecoveryrecyclebin.R
import
com.base.filerecoveryrecyclebin.ads.AdDisplayUtils
import
com.base.filerecoveryrecyclebin.ads.AdmobCommonUtils
import
com.base.filerecoveryrecyclebin.ads.admob.AdmobEvent
import
com.base.filerecoveryrecyclebin.ads.admob.AdmobInterstitialUtils
import
com.base.filerecoveryrecyclebin.help.ConfigHelper
import
com.base.filerecoveryrecyclebin.utils.EventUtils
import
com.base.filerecoveryrecyclebin.utils.LogEx
import
com.base.filerecoveryrecyclebin.view.CustomDialog
import
com.google.android.gms.ads.AdError
import
com.google.android.gms.ads.FullScreenContentCallback
import
kotlinx.coroutines.MainScope
import
kotlinx.coroutines.delay
import
kotlinx.coroutines.launch
...
...
@@ -19,13 +30,17 @@ import kotlin.math.pow
object
AdMaxInterstitialUtils
{
private
val
TAG
=
"AdMaxInterstitialUtils"
private
var
interstitialAd
:
MaxInterstitialAd
?
=
null
private
var
interLoadTime
=
Long
.
MAX_VALUE
private
var
onHidden
:
(()
->
Unit
)?
=
null
private
var
loadingListener
:
(()
->
Unit
)?
=
null
private
var
retryAttempt
=
0
fun
setListener
(
activity
:
Activity
)
{
@SuppressLint
(
"StaticFieldLeak"
)
private
var
customDialog
:
CustomDialog
?
=
null
private
fun
setListener
(
activity
:
Activity
)
{
if
(
interstitialAd
==
null
)
{
interstitialAd
=
MaxInterstitialAd
(
ConfigHelper
.
interAdMaxId
,
activity
)
}
...
...
@@ -94,13 +109,12 @@ object AdMaxInterstitialUtils {
this
.
onHidden
=
onHidden
if
(
interstitialAd
?.
isReady
==
true
)
{
interstitialAd
?.
showAd
()
LogEx
.
logDebug
(
TAG
,
"isReady=true"
)
showIntervalDialogAndShowAd
(
activity
,
isShowDialog
,
onHidden
,
2
)
}
else
{
interstitialAd
?.
loadAd
()
loadingListener
=
{
interstitialAd
?.
showAd
()
loadingListener
=
null
}
LogEx
.
logDebug
(
TAG
,
"isReady=false"
)
showAdDialogAndLoadInterstitial
(
activity
,
isReLoadAd
,
isShowDialog
,
onHidden
)
}
}
...
...
@@ -108,4 +122,69 @@ object AdMaxInterstitialUtils {
private
fun
isAdExpired
():
Boolean
{
return
System
.
currentTimeMillis
()
-
interLoadTime
>
1000
*
60
*
60
}
private
fun
showIntervalDialogAndShowAd
(
activity
:
Activity
,
isShowDialog
:
Boolean
,
onHidden
:
(()
->
Unit
)?,
interval
:
Int
)
{
if
(!
isShowDialog
)
{
return
}
if
(
customDialog
!=
null
&&
customDialog
?.
isShowing
==
true
)
{
return
// 如果对话框已经显示,则不再显示
}
customDialog
=
CustomDialog
(
activity
,
R
.
layout
.
dialog_ad_loading
)
customDialog
?.
setCountdownText
(
R
.
id
.
dialog_ad_loading_text
)
val
countdownTimer
=
object
:
CountDownTimer
((
interval
*
1000
).
toLong
(),
1000
)
{
override
fun
onTick
(
millisUntilFinished
:
Long
)
{
val
seconds
=
(
millisUntilFinished
/
1000
).
toInt
()
customDialog
?.
updateCountdownText
(
"Advertising in preparation ($seconds"
+
"s)..."
)
}
override
fun
onFinish
()
{
if
(!
activity
.
isDestroyed
&&
!
activity
.
isFinishing
)
{
customDialog
?.
dismiss
()
}
customDialog
=
null
LogEx
.
logDebug
(
TAG
,
"onFinish"
)
interstitialAd
?.
showAd
()
}
}
countdownTimer
.
start
()
customDialog
?.
show
()
}
private
fun
showAdDialogAndLoadInterstitial
(
activity
:
Activity
,
isReLoadAd
:
Boolean
,
isShowDialog
:
Boolean
,
onHidden
:
(()
->
Unit
)?
)
{
if
(!
isShowDialog
)
{
return
}
var
mDialog
:
Dialog
?
=
null
if
(!
activity
.
isFinishing
&&
!
activity
.
isDestroyed
)
{
mDialog
=
CustomDialog
(
activity
,
R
.
layout
.
dialog_ad_loading
)
// 设置对话框的样式和内容
mDialog
.
show
()
}
loadingListener
=
{
mDialog
?.
dismiss
()
interstitialAd
?.
showAd
()
loadingListener
=
null
}
// if (isReLoadAd) {
// mDialog?.dismiss()
// onHidden?.invoke()
// }
}
}
\ No newline at end of file
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