mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-22 20:48:00 +01:00
using a few more extension functions
This commit is contained in:
parent
c4edf3c28e
commit
75beef4da6
4 changed files with 15 additions and 16 deletions
|
@ -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<String>) = context.rescanFiles(paths)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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<Directory>(dirs)
|
||||
|
||||
val invalids = invalidFiles.toTypedArray()
|
||||
MediaScannerConnection.scanFile(context, invalids, null, null)
|
||||
context.rescanFiles(invalids)
|
||||
return dirs
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue