Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 23c2fae8 authored by Matt Casey's avatar Matt Casey
Browse files

Fix scroll capture in infinite scroll apps

Previously it would be scrolling down looking for a boundary but not
stop if it hit the max tile count, which would break the scroll capture
system. In reality, if it *ever* hits max tile count, there's nothing
more to be done.

Also added more debug logging to help diagnose any issues.

Unit testing to come in after ag/13766690 lands.

Bug: 182044708
Test: Verify output at the bottom, top and middle of a finite scroll
(Settings), verify output in infinite scroll (Reddit).

Change-Id: I0e70c554f9d4b3ebab4e9cf1003751a44aa5a81e
parent 156864ee
Loading
Loading
Loading
Loading
+11 −4
Original line number Diff line number Diff line
@@ -88,7 +88,7 @@ public class ScrollCaptureController {
    }

    private void onCaptureResult(CaptureResult result) {
        Log.d(TAG, "onCaptureResult: " + result + " scrolling up: " + mScrollingUp
        Log.d(TAG, "onCaptureResult: " + result + " scrolling " + (mScrollingUp ? "UP" : "DOWN")
                + " finish on boundary: " + mFinishOnBoundary);
        boolean emptyResult = result.captured.height() == 0;
        boolean partialResult = !emptyResult
@@ -98,6 +98,7 @@ public class ScrollCaptureController {
        if (partialResult || emptyResult) {
            // Potentially reached a vertical boundary. Extend in the other direction.
            if (mFinishOnBoundary) {
                Log.d(TAG, "Partial/empty: finished!");
                finish = true;
            } else {
                // We hit a boundary, clear the tiles, capture everything in the opposite direction,
@@ -105,16 +106,22 @@ public class ScrollCaptureController {
                mImageTileSet.clear();
                mFinishOnBoundary = true;
                mScrollingUp = !mScrollingUp;
                Log.d(TAG, "Partial/empty: cleared, switch direction to finish");
            }
        } else {
            // Got the full requested result, but may have got enough bitmap data now
            int expectedTiles = mImageTileSet.size() + 1;
            boolean hitMaxTiles = expectedTiles >= mSession.getMaxTiles();
            if (hitMaxTiles && mFinishOnBoundary) {
            if (expectedTiles >= mSession.getMaxTiles()) {
                Log.d(TAG, "Hit max tiles: finished");
                // If we ever hit the max tiles, we've got enough bitmap data to finish (even if we
                // weren't sure we'd finish on this pass).
                finish = true;
            } else {
                if (mScrollingUp) {
                if (mScrollingUp && !mFinishOnBoundary) {
                    // During the initial scroll up, we only want to acquire the portion described
                    // by IDEAL_PORTION_ABOVE.
                    if (expectedTiles >= mSession.getMaxTiles() * IDEAL_PORTION_ABOVE) {
                        Log.d(TAG, "Hit ideal portion above: clear and switch direction");
                        // We got enough above the start point, now see how far down it can go.
                        mImageTileSet.clear();
                        mScrollingUp = false;