Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
F
File Recovery RecycleBin
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
File Recovery RecycleBin
Commits
7cd6ad09
Commit
7cd6ad09
authored
Sep 09, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
d2596d6f
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
52 additions
and
63 deletions
+52
-63
RecycleBinDetailActivity.kt
...ecyclebin/activity/recyclebin/RecycleBinDetailActivity.kt
+9
-16
RecycleBinAdapter.kt
.../base/filerecoveryrecyclebin/adapter/RecycleBinAdapter.kt
+1
-6
RecycleBinBean.kt
...va/com/base/filerecoveryrecyclebin/bean/RecycleBinBean.kt
+5
-3
BackUpUtils.kt
...va/com/base/filerecoveryrecyclebin/service/BackUpUtils.kt
+32
-24
FileObserverExample.java
...e/filerecoveryrecyclebin/service/FileObserverExample.java
+4
-13
activity_recycle_bin_detail.xml
app/src/main/res/layout/activity_recycle_bin_detail.xml
+1
-1
No files found.
app/src/main/java/com/base/filerecoveryrecyclebin/activity/recyclebin/RecycleBinDetailActivity.kt
View file @
7cd6ad09
...
...
@@ -4,19 +4,14 @@ import android.annotation.SuppressLint
import
android.content.Intent
import
android.graphics.Color
import
android.os.Build
import
android.util.Log
import
android.view.View
import
androidx.activity.addCallback
import
androidx.annotation.RequiresApi
import
androidx.core.view.isVisible
import
androidx.core.view.updatePadding
import
com.base.filerecoveryrecyclebin.R
import
com.base.filerecoveryrecyclebin.activity.ResultActivity
import
com.base.filerecoveryrecyclebin.activity.recovery.FileRecoveredActivity
import
com.base.filerecoveryrecyclebin.activity.recyclebin.RecycleBinFileEx.findRecycleBinFile
import
com.base.filerecoveryrecyclebin.activity.recyclebin.RecycleBinFileEx.findRecycleBinJsonFile
import
com.base.filerecoveryrecyclebin.bean.ConstObject
import
com.base.filerecoveryrecyclebin.bean.ConstObject.RECYCLE_BIN
import
com.base.filerecoveryrecyclebin.bean.RecycleBinBean
import
com.base.filerecoveryrecyclebin.bean.RecycleBinBean.Companion.mAudioStr
import
com.base.filerecoveryrecyclebin.bean.RecycleBinBean.Companion.mDocumentStr
...
...
@@ -27,6 +22,7 @@ import com.base.filerecoveryrecyclebin.help.BaseActivity
import
com.base.filerecoveryrecyclebin.help.KotlinExt.toFormatSize
import
com.base.filerecoveryrecyclebin.help.KotlinExt.toFormatTime
import
com.base.filerecoveryrecyclebin.help.VideoPlayerUtil
import
com.base.filerecoveryrecyclebin.service.BackUpUtils
import
com.base.filerecoveryrecyclebin.service.BackUpUtils.recoveryFile
import
com.base.filerecoveryrecyclebin.utils.BarUtils
import
com.base.filerecoveryrecyclebin.utils.LogEx
...
...
@@ -85,7 +81,7 @@ class RecycleBinDetailActivity : BaseActivity<ActivityRecycleBinDetailBinding>()
}
Glide
.
with
(
this
).
load
(
bean
.
backupPath
).
centerCrop
().
into
(
binding
.
iv
)
binding
.
tv
Name
.
text
=
bean
.
path
binding
.
tv
Path
.
text
=
bean
.
path
binding
.
tvSize
.
text
=
bean
.
size
.
toFormatSize
()
binding
.
tvTime
.
text
=
"Delete time:${bean.deleteTime.toFormatTime()}"
}
...
...
@@ -106,7 +102,7 @@ class RecycleBinDetailActivity : BaseActivity<ActivityRecycleBinDetailBinding>()
runCatching
{
binFile
.
copyTo
(
file
,
true
)
binFile
.
delete
()
recoveryFile
(
bean
.
name
)
recoveryFile
(
bean
.
name
Path
)
}
}
startActivity
(
Intent
(
this
,
FileRecoveredActivity
::
class
.
java
).
apply
{
...
...
@@ -132,20 +128,17 @@ class RecycleBinDetailActivity : BaseActivity<ActivityRecycleBinDetailBinding>()
binding
.
ivBofang
.
setOnClickListener
{
recycleBinBean
?.
let
{
bean
->
val
file
=
File
(
bean
.
path
)
val
binFile
=
findRecycleBinFile
(
file
.
name
)
VideoPlayerUtil
.
playVideo
(
this
,
binFile
?.
absolutePath
)
VideoPlayerUtil
.
playVideo
(
this
,
bean
.
backupPath
)
}
}
binding
.
flDelete
.
setOnClickListener
{
recycleBinBean
?.
let
{
bean
->
val
file
=
File
(
bean
.
path
)
val
binFile
=
findRecycleBinFile
(
file
.
name
)
val
binJsonFile
=
findRecycleBinJsonFile
(
file
.
name
)
binFile
?.
delete
()
binJsonFile
?.
delete
()
BackUpUtils
.
deleteFileSp
(
bean
.
namePath
)
val
file
=
File
(
bean
.
backupPath
)
if
(
file
.
exists
())
{
file
.
delete
()
}
}
finish
()
}
...
...
app/src/main/java/com/base/filerecoveryrecyclebin/adapter/RecycleBinAdapter.kt
View file @
7cd6ad09
...
...
@@ -2,15 +2,11 @@ package com.base.filerecoveryrecyclebin.adapter
import
android.annotation.SuppressLint
import
android.graphics.drawable.Drawable
import
android.os.Build
import
android.view.View
import
android.view.ViewGroup
import
androidx.annotation.RequiresApi
import
androidx.core.content.ContextCompat
import
androidx.recyclerview.widget.RecyclerView
import
androidx.recyclerview.widget.RecyclerView.ViewHolder
import
com.base.filerecoveryrecyclebin.R
import
com.base.filerecoveryrecyclebin.activity.recyclebin.RecycleBinFileEx.findRecycleBinFile
import
com.base.filerecoveryrecyclebin.bean.RecycleBinBean
import
com.base.filerecoveryrecyclebin.bean.RecycleBinBean.Companion.mAudioStr
import
com.base.filerecoveryrecyclebin.bean.RecycleBinBean.Companion.mDocumentStr
...
...
@@ -26,7 +22,6 @@ import com.bumptech.glide.load.DataSource
import
com.bumptech.glide.load.engine.GlideException
import
com.bumptech.glide.request.RequestListener
import
com.bumptech.glide.request.target.Target
import
java.io.File
class
RecycleBinAdapter
(
val
click
:
(
bean
:
RecycleBinBean
)
->
Unit
)
:
RecyclerView
.
Adapter
<
RecycleBinAdapter
.
RBAV
>()
{
...
...
@@ -86,7 +81,7 @@ class RecycleBinAdapter(val click: (bean: RecycleBinBean) -> Unit) : RecyclerVie
binding
.
iv
.
setImageResource
(
R
.
mipmap
.
h_documents
)
}
binding
.
tvName
.
text
=
bean
.
name
binding
.
tvName
.
text
=
bean
.
name
Path
binding
.
tvTime
.
text
=
"delete time:"
+
bean
.
deleteTime
.
toFormatTime
()
binding
.
tvSize
.
text
=
bean
.
size
.
toFormatSize
()
binding
.
root
.
setOnClickListener
{
...
...
app/src/main/java/com/base/filerecoveryrecyclebin/bean/RecycleBinBean.kt
View file @
7cd6ad09
...
...
@@ -2,14 +2,16 @@ package com.base.filerecoveryrecyclebin.bean
data class
RecycleBinBean
(
val
name
:
String
=
""
,
val
path
:
String
=
""
,
val
backupPath
:
String
=
""
,
val
name
Path
:
String
=
""
,
//文件名称,sp的key,容易重复,所已会覆盖之前的文件
val
path
:
String
=
""
,
//原文件路径
val
backupPath
:
String
=
""
,
//备份文件路径
var
deleteTime
:
Long
=
0
,
val
size
:
Long
=
0
,
val
mimeType
:
String
=
""
,
var
deleted
:
Boolean
=
false
)
{
companion
object
{
val
mImageStr
:
Set
<
String
>
=
HashSet
(
mutableListOf
(
...
...
app/src/main/java/com/base/filerecoveryrecyclebin/service/BackUpUtils.kt
View file @
7cd6ad09
...
...
@@ -25,12 +25,13 @@ object BackUpUtils {
private
const
val
KEY
=
"backup_key"
fun
backupFile
(
src
:
File
,
path
:
String
)
{
fun
backupFile
(
src
:
File
,
namePath
:
String
)
{
if
(
namePath
.
isEmpty
())
return
if
(!
hasStorageReadWritePermission
())
{
return
}
try
{
val
recycleBinFile
=
File
(
getRecycleBinDir
(),
".$
p
ath"
)
val
recycleBinFile
=
File
(
getRecycleBinDir
(),
".$
nameP
ath"
)
LogEx
.
logDebug
(
TAG
,
"oo=$src ${src.length()}"
)
if
(
src
.
length
()
==
0L
)
{
return
...
...
@@ -41,19 +42,35 @@ object BackUpUtils {
return
}
val
binBean
=
RecycleBinBean
(
p
ath
,
src
.
p
ath
,
nameP
ath
,
src
.
absoluteP
ath
,
recycleBinFile
.
absolutePath
,
0
,
src
.
length
(),
getFileExtension
(
src
),
false
)
saveData
(
binBean
,
p
ath
)
saveData
(
binBean
,
nameP
ath
)
}
catch
(
e
:
Exception
)
{
}
}
fun
deleteFile
(
path
:
String
)
{
if
(
path
.
isEmpty
())
return
val
isExists
=
queryFileExists
(
path
)
if
(
isExists
)
{
val
hashMap
=
queryBackUpSp
()
val
data
=
hashMap
[
path
]
if
(
data
!=
null
)
{
data
.
deleted
=
true
data
.
deleteTime
=
System
.
currentTimeMillis
()
hashMap
[
path
]
=
data
saveBackUpSp
(
hashMap
)
}
}
}
private
fun
getFileExtension
(
file
:
File
):
String
{
...
...
@@ -65,10 +82,10 @@ object BackUpUtils {
}
}
fun
saveData
(
binBean
:
RecycleBinBean
,
path
:
String
)
{
fun
saveData
(
binBean
:
RecycleBinBean
,
namePath
:
String
)
{
if
(
namePath
.
isEmpty
())
return
val
hashMap
=
queryBackUpSp
()
hashMap
.
put
(
path
,
binBean
)
hashMap
.
put
(
namePath
,
binBean
)
saveBackUpSp
(
hashMap
)
}
...
...
@@ -103,25 +120,16 @@ object BackUpUtils {
}
}
fun
queryFileExists
(
path
:
String
):
Boolean
{
val
hashMap
=
queryBackUpSp
()
return
hashMap
.
contains
(
path
)
}
fun
deleteFile
(
path
:
String
)
{
val
isExists
=
queryFileExists
(
path
)
if
(
isExists
)
{
fun
queryFileExists
(
namePath
:
String
):
Boolean
{
val
hashMap
=
queryBackUpSp
()
val
data
=
hashMap
[
path
]
if
(
data
!=
null
)
{
data
?.
deleted
=
true
data
?.
deleteTime
=
System
.
currentTimeMillis
()
hashMap
[
path
]
=
data
saveBackUpSp
(
hashMap
)
return
hashMap
.
contains
(
namePath
)
}
}
fun
deleteFileSp
(
namePath
:
String
)
{
val
map
=
queryBackUpSp
()
map
.
remove
(
namePath
)
saveBackUpSp
(
map
)
}
...
...
app/src/main/java/com/base/filerecoveryrecyclebin/service/FileObserverExample.java
View file @
7cd6ad09
package
com
.
base
.
filerecoveryrecyclebin
.
service
;
import
static
android
.
os
.
FileObserver
.
ALL_EVENTS
;
import
static
android
.
os
.
FileObserver
.
ATTRIB
;
import
static
android
.
os
.
FileObserver
.
MOVED_FROM
;
import
android.os.Build
;
import
android.os.Environment
;
import
android.os.FileObserver
;
import
android.os.Handler
;
import
android.os.HandlerThread
;
import
android.text.TextUtils
;
import
android.util.Log
;
import
com.base.filerecoveryrecyclebin.MyApplication
;
import
com.base.filerecoveryrecyclebin.activity.recyclebin.RecycleBinFileEx
;
import
com.base.filerecoveryrecyclebin.help.FileHelp
;
import
java.io.File
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
...
...
@@ -108,13 +99,13 @@ public class FileObserverExample {
}
}
private
void
handleFileCreation
(
String
p
ath
)
{
private
void
handleFileCreation
(
String
nameP
ath
)
{
// 确保线程安全,这里我们只是打印出来,实际使用中可能需要同步机制
for
(
File
dir
:
watchList
)
{
File
src
=
new
File
(
dir
,
p
ath
);
File
src
=
new
File
(
dir
,
nameP
ath
);
if
(
src
.
exists
())
{
Log
.
d
(
TAG
,
"新创建的文件 "
+
p
ath
+
" 属于目录: "
+
dir
.
getAbsolutePath
());
BackUpUtils
.
INSTANCE
.
backupFile
(
src
,
p
ath
);
Log
.
d
(
TAG
,
"新创建的文件 "
+
nameP
ath
+
" 属于目录: "
+
dir
.
getAbsolutePath
());
BackUpUtils
.
INSTANCE
.
backupFile
(
src
,
nameP
ath
);
break
;
}
}
...
...
app/src/main/res/layout/activity_recycle_bin_detail.xml
View file @
7cd6ad09
...
...
@@ -109,7 +109,7 @@
app:layout_constraintTop_toTopOf=
"parent"
>
<TextView
android:id=
"@+id/tv_
name
"
android:id=
"@+id/tv_
path
"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:textColor=
"@color/black"
...
...
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