create a helper function for getting the documentfile
This commit is contained in:
parent
b6cd6e39eb
commit
20fb58ddbe
|
@ -3,8 +3,10 @@ package com.simplemobiletools.filemanager
|
||||||
import android.Manifest
|
import android.Manifest
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.support.v4.content.ContextCompat
|
import android.support.v4.content.ContextCompat
|
||||||
|
import android.support.v4.provider.DocumentFile
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import com.simplemobiletools.filepicker.extensions.getSDCardPath
|
import com.simplemobiletools.filepicker.extensions.getSDCardPath
|
||||||
import java.util.regex.Pattern
|
import java.util.regex.Pattern
|
||||||
|
@ -39,4 +41,14 @@ object Utils {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isKitkat() = Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT
|
fun isKitkat() = Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT
|
||||||
|
|
||||||
|
fun getFileDocument(context: Context, path: String): DocumentFile {
|
||||||
|
val relativePath = path.substring(context.getSDCardPath().length + 1)
|
||||||
|
var document = DocumentFile.fromTreeUri(context, Uri.parse(Config.newInstance(context).treeUri))
|
||||||
|
val parts = relativePath.split("/")
|
||||||
|
for (part in parts) {
|
||||||
|
document = document.findFile(part)
|
||||||
|
}
|
||||||
|
return document
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,18 +2,14 @@ package com.simplemobiletools.filemanager.dialogs
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.media.MediaScannerConnection
|
import android.media.MediaScannerConnection
|
||||||
import android.net.Uri
|
|
||||||
import android.support.v4.provider.DocumentFile
|
|
||||||
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
|
||||||
import com.simplemobiletools.filemanager.Config
|
|
||||||
import com.simplemobiletools.filemanager.R
|
import com.simplemobiletools.filemanager.R
|
||||||
import com.simplemobiletools.filemanager.Utils
|
import com.simplemobiletools.filemanager.Utils
|
||||||
import com.simplemobiletools.filemanager.extensions.rescanItem
|
import com.simplemobiletools.filemanager.extensions.rescanItem
|
||||||
import com.simplemobiletools.filemanager.extensions.toast
|
import com.simplemobiletools.filemanager.extensions.toast
|
||||||
import com.simplemobiletools.filemanager.extensions.value
|
import com.simplemobiletools.filemanager.extensions.value
|
||||||
import com.simplemobiletools.filepicker.extensions.getSDCardPath
|
|
||||||
import com.simplemobiletools.filepicker.models.FileDirItem
|
import com.simplemobiletools.filepicker.models.FileDirItem
|
||||||
import kotlinx.android.synthetic.main.rename_item.view.*
|
import kotlinx.android.synthetic.main.rename_item.view.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
@ -44,12 +40,7 @@ class RenameItemDialog(val context: Context, val path: String, val item: FileDir
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Utils.needsStupidWritePermissions(context, path)) {
|
if (Utils.needsStupidWritePermissions(context, path)) {
|
||||||
val relativePath = currFile.absolutePath.substring(context.getSDCardPath().length + 1)
|
val document = Utils.getFileDocument(context, currFile.absolutePath)
|
||||||
var document = DocumentFile.fromTreeUri(context, Uri.parse(Config.newInstance(context).treeUri))
|
|
||||||
val parts = relativePath.split("/")
|
|
||||||
for (part in parts) {
|
|
||||||
document = document.findFile(part)
|
|
||||||
}
|
|
||||||
if (document.canWrite())
|
if (document.canWrite())
|
||||||
document.renameTo(newName)
|
document.renameTo(newName)
|
||||||
sendSuccess(currFile, newFile)
|
sendSuccess(currFile, newFile)
|
||||||
|
|
Loading…
Reference in New Issue