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 8aaa5cb3d..7b76fb7a9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -11,7 +11,6 @@ import com.bignerdranch.android.multiselector.MultiSelector import com.bignerdranch.android.multiselector.SwappingHolder import com.bumptech.glide.Glide import com.google.gson.Gson -import com.google.gson.reflect.TypeToken import com.simplemobiletools.commons.dialogs.ConfirmationDialog import com.simplemobiletools.commons.dialogs.PropertiesDialog import com.simplemobiletools.commons.dialogs.RenameItemDialog @@ -332,8 +331,7 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList>() {}.type - var albumCovers = Gson().fromJson>(config.albumCovers, listType) ?: ArrayList(1) + var albumCovers = config.parseAlbumCovers() if (useDefault) { albumCovers = albumCovers.filterNot { it.path == path } as ArrayList 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 2ba94ceee..539e78e1e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt @@ -35,6 +35,7 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va } private fun groupDirectories(media: ArrayList): Map { + val albumCovers = config.parseAlbumCovers() val hidden = context.resources.getString(R.string.hidden) val directories = LinkedHashMap() for ((name, path, isVideo, dateModified, dateTaken, size) in media) { @@ -62,7 +63,14 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va continue } - val directory = Directory(parentDir, path, dirName, 1, dateModified, dateTaken, size) + var thumbnail = path + albumCovers.forEach { + if (it.path == parentDir && File(it.tmb).exists()) { + thumbnail = it.tmb + } + } + + val directory = Directory(parentDir, thumbnail, dirName, 1, dateModified, dateTaken, size) directories.put(parentDir, directory) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt index d35a981bf..424721c88 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt @@ -1,10 +1,13 @@ package com.simplemobiletools.gallery.helpers import android.content.Context +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.simplemobiletools.commons.helpers.BaseConfig import com.simplemobiletools.commons.helpers.SORT_BY_DATE_MODIFIED import com.simplemobiletools.commons.helpers.SORT_DESCENDING import com.simplemobiletools.gallery.R +import com.simplemobiletools.gallery.models.AlbumCover import java.util.* class Config(context: Context) : BaseConfig(context) { @@ -171,4 +174,9 @@ class Config(context: Context) : BaseConfig(context) { var albumCovers: String get() = prefs.getString(ALBUM_COVERS, "") set(albumCovers) = prefs.edit().putString(ALBUM_COVERS, albumCovers).apply() + + fun parseAlbumCovers(): ArrayList { + val listType = object : TypeToken>() {}.type + return Gson().fromJson>(albumCovers, listType) ?: ArrayList(1) + } }