fix: 悬浮窗Detach时机问题造成的崩溃2
This commit is contained in:
@ -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() {
|
||||
|
||||
@ -109,7 +109,7 @@ class NDownloadSuspendIconView @JvmOverloads constructor(
|
||||
addView(it, layoutParams)
|
||||
}
|
||||
|
||||
fun setOnIconClickListener(listener: OnIconClickListener) {
|
||||
fun setOnIconClickListener(listener: OnIconClickListener?) {
|
||||
this.onIconClickListener = listener
|
||||
}
|
||||
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user