From d95b9c112930da6a9342d200d2e059d787c2fa24 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 3 Dec 2019 22:45:59 +0100 Subject: [PATCH] migrate album covers at exporting/importing settings too --- .../gallery/pro/activities/SettingsActivity.kt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SettingsActivity.kt index c9c296874..bafa61116 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SettingsActivity.kt @@ -4,6 +4,8 @@ import android.content.Intent import android.os.Bundle import android.text.TextUtils import android.view.Menu +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.simplemobiletools.commons.dialogs.* import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.* @@ -16,6 +18,7 @@ import com.simplemobiletools.gallery.pro.extensions.emptyTheRecycleBin import com.simplemobiletools.gallery.pro.extensions.galleryDB import com.simplemobiletools.gallery.pro.extensions.showRecycleBinEmptyingDialog import com.simplemobiletools.gallery.pro.helpers.* +import com.simplemobiletools.gallery.pro.models.AlbumCover import kotlinx.android.synthetic.main.activity_settings.* import java.io.File import java.util.* @@ -690,6 +693,7 @@ class SettingsActivity : SimpleActivity() { put(LAST_EDITOR_BRUSH_SIZE, config.lastEditorBrushSize) put(LAST_CONFLICT_RESOLUTION, config.lastConflictResolution) put(LAST_CONFLICT_APPLY_TO_ALL, config.lastConflictApplyToAll) + put(ALBUM_COVERS, config.albumCovers) } exportSettings(configItems, "gallery-settings.txt") @@ -812,6 +816,18 @@ class SettingsActivity : SimpleActivity() { LAST_EDITOR_BRUSH_SIZE -> config.lastEditorBrushSize = value.toInt() LAST_CONFLICT_RESOLUTION -> config.lastConflictResolution = value.toInt() LAST_CONFLICT_APPLY_TO_ALL -> config.lastConflictApplyToAll = value.toBoolean() + ALBUM_COVERS -> { + val existingCovers = config.parseAlbumCovers() + val existingCoverPaths = existingCovers.map { it.path }.toMutableList() as ArrayList + + val listType = object : TypeToken>() {}.type + val covers = Gson().fromJson>(value.toString(), listType) ?: ArrayList(1) + covers.filter { !existingCoverPaths.contains(it.path) && getDoesFilePathExist(it.tmb) }.forEach { + existingCovers.add(it) + } + + config.albumCovers = Gson().toJson(existingCovers) + } } }