Commit 117ac552 authored by wanglei's avatar wanglei

...

parent fdea62c1
...@@ -9,9 +9,12 @@ import androidx.core.view.isVisible ...@@ -9,9 +9,12 @@ import androidx.core.view.isVisible
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import com.base.filerecoveryrecyclebin.activity.MainActivity import com.base.filerecoveryrecyclebin.activity.MainActivity
import com.base.filerecoveryrecyclebin.activity.recyclebin.RecycleBinDetailActivity import com.base.filerecoveryrecyclebin.activity.recyclebin.RecycleBinDetailActivity
import com.base.filerecoveryrecyclebin.activity.recyclebin.RecycleBinFileEx.getRecycleBinDir
import com.base.filerecoveryrecyclebin.adapter.RecycleBinAdapter import com.base.filerecoveryrecyclebin.adapter.RecycleBinAdapter
import com.base.filerecoveryrecyclebin.bean.RecycleBinBean import com.base.filerecoveryrecyclebin.bean.RecycleBinBean
import com.base.filerecoveryrecyclebin.bean.RecycleBinBean.Companion.mAudioStr
import com.base.filerecoveryrecyclebin.bean.RecycleBinBean.Companion.mDocumentStr
import com.base.filerecoveryrecyclebin.bean.RecycleBinBean.Companion.mImageStr
import com.base.filerecoveryrecyclebin.bean.RecycleBinBean.Companion.mVideoStr
import com.base.filerecoveryrecyclebin.databinding.FragmentRecycleBinBinding import com.base.filerecoveryrecyclebin.databinding.FragmentRecycleBinBinding
import com.base.filerecoveryrecyclebin.help.BaseFragment import com.base.filerecoveryrecyclebin.help.BaseFragment
import com.base.filerecoveryrecyclebin.help.PermissionHelp.checkStorePermission import com.base.filerecoveryrecyclebin.help.PermissionHelp.checkStorePermission
...@@ -19,9 +22,9 @@ import com.base.filerecoveryrecyclebin.help.PermissionHelp.requestStorePermissio ...@@ -19,9 +22,9 @@ import com.base.filerecoveryrecyclebin.help.PermissionHelp.requestStorePermissio
import com.base.filerecoveryrecyclebin.service.BackUpUtils import com.base.filerecoveryrecyclebin.service.BackUpUtils
import com.base.filerecoveryrecyclebin.utils.LogEx import com.base.filerecoveryrecyclebin.utils.LogEx
import com.base.filerecoveryrecyclebin.view.DialogViews.showGerPermission import com.base.filerecoveryrecyclebin.view.DialogViews.showGerPermission
import com.base.filerecoveryrecyclebin.view.DialogViews.showRecycleBinFilter
import com.google.gson.Gson import com.google.gson.Gson
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
class RecycleBinFragment : BaseFragment<FragmentRecycleBinBinding>() { class RecycleBinFragment : BaseFragment<FragmentRecycleBinBinding>() {
...@@ -47,11 +50,16 @@ class RecycleBinFragment : BaseFragment<FragmentRecycleBinBinding>() { ...@@ -47,11 +50,16 @@ class RecycleBinFragment : BaseFragment<FragmentRecycleBinBinding>() {
} }
var binFilter: String? = null
@RequiresApi(Build.VERSION_CODES.Q) @RequiresApi(Build.VERSION_CODES.Q)
override fun setListener() { override fun setListener() {
super.setListener() super.setListener()
binding.flGengduo.setOnClickListener { binding.flGengduo.setOnClickListener {
requireContext().showRecycleBinFilter(lifecycleScope, binFilter) {
binFilter = if (binFilter == it) null else it
initData()
}
} }
binding.swipeRefreshLayout.setOnRefreshListener { binding.swipeRefreshLayout.setOnRefreshListener {
binding.swipeRefreshLayout.isRefreshing = true binding.swipeRefreshLayout.isRefreshing = true
...@@ -61,11 +69,22 @@ class RecycleBinFragment : BaseFragment<FragmentRecycleBinBinding>() { ...@@ -61,11 +69,22 @@ class RecycleBinFragment : BaseFragment<FragmentRecycleBinBinding>() {
} }
} }
private fun filterAction(bin: RecycleBinBean): Boolean {
LogEx.logDebug(TAG, "binFilter=$binFilter")
return when (binFilter) {
"Photos" -> mImageStr.contains("." + bin.mimeType)
"Videos" -> mVideoStr.contains("." + bin.mimeType)
"Audios" -> mAudioStr.contains("." + bin.mimeType)
"Documents" -> mDocumentStr.contains("." + bin.mimeType)
else -> true
}
}
private fun initData(callBack: (() -> Unit)? = null) { private fun initData(callBack: (() -> Unit)? = null) {
LogEx.logDebug(TAG, "initData") LogEx.logDebug(TAG, "initData")
lifecycleScope.launch(Dispatchers.IO) { lifecycleScope.launch(Dispatchers.IO) {
val beanList = BackUpUtils.getBackUpListObj() val beanList = BackUpUtils.getBackUpListObj()
val deleteFile: List<RecycleBinBean>? = beanList?.filter { it.deleted } val deleteFile: List<RecycleBinBean>? = beanList?.filter { it.deleted && filterAction(it) }
// val deleteFile: List<RecycleBinBean>? = beanList // val deleteFile: List<RecycleBinBean>? = beanList
LogEx.logDebug(TAG, "deleteFile=$deleteFile") LogEx.logDebug(TAG, "deleteFile=$deleteFile")
deleteFile?.forEach { deleteFile?.forEach {
......
...@@ -34,10 +34,12 @@ import com.base.filerecoveryrecyclebin.databinding.DialogLargeFileTypeBinding ...@@ -34,10 +34,12 @@ import com.base.filerecoveryrecyclebin.databinding.DialogLargeFileTypeBinding
import com.base.filerecoveryrecyclebin.databinding.DialogPermissonOpenBinding import com.base.filerecoveryrecyclebin.databinding.DialogPermissonOpenBinding
import com.base.filerecoveryrecyclebin.databinding.DialogRecoveringBinding import com.base.filerecoveryrecyclebin.databinding.DialogRecoveringBinding
import com.base.filerecoveryrecyclebin.databinding.DialogRecyclebinFileRestoreBinding import com.base.filerecoveryrecyclebin.databinding.DialogRecyclebinFileRestoreBinding
import com.base.filerecoveryrecyclebin.databinding.DialogRecyclebinFilterBinding
import com.base.filerecoveryrecyclebin.databinding.DialogRemoveFileTipBinding import com.base.filerecoveryrecyclebin.databinding.DialogRemoveFileTipBinding
import com.base.filerecoveryrecyclebin.help.KotlinExt.toFormatSize import com.base.filerecoveryrecyclebin.help.KotlinExt.toFormatSize
import com.base.filerecoveryrecyclebin.help.KotlinExt.toFormatTime import com.base.filerecoveryrecyclebin.help.KotlinExt.toFormatTime
import com.base.filerecoveryrecyclebin.utils.LogEx import com.base.filerecoveryrecyclebin.utils.LogEx
import com.base.filerecoveryrecyclebin.view.DialogViews.showLargeFileTypeDialog
import com.base.filerecoveryrecyclebin.view.DialogViews.showRecycleBinDetailDialog import com.base.filerecoveryrecyclebin.view.DialogViews.showRecycleBinDetailDialog
import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.bottomsheet.BottomSheetDialog
...@@ -404,5 +406,84 @@ object DialogViews { ...@@ -404,5 +406,84 @@ object DialogViews {
} }
} }
fun Context.showRecycleBinFilter(
lifecycleScope: LifecycleCoroutineScope,
filter: String?,
filterAction: (filter: String) -> Unit
) {
val binding = DialogRecyclebinFilterBinding.inflate(LayoutInflater.from(this))
val dialog = AlertDialog.Builder(this).create()
dialog.setView(binding.root)
dialog.show()
dialog.window?.setBackgroundDrawableResource(android.R.color.transparent)
val lp: WindowManager.LayoutParams? = dialog.window?.attributes
lp?.gravity = Gravity.TOP or Gravity.END
lp?.x = 30
lp?.width = this.resources.getDimensionPixelOffset(R.dimen.dp_205)
dialog.window?.setAttributes(lp)
when (filter) {
"Photos" -> {
binding.ivPhotos.visibility = View.VISIBLE
}
"Videos" -> {
binding.ivVideos.visibility = View.VISIBLE
}
"Audios" -> {
binding.ivAudios.visibility = View.VISIBLE
}
"Documents" -> {
binding.ivDocuments.visibility = View.VISIBLE
}
}
val action = {
binding.ivPhotos.visibility = View.INVISIBLE
binding.ivVideos.visibility = View.INVISIBLE
binding.ivAudios.visibility = View.INVISIBLE
binding.ivDocuments.visibility = View.INVISIBLE
}
binding.flPhotos.setOnClickListener {
action.invoke()
binding.ivPhotos.visibility = View.VISIBLE
lifecycleScope.launch {
delay(250)
dialog.dismiss()
filterAction.invoke("Photos")
}
}
binding.flVideos.setOnClickListener {
action.invoke()
binding.ivVideos.visibility = View.VISIBLE
lifecycleScope.launch {
delay(250)
dialog.dismiss()
filterAction.invoke("Videos")
}
}
binding.flAudios.setOnClickListener {
action.invoke()
binding.ivAudios.visibility = View.VISIBLE
lifecycleScope.launch {
delay(250)
dialog.dismiss()
filterAction.invoke("Audios")
}
}
binding.flDocuments.setOnClickListener {
action.invoke()
binding.ivDocuments.visibility = View.VISIBLE
lifecycleScope.launch {
delay(250)
dialog.dismiss()
filterAction.invoke("Documents")
}
}
}
} }
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="top|end"
android:layout_margin="5dp"
app:cardBackgroundColor="@color/white"
app:cardCornerRadius="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingVertical="5dp">
<FrameLayout
android:id="@+id/fl_photos"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:paddingVertical="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="20dp"
android:text="Photos"
android:textColor="#333333"
android:textSize="16sp"
tools:ignore="HardcodedText" />
<ImageView
android:id="@+id/iv_photos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|end"
android:layout_marginEnd="15dp"
android:src="@mipmap/xuan_bin_filter"
android:visibility="invisible"
tools:ignore="ContentDescription" />
</FrameLayout>
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="#EEEEEE" />
<FrameLayout
android:id="@+id/fl_videos"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:paddingVertical="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="20dp"
android:text="Videos"
android:textColor="#333333"
android:textSize="16sp"
tools:ignore="HardcodedText" />
<ImageView
android:id="@+id/iv_videos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|end"
android:layout_marginEnd="15dp"
android:src="@mipmap/xuan_bin_filter"
android:visibility="invisible"
tools:ignore="ContentDescription" />
</FrameLayout>
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="#EEEEEE" />
<FrameLayout
android:id="@+id/fl_audios"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:paddingVertical="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="20dp"
android:text="Audios"
android:textColor="#333333"
android:textSize="16sp"
tools:ignore="HardcodedText" />
<ImageView
android:id="@+id/iv_audios"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|end"
android:layout_marginEnd="15dp"
android:src="@mipmap/xuan_bin_filter"
android:visibility="invisible"
tools:ignore="ContentDescription" />
</FrameLayout>
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="#EEEEEE" />
<FrameLayout
android:id="@+id/fl_documents"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:paddingVertical="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="20dp"
android:text="Documents"
android:textColor="#333333"
android:textSize="16sp"
tools:ignore="HardcodedText" />
<ImageView
android:id="@+id/iv_documents"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|end"
android:layout_marginEnd="15dp"
android:src="@mipmap/xuan_bin_filter"
android:visibility="invisible"
tools:ignore="ContentDescription" />
</FrameLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
\ No newline at end of file
...@@ -31,8 +31,7 @@ ...@@ -31,8 +31,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical|end" android:layout_gravity="center_vertical|end"
android:padding="18dp" android:padding="18dp">
android:visibility="invisible">
<ImageView <ImageView
android:layout_width="wrap_content" android:layout_width="wrap_content"
......
...@@ -7,4 +7,5 @@ ...@@ -7,4 +7,5 @@
<dimen name="dp_355">355dp</dimen> <dimen name="dp_355">355dp</dimen>
<dimen name="dp_35">35dp</dimen> <dimen name="dp_35">35dp</dimen>
<dimen name="dp_9">9dp</dimen> <dimen name="dp_9">9dp</dimen>
<dimen name="dp_205">205dp</dimen>
</resources> </resources>
\ 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