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
98e2c70e
Commit
98e2c70e
authored
Sep 09, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
2ca447af
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
108 additions
and
63 deletions
+108
-63
MainActivity.kt
.../com/base/filerecoveryrecyclebin/activity/MainActivity.kt
+11
-2
RepeatActivity.kt
.../filerecoveryrecyclebin/activity/repeat/RepeatActivity.kt
+22
-17
ScreenShotActivity.kt
...overyrecyclebin/activity/screenshot/ScreenShotActivity.kt
+28
-13
LogEx.kt
.../main/java/com/base/filerecoveryrecyclebin/utils/LogEx.kt
+1
-1
SimilarHelper.kt
...va/com/base/filerecoveryrecyclebin/utils/SimilarHelper.kt
+46
-30
No files found.
app/src/main/java/com/base/filerecoveryrecyclebin/activity/MainActivity.kt
View file @
98e2c70e
...
@@ -14,6 +14,7 @@ import androidx.fragment.app.Fragment
...
@@ -14,6 +14,7 @@ import androidx.fragment.app.Fragment
import
androidx.lifecycle.lifecycleScope
import
androidx.lifecycle.lifecycleScope
import
androidx.viewpager2.adapter.FragmentStateAdapter
import
androidx.viewpager2.adapter.FragmentStateAdapter
import
androidx.viewpager2.widget.ViewPager2
import
androidx.viewpager2.widget.ViewPager2
import
com.base.filerecoveryrecyclebin.activity.repeat.RepeatActivity
import
com.base.filerecoveryrecyclebin.ads.admob.AdmobBannerUtils
import
com.base.filerecoveryrecyclebin.ads.admob.AdmobBannerUtils
import
com.base.filerecoveryrecyclebin.bean.MediaBean
import
com.base.filerecoveryrecyclebin.bean.MediaBean
import
com.base.filerecoveryrecyclebin.databinding.ActivityMainBinding
import
com.base.filerecoveryrecyclebin.databinding.ActivityMainBinding
...
@@ -33,6 +34,7 @@ import com.base.filerecoveryrecyclebin.view.PermissionDialog.showPermissionBotto
...
@@ -33,6 +34,7 @@ import com.base.filerecoveryrecyclebin.view.PermissionDialog.showPermissionBotto
import
com.base.filerecoveryrecyclebin.view.RateStarPop.showRateStarPopDialog
import
com.base.filerecoveryrecyclebin.view.RateStarPop.showRateStarPopDialog
import
com.facebook.appevents.AppEventsLogger
import
com.facebook.appevents.AppEventsLogger
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.Job
import
kotlinx.coroutines.delay
import
kotlinx.coroutines.delay
import
kotlinx.coroutines.flow.MutableSharedFlow
import
kotlinx.coroutines.flow.MutableSharedFlow
import
kotlinx.coroutines.launch
import
kotlinx.coroutines.launch
...
@@ -177,7 +179,9 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
...
@@ -177,7 +179,9 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
if
(
checkStorePermission
())
{
if
(
checkStorePermission
())
{
initStayServiceObserver
()
initStayServiceObserver
()
initPhotoSize
()
if
(
photoSizejob
==
null
)
{
photoSizejob
=
initPhotoSize
()
}
}
}
lifecycleScope
.
launch
(
Dispatchers
.
Main
)
{
lifecycleScope
.
launch
(
Dispatchers
.
Main
)
{
...
@@ -186,6 +190,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
...
@@ -186,6 +190,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
}
}
}
}
var
photoSizejob
:
Job
?
=
null
private
fun
initPhotoSize
()
=
lifecycleScope
.
launch
(
Dispatchers
.
IO
)
{
private
fun
initPhotoSize
()
=
lifecycleScope
.
launch
(
Dispatchers
.
IO
)
{
LogEx
.
logDebug
(
TAG
,
"initPhotoSize"
)
LogEx
.
logDebug
(
TAG
,
"initPhotoSize"
)
...
@@ -195,13 +200,17 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
...
@@ -195,13 +200,17 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
val
screenSize
=
val
screenSize
=
list
.
filter
{
it
.
path
.
lowercase
(
Locale
.
ENGLISH
).
contains
(
"screenshot"
)
}.
map
{
File
(
it
.
path
)
}.
sumOf
{
it
.
length
()
}
list
.
filter
{
it
.
path
.
lowercase
(
Locale
.
ENGLISH
).
contains
(
"screenshot"
)
}.
map
{
File
(
it
.
path
)
}.
sumOf
{
it
.
length
()
}
val
similar
=
calculateSimilar
(
list
).
flatMap
{
it
.
value
}.
map
{
File
(
it
.
path
)
}.
sumOf
{
it
.
length
()
}
val
similarPhoto
=
calculateSimilar
(
list
)
RepeatActivity
.
readySimilarList
=
similarPhoto
val
similar
=
similarPhoto
.
flatMap
{
it
.
value
}.
map
{
File
(
it
.
path
)
}.
sumOf
{
it
.
length
()
}
LogEx
.
logDebug
(
TAG
,
"screenSize=$screenSize"
)
LogEx
.
logDebug
(
TAG
,
"screenSize=$screenSize"
)
delay
(
1500
)
delay
(
1500
)
photoSizeFlow
.
emit
(
Pair
(
screenSize
,
similar
))
photoSizeFlow
.
emit
(
Pair
(
screenSize
,
similar
))
photoSizejob
=
null
}
}
}
}
\ No newline at end of file
app/src/main/java/com/base/filerecoveryrecyclebin/activity/repeat/RepeatActivity.kt
View file @
98e2c70e
...
@@ -27,6 +27,7 @@ import com.base.filerecoveryrecyclebin.view.DialogViews.showGerPermission
...
@@ -27,6 +27,7 @@ import com.base.filerecoveryrecyclebin.view.DialogViews.showGerPermission
import
com.base.filerecoveryrecyclebin.view.DialogViews.showTittleDescExitDialog
import
com.base.filerecoveryrecyclebin.view.DialogViews.showTittleDescExitDialog
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.launch
import
kotlinx.coroutines.launch
import
kotlinx.coroutines.withTimeout
import
java.io.File
import
java.io.File
class
RepeatActivity
:
BaseActivity
<
ActivityRepeatBinding
>()
{
class
RepeatActivity
:
BaseActivity
<
ActivityRepeatBinding
>()
{
...
@@ -74,9 +75,6 @@ class RepeatActivity : BaseActivity<ActivityRepeatBinding>() {
...
@@ -74,9 +75,6 @@ class RepeatActivity : BaseActivity<ActivityRepeatBinding>() {
})
})
}
}
// val s = opencvCompareSimilar("/storage/emulated/0/DCIM/1.jpg","/storage/emulated/0/DCIM/22.jpg")
// LogEx.logDebug(TAG,"s=$s")
// Toast.makeText(this, s.toString(), Toast.LENGTH_SHORT).show()
}
}
override
fun
initListener
()
{
override
fun
initListener
()
{
...
@@ -147,20 +145,24 @@ class RepeatActivity : BaseActivity<ActivityRepeatBinding>() {
...
@@ -147,20 +145,24 @@ class RepeatActivity : BaseActivity<ActivityRepeatBinding>() {
val
list
=
arrayListOf
<
MediaBean
>()
val
list
=
arrayListOf
<
MediaBean
>()
getImageMedia
(
list
)
getImageMedia
(
list
)
LogEx
.
logDebug
(
TAG
,
"list=${list.size}"
)
LogEx
.
logDebug
(
TAG
,
"list=${list.size}"
)
val
similarList
=
calculateSimilar
(
list
)
list
.
reversed
()
// similarList.forEach { t, u ->
// LogEx.logDebug(TAG, "t=$t u=$u")
// }
val
result
=
if
(
readySimilarList
==
null
)
{
val
similarList
=
HashMap
<
String
,
ArrayList
<
MediaBean
>>()
// val hashMap = HashMap<String, ArrayList<MediaBean>>()
val
startTime
=
System
.
currentTimeMillis
()
// list.forEach {
val
endTime
=
withTimeout
(
15
*
1000
)
{
// val time = it.time.toFormatTime()
calculateSimilar
(
list
,
similarList
)
// if (hashMap[time] == null) {
System
.
currentTimeMillis
()
// hashMap[time] = arrayListOf()
}
// }
val
spendTime
=
endTime
-
startTime
// hashMap[time]?.add(it)
LogEx
.
logDebug
(
TAG
,
"spendTime=$spendTime startTime=$startTime endTime=$endTime"
)
// }
similarList
val
beanList
=
similarList
.
map
{
map
->
}
else
{
readySimilarList
?:
hashMapOf
()
}
val
beanList
=
result
.
map
{
map
->
val
time
=
File
(
map
.
key
).
lastModified
().
toFormatTime
()
val
time
=
File
(
map
.
key
).
lastModified
().
toFormatTime
()
MediaTimeBean
(
time
=
time
,
beans
=
map
.
value
)
MediaTimeBean
(
time
=
time
,
beans
=
map
.
value
)
}
}
...
@@ -175,7 +177,10 @@ class RepeatActivity : BaseActivity<ActivityRepeatBinding>() {
...
@@ -175,7 +177,10 @@ class RepeatActivity : BaseActivity<ActivityRepeatBinding>() {
binding
.
llEmpty
.
isVisible
=
beanList
.
isEmpty
()
binding
.
llEmpty
.
isVisible
=
beanList
.
isEmpty
()
}
}
}
}
}
companion
object
{
var
readySimilarList
:
HashMap
<
String
,
ArrayList
<
MediaBean
>>?
=
null
}
}
}
}
\ No newline at end of file
app/src/main/java/com/base/filerecoveryrecyclebin/activity/screenshot/ScreenShotActivity.kt
View file @
98e2c70e
...
@@ -22,9 +22,12 @@ import com.base.filerecoveryrecyclebin.utils.BarUtils
...
@@ -22,9 +22,12 @@ import com.base.filerecoveryrecyclebin.utils.BarUtils
import
com.base.filerecoveryrecyclebin.view.DialogViews.showDeletePermanentlyDialog
import
com.base.filerecoveryrecyclebin.view.DialogViews.showDeletePermanentlyDialog
import
com.base.filerecoveryrecyclebin.view.DialogViews.showExitFunctionDialog
import
com.base.filerecoveryrecyclebin.view.DialogViews.showExitFunctionDialog
import
com.base.filerecoveryrecyclebin.view.DialogViews.showGerPermission
import
com.base.filerecoveryrecyclebin.view.DialogViews.showGerPermission
import
kotlinx.coroutines.CoroutineScope
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.async
import
kotlinx.coroutines.async
import
kotlinx.coroutines.isActive
import
kotlinx.coroutines.launch
import
kotlinx.coroutines.launch
import
kotlinx.coroutines.withTimeout
import
java.io.File
import
java.io.File
import
java.text.SimpleDateFormat
import
java.text.SimpleDateFormat
import
java.util.Locale
import
java.util.Locale
...
@@ -32,6 +35,7 @@ import kotlin.collections.HashSet
...
@@ -32,6 +35,7 @@ import kotlin.collections.HashSet
class
ScreenShotActivity
:
BaseActivity
<
ActivityScreenShotBinding
>()
{
class
ScreenShotActivity
:
BaseActivity
<
ActivityScreenShotBinding
>()
{
private
val
TAG
=
"ScreenShotActivity"
private
lateinit
var
screenShotAdapter
:
ScreenShotAdapter
private
lateinit
var
screenShotAdapter
:
ScreenShotAdapter
override
val
binding
:
ActivityScreenShotBinding
by
lazy
{
override
val
binding
:
ActivityScreenShotBinding
by
lazy
{
...
@@ -79,7 +83,9 @@ class ScreenShotActivity : BaseActivity<ActivityScreenShotBinding>() {
...
@@ -79,7 +83,9 @@ class ScreenShotActivity : BaseActivity<ActivityScreenShotBinding>() {
}
}
private
fun
initData
()
=
lifecycleScope
.
launch
(
Dispatchers
.
IO
)
{
private
fun
initData
()
=
lifecycleScope
.
launch
(
Dispatchers
.
IO
)
{
val
list
=
getScreenshotBean
()
val
list
=
getScreenshotBean
()
launch
(
Dispatchers
.
Main
)
{
launch
(
Dispatchers
.
Main
)
{
screenShotAdapter
.
setData
(
list
)
screenShotAdapter
.
setData
(
list
)
val
size
=
list
.
sumOf
{
it
.
screenPhotoBean
.
sumOf
{
ss
->
ss
.
file
.
length
()
}
}
val
size
=
list
.
sumOf
{
it
.
screenPhotoBean
.
sumOf
{
ss
->
ss
.
file
.
length
()
}
}
...
@@ -156,28 +162,37 @@ class ScreenShotActivity : BaseActivity<ActivityScreenShotBinding>() {
...
@@ -156,28 +162,37 @@ class ScreenShotActivity : BaseActivity<ActivityScreenShotBinding>() {
}
}
}
}
private
fun
getScreenshotBean
():
ArrayList
<
ScreenshotBean
>
{
private
fun
CoroutineScope
.
getScreenshotBean
(
myBeans
:
ArrayList
<
ScreenshotBean
>?
=
null
):
ArrayList
<
ScreenshotBean
>
{
val
beans
=
myBeans
?:
arrayListOf
<
ScreenshotBean
>()
val
dcim
=
Environment
.
getExternalStoragePublicDirectory
(
Environment
.
DIRECTORY_DCIM
)
val
dcim
=
Environment
.
getExternalStoragePublicDirectory
(
Environment
.
DIRECTORY_DCIM
)
val
screenFiles
=
FileHelp
.
getDirFiles
(
dcim
)
val
screenFiles
=
FileHelp
.
getDirFiles
(
dcim
)
val
hash
=
HashMap
<
String
,
HashSet
<
File
>>()
val
hash
=
HashMap
<
String
,
HashSet
<
File
>>()
val
formatter
=
SimpleDateFormat
(
"yyyy/MM"
,
Locale
.
getDefault
())
val
formatter
=
SimpleDateFormat
(
"yyyy/MM"
,
Locale
.
getDefault
())
screenFiles
.
forEach
{
file
->
runCatching
{
val
time
=
formatter
.
format
(
file
.
lastModified
())
screenFiles
.
forEach
{
file
->
if
(
hash
[
time
]
==
null
)
{
hash
[
time
]
=
HashSet
()
val
time
=
formatter
.
format
(
file
.
lastModified
())
if
(
hash
[
time
]
==
null
)
{
hash
[
time
]
=
HashSet
()
}
val
set
=
hash
[
time
]
set
?.
add
(
file
)
if
(!
isActive
)
throw
Exception
(
"out Time"
)
}
}
val
set
=
hash
[
time
]
set
?.
add
(
file
)
}
}
val
beans
=
arrayListOf
<
ScreenshotBean
>()
hash
.
forEach
{
(
t
,
u
)
->
runCatching
{
val
arrayList
=
arrayListOf
<
ScreenPhotoBean
>()
hash
.
forEach
{
(
t
,
u
)
->
val
mapList
=
u
.
map
{
file
->
ScreenPhotoBean
(
file
)
}
val
arrayList
=
arrayListOf
<
ScreenPhotoBean
>()
arrayList
.
addAll
(
mapList
)
val
mapList
=
u
.
map
{
file
->
ScreenPhotoBean
(
file
)
}
beans
.
add
(
ScreenshotBean
(
t
,
arrayList
))
arrayList
.
addAll
(
mapList
)
beans
.
add
(
ScreenshotBean
(
t
,
arrayList
))
if
(!
isActive
)
throw
Exception
(
"out Time"
)
}
}
}
return
beans
return
beans
}
}
}
}
\ No newline at end of file
app/src/main/java/com/base/filerecoveryrecyclebin/utils/LogEx.kt
View file @
98e2c70e
...
@@ -10,7 +10,7 @@ object LogEx {
...
@@ -10,7 +10,7 @@ object LogEx {
// "FileHexEx",
// "FileHexEx",
"FileScanResultActivity"
,
"FileScanResultActivity"
,
"FileGridAdapter"
,
"FileGridAdapter"
,
"TestSimilar"
,
"SimilarHelper"
//
"TestSimilar", "SimilarHelper"
)
)
fun
logDebug
(
tag
:
String
,
content
:
String
,
isMust
:
Boolean
=
false
)
{
fun
logDebug
(
tag
:
String
,
content
:
String
,
isMust
:
Boolean
=
false
)
{
...
...
app/src/main/java/com/base/filerecoveryrecyclebin/utils/SimilarHelper.kt
View file @
98e2c70e
...
@@ -4,8 +4,11 @@ import android.graphics.BitmapFactory
...
@@ -4,8 +4,11 @@ import android.graphics.BitmapFactory
import
android.provider.MediaStore.Audio.Radio
import
android.provider.MediaStore.Audio.Radio
import
com.base.filerecoveryrecyclebin.bean.MediaBean
import
com.base.filerecoveryrecyclebin.bean.MediaBean
import
com.base.filerecoveryrecyclebin.utils.TestSimilar.testSimilar
import
com.base.filerecoveryrecyclebin.utils.TestSimilar.testSimilar
import
kotlinx.coroutines.CoroutineScope
import
kotlinx.coroutines.isActive
//import com.base.filerecoveryrecyclebin.utils.OpencvImageHelp.opencvCompareSimilar
//import com.base.filerecoveryrecyclebin.utils.OpencvImageHelp.opencvCompareSimilar
import
java.io.File
import
java.io.File
import
kotlin.math.abs
import
kotlin.random.Random
import
kotlin.random.Random
object
SimilarHelper
{
object
SimilarHelper
{
...
@@ -13,53 +16,66 @@ object SimilarHelper {
...
@@ -13,53 +16,66 @@ object SimilarHelper {
private
val
TAG
=
"SimilarHelper"
private
val
TAG
=
"SimilarHelper"
fun
calculateSimilar
(
list
:
List
<
MediaBean
>):
HashMap
<
String
,
ArrayList
<
MediaBean
>>
{
fun
CoroutineScope
.
calculateSimilar
(
list
:
List
<
MediaBean
>,
myResult
:
HashMap
<
String
,
ArrayList
<
MediaBean
>>?
=
null
):
HashMap
<
String
,
ArrayList
<
MediaBean
>>
{
val
result
=
HashMap
<
String
,
ArrayList
<
MediaBean
>>()
val
result
=
myResult
?:
HashMap
<
String
,
ArrayList
<
MediaBean
>>()
val
eachArrayList
=
arrayListOf
<
MediaBean
>().
apply
{
try
{
addAll
(
list
)
}
val
eachArrayList
=
arrayListOf
<
MediaBean
>().
apply
{
val
haveComperedList
:
ArrayList
<
String
>
=
arrayListOf
()
addAll
(
list
)
}
val
haveComperedList
:
ArrayList
<
String
>
=
arrayListOf
()
val
iterator
=
list
.
iterator
()
val
iterator
=
list
.
iterator
()
while
(
iterator
.
hasNext
()
)
{
while
(
iterator
.
hasNext
()
&&
isActive
)
{
val
item
=
iterator
.
next
()
val
item
=
iterator
.
next
()
LogEx
.
logDebug
(
TAG
,
"next item=$item"
)
LogEx
.
logDebug
(
TAG
,
"next item=$item"
)
LogEx
.
logDebug
(
TAG
,
"eachArrayList=${eachArrayList.size}"
)
LogEx
.
logDebug
(
TAG
,
"eachArrayList=${eachArrayList.size}"
)
if
(!
haveComperedList
.
contains
(
item
.
path
))
{
if
(!
haveComperedList
.
contains
(
item
.
path
))
{
val
compareIterator
=
eachArrayList
.
iterator
()
val
compareIterator
=
eachArrayList
.
iterator
()
while
(
compareIterator
.
hasNext
()
)
{
while
(
compareIterator
.
hasNext
()
&&
isActive
)
{
val
compareItem
=
compareIterator
.
next
()
val
compareItem
=
compareIterator
.
next
()
// LogEx.logDebug(TAG, "compareItem=$compareItem")
// LogEx.logDebug(TAG, "compareItem=$compareItem")
if
(
item
.
path
!=
compareItem
.
path
)
{
if
(
item
.
path
!=
compareItem
.
path
)
{
// val percent = opencvCompareSimilar(item.path, compareItem.path)
// val percent = opencvCompareSimilar(item.path, compareItem.path)
// val percent = similarPercent(File(item.path), File(compareItem.path))
// val percent = similarPercent(File(item.path), File(compareItem.path))
val
isSimilar
=
testSimilar
(
item
.
path
,
compareItem
.
path
)
val
file
=
File
(
item
.
path
)
LogEx
.
logDebug
(
TAG
,
"isSimilar=$isSimilar"
)
val
compareFile
=
File
(
compareItem
.
path
)
if
(
isSimilar
)
{
val
timeFlag
=
abs
(
file
.
lastModified
()
-
compareFile
.
lastModified
())
<
7
*
24
*
60
*
60
*
1000L
if
(
result
[
item
.
path
]
==
null
)
{
if
(!
timeFlag
)
continue
LogEx
.
logDebug
(
TAG
,
"item=$item"
)
val
isSimilar
=
testSimilar
(
item
.
path
,
compareItem
.
path
)
result
[
item
.
path
]
=
arrayListOf
()
LogEx
.
logDebug
(
TAG
,
"isSimilar=$isSimilar"
)
}
if
(
isSimilar
)
{
if
(
result
[
item
.
path
]
?.
isEmpty
()
==
true
)
{
if
(
result
[
item
.
path
]
==
null
)
{
result
[
item
.
path
]
?.
add
(
item
)
LogEx
.
logDebug
(
TAG
,
"item=$item"
)
result
[
item
.
path
]
=
arrayListOf
()
}
if
(
result
[
item
.
path
]
?.
isEmpty
()
==
true
)
{
result
[
item
.
path
]
?.
add
(
item
)
}
result
[
item
.
path
]
?.
add
(
compareItem
)
haveComperedList
.
add
(
compareItem
.
path
)
compareIterator
.
remove
()
}
}
result
[
item
.
path
]
?.
add
(
compareItem
)
}
else
{
haveComperedList
.
add
(
compareItem
.
path
)
compareIterator
.
remove
()
compareIterator
.
remove
()
}
}
}
else
{
compareIterator
.
remove
()
}
}
}
}
}
}
}
catch
(
e
:
Exception
)
{
e
.
printStackTrace
()
}
}
return
result
return
result
}
}
...
...
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