Skip to content

Commit

Permalink
ask user to change settings in case no permission on camera or photos…
Browse files Browse the repository at this point in the history
… is given
  • Loading branch information
repolevedavaj committed May 22, 2022
1 parent 76cc7f0 commit 1cad896
Showing 1 changed file with 34 additions and 14 deletions.
48 changes: 34 additions & 14 deletions src/stacks/default/tabs/plants/screens/PlantEditScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
Button,
Card,
Datepicker,
Divider,
IndexPath,
Input,
Expand All @@ -12,7 +11,7 @@ import {
TopNavigation
} from "@ui-kitten/components";
import React, {useState} from "react";
import {KeyboardAvoidingView, Platform, ScrollView, StyleSheet, View} from "react-native";
import {Alert, KeyboardAvoidingView, Linking, Platform, ScrollView, StyleSheet, View} from "react-native";
import {StackActions, useNavigation, useRoute} from "@react-navigation/native";
import {PlantsStackNavigationProp, PlantsStackRoute, PlantsStackRouteProp} from "../PlantsStackRoute";
import {Plant} from "../../../../../model/Plant";
Expand Down Expand Up @@ -77,6 +76,11 @@ export default () => {
async function chooseAvatarFromMediaLibrary() {
let response = await ImagePicker.requestMediaLibraryPermissionsAsync();
if (!response.granted) {
askUserToChangeAppPermissions(
'Zugriff auf deine Fotos',
'Erlaube in den Einstellungen den Zugriff auf deine Fotos um ein Foto deiner Pflanze wählen zu können.'
);

return;
}

Expand All @@ -86,12 +90,28 @@ export default () => {
async function createAvatarWithCamera() {
let response = await ImagePicker.requestCameraPermissionsAsync();
if (!response.granted) {
askUserToChangeAppPermissions(
'Zugriff auf deine Kamera',
'Erlaube in den Einstellungen den Zugriff auf die Kamera um ein Foto deiner Pflanze schiessen zu können.'
);

return;
}

handleImagePickerResult(await ImagePicker.launchCameraAsync(IMAGE_PICKER_OPTIONS));
}

function askUserToChangeAppPermissions(title: string, message: string) {
Alert.alert(
title,
message,
[
{text: 'Einstellungen', onPress: () => Linking.openSettings()},
{text: 'Abbrechen'}
]
);
}

function getUpdatedPlant() {
return Object.assign(plant, {
name,
Expand Down Expand Up @@ -213,18 +233,18 @@ export default () => {
</Card>

{plant.id !== undefined &&
<Card status="basic">
<Button onPress={completePlant}
style={styles.firstButton}
appearance="outline">
Automatisch vervollständigen
</Button>
<Button onPress={deletePlant}
appearance="outline"
status="danger">
Löschen
</Button>
</Card>
<Card status="basic">
<Button onPress={completePlant}
style={styles.firstButton}
appearance="outline">
Automatisch vervollständigen
</Button>
<Button onPress={deletePlant}
appearance="outline"
status="danger">
Löschen
</Button>
</Card>
}
</View>
</ScrollView>
Expand Down

0 comments on commit 1cad896

Please sign in to comment.