Commit fbf33e18 authored by wanglei's avatar wanglei

...

parent cc2dbc40
......@@ -195,7 +195,9 @@
<receiver
android:name=".fcm.CloseNotificationReceiver"
android:exported="false" /> <!-- 添加以下接收器 -->
android:exported="false" />
<!-- 添加以下接收器 -->
<!-- 注册广播 -->
<receiver
android:name=".fcm.FcmReceiver"
......
......@@ -2,6 +2,7 @@ package com.base.filerecoveryrecyclebin.activity
import android.graphics.Color
import android.graphics.Typeface
import androidx.core.view.updatePadding
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import androidx.viewpager2.adapter.FragmentStateAdapter
......@@ -40,7 +41,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
override fun initView() {
BarUtils.setStatusBarLightMode(this, true)
BarUtils.setStatusBarColor(this, Color.TRANSPARENT)
// binding.root.updatePadding(top = BarUtils.getStatusBarHeight())
binding.root.updatePadding(top = BarUtils.getStatusBarHeight())
// showRateStarPopDialog()
// showExitFunctionDialog()
......
......@@ -20,6 +20,7 @@ class MediaContentObserver(val context: Context, val handler: Handler? = null) :
override fun onChange(selfChange: Boolean, uri: Uri?) {
super.onChange(selfChange, uri)
LogEx.logDebug(TAG, "uri=${uri.toString()}")
uri?.let { queryNewMediaFiles(it) }
}
......@@ -30,6 +31,7 @@ class MediaContentObserver(val context: Context, val handler: Handler? = null) :
MediaStore.MediaColumns.DISPLAY_NAME,
MediaStore.MediaColumns.DATA,
MediaStore.MediaColumns.MIME_TYPE,
MediaStore.MediaColumns.SIZE,
)
val cursor: Cursor? = context.contentResolver.query(uri, projection, null, null, null)
......@@ -39,6 +41,7 @@ class MediaContentObserver(val context: Context, val handler: Handler? = null) :
val name = cursor.getString(cursor.getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME))
val path = cursor.getString(cursor.getColumnIndex(MediaStore.MediaColumns.DATA))
val mimeType = cursor.getString(cursor.getColumnIndex(MediaStore.MediaColumns.MIME_TYPE))
val size = cursor.getString(cursor.getColumnIndex(MediaStore.MediaColumns.SIZE))
// 处理新文件路径
backupRecycleBinFile(name, path, mimeType)
}
......@@ -52,7 +55,9 @@ class MediaContentObserver(val context: Context, val handler: Handler? = null) :
}
private fun backupRecycleBinFile(name: String, path: String, mimeType: String) {
LogEx.logDebug(TAG, "name=$name path=$path mimeType=$mimeType")
val src = File(path)
LogEx.logDebug(TAG, "name=$name path=$path mimeType=$mimeType size=${src.length()}")
val file = context.filesDir
val recycleBinDir = File(file, "RecycleBin")
......@@ -60,16 +65,21 @@ class MediaContentObserver(val context: Context, val handler: Handler? = null) :
recycleBinDir.mkdirs()
}
val src = File(path)
val recycleBinFile = File(recycleBinDir, ".$name")
if (!recycleBinFile.exists()) {
src.copyTo(recycleBinFile, true)
val binBean = RecycleBinBean(src.path, 0, src.length(), mimeType)
val binFile = File(recycleBinDir, ".$name.bin")
binFile.createNewFile()
binFile.writeText(Gson().toJson(binBean))
LogEx.logDebug(TAG, "回收站备份成功")
handler?.sendEmptyMessage(99)
recycleBinFile.createNewFile()
} else {
if (recycleBinFile.length()==0L){
src.copyTo(recycleBinFile, true)
LogEx.logDebug(TAG, "size=${src.length()}")
val binBean = RecycleBinBean(src.path, 0, src.length(), mimeType)
val binFile = File(recycleBinDir, ".$name.bin")
binFile.createNewFile()
binFile.writeText(Gson().toJson(binBean))
LogEx.logDebug(TAG, "回收站备份成功")
handler?.sendEmptyMessage(99)
}
}
}
......
......@@ -7,9 +7,8 @@ import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.base.filerecoveryrecyclebin.R
import com.base.filerecoveryrecyclebin.bean.RecycleBinBean
import com.base.filerecoveryrecyclebin.databinding.ItemMediaFileBinding
import com.base.filerecoveryrecyclebin.databinding.ItemRecycleBinBeanBinding
import com.base.filerecoveryrecyclebin.databinding.ItemRecyclebinFileBinding
import com.base.filerecoveryrecyclebin.help.KotlinExt.toFormatSize
import com.base.filerecoveryrecyclebin.help.KotlinExt.toFormatTime
import com.base.filerecoveryrecyclebin.view.XmlEx.inflate
import com.bumptech.glide.Glide
......@@ -40,8 +39,8 @@ class RecycleBinAdapter : RecyclerView.Adapter<RecycleBinAdapter.RBAV>() {
val context = holder.itemView.context
Glide.with(context).load(bean.path).centerCrop().into(binding.iv)
binding.tvName.text = file.name
binding.tvTime.text = "delete time:" + bean.deleteTime.toString()
binding.tvSize.text = bean.size.toFormatTime()
binding.tvTime.text = "delete time:" + bean.deleteTime.toFormatTime()
binding.tvSize.text = bean.size.toFormatSize()
}
@SuppressLint("NotifyDataSetChanged")
......
......@@ -18,6 +18,7 @@ import com.base.filerecoveryrecyclebin.utils.LogEx
import com.base.filerecoveryrecyclebin.view.DialogViews.showGerPermission
import com.google.gson.Gson
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import java.io.File
......@@ -36,9 +37,11 @@ class RecycleBinFragment : BaseFragment<FragmentRecycleBinBinding>() {
handler = Handler(requireActivity().mainLooper) { message ->
if (message.what == 99) {
// LogEx.logDebug(TAG, "媒体库更新了")
initData()
}
if (message.what == 100) {
// LogEx.logDebug(TAG, "回收站数据更新了")
initData()
}
true
}
......@@ -68,6 +71,21 @@ class RecycleBinFragment : BaseFragment<FragmentRecycleBinBinding>() {
}
}
override fun setListener() {
super.setListener()
binding.flGengduo.setOnClickListener {
}
binding.swipeRefreshLayout.setOnRefreshListener {
binding.swipeRefreshLayout.isRefreshing = true
initData()
lifecycleScope.launch(Dispatchers.Main) {
delay(1000)
binding.swipeRefreshLayout.isRefreshing = false
}
}
}
private fun initData() {
lifecycleScope.launch(Dispatchers.IO) {
val file = requireActivity().filesDir
......@@ -78,12 +96,15 @@ class RecycleBinFragment : BaseFragment<FragmentRecycleBinBinding>() {
val binList = recycleBinDir.listFiles()?.filter { it.name.contains(".bin") }
val beanList = arrayListOf<RecycleBinBean>()
binList?.forEach {
LogEx.logDebug(TAG, it.absolutePath)
val bean = Gson().fromJson(it.readText(), RecycleBinBean::class.java)
beanList.add(bean)
}
val deleteFile = beanList.filter { it.deleted }
// val deleteFile = beanList
launch(Dispatchers.Main) {
binding.rv.isVisible = !binList.isNullOrEmpty()
binding.llEmpty.isVisible = binList.isNullOrEmpty()
binding.rv.isVisible = deleteFile.isNotEmpty()
binding.llEmpty.isVisible = deleteFile.isEmpty()
recycleBinAdapter.setData(beanList)
}
......
......@@ -111,7 +111,6 @@ class StayNotificationService : Service() {
if (myFileObserver == null) {
val dcimList = FileHelp.getFileFolder(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM))
val watchList = arrayListOf<File>()
watchList.addAll(dcimList)
watchList.forEach {
......
......@@ -8,11 +8,6 @@
android:orientation="vertical"
tools:context=".fragment.HomeFragment">
<View
android:layout_width="match_parent"
android:layout_height="40dp"
app:layout_constraintTop_toTopOf="parent" />
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
......
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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="match_parent"
android:layout_height="match_parent"
......@@ -7,13 +8,53 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv"
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:listitem="@layout/item_media_file" />
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="18dp"
android:text="RecycleBin"
android:textColor="@color/black"
android:textSize="19sp"
android:textStyle="bold"
tools:ignore="HardcodedText" />
<FrameLayout
android:id="@+id/fl_gengduo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|end"
android:padding="18dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/gengduo"
tools:ignore="ContentDescription" />
</FrameLayout>
</FrameLayout>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/item_media_file" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</LinearLayout>
......
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