Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
P
PDF Viewer Scanner White ago
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
kuxulei
PDF Viewer Scanner White ago
Commits
eacf3173
Commit
eacf3173
authored
Oct 08, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
4bcf42c8
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
235 additions
and
307 deletions
+235
-307
AdDisplayUtils.kt
...java/com/base/pdfviewerscannerwhite/ads/AdDisplayUtils.kt
+175
-251
FirebaseDatabase.kt
...va/com/base/pdfviewerscannerwhite/ads/FirebaseDatabase.kt
+52
-48
AdmobInterstitialUtils.kt
...pdfviewerscannerwhite/ads/admob/AdmobInterstitialUtils.kt
+4
-4
AdmobNativeUtils.kt
.../base/pdfviewerscannerwhite/ads/admob/AdmobNativeUtils.kt
+2
-2
AdmobOpenUtils.kt
...om/base/pdfviewerscannerwhite/ads/admob/AdmobOpenUtils.kt
+2
-2
No files found.
app/src/main/java/com/base/pdfviewerscannerwhite/ads/AdDisplayUtils.kt
View file @
eacf3173
package
com.base.pdfviewerscannerwhite.ads
;
package
com.base.pdfviewerscannerwhite.ads
import
android.content.Context;
import
com.base.pdfviewerscannerwhite.ads.FirebaseDatabase.inter_limit_click
import
android.content.SharedPreferences;
import
com.base.pdfviewerscannerwhite.ads.FirebaseDatabase.inter_limit_request
import
android.util.Log;
import
com.base.pdfviewerscannerwhite.ads.FirebaseDatabase.inter_limit_show
import
com.base.pdfviewerscannerwhite.ads.FirebaseDatabase.native_limit_request
import
com.base.pdfviewerscannerwhite.ads.FirebaseDatabase.native_limit_show
import
com.base.pdfviewerscannerwhite.ads.FirebaseDatabase.open_limit_click
import
com.base.pdfviewerscannerwhite.ads.FirebaseDatabase.open_limit_request
import
com.base.pdfviewerscannerwhite.ads.FirebaseDatabase.open_limit_show
import
com.base.pdfviewerscannerwhite.helper.EventUtils
import
com.base.pdfviewerscannerwhite.utils.AppPreferences
import
com.base.pdfviewerscannerwhite.utils.LogEx
import
java.text.SimpleDateFormat
import
java.util.Calendar
import
java.util.Locale
import
org.json.JSONException;
object
AdDisplayUtils
{
import
org.json.JSONObject;
import
java.text.SimpleDateFormat;
import
java.util.Calendar;
import
java.util.Date;
import
java.util.Locale;
import
com.base.pdfviewerscannerwhite.BuildConfig;
//region open
import
com.base.pdfviewerscannerwhite.helper.EventUtils;
private
val
open_max_request
=
AppPreferences
.
getInstance
().
getString
(
open_limit_request
,
"15"
).
toInt
()
import
com.base.pdfviewerscannerwhite.helper.MyApplication;
private
val
open_max_show
=
AppPreferences
.
getInstance
().
getString
(
open_limit_show
,
"10"
).
toInt
()
import
com.base.pdfviewerscannerwhite.utils.AppPreferences;
private
val
open_max_click
=
AppPreferences
.
getInstance
().
getString
(
open_limit_click
,
"1"
).
toInt
()
import
com.base.pdfviewerscannerwhite.utils.LogEx;
import
com.facebook.appevents.AppEventsLogger;
public
class
AdDisplayUtils
{
private
String
TAG
=
"AdDisplayUtils"
;
public
static
final
int
DEFAULT_MAX_AD_REQUEST_COUNT
=
100
;
// 广告请求次数限制默认值
public
static
final
int
DEFAULT_MAX_AD_REQUEST_FAIL_COUNT
=
20
;
// 单个广告点击次数限制默认值
public
static
final
int
DEFAULT_MAX_AD_DISPLAY_COUNT
=
45
;
// 总广告展示次数限制默认值
public
static
final
int
DEFAULT_MAX_AD_CLICK_COUNT
=
10
;
// 单个广告点击次数限制默认值
private
static
final
String
AD_PREFS_NAME
=
"ad_prefs"
;
// SharedPreferences 名称
private
static
AdDisplayUtils
instance
;
// 单例对象
private
String
currentDate
;
// 当前日期
private
Context
context
=
MyApplication
.
context
;
public
void
saveSp
()
{
this
.
maxAdRequestCount
=
Integer
.
parseInt
(
AppPreferences
.
getInstance
().
getString
(
"adMaxRequestCount"
,
String
.
valueOf
(
DEFAULT_MAX_AD_REQUEST_COUNT
)));
saveMaxAdRequestCount
();
this
.
maxAdRequestFailCount
=
Integer
.
parseInt
(
AppPreferences
.
getInstance
().
getString
(
"adRequestFailCount"
,
String
.
valueOf
(
DEFAULT_MAX_AD_REQUEST_FAIL_COUNT
)));
saveMaxAdRequestFailCount
();
this
.
maxAdDisplayCount
=
Integer
.
parseInt
(
AppPreferences
.
getInstance
().
getString
(
"adShowCount"
,
String
.
valueOf
(
DEFAULT_MAX_AD_DISPLAY_COUNT
)));
saveMaxAdDisplayCount
();
this
.
maxAdClickCount
=
Integer
.
parseInt
(
AppPreferences
.
getInstance
().
getString
(
"adClickCount"
,
String
.
valueOf
(
DEFAULT_MAX_AD_CLICK_COUNT
)));
saveMaxAdClickCount
();
fun
incrementOpenRequestCount
()
{
currentOpenRequest
+=
1
}
}
private
AdDisplayUtils
()
{
fun
incrementOpenShow
()
{
currentDate
=
getCurrentDate
();
currentOpenShow
+=
1
SharedPreferences
prefs
=
context
.
getSharedPreferences
(
AD_PREFS_NAME
,
0
);
maxAdRequestCount
=
prefs
.
getInt
(
MAX_AD_REQUEST_COUNT_KEY
,
DEFAULT_MAX_AD_REQUEST_COUNT
);
maxAdRequestFailCount
=
prefs
.
getInt
(
MAX_AD_REQUEST_FAIL_COUNT_KEY
,
DEFAULT_MAX_AD_REQUEST_FAIL_COUNT
);
maxAdDisplayCount
=
prefs
.
getInt
(
MAX_AD_DISPLAY_COUNT_KEY
,
DEFAULT_MAX_AD_DISPLAY_COUNT
);
maxAdClickCount
=
prefs
.
getInt
(
MAX_AD_CLICK_COUNT_KEY
,
DEFAULT_MAX_AD_CLICK_COUNT
);
adRequestCount
=
prefs
.
getInt
(
getAdRequestCountKey
(),
0
);
adRequestFailCount
=
prefs
.
getInt
(
getAdRequestFailCountKey
(),
0
);
adDisplayCount
=
prefs
.
getInt
(
getAdDisplayCountKey
(),
0
);
adClickCount
=
prefs
.
getInt
(
getAdClickCountKey
(),
0
);
}
}
public
static
synchronized
AdDisplayUtils
getInstance
()
{
fun
incrementClickShow
()
{
if
(
instance
==
null
)
{
currentOpenClick
+=
1
instance
=
new
AdDisplayUtils
();
}
return
instance
;
}
}
public
boolean
shouldSendAdRequest
()
{
return
adRequestCount
<
maxAdRequestCount
;
}
public
boolean
shouldIncrementRequestFailAd
()
{
//当前开屏请求次数
return
adRequestFailCount
<
maxAdRequestFailCount
;
private
var
currentOpenRequest
=
0
get
()
{
return
AppPreferences
.
getInstance
().
getInt
(
"currentOpenRequest_${currentDate()}"
,
field
)
}
}
set
(
value
)
{
public
boolean
shouldDisplayAd
()
{
field
=
value
return
adDisplayCount
<
maxAdDisplayCount
;
AppPreferences
.
getInstance
().
put
(
"currentOpenRequest_${currentDate()}"
,
value
,
true
)
}
}
public
boolean
shouldIncrementClickCount
()
{
//当前开屏展示次数
return
adClickCount
<
maxAdClickCount
;
private
var
currentOpenShow
=
0
get
()
{
return
AppPreferences
.
getInstance
().
getInt
(
"currentOpenShow_${currentDate()}"
,
field
)
}
}
set
(
value
)
{
public
boolean
shouldShowAd
(
String
ad_unit
)
{
field
=
value
if
(
BuildConfig
.
DEBUG
)
{
AppPreferences
.
getInstance
().
put
(
"currentOpenShow_${currentDate()}"
,
value
,
true
)
return
true
;
}
}
boolean
shouldDisplayAd
=
shouldDisplayAd
();
boolean
shouldIncrementClickCount
=
shouldIncrementClickCount
();
boolean
shouldIncrementRequestFailAd
=
shouldIncrementRequestFailAd
();
boolean
shouldSendAdRequest
=
shouldSendAdRequest
();
LogEx
.
INSTANCE
.
logDebug
(
TAG
,
"shouldSendAdRequest="
+
shouldSendAdRequest
,
false
);
LogEx
.
INSTANCE
.
logDebug
(
TAG
,
"shouldIncrementRequestFailAd="
+
shouldIncrementRequestFailAd
,
false
);
LogEx
.
INSTANCE
.
logDebug
(
TAG
,
"shouldIncrementClickCount="
+
shouldIncrementClickCount
,
false
);
LogEx
.
INSTANCE
.
logDebug
(
TAG
,
"shouldDisplayAd="
+
shouldDisplayAd
,
false
);
boolean
show
=
shouldIncrementRequestFailAd
&&
shouldSendAdRequest
&&
shouldDisplayAd
&&
shouldIncrementClickCount
;
if
(!
show
)
{
LogEx
.
INSTANCE
.
logDebug
(
"glc"
,
"!shouldShowAd"
,
false
);
JSONObject
obj2
=
new
JSONObject
();
try
{
obj2
.
put
(
"reason"
,
"ad_limit"
);
obj2
.
put
(
"shouldSendAdRequest"
,
shouldSendAdRequest
);
obj2
.
put
(
"shouldIncrementRequestFailAd"
,
shouldIncrementRequestFailAd
);
obj2
.
put
(
"shouldDisplayAd"
,
shouldDisplayAd
);
obj2
.
put
(
"shouldIncrementClickCount"
,
shouldIncrementClickCount
);
obj2
.
put
(
"adDisplayCount"
,
adDisplayCount
);
obj2
.
put
(
"maxAdDisplayCount"
,
maxAdDisplayCount
);
obj2
.
put
(
"adClickCount"
,
adClickCount
);
//当前开屏点击次数
obj2
.
put
(
"maxAdClickCount"
,
maxAdClickCount
);
private
var
currentOpenClick
=
0
get
()
{
obj2
.
put
(
"adRequestFailCount"
,
adRequestFailCount
);
return
AppPreferences
.
getInstance
().
getInt
(
"currentOpenClick_${currentDate()}"
,
field
)
obj2
.
put
(
"adRequestCount"
,
maxAdRequestFailCount
);
}
set
(
value
)
{
obj2
.
put
(
"adRequestCount"
,
adRequestCount
);
field
=
value
AppPreferences
.
getInstance
().
put
(
"currentOpenClick_${currentDate()}"
,
value
,
true
)
}
obj2
.
put
(
"ad_unit"
,
ad_unit
);
fun
shouldShowOpenAd
():
Boolean
{
EventUtils
.
INSTANCE
.
event
(
"ad_limit"
,
null
,
obj2
,
false
);
}
catch
(
JSONException
ignored
)
{
if
(
currentOpenRequest
>
open_max_request
)
{
LogEx
.
logDebug
(
TAG
,
"currentOpenRequest=$currentOpenRequest open_max_request=$open_max_request"
)
EventUtils
.
event
(
"ad_limit"
,
"currentOpenRequest=$currentOpenRequest open_max_request=$open_max_request"
)
return
false
}
}
if
(
currentOpenShow
>
open_max_show
)
{
LogEx
.
logDebug
(
TAG
,
"currentOpenShow=$currentOpenShow open_max_show=$open_max_show"
)
EventUtils
.
event
(
"ad_limit"
,
"currentOpenShow=$currentOpenShow open_max_show=$open_max_show"
)
return
false
}
}
return
show
;
if
(
currentOpenClick
>
open_max_click
)
{
LogEx
.
logDebug
(
TAG
,
"currentOpenClick=$currentOpenClick open_max_click=$open_max_click"
)
EventUtils
.
event
(
"ad_limit"
,
"currentOpenClick=$currentOpenClick open_max_click=$open_max_click"
)
return
false
}
}
return
true
}
//endregion
//region AdRequestCount
//region inter
private
int
maxAdRequestCount
=
0
;
// 最大广告请求次数
private
int
adRequestCount
=
0
;
// 当前广告请求次数
private
static
final
String
MAX_AD_REQUEST_COUNT_KEY
=
"max_ad_request_count"
;
// 广告请求次数限制的键
private
static
final
String
AD_REQUEST_COUNT_KEY
=
"ad_request_count"
;
//广告请求次数
private
v
oid
saveMaxAdRequestCount
()
{
private
v
al
inter_max_request
=
AppPreferences
.
getInstance
().
getString
(
inter_limit_request
,
"15"
).
toInt
()
SharedPreferences
prefs
=
context
.
getSharedPreferences
(
AD_PREFS_NAME
,
0
);
private
val
inter_max_show
=
AppPreferences
.
getInstance
().
getString
(
inter_limit_show
,
"10"
).
toInt
()
SharedPreferences
.
Editor
editor
=
prefs
.
edit
();
private
val
inter_max_click
=
AppPreferences
.
getInstance
().
getString
(
inter_limit_click
,
"1"
).
toInt
()
editor
.
putInt
(
MAX_AD_REQUEST_COUNT_KEY
,
maxAdRequestCount
);
fun
incrementInterRequestCount
()
{
editor
.
apply
();
currentInterRequest
+=
1
}
}
public
void
incrementAdRequestCount
()
{
fun
incrementInterShowCount
()
{
if
(!
currentDate
.
equals
(
getCurrentDate
()))
{
currentInterShow
+=
1
currentDate
=
getCurrentDate
();
adRequestCount
=
0
;
}
adRequestCount
++;
saveAdRequestCount
();
}
}
private
String
getAdRequestCountKey
()
{
fun
incrementInterClickCount
()
{
return
AD_REQUEST_COUNT_KEY
+
"_"
+
currentDate
;
currentInterClick
+=
1
}
}
private
void
saveAdRequestCount
()
{
//当前插页请求次数
SharedPreferences
prefs
=
context
.
getSharedPreferences
(
AD_PREFS_NAME
,
0
);
private
var
currentInterRequest
=
0
SharedPreferences
.
Editor
editor
=
prefs
.
edit
();
get
()
{
editor
.
putInt
(
getAdRequestCountKey
(),
adRequestCount
);
return
AppPreferences
.
getInstance
().
getInt
(
"currentInterRequest_${currentDate()}"
,
field
)
editor
.
apply
();
}
}
//endregion
set
(
value
)
{
field
=
value
//region AdRequestFailCount
AppPreferences
.
getInstance
().
put
(
"currentInterRequest_${currentDate()}"
,
value
,
true
)
private
int
maxAdRequestFailCount
;
// 请求失败总
private
int
adRequestFailCount
=
0
;
// 请求失败当前
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
void
saveMaxAdRequestFailCount
()
{
SharedPreferences
prefs
=
context
.
getSharedPreferences
(
AD_PREFS_NAME
,
0
);
SharedPreferences
.
Editor
editor
=
prefs
.
edit
();
editor
.
putInt
(
MAX_AD_REQUEST_FAIL_COUNT_KEY
,
maxAdRequestFailCount
);
editor
.
apply
();
}
}
public
void
incrementAdRequestFailCount
()
{
//当前插页展示次数
if
(!
currentDate
.
equals
(
getCurrentDate
()))
{
private
var
currentInterShow
=
0
currentDate
=
getCurrentDate
();
get
()
{
adRequestFailCount
=
0
;
return
AppPreferences
.
getInstance
().
getInt
(
"currentInterShow_${currentDate()}"
,
field
)
}
}
adRequestFailCount
++;
set
(
value
)
{
saveAdRequestFailCount
();
field
=
value
Log
.
d
(
"glc"
,
"广告请求失败:"
+
adRequestFailCount
);
AppPreferences
.
getInstance
().
put
(
"currentInterShow_${currentDate()}"
,
value
,
true
)
}
}
private
String
getAdRequestFailCountKey
()
{
//当前插页点击次数
return
AD_REQUEST_FAIL_COUNT_KEY
+
"_"
+
currentDate
;
private
var
currentInterClick
=
0
get
()
{
return
AppPreferences
.
getInstance
().
getInt
(
"currentInterClick_${currentDate()}"
,
field
)
}
}
set
(
value
)
{
private
void
saveAdRequestFailCount
()
{
field
=
value
SharedPreferences
prefs
=
context
.
getSharedPreferences
(
AD_PREFS_NAME
,
0
);
AppPreferences
.
getInstance
().
put
(
"currentInterClick_${currentDate()}"
,
value
,
true
)
SharedPreferences
.
Editor
editor
=
prefs
.
edit
();
editor
.
putInt
(
getAdRequestFailCountKey
(),
adRequestFailCount
);
editor
.
apply
();
}
}
//endregion
//region AdDisplayCount
private
int
maxAdDisplayCount
;
// 总广告展示次数限制
private
int
adDisplayCount
=
0
;
// 当前广告展示次数
private
static
final
String
MAX_AD_DISPLAY_COUNT_KEY
=
"max_ad_display_count"
;
// 总广告展示次数限制的键
private
static
final
String
AD_DISPLAY_COUNT_KEY
=
"ad_display_count"
;
// 广告展示次数的键
fun
shouldShowInterAd
():
Boolean
{
if
(
currentInterRequest
>
inter_max_request
)
{
private
void
saveMaxAdDisplayCount
()
{
LogEx
.
logDebug
(
TAG
,
"currentInterRequest=$currentInterRequest inter_max_request=$inter_max_request"
)
SharedPreferences
prefs
=
context
.
getSharedPreferences
(
AD_PREFS_NAME
,
0
);
EventUtils
.
event
(
"ad_limit"
,
"currentInterRequest=$currentInterRequest inter_max_request=$inter_max_request"
)
SharedPreferences
.
Editor
editor
=
prefs
.
edit
();
return
false
editor
.
putInt
(
MAX_AD_DISPLAY_COUNT_KEY
,
maxAdDisplayCount
);
editor
.
apply
();
}
}
if
(
currentInterShow
>
inter_max_show
)
{
public
void
incrementAdDisplayCount
()
{
LogEx
.
logDebug
(
TAG
,
"currentInterShow=$currentInterShow inter_max_show=$inter_max_show"
)
if
(!
currentDate
.
equals
(
getCurrentDate
()))
{
EventUtils
.
event
(
"ad_limit"
,
"currentInterShow=$currentInterShow inter_max_show=$inter_max_show"
)
currentDate
=
getCurrentDate
();
return
false
adDisplayCount
=
0
;
}
}
adDisplayCount
++;
if
(
currentInterClick
>
inter_max_click
)
{
LogEx
.
logDebug
(
TAG
,
"currentInterClick=$currentInterClick inter_max_click=$inter_max_click"
)
EventUtils
.
event
(
"ad_limit"
,
"currentInterClick=$currentInterClick inter_max_click=$inter_max_click"
)
int
max
=
AppPreferences
.
getInstance
().
getInt
(
"facebookAdShowEventCount"
,
3
);
return
false
if
(
adClickCount
>=
max
&&
max
!=
-
1
)
{
AppEventsLogger
logger
=
AppEventsLogger
.
newLogger
(
context
);
logger
.
logEvent
(
"ad_show"
);
AppPreferences
.
getInstance
().
put
(
"facebookAdShowEventCount"
,
-
1
);
}
}
return
true
saveAdDisplayCount
();
}
}
//endregion
//region native
private
val
native_max_request
=
AppPreferences
.
getInstance
().
getString
(
native_limit_request
,
"15"
).
toInt
()
private
val
native_max_show
=
AppPreferences
.
getInstance
().
getString
(
native_limit_show
,
"10"
).
toInt
()
private
val
native_max_click
=
AppPreferences
.
getInstance
().
getString
(
native_limit_show
,
"1"
).
toInt
()
private
String
getAdDisplayCountKey
()
{
fun
incrementNativeRequestCount
()
{
return
AD_DISPLAY_COUNT_KEY
+
"_"
+
currentDate
;
currentNativeRequest
+=
1
}
}
private
void
saveAdDisplayCount
()
{
fun
incrementNativeShowCount
()
{
SharedPreferences
prefs
=
context
.
getSharedPreferences
(
AD_PREFS_NAME
,
0
);
currentNativeShow
+=
1
SharedPreferences
.
Editor
editor
=
prefs
.
edit
();
editor
.
putInt
(
getAdDisplayCountKey
(),
adDisplayCount
);
editor
.
apply
();
}
}
//endregion
//region AdClickCount
public
int
maxAdClickCount
;
// 单个广告点击次数限制
private
int
adClickCount
=
0
;
// 当前广告点击次数
private
static
final
String
MAX_AD_CLICK_COUNT_KEY
=
"max_ad_click_count"
;
// 单个广告点击次数限制的键
private
static
final
String
AD_CLICK_COUNT_KEY
=
"ad_click_count"
;
// 广告点击次数的键
private
void
saveMaxAdClickCount
()
{
fun
incrementNativeClickCount
()
{
SharedPreferences
prefs
=
context
.
getSharedPreferences
(
AD_PREFS_NAME
,
0
);
currentNativeClick
+=
1
SharedPreferences
.
Editor
editor
=
prefs
.
edit
();
editor
.
putInt
(
MAX_AD_CLICK_COUNT_KEY
,
maxAdClickCount
);
editor
.
apply
();
}
}
public
void
incrementAdClickCount
()
{
private
var
currentNativeRequest
=
0
LogEx
.
INSTANCE
.
logDebug
(
TAG
,
"incrementAdClickCount"
,
false
);
get
()
{
if
(!
currentDate
.
equals
(
getCurrentDate
()))
{
return
AppPreferences
.
getInstance
().
getInt
(
"currentNativeRequest_${currentDate()}"
,
field
)
currentDate
=
getCurrentDate
();
adClickCount
=
0
;
}
}
adClickCount
++;
set
(
value
)
{
saveAdClickCount
();
field
=
value
AppPreferences
.
getInstance
().
put
(
"currentNativeRequest_${currentDate()}"
,
value
,
true
)
}
}
private
var
currentNativeShow
=
0
private
String
getAdClickCountKey
()
{
get
()
{
return
AD_CLICK_COUNT_KEY
+
"_"
+
currentDate
;
return
AppPreferences
.
getInstance
().
getInt
(
"currentNativeShow_${currentDate()}"
,
field
)
}
set
(
value
)
{
field
=
value
AppPreferences
.
getInstance
().
put
(
"currentNativeShow_${currentDate()}"
,
value
,
true
)
}
}
public
void
setAdClickCount
(
int
s
)
{
private
var
currentNativeClick
=
0
if
(!
currentDate
.
equals
(
getCurrentDate
()))
{
get
()
{
currentDate
=
getCurrentDate
();
return
AppPreferences
.
getInstance
().
getInt
(
"currentNativeClick_${currentDate()}"
,
field
)
adClickCount
=
0
;
}
}
adClickCount
=
s
;
set
(
value
)
{
saveAdClickCount
();
field
=
value
AppPreferences
.
getInstance
().
put
(
"currentNativeClick_${currentDate()}"
,
value
,
true
)
}
}
private
void
saveAdClickCount
()
{
SharedPreferences
prefs
=
context
.
getSharedPreferences
(
AD_PREFS_NAME
,
0
);
fun
shouldShowNative
():
Boolean
{
SharedPreferences
.
Editor
editor
=
prefs
.
edit
();
if
(
currentNativeRequest
>
native_max_request
)
{
editor
.
putInt
(
getAdClickCountKey
(),
adClickCount
);
LogEx
.
logDebug
(
TAG
,
"currentNativeRequest=$currentNativeRequest native_max_request=$native_max_request"
)
editor
.
apply
();
EventUtils
.
event
(
"ad_limit"
,
"currentNativeRequest=$currentNativeRequest native_max_request=$native_max_request"
)
LogEx
.
INSTANCE
.
logDebug
(
TAG
,
"adClickCount="
+
adClickCount
,
false
);
return
false
}
if
(
currentNativeShow
>
native_max_show
)
{
LogEx
.
logDebug
(
TAG
,
"currentNativeShow=$currentNativeShow native_max_show=$native_max_show"
)
EventUtils
.
event
(
"ad_limit"
,
"currentNativeShow=$currentNativeShow native_max_show=$native_max_show"
)
return
false
}
if
(
currentNativeClick
>
native_max_click
)
{
LogEx
.
logDebug
(
TAG
,
"currentNativeClick=$currentNativeClick native_max_click=$native_max_click"
)
EventUtils
.
event
(
"ad_limit"
,
"currentNativeClick=$currentNativeClick native_max_click=$native_max_click"
)
return
false
}
return
true
}
}
//endregion
//endregion
public
String
getCurrentDate
()
{
private
val
TAG
=
"AdDisplayUtils"
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
,
Locale
.
getDefault
());
private
fun
currentDate
():
String
{
Date
currentDate
=
Calendar
.
getInstance
().
getTime
();
val
dateFormat
=
SimpleDateFormat
(
"yyyy-MM-dd"
,
Locale
.
getDefault
())
return
dateFormat
.
format
(
currentDate
);
val
currentDate
=
Calendar
.
getInstance
().
time
return
dateFormat
.
format
(
currentDate
)
}
}
}
}
app/src/main/java/com/base/pdfviewerscannerwhite/ads/FirebaseDatabase.kt
View file @
eacf3173
package
com.base.pdfviewerscannerwhite.ads
package
com.base.pdfviewerscannerwhite.ads
import
com.base.pdfviewerscannerwhite.utils.AppPreferences
import
com.base.pdfviewerscannerwhite.utils.LogEx
import
com.base.pdfviewerscannerwhite.utils.LogEx
import
com.google.firebase.database.DataSnapshot
import
com.google.firebase.database.DataSnapshot
import
com.google.firebase.database.DatabaseError
import
com.google.firebase.database.DatabaseError
...
@@ -27,7 +28,7 @@ object FirebaseDatabase {
...
@@ -27,7 +28,7 @@ object FirebaseDatabase {
const
val
inter_limit_show
=
"inter_limit_show"
const
val
inter_limit_show
=
"inter_limit_show"
const
val
inter_limit_click
=
"inter_limit_click"
const
val
inter_limit_click
=
"inter_limit_click"
//原生广告
现在
//原生广告
限制
const
val
native_limit_request
=
"native_limit_request"
const
val
native_limit_request
=
"native_limit_request"
const
val
native_limit_show
=
"native_limit_show"
const
val
native_limit_show
=
"native_limit_show"
const
val
native_limit_click
=
"native_limit_click"
const
val
native_limit_click
=
"native_limit_click"
...
@@ -90,60 +91,63 @@ object FirebaseDatabase {
...
@@ -90,60 +91,63 @@ object FirebaseDatabase {
//可请求时间段间隔时间
//可请求时间段间隔时间
const
val
ad_request_period_interval
=
"ad_request_period_interval"
const
val
ad_request_period_interval
=
"ad_request_period_interval"
fun
saveDatabase2Sp
()
{
fun
saveDatabase2Sp
()
{
add
(
open_limit_request
,
"15"
)
//
add(open_limit_request, "15")
add
(
open_limit_show
,
"10"
)
//
add(open_limit_show, "10")
add
(
open_limit_click
,
"1"
)
//
add(open_limit_click, "1")
//
//
add
(
inter_limit_request
,
"15"
)
//
add(inter_limit_request, "15")
add
(
inter_limit_show
,
"10"
)
//
add(inter_limit_show, "10")
add
(
inter_limit_click
,
"1"
)
//
add(inter_limit_click, "1")
//
add
(
native_limit_request
,
"15"
)
//
add(native_limit_request, "15")
add
(
native_limit_show
,
"10"
)
//
add(native_limit_show, "10")
add
(
native_limit_click
,
"1"
)
//
add(native_limit_click, "1")
//
add
(
popup_count
,
"0"
)
//
add(popup_count, "0")
add
(
popup_status
,
"1"
)
//
add(popup_status, "1")
//
add
(
popup_style1_start
,
"7"
)
//
add(popup_style1_start, "7")
add
(
popup_style1_end
,
"11"
)
//
add(popup_style1_end, "11")
add
(
popup_style1_count
,
"0"
)
//
add(popup_style1_count, "0")
add
(
popup_style1_status
,
"1"
)
//
add(popup_style1_status, "1")
add
(
popup_style1_interval
,
"120"
)
//
add(popup_style1_interval, "120")
//
add
(
popup_style2_start
,
"12"
)
//
add(popup_style2_start, "12")
add
(
popup_style2_end
,
"17"
)
//
add(popup_style2_end, "17")
add
(
popup_style2_count
,
"0"
)
//
add(popup_style2_count, "0")
add
(
popup_style2_status
,
"1"
)
//
add(popup_style2_status, "1")
add
(
popup_style2_interval
,
"120"
)
//
add(popup_style2_interval, "120")
//
add
(
popup_style3_start
,
"18"
)
//
add(popup_style3_start, "18")
add
(
popup_style3_end
,
"24"
)
//
add(popup_style3_end, "24")
add
(
popup_style3_count
,
"0"
)
//
add(popup_style3_count, "0")
add
(
popup_style3_status
,
"1"
)
//
add(popup_style3_status, "1")
add
(
popup_style3_interval
,
"120"
)
//
add(popup_style3_interval, "120")
//
add
(
showLanPage
,
"1"
)
//
add(showLanPage, "1")
//
add
(
open_ad_loading
,
"8000"
)
//
add(open_ad_loading, "8000")
add
(
create_pdf_loading
,
"8000"
)
//
add(create_pdf_loading, "8000")
add
(
delete_loading
,
"8000"
)
//
add(delete_loading, "8000")
add
(
open_file_loading
,
"8000"
)
//
add(open_file_loading, "8000")
add
(
merge_loading
,
"8000"
)
//
add(merge_loading, "8000")
add
(
split_loading
,
"8000"
)
//
add(split_loading, "8000")
//
add
(
ad_request_period
,
"1"
)
//
add(ad_request_period, "1")
add
(
ad_period_max_request
,
"10"
)
//
add(ad_period_max_request, "10")
add
(
ad_request_period_interval
,
"60"
)
//
add(ad_request_period_interval, "60")
rootRef
.
addListenerForSingleValueEvent
(
object
:
ValueEventListener
{
rootRef
.
addListenerForSingleValueEvent
(
object
:
ValueEventListener
{
override
fun
onDataChange
(
dataSnapshot
:
DataSnapshot
)
{
override
fun
onDataChange
(
dataSnapshot
:
DataSnapshot
)
{
var
i
=
0
for
(
snapshot
in
dataSnapshot
.
getChildren
())
{
for
(
snapshot
in
dataSnapshot
.
getChildren
())
{
val
key1
=
snapshot
.
key
val
key1
=
snapshot
.
key
val
value1
=
snapshot
.
value
val
value1
=
snapshot
.
value
LogEx
.
logDebug
(
"Database"
,
"Key: $key1, Value: $value1"
)
i
++
LogEx
.
logDebug
(
"Database"
,
"Key: $key1, Value: $value1 $i"
)
AppPreferences
.
getInstance
().
put
(
key1
,
value1
)
}
}
}
}
...
...
app/src/main/java/com/base/pdfviewerscannerwhite/ads/admob/AdmobInterstitialUtils.kt
View file @
eacf3173
...
@@ -55,7 +55,7 @@ object AdmobInterstitialUtils {
...
@@ -55,7 +55,7 @@ object AdmobInterstitialUtils {
return
return
}
}
if
(!
AdDisplayUtils
.
getInstance
().
shouldShowAd
(
"interAd"
))
{
if
(!
AdDisplayUtils
.
shouldShowInterAd
(
))
{
onHidden
?.
invoke
(
false
)
onHidden
?.
invoke
(
false
)
return
return
}
}
...
@@ -79,7 +79,7 @@ object AdmobInterstitialUtils {
...
@@ -79,7 +79,7 @@ object AdmobInterstitialUtils {
onLoad
?.
invoke
()
onLoad
?.
invoke
()
return
return
}
}
if
(!
AdDisplayUtils
.
getInstance
().
shouldShowAd
(
"interAd"
))
{
if
(!
AdDisplayUtils
.
shouldShowInterAd
(
))
{
onLoad
?.
invoke
()
onLoad
?.
invoke
()
return
return
}
}
...
@@ -152,7 +152,7 @@ object AdmobInterstitialUtils {
...
@@ -152,7 +152,7 @@ object AdmobInterstitialUtils {
thisInterAd
?.
fullScreenContentCallback
=
object
:
FullScreenContentCallback
()
{
thisInterAd
?.
fullScreenContentCallback
=
object
:
FullScreenContentCallback
()
{
override
fun
onAdClicked
()
{
override
fun
onAdClicked
()
{
clickAd
(
thisInterAd
?.
responseInfo
,
"interAd"
)
clickAd
(
thisInterAd
?.
responseInfo
,
"interAd"
)
AdDisplayUtils
.
getInstance
().
increment
AdClickCount
()
AdDisplayUtils
.
incrementInter
AdClickCount
()
}
}
override
fun
onAdDismissedFullScreenContent
()
{
override
fun
onAdDismissedFullScreenContent
()
{
...
@@ -172,7 +172,7 @@ object AdmobInterstitialUtils {
...
@@ -172,7 +172,7 @@ object AdmobInterstitialUtils {
override
fun
onAdShowedFullScreenContent
()
{
override
fun
onAdShowedFullScreenContent
()
{
dialog
?.
dismiss
()
dialog
?.
dismiss
()
showAd
(
thisInterAd
?.
responseInfo
,
"interAd"
,
activity
)
showAd
(
thisInterAd
?.
responseInfo
,
"interAd"
,
activity
)
AdDisplayUtils
.
getInstance
().
increment
AdDisplayCount
()
AdDisplayUtils
.
incrementInter
AdDisplayCount
()
adLastDisplayTime
=
System
.
currentTimeMillis
()
/
1000
adLastDisplayTime
=
System
.
currentTimeMillis
()
/
1000
}
}
}
}
...
...
app/src/main/java/com/base/pdfviewerscannerwhite/ads/admob/AdmobNativeUtils.kt
View file @
eacf3173
...
@@ -40,7 +40,7 @@ object AdmobNativeUtils {
...
@@ -40,7 +40,7 @@ object AdmobNativeUtils {
return
return
}
}
isLoading
=
true
isLoading
=
true
if
(!
AdDisplayUtils
.
getInstance
().
shouldShowAd
(
"nativeAd"
))
{
if
(!
AdDisplayUtils
.
shouldShowNative
(
))
{
return
return
}
}
...
@@ -88,7 +88,7 @@ object AdmobNativeUtils {
...
@@ -88,7 +88,7 @@ object AdmobNativeUtils {
val
obj
=
JSONObject
()
val
obj
=
JSONObject
()
obj
.
put
(
"ad_unit"
,
"NativeAd"
)
obj
.
put
(
"ad_unit"
,
"NativeAd"
)
EventUtils
.
event
(
"ad_prepare_show_native"
,
ext
=
obj
)
EventUtils
.
event
(
"ad_prepare_show_native"
,
ext
=
obj
)
if
(!
AdDisplayUtils
.
getInstance
().
shouldShowAd
(
"nativeAd"
))
{
if
(!
AdDisplayUtils
.
shouldShowNative
(
))
{
return
return
}
}
loadingListener
=
{
loadingListener
=
{
...
...
app/src/main/java/com/base/pdfviewerscannerwhite/ads/admob/AdmobOpenUtils.kt
View file @
eacf3173
...
@@ -32,7 +32,7 @@ object AdmobOpenUtils {
...
@@ -32,7 +32,7 @@ object AdmobOpenUtils {
onLoad
?.
invoke
(
1
)
onLoad
?.
invoke
(
1
)
return
return
}
}
if
(!
AdDisplayUtils
.
getInstance
().
shouldShowAd
(
"openAd"
))
{
if
(!
AdDisplayUtils
.
shouldShowOpenAd
(
))
{
onLoad
?.
invoke
(
2
)
onLoad
?.
invoke
(
2
)
return
return
}
}
...
@@ -75,7 +75,7 @@ object AdmobOpenUtils {
...
@@ -75,7 +75,7 @@ object AdmobOpenUtils {
if
(
activity
.
isFinishing
||
activity
.
isDestroyed
)
{
if
(
activity
.
isFinishing
||
activity
.
isDestroyed
)
{
return
return
}
}
if
(!
AdDisplayUtils
.
getInstance
().
shouldShowAd
(
"openAd"
))
{
if
(!
AdDisplayUtils
.
shouldShowOpenAd
(
))
{
onHidden
?.
invoke
(
false
)
onHidden
?.
invoke
(
false
)
return
return
}
}
...
...
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