properly remove the widget ID from the database on deletion

This commit is contained in:
tibbi 2018-12-16 20:55:56 +01:00
parent 069d991fac
commit 9e2847fb8f
2 changed files with 12 additions and 4 deletions

View File

@ -30,9 +30,8 @@ class MyWidgetProvider : AppWidgetProvider() {
override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) {
super.onUpdate(context, appWidgetManager, appWidgetIds)
Thread {
val widgets = context.widgetsDB.getWidgets()
val config = context.config
widgets.forEach {
context.widgetsDB.getWidgets().forEach {
val views = RemoteViews(context.packageName, R.layout.widget).apply {
setBackgroundColor(R.id.widget_holder, config.widgetBgColor)
setVisibleIf(R.id.widget_folder_name, config.showWidgetFolderName)
@ -61,4 +60,13 @@ class MyWidgetProvider : AppWidgetProvider() {
}
}.start()
}
override fun onDeleted(context: Context, appWidgetIds: IntArray) {
super.onDeleted(context, appWidgetIds)
Thread {
appWidgetIds.forEach {
context.widgetsDB.deleteWidgetId(it)
}
}.start()
}
}

View File

@ -14,6 +14,6 @@ interface WidgetsDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertOrUpdate(widget: Widget): Long
@Query("DELETE FROM widgets WHERE folder_path = :folderPath")
fun deleteNoteWidgets(folderPath: String)
@Query("DELETE FROM widgets WHERE widget_id = :widgetId")
fun deleteWidgetId(widgetId: Int)
}