From a7f2cc61c8dd10b3ff0d52a48bbdbe287beed3eb Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 16 Dec 2018 17:13:17 +0100 Subject: [PATCH] store the folder path at widgets, not thumbnail path --- .../pro/activities/WidgetConfigureActivity.kt | 19 +++++++++---------- .../gallery/pro/extensions/Context.kt | 2 ++ .../gallery/pro/interfaces/DirectoryDao.kt | 3 +++ 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/WidgetConfigureActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/WidgetConfigureActivity.kt index 9b3a26bf7..a656c01ec 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/WidgetConfigureActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/WidgetConfigureActivity.kt @@ -11,10 +11,7 @@ import com.simplemobiletools.commons.dialogs.ColorPickerDialog import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.gallery.pro.R import com.simplemobiletools.gallery.pro.dialogs.PickDirectoryDialog -import com.simplemobiletools.gallery.pro.extensions.config -import com.simplemobiletools.gallery.pro.extensions.getCachedDirectories -import com.simplemobiletools.gallery.pro.extensions.loadJpg -import com.simplemobiletools.gallery.pro.extensions.widgetsDB +import com.simplemobiletools.gallery.pro.extensions.* import com.simplemobiletools.gallery.pro.helpers.MyWidgetProvider import com.simplemobiletools.gallery.pro.models.Directory import com.simplemobiletools.gallery.pro.models.Widget @@ -83,7 +80,7 @@ class WidgetConfigureActivity : SimpleActivity() { val views = RemoteViews(packageName, R.layout.widget) views.setBackgroundColor(R.id.widget_holder, mBgColor) AppWidgetManager.getInstance(this).updateAppWidget(mWidgetId, views) - val widget = Widget(null, mWidgetId, "/storage/emulated/0") + val widget = Widget(null, mWidgetId, mFolderPath) Thread { widgetsDB.insertOrUpdate(widget) }.start() @@ -135,11 +132,13 @@ class WidgetConfigureActivity : SimpleActivity() { private fun updateFolderImage(folderPath: String) { mFolderPath = folderPath - val tmb = mDirectories.firstOrNull { it.path == folderPath }?.tmb - if (tmb != null) { - runOnUiThread { - loadJpg(tmb, config_image, true) + Thread { + val path = directoryDB.getDirectoryThumbnail(folderPath) + if (path != null) { + runOnUiThread { + loadJpg(path, config_image, true) + } } - } + }.start() } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt index 2e7cdb0a3..161d131e7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt @@ -107,6 +107,8 @@ val Context.galleryDB: GalleryDatabase get() = GalleryDatabase.getInstance(appli val Context.widgetsDB: WidgetsDao get() = GalleryDatabase.getInstance(applicationContext).WidgetsDao() +val Context.directoryDB: DirectoryDao get() = GalleryDatabase.getInstance(applicationContext).DirectoryDao() + val Context.recycleBin: File get() = filesDir val Context.recycleBinPath: String get() = filesDir.absolutePath diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/interfaces/DirectoryDao.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/interfaces/DirectoryDao.kt index 78641ebf9..57d6807c2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/interfaces/DirectoryDao.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/interfaces/DirectoryDao.kt @@ -29,4 +29,7 @@ interface DirectoryDao { @Query("DELETE FROM directories WHERE path = \'$RECYCLE_BIN\' COLLATE NOCASE") fun deleteRecycleBin() + + @Query("SELECT thumbnail FROM directories WHERE path = :path") + fun getDirectoryThumbnail(path: String): String? }