diff --git a/app/src/main/java/com/simplemobiletools/gallery/Utils.kt b/app/src/main/java/com/simplemobiletools/gallery/Utils.kt index 3ee8b00fa..453797c7f 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/Utils.kt +++ b/app/src/main/java/com/simplemobiletools/gallery/Utils.kt @@ -1,6 +1,5 @@ package com.simplemobiletools.gallery -import android.annotation.TargetApi import android.app.Activity import android.content.Context import android.content.Intent @@ -136,15 +135,6 @@ class Utils { fun getFileDocument(context: Context, path: String, treeUri: String) = context.getFileDocument(path, treeUri) - @TargetApi(Build.VERSION_CODES.KITKAT) - fun saveTreeUri(context: Context, resultData: Intent) { - val treeUri = resultData.data - Config.newInstance(context).treeUri = treeUri.toString() - - val takeFlags = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION - context.contentResolver.takePersistableUriPermission(treeUri, takeFlags) - } - fun scanFiles(context: Context, paths: Array) = context.rescanFiles(paths) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SimpleActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SimpleActivity.kt index b97720dd6..543d6fc8e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SimpleActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SimpleActivity.kt @@ -1,7 +1,9 @@ package com.simplemobiletools.gallery.activities +import android.annotation.TargetApi import android.app.Activity import android.content.Intent +import android.os.Build import android.os.Bundle import android.support.v7.app.AppCompatActivity import android.view.MenuItem @@ -9,7 +11,6 @@ import com.simplemobiletools.filepicker.extensions.isShowingWritePermissions import com.simplemobiletools.gallery.Config import com.simplemobiletools.gallery.Constants import com.simplemobiletools.gallery.R -import com.simplemobiletools.gallery.Utils import java.io.File open class SimpleActivity : AppCompatActivity() { @@ -38,9 +39,18 @@ open class SimpleActivity : AppCompatActivity() { override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) { super.onActivityResult(requestCode, resultCode, resultData) if (requestCode == Constants.OPEN_DOCUMENT_TREE && resultCode == Activity.RESULT_OK && resultData != null) { - Utils.saveTreeUri(this, resultData) + saveTreeUri(resultData) } } + @TargetApi(Build.VERSION_CODES.KITKAT) + fun saveTreeUri(resultData: Intent) { + val treeUri = resultData.data + mConfig.treeUri = treeUri.toString() + + val takeFlags = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION + contentResolver.takePersistableUriPermission(treeUri, takeFlags) + } + fun isShowingPermDialog(file: File) = isShowingWritePermissions(file, mConfig.treeUri, Constants.OPEN_DOCUMENT_TREE) } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt index 07c6f0eba..345bfef0f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt @@ -1,9 +1,9 @@ package com.simplemobiletools.gallery.asynctasks import android.content.Context -import android.media.MediaScannerConnection import android.os.AsyncTask import android.provider.MediaStore +import com.simplemobiletools.filepicker.extensions.rescanFiles import com.simplemobiletools.gallery.Config import com.simplemobiletools.gallery.Constants import com.simplemobiletools.gallery.R @@ -80,7 +80,7 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va Collections.sort(dirs) val invalids = invalidFiles.toTypedArray() - MediaScannerConnection.scanFile(context, invalids, null, null) + context.rescanFiles(invalids) return dirs } 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 a11553470..424359521 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,5 @@ package com.simplemobiletools.gallery.dialogs -import android.media.MediaScannerConnection import android.support.v7.app.AlertDialog import android.view.LayoutInflater import android.view.WindowManager @@ -69,7 +68,7 @@ class RenameFileDialog(val activity: SimpleActivity, val file: File, val listene private fun sendSuccess(currFile: File, newFile: File) { val changedFiles = arrayOf(currFile.absolutePath, newFile.absolutePath) - MediaScannerConnection.scanFile(activity.applicationContext, changedFiles, null, null) + activity.rescanFiles(changedFiles) listener.onRenameFileSuccess(newFile) }