From abb0a69f7a32935f53a9f68742695f7438a21d01 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 16 Dec 2018 16:50:10 +0100 Subject: [PATCH] add handling for widget folder picking --- .../pro/activities/WidgetConfigureActivity.kt | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 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 899f59629..22c10231d 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 @@ -10,11 +10,13 @@ import android.widget.RemoteViews 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.helpers.MyWidgetProvider +import com.simplemobiletools.gallery.pro.models.Directory import com.simplemobiletools.gallery.pro.models.Widget import kotlinx.android.synthetic.main.widget_config.* @@ -23,6 +25,8 @@ class WidgetConfigureActivity : SimpleActivity() { private var mWidgetId = 0 private var mBgColor = 0 private var mBgColorWithoutTransparency = 0 + private var mFolderPath = "" + private var mDirectories = ArrayList() public override fun onCreate(savedInstanceState: Bundle?) { useDynamicTheme = false @@ -39,16 +43,17 @@ class WidgetConfigureActivity : SimpleActivity() { config_save.setOnClickListener { saveConfig() } config_bg_color.setOnClickListener { pickBackgroundColor() } + folder_picker_value.setOnClickListener { changeSelectedFolder() } + config_image_holder.setOnClickListener { changeSelectedFolder() } config_save.setTextColor(getAdjustedPrimaryColor()) updateTextColors(folder_picker_holder) folder_picker_holder.background = ColorDrawable(config.backgroundColor) getCachedDirectories(false, false) { - val path = it.firstOrNull()?.tmb + mDirectories = it + val path = it.firstOrNull()?.path if (path != null) { - runOnUiThread { - loadJpg(path, config_image, true) - } + updateFolderImage(path) } } } @@ -121,4 +126,20 @@ class WidgetConfigureActivity : SimpleActivity() { } } } + + private fun changeSelectedFolder() { + PickDirectoryDialog(this, mFolderPath) { + updateFolderImage(it) + } + } + + private fun updateFolderImage(folderPath: String) { + mFolderPath = folderPath + val tmb = mDirectories.firstOrNull { it.path == folderPath }?.tmb + if (tmb != null) { + runOnUiThread { + loadJpg(tmb, config_image, true) + } + } + } }