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
Show 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
import
androidx.lifecycle.lifecycleScope
import
androidx.viewpager2.adapter.FragmentStateAdapter
import
androidx.viewpager2.widget.ViewPager2
import
com.base.filerecoveryrecyclebin.activity.repeat.RepeatActivity
import
com.base.filerecoveryrecyclebin.ads.admob.AdmobBannerUtils
import
com.base.filerecoveryrecyclebin.bean.MediaBean
import
com.base.filerecoveryrecyclebin.databinding.ActivityMainBinding
...
...
@@ -33,6 +34,7 @@ import com.base.filerecoveryrecyclebin.view.PermissionDialog.showPermissionBotto
import
com.base.filerecoveryrecyclebin.view.RateStarPop.showRateStarPopDialog
import
com.facebook.appevents.AppEventsLogger
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.Job
import
kotlinx.coroutines.delay
import
kotlinx.coroutines.flow.MutableSharedFlow
import
kotlinx.coroutines.launch
...
...
@@ -177,7 +179,9 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
if
(
checkStorePermission
())
{
initStayServiceObserver
()
initPhotoSize
()
if
(
photoSizejob
==
null
)
{
photoSizejob
=
initPhotoSize
()
}
}
lifecycleScope
.
launch
(
Dispatchers
.
Main
)
{
...
...
@@ -186,6 +190,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
}
}
var
photoSizejob
:
Job
?
=
null
private
fun
initPhotoSize
()
=
lifecycleScope
.
launch
(
Dispatchers
.
IO
)
{
LogEx
.
logDebug
(
TAG
,
"initPhotoSize"
)
...
...
@@ -195,13 +200,17 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
val
screenSize
=
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"
)
delay
(
1500
)
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
import
com.base.filerecoveryrecyclebin.view.DialogViews.showTittleDescExitDialog
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.launch
import
kotlinx.coroutines.withTimeout
import
java.io.File
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
()
{
...
...
@@ -147,20 +145,24 @@ class RepeatActivity : BaseActivity<ActivityRepeatBinding>() {
val
list
=
arrayListOf
<
MediaBean
>()
getImageMedia
(
list
)
LogEx
.
logDebug
(
TAG
,
"list=${list.size}"
)
val
similarList
=
calculateSimilar
(
list
)
// similarList.forEach { t, u ->
// LogEx.logDebug(TAG, "t=$t u=$u")
// }
// val hashMap = HashMap<String, ArrayList<MediaBean>>()
// list.forEach {
// val time = it.time.toFormatTime()
// if (hashMap[time] == null) {
// hashMap[time] = arrayListOf()
// }
// hashMap[time]?.add(it)
// }
val
beanList
=
similarList
.
map
{
map
->
list
.
reversed
()
val
result
=
if
(
readySimilarList
==
null
)
{
val
similarList
=
HashMap
<
String
,
ArrayList
<
MediaBean
>>()
val
startTime
=
System
.
currentTimeMillis
()
val
endTime
=
withTimeout
(
15
*
1000
)
{
calculateSimilar
(
list
,
similarList
)
System
.
currentTimeMillis
()
}
val
spendTime
=
endTime
-
startTime
LogEx
.
logDebug
(
TAG
,
"spendTime=$spendTime startTime=$startTime endTime=$endTime"
)
similarList
}
else
{
readySimilarList
?:
hashMapOf
()
}
val
beanList
=
result
.
map
{
map
->
val
time
=
File
(
map
.
key
).
lastModified
().
toFormatTime
()
MediaTimeBean
(
time
=
time
,
beans
=
map
.
value
)
}
...
...
@@ -175,7 +177,10 @@ class RepeatActivity : BaseActivity<ActivityRepeatBinding>() {
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
import
com.base.filerecoveryrecyclebin.view.DialogViews.showDeletePermanentlyDialog
import
com.base.filerecoveryrecyclebin.view.DialogViews.showExitFunctionDialog
import
com.base.filerecoveryrecyclebin.view.DialogViews.showGerPermission
import
kotlinx.coroutines.CoroutineScope
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.async
import
kotlinx.coroutines.isActive
import
kotlinx.coroutines.launch
import
kotlinx.coroutines.withTimeout
import
java.io.File
import
java.text.SimpleDateFormat
import
java.util.Locale
...
...
@@ -32,6 +35,7 @@ import kotlin.collections.HashSet
class
ScreenShotActivity
:
BaseActivity
<
ActivityScreenShotBinding
>()
{
private
val
TAG
=
"ScreenShotActivity"
private
lateinit
var
screenShotAdapter
:
ScreenShotAdapter
override
val
binding
:
ActivityScreenShotBinding
by
lazy
{
...
...
@@ -79,7 +83,9 @@ class ScreenShotActivity : BaseActivity<ActivityScreenShotBinding>() {
}
private
fun
initData
()
=
lifecycleScope
.
launch
(
Dispatchers
.
IO
)
{
val
list
=
getScreenshotBean
()
launch
(
Dispatchers
.
Main
)
{
screenShotAdapter
.
setData
(
list
)
val
size
=
list
.
sumOf
{
it
.
screenPhotoBean
.
sumOf
{
ss
->
ss
.
file
.
length
()
}
}
...
...
@@ -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
screenFiles
=
FileHelp
.
getDirFiles
(
dcim
)
val
hash
=
HashMap
<
String
,
HashSet
<
File
>>()
val
formatter
=
SimpleDateFormat
(
"yyyy/MM"
,
Locale
.
getDefault
())
runCatching
{
screenFiles
.
forEach
{
file
->
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
beans
=
arrayListOf
<
ScreenshotBean
>()
runCatching
{
hash
.
forEach
{
(
t
,
u
)
->
val
arrayList
=
arrayListOf
<
ScreenPhotoBean
>()
val
mapList
=
u
.
map
{
file
->
ScreenPhotoBean
(
file
)
}
arrayList
.
addAll
(
mapList
)
beans
.
add
(
ScreenshotBean
(
t
,
arrayList
))
if
(!
isActive
)
throw
Exception
(
"out Time"
)
}
}
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 {
// "FileHexEx",
"FileScanResultActivity"
,
"FileGridAdapter"
,
"TestSimilar"
,
"SimilarHelper"
//
"TestSimilar", "SimilarHelper"
)
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
import
android.provider.MediaStore.Audio.Radio
import
com.base.filerecoveryrecyclebin.bean.MediaBean
import
com.base.filerecoveryrecyclebin.utils.TestSimilar.testSimilar
import
kotlinx.coroutines.CoroutineScope
import
kotlinx.coroutines.isActive
//import com.base.filerecoveryrecyclebin.utils.OpencvImageHelp.opencvCompareSimilar
import
java.io.File
import
kotlin.math.abs
import
kotlin.random.Random
object
SimilarHelper
{
...
...
@@ -13,9 +16,14 @@ object 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
=
myResult
?:
HashMap
<
String
,
ArrayList
<
MediaBean
>>()
try
{
val
result
=
HashMap
<
String
,
ArrayList
<
MediaBean
>>()
val
eachArrayList
=
arrayListOf
<
MediaBean
>().
apply
{
addAll
(
list
)
}
...
...
@@ -24,7 +32,7 @@ object SimilarHelper {
val
iterator
=
list
.
iterator
()
while
(
iterator
.
hasNext
()
)
{
while
(
iterator
.
hasNext
()
&&
isActive
)
{
val
item
=
iterator
.
next
()
LogEx
.
logDebug
(
TAG
,
"next item=$item"
)
...
...
@@ -32,13 +40,17 @@ object SimilarHelper {
if
(!
haveComperedList
.
contains
(
item
.
path
))
{
val
compareIterator
=
eachArrayList
.
iterator
()
while
(
compareIterator
.
hasNext
()
)
{
while
(
compareIterator
.
hasNext
()
&&
isActive
)
{
val
compareItem
=
compareIterator
.
next
()
// LogEx.logDebug(TAG, "compareItem=$compareItem")
if
(
item
.
path
!=
compareItem
.
path
)
{
// val percent = opencvCompareSimilar(item.path, compareItem.path)
// val percent = similarPercent(File(item.path), File(compareItem.path))
val
file
=
File
(
item
.
path
)
val
compareFile
=
File
(
compareItem
.
path
)
val
timeFlag
=
abs
(
file
.
lastModified
()
-
compareFile
.
lastModified
())
<
7
*
24
*
60
*
60
*
1000L
if
(!
timeFlag
)
continue
val
isSimilar
=
testSimilar
(
item
.
path
,
compareItem
.
path
)
LogEx
.
logDebug
(
TAG
,
"isSimilar=$isSimilar"
)
if
(
isSimilar
)
{
...
...
@@ -60,6 +72,10 @@ object SimilarHelper {
}
}
}
catch
(
e
:
Exception
)
{
e
.
printStackTrace
()
}
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