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

Commit a20b1570 authored by Bryan Eyler's avatar Bryan Eyler
Browse files

Fix users not showing up in fullscreen selection.

- Move layout logic to view pager.
- Move alpha for user pod to resource definition and adjust as
necessary.

Bug: 69861898
Change-Id: Iae8f489fca9cfbfad8acf32064be75c6e311eb0d
parent 204fbcbb
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:clipChildren="false"
    android:alpha="0"
    android:layout_width="wrap_content"
    android:layout_height="@dimen/car_fullscreen_user_pod_height"
    android:layout_gravity="center_horizontal|bottom" >
+7 −1
Original line number Diff line number Diff line
@@ -76,7 +76,8 @@ public class CarQSFragment extends Fragment implements QS {
        updateUserSwitcherHeight(0);

        mUserGridView = view.findViewById(R.id.user_grid);
        mUserGridView.init(null, Dependency.get(UserSwitcherController.class));
        mUserGridView.init(null, Dependency.get(UserSwitcherController.class),
                false /* overrideAlpha */);

        mPageIndicator = view.findViewById(R.id.user_switcher_page_indicator);
        mPageIndicator.setupWithViewPager(mUserGridView);
@@ -228,6 +229,11 @@ public class CarQSFragment extends Fragment implements QS {
                    if (podContainer.getChildCount() > 0) {
                        podContainer.getChildAt(podContainer.getChildCount() - 1).bringToFront();
                    }
                    // The alpha values are default to 0, so if the pods have been refreshed, they
                    // need to be set to 1 when showing.
                    for (int j = 0; j < podContainer.getChildCount(); j++) {
                        podContainer.getChildAt(j).setAlpha(1f);
                    }
                }
            }
        }
+1 −1
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ public class FullscreenUserSwitcher {
        mParent = containerStub.inflate();
        mContainer = mParent.findViewById(R.id.container);
        mUserGridView = mContainer.findViewById(R.id.user_grid);
        mUserGridView.init(statusBar, mUserSwitcherController);
        mUserGridView.init(statusBar, mUserSwitcherController, true /* overrideAlpha */);
        mUserGridView.setUserSelectionListener(record -> {
            if (!record.isCurrent) {
                toggleSwitchInProgress(true);
+22 −12
Original line number Diff line number Diff line
@@ -57,19 +57,35 @@ public class UserGridView extends ViewPager implements
    private UserSelectionListener mUserSelectionListener;
    private UserInfoController mUserInfoController;
    private Vector mUserContainers;
    private int mContainerWidth;
    private boolean mOverrideAlpha;
    private CarQSFragment.UserSwitchCallback mUserSwitchCallback;

    public UserGridView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public void init(StatusBar statusBar, UserSwitcherController userSwitcherController) {
    public void init(StatusBar statusBar, UserSwitcherController userSwitcherController,
            boolean overrideAlpha) {
        mStatusBar = statusBar;
        mUserSwitcherController = userSwitcherController;
        mAdapter = new Adapter(mUserSwitcherController);
        mUserInfoController = Dependency.get(UserInfoController.class);
        mOverrideAlpha = overrideAlpha;
        // Whenever the container width changes, the containers must be refreshed. Instead of
        // doing an initial refreshContainers() to populate the containers, this listener will
        // refresh them on layout change because that affects how the users are split into
        // containers. Furthermore, at this point, the container width is unknown, so
        // refreshContainers() cannot populate any containers.
        addOnLayoutChangeListener(
                (v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
                    int newWidth = Math.max(left - right, right - left);
                    if (mContainerWidth != newWidth) {
                        mContainerWidth = newWidth;
                        refreshContainers();
                    }
                });
    }

    private void refreshContainers() {
        mUserContainers = new Vector();
@@ -85,6 +101,9 @@ public class UserGridView extends ViewPager implements
            int limit = Math.min(mUserSwitcherController.getUsers().size(), (i + 1) * iconsPerPage);
            for (int j = i * iconsPerPage; j < limit; j++) {
                View v = mAdapter.makeUserPod(inflater, context, j, pods);
                if (mOverrideAlpha) {
                    v.setAlpha(1f);
                }
                pods.addView(v);
                // This is hacky, but the dividers on the pod container LinearLayout don't seem
                // to work for whatever reason.  Instead, set a right margin on the pod if it's not
@@ -101,7 +120,6 @@ public class UserGridView extends ViewPager implements
        }

        mAdapter = new Adapter(mUserSwitcherController);
        addOnLayoutChangeListener(mAdapter);
        setAdapter(mAdapter);
    }

@@ -166,14 +184,13 @@ public class UserGridView extends ViewPager implements
     * to use composition instead to achieve the same goal since both the base classes are abstract
     * classes and not interfaces.
     */
    private final class Adapter extends PagerAdapter implements View.OnLayoutChangeListener {
    private final class Adapter extends PagerAdapter {
        private final int mPodWidth;
        private final int mPodMarginBetween;
        private final int mPodImageAvatarWidth;
        private final int mPodImageAvatarHeight;

        private final WrappedBaseUserAdapter mUserAdapter;
        private int mContainerWidth;

        public Adapter(UserSwitcherController controller) {
            super();
@@ -319,13 +336,6 @@ public class UserGridView extends ViewPager implements
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

        @Override
        public void onLayoutChange(View v, int left, int top, int right, int bottom,
                int oldLeft, int oldTop, int oldRight, int oldBottom) {
            mContainerWidth = Math.max(left - right, right - left);
            notifyDataSetChanged();
        }
    }

    private final class WrappedBaseUserAdapter extends UserSwitcherController.BaseUserAdapter {