adding some null checks at deleting files/folders

This commit is contained in:
tibbi 2018-07-06 13:00:45 +02:00
parent 902bdb0255
commit bb8acad55e
2 changed files with 12 additions and 10 deletions

View file

@ -380,7 +380,8 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
activity.handleSAFDialog(SAFPath) { activity.handleSAFDialog(SAFPath) {
selectedPositions.sortedDescending().forEach { selectedPositions.sortedDescending().forEach {
val directory = dirs[it] val directory = dirs.getOrNull(it)
if (directory != null) {
if (directory.areFavorites() || directory.isRecycleBin()) { if (directory.areFavorites() || directory.isRecycleBin()) {
if (selectedPositions.size == 1) { if (selectedPositions.size == 1) {
finishActMode() finishActMode()
@ -393,6 +394,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
removeFolders.add(directory) removeFolders.add(directory)
} }
} }
}
dirs.removeAll(removeFolders) dirs.removeAll(removeFolders)
listener?.deleteFolders(folders) listener?.deleteFolders(folders)

View file

@ -316,7 +316,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
val SAFPath = (media[selectedPositions.first()] as Medium).path val SAFPath = (media[selectedPositions.first()] as Medium).path
activity.handleSAFDialog(SAFPath) { activity.handleSAFDialog(SAFPath) {
selectedPositions.sortedDescending().forEach { selectedPositions.sortedDescending().forEach {
val thumbnailItem = media[it] val thumbnailItem = media.getOrNull(it)
if (thumbnailItem is Medium) { if (thumbnailItem is Medium) {
fileDirItems.add(FileDirItem(thumbnailItem.path, thumbnailItem.name)) fileDirItems.add(FileDirItem(thumbnailItem.path, thumbnailItem.name))
removeMedia.add(thumbnailItem) removeMedia.add(thumbnailItem)