Commit 7602108d authored by wanglei's avatar wanglei

Merge remote-tracking branch 'origin/master'

parents b3324d55 0ff270d3
...@@ -16,7 +16,7 @@ import java.io.File ...@@ -16,7 +16,7 @@ import java.io.File
/** /**
* Observer MediaContent add * Observer MediaContent add
*/ */
class MediaContentObserver(val context: Context, val handler: Handler? = null) : ContentObserver(null) { class MediaContentObserver(val context: Context) : ContentObserver(null) {
private val TAG = "MediaContentObserver" private val TAG = "MediaContentObserver"
...@@ -84,7 +84,6 @@ class MediaContentObserver(val context: Context, val handler: Handler? = null) : ...@@ -84,7 +84,6 @@ class MediaContentObserver(val context: Context, val handler: Handler? = null) :
binFile.createNewFile() binFile.createNewFile()
binFile.writeText(Gson().toJson(binBean)) binFile.writeText(Gson().toJson(binBean))
LogEx.logDebug(TAG, "RecycleBin backup") LogEx.logDebug(TAG, "RecycleBin backup")
handler?.sendEmptyMessage(99)
} }
} }
} }
...@@ -13,7 +13,7 @@ import com.google.gson.Gson ...@@ -13,7 +13,7 @@ import com.google.gson.Gson
import java.io.File import java.io.File
@RequiresApi(Build.VERSION_CODES.Q) @RequiresApi(Build.VERSION_CODES.Q)
class MyFileObserver(val handler: Handler? = null, files: List<File>) : FileObserver(files, ALL_EVENTS) { class MyFileObserver(files: List<File>) : FileObserver(files, ALL_EVENTS) {
private val TAG = "MyFileObserver" private val TAG = "MyFileObserver"
...@@ -75,7 +75,6 @@ class MyFileObserver(val handler: Handler? = null, files: List<File>) : FileObse ...@@ -75,7 +75,6 @@ class MyFileObserver(val handler: Handler? = null, files: List<File>) : FileObse
val wJson = Gson().toJson(bean) val wJson = Gson().toJson(bean)
recycleBinJsonFile.writeText(wJson) recycleBinJsonFile.writeText(wJson)
LogEx.logDebug(TAG, "writeText wJson=$wJson") LogEx.logDebug(TAG, "writeText wJson=$wJson")
handler?.sendEmptyMessage(100)
} }
} }
......
...@@ -111,7 +111,9 @@ class RecycleBinFragment : BaseFragment<FragmentRecycleBinBinding>() { ...@@ -111,7 +111,9 @@ class RecycleBinFragment : BaseFragment<FragmentRecycleBinBinding>() {
super.onResume() super.onResume()
LogEx.logDebug(TAG, "onResume") LogEx.logDebug(TAG, "onResume")
if (requireContext().checkStorePermission()) { if (requireContext().checkStorePermission()) {
initData() if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
initData()
}
} }
} }
......
...@@ -46,7 +46,6 @@ class StayNotificationService : Service() { ...@@ -46,7 +46,6 @@ class StayNotificationService : Service() {
const val FILE_OBSERVER_ACTION = "file_observer_action" const val FILE_OBSERVER_ACTION = "file_observer_action"
var isRunning = false var isRunning = false
var mainHandler: Handler? = null
fun Context.startStayNotification() { fun Context.startStayNotification() {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.TIRAMISU) { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.TIRAMISU) {
...@@ -88,7 +87,7 @@ class StayNotificationService : Service() { ...@@ -88,7 +87,7 @@ class StayNotificationService : Service() {
private fun observerMediaContentObserver() { private fun observerMediaContentObserver() {
if (mediaContentObserver == null) { if (mediaContentObserver == null) {
LogEx.logDebug(TAG, "observerMediaContentObserver") LogEx.logDebug(TAG, "observerMediaContentObserver")
mediaContentObserver = MediaContentObserver(this, mainHandler) mediaContentObserver = MediaContentObserver(this)
mediaContentObserver?.let { mediaContentObserver?.let {
this.contentResolver.registerContentObserver( this.contentResolver.registerContentObserver(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, true, it MediaStore.Images.Media.EXTERNAL_CONTENT_URI, true, it
...@@ -122,7 +121,7 @@ class StayNotificationService : Service() { ...@@ -122,7 +121,7 @@ class StayNotificationService : Service() {
watchList.forEach { watchList.forEach {
LogEx.logDebug(TAG, "watchList=${it.absolutePath}") LogEx.logDebug(TAG, "watchList=${it.absolutePath}")
} }
myFileObserver = MyFileObserver(handler = mainHandler, watchList) myFileObserver = MyFileObserver(watchList)
LogEx.logDebug(TAG, "watchList=${dcimList.size}") LogEx.logDebug(TAG, "watchList=${dcimList.size}")
myFileObserver?.startWatching() myFileObserver?.startWatching()
} }
......
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