Skip to content

Commit

Permalink
Prevent view ID conflict/crash by multiplying each generated view ID …
Browse files Browse the repository at this point in the history
…by a prime number (#2588)

* Multiply each ID by a prime number to increase chances of uniqueness

* Format files.
  • Loading branch information
sufyanAbbasi authored Aug 1, 2024
1 parent cb73c59 commit da84209
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ class CaptureLocationTaskFragment : AbstractTaskFragment<CaptureLocationTaskView
TaskViewFactory.createWithCombinedHeader(inflater, R.drawable.outline_pin_drop)

override fun onCreateTaskBody(inflater: LayoutInflater): View {
val rowLayout = LinearLayout(requireContext()).apply { id = View.generateViewId() }
// NOTE(#2493): Multiplying by a random prime to allow for some mathematical uniqueness.
// Otherwise, the sequentially generated ID might conflict with an ID produced by Google Maps.
val rowLayout = LinearLayout(requireContext()).apply { id = View.generateViewId() * 11149 }
parentFragmentManager
.beginTransaction()
.add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ class DropPinTaskFragment : AbstractTaskFragment<DropPinTaskViewModel>() {
TaskViewFactory.createWithCombinedHeader(inflater, R.drawable.outline_pin_drop)

override fun onCreateTaskBody(inflater: LayoutInflater): View {
val rowLayout = LinearLayout(requireContext()).apply { id = View.generateViewId() }
// NOTE(#2493): Multiplying by a random prime to allow for some mathematical "uniqueness".
// Otherwise, the sequentially generated ID might conflict with an ID produced by Google Maps.
val rowLayout = LinearLayout(requireContext()).apply { id = View.generateViewId() * 11617 }
parentFragmentManager
.beginTransaction()
.add(rowLayout.id, DropPinTaskMapFragment.newInstance(viewModel, map), "Drop a pin fragment")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ class DrawAreaTaskFragment : AbstractTaskFragment<DrawAreaTaskViewModel>() {
TaskViewFactory.createWithCombinedHeader(inflater, R.drawable.outline_draw)

override fun onCreateTaskBody(inflater: LayoutInflater): View {
val rowLayout = LinearLayout(requireContext()).apply { id = View.generateViewId() }
// NOTE(#2493): Multiplying by a random prime to allow for some mathematical "uniqueness".
// Otherwise, the sequentially generated ID might conflict with an ID produced by Google Maps.
val rowLayout = LinearLayout(requireContext()).apply { id = View.generateViewId() * 11411 }
drawAreaTaskMapFragment = DrawAreaTaskMapFragment.newInstance(viewModel, map)
parentFragmentManager
.beginTransaction()
Expand Down

0 comments on commit da84209

Please sign in to comment.