From 2de23696002c17cfdf1eb6330e176feec85dae5d Mon Sep 17 00:00:00 2001 From: darken Date: Tue, 25 Jan 2022 12:06:09 +0100 Subject: [PATCH] Fix popup window overdraw --- .../capod/reaction/popup/ui/PopUpWindow.kt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/eu/darken/capod/reaction/popup/ui/PopUpWindow.kt b/app/src/main/java/eu/darken/capod/reaction/popup/ui/PopUpWindow.kt index c4441a85..2180e26e 100644 --- a/app/src/main/java/eu/darken/capod/reaction/popup/ui/PopUpWindow.kt +++ b/app/src/main/java/eu/darken/capod/reaction/popup/ui/PopUpWindow.kt @@ -42,16 +42,17 @@ class PopUpWindow @Inject constructor( findViewById(R.id.close_action).setOnClickListener { close() } } private val deviceContainer = popUpView.findViewById(R.id.popup_content) - fun show(device: PodDevice) = try { log(TAG) { "open()" } - if (popUpView.windowToken == null && popUpView.parent == null) { - val podView = podViewFactory.createContentView(deviceContainer, device) - deviceContainer.addView(podView) - windowManager.addView(popUpView, layoutParams) - } else { + if (popUpView.windowToken != null || popUpView.parent != null) { log(TAG) { "View already added." } + close() } + + val podView = podViewFactory.createContentView(deviceContainer, device) + deviceContainer.removeAllViews() + deviceContainer.addView(podView) + windowManager.addView(popUpView, layoutParams) } catch (e: Exception) { log(TAG, ERROR) { "open() failed: ${e.asLog()}" } } @@ -59,9 +60,8 @@ class PopUpWindow @Inject constructor( fun close() = try { log(TAG) { "close()" } if (popUpView.parent != null) { -// (popUpView.parent as ViewGroup).removeAllViews() -// popUpView.invalidate() windowManager.removeView(popUpView) + deviceContainer.removeAllViews() } else { log(TAG) { "View was not added" } }