6.6.2 - Alpha4 - 修复 ExplorerFragment 的 binding 对象未及时回收问题
This commit is contained in:
@@ -1,22 +1,32 @@
|
||||
package org.autojs.autojs.ui.fragment
|
||||
|
||||
import androidx.fragment.app.Fragment
|
||||
import android.view.View
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.DefaultLifecycleObserver
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import kotlin.properties.ReadOnlyProperty
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
object BindingDelegates {
|
||||
|
||||
fun <T> Fragment.viewBinding(bindView: (View) -> T) = object : ReadOnlyProperty<Fragment, T> {
|
||||
// @Created by JetBrains AI Assistant on Mar 12, 2025.
|
||||
// @Modified by JetBrains AI Assistant as of Mar 13, 2025.
|
||||
inline fun <reified T : ViewBinding> Fragment.viewBinding(crossinline bindView: (View) -> T) = object : ReadOnlyProperty<Fragment, T> {
|
||||
|
||||
private var binding: T? = null
|
||||
|
||||
override fun getValue(thisRef: Fragment, property: KProperty<*>): T {
|
||||
return binding ?: bindView(thisRef.requireView()).also { binding = it }
|
||||
return binding ?: bindView(requireView()).also {
|
||||
binding = it
|
||||
|
||||
viewLifecycleOwner.lifecycle.addObserver(object : DefaultLifecycleObserver {
|
||||
override fun onDestroy(owner: LifecycleOwner) {
|
||||
binding = null
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
override fun toString() = "Binding for ${this@viewBinding.javaClass.name}: $binding"
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -42,21 +42,22 @@ import org.greenrobot.eventbus.Subscribe
|
||||
* Modified by SuperMonster003 as of Mar 20, 2022.
|
||||
* Transformed by SuperMonster003 on Mar 31, 2023.
|
||||
*/
|
||||
open class ExplorerFragment : ViewPagerFragment(0), OnFloatingActionButtonClickListener, ViewStatesManageable {
|
||||
class ExplorerFragment : ViewPagerFragment(0), OnFloatingActionButtonClickListener, ViewStatesManageable {
|
||||
|
||||
private var mBottomInset: Int = 0
|
||||
private val binding by viewBinding(FragmentExplorerBinding::bind)
|
||||
|
||||
private var mExplorerView: ExplorerView? = null
|
||||
private var mFloatingActionMenu: FloatingActionMenu? = null
|
||||
private var mIsCurrentPageFiles = false
|
||||
|
||||
private var mBottomInset: Int = 0
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
EventBus.getDefault().register(this)
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||
return FragmentExplorerBinding.inflate(inflater, container, false).root
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user