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
fbfdfe55
Commit
fbfdfe55
authored
Nov 11, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
5e69f782
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
101 additions
and
106 deletions
+101
-106
NotificationUtil.kt
...c/main/java/com/base/datarecovery/fcm/NotificationUtil.kt
+44
-32
RecoveryTimerManager.kt
...in/java/com/base/datarecovery/fcm/RecoveryTimerManager.kt
+55
-44
InstallHelps.kt
...src/main/java/com/base/datarecovery/utils/InstallHelps.kt
+2
-30
No files found.
app/src/main/java/com/base/datarecovery/fcm/NotificationUtil.kt
View file @
fbfdfe55
...
@@ -12,6 +12,7 @@ import android.os.HandlerThread
...
@@ -12,6 +12,7 @@ import android.os.HandlerThread
import
android.widget.RemoteViews
import
android.widget.RemoteViews
import
androidx.core.app.NotificationCompat
import
androidx.core.app.NotificationCompat
import
androidx.core.graphics.drawable.IconCompat
import
androidx.core.graphics.drawable.IconCompat
import
com.base.datarecovery.BuildConfig
import
com.base.datarecovery.MyApplication
import
com.base.datarecovery.MyApplication
import
com.base.datarecovery.R
import
com.base.datarecovery.R
import
com.base.datarecovery.activity.splash.Splash2Activity
import
com.base.datarecovery.activity.splash.Splash2Activity
...
@@ -51,9 +52,50 @@ import java.util.Random
...
@@ -51,9 +52,50 @@ import java.util.Random
*/
*/
object
NotificationUtil
{
object
NotificationUtil
{
private
val
TAG
=
"NotificationUtil"
private
const
val
CHANNEL_ID
=
"recovery_notification_id"
// 通知渠道ID
private
const
val
CHANNEL_ID
=
"recovery_notification_id"
// 通知渠道ID
private
const
val
CHANNEL_NAME
=
"recovery_fcm_channel"
// 通知渠道名称
private
const
val
CHANNEL_NAME
=
"recovery_fcm_channel"
// 通知渠道名称
fun
sendNotification
(
context
:
Context
,
where
:
String
=
""
)
{
LogEx
.
logDebug
(
TAG
,
"sendNotification where=$where"
)
if
(
MyApplication
.
PAUSED_VALUE
==
1
)
{
LogEx
.
logDebug
(
TAG
,
"MyApplication.PAUSED_VALUE == 1"
)
return
}
if
(!
BuildConfig
.
DEBUG
)
{
val
currentNum
=
AppPreferences
.
getInstance
().
getInt
(
"showNotificationCount_"
+
AdDisplayUtils
.
getInstance
().
getCurrentDate
(),
0
)
val
maxNum
=
AppPreferences
.
getInstance
().
getString
(
"maxShowNotificationCount"
,
"156"
).
toIntOrNull
()
?:
156
if
(
currentNum
>=
maxNum
)
{
LogEx
.
logDebug
(
"glc"
,
"currentNum >= maxNum"
)
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
))
{
LogEx
.
logDebug
(
"glc"
,
"sendNotification x < (interval * 1000)"
)
return
}
}
val
actionId
:
Int
=
getNextNotificationId
()
sendNotification
(
context
,
actionId
)
incrementNotification
()
EventUtils
.
event
(
"showNotification"
,
where
,
null
,
false
)
startHover
(
context
,
actionId
)
}
fun
sendNotification
(
context
:
Context
,
actionId
:
Int
)
{
fun
sendNotification
(
context
:
Context
,
actionId
:
Int
)
{
val
bigRemoteViews
=
RemoteViews
(
context
.
packageName
,
R
.
layout
.
notification_common
)
val
bigRemoteViews
=
RemoteViews
(
context
.
packageName
,
R
.
layout
.
notification_common
)
val
smallRemoteViews
=
RemoteViews
(
context
.
packageName
,
R
.
layout
.
notification_common_small
)
val
smallRemoteViews
=
RemoteViews
(
context
.
packageName
,
R
.
layout
.
notification_common_small
)
...
@@ -253,38 +295,8 @@ object NotificationUtil {
...
@@ -253,38 +295,8 @@ object NotificationUtil {
AppPreferences
.
getInstance
().
put
(
key
,
s
)
AppPreferences
.
getInstance
().
put
(
key
,
s
)
}
}
fun
sendNotification
(
context
:
Context
,
where
:
String
=
""
)
{
val
currentNum
=
AppPreferences
.
getInstance
().
getInt
(
"showNotificationCount_"
+
AdDisplayUtils
.
getInstance
().
getCurrentDate
(),
0
)
val
maxNum
=
AppPreferences
.
getInstance
().
getString
(
"maxShowNotificationCount"
,
"156"
).
toIntOrNull
()
?:
156
if
(
currentNum
>=
maxNum
)
{
LogEx
.
logDebug
(
"glc"
,
"currentNum >= maxNum"
)
return
}
val
actionId
:
Int
=
getNextNotificationId
()
if
(
MyApplication
.
PAUSED_VALUE
==
1
)
{
LogEx
.
logDebug
(
"glc"
,
"MyApplication.PAUSED_VALUE == 1)"
)
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
))
{
LogEx
.
logDebug
(
"glc"
,
"sendNotification x < (interval * 1000)"
)
return
}
sendNotification
(
context
,
actionId
)
incrementNotification
()
EventUtils
.
event
(
"showNotification"
,
where
,
null
,
false
)
private
fun
startHover
(
context
:
Context
,
actionId
:
Int
)
{
val
open
:
Int
=
AppPreferences
.
getInstance
().
getString
(
"open"
,
"0"
).
toIntOrNull
()
?:
0
val
open
:
Int
=
AppPreferences
.
getInstance
().
getString
(
"open"
,
"0"
).
toIntOrNull
()
?:
0
if
(
open
==
1
)
{
if
(
open
==
1
)
{
...
@@ -328,7 +340,7 @@ object NotificationUtil {
...
@@ -328,7 +340,7 @@ object NotificationUtil {
private
var
currentNotificationIdIndex
=
-
1
private
var
currentNotificationIdIndex
=
-
1
fun
getNextNotificationId
():
Int
{
private
fun
getNextNotificationId
():
Int
{
// 将当前通知 ID 索引加 1
// 将当前通知 ID 索引加 1
currentNotificationIdIndex
++
currentNotificationIdIndex
++
...
...
app/src/main/java/com/base/datarecovery/fcm/RecoveryTimerManager.kt
View file @
fbfdfe55
package
com.base.datarecovery.fcm
;
package
com.base.datarecovery.fcm
import
android.util.Log;
import
com.base.datarecovery.BuildConfig
import
com.base.datarecovery.MyApplication;
import
com.base.datarecovery.MyApplication
import
java.util.Timer;
import
com.base.datarecovery.fcm.NotificationUtil.sendNotification
import
java.util.TimerTask;
import
com.base.datarecovery.help.BaseApplication.Companion.context
import
com.base.datarecovery.utils.AppPreferences
import
com.base.datarecovery.utils.LogEx
import
java.util.Timer
import
java.util.TimerTask
public
class
RecoveryTimerManager
{
object
RecoveryTimerManager
{
private
static
RecoveryTimerManager
instance
;
private
Timer
taskTimer
;
private
boolean
isTimerActive
;
private
RecoveryTimerManager
()
{
private
val
TAG
=
"RecoveryTimerManager"
// 私有构造方法
private
var
taskTimer
:
Timer
?
=
null
}
private
var
isTaskTimerActive
:
Boolean
=
false
public
static
synchronized
RecoveryTimerManager
getInstance
()
{
if
(
instance
==
null
)
{
instance
=
new
RecoveryTimerManager
();
}
return
instance
;
}
public
void
scheduleTask
(
long
delay
,
long
period
)
{
private
fun
scheduleTask
(
delay
:
Long
,
period
:
Long
)
{
synchronized
(
RecoveryTimerManager
.
class
)
{
synchronized
(
RecoveryTimerManager
::
class
.
java
)
{
ensureTimerIsStopped
();
// 确保定时器未运行
ensureTimerIsStopped
()
// 确保定时器未运行
taskTimer
=
new
Timer
();
// 创建新的 Timer 实例
taskTimer
=
Timer
()
// 创建新的 Timer 实例
TimerTask
task
=
new
TimerTask
()
{
val
task
:
TimerTask
=
object
:
TimerTask
()
{
@Override
override
fun
run
()
{
public
void
run
()
{
LogEx
.
logDebug
(
TAG
,
"Scheduled task is running"
)
Log
.
d
(
"glc"
,
"Scheduled task is running"
);
// 确保设备处于交互状态,未锁定,且应用未暂停
// 确保设备处于交互状态,未锁定,且应用未暂停
if
(
ScreenStatusReceiver
.
isDeviceInteractive
()
&&
if
(
ScreenStatusReceiver
.
isDeviceInteractive
()
&&
!
ScreenStatusReceiver
.
isSecureLockActive
()
&&
MyApplication
.
PAUSED_VALUE
!=
1
!
ScreenStatusReceiver
.
isSecureLockActive
()
&&
)
{
MyApplication
.
PAUSED_VALUE
!=
1
)
{
LogEx
.
logDebug
(
TAG
,
"Scheduled task conditions are met"
)
Log
.
d
(
"glc"
,
"Scheduled task conditions are met"
);
sendNotification
(
context
,
"scheduleTask"
)
NotificationUtil
.
INSTANCE
.
sendNotification
(
MyApplication
.
context
,
"scheduleTask"
);
}
}
}
}
}
;
}
taskTimer
.
schedule
(
task
,
delay
,
period
);
// 调度任务
taskTimer
?.
schedule
(
task
,
delay
,
period
)
// 调度任务
isT
imerActive
=
true
;
// 设置定时器状态为活跃
isT
askTimerActive
=
true
// 设置定时器状态为活跃
}
}
}
}
private
void
ensureTimerIsStopped
()
{
private
fun
ensureTimerIsStopped
()
{
if
(
isTimerActive
)
{
if
(
isT
askT
imerActive
)
{
if
(
taskTimer
!=
null
)
{
if
(
taskTimer
!=
null
)
{
taskTimer
.
cancel
();
taskTimer
?.
cancel
()
taskTimer
.
purge
();
// 清除所有取消的任务
taskTimer
?.
purge
()
// 清除所有取消的任务
}
}
isT
imerActive
=
false
;
// 重置定时器状态
isT
askTimerActive
=
false
// 重置定时器状态
}
}
}
}
p
ublic
void
stopTaskTimer
()
{
p
rivate
fun
stopTaskTimer
()
{
synchronized
(
RecoveryTimerManager
.
class
)
{
synchronized
(
RecoveryTimerManager
::
class
.
java
)
{
ensureTimerIsStopped
()
;
// 停止定时器
ensureTimerIsStopped
()
// 停止定时器
}
}
}
}
public
boolean
isTaskTimerActive
()
{
return
isTimerActive
;
fun
changeTimerSp
()
{
val
timerStatus
:
Int
=
AppPreferences
.
getInstance
().
getString
(
"timerS"
,
"1"
).
toIntOrNull
()
?:
1
if
(
timerStatus
==
0
)
{
stopTaskTimer
()
}
else
{
var
timerDelay
:
Int
=
AppPreferences
.
getInstance
().
getString
(
"timerDelay"
,
"1"
).
toIntOrNull
()
?:
1
timerDelay
=
(
timerDelay
*
60
*
1000
)
var
timerInterval
:
Int
=
AppPreferences
.
getInstance
().
getString
(
"timerInterval"
,
"7"
).
toIntOrNull
()
?:
7
timerInterval
=
(
timerInterval
*
60
*
1000
)
LogEx
.
logDebug
(
TAG
,
"timerDelay=$timerDelay timerInterval=$timerInterval"
)
if
(!
isTaskTimerActive
)
{
scheduleTask
(
timerDelay
.
toLong
(),
timerInterval
.
toLong
())
}
}
}
}
}
}
\ No newline at end of file
app/src/main/java/com/base/datarecovery/utils/InstallHelps.kt
View file @
fbfdfe55
...
@@ -6,6 +6,7 @@ import com.android.installreferrer.api.InstallReferrerStateListener
...
@@ -6,6 +6,7 @@ import com.android.installreferrer.api.InstallReferrerStateListener
import
com.base.datarecovery.BuildConfig
import
com.base.datarecovery.BuildConfig
import
com.base.datarecovery.ads.AdmobMaxHelper
import
com.base.datarecovery.ads.AdmobMaxHelper
import
com.base.datarecovery.fcm.RecoveryTimerManager
import
com.base.datarecovery.fcm.RecoveryTimerManager
import
com.base.datarecovery.fcm.RecoveryTimerManager.changeTimerSp
import
com.base.datarecovery.help.BaseApplication
import
com.base.datarecovery.help.BaseApplication
import
org.json.JSONObject
import
org.json.JSONObject
...
@@ -84,37 +85,8 @@ object InstallHelps {
...
@@ -84,37 +85,8 @@ object InstallHelps {
if
(
callBackAd
)
{
if
(
callBackAd
)
{
AdmobMaxHelper
.
initAdmobMaxAd
()
AdmobMaxHelper
.
initAdmobMaxAd
()
}
}
if
(
Build
.
VERSION
.
SDK_INT
<
Build
.
VERSION_CODES
.
UPSIDE_DOWN_CAKE
)
{
val
notificationSwitch
=
AppPreferences
.
getInstance
().
getString
(
"notificationSwitch"
,
"0"
).
toInt
()
if
(
notificationSwitch
==
0
)
{
val
notificationTimeInterval
=
AppPreferences
.
getInstance
().
getString
(
"notificationTimeInterval"
,
"60"
).
toInt
()
NotificationTimerManager
.
getInstance
()
.
startTimer
(
(
notificationTimeInterval
*
1000
).
toLong
(),
(
notificationTimeInterval
*
1000
).
toLong
()
)
}
}
changeTimerSp
()
val
timerStatus
:
Int
=
AppPreferences
.
getInstance
().
getString
(
"timerS"
,
"1"
)
.
toIntOrNull
()
?:
1
if
(
timerStatus
==
0
)
{
RecoveryTimerManager
.
getInstance
().
stopTaskTimer
()
}
else
{
val
timerDelay
:
Int
=
AppPreferences
.
getInstance
().
getString
(
"timerDelay"
,
"1"
)
.
toIntOrNull
()
?:
1
val
timerInterval
:
Int
=
AppPreferences
.
getInstance
().
getString
(
"timerInterval"
,
"7"
)
.
toIntOrNull
()
?:
7
if
(!
RecoveryTimerManager
.
getInstance
().
isTaskTimerActive
)
{
RecoveryTimerManager
.
getInstance
().
scheduleTask
(
(
timerDelay
*
60
*
1000
).
toLong
(),
(
timerInterval
*
60
*
1000
).
toLong
()
)
}
}
}
}
}
}
}
}
\ No newline at end of file
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