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

Commit d7b478ff authored by Abhishek Aggarwal's avatar Abhishek Aggarwal Committed by Saalim Quadri
Browse files

fix(widget): Remove widgets not present in db



[SahilSonar - adapted to A14]

Signed-off-by: default avatarSahilSonar <sss.sonar2003@gmail.com>
Signed-off-by: default avatarSaalim Quadri <danascape@gmail.com>
parent 6b2b91bb
Loading
Loading
Loading
Loading
+11 −4
Original line number Diff line number Diff line
@@ -255,10 +255,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