From e319bb1623adc36b8b21716e1390d99fb0748fb7 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 7 Dec 2016 19:16:50 +0100 Subject: [PATCH] update mediastore after a rename manually, so its instant --- .../gallery/dialogs/RenameFileDialog.kt | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/RenameFileDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/RenameFileDialog.kt index 92e7a99c7..d197771bb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/RenameFileDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/RenameFileDialog.kt @@ -1,6 +1,8 @@ package com.simplemobiletools.gallery.dialogs import android.app.AlertDialog +import android.content.ContentValues +import android.provider.MediaStore import android.view.LayoutInflater import android.view.WindowManager import com.simplemobiletools.filepicker.extensions.* @@ -75,10 +77,19 @@ class RenameFileDialog(val activity: SimpleActivity, val file: File, val callbac } } - private fun sendSuccess(currFile: File, newFile: File) { - val changedFiles = arrayListOf(currFile, newFile) - activity.scanFiles(changedFiles) { + private fun sendSuccess(oldFile: File, newFile: File) { + val values = ContentValues() + values.put(MediaStore.MediaColumns.DATA, newFile.absolutePath) + val updated = activity.contentResolver.update(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values, + "${MediaStore.MediaColumns.DATA} = '${oldFile.absolutePath}'", null) == 1 + + if (updated) { callback.invoke(newFile) + } else { + val changedFiles = arrayListOf(oldFile, newFile) + activity.scanFiles(changedFiles) { + callback.invoke(newFile) + } } } }