Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
B
Browser 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
Browser White
Commits
d808999d
Commit
d808999d
authored
Sep 05, 2024
by
leichao.gao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
eea87918
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
129 additions
and
154 deletions
+129
-154
MyApplication.kt
app/src/main/java/com/base/browserwhite/MyApplication.kt
+0
-1
NotificationHelp.kt
...c/main/java/com/base/browserwhite/fcm/NotificationHelp.kt
+125
-0
NotificationPushUtil.kt
...in/java/com/base/browserwhite/fcm/NotificationPushUtil.kt
+3
-144
NotificationUiUtil.kt
...main/java/com/base/browserwhite/fcm/NotificationUiUtil.kt
+1
-7
Splash2Activity.kt
...m/base/browserwhite/ui/activity/splash/Splash2Activity.kt
+0
-2
No files found.
app/src/main/java/com/base/browserwhite/MyApplication.kt
View file @
d808999d
...
...
@@ -6,7 +6,6 @@ import android.content.Intent
import
android.os.Bundle
import
android.text.TextUtils
import
com.base.browserwhite.fcm.FCMManager
import
com.base.browserwhite.fcm.NotificationPushUtil.sendNotificationWhere
import
com.base.browserwhite.fcm.PackageBroadcastReceiver
import
com.base.browserwhite.fcm.PackageBroadcastReceiver.Companion.registerPackageBroadcastReceiver
import
com.base.browserwhite.fcm.ScreenStatusReceiver
...
...
app/src/main/java/com/base/browserwhite/fcm/NotificationHelp.kt
0 → 100644
View file @
d808999d
package
com.base.browserwhite.fcm
import
android.util.Log
import
com.base.browserwhite.bean.ConstObject
import
com.base.browserwhite.utils.AppPreferences
import
com.base.browserwhite.utils.LogEx
import
com.base.browserwhite.utils.TimeUtils
import
com.base.browserwhite.utils.TimeUtils.formatTimeH
object
NotificationHelp
{
private
var
currentNotificationIdIndex
=
-
1
fun
getNotificationId
():
Int
{
var
id
=
0
NOTIFICATION_IDS
.
forEach
{
val
boolean
=
canPushNotification
(
it
)
if
(
boolean
)
{
id
=
it
Log
.
d
(
"glc"
,
"forEach"
+
it
)
return
id
}
}
return
id
}
/**
* 是否可以推送判断
*/
fun
canPushNotification
(
actionId
:
Int
):
Boolean
{
//默认可以推送
var
canPush
:
Boolean
=
true
when
(
actionId
)
{
ConstObject
.
ID_JUNK_CLEANER
->
{
canPush
=
canPushJunkClean
()
}
ConstObject
.
ID_CLEAN_JUNK_MEMORY
->
{
}
ConstObject
.
ID_NEWS
->
{
canPush
=
canPushNews
()
}
ConstObject
.
ID_WEATHER
->
{
canPush
=
canPushWeather
()
}
ConstObject
.
ID_APP_PROCESS
->
{
canPush
=
canPushAppProcess
()
}
}
return
canPush
}
//天气
private
fun
canPushWeather
():
Boolean
{
val
lastPushTime
=
AppPreferences
.
getInstance
().
getLong
(
"last_notification_time"
,
0
)
return
lastPushTime
==
0L
||
System
.
currentTimeMillis
()
-
lastPushTime
>
3
*
60
*
60
*
1000
}
//清理
private
fun
canPushJunkClean
():
Boolean
{
//last push
val
lastPushTime
=
AppPreferences
.
getInstance
().
getLong
(
"last_junk_notification_time"
,
0
)
val
flag1
=
lastPushTime
==
0L
||
System
.
currentTimeMillis
()
-
lastPushTime
>
24
*
60
*
60
*
1000
//last use
val
lastUseJunkTime
=
AppPreferences
.
getInstance
().
getLong
(
"last_use_junk_clean"
,
0
)
val
flag2
=
lastUseJunkTime
==
0L
||
System
.
currentTimeMillis
()
-
lastUseJunkTime
>
24
*
60
*
60
*
1000
return
flag1
||
flag2
}
//新闻
private
fun
canPushNews
():
Boolean
{
val
time
=
System
.
currentTimeMillis
().
formatTimeH
()
val
lashPushTime
=
AppPreferences
.
getInstance
().
getLong
(
"last_news_notification_time"
,
0
).
formatTimeH
()
return
TimeUtils
.
isTimeBetweenEightAndTenPM
()
&&
time
!=
lashPushTime
}
//app进程
private
fun
canPushAppProcess
():
Boolean
{
val
lastPushTime
=
AppPreferences
.
getInstance
().
getLong
(
"last_process_notification_time"
,
0
)
val
flag1
=
lastPushTime
==
0L
||
System
.
currentTimeMillis
()
-
lastPushTime
>
24
*
60
*
60
*
1000
val
lastUseTime
=
AppPreferences
.
getInstance
().
getLong
(
"last_process_use_time"
,
0
)
val
flag2
=
lastUseTime
==
0L
||
System
.
currentTimeMillis
()
-
lastUseTime
>
24
*
60
*
60
*
1000
return
flag1
||
flag2
}
private
fun
getNextNotificationId
():
Int
{
// 将当前通知 ID 索引加 1
currentNotificationIdIndex
++
// 如果当前通知 ID 索引超出列表范围,则将其重置为 0
if
(
currentNotificationIdIndex
>=
NOTIFICATION_IDS
.
size
)
{
currentNotificationIdIndex
=
0
}
// 返回下一个通知 ID
return
NOTIFICATION_IDS
[
currentNotificationIdIndex
]
}
private
val
NOTIFICATION_IDS
=
intArrayOf
(
ConstObject
.
ID_JUNK_CLEANER
,
ConstObject
.
ID_CLEAN_JUNK_MEMORY
,
ConstObject
.
ID_NEWS
,
ConstObject
.
ID_APP_PROCESS
,
ConstObject
.
ID_WEATHER
)
}
app/src/main/java/com/base/browserwhite/fcm/NotificationPushUtil.kt
View file @
d808999d
...
...
@@ -23,170 +23,29 @@ import java.util.Locale
object
NotificationPushUtil
{
private
val
TAG
=
"NotificationPushUtil"
private
var
handlerThread
:
HandlerThread
?
=
null
private
var
handler
:
Handler
?
=
null
const
val
PUSH_WHERE_TIMBER
=
"push_where_timber"
//定时推送
const
val
PUSH_WHERE_UN_INSTALL_BROADCAST
=
"push_where_un_install_broadcast"
//安装卸载广播
const
val
PUSH_WHERE_UNLOCK
=
"push_where_unlock"
//解锁推送
const
val
PUSH_WHERE_FCM
=
"push_where_fcm"
//fcm推送
fun
stopNotificationHandler
()
{
// 停止 HandlerThread
if
(
handler
!=
null
)
{
handler
?.
removeCallbacksAndMessages
(
null
)
}
if
(
handlerThread
!=
null
)
{
handlerThread
?.
quit
()
handlerThread
=
null
}
handler
=
null
}
/**
* 统一调用入口
* @param where [PUSH_WHERE_TIMBER]
*/
fun
Context
.
sendNotificationWhere
(
setActionId
:
Int
?,
where
:
String
)
{
val
actionId
:
Int
=
setActionId
?:
getNextNotificationId
(
)
Log
.
d
(
"glc"
,
"sendNotificationWhere"
)
val
actionId
:
Int
=
setActionId
?:
NotificationHelp
.
getNotificationId
()
if
(
MyApplication
.
PAUSED_VALUE
==
1
)
{
return
}
NotificationUiUtil
.
sendNotification
(
this
,
actionId
,
where
)
NotificationUiUtil
.
sendNotification
(
this
,
actionId
)
EventUtils
.
event
(
"showNotification"
,
where
,
null
,
false
)
// AppPreferences.getInstance().putInt("notificationCount_${getCurrentDate()}", todayShowCount + 1)
}
/**
* 是否可以推送判断
*/
fun
canPushNotification
(
actionId
:
Int
,
where
:
String
):
Boolean
{
//默认可以推送
var
canPush
:
Boolean
=
true
// val maxShowNotificationCount = AppPreferences.getInstance().getString("maxShowNotificationCount", "200").toInt()
// val todayShowCount = AppPreferences.getInstance().getInt("notificationCount_${getCurrentDate()}", 0)
// if (todayShowCount >= maxShowNotificationCount) {
// return
// }
// val interval: Int = AppPreferences.getInstance().getString("notificationInterval", "60").toIntOrNull() ?: 60
// val lastTime: Long = AppPreferences.getInstance().getLong("last_notification_time", 0)
// val nowTime = System.currentTimeMillis()
// val x = nowTime - lastTime
// if (x < (interval * 1000)) {
// return
// }
when
(
actionId
)
{
ID_JUNK_CLEANER
->
{
canPush
=
canPushJunkClean
(
where
)
}
ID_CLEAN_JUNK_MEMORY
->
{
}
ID_NEWS
->
{
canPush
=
canPushNews
(
where
)
LogEx
.
logDebug
(
TAG
,
"ID_NEWS canPush=$canPush"
)
}
ID_WEATHER
->
{
canPush
=
canPushWeather
(
where
)
LogEx
.
logDebug
(
TAG
,
"ID_WEATHER canPush=$canPush"
)
}
ID_APP_PROCESS
->
{
canPush
=
canPushAppProcess
(
where
)
LogEx
.
logDebug
(
TAG
,
"ID_APP_PROCESS canPush=$canPush"
)
}
}
return
canPush
}
//天气
private
fun
canPushWeather
(
where
:
String
):
Boolean
{
val
lastPushTime
=
AppPreferences
.
getInstance
().
getLong
(
"last_notification_time"
,
0
)
if
(
where
==
PUSH_WHERE_TIMBER
||
where
==
PUSH_WHERE_UNLOCK
)
{
return
lastPushTime
==
0L
||
System
.
currentTimeMillis
()
-
lastPushTime
>
3
*
60
*
60
*
1000
}
else
{
return
false
}
}
//清理
private
fun
canPushJunkClean
(
where
:
String
):
Boolean
{
if
(
where
==
PUSH_WHERE_TIMBER
||
where
==
PUSH_WHERE_UNLOCK
)
{
//last push
val
lastPushTime
=
AppPreferences
.
getInstance
().
getLong
(
"last_junk_notification_time"
,
0
)
val
flag1
=
lastPushTime
==
0L
||
System
.
currentTimeMillis
()
-
lastPushTime
>
24
*
60
*
60
*
1000
//last use
val
lastUseJunkTime
=
AppPreferences
.
getInstance
().
getLong
(
"last_use_junk_clean"
,
0
)
val
flag2
=
lastUseJunkTime
==
0L
||
System
.
currentTimeMillis
()
-
lastUseJunkTime
>
24
*
60
*
60
*
1000
return
flag1
||
flag2
}
else
{
return
false
}
}
//新闻
private
fun
canPushNews
(
where
:
String
):
Boolean
{
return
true
if
(
where
==
PUSH_WHERE_TIMBER
||
where
==
PUSH_WHERE_UNLOCK
)
{
val
time
=
System
.
currentTimeMillis
().
formatTimeH
()
val
lashPushTime
=
AppPreferences
.
getInstance
().
getLong
(
"last_news_notification_time"
,
0
).
formatTimeH
()
return
isTimeBetweenEightAndTenPM
()
&&
time
!=
lashPushTime
}
else
{
return
false
}
}
//app进程
private
fun
canPushAppProcess
(
where
:
String
):
Boolean
{
if
(
where
==
PUSH_WHERE_TIMBER
||
where
==
PUSH_WHERE_UNLOCK
)
{
val
lastPushTime
=
AppPreferences
.
getInstance
().
getLong
(
"last_process_notification_time"
,
0
)
val
flag1
=
lastPushTime
==
0L
||
System
.
currentTimeMillis
()
-
lastPushTime
>
24
*
60
*
60
*
1000
val
lastUseTime
=
AppPreferences
.
getInstance
().
getLong
(
"last_process_use_time"
,
0
)
val
flag2
=
lastUseTime
==
0L
||
System
.
currentTimeMillis
()
-
lastUseTime
>
24
*
60
*
60
*
1000
return
flag1
||
flag2
}
else
{
return
false
}
}
private
var
currentNotificationIdIndex
=
-
1
private
fun
getNextNotificationId
():
Int
{
// 将当前通知 ID 索引加 1
currentNotificationIdIndex
++
// 如果当前通知 ID 索引超出列表范围,则将其重置为 0
if
(
currentNotificationIdIndex
>=
NOTIFICATION_IDS
.
size
)
{
currentNotificationIdIndex
=
0
}
// 返回下一个通知 ID
return
NOTIFICATION_IDS
[
currentNotificationIdIndex
]
}
private
val
NOTIFICATION_IDS
=
intArrayOf
(
ConstObject
.
ID_JUNK_CLEANER
,
ConstObject
.
ID_CLEAN_JUNK_MEMORY
,
ConstObject
.
ID_NEWS
,
ConstObject
.
ID_APP_PROCESS
,
ConstObject
.
ID_WEATHER
)
private
fun
getCurrentDate
():
String
{
val
dateFormat
=
SimpleDateFormat
(
"yyyy-MM-dd"
,
Locale
.
getDefault
())
...
...
app/src/main/java/com/base/browserwhite/fcm/NotificationUiUtil.kt
View file @
d808999d
...
...
@@ -50,13 +50,7 @@ object NotificationUiUtil {
private
const
val
CHANNEL_NAME
=
"browser_fcm_channel"
// 通知渠道名称
@SuppressLint
(
"RemoteViewLayout"
)
fun
sendNotification
(
context
:
Context
,
actionId
:
Int
,
where
:
String
)
{
if
(!
NotificationPushUtil
.
canPushNotification
(
actionId
,
where
))
{
return
}
fun
sendNotification
(
context
:
Context
,
actionId
:
Int
)
{
when
(
actionId
)
{
ID_JUNK_CLEANER
,
ID_INSTALL_APP
,
ID_UNINSTALL_APP
->
{
//清理
var
size
=
fastGetJunkSize
(
context
)
...
...
app/src/main/java/com/base/browserwhite/ui/activity/splash/Splash2Activity.kt
View file @
d808999d
...
...
@@ -68,8 +68,6 @@ class Splash2Activity : BaseActivity<ActivitySplash2Binding>(),
return
}
NotificationPushUtil
.
stopNotificationHandler
()
NotificationPushUtil
.
stopNotificationHandlerNews
()
jumpType
=
intent
.
getIntExtra
(
"actionId"
,
0
)
closeNotification
()
mTaskManager
=
TaskManager
(
binding
,
this
)
...
...
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