Remove appbar offset listener when call log is unbound.

This commit is contained in:
Alex Hart 2024-07-17 10:34:09 -03:00 committed by Greyson Parrelli
parent 7f1227ee19
commit d0baf1dc95

View file

@ -80,8 +80,13 @@ class CallLogFragment : Fragment(R.layout.call_log_fragment), CallLogAdapter.Cal
private val TAG = Log.tag(CallLogFragment::class.java) private val TAG = Log.tag(CallLogFragment::class.java)
} }
private var filterViewOffsetChangeListener: AppBarLayout.OnOffsetChangedListener? = null
private val viewModel: CallLogViewModel by activityViewModels() private val viewModel: CallLogViewModel by activityViewModels()
private val binding: CallLogFragmentBinding by ViewBinderDelegate(CallLogFragmentBinding::bind) private val binding: CallLogFragmentBinding by ViewBinderDelegate(CallLogFragmentBinding::bind) {
binding.recyclerCoordinatorAppBar.removeOnOffsetChangedListener(filterViewOffsetChangeListener)
}
private val disposables = LifecycleDisposable() private val disposables = LifecycleDisposable()
private val callLogContextMenu = CallLogContextMenu(this, this) private val callLogContextMenu = CallLogContextMenu(this, this)
private val callLogActionMode = CallLogActionMode(CallLogActionModeCallback()) private val callLogActionMode = CallLogActionMode(CallLogActionModeCallback())
@ -328,11 +333,14 @@ class CallLogFragment : Fragment(R.layout.call_log_fragment), CallLogAdapter.Cal
} }
} }
binding.recyclerCoordinatorAppBar.addOnOffsetChangedListener { layout: AppBarLayout, verticalOffset: Int -> filterViewOffsetChangeListener = AppBarLayout.OnOffsetChangedListener {
layout: AppBarLayout, verticalOffset: Int ->
val progress = 1 - verticalOffset.toFloat() / -layout.height val progress = 1 - verticalOffset.toFloat() / -layout.height
binding.pullView.onUserDrag(progress) binding.pullView.onUserDrag(progress)
} }
binding.recyclerCoordinatorAppBar.addOnOffsetChangedListener(filterViewOffsetChangeListener)
if (viewModel.filterSnapshot != CallLogFilter.ALL) { if (viewModel.filterSnapshot != CallLogFilter.ALL) {
binding.root.doAfterNextLayout { binding.root.doAfterNextLayout {
binding.pullView.openImmediate() binding.pullView.openImmediate()