store the folder path at widgets, not thumbnail path

This commit is contained in:
tibbi 2018-12-16 17:13:17 +01:00
parent 69f6599f8d
commit a7f2cc61c8
3 changed files with 14 additions and 10 deletions

View File

@ -11,10 +11,7 @@ import com.simplemobiletools.commons.dialogs.ColorPickerDialog
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.gallery.pro.R import com.simplemobiletools.gallery.pro.R
import com.simplemobiletools.gallery.pro.dialogs.PickDirectoryDialog import com.simplemobiletools.gallery.pro.dialogs.PickDirectoryDialog
import com.simplemobiletools.gallery.pro.extensions.config import com.simplemobiletools.gallery.pro.extensions.*
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.helpers.MyWidgetProvider import com.simplemobiletools.gallery.pro.helpers.MyWidgetProvider
import com.simplemobiletools.gallery.pro.models.Directory import com.simplemobiletools.gallery.pro.models.Directory
import com.simplemobiletools.gallery.pro.models.Widget import com.simplemobiletools.gallery.pro.models.Widget
@ -83,7 +80,7 @@ class WidgetConfigureActivity : SimpleActivity() {
val views = RemoteViews(packageName, R.layout.widget) val views = RemoteViews(packageName, R.layout.widget)
views.setBackgroundColor(R.id.widget_holder, mBgColor) views.setBackgroundColor(R.id.widget_holder, mBgColor)
AppWidgetManager.getInstance(this).updateAppWidget(mWidgetId, views) AppWidgetManager.getInstance(this).updateAppWidget(mWidgetId, views)
val widget = Widget(null, mWidgetId, "/storage/emulated/0") val widget = Widget(null, mWidgetId, mFolderPath)
Thread { Thread {
widgetsDB.insertOrUpdate(widget) widgetsDB.insertOrUpdate(widget)
}.start() }.start()
@ -135,11 +132,13 @@ class WidgetConfigureActivity : SimpleActivity() {
private fun updateFolderImage(folderPath: String) { private fun updateFolderImage(folderPath: String) {
mFolderPath = folderPath mFolderPath = folderPath
val tmb = mDirectories.firstOrNull { it.path == folderPath }?.tmb Thread {
if (tmb != null) { val path = directoryDB.getDirectoryThumbnail(folderPath)
if (path != null) {
runOnUiThread { runOnUiThread {
loadJpg(tmb, config_image, true) loadJpg(path, config_image, true)
} }
} }
}.start()
} }
} }

View File

@ -107,6 +107,8 @@ val Context.galleryDB: GalleryDatabase get() = GalleryDatabase.getInstance(appli
val Context.widgetsDB: WidgetsDao get() = GalleryDatabase.getInstance(applicationContext).WidgetsDao() 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.recycleBin: File get() = filesDir
val Context.recycleBinPath: String get() = filesDir.absolutePath val Context.recycleBinPath: String get() = filesDir.absolutePath

View File

@ -29,4 +29,7 @@ interface DirectoryDao {
@Query("DELETE FROM directories WHERE path = \'$RECYCLE_BIN\' COLLATE NOCASE") @Query("DELETE FROM directories WHERE path = \'$RECYCLE_BIN\' COLLATE NOCASE")
fun deleteRecycleBin() fun deleteRecycleBin()
@Query("SELECT thumbnail FROM directories WHERE path = :path")
fun getDirectoryThumbnail(path: String): String?
} }