Commit 60d400a9 authored by wanglei's avatar wanglei

....回收站Glide加载失败

parent 0fb9fa34
...@@ -12,6 +12,7 @@ import com.base.filerecoveryrecyclebin.utils.LogEx ...@@ -12,6 +12,7 @@ import com.base.filerecoveryrecyclebin.utils.LogEx
import com.google.gson.Gson import com.google.gson.Gson
import java.io.File import java.io.File
@RequiresApi(Build.VERSION_CODES.Q)
class MyFileObserver(files: List<File>) : FileObserver(files, ALL_EVENTS) { class MyFileObserver(files: List<File>) : FileObserver(files, ALL_EVENTS) {
private val TAG = "MyFileObserver" private val TAG = "MyFileObserver"
......
package com.base.filerecoveryrecyclebin.adapter package com.base.filerecoveryrecyclebin.adapter
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.graphics.drawable.Drawable
import android.os.Build import android.os.Build
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
...@@ -13,12 +14,19 @@ import com.base.filerecoveryrecyclebin.bean.RecycleBinBean ...@@ -13,12 +14,19 @@ import com.base.filerecoveryrecyclebin.bean.RecycleBinBean
import com.base.filerecoveryrecyclebin.databinding.ItemRecyclebinFileBinding import com.base.filerecoveryrecyclebin.databinding.ItemRecyclebinFileBinding
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.view.XmlEx.inflate import com.base.filerecoveryrecyclebin.view.XmlEx.inflate
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import com.bumptech.glide.load.DataSource
import com.bumptech.glide.load.engine.GlideException
import com.bumptech.glide.request.RequestListener
import com.bumptech.glide.request.target.Target
import java.io.File import java.io.File
class RecycleBinAdapter(val click: (bean: RecycleBinBean) -> Unit) : RecyclerView.Adapter<RecycleBinAdapter.RBAV>() { class RecycleBinAdapter(val click: (bean: RecycleBinBean) -> Unit) : RecyclerView.Adapter<RecycleBinAdapter.RBAV>() {
private val TAG = "RecycleBinAdapter"
private val beanList = arrayListOf<RecycleBinBean>() private val beanList = arrayListOf<RecycleBinBean>()
...@@ -34,7 +42,6 @@ class RecycleBinAdapter(val click: (bean: RecycleBinBean) -> Unit) : RecyclerVie ...@@ -34,7 +42,6 @@ class RecycleBinAdapter(val click: (bean: RecycleBinBean) -> Unit) : RecyclerVie
return beanList.size return beanList.size
} }
@RequiresApi(Build.VERSION_CODES.Q)
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
override fun onBindViewHolder(holder: RBAV, position: Int) { override fun onBindViewHolder(holder: RBAV, position: Int) {
val binding = ItemRecyclebinFileBinding.bind(holder.itemView) val binding = ItemRecyclebinFileBinding.bind(holder.itemView)
...@@ -42,7 +49,23 @@ class RecycleBinAdapter(val click: (bean: RecycleBinBean) -> Unit) : RecyclerVie ...@@ -42,7 +49,23 @@ class RecycleBinAdapter(val click: (bean: RecycleBinBean) -> Unit) : RecyclerVie
val file = File(bean.path) val file = File(bean.path)
val binFile = findRecycleBinFile(file.name) val binFile = findRecycleBinFile(file.name)
val context = holder.itemView.context val context = holder.itemView.context
Glide.with(context).load(binFile?.absoluteFile).centerCrop().into(binding.iv) Glide.with(context).load(binFile?.absoluteFile).listener(object : RequestListener<Drawable> {
override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Drawable>, isFirstResource: Boolean): Boolean {
LogEx.logDebug(TAG, "Failed to load image: $model")
return false
}
override fun onResourceReady(
resource: Drawable,
model: Any,
target: Target<Drawable>?,
dataSource: DataSource,
isFirstResource: Boolean
): Boolean {
return false
}
}).centerCrop().into(binding.iv)
binding.tvName.text = file.name binding.tvName.text = file.name
binding.tvTime.text = "delete time:" + bean.deleteTime.toFormatTime() binding.tvTime.text = "delete time:" + bean.deleteTime.toFormatTime()
binding.tvSize.text = bean.size.toFormatSize() binding.tvSize.text = bean.size.toFormatSize()
......
...@@ -76,7 +76,6 @@ class RecycleBinFragment : BaseFragment<FragmentRecycleBinBinding>() { ...@@ -76,7 +76,6 @@ class RecycleBinFragment : BaseFragment<FragmentRecycleBinBinding>() {
} }
} }
@RequiresApi(Build.VERSION_CODES.Q)
private fun initData() { private fun initData() {
lifecycleScope.launch(Dispatchers.IO) { lifecycleScope.launch(Dispatchers.IO) {
......
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
<androidx.cardview.widget.CardView <androidx.cardview.widget.CardView
android:id="@+id/card" android:id="@+id/card"
android:layout_width="50dp" android:layout_width="55dp"
android:layout_height="50dp" android:layout_height="55dp"
app:cardCornerRadius="8dp" app:cardCornerRadius="8dp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
android:id="@+id/iv" android:id="@+id/iv"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_margin="5dp"
tools:ignore="ContentDescription" /> tools:ignore="ContentDescription" />
</androidx.cardview.widget.CardView> </androidx.cardview.widget.CardView>
......
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