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

Commit bcdd859f authored by Pinyao Ting's avatar Pinyao Ting
Browse files

Fix actions for player integration in RemoteViews

Click handlers needs to be re-added each time a new document was passed
to the player.

Bug: 26162947
Test: atest RemoteViewsTest
Change-Id: Ib4e0f5d117554b71e5751a345034380f796ae303
parent f8894145
Loading
Loading
Loading
Loading
+10 −11
Original line number Diff line number Diff line
@@ -3874,7 +3874,7 @@ public class RemoteViews implements Parcelable, Filter {
        }
    }

    private static class SetDrawInstructionAction extends Action {
    private class SetDrawInstructionAction extends Action {

        @Nullable
        private final DrawInstructions mInstructions;
@@ -3909,6 +3909,15 @@ public class RemoteViews implements Parcelable, Filter {
                }
                try (ByteArrayInputStream is = new ByteArrayInputStream(bytes.get(0))) {
                    player.setDocument(new RemoteComposeDocument(is));
                    player.addClickListener((viewId, metadata) -> {
                        mActions.forEach(action -> {
                            if (viewId == action.mViewId
                                    && action instanceof SetOnClickResponse setOnClickResponse) {
                                setOnClickResponse.mResponse.handleViewInteraction(
                                        player, params.handler);
                            }
                        });
                    });
                } catch (IOException e) {
                    Log.e(LOG_TAG, "Failed to render draw instructions", e);
                }
@@ -6051,16 +6060,6 @@ public class RemoteViews implements Parcelable, Filter {
        RemoteViews rvToApply = getRemoteViewsToApply(context, size);
        View result = inflateView(context, rvToApply, directParent,
                params.applyThemeResId, params.colorResources);
        if (result instanceof RemoteComposePlayer player) {
            player.addClickListener((viewId, metadata) -> {
                mActions.forEach(action -> {
                    if (viewId == action.mViewId
                            && action instanceof SetOnClickResponse setOnClickResponse) {
                        setOnClickResponse.mResponse.handleViewInteraction(player, params.handler);
                    }
                });
            });
        }
        rvToApply.performApply(result, rootParent, params);
        return result;
    }