diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a33b0c153..883b24d4c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -215,6 +215,15 @@ + + + + + + + + + + + + + + + if (wasPositivePressed) { + mBgColorWithoutTransparency = color + updateBackgroundColor() + } + } + } +} 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 d7430f161..2e7cdb0a3 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 @@ -25,6 +25,7 @@ import com.simplemobiletools.gallery.pro.databases.GalleryDatabase import com.simplemobiletools.gallery.pro.helpers.* import com.simplemobiletools.gallery.pro.interfaces.DirectoryDao import com.simplemobiletools.gallery.pro.interfaces.MediumDao +import com.simplemobiletools.gallery.pro.interfaces.WidgetsDao import com.simplemobiletools.gallery.pro.models.Directory import com.simplemobiletools.gallery.pro.models.Medium import com.simplemobiletools.gallery.pro.models.ThumbnailItem @@ -104,6 +105,8 @@ val Context.config: Config get() = Config.newInstance(applicationContext) val Context.galleryDB: GalleryDatabase get() = GalleryDatabase.getInstance(applicationContext) +val Context.widgetsDB: WidgetsDao get() = GalleryDatabase.getInstance(applicationContext).WidgetsDao() + val Context.recycleBin: File get() = filesDir val Context.recycleBinPath: String get() = filesDir.absolutePath diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MyWidgetProvider.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MyWidgetProvider.kt new file mode 100644 index 000000000..08ef3081c --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MyWidgetProvider.kt @@ -0,0 +1,37 @@ +package com.simplemobiletools.gallery.pro.helpers + +import android.app.PendingIntent +import android.appwidget.AppWidgetManager +import android.appwidget.AppWidgetProvider +import android.content.Context +import android.content.Intent +import android.widget.RemoteViews +import com.simplemobiletools.commons.extensions.setBackgroundColor +import com.simplemobiletools.gallery.pro.R +import com.simplemobiletools.gallery.pro.activities.MediaActivity +import com.simplemobiletools.gallery.pro.extensions.config +import com.simplemobiletools.gallery.pro.extensions.widgetsDB +import com.simplemobiletools.gallery.pro.models.Widget + +class MyWidgetProvider : AppWidgetProvider() { + private fun setupAppOpenIntent(context: Context, views: RemoteViews, id: Int, widget: Widget) { + val intent = Intent(context, MediaActivity::class.java).apply { + putExtra(DIRECTORY, widget.folderPath) + } + + val pendingIntent = PendingIntent.getActivity(context, widget.widgetId, intent, PendingIntent.FLAG_UPDATE_CURRENT) + views.setOnClickPendingIntent(id, pendingIntent) + } + + override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) { + super.onUpdate(context, appWidgetManager, appWidgetIds) + Thread { + context.widgetsDB.getWidgets().forEach { + val views = RemoteViews(context.packageName, R.layout.widget) + views.setBackgroundColor(R.id.widget_holder, context.config.widgetBgColor) + setupAppOpenIntent(context, views, R.id.widget_holder, it) + appWidgetManager.updateAppWidget(it.widgetId, views) + } + }.start() + } +} diff --git a/app/src/main/res/layout/widget.xml b/app/src/main/res/layout/widget.xml new file mode 100644 index 000000000..2be9e64d5 --- /dev/null +++ b/app/src/main/res/layout/widget.xml @@ -0,0 +1,14 @@ + + + + + + diff --git a/app/src/main/res/layout/widget_config.xml b/app/src/main/res/layout/widget_config.xml new file mode 100644 index 000000000..1b36ee583 --- /dev/null +++ b/app/src/main/res/layout/widget_config.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + +