Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
A
appzxhy
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
appzxhy
Commits
4f362a4f
Commit
4f362a4f
authored
Jul 11, 2025
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[AI重构]AI重构SimilarPhotosActivity
parent
2111510d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
19 deletions
+22
-19
SimilarPhotosActivity.kt
...com/simplecleaner/app/ui/similar/SimilarPhotosActivity.kt
+22
-19
No files found.
app/src/main/java/com/simplecleaner/app/ui/similar/SimilarPhotosActivity.kt
View file @
4f362a4f
...
...
@@ -38,6 +38,7 @@ import kotlinx.coroutines.async
import
kotlinx.coroutines.launch
import
java.io.File
import
java.util.concurrent.Semaphore
import
kotlinx.coroutines.withContext
class
SimilarPhotosActivity
:
BaseActivity
<
ActivitySimilarPhotosBinding
>(
ActivitySimilarPhotosBinding
::
inflate
)
{
...
...
@@ -191,34 +192,36 @@ class SimilarPhotosActivity : BaseActivity<ActivitySimilarPhotosBinding>(Activit
private
fun
initData
()
{
lifecycleScope
.
launch
(
Dispatchers
.
IO
)
{
val
images
=
MediaUtils
.
findImageFiles
(
this
@SimilarPhotosActivity
)
val
similarBeans
=
images
.
mapNotNull
{
value
->
lifecycleScope
.
async
(
Dispatchers
.
IO
)
{
semaphore
.
acquire
()
// 请求许可
try
{
SimilarUtils
.
createImage
(
value
.
path
)
}
finally
{
semaphore
.
release
()
// 释放许可
}
}.
await
()
}
val
hasSame
=
mutableSetOf
<
String
>()
similarBeans
.
forEach
{
similar
->
if
(
hasSame
.
contains
(
similar
.
url
))
return
@forEach
for
(
value
in
images
)
{
semaphore
.
acquire
()
val
similar
=
try
{
SimilarUtils
.
createImage
(
value
.
path
)
}
finally
{
semaphore
.
release
()
}
if
(
similar
==
null
||
hasSame
.
contains
(
similar
.
url
))
continue
hasSame
.
add
(
similar
.
url
)
similar
.
items
.
add
(
similar
)
similarBeans
.
forEach
{
if
(!
hasSame
.
contains
(
it
.
url
)
&&
SimilarUtils
.
similarCondition
(
similar
,
it
))
{
hasSame
.
add
(
it
.
url
)
similar
.
items
.
add
(
it
)
for
(
it
in
images
)
{
if
(
it
.
path
==
value
.
path
)
continue
val
other
=
SimilarUtils
.
createImage
(
it
.
path
)
if
(
other
!=
null
&&
!
hasSame
.
contains
(
other
.
url
)
&&
SimilarUtils
.
similarCondition
(
similar
,
other
))
{
hasSame
.
add
(
other
.
url
)
similar
.
items
.
add
(
other
)
}
}
if
(
similar
.
items
.
size
>
1
)
{
withContext
(
Dispatchers
.
Main
)
{
list
.
add
(
similar
)
adapter
.
notifyItemInserted
(
list
.
lastIndex
)
updateSelection
()
}
}
}
list
=
similarBeans
.
filter
{
it
.
items
.
size
>
1
}.
toMutableList
()
launch
(
Dispatchers
.
IO
)
{
similarSize
=
list
.
sumOf
{
it
.
size
}
+
list
.
sumOf
{
it
.
items
.
sumOf
{
it
.
size
}
}
}
launch
(
Dispatchers
.
Main
)
{
if
(
state
!=
0
)
scanComplete
()
state
=
2
...
...
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