Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
D
Data Recovery White
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
Data Recovery White
Commits
d577cc54
Commit
d577cc54
authored
Jul 24, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...广告限制类型
parent
60ffef06
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
5 deletions
+48
-5
AdDisplayUtils.java
...c/main/java/com/base/datarecovery/ads/AdDisplayUtils.java
+46
-5
AdMaxInterstitialUtils.kt
...a/com/base/datarecovery/ads/max/AdMaxInterstitialUtils.kt
+1
-0
AdMaxOpenUtils.kt
...main/java/com/base/datarecovery/ads/max/AdMaxOpenUtils.kt
+1
-0
No files found.
app/src/main/java/com/base/datarecovery/ads/AdDisplayUtils.java
View file @
d577cc54
...
@@ -29,6 +29,9 @@ public class AdDisplayUtils {
...
@@ -29,6 +29,9 @@ public class AdDisplayUtils {
private
static
final
String
MAX_AD_REQUEST_FAIL_COUNT_KEY
=
"max_ad_request_fail_count"
;
// 单个广告点击次数限制的键
private
static
final
String
MAX_AD_REQUEST_FAIL_COUNT_KEY
=
"max_ad_request_fail_count"
;
// 单个广告点击次数限制的键
private
static
final
String
AD_REQUEST_FAIL_COUNT_KEY
=
"ad_request_fail_count"
;
// 单个广告点击次数限制的键
private
static
final
String
AD_REQUEST_FAIL_COUNT_KEY
=
"ad_request_fail_count"
;
// 单个广告点击次数限制的键
private
static
final
String
AD_REQUEST_COUNT_KEY
=
"ad_request_count"
;
//广告请求次数
private
static
final
String
MAX_AD_REQUEST_COUNT_KEY
=
"max_ad_request_count"
;
// 广告请求次数限制的键
private
static
AdDisplayUtils
instance
;
// 单例对象
private
static
AdDisplayUtils
instance
;
// 单例对象
private
int
adDisplayCount
=
0
;
// 当前广告展示次数
private
int
adDisplayCount
=
0
;
// 当前广告展示次数
private
int
adClickCount
=
0
;
// 当前广告点击次数
private
int
adClickCount
=
0
;
// 当前广告点击次数
...
@@ -39,6 +42,10 @@ public class AdDisplayUtils {
...
@@ -39,6 +42,10 @@ public class AdDisplayUtils {
private
int
adRequestFailCount
=
0
;
// 请求失败当前
private
int
adRequestFailCount
=
0
;
// 请求失败当前
private
String
currentDate
;
// 当前日期
private
String
currentDate
;
// 当前日期
private
int
adRequestCount
=
0
;
// 当前广告请求次数
private
int
maxAdRequestCount
=
0
;
// 最大广告请求次数
private
static
final
int
DEFAULT_MAX_AD_REQUEST_COUNT
=
100
;
// 广告请求次数限制默认值
private
AdDisplayUtils
()
{
private
AdDisplayUtils
()
{
currentDate
=
getCurrentDate
();
currentDate
=
getCurrentDate
();
...
@@ -49,6 +56,9 @@ public class AdDisplayUtils {
...
@@ -49,6 +56,9 @@ public class AdDisplayUtils {
adDisplayCount
=
prefs
.
getInt
(
getAdDisplayCountKey
(),
0
);
adDisplayCount
=
prefs
.
getInt
(
getAdDisplayCountKey
(),
0
);
adClickCount
=
prefs
.
getInt
(
getAdClickCountKey
(),
0
);
adClickCount
=
prefs
.
getInt
(
getAdClickCountKey
(),
0
);
adRequestFailCount
=
prefs
.
getInt
(
getAdRequestFailCountKey
(),
0
);
adRequestFailCount
=
prefs
.
getInt
(
getAdRequestFailCountKey
(),
0
);
adRequestCount
=
prefs
.
getInt
(
getAdRequestCountKey
(),
0
);
maxAdRequestCount
=
prefs
.
getInt
(
MAX_AD_REQUEST_COUNT_KEY
,
DEFAULT_MAX_AD_REQUEST_COUNT
);
}
}
public
static
synchronized
AdDisplayUtils
getInstance
()
{
public
static
synchronized
AdDisplayUtils
getInstance
()
{
...
@@ -58,6 +68,10 @@ public class AdDisplayUtils {
...
@@ -58,6 +68,10 @@ public class AdDisplayUtils {
return
instance
;
return
instance
;
}
}
private
String
getAdRequestCountKey
()
{
return
AD_REQUEST_COUNT_KEY
+
"_"
+
currentDate
;
}
public
boolean
shouldDisplayAd
()
{
public
boolean
shouldDisplayAd
()
{
return
adDisplayCount
<
getMaxAdDisplayCount
();
return
adDisplayCount
<
getMaxAdDisplayCount
();
}
}
...
@@ -70,6 +84,14 @@ public class AdDisplayUtils {
...
@@ -70,6 +84,14 @@ public class AdDisplayUtils {
return
adClickCount
<
getMaxAdClickCount
();
return
adClickCount
<
getMaxAdClickCount
();
}
}
public
boolean
shouldSendAdRequest
()
{
return
adRequestCount
<
getMaxAdRequestCount
();
}
public
int
getMaxAdRequestCount
()
{
return
maxAdRequestCount
;
}
public
boolean
shouldShowAd
(
String
ad_unit
)
{
public
boolean
shouldShowAd
(
String
ad_unit
)
{
if
(
BuildConfig
.
DEBUG
)
{
if
(
BuildConfig
.
DEBUG
)
{
return
true
;
return
true
;
...
@@ -77,18 +99,20 @@ public class AdDisplayUtils {
...
@@ -77,18 +99,20 @@ public class AdDisplayUtils {
boolean
shouldDisplayAd
=
shouldDisplayAd
();
boolean
shouldDisplayAd
=
shouldDisplayAd
();
boolean
shouldIncrementClickCount
=
shouldIncrementClickCount
();
boolean
shouldIncrementClickCount
=
shouldIncrementClickCount
();
boolean
shouldIncrementRequestFailAd
=
shouldIncrementRequestFailAd
();
boolean
shouldIncrementRequestFailAd
=
shouldIncrementRequestFailAd
();
boolean
shouldSendAdRequest
=
shouldSendAdRequest
();
boolean
s
=
shouldDisplayAd
&&
shouldIncrementClickCount
&&
shouldIncrementRequestFailAd
;
boolean
s
=
shouldDisplayAd
&&
shouldIncrementClickCount
&&
shouldIncrementRequestFailAd
&&
shouldSendAdRequest
;
if
(!
s
)
{
if
(!
s
)
{
LogEx
.
INSTANCE
.
logDebug
(
"glc"
,
"!shouldShowAd"
,
false
);
LogEx
.
INSTANCE
.
logDebug
(
"glc"
,
"!shouldShowAd"
,
false
);
JSONObject
obj2
=
new
JSONObject
();
JSONObject
obj2
=
new
JSONObject
();
try
{
try
{
obj2
.
put
(
"reason"
,
"ad limit"
);
obj2
.
put
(
"reason"
,
"ad limit"
);
obj2
.
put
(
"shouldDisplayAd"
,
shouldDisplayAd
);
obj2
.
put
(
"shouldDisplayAd"
,
shouldDisplayAd
);
obj2
.
put
(
"shouldIncrementClickCount"
,
shouldIncrementClickCount
);
obj2
.
put
(
"shouldIncrementClickCount"
,
shouldIncrementClickCount
);
obj2
.
put
(
"shouldIncrementRequestFailAd"
,
shouldIncrementRequestFailAd
);
obj2
.
put
(
"shouldIncrementRequestFailAd"
,
shouldIncrementRequestFailAd
);
obj2
.
put
(
"shouldSendAdRequest"
,
shouldSendAdRequest
);
obj2
.
put
(
"ad_unit"
,
ad_unit
);
obj2
.
put
(
"ad_unit"
,
ad_unit
);
EventUtils
.
INSTANCE
.
event
(
"ad_show_error"
,
null
,
obj2
,
false
);
EventUtils
.
INSTANCE
.
event
(
"ad_show_error"
,
null
,
obj2
,
false
);
}
catch
(
JSONException
e
)
{
}
catch
(
JSONException
e
)
{
...
@@ -219,6 +243,23 @@ public class AdDisplayUtils {
...
@@ -219,6 +243,23 @@ public class AdDisplayUtils {
editor
.
apply
();
editor
.
apply
();
}
}
public
void
incrementAdRequestCount
()
{
if
(!
currentDate
.
equals
(
getCurrentDate
()))
{
currentDate
=
getCurrentDate
();
adRequestCount
=
0
;
}
adRequestCount
++;
saveAdRequestCount
();
}
private
void
saveAdRequestCount
()
{
SharedPreferences
prefs
=
BaseApplication
.
context
.
getSharedPreferences
(
AD_PREFS_NAME
,
0
);
SharedPreferences
.
Editor
editor
=
prefs
.
edit
();
editor
.
putInt
(
getAdRequestCountKey
(),
adRequestCount
);
editor
.
apply
();
}
private
String
getAdRequestFailCountKey
()
{
private
String
getAdRequestFailCountKey
()
{
return
AD_REQUEST_FAIL_COUNT_KEY
+
"_"
+
currentDate
;
return
AD_REQUEST_FAIL_COUNT_KEY
+
"_"
+
currentDate
;
}
}
...
...
app/src/main/java/com/base/datarecovery/ads/max/AdMaxInterstitialUtils.kt
View file @
d577cc54
...
@@ -182,6 +182,7 @@ object AdMaxInterstitialUtils {
...
@@ -182,6 +182,7 @@ object AdMaxInterstitialUtils {
obj
.
put
(
"ad_type"
,
"interAd"
)
obj
.
put
(
"ad_type"
,
"interAd"
)
EventUtils
.
event
(
"ad_pull_start"
,
ext
=
obj
)
EventUtils
.
event
(
"ad_pull_start"
,
ext
=
obj
)
interstitialAd
?.
loadAd
()
interstitialAd
?.
loadAd
()
AdDisplayUtils
.
getInstance
().
incrementAdRequestCount
()
return
true
return
true
}
else
{
}
else
{
EventUtils
.
event
(
"isAdInit"
,
value
=
"loadInterstitialAd isAdInit=${isAdInit.get()}"
)
EventUtils
.
event
(
"isAdInit"
,
value
=
"loadInterstitialAd isAdInit=${isAdInit.get()}"
)
...
...
app/src/main/java/com/base/datarecovery/ads/max/AdMaxOpenUtils.kt
View file @
d577cc54
...
@@ -174,6 +174,7 @@ object AdMaxOpenUtils {
...
@@ -174,6 +174,7 @@ object AdMaxOpenUtils {
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
?.
loadAd
()
appOpenAd
?.
loadAd
()
AdDisplayUtils
.
getInstance
().
incrementAdRequestCount
()
return
true
return
true
}
}
return
false
return
false
...
...
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