Commit 98e2c70e authored by wanglei's avatar wanglei

...

parent 2ca447af
...@@ -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
...@@ -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
...@@ -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())
runCatching {
screenFiles.forEach { file -> screenFiles.forEach { file ->
val time = formatter.format(file.lastModified()) val time = formatter.format(file.lastModified())
if (hash[time] == null) { if (hash[time] == null) {
hash[time] = HashSet() hash[time] = HashSet()
} }
val set = hash[time] val set = hash[time]
set?.add(file) set?.add(file)
if (!isActive) throw Exception("out Time")
}
} }
val beans = arrayListOf<ScreenshotBean>()
runCatching {
hash.forEach { (t, u) -> hash.forEach { (t, u) ->
val arrayList = arrayListOf<ScreenPhotoBean>() val arrayList = arrayListOf<ScreenPhotoBean>()
val mapList = u.map { file -> ScreenPhotoBean(file) } val mapList = u.map { file -> ScreenPhotoBean(file) }
arrayList.addAll(mapList) arrayList.addAll(mapList)
beans.add(ScreenshotBean(t, arrayList)) beans.add(ScreenshotBean(t, arrayList))
if (!isActive) throw Exception("out Time")
} }
}
return beans return beans
} }
} }
\ No newline at end of file
...@@ -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) {
......
...@@ -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,9 +16,14 @@ object SimilarHelper { ...@@ -13,9 +16,14 @@ 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 = myResult ?: HashMap<String, ArrayList<MediaBean>>()
try {
val result = HashMap<String, ArrayList<MediaBean>>()
val eachArrayList = arrayListOf<MediaBean>().apply { val eachArrayList = arrayListOf<MediaBean>().apply {
addAll(list) addAll(list)
} }
...@@ -24,7 +32,7 @@ object SimilarHelper { ...@@ -24,7 +32,7 @@ object SimilarHelper {
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")
...@@ -32,13 +40,17 @@ object SimilarHelper { ...@@ -32,13 +40,17 @@ object SimilarHelper {
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 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) val isSimilar = testSimilar(item.path, compareItem.path)
LogEx.logDebug(TAG, "isSimilar=$isSimilar") LogEx.logDebug(TAG, "isSimilar=$isSimilar")
if (isSimilar) { if (isSimilar) {
...@@ -60,6 +72,10 @@ object SimilarHelper { ...@@ -60,6 +72,10 @@ object SimilarHelper {
} }
} }
} catch (e: Exception) {
e.printStackTrace()
}
return result return result
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment