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
f4f6d9a6
Commit
f4f6d9a6
authored
Jun 19, 2025
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[广告]限制原生广告展示次数 限制原生广告展示次数 限制原生广告展示次数
parent
ece2d799
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
18 deletions
+58
-18
AdConfigBean.kt
...rc/main/java/com/base/appzxhy/bean/config/AdConfigBean.kt
+1
-0
LimitUtils.kt
...src/main/java/com/base/appzxhy/business/ads/LimitUtils.kt
+40
-5
AdNativeMgr.kt
...n/java/com/base/appzxhy/business/ads/admob/AdNativeMgr.kt
+17
-13
No files found.
app/src/main/java/com/base/appzxhy/bean/config/AdConfigBean.kt
View file @
f4f6d9a6
...
...
@@ -13,6 +13,7 @@ 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
,
//功能退出显示广告
...
...
app/src/main/java/com/base/appzxhy/business/ads/LimitUtils.kt
View file @
f4f6d9a6
...
...
@@ -11,6 +11,8 @@ import com.base.appzxhy.utils.KotlinExt.toFormatTime4
*
*/
object
LimitUtils
{
const
val
NUM_NATIVE_DISPLAY
=
"local_numNativeDisplayLimit"
const
val
NUM_DISPLAY
=
"local_numDisplayLimit"
const
val
NUM_REQUEST
=
"local_numRequestLimit"
...
...
@@ -93,15 +95,16 @@ object LimitUtils {
AppPreferences
.
getInstance
().
put
(
NUM_REQUEST
,
0
)
AppPreferences
.
getInstance
().
put
(
NUM_CLICK
,
0
)
}
if
(
isDisplayLimited
)
{
val
flag1
=
isDisplayLimited
if
(
flag1
)
{
val
value
=
"current${getAdEventMsg(adsType)} "
+
"show=${AppPreferences.getInstance().getInt(NUM_DISPLAY, 0)} "
+
"${getAdEventMsg(adsType).lowercase()}_"
+
"max_show=${AdConfigBean.adsConfigBean.numDisplayLimit}"
adEvent
?.
adLimited
(
value
)
}
if
(
isClickLimited
)
{
val
flag2
=
isClickLimited
if
(
flag2
)
{
val
value
=
"current${getAdEventMsg(adsType)}Click=${AppPreferences.getInstance().getInt(NUM_CLICK, 0)} "
"${getAdEventMsg(adsType).lowercase()}_max_click=${AdConfigBean.adsConfigBean.numClickLimit}"
...
...
@@ -109,14 +112,15 @@ object LimitUtils {
adEvent
?.
adLimited
(
value
)
}
if
(
isRequestLimited
)
{
val
flag3
=
isRequestLimited
if
(
flag3
)
{
val
value
=
"current${getAdEventMsg(adsType)}Request=${AppPreferences.getInstance().getInt(NUM_REQUEST, 0)} "
+
"${getAdEventMsg(adsType).lowercase()}_max_request=${AdConfigBean.adsConfigBean.numRequestLimit}"
adEvent
?.
adLimited
(
value
)
}
return
!(
isDisplayLimited
||
isClickLimited
||
isRequestLimited
)
return
!(
flag1
||
flag2
||
flag3
)
}
private
fun
addNum
(
key
:
String
)
{
...
...
@@ -143,6 +147,10 @@ object LimitUtils {
addNum
(
NUM_CLICK
)
}
fun
addNativeDisplayNum
()
{
addNum
(
NUM_NATIVE_DISPLAY
)
}
/**
* 开屏和插页广告的显示间隔限制
*/
...
...
@@ -163,4 +171,31 @@ 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/base/appzxhy/business/ads/admob/AdNativeMgr.kt
View file @
f4f6d9a6
...
...
@@ -98,6 +98,10 @@ class AdNativeMgr {
cacheItems
.
clear
()
return
}
if
(!
LimitUtils
.
isShowNative
(
AdsType
.
NATIVE
,
admobEvent
))
{
return
}
Log
.
e
(
TAG
,
"adNative can show"
)
if
(!
adAvailable
())
{
...
...
@@ -108,27 +112,27 @@ class AdNativeMgr {
parent
.
isAdShowed
=
true
val
nativeAd
=
cacheItems
.
peek
()
if
(
nativeAd
==
null
)
{
loadAd
(
parent
.
context
,
admobEvent
)
{
ad
->
Log
.
e
(
TAG
,
"load show"
)
var
showAction
:
(
ad
:
NativeAd
)
->
Unit
=
{
ad
->
nativeCallBack
?.
invoke
(
ad
)
parent
.
setNativeAd
(
ad
,
layout
)
admobEvent
.
showAd
(
ad
.
responseInfo
)
//添加原生数量
LimitUtils
.
addNativeDisplayNum
()
loadAd
(
MyApplication
.
appContext
,
AdmobEvent
(
"nativeAd"
,
"preload"
),
null
)
}
}
else
{
if
(
nativeAd
==
null
)
{
loadAd
(
parent
.
context
,
admobEvent
)
{
ad
->
Log
.
e
(
TAG
,
"load show"
)
showAction
.
invoke
(
ad
)
}
}
else
{
val
flag
=
cacheItems
.
remove
(
nativeAd
)
Log
.
e
(
TAG
,
"ready show remove=$flag size=${cacheItems.size}"
)
nativeCallBack
?.
invoke
(
nativeAd
)
parent
.
setNativeAd
(
nativeAd
,
layout
)
admobEvent
.
showAd
(
nativeAd
.
responseInfo
)
loadAd
(
MyApplication
.
appContext
,
AdmobEvent
(
"nativeAd"
,
"preload"
),
null
)
showAction
.
invoke
(
nativeAd
)
}
}
...
...
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