Merge branch 'fix/sentry-404504' into 'release'

fix: 悬浮窗Detach时机问题造成的崩溃

See merge request halo/android/assistant-android!1839
This commit is contained in:
曾祥俊
2024-08-16 14:04:09 +08:00
2 changed files with 11 additions and 4 deletions

View File

@ -71,9 +71,10 @@ class NDownloadSuspendIconWindow(context: Context, suspend: Boolean = true, priv
this.onDragListener = onDragListener
}
override fun detach() {
super.detach()
override fun onDetach() {
root.removeCallbacks(initRunnable)
edgeAnimator.removeAllUpdateListeners()
edgeAnimator.removeAllListeners()
edgeAnimator.cancel()
}

View File

@ -46,22 +46,28 @@ abstract class NDownloadSuspendWindow<T : View>(
onViewCreated(it)
}
open fun attach() {
fun attach() {
if (!isAttached) {
_isAttached = true
windowManager.addView(root, layoutParams)
context.registerComponentCallbacks(this)
onAttach()
}
}
open fun detach() {
fun detach() {
if (isAttached) {
_isAttached = false
onDetach()
context.unregisterComponentCallbacks(this)
windowManager.removeView(root)
}
}
protected open fun onAttach() = Unit
protected open fun onDetach() = Unit
protected open fun onViewCreated(view: T) = Unit
override fun onConfigurationChanged(configuration: Configuration) = Unit