Commit 2be825d7 authored by wanglei's avatar wanglei

...

parent 09271904
...@@ -6,6 +6,7 @@ import android.graphics.Color ...@@ -6,6 +6,7 @@ import android.graphics.Color
import android.os.Environment import android.os.Environment
import android.view.View import android.view.View
import androidx.activity.addCallback import androidx.activity.addCallback
import androidx.core.view.isVisible
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import com.base.datarecovery.adapter.FileFolderAdapter import com.base.datarecovery.adapter.FileFolderAdapter
import com.base.datarecovery.ads.AdmobInterstitialUtils import com.base.datarecovery.ads.AdmobInterstitialUtils
...@@ -18,6 +19,7 @@ import com.base.datarecovery.bean.RecoveryBean.Companion.setType ...@@ -18,6 +19,7 @@ import com.base.datarecovery.bean.RecoveryBean.Companion.setType
import com.base.datarecovery.databinding.ActivityFileScanResultBinding import com.base.datarecovery.databinding.ActivityFileScanResultBinding
import com.base.datarecovery.help.BaseActivity import com.base.datarecovery.help.BaseActivity
import com.base.datarecovery.help.FileHelp.loadFileByFilter import com.base.datarecovery.help.FileHelp.loadFileByFilter
import com.base.datarecovery.help.KotlinExt.toFormatTime
import com.base.datarecovery.help.PermissionHelp.checkStorePermission import com.base.datarecovery.help.PermissionHelp.checkStorePermission
import com.base.datarecovery.help.PermissionHelp.requestStorePermission import com.base.datarecovery.help.PermissionHelp.requestStorePermission
import com.base.datarecovery.utils.BarUtils import com.base.datarecovery.utils.BarUtils
...@@ -28,12 +30,15 @@ import com.base.datarecovery.view.FileScanDialog ...@@ -28,12 +30,15 @@ import com.base.datarecovery.view.FileScanDialog
import com.google.gson.Gson import com.google.gson.Gson
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.channels.BufferOverflow import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.io.File import java.io.File
import java.util.HashMap import java.text.SimpleDateFormat
import java.util.Locale
import java.util.concurrent.LinkedBlockingQueue
class FileScanResultActivity : BaseActivity<ActivityFileScanResultBinding>() { class FileScanResultActivity : BaseActivity<ActivityFileScanResultBinding>() {
...@@ -105,27 +110,6 @@ class FileScanResultActivity : BaseActivity<ActivityFileScanResultBinding>() { ...@@ -105,27 +110,6 @@ class FileScanResultActivity : BaseActivity<ActivityFileScanResultBinding>() {
} }
} }
private fun setAdapterData(pathList: ArrayList<String>) {
val hashMap = HashMap<String, ArrayList<RecoveryBean>>()
pathList.forEach { path ->
val folder = File(path).parent ?: ""
if (hashMap[folder] == null) {
hashMap[folder] = arrayListOf()
}
hashMap[folder]?.add(RecoveryBean(path))
}
val list = hashMap.map {
val folder = it.key.split("/").last()
if (scanType == SCAN_DOCUMENTS) {
it.value.forEach { bean -> bean.setType() }
}
FolderBean(folder, recoveryList = it.value)
}
binding.tvFolderNumber.text = list.size.toString()
fileFolderAdapter.setData(list)
}
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
private fun beginScan() { private fun beginScan() {
...@@ -149,8 +133,18 @@ class FileScanResultActivity : BaseActivity<ActivityFileScanResultBinding>() { ...@@ -149,8 +133,18 @@ class FileScanResultActivity : BaseActivity<ActivityFileScanResultBinding>() {
) )
val foundFlow: SharedFlow<Pair<Int, String>> = mFoundFlow val foundFlow: SharedFlow<Pair<Int, String>> = mFoundFlow
var pathShowed = false
val dialogClass = FileScanDialog(this) val dialogClass = FileScanDialog(this)
val scanDialog = dialogClass.showFileScanDialog(pathFlow, foundFlow) val scanDialog = dialogClass.showFileScanDialog(pathFlow, foundFlow) {
if (!pathShowed) {
pathShowed = true
dialogClass.scanShowUI()
}
pathList.add(it)
binding.tvFileNumber.text = pathList.size.toString()
setAdapterData(it)
}
val filter = when (scanType) { val filter = when (scanType) {
SCAN_PHOTOS -> FileHexEx::isImage SCAN_PHOTOS -> FileHexEx::isImage
...@@ -158,22 +152,6 @@ class FileScanResultActivity : BaseActivity<ActivityFileScanResultBinding>() { ...@@ -158,22 +152,6 @@ class FileScanResultActivity : BaseActivity<ActivityFileScanResultBinding>() {
SCAN_VIDEOS -> FileHexEx::isVideo SCAN_VIDEOS -> FileHexEx::isVideo
else -> FileHexEx::isImage else -> FileHexEx::isImage
} }
val pathList = ArrayList<String>()
var pathShowed = false
lifecycleScope.launch(Dispatchers.Main) {
mFoundFlow.collectLatest {
if (!pathShowed) {
pathShowed = true
dialogClass.scanShowUI()
}
pathList.add(it.second)
binding.tvFileNumber.text = pathList.size.toString()
setAdapterData(pathList)
}
}
val root = Environment.getExternalStorageDirectory() val root = Environment.getExternalStorageDirectory()
lifecycleScope.loadFileByFilter( lifecycleScope.loadFileByFilter(
mPathFlow, mPathFlow,
...@@ -186,7 +164,8 @@ class FileScanResultActivity : BaseActivity<ActivityFileScanResultBinding>() { ...@@ -186,7 +164,8 @@ class FileScanResultActivity : BaseActivity<ActivityFileScanResultBinding>() {
lifecycleScope.launch(Dispatchers.Main) { lifecycleScope.launch(Dispatchers.Main) {
binding.ivWancheng.visibility = View.VISIBLE binding.ivWancheng.visibility = View.VISIBLE
binding.tvScanning.text = "Completed!" binding.tvScanning.text = "Completed!"
AdmobInterstitialUtils.showInterstitialAd(this@FileScanResultActivity) {} AdmobInterstitialUtils.showInterstitialAd(this@FileScanResultActivity, isShowDialog = false) {}
binding.ivEmpty.isVisible = pathList.isEmpty()
dialogClass.finishScan { dialogClass.finishScan {
scanDialog.dismiss() scanDialog.dismiss()
} }
...@@ -195,4 +174,34 @@ class FileScanResultActivity : BaseActivity<ActivityFileScanResultBinding>() { ...@@ -195,4 +174,34 @@ class FileScanResultActivity : BaseActivity<ActivityFileScanResultBinding>() {
) )
} }
private val pathList = ArrayList<String>()
private val hashMap = HashMap<String, ArrayList<RecoveryBean>>()
private fun setAdapterData(path: String) {
val flag = addMapFolder(path)
if (flag) {
binding.tvFolderNumber.text = hashMap.keys.size.toString()
val mapList = hashMap.map {
val folderName = it.key.split("/").last()
FolderBean(folderName, recoveryList = it.value)
}
fileFolderAdapter.setData(mapList)
} else {
binding.tvFileNumber.text = hashMap.values.sumOf { it.size }.toString()
}
}
private fun addMapFolder(path: String): Boolean {
val folder = File(path).parent ?: ""
if (hashMap[folder] == null) {
hashMap[folder] = arrayListOf()
return true
}
val recoveryBean = RecoveryBean(path)
if (scanType == SCAN_DOCUMENTS) {
recoveryBean.setType()
}
hashMap[folder]?.add(recoveryBean)
return false
}
} }
\ No newline at end of file
...@@ -101,4 +101,9 @@ class FileFolderAdapter( ...@@ -101,4 +101,9 @@ class FileFolderAdapter(
beanList.addAll(list) beanList.addAll(list)
notifyDataSetChanged() notifyDataSetChanged()
} }
@SuppressLint("NotifyDataSetChanged")
fun addData(list: List<FolderBean>) {
beanList.addAll(list)
notifyDataSetChanged()
}
} }
\ No newline at end of file
...@@ -47,8 +47,9 @@ class FileTimeColumnsAdapter( ...@@ -47,8 +47,9 @@ class FileTimeColumnsAdapter(
val binding = ItemTimeMediaBinding.bind(holder.itemView) val binding = ItemTimeMediaBinding.bind(holder.itemView)
val context = holder.itemView.context val context = holder.itemView.context
val bean = beanList[position] val bean = beanList[position]
val file = File(bean.recoveryList.first().path)
binding.tvTime.text = bean.time val time = SimpleDateFormat("yyyy-MMM-dd", Locale.getDefault()).format(file.lastModified())
binding.tvTime.text = time
binding.ivSelector.isSelected = bean.isSelect binding.ivSelector.isSelected = bean.isSelect
......
...@@ -37,8 +37,8 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() { ...@@ -37,8 +37,8 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {
override fun setListener() { override fun setListener() {
binding.flScan.setOnClickListener { binding.flScan.setOnClickListener {
// startActivity(Intent(requireContext(), ScanJunkActivity::class.java)) startActivity(Intent(requireContext(), ScanJunkActivity::class.java))
sendNotification(requireContext(), ConstObject.ID_JUNK_CLEAN_PUSH) // sendNotification(requireContext(), ConstObject.ID_JUNK_CLEAN_PUSH)
} }
binding.flRyPhoto.setOnClickListener { binding.flRyPhoto.setOnClickListener {
startActivity(Intent(requireContext(), FileScanResultActivity::class.java).apply { startActivity(Intent(requireContext(), FileScanResultActivity::class.java).apply {
......
...@@ -29,7 +29,8 @@ class FileScanDialog( ...@@ -29,7 +29,8 @@ class FileScanDialog(
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
fun showFileScanDialog( fun showFileScanDialog(
pathFlow: SharedFlow<String>, pathFlow: SharedFlow<String>,
foundFlow: SharedFlow<Pair<Int, String>> foundFlow: SharedFlow<Pair<Int, String>>,
foundAction: ((path: String) -> Unit)? = null
): AlertDialog { ): AlertDialog {
dialog?.setView(binding.root) dialog?.setView(binding.root)
dialog?.setCanceledOnTouchOutside(false) dialog?.setCanceledOnTouchOutside(false)
...@@ -66,6 +67,7 @@ class FileScanDialog( ...@@ -66,6 +67,7 @@ class FileScanDialog(
activity.lifecycleScope.launch { activity.lifecycleScope.launch {
foundFlow.collectLatest { foundFlow.collectLatest {
binding.tvFoundNumber.text = "Found ${it.first} files" binding.tvFoundNumber.text = "Found ${it.first} files"
foundAction?.invoke(it.second)
} }
} }
......
...@@ -172,13 +172,27 @@ ...@@ -172,13 +172,27 @@
</androidx.cardview.widget.CardView> </androidx.cardview.widget.CardView>
<androidx.recyclerview.widget.RecyclerView <FrameLayout
android:id="@+id/rv"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="16dp" android:layout_marginTop="16dp">
android:orientation="vertical"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" <androidx.recyclerview.widget.RecyclerView
tools:listitem="@layout/item_folder_recovery" /> android:id="@+id/rv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/item_folder_recovery" />
<ImageView
android:id="@+id/iv_empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@mipmap/queshengye"
android:visibility="gone"
tools:ignore="ContentDescription" />
</FrameLayout>
</LinearLayout> </LinearLayout>
\ No newline at end of file
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