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,17 +380,19 @@ 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.areFavorites() || directory.isRecycleBin()) { if (directory != null) {
if (selectedPositions.size == 1) { if (directory.areFavorites() || directory.isRecycleBin()) {
finishActMode() if (selectedPositions.size == 1) {
finishActMode()
} else {
selectedPositions.remove(it)
toggleItemSelection(false, it)
}
} else { } else {
selectedPositions.remove(it) folders.add(File(directory.path))
toggleItemSelection(false, it) removeFolders.add(directory)
} }
} else {
folders.add(File(directory.path))
removeFolders.add(directory)
} }
} }

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)