add handling for widget folder picking

This commit is contained in:
tibbi 2018-12-16 16:50:10 +01:00
parent ba4b120dfe
commit abb0a69f7a

View file

@ -10,11 +10,13 @@ import android.widget.RemoteViews
import com.simplemobiletools.commons.dialogs.ColorPickerDialog 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.extensions.config import com.simplemobiletools.gallery.pro.extensions.config
import com.simplemobiletools.gallery.pro.extensions.getCachedDirectories import com.simplemobiletools.gallery.pro.extensions.getCachedDirectories
import com.simplemobiletools.gallery.pro.extensions.loadJpg import com.simplemobiletools.gallery.pro.extensions.loadJpg
import com.simplemobiletools.gallery.pro.extensions.widgetsDB 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.Widget import com.simplemobiletools.gallery.pro.models.Widget
import kotlinx.android.synthetic.main.widget_config.* import kotlinx.android.synthetic.main.widget_config.*
@ -23,6 +25,8 @@ class WidgetConfigureActivity : SimpleActivity() {
private var mWidgetId = 0 private var mWidgetId = 0
private var mBgColor = 0 private var mBgColor = 0
private var mBgColorWithoutTransparency = 0 private var mBgColorWithoutTransparency = 0
private var mFolderPath = ""
private var mDirectories = ArrayList<Directory>()
public override fun onCreate(savedInstanceState: Bundle?) { public override fun onCreate(savedInstanceState: Bundle?) {
useDynamicTheme = false useDynamicTheme = false
@ -39,16 +43,17 @@ class WidgetConfigureActivity : SimpleActivity() {
config_save.setOnClickListener { saveConfig() } config_save.setOnClickListener { saveConfig() }
config_bg_color.setOnClickListener { pickBackgroundColor() } config_bg_color.setOnClickListener { pickBackgroundColor() }
folder_picker_value.setOnClickListener { changeSelectedFolder() }
config_image_holder.setOnClickListener { changeSelectedFolder() }
config_save.setTextColor(getAdjustedPrimaryColor()) config_save.setTextColor(getAdjustedPrimaryColor())
updateTextColors(folder_picker_holder) updateTextColors(folder_picker_holder)
folder_picker_holder.background = ColorDrawable(config.backgroundColor) folder_picker_holder.background = ColorDrawable(config.backgroundColor)
getCachedDirectories(false, false) { getCachedDirectories(false, false) {
val path = it.firstOrNull()?.tmb mDirectories = it
val path = it.firstOrNull()?.path
if (path != null) { if (path != null) {
runOnUiThread { updateFolderImage(path)
loadJpg(path, config_image, true)
}
} }
} }
} }
@ -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)
}
}
}
} }