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
c069ba6c
Commit
c069ba6c
authored
Jun 24, 2025
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[同步]通过广告的问题
parent
b528ae88
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
145 additions
and
33 deletions
+145
-33
AdConfigBean.kt
...ain/java/com/dumpster/cleaner/bean/config/AdConfigBean.kt
+3
-1
AdsShowCallBack.kt
...java/com/dumpster/cleaner/business/ads/AdsShowCallBack.kt
+25
-4
LimitUtils.kt
...main/java/com/dumpster/cleaner/business/ads/LimitUtils.kt
+35
-0
AdNativeMgr.kt
...va/com/dumpster/cleaner/business/ads/admob/AdNativeMgr.kt
+3
-0
SplashActivity.kt
...ain/java/com/dumpster/cleaner/ui/splash/SplashActivity.kt
+54
-18
SplashViewModel.kt
...in/java/com/dumpster/cleaner/ui/splash/SplashViewModel.kt
+25
-10
No files found.
app/src/main/java/com/dumpster/cleaner/bean/config/AdConfigBean.kt
View file @
c069ba6c
...
...
@@ -13,12 +13,14 @@ class AdConfigBean(
var
numClickLimit
:
Int
=
-
1
,
//点击次数限制
var
timeInterval
:
Int
=
10
,
//广告间隔秒
var
openAdLoading
:
Int
=
15
,
//开屏广告拉取时间
var
numNativeDisplayLimit
:
Int
=
-
1
,
//原生展示次数限制
var
fullNativeShow
:
Boolean
=
true
,
//显示全屏原生
var
functionBackShowAd
:
Boolean
=
true
,
//功能退出显示广告
var
functionInShowAd
:
Boolean
=
true
,
//功能进入显示广告
var
rvEmptyShowNative
:
Boolean
=
true
,
//列表空的显示原生不
var
requestUmp
:
Boolean
=
false
,
//是否需要请求ump
var
showCountdown
:
Boolean
=
false
,
//是否显示倒计时
)
{
companion
object
{
...
...
app/src/main/java/com/dumpster/cleaner/business/ads/AdsShowCallBack.kt
View file @
c069ba6c
package
com.dumpster.cleaner.business.ads
abstract
class
AdsShowCallBack
{
open
fun
show
()
{}
var
adShowed
:
Boolean
=
false
var
nextCalled
:
Boolean
=
false
//展示广告时调用
open
fun
show
()
{
adShowed
=
true
}
//流程中非广告的失败时调用
open
fun
failed
(
where
:
Int
=
0
)
{
adShowed
=
false
if
(!
nextCalled
)
{
nextCalled
=
true
next
()
}
}
//流程中广告本身时调用
open
fun
adFailed
(
where
:
Int
=
0
)
{
adShowed
=
false
if
(!
nextCalled
)
{
nextCalled
=
true
next
()
}
}
//用户手动关闭广告时调用
open
fun
close
(
where
:
Int
=
0
)
{
if
(!
nextCalled
)
{
nextCalled
=
true
next
()
}
}
abstract
fun
next
()
}
\ No newline at end of file
app/src/main/java/com/dumpster/cleaner/business/ads/LimitUtils.kt
View file @
c069ba6c
...
...
@@ -11,6 +11,8 @@ import com.dumpster.cleaner.utils.KotlinExt.toFormatTime4
*
*/
object
LimitUtils
{
const
val
NUM_NATIVE_DISPLAY
=
"local_numNativeDisplayLimit"
const
val
NUM_DISPLAY
=
"local_numDisplayLimit"
const
val
NUM_REQUEST
=
"local_numRequestLimit"
...
...
@@ -143,6 +145,11 @@ object LimitUtils {
addNum
(
NUM_CLICK
)
}
fun
addNativeDisplayNum
()
{
addNum
(
NUM_NATIVE_DISPLAY
)
}
/**
* 开屏和插页广告的显示间隔限制
*/
...
...
@@ -163,4 +170,32 @@ object LimitUtils {
field
=
value
AppPreferences
.
getInstance
().
put
(
"openInterLastShowTime"
,
value
,
true
)
}
/**
* 原生广告是否到达限制
*/
private
inline
val
isNativeLimited
:
Boolean
get
()
{
val
maxCount
=
AdConfigBean
.
adsConfigBean
.
numNativeDisplayLimit
return
maxCount
>
-
1
&&
AppPreferences
.
getInstance
()
.
getInt
(
NUM_NATIVE_DISPLAY
,
0
)
>=
maxCount
}
fun
isShowNative
(
adsType
:
AdsType
,
adEvent
:
AdEvent
?):
Boolean
{
val
currentDate
=
System
.
currentTimeMillis
().
toFormatTime4
()
if
(
saveDate
!=
currentDate
)
{
//如果已经不是今天了,就重置个数
saveDate
=
currentDate
AppPreferences
.
getInstance
().
put
(
NUM_NATIVE_DISPLAY
,
0
)
}
val
flag
=
isNativeLimited
if
(
flag
)
{
val
value
=
"current${getAdEventMsg(adsType)} "
+
"show=${AppPreferences.getInstance().getInt(NUM_NATIVE_DISPLAY, 0)} "
+
"${getAdEventMsg(adsType).lowercase()}_"
+
"max_show=${AdConfigBean.adsConfigBean.numNativeDisplayLimit}"
adEvent
?.
adLimited
(
value
)
}
return
!
flag
}
}
\ No newline at end of file
app/src/main/java/com/dumpster/cleaner/business/ads/admob/AdNativeMgr.kt
View file @
c069ba6c
...
...
@@ -98,6 +98,9 @@ class AdNativeMgr {
cacheItems
.
clear
()
return
}
if
(!
LimitUtils
.
isShowNative
(
AdsType
.
NATIVE
,
admobEvent
))
{
return
}
Log
.
e
(
TAG
,
"adNative can show"
)
if
(!
adAvailable
())
{
...
...
app/src/main/java/com/dumpster/cleaner/ui/splash/SplashActivity.kt
View file @
c069ba6c
...
...
@@ -26,6 +26,7 @@ import com.dumpster.cleaner.SpConstObject.isGuided
import
com.dumpster.cleaner.base.BaseActivity
import
com.dumpster.cleaner.base.jumpAction
import
com.dumpster.cleaner.bean.FeatureBean.Companion.BATTERY_INFO
import
com.dumpster.cleaner.bean.config.AdConfigBean
import
com.dumpster.cleaner.business.ads.AdsMgr
import
com.dumpster.cleaner.business.ads.AdsShowCallBack
import
com.dumpster.cleaner.business.helper.EventUtils
...
...
@@ -37,9 +38,11 @@ import com.dumpster.cleaner.databinding.ActivitySplashBinding
import
com.dumpster.cleaner.ui.dialog.StoragePermissionDialog
import
com.dumpster.cleaner.ui.guide.GuideCleanActivity
import
com.dumpster.cleaner.ui.main.MainActivity
import
com.dumpster.cleaner.utils.LogEx
import
com.dumpster.cleaner.utils.PermissionUtils.checkStorePermission
import
com.dumpster.cleaner.utils.PermissionUtils.requestStoragePermission
import
com.dumpster.cleaner.utils.UmpUtils
import
com.dumpster.cleaner.utils.umpCalled
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.launch
import
java.util.concurrent.atomic.AtomicBoolean
...
...
@@ -63,7 +66,6 @@ class SplashActivity : BaseActivity<ActivitySplashBinding>(ActivitySplashBinding
}
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
// initUMP()
super
.
onCreate
(
savedInstanceState
)
handleIntentExtras
()
}
...
...
@@ -80,9 +82,9 @@ class SplashActivity : BaseActivity<ActivitySplashBinding>(ActivitySplashBinding
override
fun
initView
()
{
super
.
initView
()
requestNotificationPermission
()
showLoadingAd
()
setPrivacyPolicy
()
requestNotificationPermission
()
}
private
fun
setPrivacyPolicy
()
{
...
...
@@ -139,19 +141,30 @@ class SplashActivity : BaseActivity<ActivitySplashBinding>(ActivitySplashBinding
}
private
fun
initUMP
()
{
val
ump
=
UmpUtils
(
this
)
private
fun
initUMP
(
callBack
:
()
->
Unit
)
{
if
(
AdConfigBean
.
adsConfigBean
.
requestUmp
&&
!
umpCalled
)
{
umpCalled
=
true
val
ump
=
UmpUtils
(
this
)
if
(
ump
.
consentInformation
.
canRequestAds
())
{
AdsMgr
.
init
(
this
)
callBack
.
invoke
(
)
}
else
{
ump
.
callback
=
{
AdsMgr
.
init
(
this
)
callBack
.
invoke
(
)
}
LogEx
.
logDebug
(
TAG
,
"requestUMP"
)
ump
.
requestUMP
()
}
}
else
{
callBack
.
invoke
()
}
}
private
fun
showLoadingAd
()
{
binding
.
clBottomStart
.
visibility
=
if
(
ifAgreePrivacy
)
View
.
GONE
else
View
.
VISIBLE
binding
.
clBottomLoading
.
visibility
=
if
(
ifAgreePrivacy
)
View
.
VISIBLE
else
View
.
GONE
...
...
@@ -160,17 +173,40 @@ class SplashActivity : BaseActivity<ActivitySplashBinding>(ActivitySplashBinding
if
(
ifAgreePrivacy
)
{
val
acAction
=
{
initUMP
{
LogEx
.
logDebug
(
TAG
,
"initUMP callback"
)
AdsMgr
.
showOpen
(
this
,
showCallBack
=
object
:
AdsShowCallBack
()
{
override
fun
show
()
{
super
.
show
()
viewModel
.
stopCountdown
()
}
override
fun
next
()
{
binding
.
root
.
postDelayed
({
jumpNext
()
},
200
)
val
action
=
{
LogEx
.
logDebug
(
TAG
,
"next"
)
viewModel
.
overCountDown
()
// binding.progressBar.setProgress(100.0)
binding
.
root
.
postDelayed
({
jumpNext
()
},
250
)
}
LogEx
.
logDebug
(
"AdmobEvent"
,
"inter adShowed=${adShowed}"
)
if
(
adShowed
)
{
action
.
invoke
()
}
else
{
LogEx
.
logDebug
(
"AdmobEvent"
,
"inter open show inter"
)
AdsMgr
.
showInsert
(
this
@SplashActivity
,
showCallBack
=
object
:
AdsShowCallBack
()
{
override
fun
next
()
{
action
.
invoke
()
}
})
}
}
})
}
}
if
(
spConfig
.
isNotEmpty
())
{
Log
.
e
(
TAG
,
"1"
)
...
...
app/src/main/java/com/dumpster/cleaner/ui/splash/SplashViewModel.kt
View file @
c069ba6c
...
...
@@ -6,6 +6,7 @@ import com.dumpster.cleaner.SpConstObject.ifAgreePrivacy
import
com.dumpster.cleaner.bean.config.AdConfigBean
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.Job
import
kotlinx.coroutines.async
import
kotlinx.coroutines.delay
import
kotlinx.coroutines.isActive
import
kotlinx.coroutines.launch
...
...
@@ -15,40 +16,44 @@ class SplashViewModel : ViewModel() {
private
var
countdownJob
:
Job
?
=
null
private
var
startTime
:
Long
=
0
val
totalTimeMs
=
AdConfigBean
.
adsConfigBean
.
openAdLoading
*
1000L
// 倒计时总时长
val
totalTimeMs
=
(
AdConfigBean
.
adsConfigBean
.
openAdLoading
+
1
)
*
1000L
// 倒计时总时长
private
val
checkIntervalMs
=
100L
// 检查间隔(100毫秒)
private
var
countdownOver
:
Boolean
=
false
var
jumpNext
:
(()
->
Unit
)?
=
null
var
onTick
:
((
sLong
:
Long
,
total
:
Long
)
->
Unit
)?
=
null
var
onTick
:
((
sLong
:
Long
,
total
:
Long
,
percent
:
Float
)
->
Unit
)?
=
null
fun
startCountdown
()
{
if
(!
ifAgreePrivacy
)
return
if
(
countdownOver
)
return
countdownJob
?.
cancel
()
startTime
=
System
.
currentTimeMillis
()
countdownJob
=
viewModelScope
.
launch
(
Dispatchers
.
IO
)
{
while
(
isActive
)
{
val
currentTime
=
System
.
currentTimeMillis
()
val
elapsed
=
currentTime
-
startTime
val
elapsed
=
System
.
currentTimeMillis
()
-
startTime
val
remaining
=
totalTimeMs
-
elapsed
if
(
remaining
<=
0
)
{
launch
(
Dispatchers
.
Main
)
{
onTick
?.
invoke
(
totalTimeMs
,
totalTimeMs
)
}
async
(
Dispatchers
.
Main
)
{
onTick
?.
invoke
(
totalTimeMs
,
totalTimeMs
,
100f
)
}
break
}
else
{
launch
(
Dispatchers
.
Main
)
{
onTick
?.
invoke
(
elapsed
,
totalTimeMs
)
val
percent
=
elapsed
*
100f
/
totalTimeMs
if
(
percent
>
95
)
{
async
(
Dispatchers
.
Main
)
{
onTick
?.
invoke
(
totalTimeMs
,
totalTimeMs
,
100f
)
}
break
}
else
{
async
(
Dispatchers
.
Main
)
{
onTick
?.
invoke
(
elapsed
,
totalTimeMs
,
percent
)
}.
await
()
}
}
delay
(
Random
.
nextLong
(
checkIntervalMs
,
checkIntervalMs
+
100L
))
}
launch
(
Dispatchers
.
Main
)
{
jumpNext
?.
invoke
()
jumpNext
=
null
}
}
}
...
...
@@ -60,4 +65,14 @@ class SplashViewModel : ViewModel() {
countdownJob
?.
cancel
()
countdownJob
=
null
}
/**
* 永久结束倒计时
*/
fun
overCountDown
()
{
countdownOver
=
true
stopCountdown
()
}
}
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