do not lowercase deleted path urls + some safety checks
This commit is contained in:
parent
7658651ebf
commit
732e703d88
7 changed files with 19 additions and 10 deletions
|
@ -204,7 +204,11 @@ class MainActivity : SimpleActivity(), GetDirectoriesAsynctask.GetDirectoriesLis
|
||||||
private fun deleteItem(file: File) {
|
private fun deleteItem(file: File) {
|
||||||
if (needsStupidWritePermissions(file.absolutePath)) {
|
if (needsStupidWritePermissions(file.absolutePath)) {
|
||||||
if (!isShowingPermDialog(file)) {
|
if (!isShowingPermDialog(file)) {
|
||||||
getFileDocument(file.absolutePath, mConfig.treeUri).delete()
|
val document = getFileDocument(file.absolutePath, mConfig.treeUri)
|
||||||
|
|
||||||
|
// double check we have the uri to the proper file path, not some parent folder
|
||||||
|
if (document.uri.toString().endsWith(file.absolutePath.getFilenameFromPath()))
|
||||||
|
document.delete()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
file.delete()
|
file.delete()
|
||||||
|
|
|
@ -231,12 +231,17 @@ class MediaActivity : SimpleActivity(), View.OnTouchListener, MediaAdapter.Media
|
||||||
for (delPath in mToBeDeleted) {
|
for (delPath in mToBeDeleted) {
|
||||||
val file = File(delPath)
|
val file = File(delPath)
|
||||||
if (file.exists() && file.isPhotoVideo()) {
|
if (file.exists() && file.isPhotoVideo()) {
|
||||||
if (needsStupidWritePermissions(delPath)) {
|
if (needsStupidWritePermissions(file.absolutePath)) {
|
||||||
if (isShowingPermDialog(file))
|
if (isShowingPermDialog(file))
|
||||||
return
|
return
|
||||||
|
|
||||||
if (getFileDocument(delPath, mConfig.treeUri).delete()) {
|
val document = getFileDocument(file.absolutePath, mConfig.treeUri)
|
||||||
wereFilesDeleted = true
|
|
||||||
|
// double check we have the uri to the proper file path, not some parent folder
|
||||||
|
if (document.uri.toString().endsWith(file.absolutePath.getFilenameFromPath())) {
|
||||||
|
if (document.delete()) {
|
||||||
|
wereFilesDeleted = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (file.delete())
|
if (file.delete())
|
||||||
|
@ -251,8 +256,8 @@ class MediaActivity : SimpleActivity(), View.OnTouchListener, MediaAdapter.Media
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mToBeDeleted.clear()
|
|
||||||
}
|
}
|
||||||
|
mToBeDeleted.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
private val undoDeletion = View.OnClickListener {
|
private val undoDeletion = View.OnClickListener {
|
||||||
|
|
|
@ -343,7 +343,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
|
|
||||||
private fun deleteDirectoryIfEmpty() {
|
private fun deleteDirectoryIfEmpty() {
|
||||||
val file = File(mDirectory)
|
val file = File(mDirectory)
|
||||||
if (file.isDirectory && file.listFiles().size == 0) {
|
if (file.isDirectory && file.listFiles().isEmpty()) {
|
||||||
file.delete()
|
file.delete()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -187,7 +187,7 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
|
||||||
private fun prepareForDeleting() {
|
private fun prepareForDeleting() {
|
||||||
val selections = multiSelector.selectedPositions
|
val selections = multiSelector.selectedPositions
|
||||||
val paths = ArrayList<String>(selections.size)
|
val paths = ArrayList<String>(selections.size)
|
||||||
selections.forEach { paths.add(dirs[it].path.toLowerCase()) }
|
selections.forEach { paths.add(dirs[it].path) }
|
||||||
listener?.prepareForDeleting(paths)
|
listener?.prepareForDeleting(paths)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -137,7 +137,7 @@ class MediaAdapter(val activity: SimpleActivity, val media: MutableList<Medium>,
|
||||||
private fun prepareForDeleting() {
|
private fun prepareForDeleting() {
|
||||||
val selections = multiSelector.selectedPositions
|
val selections = multiSelector.selectedPositions
|
||||||
val paths = ArrayList<String>(selections.size)
|
val paths = ArrayList<String>(selections.size)
|
||||||
selections.forEach { paths.add(media[it].path.toLowerCase()) }
|
selections.forEach { paths.add(media[it].path) }
|
||||||
listener?.prepareForDeleting(paths)
|
listener?.prepareForDeleting(paths)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,7 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va
|
||||||
val newImageCnt = directory.mediaCnt + 1
|
val newImageCnt = directory.mediaCnt + 1
|
||||||
directory.mediaCnt = newImageCnt
|
directory.mediaCnt = newImageCnt
|
||||||
directory.addSize(file.length())
|
directory.addSize(file.length())
|
||||||
} else if (!mToBeDeleted.contains(parentDir.toLowerCase())) {
|
} else if (!mToBeDeleted.contains(parentDir)) {
|
||||||
var dirName = context.getHumanizedFilename(parentDir)
|
var dirName = context.getHumanizedFilename(parentDir)
|
||||||
if (mConfig.getIsFolderHidden(parentDir)) {
|
if (mConfig.getIsFolderHidden(parentDir)) {
|
||||||
dirName += " ${context.resources.getString(R.string.hidden)}"
|
dirName += " ${context.resources.getString(R.string.hidden)}"
|
||||||
|
|
|
@ -51,7 +51,7 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickVideo
|
||||||
do {
|
do {
|
||||||
val curPath = cursor.getString(pathIndex) ?: continue
|
val curPath = cursor.getString(pathIndex) ?: continue
|
||||||
|
|
||||||
if (curPath.matches(pattern.toRegex()) && !mToBeDeleted.contains(curPath.toLowerCase())) {
|
if (curPath.matches(pattern.toRegex()) && !mToBeDeleted.contains(curPath)) {
|
||||||
val file = File(curPath)
|
val file = File(curPath)
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
val dateIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATE_MODIFIED)
|
val dateIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATE_MODIFIED)
|
||||||
|
|
Loading…
Reference in a new issue