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

Commit cf44428e authored by Jovana Knezevic's avatar Jovana Knezevic Committed by android-build-merger
Browse files

Merge "Fixes clicking on foreground user in the switcher." into pi-dev

am: a153811a

Change-Id: I3b7a6f0e6d8c62661ae7aa758207379173454bac
parents 87615abc a153811a
Loading
Loading
Loading
Loading
+31 −17
Original line number Diff line number Diff line
@@ -37,19 +37,20 @@ public class FullscreenUserSwitcher {
    private final UserGridRecyclerView mUserGridView;
    private final ProgressBar mSwitchingUsers;
    private final int mShortAnimDuration;
    private final StatusBar mStatusBar;

    private boolean mShowing;

    public FullscreenUserSwitcher(StatusBar statusBar, ViewStub containerStub, Context context) {
        mStatusBar = statusBar;
        mParent = containerStub.inflate();
        mContainer = mParent.findViewById(R.id.container);
        mUserGridView = mContainer.findViewById(R.id.user_grid);
        mUserGridView.setStatusBar(statusBar);
        GridLayoutManager layoutManager = new GridLayoutManager(context,
                context.getResources().getInteger(R.integer.user_fullscreen_switcher_num_col));
        mUserGridView.setLayoutManager(layoutManager);
        mUserGridView.buildAdapter();
        mUserGridView.setUserSelectionListener(record -> toggleSwitchInProgress(true));
        mUserGridView.setUserSelectionListener(this::onUserSelected);

        mShortAnimDuration = mContainer.getResources()
            .getInteger(android.R.integer.config_shortAnimTime);
@@ -57,8 +58,35 @@ public class FullscreenUserSwitcher {
        mSwitchingUsers = mParent.findViewById(R.id.switching_users);
    }

    public void show() {
        if (mShowing) {
            return;
        }
        mShowing = true;
        mParent.setVisibility(View.VISIBLE);
    }

    public void hide() {
        mShowing = false;
        toggleSwitchInProgress(false);
        mParent.setVisibility(View.GONE);
    }

    public void onUserSwitched(int newUserId) {
        mUserGridView.onUserSwitched(newUserId);
        mParent.post(this::showOfflineAuthUi);
    }

    private void onUserSelected(UserGridRecyclerView.UserRecord record) {
        if (record.mIsForeground) {
            showOfflineAuthUi();
            return;
        }
        toggleSwitchInProgress(true);
    }

    private void showOfflineAuthUi() {
        mStatusBar.executeRunnableDismissingKeyguard(null/* runnable */, null /* cancelAction */,
                true /* dismissShade */, true /* afterKeyguardGone */, true /* deferred */);
    }

    private void toggleSwitchInProgress(boolean inProgress) {
@@ -91,18 +119,4 @@ public class FullscreenUserSwitcher {
                }
            });
    }

    public void show() {
        if (mShowing) {
            return;
        }
        mShowing = true;
        mParent.setVisibility(View.VISIBLE);
    }

    public void hide() {
        mShowing = false;
        toggleSwitchInProgress(false);
        mParent.setVisibility(View.GONE);
    }
}
+10 −34
Original line number Diff line number Diff line
@@ -38,8 +38,6 @@ import android.widget.TextView;

import com.android.settingslib.users.UserManagerHelper;
import com.android.systemui.R;
import com.android.systemui.qs.car.CarQSFragment;
import com.android.systemui.statusbar.phone.StatusBar;

import java.util.ArrayList;
import java.util.List;
@@ -50,8 +48,6 @@ import java.util.List;
 */
public class UserGridRecyclerView extends RecyclerView implements
        UserManagerHelper.OnUsersUpdateListener {

    private StatusBar mStatusBar;
    private UserSelectionListener mUserSelectionListener;
    private UserAdapter mAdapter;
    private UserManagerHelper mUserManagerHelper;
@@ -92,28 +88,21 @@ public class UserGridRecyclerView extends RecyclerView implements
        super.setAdapter(mAdapter);
    }

    public void setStatusBar(@Nullable StatusBar statusBar) {
        mStatusBar = statusBar;
    }

    private List<UserRecord> createUserRecords(List<UserInfo> userInfoList) {
        List<UserRecord> userRecords = new ArrayList<>();
        for (UserInfo userInfo : userInfoList) {
            boolean isCurrent = false;
            if (ActivityManager.getCurrentUser() == userInfo.id) {
                isCurrent = true;
            }
            boolean isForeground = mUserManagerHelper.getForegroundUserId() == userInfo.id;
            UserRecord record = new UserRecord(userInfo, false /* isGuest */,
                    false /* isAddUser */, isCurrent);
                    false /* isAddUser */, isForeground);
            userRecords.add(record);
        }

        // Add guest user record if the current user is not a guest
        // Add guest user record if the foreground user is not a guest
        if (!mUserManagerHelper.foregroundUserIsGuestUser()) {
            userRecords.add(addGuestUserRecord());
        }

        // Add add user record if the current user can add users
        // Add add user record if the foreground user can add users
        if (mUserManagerHelper.foregroundUserCanAddUsers()) {
            userRecords.add(addUserRecord());
        }
@@ -128,7 +117,7 @@ public class UserGridRecyclerView extends RecyclerView implements
        UserInfo userInfo = new UserInfo();
        userInfo.name = mContext.getString(R.string.car_guest);
        return new UserRecord(userInfo, true /* isGuest */,
                false /* isAddUser */, false /* isCurrent */);
                false /* isAddUser */, false /* isForeground */);
    }

    /**
@@ -138,26 +127,13 @@ public class UserGridRecyclerView extends RecyclerView implements
        UserInfo userInfo = new UserInfo();
        userInfo.name = mContext.getString(R.string.car_add_user);
        return new UserRecord(userInfo, false /* isGuest */,
                true /* isAddUser */, false /* isCurrent */);
    }

    public void onUserSwitched(int newUserId) {
        // Bring up security view after user switch is completed.
        post(this::showOfflineAuthUi);
                true /* isAddUser */, false /* isForeground */);
    }

    public void setUserSelectionListener(UserSelectionListener userSelectionListener) {
        mUserSelectionListener = userSelectionListener;
    }

    void showOfflineAuthUi() {
        // TODO: Show keyguard UI in-place.
        if (mStatusBar != null) {
            mStatusBar.executeRunnableDismissingKeyguard(null/* runnable */, null /* cancelAction */,
                    true /* dismissShade */, true /* afterKeyguardGone */, true /* deferred */);
        }
    }

    @Override
    public void onUsersUpdate() {
        mAdapter.clearUsers();
@@ -332,21 +308,21 @@ public class UserGridRecyclerView extends RecyclerView implements

    /**
     * Object wrapper class for the userInfo.  Use it to distinguish if a profile is a
     * guest profile, add user profile, or a current user.
     * guest profile, add user profile, or the foreground user.
     */
    public static final class UserRecord {

        public final UserInfo mInfo;
        public final boolean mIsGuest;
        public final boolean mIsAddUser;
        public final boolean mIsCurrent;
        public final boolean mIsForeground;

        public UserRecord(UserInfo userInfo, boolean isGuest, boolean isAddUser,
                boolean isCurrent) {
                boolean isForeground) {
            mInfo = userInfo;
            mIsGuest = isGuest;
            mIsAddUser = isAddUser;
            mIsCurrent = isCurrent;
            mIsForeground = isForeground;
        }
    }