Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
E
Easy Cleaner Junk
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
Easy Cleaner Junk
Commits
32c17708
Commit
32c17708
authored
Jul 01, 2024
by
leichao.gao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
推送类型 and 广告限制
parent
fa677fdd
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
177 additions
and
67 deletions
+177
-67
ConfigBean.kt
...ain/java/com/test/easy/easycleanerjunk/bean/ConfigBean.kt
+2
-11
NotificationUtil.java
...a/com/test/easy/easycleanerjunk/fcm/NotificationUtil.java
+20
-1
AdDisplayUtils.java
...m/test/easy/easycleanerjunk/helps/ads/AdDisplayUtils.java
+99
-0
AdmobUtils.kt
...ava/com/test/easy/easycleanerjunk/helps/ads/AdmobUtils.kt
+56
-55
No files found.
app/src/main/java/com/test/easy/easycleanerjunk/bean/ConfigBean.kt
View file @
32c17708
...
...
@@ -44,18 +44,9 @@ data class ConfigBean(
const
val
ID_APP_MANAGER
=
11011
//应用管理
const
val
ID_SIMILAR_IMAGE
=
11015
//清理相似图片
const
val
ID_SCREENSHOT_CLEAN
=
12000
//截图清理
const
val
ID_BATTERY
=
11004
//截图清理
const
val
ID_WHATSAPP
=
12001
//截图清理
fun
ConfigBean
.
getActionPushInterval
(
actionId
:
Int
):
Int
{
val
interval
=
when
(
actionId
)
{
ID_JUNK_CLEAN_PUSH
->
push_interval_11001
ID_PHOTO_COMPRESS
->
push_interval_11010
ID_APP_MANAGER
->
push_interval_11011
ID_SIMILAR_IMAGE
->
push_interval_11015
ID_SCREENSHOT_CLEAN
->
push_interval_12000
else
->
0
}
return
interval
}
}
}
\ No newline at end of file
app/src/main/java/com/test/easy/easycleanerjunk/fcm/NotificationUtil.java
View file @
32c17708
...
...
@@ -141,6 +141,22 @@ public class NotificationUtil {
icon
=
R
.
drawable
.
similar
;
desc
=
"Check similar photos to release more space"
;
btn
=
"Clean up"
;
}
else
if
(
actionId
==
ConfigBean
.
ID_APP_MANAGER
){
icon
=
R
.
drawable
.
appmanager
;
desc
=
"Manage apps that are not frequently used, free up storage space on your phone, and keep it running smoothly!"
;
btn
=
"View"
;
}
else
if
(
actionId
==
ConfigBean
.
ID_BATTERY
){
icon
=
R
.
drawable
.
battery
;
desc
=
"View phone battery consumption recently!"
;
btn
=
"View"
;
}
else
if
(
actionId
==
ConfigBean
.
ID_SCREENSHOT_CLEAN
){
icon
=
R
.
drawable
.
similar
;
desc
=
"Too many screenshots? Free up your phone storage!"
;
btn
=
"View"
;
}
else
if
(
actionId
==
ConfigBean
.
ID_WHATSAPP
){
icon
=
R
.
drawable
.
similar
;
desc
=
"Running out of storage space on your phone? Clean up WhatsApp to free up space"
;
btn
=
"View"
;
}
else
{
return
;
}
...
...
@@ -192,6 +208,9 @@ public class NotificationUtil {
ConfigBean
.
ID_PHOTO_COMPRESS
,
ConfigBean
.
ID_APP_MANAGER
,
ConfigBean
.
ID_SIMILAR_IMAGE
,
ConfigBean
.
ID_SCREENSHOT_CLEAN
ConfigBean
.
ID_SCREENSHOT_CLEAN
,
ConfigBean
.
ID_BATTERY
,
ConfigBean
.
ID_WHATSAPP
};
}
app/src/main/java/com/test/easy/easycleanerjunk/helps/ads/AdDisplayUtils.java
0 → 100644
View file @
32c17708
package
com
.
test
.
easy
.
easycleanerjunk
.
helps
.
ads
;
import
android.content.Context
;
import
android.content.SharedPreferences
;
import
com.test.easy.easycleanerjunk.MyApplication
;
import
java.text.SimpleDateFormat
;
import
java.util.Calendar
;
import
java.util.Date
;
import
java.util.Locale
;
import
android.content.SharedPreferences
;
import
java.text.SimpleDateFormat
;
import
java.util.Calendar
;
import
java.util.Date
;
import
java.util.Locale
;
public
class
AdDisplayUtils
{
private
static
final
int
MAX_AD_DISPLAY_COUNT
=
5
;
// 总广告展示次数限制
private
static
final
int
MAX_AD_CLICK_COUNT
=
2
;
// 单个广告点击次数限制
private
static
final
String
AD_PREFS_NAME
=
"ad_prefs"
;
// SharedPreferences 名称
private
static
final
String
AD_DISPLAY_COUNT_KEY
=
"ad_display_count"
;
// 广告展示次数的键
private
static
final
String
AD_CLICK_COUNT_KEY
=
"ad_click_count"
;
// 广告点击次数的键
private
static
AdDisplayUtils
instance
;
// 单例对象
private
int
adDisplayCount
=
0
;
// 当前广告展示次数
private
int
adClickCount
=
0
;
// 当前广告点击次数
private
String
currentDate
;
// 当前日期
private
AdDisplayUtils
()
{
currentDate
=
getCurrentDate
();
SharedPreferences
prefs
=
MyApplication
.
context
.
getSharedPreferences
(
AD_PREFS_NAME
,
0
);
adDisplayCount
=
prefs
.
getInt
(
getAdDisplayCountKey
(),
0
);
adClickCount
=
prefs
.
getInt
(
getAdClickCountKey
(),
0
);
}
public
static
synchronized
AdDisplayUtils
getInstance
()
{
if
(
instance
==
null
)
{
instance
=
new
AdDisplayUtils
();
}
return
instance
;
}
public
boolean
shouldDisplayAd
()
{
return
adDisplayCount
<
MAX_AD_DISPLAY_COUNT
;
}
public
boolean
shouldIncrementClickCount
()
{
return
adClickCount
<
MAX_AD_CLICK_COUNT
;
}
public
void
incrementAdDisplayCount
()
{
if
(!
currentDate
.
equals
(
getCurrentDate
()))
{
currentDate
=
getCurrentDate
();
adDisplayCount
=
0
;
}
adDisplayCount
++;
saveAdDisplayCount
();
}
public
void
incrementAdClickCount
()
{
if
(!
currentDate
.
equals
(
getCurrentDate
()))
{
currentDate
=
getCurrentDate
();
adClickCount
=
0
;
}
adClickCount
++;
saveAdClickCount
();
}
private
String
getCurrentDate
()
{
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
,
Locale
.
getDefault
());
Date
currentDate
=
Calendar
.
getInstance
().
getTime
();
return
dateFormat
.
format
(
currentDate
);
}
private
String
getAdDisplayCountKey
()
{
return
AD_DISPLAY_COUNT_KEY
+
"_"
+
currentDate
;
}
private
String
getAdClickCountKey
()
{
return
AD_CLICK_COUNT_KEY
+
"_"
+
currentDate
;
}
private
void
saveAdDisplayCount
()
{
SharedPreferences
prefs
=
MyApplication
.
context
.
getSharedPreferences
(
AD_PREFS_NAME
,
0
);
SharedPreferences
.
Editor
editor
=
prefs
.
edit
();
editor
.
putInt
(
getAdDisplayCountKey
(),
adDisplayCount
);
editor
.
apply
();
}
private
void
saveAdClickCount
()
{
SharedPreferences
prefs
=
MyApplication
.
context
.
getSharedPreferences
(
AD_PREFS_NAME
,
0
);
SharedPreferences
.
Editor
editor
=
prefs
.
edit
();
editor
.
putInt
(
getAdClickCountKey
(),
adClickCount
);
editor
.
apply
();
}
}
app/src/main/java/com/test/easy/easycleanerjunk/helps/ads/AdmobUtils.kt
View file @
32c17708
...
...
@@ -268,36 +268,64 @@ object AdmobUtils {
})
}
fun
showInterstitialAd
(
activity
:
Activity
,
skip
:
Boolean
=
false
,
isASkip
:
Boolean
=
true
,
isFirst
:
Boolean
=
true
,
onHidden
:
(()
->
Unit
)?
=
null
)
{
private
fun
isAdExpired
():
Boolean
{
return
System
.
currentTimeMillis
()
-
interLoadTime
>
1000
*
60
*
60
}
fun
showInterstitialAd
(
activity
:
Activity
,
isLoadAdNow
:
Boolean
=
false
,
onHidden
:
(()
->
Unit
)?
=
null
)
{
if
(
activity
.
isFinishing
||
activity
.
isDestroyed
)
{
return
}
val
obj
=
JSONObject
()
obj
.
put
(
"ad_unit"
,
"interAd"
)
if
(
skip
)
{
if
(
isAdExpired
())
{
interAd
=
null
loadInterstitialAd
(
activity
)
onHidden
?.
invoke
()
return
}
if
(
System
.
currentTimeMillis
()
-
interLoadTime
>
1000
*
60
*
60
)
{
interAd
=
null
val
obj
=
JSONObject
()
obj
.
put
(
"ad_unit"
,
"interAd"
)
loadInterstitialAd
(
activity
)
if
(!
AdDisplayUtils
.
getInstance
().
shouldDisplayAd
()){
onHidden
?.
invoke
()
return
}
if
(!
AdDisplayUtils
.
getInstance
().
shouldIncrementClickCount
()){
onHidden
?.
invoke
()
return
}
if
(
interAd
!=
null
)
{
displayInterstitialAd
(
activity
,
onHidden
)
}
else
{
showAdDialogAndLoadInterstitial
(
activity
,
isLoadAdNow
,
onHidden
)
}
}
private
fun
showAdDialogAndLoadInterstitial
(
activity
:
Activity
,
isLoadAdNow
:
Boolean
,
onHidden
:
(()
->
Unit
)?){
var
mDialog
:
Dialog
?
=
null
mDialog
=
CustomDialog
(
activity
,
R
.
layout
.
dialog_ad_loading
)
mDialog
.
show
()
loadInterstitialAd
(
activity
)
{
mDialog
?.
dismiss
()
if
(!
isLoadAdNow
)
{
showInterstitialAd
(
activity
,
true
)
{
onHidden
?.
invoke
()
}
}
}
if
(
isLoadAdNow
)
{
mDialog
?.
dismiss
()
onHidden
?.
invoke
()
}
}
private
fun
displayInterstitialAd
(
activity
:
Activity
,
onHidden
:
(()
->
Unit
)?
=
null
){
val
thisInterAd
=
interAd
interAd
=
null
thisInterAd
?.
fullScreenContentCallback
=
object
:
FullScreenContentCallback
()
{
override
fun
onAdClicked
()
{
click
(
thisInterAd
?.
responseInfo
,
"interAd"
)
AdDisplayUtils
.
getInstance
().
incrementAdClickCount
()
}
override
fun
onAdDismissedFullScreenContent
()
{
...
...
@@ -310,41 +338,14 @@ object AdmobUtils {
interAd
=
null
onHidden
?.
invoke
()
loadInterstitialAd
(
activity
)
val
obj
=
JSONObject
()
obj
.
put
(
"reason"
,
p0
.
message
)
obj
.
put
(
"ad_unit"
,
"interAd"
)
}
override
fun
onAdShowedFullScreenContent
()
{
show
(
thisInterAd
?.
responseInfo
,
"interAd"
,
activity
)
AdDisplayUtils
.
getInstance
().
incrementAdDisplayCount
()
}
}
thisInterAd
?.
show
(
activity
)
}
else
{
var
mDialog
:
Dialog
?
=
null
mDialog
=
CustomDialog
(
activity
,
R
.
layout
.
dialog_ad_loading
)
mDialog
.
show
()
loadInterstitialAd
(
activity
)
{
if
(
isFirst
)
{
}
mDialog
?.
dismiss
()
if
(
isASkip
)
{
showInterstitialAd
(
activity
,
false
,
false
)
{
onHidden
?.
invoke
()
}
}
}
val
obj
=
JSONObject
()
obj
.
put
(
"reason"
,
"no_ad"
)
obj
.
put
(
"ad_unit"
,
"interAd"
)
if
(!
isASkip
)
{
mDialog
?.
dismiss
()
onHidden
?.
invoke
()
}
}
}
private
fun
pull
(
...
...
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