url decode the document file uri before deleting, should fix SD delete issues

This commit is contained in:
tibbi 2017-02-09 21:46:43 +01:00
parent 099e13ea0c
commit 58ace8e59f
3 changed files with 11 additions and 3 deletions

View file

@ -29,6 +29,7 @@ import com.simplemobiletools.gallery.models.Directory
import com.simplemobiletools.gallery.views.MyScalableRecyclerView import com.simplemobiletools.gallery.views.MyScalableRecyclerView
import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.activity_main.*
import java.io.File import java.io.File
import java.net.URLDecoder
import java.util.* import java.util.*
class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
@ -193,7 +194,8 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
val document = getFileDocument(file.absolutePath, config.treeUri) 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
if (document.uri.toString().endsWith(file.absolutePath.getFilenameFromPath())) { val uri = URLDecoder.decode(document.uri.toString(), "UTF-8")
if (uri.endsWith(file.absolutePath.getFilenameFromPath())) {
Thread({ Thread({
document.delete() document.delete()
}).start() }).start()

View file

@ -27,6 +27,7 @@ import com.simplemobiletools.gallery.views.MyScalableRecyclerView
import kotlinx.android.synthetic.main.activity_media.* import kotlinx.android.synthetic.main.activity_media.*
import java.io.File import java.io.File
import java.io.IOException import java.io.IOException
import java.net.URLDecoder
import java.util.* import java.util.*
class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
@ -222,7 +223,8 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
val document = getFileDocument(it.absolutePath, config.treeUri) 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
if (document.uri.toString().endsWith(it.absolutePath.getFilenameFromPath()) && !document.isDirectory) { val uri = URLDecoder.decode(document.uri.toString(), "UTF-8")
if (uri.endsWith(it.absolutePath.getFilenameFromPath()) && !document.isDirectory) {
Thread({ Thread({
document.delete() document.delete()
}).start() }).start()

View file

@ -28,6 +28,7 @@ import com.simplemobiletools.gallery.helpers.REQUEST_SET_WALLPAPER
import com.simplemobiletools.gallery.models.Medium import com.simplemobiletools.gallery.models.Medium
import kotlinx.android.synthetic.main.activity_medium.* import kotlinx.android.synthetic.main.activity_medium.*
import java.io.File import java.io.File
import java.net.URLDecoder
import java.util.* import java.util.*
class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, ViewPagerFragment.FragmentListener { class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, ViewPagerFragment.FragmentListener {
@ -237,7 +238,10 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
if (needsStupidWritePermissions(mPath)) { if (needsStupidWritePermissions(mPath)) {
if (!isShowingPermDialog(file)) { if (!isShowingPermDialog(file)) {
val document = getFileDocument(mPath, config.treeUri) val document = getFileDocument(mPath, config.treeUri)
if (document.uri.toString().endsWith(file.absolutePath.getFilenameFromPath()) && !document.isDirectory)
// double check we have the uri to the proper file path, not some parent folder
val uri = URLDecoder.decode(document.uri.toString(), "UTF-8")
if (uri.endsWith(file.absolutePath.getFilenameFromPath()) && !document.isDirectory)
document.delete() document.delete()
} }
} else { } else {