Skip to content

Commit

Permalink
Fixed updating appbar color in viewpager
Browse files Browse the repository at this point in the history
  • Loading branch information
grzesiek2010 committed Sep 2, 2024
1 parent 550892d commit d2250b6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
7 changes: 4 additions & 3 deletions androidshared/src/main/res/layout/app_bar_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
whether it should lift by setting `app:liftOnScrollTargetViewId` to the ID of the scrolling view.
Since this `AppBarLayout` is used throughout the app with various scrolling views, it’s best to
use a shared ID like `scrollable_container`.
If the scrollable view is added programmatically, it may not work as expected anyway, and
`app:liftOnScrollTargetViewId` might need to be updated programmatically after adding such a view.
The `ODKView` and its `odk_view_container` is a good example of this scenario.
If the scrollable view is added programmatically or it is displayed in a `ViewPager` with a
shared id, it may not work as expected anyway, and `app:liftOnScrollTargetViewId` might
need to be updated programmatically after adding such a view.
The `ODKView` and its `odk_view_container` or `DeleteFormsActivity` are good examples of this scenario.
-->
<com.google.android.material.appbar.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import androidx.fragment.app.viewModels
import androidx.lifecycle.Lifecycle.State
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.map
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import org.odk.collect.android.R
import org.odk.collect.androidshared.ui.FragmentFactoryBuilder
Expand Down Expand Up @@ -42,6 +44,8 @@ class DeleteBlankFormFragment(
}
)
}
private lateinit var appBarLayout: AppBarLayout
private lateinit var list: RecyclerView

override fun onAttach(context: Context) {
super.onAttach(context)
Expand All @@ -57,7 +61,8 @@ class DeleteBlankFormFragment(
it.empty.setTitle(getString(string.empty_list_of_forms_to_delete_title))
it.empty.setSubtitle(getString(string.empty_list_of_blank_forms_to_delete_subtitle))

it.list.addItemDecoration(RecyclerViewUtils.verticalLineDivider(context))
list = it.list
list.addItemDecoration(RecyclerViewUtils.verticalLineDivider(context))
}
}
.build()
Expand All @@ -80,11 +85,17 @@ class DeleteBlankFormFragment(
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
appBarLayout = requireActivity().findViewById(org.odk.collect.androidshared.R.id.appBarLayout)
val blankFormListMenuProvider =
BlankFormListMenuProvider(requireActivity(), blankFormListViewModel)
menuHost.addMenuProvider(blankFormListMenuProvider, viewLifecycleOwner, State.RESUMED)
}

override fun onResume() {
super.onResume()
appBarLayout.setLiftOnScrollTargetView(list)
}

private fun onDeleteSelected(selected: LongArray) {
MaterialAlertDialogBuilder(requireContext())
.setTitle(string.delete_file)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import androidx.fragment.app.viewModels
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.map
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import org.odk.collect.analytics.Analytics
import org.odk.collect.android.R
Expand Down Expand Up @@ -46,6 +48,8 @@ class DeleteSavedFormFragment(
}
)
}
private lateinit var appBarLayout: AppBarLayout
private lateinit var list: RecyclerView

override fun onAttach(context: Context) {
super.onAttach(context)
Expand All @@ -61,7 +65,8 @@ class DeleteSavedFormFragment(
it.empty.setTitle(getString(string.empty_list_of_forms_to_delete_title))
it.empty.setSubtitle(getString(string.empty_list_of_saved_forms_to_delete_subtitle))

it.list.addItemDecoration(RecyclerViewUtils.verticalLineDivider(context))
list = it.list
list.addItemDecoration(RecyclerViewUtils.verticalLineDivider(context))
}
}
.build()
Expand All @@ -88,6 +93,7 @@ class DeleteSavedFormFragment(
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
appBarLayout = requireActivity().findViewById(org.odk.collect.androidshared.R.id.appBarLayout)
menuHost?.addMenuProvider(
SavedFormListListMenuProvider(requireContext(), savedFormListViewModel),
viewLifecycleOwner,
Expand All @@ -105,6 +111,11 @@ class DeleteSavedFormFragment(
}
}

override fun onResume() {
super.onResume()
appBarLayout.setLiftOnScrollTargetView(list)
}

private fun onDeleteSelected(selected: LongArray) {
MaterialAlertDialogBuilder(requireContext())
.setTitle(string.delete_file)
Expand Down

0 comments on commit d2250b6

Please sign in to comment.