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
c3a71894
Commit
c3a71894
authored
Jul 11, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of gitlab.huolea.com:koko/data-recovery-white
parents
6f404f00
ac1ee685
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
492 additions
and
468 deletions
+492
-468
AndroidManifest.xml
app/src/main/AndroidManifest.xml
+30
-0
ResultActivity.kt
...ain/java/com/base/datarecovery/activity/ResultActivity.kt
+2
-2
AppFunctionAdapter.kt
.../java/com/base/datarecovery/adapter/AppFunctionAdapter.kt
+2
-2
ConstObject.kt
app/src/main/java/com/base/datarecovery/bean/ConstObject.kt
+13
-13
CloseNotificationReceiver.kt
...va/com/base/datarecovery/fcm/CloseNotificationReceiver.kt
+2
-2
FCMManager.java
app/src/main/java/com/base/datarecovery/fcm/FCMManager.java
+48
-0
FcmReceiver.java
app/src/main/java/com/base/datarecovery/fcm/FcmReceiver.java
+14
-0
FcmService.java
app/src/main/java/com/base/datarecovery/fcm/FcmService.java
+58
-0
MessagingService.java
...main/java/com/base/datarecovery/fcm/MessagingService.java
+56
-0
NotificationUtil.kt
...c/main/java/com/base/datarecovery/fcm/NotificationUtil.kt
+3
-3
RecoveryTimerManager.java
.../java/com/base/datarecovery/fcm/RecoveryTimerManager.java
+62
-0
ScreenStatusReceiver.java
.../java/com/base/datarecovery/fcm/ScreenStatusReceiver.java
+70
-0
AppPreferences.java
...main/java/com/base/datarecovery/utils/AppPreferences.java
+127
-0
SPUtils.java
app/src/main/java/com/base/datarecovery/utils/SPUtils.java
+0
-441
RateStarPop.kt
app/src/main/java/com/base/datarecovery/view/RateStarPop.kt
+5
-5
No files found.
app/src/main/AndroidManifest.xml
View file @
c3a71894
...
...
@@ -8,6 +8,15 @@
<uses-permission
android:name=
"android.permission.MANAGE_EXTERNAL_STORAGE"
/>
<uses-permission
android:name=
"android.permission.FOREGROUND_SERVICE"
/>
<!-- fcm 添加以下权限 -->
<uses-permission
android:name=
"android.permission.WAKE_LOCK"
/>
<uses-permission
android:name=
"com.google.android.c2dm.permission.RECEIVE"
/>
<uses-permission
android:name=
"android.permission.RECEIVE_BOOT_COMPLETED"
/>
<uses-permission
android:name=
"android.permission.POST_NOTIFICATIONS"
/>
<uses-permission
android:name=
"android.permission.FOREGROUND_SERVICE"
/>
<uses-permission
android:name=
"android.permission.REQUEST_DELETE_PACKAGES"
/>
<application
android:name=
".MyApplication"
android:allowBackup=
"true"
...
...
@@ -159,6 +168,27 @@
<meta-data
android:name=
"com.facebook.sdk.ApplicationId"
android:value=
"@string/facebook_app_id"
/>
<service
android:name=
".fcm.FcmService"
android:exported=
"true"
>
<intent-filter>
<action
android:name=
"com.google.firebase.MESSAGING_EVENT"
/>
</intent-filter>
</service>
<!-- 添加以下接收器 -->
<!-- 注册广播 -->
<receiver
android:name=
".fcm.FcmReceiver"
android:exported=
"true"
android:permission=
"com.google.android.c2dm.permission.SEND"
>
<intent-filter>
<action
android:name=
"com.google.firebase.MESSAGING_EVENT"
/>
<action
android:name=
"com.google.android.c2dm.intent.RECEIVE"
/>
<category
android:name=
"com.test.easy.cleanerjunk"
/>
</intent-filter>
</receiver>
</application>
</manifest>
\ No newline at end of file
app/src/main/java/com/base/datarecovery/activity/ResultActivity.kt
View file @
c3a71894
...
...
@@ -16,7 +16,7 @@ import com.base.datarecovery.databinding.ActivityLayoutResultBinding
import
com.base.datarecovery.help.BaseActivity
import
com.base.datarecovery.help.KotlinExt.toFormatSize
import
com.base.datarecovery.utils.BarUtils
import
com.base.datarecovery.utils.
SPUtil
s
import
com.base.datarecovery.utils.
AppPreference
s
class
ResultActivity
:
BaseActivity
<
ActivityLayoutResultBinding
>()
{
...
...
@@ -60,7 +60,7 @@ class ResultActivity : BaseActivity<ActivityLayoutResultBinding>() {
}
else
{
binding
.
tvInfo
.
text
=
"No junk files found."
}
SPUtil
s
.
getInstance
().
put
(
"last_use_junk_cleaner"
,
System
.
currentTimeMillis
())
AppPreference
s
.
getInstance
().
put
(
"last_use_junk_cleaner"
,
System
.
currentTimeMillis
())
}
else
->
{}
...
...
app/src/main/java/com/base/datarecovery/adapter/AppFunctionAdapter.kt
View file @
c3a71894
...
...
@@ -11,7 +11,7 @@ import com.base.datarecovery.bean.ConstObject.JUNK_CLEANER
import
com.base.datarecovery.bean.ConstObject.REPEAT_PHOTOS
import
com.base.datarecovery.bean.ConstObject.SCREENSHOT_CLEANER
import
com.base.datarecovery.databinding.ItemResultFunBinding
import
com.base.datarecovery.utils.
SPUtil
s
import
com.base.datarecovery.utils.
AppPreference
s
import
com.base.datarecovery.view.XmlEx.inflate
import
java.util.Collections
...
...
@@ -64,7 +64,7 @@ class AppFunctionAdapter(val click: (name: String) -> Unit) :
fun
updateListPosition
()
{
//本次进入结果页,判断使用垃圾的功能是否超过5分钟
val
lastUseJunkCleaner
=
SPUtil
s
.
getInstance
().
getLong
(
"last_use_junk_cleaner"
,
0
)
val
lastUseJunkCleaner
=
AppPreference
s
.
getInstance
().
getLong
(
"last_use_junk_cleaner"
,
0
)
if
((
System
.
currentTimeMillis
()
-
lastUseJunkCleaner
)
>=
60
*
5
*
1000
)
{
}
else
{
Collections
.
rotate
(
list
,
list
.
size
-
1
)
...
...
app/src/main/java/com/base/datarecovery/bean/ConstObject.kt
View file @
c3a71894
package
com.base.datarecovery.bean
import
com.base.datarecovery.utils.
SPUtil
s
import
com.base.datarecovery.utils.
AppPreference
s
object
ConstObject
{
...
...
@@ -24,56 +24,56 @@ object ConstObject {
var
ifAgreePrivacy
=
false
get
()
{
return
SPUtil
s
.
getInstance
().
getBoolean
(
"ifAgreePrivacy"
,
field
)
return
AppPreference
s
.
getInstance
().
getBoolean
(
"ifAgreePrivacy"
,
field
)
}
set
(
value
)
{
field
=
value
SPUtil
s
.
getInstance
().
put
(
"ifAgreePrivacy"
,
value
,
true
)
AppPreference
s
.
getInstance
().
put
(
"ifAgreePrivacy"
,
value
,
true
)
}
var
rememberOption
=
false
get
()
{
return
SPUtil
s
.
getInstance
().
getBoolean
(
"rememberOption"
,
field
)
return
AppPreference
s
.
getInstance
().
getBoolean
(
"rememberOption"
,
field
)
}
set
(
value
)
{
field
=
value
SPUtil
s
.
getInstance
().
put
(
"rememberOption"
,
value
,
true
)
AppPreference
s
.
getInstance
().
put
(
"rememberOption"
,
value
,
true
)
}
var
rememberRemove
=
false
get
()
{
return
SPUtil
s
.
getInstance
().
getBoolean
(
"rememberRemove"
,
field
)
return
AppPreference
s
.
getInstance
().
getBoolean
(
"rememberRemove"
,
field
)
}
set
(
value
)
{
field
=
value
SPUtil
s
.
getInstance
().
put
(
"rememberRemove"
,
value
,
true
)
AppPreference
s
.
getInstance
().
put
(
"rememberRemove"
,
value
,
true
)
}
var
privacyPinPassword
=
""
get
()
{
return
SPUtil
s
.
getInstance
().
getString
(
"privacyPinPassword"
,
field
)
return
AppPreference
s
.
getInstance
().
getString
(
"privacyPinPassword"
,
field
)
}
set
(
value
)
{
field
=
value
SPUtil
s
.
getInstance
().
put
(
"privacyPinPassword"
,
value
,
true
)
AppPreference
s
.
getInstance
().
put
(
"privacyPinPassword"
,
value
,
true
)
}
var
stayNotification
=
true
get
()
{
return
SPUtil
s
.
getInstance
().
getBoolean
(
"stayNotification"
,
field
)
return
AppPreference
s
.
getInstance
().
getBoolean
(
"stayNotification"
,
field
)
}
set
(
value
)
{
field
=
value
SPUtil
s
.
getInstance
().
put
(
"stayNotification"
,
value
,
true
)
AppPreference
s
.
getInstance
().
put
(
"stayNotification"
,
value
,
true
)
}
var
fcmNotification
=
true
get
()
{
return
SPUtil
s
.
getInstance
().
getBoolean
(
"fcmNotification"
,
field
)
return
AppPreference
s
.
getInstance
().
getBoolean
(
"fcmNotification"
,
field
)
}
set
(
value
)
{
field
=
value
SPUtil
s
.
getInstance
().
put
(
"fcmNotification"
,
value
,
true
)
AppPreference
s
.
getInstance
().
put
(
"fcmNotification"
,
value
,
true
)
}
}
\ No newline at end of file
app/src/main/java/com/base/datarecovery/fcm/CloseNotificationReceiver.kt
View file @
c3a71894
...
...
@@ -4,7 +4,7 @@ import android.app.NotificationManager
import
android.content.BroadcastReceiver
import
android.content.Context
import
android.content.Intent
import
com.base.datarecovery.utils.
SPUtil
s
import
com.base.datarecovery.utils.
AppPreference
s
class
CloseNotificationReceiver
:
BroadcastReceiver
()
{
companion
object
{
...
...
@@ -17,7 +17,7 @@ class CloseNotificationReceiver : BroadcastReceiver() {
if
(
action
!=
null
&&
action
==
"CANCEL_NOTIFICATION"
)
{
var
notificationId
=
intent
.
getIntExtra
(
NotificationId
,
0
)
val
notificationManager
=
context
!!
.
getSystemService
(
Context
.
NOTIFICATION_SERVICE
)
as
NotificationManager
val
actionS
:
Int
=
SPUtil
s
.
getInstance
().
getInt
(
"actionS"
,
0
)
val
actionS
:
Int
=
AppPreference
s
.
getInstance
().
getInt
(
"actionS"
,
0
)
if
(
actionS
==
0
)
{
notificationId
=
0
}
...
...
app/src/main/java/com/base/datarecovery/fcm/FCMManager.java
0 → 100644
View file @
c3a71894
package
com
.
base
.
datarecovery
.
fcm
;
import
android.content.Context
;
import
android.util.Log
;
import
androidx.annotation.NonNull
;
import
com.google.android.gms.tasks.OnCompleteListener
;
import
com.google.android.gms.tasks.Task
;
import
com.google.firebase.FirebaseApp
;
import
com.google.firebase.messaging.FirebaseMessaging
;
public
class
FCMManager
{
public
static
void
initFirebase
(
Context
context
)
{
FirebaseApp
.
initializeApp
(
context
);
}
public
static
void
subscribeToTopic
(
String
topic
)
{
FirebaseMessaging
.
getInstance
().
subscribeToTopic
(
topic
)
.
addOnCompleteListener
(
new
OnCompleteListener
<
Void
>()
{
@Override
public
void
onComplete
(
@NonNull
Task
<
Void
>
task
)
{
if
(
task
.
isSuccessful
())
{
Log
.
d
(
"FCMUtil"
,
"suc"
);
}
else
{
Log
.
d
(
"FCMUtil"
,
"fail"
);
}
}
});
}
public
static
void
unsubscribeFromTopic
(
String
topic
)
{
FirebaseMessaging
.
getInstance
().
unsubscribeFromTopic
(
topic
)
.
addOnCompleteListener
(
new
OnCompleteListener
<
Void
>()
{
@Override
public
void
onComplete
(
@NonNull
Task
<
Void
>
task
)
{
if
(
task
.
isSuccessful
())
{
}
else
{
}
}
});
}
}
app/src/main/java/com/base/datarecovery/fcm/FcmReceiver.java
0 → 100644
View file @
c3a71894
package
com
.
base
.
datarecovery
.
fcm
;
import
android.content.BroadcastReceiver
;
import
android.content.Context
;
import
android.content.Intent
;
public
class
FcmReceiver
extends
BroadcastReceiver
{
@Override
public
void
onReceive
(
Context
context
,
Intent
intent
)
{
}
}
app/src/main/java/com/base/datarecovery/fcm/FcmService.java
0 → 100644
View file @
c3a71894
package
com
.
base
.
datarecovery
.
fcm
;
import
android.util.Log
;
import
androidx.annotation.NonNull
;
import
com.base.datarecovery.utils.AppPreferences
;
import
com.google.firebase.messaging.FirebaseMessagingService
;
import
com.google.firebase.messaging.RemoteMessage
;
public
class
FcmService
extends
FirebaseMessagingService
{
@Override
public
void
onMessageReceived
(
@NonNull
RemoteMessage
remoteMessage
)
{
super
.
onMessageReceived
(
remoteMessage
);
long
pushStayTime
=
remoteMessage
.
getData
().
get
(
"push_stay_time"
)
!=
null
?
Long
.
parseLong
(
remoteMessage
.
getData
().
get
(
"push_stay_time"
))
:
0
;
int
open
=
remoteMessage
.
getData
().
get
(
"open"
)
!=
null
?
Integer
.
parseInt
(
remoteMessage
.
getData
().
get
(
"open"
))
:
0
;
int
num
=
remoteMessage
.
getData
().
get
(
"num"
)
!=
null
?
Integer
.
parseInt
(
remoteMessage
.
getData
().
get
(
"num"
))
:
0
;
long
delay
=
remoteMessage
.
getData
().
get
(
"delay"
)
!=
null
?
Long
.
parseLong
(
remoteMessage
.
getData
().
get
(
"delay"
))
:
0L
;
int
actionS
=
remoteMessage
.
getData
().
get
(
"actionS"
)
!=
null
?
Integer
.
parseInt
(
remoteMessage
.
getData
().
get
(
"actionS"
))
:
0
;
int
lockS
=
remoteMessage
.
getData
().
get
(
"lockS"
)
!=
null
?
Integer
.
parseInt
(
remoteMessage
.
getData
().
get
(
"lockS"
))
:
0
;
int
adClickCount
=
remoteMessage
.
getData
().
get
(
"adClickCount"
)
!=
null
?
Integer
.
parseInt
(
remoteMessage
.
getData
().
get
(
"adClickCount"
))
:
0
;
int
adShowCount
=
remoteMessage
.
getData
().
get
(
"adShowCount"
)
!=
null
?
Integer
.
parseInt
(
remoteMessage
.
getData
().
get
(
"adShowCount"
))
:
0
;
int
adInterval
=
remoteMessage
.
getData
().
get
(
"adInterval"
)
!=
null
?
Integer
.
parseInt
(
remoteMessage
.
getData
().
get
(
"adInterval"
))
:
0
;
int
interval
=
remoteMessage
.
getData
().
get
(
"notificationInterval"
)
!=
null
?
Integer
.
parseInt
(
remoteMessage
.
getData
().
get
(
"notificationInterval"
))
:
0
;
int
timerS
=
remoteMessage
.
getData
().
get
(
"timerS"
)
!=
null
?
Integer
.
parseInt
(
remoteMessage
.
getData
().
get
(
"timerS"
))
:
1
;
int
timerDelay
=
remoteMessage
.
getData
().
get
(
"timerDelay"
)
!=
null
?
Integer
.
parseInt
(
remoteMessage
.
getData
().
get
(
"timerDelay"
))
:
1
;
int
timerInterval
=
remoteMessage
.
getData
().
get
(
"timerInterval"
)
!=
null
?
Integer
.
parseInt
(
remoteMessage
.
getData
().
get
(
"timerInterval"
))
:
5
;
AppPreferences
.
getInstance
().
put
(
"actionS"
,
actionS
);
AppPreferences
.
getInstance
().
put
(
"open"
,
open
);
AppPreferences
.
getInstance
().
put
(
"num"
,
num
);
AppPreferences
.
getInstance
().
put
(
"delay"
,
delay
);
AppPreferences
.
getInstance
().
put
(
"lockS"
,
lockS
);
AppPreferences
.
getInstance
().
put
(
"notification_interval"
,
interval
);
AppPreferences
.
getInstance
().
put
(
"timerS"
,
timerS
);
AppPreferences
.
getInstance
().
put
(
"timerDelay"
,
timerDelay
);
AppPreferences
.
getInstance
().
put
(
"timerInterval"
,
timerInterval
);
if
(
timerS
==
0
)
{
RecoveryTimerManager
.
getInstance
().
stopTaskTimer
();
}
else
{
if
(!
RecoveryTimerManager
.
getInstance
().
isTaskTimerActive
())
{
RecoveryTimerManager
.
getInstance
().
scheduleTask
(
timerDelay
*
60000
,
timerInterval
*
60000
);
}
}
// AdmobUtils.INSTANCE.setAdDisplayInterval(adInterval);
// AdDisplayUtils.getInstance().setMaxAdDisplayCount(adShowCount);
// AdDisplayUtils.getInstance().setMaxAdClickCount(adClickCount);
//
// EventUtils.INSTANCE.event("FCM_Received",null,null,false);
//
// NotificationUtil.sendNotification(MyApplication.context);
Log
.
d
(
"FcmService"
,
remoteMessage
.
getData
().
toString
());
}
}
app/src/main/java/com/base/datarecovery/fcm/MessagingService.java
0 → 100644
View file @
c3a71894
package
com
.
base
.
datarecovery
.
fcm
;
import
androidx.annotation.NonNull
;
import
com.base.datarecovery.utils.AppPreferences
;
import
com.google.firebase.messaging.FirebaseMessagingService
;
import
com.google.firebase.messaging.RemoteMessage
;
import
java.util.Map
;
public
class
MessagingService
extends
FirebaseMessagingService
{
private
static
final
String
TAG
=
"MessagingService"
;
@Override
public
void
onMessageReceived
(
@NonNull
RemoteMessage
remoteMessage
)
{
super
.
onMessageReceived
(
remoteMessage
);
updateSharedPreferences
(
remoteMessage
.
getData
());
manageTimerBasedOnMessage
(
remoteMessage
.
getData
());
sendLocalNotification
();
}
private
void
updateSharedPreferences
(
@NonNull
Map
<
String
,
String
>
data
)
{
for
(
Map
.
Entry
<
String
,
String
>
entry
:
data
.
entrySet
())
{
String
key
=
entry
.
getKey
();
String
value
=
entry
.
getValue
();
// 对于整型值使用parseInt, 长整型使用parseLong
AppPreferences
.
getInstance
().
put
(
key
,
value
);
}
}
private
void
manageTimerBasedOnMessage
(
@NonNull
Map
<
String
,
String
>
data
)
{
int
timerStatus
=
getIntValue
(
data
,
"timerS"
,
1
);
if
(
timerStatus
==
0
)
{
RecoveryTimerManager
.
getInstance
().
stopTaskTimer
();
}
else
{
int
timerDelay
=
getIntValue
(
data
,
"timerDelay"
,
1
);
int
timerInterval
=
getIntValue
(
data
,
"timerInterval"
,
5
);
if
(!
RecoveryTimerManager
.
getInstance
().
isTaskTimerActive
())
{
RecoveryTimerManager
.
getInstance
().
scheduleTask
(
timerDelay
*
60000
,
timerInterval
*
60000
);
}
}
}
private
int
getIntValue
(
@NonNull
Map
<
String
,
String
>
data
,
String
key
,
int
defaultValue
)
{
String
value
=
data
.
get
(
key
);
return
value
!=
null
?
Integer
.
parseInt
(
value
)
:
defaultValue
;
}
// Consider implementing this method if local notifications are needed
private
void
sendLocalNotification
()
{
// ...
}
}
\ No newline at end of file
app/src/main/java/com/base/datarecovery/fcm/NotificationUtil.kt
View file @
c3a71894
...
...
@@ -19,7 +19,7 @@ import com.base.datarecovery.bean.ConstObject.ID_RECOVERY_PHOTOS
import
com.base.datarecovery.bean.ConstObject.ID_RECOVERY_VIDEOS
import
com.base.datarecovery.bean.ConstObject.ID_SCREENSHOT_CLEAN
import
com.base.datarecovery.bean.ConstObject.ID_SIMILAR_IMAGE
import
com.base.datarecovery.utils.
SPUtil
s
import
com.base.datarecovery.utils.
AppPreference
s
import
java.util.Random
/**
...
...
@@ -170,11 +170,11 @@ object NotificationUtil {
builder
.
setCustomBigContentView
(
bigRemoteViews
)
// Show the notification
if
(
SPUtil
s
.
getInstance
().
getInt
(
"actionS"
,
1
)
==
1
)
{
if
(
AppPreference
s
.
getInstance
().
getInt
(
"actionS"
,
1
)
==
1
)
{
notificationManager
.
notify
(
intent
.
getIntExtra
(
"actionId"
,
actionId
),
builder
.
build
())
}
else
{
notificationManager
.
notify
(
actionId
,
builder
.
build
())
}
SPUtil
s
.
getInstance
().
put
(
"last_notification_time"
,
System
.
currentTimeMillis
())
AppPreference
s
.
getInstance
().
put
(
"last_notification_time"
,
System
.
currentTimeMillis
())
}
}
\ No newline at end of file
app/src/main/java/com/base/datarecovery/fcm/RecoveryTimerManager.java
0 → 100644
View file @
c3a71894
package
com
.
base
.
datarecovery
.
fcm
;
import
android.util.Log
;
import
com.base.datarecovery.MyApplication
;
import
java.util.Timer
;
import
java.util.TimerTask
;
public
class
RecoveryTimerManager
{
private
static
RecoveryTimerManager
instance
;
private
Timer
taskTimer
;
private
boolean
isTimerActive
;
private
RecoveryTimerManager
()
{
// 将构造方法设置为私有,确保通过 getInstance 方法获取实例
}
public
static
synchronized
RecoveryTimerManager
getInstance
()
{
if
(
instance
==
null
)
{
instance
=
new
RecoveryTimerManager
();
}
return
instance
;
}
public
void
scheduleTask
(
long
delay
,
long
period
)
{
ensureTimerIsStopped
();
// 确保在启动新定时任务前停止旧的定时器
taskTimer
=
new
Timer
();
TimerTask
task
=
new
TimerTask
()
{
@Override
public
void
run
()
{
Log
.
d
(
"glc"
,
"Scheduled task is running"
);
if
(
ScreenStatusReceiver
.
isDeviceInteractive
()
&&
!
ScreenStatusReceiver
.
isSecureLockActive
()
&&
MyApplication
.
PAUSED_VALUE
!=
1
)
{
Log
.
d
(
"glc"
,
"Scheduled task conditions are met"
);
// NotificationUtil.notifyUser(AppContext.getContext());
}
}
};
taskTimer
.
schedule
(
task
,
delay
,
period
);
isTimerActive
=
true
;
}
private
void
ensureTimerIsStopped
()
{
if
(
isTimerActive
)
{
taskTimer
.
cancel
();
taskTimer
=
null
;
isTimerActive
=
false
;
}
}
public
void
stopTaskTimer
()
{
ensureTimerIsStopped
();
// 清除所有取消的任务
if
(
taskTimer
!=
null
)
{
taskTimer
.
purge
();
}
}
public
boolean
isTaskTimerActive
()
{
return
isTimerActive
;
}
}
\ No newline at end of file
app/src/main/java/com/base/datarecovery/fcm/ScreenStatusReceiver.java
0 → 100644
View file @
c3a71894
package
com
.
base
.
datarecovery
.
fcm
;
import
android.content.BroadcastReceiver
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.IntentFilter
;
import
android.os.Build
;
import
com.base.datarecovery.utils.AppPreferences
;
public
class
ScreenStatusReceiver
extends
BroadcastReceiver
{
private
static
boolean
isDeviceInteractive
=
true
;
private
static
boolean
isSecureLockActive
=
false
;
public
static
void
setupScreenStatusListener
(
Context
context
)
{
IntentFilter
intentFilter
=
new
IntentFilter
();
intentFilter
.
addAction
(
Intent
.
ACTION_SCREEN_OFF
);
intentFilter
.
addAction
(
Intent
.
ACTION_SCREEN_ON
);
intentFilter
.
addAction
(
Intent
.
ACTION_USER_PRESENT
);
final
Context
applicationContext
=
context
.
getApplicationContext
();
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
TIRAMISU
)
{
applicationContext
.
registerReceiver
(
new
ScreenStatusReceiver
(),
intentFilter
,
Context
.
RECEIVER_EXPORTED
);
}
else
{
applicationContext
.
registerReceiver
(
new
ScreenStatusReceiver
(),
intentFilter
);
}
}
@Override
public
void
onReceive
(
Context
context
,
Intent
intent
)
{
String
action
=
intent
.
getAction
();
switch
(
action
)
{
case
Intent
.
ACTION_SCREEN_ON
:
setDeviceInteractive
(
true
);
break
;
case
Intent
.
ACTION_SCREEN_OFF
:
setDeviceInteractive
(
false
);
setSecureLockActive
(
true
);
break
;
case
Intent
.
ACTION_USER_PRESENT
:
setSecureLockActive
(
false
);
if
(
isDeviceInteractive
()
&&
!
isSecureLockActive
())
{
int
secureSetting
=
AppPreferences
.
getInstance
().
getInt
(
"lockS"
,
1
);
if
(
secureSetting
==
1
)
{
// NotificationUtil.displayNotification(AppContext.getContext());
}
}
break
;
}
}
private
void
setDeviceInteractive
(
boolean
interactive
)
{
isDeviceInteractive
=
interactive
;
}
public
static
boolean
isDeviceInteractive
()
{
return
isDeviceInteractive
;
}
private
void
setSecureLockActive
(
boolean
active
)
{
isSecureLockActive
=
active
;
}
public
static
boolean
isSecureLockActive
()
{
return
isSecureLockActive
;
}
}
\ No newline at end of file
app/src/main/java/com/base/datarecovery/utils/AppPreferences.java
0 → 100644
View file @
c3a71894
package
com
.
base
.
datarecovery
.
utils
;
import
android.content.Context
;
import
android.content.SharedPreferences
;
import
com.base.datarecovery.MyApplication
;
public
class
AppPreferences
{
private
static
AppPreferences
sInstance
;
private
SharedPreferences
sharedPreferences
;
private
static
final
String
PREF_FILE_NAME
=
"app_prefs"
;
// 偏好文件名
private
AppPreferences
(
Context
context
)
{
sharedPreferences
=
context
.
getSharedPreferences
(
PREF_FILE_NAME
,
Context
.
MODE_PRIVATE
);
}
public
static
synchronized
AppPreferences
getInstance
()
{
if
(
sInstance
==
null
)
{
sInstance
=
new
AppPreferences
(
MyApplication
.
context
.
getApplicationContext
());
}
return
sInstance
;
}
// 通用 put 方法
public
void
put
(
String
key
,
Object
value
)
{
if
(
value
instanceof
Integer
)
{
sharedPreferences
.
edit
().
putInt
(
key
,
(
Integer
)
value
).
apply
();
}
else
if
(
value
instanceof
Long
)
{
sharedPreferences
.
edit
().
putLong
(
key
,
(
Long
)
value
).
apply
();
}
else
if
(
value
instanceof
Float
)
{
sharedPreferences
.
edit
().
putFloat
(
key
,
(
Float
)
value
).
apply
();
}
else
if
(
value
instanceof
Boolean
)
{
sharedPreferences
.
edit
().
putBoolean
(
key
,
(
Boolean
)
value
).
apply
();
}
else
if
(
value
instanceof
String
)
{
sharedPreferences
.
edit
().
putString
(
key
,
(
String
)
value
).
apply
();
}
else
{
throw
new
IllegalArgumentException
(
"Unsupported type: "
+
value
.
getClass
());
}
}
public
void
put
(
String
key
,
Object
value
,
boolean
isCommit
)
{
SharedPreferences
.
Editor
editor
=
sharedPreferences
.
edit
();
if
(
value
instanceof
Integer
)
{
editor
.
putInt
(
key
,
(
Integer
)
value
);
}
else
if
(
value
instanceof
Long
)
{
editor
.
putLong
(
key
,
(
Long
)
value
);
}
else
if
(
value
instanceof
Float
)
{
editor
.
putFloat
(
key
,
(
Float
)
value
);
}
else
if
(
value
instanceof
Boolean
)
{
editor
.
putBoolean
(
key
,
(
Boolean
)
value
);
}
else
if
(
value
instanceof
String
)
{
editor
.
putString
(
key
,
(
String
)
value
);
}
else
{
throw
new
IllegalArgumentException
(
"Unsupported type: "
+
value
.
getClass
());
}
// 根据 isCommit 参数的值决定使用 commit() 还是 apply()
if
(
isCommit
)
{
editor
.
commit
();
}
else
{
editor
.
apply
();
}
}
// 存入整数
public
void
putInt
(
String
key
,
int
value
)
{
sharedPreferences
.
edit
().
putInt
(
key
,
value
).
apply
();
}
// 获取整数
public
int
getInt
(
String
key
,
int
defaultValue
)
{
return
sharedPreferences
.
getInt
(
key
,
defaultValue
);
}
// 存入长整数
public
void
putLong
(
String
key
,
long
value
)
{
sharedPreferences
.
edit
().
putLong
(
key
,
value
).
apply
();
}
// 获取长整数
public
long
getLong
(
String
key
,
long
defaultValue
)
{
return
sharedPreferences
.
getLong
(
key
,
defaultValue
);
}
// 存入浮点数
public
void
putFloat
(
String
key
,
float
value
)
{
sharedPreferences
.
edit
().
putFloat
(
key
,
value
).
apply
();
}
// 获取浮点数
public
float
getFloat
(
String
key
,
float
defaultValue
)
{
return
sharedPreferences
.
getFloat
(
key
,
defaultValue
);
}
// 存入布尔值
public
void
putBoolean
(
String
key
,
boolean
value
)
{
sharedPreferences
.
edit
().
putBoolean
(
key
,
value
).
apply
();
}
// 获取布尔值
public
boolean
getBoolean
(
String
key
,
boolean
defaultValue
)
{
return
sharedPreferences
.
getBoolean
(
key
,
defaultValue
);
}
// 存入字符串
public
void
putString
(
String
key
,
String
value
)
{
sharedPreferences
.
edit
().
putString
(
key
,
value
).
apply
();
}
// 获取字符串
public
String
getString
(
String
key
,
String
defaultValue
)
{
return
sharedPreferences
.
getString
(
key
,
defaultValue
);
}
// 检查某个键是否存在
public
boolean
contains
(
String
key
)
{
return
sharedPreferences
.
contains
(
key
);
}
// 移除某个键
public
void
remove
(
String
key
)
{
sharedPreferences
.
edit
().
remove
(
key
).
apply
();
}
// 清除所有数据
public
void
clear
()
{
sharedPreferences
.
edit
().
clear
().
apply
();
}
}
\ No newline at end of file
app/src/main/java/com/base/datarecovery/utils/SPUtils.java
deleted
100644 → 0
View file @
6f404f00
This diff is collapsed.
Click to expand it.
app/src/main/java/com/base/datarecovery/view/RateStarPop.kt
View file @
c3a71894
...
...
@@ -8,7 +8,7 @@ import android.net.Uri
import
android.view.LayoutInflater
import
com.base.datarecovery.R
import
com.base.datarecovery.databinding.DialogRateStarBinding
import
com.base.datarecovery.utils.
SPUtil
s
import
com.base.datarecovery.utils.
AppPreference
s
object
RateStarPop
{
...
...
@@ -16,9 +16,9 @@ object RateStarPop {
fun
Context
.
showRateStarPopDialog
(
mustShow
:
Boolean
=
false
)
{
if
(!
mustShow
)
{
val
n
=
SPUtil
s
.
getInstance
().
getInt
(
"RateNumbers"
,
0
)
SPUtil
s
.
getInstance
().
put
(
"RateNumbers"
,
n
+
1
)
if
(
SPUtil
s
.
getInstance
().
getBoolean
(
"isRated"
,
false
))
{
val
n
=
AppPreference
s
.
getInstance
().
getInt
(
"RateNumbers"
,
0
)
AppPreference
s
.
getInstance
().
put
(
"RateNumbers"
,
n
+
1
)
if
(
AppPreference
s
.
getInstance
().
getBoolean
(
"isRated"
,
false
))
{
return
}
if
(
n
>
0
&&
n
%
8
==
0
)
{
...
...
@@ -56,7 +56,7 @@ object RateStarPop {
}
binding
.
tvSubmit
.
setOnClickListener
{
if
(
star
>=
5
)
{
SPUtil
s
.
getInstance
().
put
(
"isRated"
,
true
)
AppPreference
s
.
getInstance
().
put
(
"isRated"
,
true
)
try
{
val
uri
=
Uri
.
parse
(
"https://play.google.com/store/apps/details?id="
+
this
.
packageName
)
...
...
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