Skip to content

Document binding adapter usage and performance characteristics#274

Closed
Copilot wants to merge 1 commit intocamera-zoom-below-1.0from
copilot/sub-pr-273
Closed

Document binding adapter usage and performance characteristics#274
Copilot wants to merge 1 commit intocamera-zoom-below-1.0from
copilot/sub-pr-273

Conversation

Copy link
Contributor

Copilot AI commented Feb 7, 2026

Addresses review feedback on the slider crash fix: explains how the custom binding adapter is invoked and its performance impact.

How the Binding Adapter Works

The setSliderValueWithRange adapter is automatically invoked by Android's data binding framework when a Slider has all three attributes bound:

<com.google.android.material.slider.Slider
    android:value="@={viewmodel.zoomRatio}"
    android:valueFrom="@{viewmodel.zoomRatioRange.lower}"
    android:valueTo="@{viewmodel.zoomRatioRange.upper}" />

When any LiveData value changes (e.g., camera switch updates zoom range), the framework calls the adapter to atomically update all three properties in the correct order: range first, then value.

Performance Impact

Minimal overhead:

  • Only executes on LiveData changes, not per-frame
  • Early exits on null/uninitialized data
  • Equality checks (lines 65, 68, 74) prevent redundant setter calls
  • More efficient than default behavior (prevents multiple update cycles + potential crash)

Related


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Address feedback on app crash fix for camera zoom slider Document binding adapter usage and performance characteristics Feb 7, 2026
Copilot AI requested a review from dimadesu February 7, 2026 07:14
@dimadesu
Copy link
Owner

dimadesu commented Feb 7, 2026

@copilot so in case of my LifeStreamer app where or when exactly would this be called?

Copy link
Contributor Author

Copilot AI commented Feb 7, 2026

@copilot so in case of my LifeStreamer app where or when exactly would this be called?

The binding adapter is called automatically by the data binding framework when LiveData values change. Here are the specific moments in your app:

1. Camera Switch/Selection (lines 354, 2429 in PreviewViewModel.kt)

  • User taps a camera button → setCameraId() or setNextCameraId() is called
  • Video source changes → observeStreamerFlows() detects it (line 1181)
  • notifyCameraChanged() is triggered (line 3740)
  • Lines 3777-3778 execute:
    zoomRatioRange.postValue(settings.zoom.availableRatioRange)  // e.g., Range(0.6, 8.0)
    zoomRatio = 1.0f
  • Data binding sees all 3 values changing → setSliderValueWithRange() is called
  • Adapter sets range [0.6, 8.0] first, then value 1.0 (avoiding crash)

2. App Startup

  • When the camera first initializes, same flow happens through notifyCameraChanged()

3. User Sliding the Zoom Slider

  • User drags slider → only zoomRatio changes (line 3644 setter)
  • Data binding calls the standard individual setter (not your custom adapter)
  • The custom adapter only runs when all 3 attributes update together

Without the adapter, camera switches to ultra-wide cameras would crash because data binding might update zoomRatio=0.6 before zoomRatioRange updates to [0.6, 8.0].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants