From d5496e04ba94d6df8e77cedb018df5b07adf7b97 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 20 Feb 2018 11:22:04 +0100 Subject: [PATCH] give proper folder names to OTG subfolders --- .../gallery/asynctasks/GetDirectoriesAsynctask.kt | 8 +++++++- .../com/simplemobiletools/gallery/helpers/MediaFetcher.kt | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt index 0869a976d..c9f8c60ef 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt @@ -49,7 +49,13 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va context.internalStoragePath -> context.getString(R.string.internal) context.sdCardPath -> context.getString(R.string.sd_card) OTG_PATH -> context.getString(R.string.otg) - else -> parentDir.getFilenameFromPath() + else -> { + if (parentDir.startsWith(OTG_PATH)) { + parentDir.getParentPath().trimEnd('/').substringAfterLast('/') + } else { + parentDir.getFilenameFromPath() + } + } } if (File(parentDir).containsNoMedia()) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt index 46c4e30e1..65347f4e1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt @@ -2,6 +2,7 @@ package com.simplemobiletools.gallery.helpers import android.content.Context import android.database.Cursor +import android.net.Uri import android.provider.MediaStore import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.* @@ -349,7 +350,7 @@ class MediaFetcher(val context: Context) { else -> TYPE_GIF } - val path = file.uri.toString().replaceFirst("${context.config.OTGBasePath}%3A", OTG_PATH) + val path = Uri.decode(file.uri.toString().replaceFirst("${context.config.OTGBasePath}%3A", OTG_PATH)) val medium = Medium(filename, path, dateModified, dateTaken, size, type) val isAlreadyAdded = curMedia.any { it.path == path } if (!isAlreadyAdded) {