fix #115, allow setting a custom image as

This commit is contained in:
tibbi 2017-06-06 21:24:06 +02:00
parent add3320c4a
commit e98de74ae4
3 changed files with 18 additions and 4 deletions

View file

@ -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<Direc
return
val path = dirs[selectedPositions.first()].path
val listType = object : TypeToken<List<AlbumCover>>() {}.type
var albumCovers = Gson().fromJson<ArrayList<AlbumCover>>(config.albumCovers, listType) ?: ArrayList(1)
var albumCovers = config.parseAlbumCovers()
if (useDefault) {
albumCovers = albumCovers.filterNot { it.path == path } as ArrayList

View file

@ -35,6 +35,7 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va
}
private fun groupDirectories(media: ArrayList<Medium>): Map<String, Directory> {
val albumCovers = config.parseAlbumCovers()
val hidden = context.resources.getString(R.string.hidden)
val directories = LinkedHashMap<String, Directory>()
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)
}
}

View file

@ -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<AlbumCover> {
val listType = object : TypeToken<List<AlbumCover>>() {}.type
return Gson().fromJson<ArrayList<AlbumCover>>(albumCovers, listType) ?: ArrayList(1)
}
}