add some array size checks at deleting from media/directory view

This commit is contained in:
tibbi 2017-08-02 23:12:48 +02:00
parent 6e1f56f864
commit ae3555b1c5
2 changed files with 12 additions and 5 deletions

View file

@ -297,12 +297,14 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Direc
activity.handleSAFDialog(File(needPermissionForPath)) { activity.handleSAFDialog(File(needPermissionForPath)) {
selectedPositions.sortedDescending().forEach { selectedPositions.sortedDescending().forEach {
if (dirs.size > it) {
val directory = dirs[it] val directory = dirs[it]
folders.add(File(directory.path)) folders.add(File(directory.path))
removeFolders.add(directory) removeFolders.add(directory)
notifyItemRemoved(it) notifyItemRemoved(it)
itemViews.put(it, null) itemViews.put(it, null)
} }
}
dirs.removeAll(removeFolders) dirs.removeAll(removeFolders)
selectedPositions.clear() selectedPositions.clear()

View file

@ -232,6 +232,11 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
val files = ArrayList<File>(selectedPositions.size) val files = ArrayList<File>(selectedPositions.size)
val removeMedia = ArrayList<Medium>(selectedPositions.size) val removeMedia = ArrayList<Medium>(selectedPositions.size)
if (media.size <= selectedPositions.first()) {
actMode?.finish()
return
}
activity.handleSAFDialog(File(media[selectedPositions.first()].path)) { activity.handleSAFDialog(File(media[selectedPositions.first()].path)) {
selectedPositions.sortedDescending().forEach { selectedPositions.sortedDescending().forEach {
val medium = media[it] val medium = media[it]