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

Commit e8184cd2 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Adding the functionality to toggle the switch when clicked on the row."

parents 5861b7b8 abf2ad0a
Loading
Loading
Loading
Loading
+36 −22
Original line number Diff line number Diff line
/**
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,7 +13,6 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.packageinstaller.permission.ui.auto;


@@ -63,6 +62,7 @@ public final class AppPermissionsFragment extends Fragment{

    /**
     * Creates a new instance.
     *
     * @param packageName the packageName of the application that we are listing the
     *                    permissions here.
     */
@@ -172,6 +172,8 @@ public final class AppPermissionsFragment extends Fragment{

    private class PermissionLineItem extends TextListItem {

        private boolean mSwitchState;

        PermissionLineItem(AppPermissionGroup permissionGroup, Context context) {
            super(context);
            setTitle(permissionGroup.getLabel().toString());
@@ -182,7 +184,20 @@ public final class AppPermissionsFragment extends Fragment{
                    permissionGroup.areRuntimePermissionsGranted(),
                    /* showDivider= */ false,
                    (button, isChecked) -> {
                        if (isChecked) {
                        mSwitchState = isChecked;
                        updatePermission(permissionGroup, context, mSwitchState);
                    });
            setOnClickListener(v -> {
                mSwitchState = !mSwitchState;
                setSwitchState(mSwitchState);
                updatePermission(permissionGroup, context, mSwitchState);
                notifyDataSetChanged();
            });
        }

        private void updatePermission(AppPermissionGroup permissionGroup, Context context,
                boolean isGranted) {
            if (isGranted) {
                permissionGroup.grantRuntimePermissions(/* fixedByTheUser= */ false);
                return;
            }
@@ -201,7 +216,6 @@ public final class AppPermissionsFragment extends Fragment{
                                    permissionGroup.revokeRuntimePermissions(
                                            /* fixedByTheUser= */ false))
                    .show();
                    });
        }
    }
}