From 60b44c27becb78a10a141ec30e94151dc10b6ca1 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 1 Oct 2020 17:23:29 +0200 Subject: [PATCH] adding some try/catch blocks --- app/build.gradle | 2 +- .../gallery/pro/helpers/MediaFetcher.kt | 54 ++++++++++--------- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 46e7519a6..e1bd6ff14 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -77,7 +77,7 @@ android { } dependencies { - implementation 'com.simplemobiletools:commons:5.30.17' + implementation 'com.simplemobiletools:commons:5.30.25' implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0' implementation 'it.sephiroth.android.exif:library:1.0.1' implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.19' 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 b6ff0c9de..926ced470 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 @@ -481,20 +481,23 @@ class MediaFetcher(val context: Context) { val uri = Files.getContentUri("external") - val cursor = context.contentResolver.query(uri, projection, null, null, null) - cursor?.use { - if (cursor.moveToFirst()) { - do { - try { - val dateTaken = cursor.getLongValue(Images.Media.DATE_TAKEN) - if (dateTaken != 0L) { - val path = cursor.getStringValue(Images.Media.DATA) - dateTakens[path] = dateTaken + try { + val cursor = context.contentResolver.query(uri, projection, null, null, null) + cursor?.use { + if (cursor.moveToFirst()) { + do { + try { + val dateTaken = cursor.getLongValue(Images.Media.DATE_TAKEN) + if (dateTaken != 0L) { + val path = cursor.getStringValue(Images.Media.DATA) + dateTakens[path] = dateTaken + } + } catch (e: Exception) { } - } catch (e: Exception) { - } - } while (cursor.moveToNext()) + } while (cursor.moveToNext()) + } } + } catch (e: Exception) { } val dateTakenValues = context.dateTakensDB.getAllDateTakens() @@ -547,20 +550,23 @@ class MediaFetcher(val context: Context) { val uri = Files.getContentUri("external") - val cursor = context.contentResolver.query(uri, projection, null, null, null) - cursor?.use { - if (cursor.moveToFirst()) { - do { - try { - val lastModified = cursor.getLongValue(Images.Media.DATE_MODIFIED) * 1000 - if (lastModified != 0L) { - val path = cursor.getStringValue(Images.Media.DATA) - lastModifieds[path] = lastModified + try { + val cursor = context.contentResolver.query(uri, projection, null, null, null) + cursor?.use { + if (cursor.moveToFirst()) { + do { + try { + val lastModified = cursor.getLongValue(Images.Media.DATE_MODIFIED) * 1000 + if (lastModified != 0L) { + val path = cursor.getStringValue(Images.Media.DATA) + lastModifieds[path] = lastModified + } + } catch (e: Exception) { } - } catch (e: Exception) { - } - } while (cursor.moveToNext()) + } while (cursor.moveToNext()) + } } + } catch (e: Exception) { } return lastModifieds