From ae3555b1c5a979a20c3d4bb697ff3ec9ad5347d0 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 2 Aug 2017 23:12:48 +0200 Subject: [PATCH] add some array size checks at deleting from media/directory view --- .../gallery/adapters/DirectoryAdapter.kt | 12 +++++++----- .../gallery/adapters/MediaAdapter.kt | 5 +++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt index d1845938e..391386562 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -297,11 +297,13 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList it) { + val directory = dirs[it] + folders.add(File(directory.path)) + removeFolders.add(directory) + notifyItemRemoved(it) + itemViews.put(it, null) + } } dirs.removeAll(removeFolders) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt index d62a63df9..7f8b511e7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -232,6 +232,11 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, val files = ArrayList(selectedPositions.size) val removeMedia = ArrayList(selectedPositions.size) + if (media.size <= selectedPositions.first()) { + actMode?.finish() + return + } + activity.handleSAFDialog(File(media[selectedPositions.first()].path)) { selectedPositions.sortedDescending().forEach { val medium = media[it]