@@ -9,14 +9,13 @@ import androidx.annotation.DrawableRes
99import androidx.core.view.OnApplyWindowInsetsListener
1010import androidx.core.view.ViewCompat
1111import androidx.core.view.isVisible
12- import com.petterp.floatingx.FloatingX
1312import com.petterp.floatingx.config.FxHelper
14- import com.petterp.floatingx.ext.BarExt
1513import com.petterp.floatingx.ext.FxDebug
14+ import com.petterp.floatingx.ext.UiExt
15+ import com.petterp.floatingx.ext.fxParentView
1616import com.petterp.floatingx.ext.hide
17- import com.petterp.floatingx.ext.rootView
1817import com.petterp.floatingx.ext.show
19- import com.petterp.floatingx.listener.FxLifecycleCallback
18+ import com.petterp.floatingx.ext.topActivity
2019import com.petterp.floatingx.listener.IFxControl
2120import com.petterp.floatingx.view.FxMagnetView
2221import com.petterp.floatingx.view.FxViewHolder
@@ -33,7 +32,6 @@ open class FxControlImpl(private val helper: FxHelper) : IFxControl {
3332 private var managerView: FxMagnetView ? = null
3433 private var viewHolder: FxViewHolder ? = null
3534 private var mContainer: WeakReference <FrameLayout >? = null
36- internal var fxLifecycleCallback: FxLifecycleCallback ? = null
3735 private val managerViewOrContainerIsNull: Boolean
3836 get() = mContainer == null && managerView == null
3937
@@ -74,7 +72,7 @@ open class FxControlImpl(private val helper: FxHelper) : IFxControl {
7472 }
7573
7674 override fun attach (activity : Activity ) {
77- activity.rootView ?.let {
75+ activity.fxParentView ?.let {
7876 attach(it)
7977 }
8078 }
@@ -87,7 +85,9 @@ open class FxControlImpl(private val helper: FxHelper) : IFxControl {
8785 if (managerView == null ) {
8886 initManagerView()
8987 } else {
90- (managerView?.parent as ? ViewGroup )?.removeView(managerView)
88+ mContainer?.get()?.removeView(managerView)
89+ mContainer?.clear()
90+ mContainer = null
9191 }
9292 FxDebug .d(" view-lifecycle-> addView" )
9393 mContainer = WeakReference (container)
@@ -97,7 +97,7 @@ open class FxControlImpl(private val helper: FxHelper) : IFxControl {
9797 /* * 删除view */
9898 override fun detach (activity : Activity ) {
9999 if (managerViewOrContainerIsNull) return
100- activity.rootView ?.let {
100+ activity.fxParentView ?.let {
101101 detach(it)
102102 }
103103 }
@@ -107,7 +107,10 @@ open class FxControlImpl(private val helper: FxHelper) : IFxControl {
107107 FxDebug .d(" view-lifecycle-> removeView" )
108108 container.removeView(managerView)
109109 }
110- mContainer = null
110+ if (container == = mContainer?.get()) {
111+ mContainer?.clear()
112+ mContainer = null
113+ }
111114 }
112115
113116 override fun setClickListener (obj : (View ) -> Unit ) {
@@ -124,9 +127,9 @@ open class FxControlImpl(private val helper: FxHelper) : IFxControl {
124127 }
125128
126129 private fun showInit () {
127- if (getContainer() == null ) {
130+ if (getContainer() == null && topActivity != null ) {
128131 // 这里的异常还是要抛出去
129- attach(FloatingX . topActivity)
132+ attach(topActivity!! )
130133 return
131134 }
132135 if (managerView == null ) initManagerView()
@@ -149,8 +152,8 @@ open class FxControlImpl(private val helper: FxHelper) : IFxControl {
149152 @SuppressLint(" WrongConstant" )
150153 val windowsInsetsListener: OnApplyWindowInsetsListener =
151154 OnApplyWindowInsetsListener { _, insets ->
152- FxDebug .v(" System--StatusBar---old-(${BarExt .realStatusBarHeight } ),new-(${insets.systemWindowInsetTop} )" )
153- BarExt .realStatusBarHeight = insets.systemWindowInsetTop
155+ FxDebug .v(" System--StatusBar---old-(${UiExt .statsBarHeightConfig } ),new-(${insets.systemWindowInsetTop} )" )
156+ UiExt .statsBarHeightConfig = insets.systemWindowInsetTop
154157 insets
155158 }
156159
0 commit comments