Coverage Summary for Class: MultiplePermissionState (dev.shreyaspatil.permissionFlow)

Class Method, % Branch, % Line, % Instruction, %
MultiplePermissionState 100% (1/1) 100% (5/5) 100% (64/64)
MultiplePermissionState$allGranted$2 100% (1/1) 100% (1/1) 100% (9/9)
MultiplePermissionState$deniedPermissions$2 100% (1/1) 100% (2/2) 100% (1/1) 100% (20/20)
MultiplePermissionState$grantedPermissions$2 100% (1/1) 100% (1/1) 100% (16/16)
MultiplePermissionState$permissionsRequiringRationale$2 100% (1/1) 100% (1/1) 100% (19/19)
Total 100% (5/5) 100% (2/2) 100% (9/9) 100% (128/128)


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  * @property isRationaleRequired Whether to show rationale for a permission or not. 24  */ 25 data class PermissionState( 26  val permission: String, 27  val isGranted: Boolean, 28  val isRationaleRequired: Boolean?, 29 ) 30  31 /** 32  * State model for multiple permissions 33  * 34  * @property permissions List of state of multiple permissions 35  */ 36 data class MultiplePermissionState(val permissions: List<PermissionState>) { 37  /** Returns true if all permissions are granted by user */ 38  val allGranted by lazy { permissions.all { it.isGranted } } 39  40  /** List of permissions which are granted by user */ 41  val grantedPermissions by lazy { permissions.filter { it.isGranted }.map { it.permission } } 42  43  /** List of permissions which are denied / not granted by user */ 44  val deniedPermissions by lazy { permissions.filter { !it.isGranted }.map { it.permission } } 45  46  /** List of permissions which are required to show rationale */ 47  val permissionsRequiringRationale by lazy { 48  permissions.filter { it.isRationaleRequired == true }.map { it.permission } 49  } 50 }