From 0d1db78e90e31f6176136d405c542d48d941d98d Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 6 Oct 2019 19:02:09 +0200 Subject: [PATCH] fix #1611, removing some portrait related crashes --- .../gallery/pro/fragments/PhotoFragment.kt | 14 ++++++++------ .../gallery/pro/helpers/MediaFetcher.kt | 8 +++++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt index c9a1e29f0..c0eb24494 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt @@ -482,13 +482,15 @@ class PhotoFragment : ViewPagerFragment() { setupStripeBottomMargin() val coverIndex = getCoverImageIndex(paths) - mCurrentPortraitPhotoPath = paths[coverIndex] - setupStripeUpListener(adapter, screenWidth, itemWidth) + if (coverIndex != -1) { + mCurrentPortraitPhotoPath = paths[coverIndex] + setupStripeUpListener(adapter, screenWidth, itemWidth) - mView.photo_portrait_stripe.onGlobalLayout { - mView.photo_portrait_stripe.scrollBy((coverIndex - fakeItemsCnt) * itemWidth, 0) - adapter.setCurrentPhoto(coverIndex) - mView.photo_portrait_stripe_wrapper.beVisible() + mView.photo_portrait_stripe.onGlobalLayout { + mView.photo_portrait_stripe.scrollBy((coverIndex - fakeItemsCnt) * itemWidth, 0) + adapter.setCurrentPhoto(coverIndex) + mView.photo_portrait_stripe_wrapper.beVisible() + } } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MediaFetcher.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MediaFetcher.kt index fd9ba54ce..682ecd1ae 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MediaFetcher.kt @@ -245,9 +245,11 @@ class MediaFetcher(val context: Context) { for (subdir in subdirs) { val portraitFiles = subdir.listFiles() ?: continue - val cover = portraitFiles.firstOrNull { it.name.contains("cover", true) } ?: portraitFiles.first() - files.add(cover) - covers.add(cover.absolutePath) + val cover = portraitFiles.firstOrNull { it.name.contains("cover", true) } ?: portraitFiles.firstOrNull() + if (cover != null) { + files.add(cover) + covers.add(cover.absolutePath) + } } for (file in files) {