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

Commit b64490ed authored by Jovana Knezevic's avatar Jovana Knezevic Committed by Android (Google) Code Review
Browse files

Merge "Adds an info dialog when a maximum number of users on the device is reached."

parents ed72380f a17e1689
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -1038,6 +1038,15 @@
    <!-- Message for add user confirmation dialog - short version. [CHAR LIMIT=none] -->
    <string name="user_add_user_message_short" msgid="1511354412249044381">When you add a new user, that person needs to set up their space.\n\nAny user can update apps for all other users. </string>

    <!-- Title for the dialog that lets users know that the maximum allowed number of users on the device has been reached. [CHAR LIMIT=35]-->
    <string name="user_limit_reached_title">User limit reached</string>

    <!-- Message that tells people what's the maximum number of uses allowed on the device. [CHAR_LIMIT=NONE]-->
    <plurals name="user_limit_reached_message">
        <item quantity="one">Only one user can be created.</item>
        <item quantity="other">You can add up to <xliff:g id="count" example="3">%d</xliff:g> users.</item>
    </plurals>

    <!-- Title of the confirmation dialog for deleting a user [CHAR LIMIT=NONE] -->
    <string name="user_remove_user_title">Remove user?</string>

+43 −17
Original line number Diff line number Diff line
@@ -164,7 +164,6 @@ public class UserGridRecyclerView extends PagedListView implements
        private final Resources mRes;
        private final String mGuestName;
        private final String mNewUserName;
        private AlertDialog mDialog;
        // View that holds the add user button.  Used to enable/disable the view
        private View mAddUserView;
        // User record for the add user.  Need to call notifyUserSelected only if the user
@@ -221,14 +220,48 @@ public class UserGridRecyclerView extends PagedListView implements
                    // Disable button so it cannot be clicked multiple times
                    mAddUserView = holder.mView;
                    mAddUserView.setEnabled(false);
                    mAddUserRecord = userRecord;

                    handleAddUserClicked();
                    return;
                }
                // If the user doesn't want to be a guest or add a user, switch to the user selected
                notifyUserSelected(userRecord);
                mCarUserManagerHelper.switchToUser(userRecord.mInfo);
            });

        }

        private void handleAddUserClicked() {
            if (mCarUserManagerHelper.isUserLimitReached()) {
                mAddUserView.setEnabled(true);
                showMaxUserLimitReachedDialog();
            } else {
                showConfirmAddUserDialog();
            }
        }

        private void showMaxUserLimitReachedDialog() {
            AlertDialog maxUsersDialog = new Builder(mContext, R.style.Theme_Car_Dark_Dialog_Alert)
                .setTitle(R.string.user_limit_reached_title)
                .setMessage(getResources().getQuantityString(
                    R.plurals.user_limit_reached_message,
                    mCarUserManagerHelper.getMaxSupportedRealUsers(),
                    mCarUserManagerHelper.getMaxSupportedRealUsers()))
                .setPositiveButton(android.R.string.ok, null)
                .create();
            // Sets window flags for the SysUI dialog
            SystemUIDialog.applyFlags(maxUsersDialog);
            maxUsersDialog.show();
        }

        private void showConfirmAddUserDialog() {
            String message = mRes.getString(R.string.user_add_user_message_setup)
                .concat(System.getProperty("line.separator"))
                .concat(System.getProperty("line.separator"))
                .concat(mRes.getString(R.string.user_add_user_message_update));

                    mAddUserRecord = userRecord;
                    mDialog = new Builder(mContext, R.style.Theme_Car_Dark_Dialog_Alert)
            AlertDialog addUserDialog = new Builder(mContext, R.style.Theme_Car_Dark_Dialog_Alert)
                .setTitle(R.string.user_add_user_title)
                .setMessage(message)
                .setNegativeButton(android.R.string.cancel, this)
@@ -236,15 +269,8 @@ public class UserGridRecyclerView extends PagedListView implements
                .setOnCancelListener(this)
                .create();
            // Sets window flags for the SysUI dialog
                    SystemUIDialog.applyFlags(mDialog);
                    mDialog.show();
                    return;
                }
                // If the user doesn't want to be a guest or add a user, switch to the user selected
                notifyUserSelected(userRecord);
                mCarUserManagerHelper.switchToUser(userRecord.mInfo);
            });

            SystemUIDialog.applyFlags(addUserDialog);
            addUserDialog.show();
        }

        private void notifyUserSelected(UserRecord userRecord) {