mirror of
https://github.com/SimpleMobileTools/Simple-File-Manager.git
synced 2025-06-05 22:09:15 +02:00
correct deleting files on SD card
This commit is contained in:
@ -11,44 +11,46 @@ import android.widget.Toast
|
||||
import com.simplemobiletools.filepicker.extensions.getSDCardPath
|
||||
import java.util.regex.Pattern
|
||||
|
||||
object Utils {
|
||||
fun getFilename(path: String): String {
|
||||
return path.substring(path.lastIndexOf("/") + 1)
|
||||
}
|
||||
|
||||
fun getFileExtension(fileName: String): String {
|
||||
return fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length).toLowerCase()
|
||||
}
|
||||
|
||||
fun showToast(context: Context, resId: Int) {
|
||||
Toast.makeText(context, context.resources.getString(resId), Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
fun hasStoragePermission(cxt: Context): Boolean {
|
||||
return ContextCompat.checkSelfPermission(cxt, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED
|
||||
}
|
||||
|
||||
fun isNameValid(name: String): Boolean {
|
||||
val pattern = Pattern.compile("^[-_.A-Za-z0-9 ]+$")
|
||||
val matcher = pattern.matcher(name)
|
||||
return matcher.matches()
|
||||
}
|
||||
|
||||
fun needsStupidWritePermissions(context: Context, path: String) = isPathOnSD(context, path) && isKitkat()
|
||||
|
||||
fun isPathOnSD(context: Context, path: String): Boolean {
|
||||
return path.startsWith(context.getSDCardPath())
|
||||
}
|
||||
|
||||
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)
|
||||
class Utils {
|
||||
companion object {
|
||||
fun getFilename(path: String): String {
|
||||
return path.substring(path.lastIndexOf("/") + 1)
|
||||
}
|
||||
|
||||
fun getFileExtension(fileName: String): String {
|
||||
return fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length).toLowerCase()
|
||||
}
|
||||
|
||||
fun showToast(context: Context, resId: Int) {
|
||||
Toast.makeText(context, context.resources.getString(resId), Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
fun hasStoragePermission(cxt: Context): Boolean {
|
||||
return ContextCompat.checkSelfPermission(cxt, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED
|
||||
}
|
||||
|
||||
fun isNameValid(name: String): Boolean {
|
||||
val pattern = Pattern.compile("^[-_.A-Za-z0-9 ]+$")
|
||||
val matcher = pattern.matcher(name)
|
||||
return matcher.matches()
|
||||
}
|
||||
|
||||
fun needsStupidWritePermissions(context: Context, path: String) = isPathOnSD(context, path) && isKitkat()
|
||||
|
||||
fun isPathOnSD(context: Context, path: String): Boolean {
|
||||
return path.startsWith(context.getSDCardPath())
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
return document
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user