# Code coverage report for atlas-mobile-ts/src/utils/GlobalUtils.ts

# All files / atlas-mobile-ts/src/utils GlobalUtils.ts

0% Statements 0/63
0% Branches 0/11
0% Functions 0/8
0% Lines 0/56

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140

     ﻿/* Copyright (C) Click & Push Accessibility, Inc - All Rights Reserved
     * Unauthorized copying of this file, via any medium is strictly prohibited
     * Proprietary and confidential
     * Written and maintained by the Click & Push Development team
     * <dev@clicknpush.ca>, January 2022
     */

    import { Alert, ImageURISource, Permission, Platform, StyleSheet } from "react-native";
    import { checkMultiple, PERMISSIONS, requestMultiple, RESULTS, } from "react-native-permissions";

    // global constants
    export const colors = {
        red: '#df3f3f',
    }

    export const SECURESTORE_ACCESSTOKEN = "access"
    export const SECURESTORE_REFRESHTOKEN = "refresh"
    export const SECURESTORE_NOTIFTOKEN = 'notif'
    export const SECURESTORE_IDTOKEN = 'id'

    export const lmTypes: {[key: number]: {image: ImageURISource, label: string}} = {
        // 1: {image: require('../../assets/uneven.png'), label: "rough terrain"}, not currently in use
        2: {image: require('../../assets/stairs.png'), label: "stairs"},
        3: {image: require('../../assets/barrier.png'), label: "barrier"},
        4: {image: require('../../assets/uneven.png'), label: "rough terrain"},
        5: {image: require('../../assets/information.png'), label: "information"},
        6: {image: require('../../assets/washroom.png'), label: "accessible washroom"},
        7: {image: require('../../assets/power.png'), label: "power issue"},
        8: {image: require('../../assets/crosswalk.png'), label: "crosswalk issue"},
        9: {image: require('../../assets/ice.png'), label: "ice"}
    }

    export const GlobalStyles = StyleSheet.create({
        itemRowContainer: {
            flexDirection: 'row',
            justifyContent: 'space-between'
        },
    })

    export const testTag = (tag: string) => {
        return {
            testID: tag,
            accessibilityLabel: tag,
            accessible: true
        }
    }

    export const checkVoicePermissions = async (permissions: string[]): Promise<boolean> => {
        try {
            if (Platform.OS == 'android') {
                permissions = [PERMISSIONS.ANDROID.RECORD_AUDIO]
            }
            else Iif (Platform.OS == 'ios') {
                permissions = [PERMISSIONS.IOS.SPEECH_RECOGNITION, PERMISSIONS.IOS.MICROPHONE]
            }

            const result = await checkMultiple(permissions as Permission[])
            let granted = false
            permissions.forEach(permission => {
                granted = result[permission] ==  RESULTS.GRANTED
            })

            return granted
        } catch (error) {
            console.log('[Permissions]: An error occured when getting voice permissions: ' + error)
        }
    }

    export const getMediaPermissions = async () => {
        let permissions = []
        if (Platform.OS == "android") {
            permissions = [
                PERMISSIONS.ANDROID.CAMERA,
                PERMISSIONS.ANDROID.READ_EXTERNAL_STORAGE,
                PERMISSIONS.ANDROID.WRITE_EXTERNAL_STORAGE,
            ]
        }

        else Iif (Platform.OS == 'ios') {
            permissions = [
                PERMISSIONS.IOS.CAMERA,
                PERMISSIONS.IOS.PHOTO_LIBRARY,
            ]
        }

        try {
            const permissionsResult = await checkMultiple(permissions)
            const ungrantedPermissions = permissions.filter(permission => permissionsResult[permission] != RESULTS.GRANTED);
            console.log(permissionsResult)
            console.log(ungrantedPermissions)
            Iif (ungrantedPermissions.length > 0) {
                console.log('asking for permissions')
                const result = await requestMultiple(ungrantedPermissions)
                const deniedPermissions = ungrantedPermissions.filter(permission => result[permission] != RESULTS.GRANTED)
                Iif (deniedPermissions.length > 0) {
                    return false
                }
            }

            return true
        }
        catch (error) {
            console.log('[Permissions]: An error occured when getting media permissions: ' + error)
        }
    }

    export const getMapPermissions = async () => {
        try {
            console.log('[Permissions]: Getting permissions for map')
            let permissions = []
            if (Platform.OS == "android") {
            permissions = [
                PERMISSIONS.ANDROID.ACCESS_COARSE_LOCATION,
                PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION,
                PERMISSIONS.ANDROID.RECORD_AUDIO,
            ]
            }

            else Iif (Platform.OS == 'ios') {
            permissions = [
                PERMISSIONS.IOS.LOCATION_ALWAYS,
                PERMISSIONS.IOS.LOCATION_WHEN_IN_USE,
                PERMISSIONS.IOS.SPEECH_RECOGNITION,
                PERMISSIONS.IOS.MICROPHONE,
            ]
            }

            try {
            const permissionsResult = await checkMultiple(permissions)
            const ungrantedPermissions = permissions.filter(permission => permissionsResult[permission] != RESULTS.GRANTED);
            requestMultiple(ungrantedPermissions)
            }
            catch (error) {
            console.log('[Permissions]: An error occured when getting map permissions: ' + error)
            }
        }
        catch (error) {
            console.log('[Permissions]:An error occured when getting map permissions: ' + error)
        }
    }