Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 95597a36 authored by Abhishek Aggarwal's avatar Abhishek Aggarwal
Browse files

fix(widget): Remove widgets not present in db

parent 8da29181
Loading
Loading
Loading
Loading
+11 −4
Original line number Diff line number Diff line
@@ -240,10 +240,17 @@ class WidgetContainer(context: Context, attrs: AttributeSet?) : FrameLayout(cont
        private fun rebindWidgets(backup: Boolean = false) {
            mWrapper.removeAllViews()
            if (!backup) {
                widgetsDbHelper
                    .getWidgets()
                    .sortedBy { it.position }
                    .forEach { addView(it.widgetId) }

                val dbWidgets =
                    widgetsDbHelper.getWidgets().apply {
                        sortedBy { it.position }
                        forEach { addView(it.widgetId) }
                    }

                // Remove all widgets not present in db
                mWidgetHost.appWidgetIds
                    .filter { id -> dbWidgets.all { info -> info.widgetId != id } }
                    .forEach { mWidgetHost.deleteAppWidgetId(it) }
            } else {
                if (mOldWidgets.isNotEmpty()) {
                    mOldWidgets