mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-23 13:08:00 +01:00
tweak the way files are deleted
This commit is contained in:
parent
6e6ea3a257
commit
bf952f71cf
3 changed files with 37 additions and 36 deletions
|
@ -200,17 +200,17 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread({
|
Thread({
|
||||||
if (needsPermissions) {
|
if (!file.delete()) {
|
||||||
val document = getFileDocument(file.absolutePath, config.treeUri)
|
if (needsPermissions) {
|
||||||
|
val document = getFileDocument(file.absolutePath, config.treeUri)
|
||||||
|
|
||||||
// double check we have the uri to the proper file path, not some parent folder
|
// double check we have the uri to the proper file path, not some parent folder
|
||||||
val uri = URLDecoder.decode(document.uri.toString(), "UTF-8")
|
val uri = URLDecoder.decode(document.uri.toString(), "UTF-8")
|
||||||
val filename = URLDecoder.decode(file.absolutePath.getFilenameFromPath(), "UTF-8")
|
val filename = URLDecoder.decode(file.absolutePath.getFilenameFromPath(), "UTF-8")
|
||||||
if (uri.endsWith(filename)) {
|
if (uri.endsWith(filename)) {
|
||||||
document.delete()
|
document.delete()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
file.delete()
|
|
||||||
}
|
}
|
||||||
}).start()
|
}).start()
|
||||||
}
|
}
|
||||||
|
|
|
@ -237,19 +237,20 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
||||||
var hadSuccess = false
|
var hadSuccess = false
|
||||||
files.filter { it.exists() && it.isImageVideoGif() }
|
files.filter { it.exists() && it.isImageVideoGif() }
|
||||||
.forEach {
|
.forEach {
|
||||||
if (needsPermissions) {
|
if (!it.delete()) {
|
||||||
val document = getFileDocument(it.absolutePath, config.treeUri)
|
if (needsPermissions) {
|
||||||
|
val document = getFileDocument(it.absolutePath, config.treeUri)
|
||||||
|
|
||||||
// double check we have the uri to the proper file path, not some parent folder
|
// double check we have the uri to the proper file path, not some parent folder
|
||||||
val uri = URLDecoder.decode(document.uri.toString(), "UTF-8")
|
val uri = URLDecoder.decode(document.uri.toString(), "UTF-8")
|
||||||
val filename = URLDecoder.decode(it.absolutePath.getFilenameFromPath(), "UTF-8")
|
val filename = URLDecoder.decode(it.absolutePath.getFilenameFromPath(), "UTF-8")
|
||||||
if (uri.endsWith(filename) && !document.isDirectory) {
|
if (uri.endsWith(filename) && !document.isDirectory) {
|
||||||
if (document.delete())
|
if (document.delete())
|
||||||
hadSuccess = true
|
hadSuccess = true
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (it.delete())
|
|
||||||
hadSuccess = true
|
hadSuccess = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
deleteFromMediaStore(it)
|
deleteFromMediaStore(it)
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import android.graphics.BitmapFactory
|
||||||
import android.graphics.Matrix
|
import android.graphics.Matrix
|
||||||
import android.media.ExifInterface
|
import android.media.ExifInterface
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.provider.MediaStore
|
import android.provider.MediaStore
|
||||||
import android.support.v4.view.ViewPager
|
import android.support.v4.view.ViewPager
|
||||||
|
@ -286,7 +287,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
return (floatD + floatM / 60 + floatS / 3600).toFloat()
|
return (floatD + floatM / 60 + floatS / 3600).toFloat()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
|
override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
|
||||||
if (requestCode == REQUEST_EDIT_IMAGE) {
|
if (requestCode == REQUEST_EDIT_IMAGE) {
|
||||||
if (resultCode == Activity.RESULT_OK && resultData != null) {
|
if (resultCode == Activity.RESULT_OK && resultData != null) {
|
||||||
|
@ -314,23 +314,23 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread({
|
Thread {
|
||||||
if (needsPermissions) {
|
if (!file.delete()) {
|
||||||
val document = getFileDocument(file.absolutePath, config.treeUri)
|
if (needsPermissions) {
|
||||||
|
val document = getFileDocument(file.absolutePath, config.treeUri)
|
||||||
|
|
||||||
// double check we have the uri to the proper file path, not some parent folder
|
// double check we have the uri to the proper file path, not some parent folder
|
||||||
val uri = URLDecoder.decode(document.uri.toString(), "UTF-8")
|
val uri = URLDecoder.decode(document.uri.toString(), "UTF-8")
|
||||||
val filename = URLDecoder.decode(file.absolutePath.getFilenameFromPath(), "UTF-8")
|
val filename = URLDecoder.decode(file.absolutePath.getFilenameFromPath(), "UTF-8")
|
||||||
if (uri.endsWith(filename) && !document.isDirectory) {
|
if (uri.endsWith(filename) && !document.isDirectory) {
|
||||||
document.delete()
|
document.delete()
|
||||||
} else {
|
} else {
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
toast(R.string.unknown_error_occurred)
|
toast(R.string.unknown_error_occurred)
|
||||||
|
}
|
||||||
|
return@Thread
|
||||||
}
|
}
|
||||||
return@Thread
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
file.delete()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deleteFromMediaStore(file)) {
|
if (deleteFromMediaStore(file)) {
|
||||||
|
@ -340,7 +340,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
reloadViewPager()
|
reloadViewPager()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).start()
|
}.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isDirEmpty(): Boolean {
|
private fun isDirEmpty(): Boolean {
|
||||||
|
|
Loading…
Reference in a new issue