using a few more extension functions

This commit is contained in:
tibbi 2016-11-12 12:16:50 +01:00
parent c4edf3c28e
commit 75beef4da6
4 changed files with 15 additions and 16 deletions

View file

@ -1,6 +1,5 @@
package com.simplemobiletools.gallery package com.simplemobiletools.gallery
import android.annotation.TargetApi
import android.app.Activity import android.app.Activity
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
@ -136,15 +135,6 @@ class Utils {
fun getFileDocument(context: Context, path: String, treeUri: String) = context.getFileDocument(path, treeUri) 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<String>) = context.rescanFiles(paths) fun scanFiles(context: Context, paths: Array<String>) = context.rescanFiles(paths)
} }
} }

View file

@ -1,7 +1,9 @@
package com.simplemobiletools.gallery.activities package com.simplemobiletools.gallery.activities
import android.annotation.TargetApi
import android.app.Activity import android.app.Activity
import android.content.Intent import android.content.Intent
import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.support.v7.app.AppCompatActivity import android.support.v7.app.AppCompatActivity
import android.view.MenuItem import android.view.MenuItem
@ -9,7 +11,6 @@ import com.simplemobiletools.filepicker.extensions.isShowingWritePermissions
import com.simplemobiletools.gallery.Config import com.simplemobiletools.gallery.Config
import com.simplemobiletools.gallery.Constants import com.simplemobiletools.gallery.Constants
import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.Utils
import java.io.File import java.io.File
open class SimpleActivity : AppCompatActivity() { open class SimpleActivity : AppCompatActivity() {
@ -38,9 +39,18 @@ open class SimpleActivity : AppCompatActivity() {
override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) { override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
super.onActivityResult(requestCode, resultCode, resultData) super.onActivityResult(requestCode, resultCode, resultData)
if (requestCode == Constants.OPEN_DOCUMENT_TREE && resultCode == Activity.RESULT_OK && resultData != null) { 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) fun isShowingPermDialog(file: File) = isShowingWritePermissions(file, mConfig.treeUri, Constants.OPEN_DOCUMENT_TREE)
} }

View file

@ -1,9 +1,9 @@
package com.simplemobiletools.gallery.asynctasks package com.simplemobiletools.gallery.asynctasks
import android.content.Context import android.content.Context
import android.media.MediaScannerConnection
import android.os.AsyncTask import android.os.AsyncTask
import android.provider.MediaStore import android.provider.MediaStore
import com.simplemobiletools.filepicker.extensions.rescanFiles
import com.simplemobiletools.gallery.Config import com.simplemobiletools.gallery.Config
import com.simplemobiletools.gallery.Constants import com.simplemobiletools.gallery.Constants
import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.R
@ -80,7 +80,7 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va
Collections.sort<Directory>(dirs) Collections.sort<Directory>(dirs)
val invalids = invalidFiles.toTypedArray() val invalids = invalidFiles.toTypedArray()
MediaScannerConnection.scanFile(context, invalids, null, null) context.rescanFiles(invalids)
return dirs return dirs
} }

View file

@ -1,6 +1,5 @@
package com.simplemobiletools.gallery.dialogs package com.simplemobiletools.gallery.dialogs
import android.media.MediaScannerConnection
import android.support.v7.app.AlertDialog import android.support.v7.app.AlertDialog
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.WindowManager 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) { private fun sendSuccess(currFile: File, newFile: File) {
val changedFiles = arrayOf(currFile.absolutePath, newFile.absolutePath) val changedFiles = arrayOf(currFile.absolutePath, newFile.absolutePath)
MediaScannerConnection.scanFile(activity.applicationContext, changedFiles, null, null) activity.rescanFiles(changedFiles)
listener.onRenameFileSuccess(newFile) listener.onRenameFileSuccess(newFile)
} }