fix memory leaks at media scanning + some rename improvements
This commit is contained in:
parent
fadf2c6859
commit
44303fe0dc
3 changed files with 23 additions and 9 deletions
|
@ -6,7 +6,7 @@ buildscript {
|
|||
propMinSdkVersion = 16
|
||||
propTargetSdkVersion = propCompileSdkVersion
|
||||
propVersionCode = 1
|
||||
propVersionName = '3.16.2'
|
||||
propVersionName = '3.16.9'
|
||||
kotlin_version = '1.2.30'
|
||||
support_libs = '27.1.0'
|
||||
}
|
||||
|
|
|
@ -67,9 +67,7 @@ class RenameItemDialog(val activity: BaseSimpleActivity, val path: String, val c
|
|||
updatedPaths.add(newPath)
|
||||
activity.renameFile(path, newPath) {
|
||||
if (it) {
|
||||
activity.scanPaths(updatedPaths) {
|
||||
callback(newPath)
|
||||
}
|
||||
callback(newPath)
|
||||
dismiss()
|
||||
} else {
|
||||
activity.toast(R.string.unknown_error_occurred)
|
||||
|
|
|
@ -230,11 +230,27 @@ fun Context.scanPaths(paths: ArrayList<String>, callback: (() -> Unit)? = null)
|
|||
|
||||
fun Context.rescanPaths(paths: ArrayList<String>, callback: (() -> Unit)? = null) {
|
||||
var cnt = paths.size
|
||||
MediaScannerConnection.scanFile(applicationContext, paths.toTypedArray(), null, { s, uri ->
|
||||
if (--cnt == 0) {
|
||||
callback?.invoke()
|
||||
var connection: MediaScannerConnection? = null
|
||||
|
||||
val connectionClient = object : MediaScannerConnection.MediaScannerConnectionClient {
|
||||
override fun onMediaScannerConnected() {
|
||||
paths.forEach {
|
||||
if (connection?.isConnected == true) {
|
||||
connection?.scanFile(it, "")
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
override fun onScanCompleted(path: String?, uri: Uri?) {
|
||||
if (--cnt == 0) {
|
||||
connection?.disconnect()
|
||||
callback?.invoke()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
connection = MediaScannerConnection(this, connectionClient)
|
||||
connection.connect()
|
||||
}
|
||||
|
||||
fun getPaths(file: File): ArrayList<String> {
|
||||
|
@ -289,7 +305,7 @@ fun Context.updateInMediaStore(oldPath: String, newPath: String) {
|
|||
|
||||
fun Context.updateLastModified(path: String, lastModified: Long) {
|
||||
val values = ContentValues().apply {
|
||||
put(MediaStore.MediaColumns.DATE_MODIFIED, lastModified)
|
||||
put(MediaStore.MediaColumns.DATE_MODIFIED, lastModified / 1000)
|
||||
}
|
||||
File(path).setLastModified(lastModified)
|
||||
val uri = getFileUri(path)
|
||||
|
|
Loading…
Reference in a new issue