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

This commit is contained in:
曾祥俊
2024-08-20 14:02:02 +08:00
parent cb093cc3f0
commit 2be52d21ee
3 changed files with 10 additions and 3 deletions

View File

@ -93,6 +93,8 @@ class NDownloadSuspendWindowController(private val application: Application) :
private fun onDetachFromUi() {
closeWindow.detach()
iconWindow.detach()
iconWindow.setOnDragListener(null)
iconWindow.setOnIconClickListener(null)
}
private fun initDownloadCount() {

View File

@ -109,7 +109,7 @@ class NDownloadSuspendIconView @JvmOverloads constructor(
addView(it, layoutParams)
}
fun setOnIconClickListener(listener: OnIconClickListener) {
fun setOnIconClickListener(listener: OnIconClickListener?) {
this.onIconClickListener = listener
}

View File

@ -71,8 +71,14 @@ class NDownloadSuspendIconWindow(context: Context, suspend: Boolean = true, priv
this.onDragListener = onDragListener
}
override fun onAttach() {
super.onAttach()
if (draggable) root.setOnDragListener(this)
}
override fun onDetach() {
root.removeCallbacks(initRunnable)
if (draggable) root.setOnDragListener(null)
edgeAnimator.removeAllUpdateListeners()
edgeAnimator.removeAllListeners()
edgeAnimator.cancel()
@ -81,7 +87,6 @@ class NDownloadSuspendIconWindow(context: Context, suspend: Boolean = true, priv
@SuppressLint("InflateParams")
override fun onCreateView(context: Context): NDownloadSuspendIconLayout =
NDownloadSuspendIconLayout(context).also {
if (draggable) it.setOnDragListener(this)
it.clipChildren = false
it.clipToPadding = false
}
@ -136,7 +141,7 @@ class NDownloadSuspendIconWindow(context: Context, suspend: Boolean = true, priv
root.icon.setDownloadIconUrl(url)
}
fun setOnIconClickListener(listener: NDownloadSuspendIconView.OnIconClickListener) {
fun setOnIconClickListener(listener: NDownloadSuspendIconView.OnIconClickListener?) {
root.icon.setOnIconClickListener(listener)
}