Coverage Summary for Class: PermissionState (dev.shreyaspatil.permissionFlow)
Class |
Class, %
|
Method, %
|
Branch, %
|
Line, %
|
Instruction, %
|
PermissionState |
100%
(1/1)
|
100%
(1/1)
|
|
100%
(1/1)
|
100%
(12/12)
|
1 /**
2 * Copyright 2022 Shreyas Patil
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package dev.shreyaspatil.permissionFlow
17
18 /**
19 * State model of a permission
20 *
21 * @property permission Name of a permission
22 * @property isGranted State of a permission whether it's granted or not
23 */
24 data class PermissionState(val permission: String, val isGranted: Boolean)
25
26 /**
27 * State model for multiple permissions
28 *
29 * @property permissions List of state of multiple permissions
30 */
31 data class MultiplePermissionState(val permissions: List<PermissionState>) {
32
33 /**
34 * Returns true if all permissions are granted by user
35 */
36 val allGranted by lazy { permissions.all { it.isGranted } }
37
38 /**
39 * List of permissions which are granted by user
40 */
41 val grantedPermissions by lazy { permissions.filter { it.isGranted }.map { it.permission } }
42
43 /**
44 * List of permissions which are denied / not granted by user
45 */
46 val deniedPermissions by lazy { permissions.filter { !it.isGranted }.map { it.permission } }
47 }