From 2dbbc2bbdb384a93643ae12afabfed1f3fd8ef78 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 19 Oct 2017 19:13:12 +0200 Subject: [PATCH] add an extra check at creating .nomedia file on the SD card --- .../gallery/adapters/DirectoryAdapter.kt | 10 ++++++---- .../simplemobiletools/gallery/extensions/activity.kt | 8 ++++---- 2 files changed, 10 insertions(+), 8 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 490e9a14f..175f729ce 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -123,10 +123,11 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList 0 @@ -138,10 +139,11 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList 0 diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt index 5b182f5ea..59d4f2b52 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt @@ -224,11 +224,11 @@ fun SimpleActivity.addNoMedia(path: String, callback: () -> Unit) { if (needsStupidWritePermissions(path)) { handleSAFDialog(file) { - try { - getFileDocument(path)?.createFile("", NOMEDIA) - } catch (e: Exception) { + val fileDocument = getFileDocument(path) + if (fileDocument?.exists() == true && fileDocument.isDirectory) { + fileDocument.createFile("", NOMEDIA) + } else toast(R.string.unknown_error_occurred) - } } } else { try {