mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 06:09:50 -06:00
Implement Refresh on DocumentProvider
"When interacting with DocumentUI or the built-in Android System Internal Files Manager app and performing Create, Rename, and Delete operations, DocumentsUI will not automatically refresh the changes. Previously, users had to manually pull down from the top to refresh the changes. This commit aims to fix this issue by automatically notifying the system that changes have occurred and triggering a requery."
This commit is contained in:
@ -9,8 +9,10 @@
|
|||||||
package org.dolphinemu.dolphinemu.features
|
package org.dolphinemu.dolphinemu.features
|
||||||
|
|
||||||
import android.annotation.TargetApi
|
import android.annotation.TargetApi
|
||||||
|
import android.content.Context
|
||||||
import android.database.Cursor
|
import android.database.Cursor
|
||||||
import android.database.MatrixCursor
|
import android.database.MatrixCursor
|
||||||
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.CancellationSignal
|
import android.os.CancellationSignal
|
||||||
import android.os.ParcelFileDescriptor
|
import android.os.ParcelFileDescriptor
|
||||||
@ -93,6 +95,8 @@ class DocumentProvider : DocumentsProvider() {
|
|||||||
appendDocument(file, result)
|
appendDocument(file, result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
result.setNotificationUri(context!!.contentResolver, DocumentsContract.buildChildDocumentsUri(
|
||||||
|
"${context!!.packageName}.user", parentDocumentId))
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,6 +125,7 @@ class DocumentProvider : DocumentsProvider() {
|
|||||||
} else {
|
} else {
|
||||||
file.createNewFile()
|
file.createNewFile()
|
||||||
}
|
}
|
||||||
|
refreshDocument(parentDocumentId)
|
||||||
return pathToDocumentId(file)
|
return pathToDocumentId(file)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,7 +133,9 @@ class DocumentProvider : DocumentsProvider() {
|
|||||||
rootDirectory ?: return
|
rootDirectory ?: return
|
||||||
|
|
||||||
val file = documentIdToPath(documentId)
|
val file = documentIdToPath(documentId)
|
||||||
|
val fileParent = file.parentFile
|
||||||
file.deleteRecursively()
|
file.deleteRecursively()
|
||||||
|
refreshDocument(pathToDocumentId(fileParent!!))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun renameDocument(documentId: String, displayName: String): String? {
|
override fun renameDocument(documentId: String, displayName: String): String? {
|
||||||
@ -137,9 +144,19 @@ class DocumentProvider : DocumentsProvider() {
|
|||||||
val file = documentIdToPath(documentId)
|
val file = documentIdToPath(documentId)
|
||||||
val dest = findFileNameForNewFile(File(file.parentFile, displayName))
|
val dest = findFileNameForNewFile(File(file.parentFile, displayName))
|
||||||
file.renameTo(dest)
|
file.renameTo(dest)
|
||||||
|
refreshDocument(pathToDocumentId(file.parentFile!!))
|
||||||
return pathToDocumentId(dest)
|
return pathToDocumentId(dest)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun refreshDocument(parentDocumentId: String) {
|
||||||
|
val parentUri: Uri =
|
||||||
|
DocumentsContract.buildChildDocumentsUri(
|
||||||
|
"${context!!.packageName}.user",
|
||||||
|
parentDocumentId
|
||||||
|
)
|
||||||
|
context!!.contentResolver.notifyChange(parentUri, null)
|
||||||
|
}
|
||||||
|
|
||||||
override fun isChildDocument(parentDocumentId: String, documentId: String): Boolean
|
override fun isChildDocument(parentDocumentId: String, documentId: String): Boolean
|
||||||
= documentId.startsWith(parentDocumentId)
|
= documentId.startsWith(parentDocumentId)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user