Commit 2be825d7 authored by wanglei's avatar wanglei

...

parent 09271904
......@@ -6,6 +6,7 @@ import android.graphics.Color
import android.os.Environment
import android.view.View
import androidx.activity.addCallback
import androidx.core.view.isVisible
import androidx.lifecycle.lifecycleScope
import com.base.datarecovery.adapter.FileFolderAdapter
import com.base.datarecovery.ads.AdmobInterstitialUtils
......@@ -18,6 +19,7 @@ import com.base.datarecovery.bean.RecoveryBean.Companion.setType
import com.base.datarecovery.databinding.ActivityFileScanResultBinding
import com.base.datarecovery.help.BaseActivity
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.requestStorePermission
import com.base.datarecovery.utils.BarUtils
......@@ -28,12 +30,15 @@ import com.base.datarecovery.view.FileScanDialog
import com.google.gson.Gson
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
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>() {
......@@ -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")
private fun beginScan() {
......@@ -149,31 +133,25 @@ class FileScanResultActivity : BaseActivity<ActivityFileScanResultBinding>() {
)
val foundFlow: SharedFlow<Pair<Int, String>> = mFoundFlow
val dialogClass = FileScanDialog(this)
val scanDialog = dialogClass.showFileScanDialog(pathFlow, foundFlow)
val filter = when (scanType) {
SCAN_PHOTOS -> FileHexEx::isImage
SCAN_DOCUMENTS -> FileHexEx::isDocument
SCAN_VIDEOS -> FileHexEx::isVideo
else -> FileHexEx::isImage
}
val pathList = ArrayList<String>()
var pathShowed = false
lifecycleScope.launch(Dispatchers.Main) {
mFoundFlow.collectLatest {
val dialogClass = FileScanDialog(this)
val scanDialog = dialogClass.showFileScanDialog(pathFlow, foundFlow) {
if (!pathShowed) {
pathShowed = true
dialogClass.scanShowUI()
}
pathList.add(it.second)
pathList.add(it)
binding.tvFileNumber.text = pathList.size.toString()
setAdapterData(pathList)
}
setAdapterData(it)
}
val filter = when (scanType) {
SCAN_PHOTOS -> FileHexEx::isImage
SCAN_DOCUMENTS -> FileHexEx::isDocument
SCAN_VIDEOS -> FileHexEx::isVideo
else -> FileHexEx::isImage
}
val root = Environment.getExternalStorageDirectory()
lifecycleScope.loadFileByFilter(
mPathFlow,
......@@ -186,7 +164,8 @@ class FileScanResultActivity : BaseActivity<ActivityFileScanResultBinding>() {
lifecycleScope.launch(Dispatchers.Main) {
binding.ivWancheng.visibility = View.VISIBLE
binding.tvScanning.text = "Completed!"
AdmobInterstitialUtils.showInterstitialAd(this@FileScanResultActivity) {}
AdmobInterstitialUtils.showInterstitialAd(this@FileScanResultActivity, isShowDialog = false) {}
binding.ivEmpty.isVisible = pathList.isEmpty()
dialogClass.finishScan {
scanDialog.dismiss()
}
......@@ -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(
beanList.addAll(list)
notifyDataSetChanged()
}
@SuppressLint("NotifyDataSetChanged")
fun addData(list: List<FolderBean>) {
beanList.addAll(list)
notifyDataSetChanged()
}
}
\ No newline at end of file
......@@ -47,8 +47,9 @@ class FileTimeColumnsAdapter(
val binding = ItemTimeMediaBinding.bind(holder.itemView)
val context = holder.itemView.context
val bean = beanList[position]
binding.tvTime.text = bean.time
val file = File(bean.recoveryList.first().path)
val time = SimpleDateFormat("yyyy-MMM-dd", Locale.getDefault()).format(file.lastModified())
binding.tvTime.text = time
binding.ivSelector.isSelected = bean.isSelect
......
......@@ -37,8 +37,8 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {
override fun setListener() {
binding.flScan.setOnClickListener {
// startActivity(Intent(requireContext(), ScanJunkActivity::class.java))
sendNotification(requireContext(), ConstObject.ID_JUNK_CLEAN_PUSH)
startActivity(Intent(requireContext(), ScanJunkActivity::class.java))
// sendNotification(requireContext(), ConstObject.ID_JUNK_CLEAN_PUSH)
}
binding.flRyPhoto.setOnClickListener {
startActivity(Intent(requireContext(), FileScanResultActivity::class.java).apply {
......
......@@ -29,7 +29,8 @@ class FileScanDialog(
@SuppressLint("SetTextI18n")
fun showFileScanDialog(
pathFlow: SharedFlow<String>,
foundFlow: SharedFlow<Pair<Int, String>>
foundFlow: SharedFlow<Pair<Int, String>>,
foundAction: ((path: String) -> Unit)? = null
): AlertDialog {
dialog?.setView(binding.root)
dialog?.setCanceledOnTouchOutside(false)
......@@ -66,6 +67,7 @@ class FileScanDialog(
activity.lifecycleScope.launch {
foundFlow.collectLatest {
binding.tvFoundNumber.text = "Found ${it.first} files"
foundAction?.invoke(it.second)
}
}
......
......@@ -172,13 +172,27 @@
</androidx.cardview.widget.CardView>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
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>
\ 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