Updated showing / hiding filters

This commit is contained in:
Viktor De Pasquale 2019-11-21 17:35:29 +01:00
parent 67c50d7504
commit 550f6aff7e
2 changed files with 23 additions and 12 deletions

View File

@ -33,6 +33,13 @@ class HideFragment : CompatFragment<HideViewModel, FragmentHideMd2Binding>() {
override val layoutRes = R.layout.fragment_hide_md2 override val layoutRes = R.layout.fragment_hide_md2
override val viewModel by viewModel<HideViewModel>() override val viewModel by viewModel<HideViewModel>()
private var isFilterVisible
get() = binding.hideFilter.isVisible
set(value) {
if (!value) hideKeyboard()
MotionRevealHelper.withViews(binding.hideFilter, binding.hideFilterToggle, value)
}
override fun consumeSystemWindowInsets(insets: Insets) = insets override fun consumeSystemWindowInsets(insets: Insets) = insets
override fun onAttach(context: Context) { override fun onAttach(context: Context) {
@ -45,11 +52,10 @@ class HideFragment : CompatFragment<HideViewModel, FragmentHideMd2Binding>() {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
binding.hideFilterToggle.setOnClickListener { binding.hideFilterToggle.setOnClickListener {
MotionRevealHelper.withViews(binding.hideFilter, binding.hideFilterToggle, true) isFilterVisible = true
} }
binding.hideFilterInclude.hideFilterDone.setOnClickListener { binding.hideFilterInclude.hideFilterDone.setOnClickListener {
hideKeyboard() isFilterVisible = false
MotionRevealHelper.withViews(binding.hideFilter, binding.hideFilterToggle, false)
} }
binding.hideContent.addOnScrollListener(object : RecyclerView.OnScrollListener() { binding.hideContent.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) { override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
@ -64,8 +70,8 @@ class HideFragment : CompatFragment<HideViewModel, FragmentHideMd2Binding>() {
override fun onPreBind(binding: FragmentHideMd2Binding) = Unit override fun onPreBind(binding: FragmentHideMd2Binding) = Unit
override fun onBackPressed(): Boolean { override fun onBackPressed(): Boolean {
if (binding.hideFilter.isVisible) { if (isFilterVisible) {
binding.hideFilterInclude.hideFilterDone.performClick() isFilterVisible = false
return true return true
} }
return super.onBackPressed() return super.onBackPressed()

View File

@ -29,6 +29,14 @@ class ModuleFragment : CompatFragment<ModuleViewModel, FragmentModuleMd2Binding>
private val listeners = hashSetOf<EndlessRecyclerScrollListener>() private val listeners = hashSetOf<EndlessRecyclerScrollListener>()
private var isFilterVisible
get() = binding.moduleFilter.isVisible
set(value) {
if (!value) hideKeyboard()
(activity as? MainActivity)?.requestNavigationHidden(value)
MotionRevealHelper.withViews(binding.moduleFilter, binding.moduleFilterToggle, value)
}
override fun consumeSystemWindowInsets(insets: Insets) = insets override fun consumeSystemWindowInsets(insets: Insets) = insets
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
@ -48,13 +56,10 @@ class ModuleFragment : CompatFragment<ModuleViewModel, FragmentModuleMd2Binding>
setEndlessSearch() setEndlessSearch()
binding.moduleFilterToggle.setOnClickListener { binding.moduleFilterToggle.setOnClickListener {
(activity as? MainActivity)?.requestNavigationHidden() isFilterVisible = true
MotionRevealHelper.withViews(binding.moduleFilter, binding.moduleFilterToggle, true)
} }
binding.moduleFilterInclude.moduleFilterDone.setOnClickListener { binding.moduleFilterInclude.moduleFilterDone.setOnClickListener {
(activity as? MainActivity)?.requestNavigationHidden(false) isFilterVisible = false
hideKeyboard()
MotionRevealHelper.withViews(binding.moduleFilter, binding.moduleFilterToggle, false)
} }
binding.moduleFilterInclude.moduleFilterList.addOnScrollListener(object : binding.moduleFilterInclude.moduleFilterList.addOnScrollListener(object :
RecyclerView.OnScrollListener() { RecyclerView.OnScrollListener() {
@ -73,8 +78,8 @@ class ModuleFragment : CompatFragment<ModuleViewModel, FragmentModuleMd2Binding>
} }
override fun onBackPressed(): Boolean { override fun onBackPressed(): Boolean {
if (binding.moduleFilter.isVisible) { if (isFilterVisible) {
binding.moduleFilterInclude.moduleFilterDone.performClick() isFilterVisible = false
return true return true
} }
return super.onBackPressed() return super.onBackPressed()