Skip to content

Commit 8079f33

Browse files
committed
Merge branch 'master' into stable-1.0
2 parents cc0f4ed + 55dece4 commit 8079f33

File tree

2 files changed

+75
-24
lines changed

2 files changed

+75
-24
lines changed

App.js

Lines changed: 56 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
import React from 'react';
1+
import React from 'react'
22
import Game from "./app/containers/Game"
3-
import {StackNavigator} from "react-navigation";
4-
import {Text, View} from "react-native";
5-
import _ from "lodash";
3+
import {StackNavigator} from "react-navigation"
4+
import {Text, View, PermissionsAndroid} from "react-native"
5+
import _ from "lodash"
66
import {AdamConfig, defaultConfig, FrycekConfig, FrycekTestConfig, KacperConfig} from "./TEMP_CONFIGS"
7-
import MainScreen from "./app/containers/MainScreen";
8-
import {readActiveConfig, readConfigs} from "./app/services/db/configs";
9-
import {ModeTypes} from "./app/services/db/format";
10-
import ConfigProvider from "./app/containers/ConfigProvider";
11-
import ConfigConsumer from "./app/containers/ConfigConsumer";
7+
import MainScreen from "./app/containers/MainScreen"
8+
import {readActiveConfig, readConfigs} from "./app/services/db/configs"
9+
import {ModeTypes} from "./app/services/db/format"
10+
import ConfigProvider from "./app/containers/ConfigProvider"
11+
import ConfigConsumer from "./app/containers/ConfigConsumer"
1212
import Analytics from "appcenter-analytics"
13-
import SplashScreen from "./app/containers/SplashScreen";
13+
import SplashScreen from "./app/containers/SplashScreen"
14+
import ErrorScreen from "./app/containers/ErrorScreen"
1415

1516
const configFromDbToGameScreen = (config) => ({
1617
...config,
@@ -21,7 +22,7 @@ const configFromDbToGameScreen = (config) => ({
2122
isInTestMode: material.isInTestMode,
2223
isInLearningMode: material.isInLearningMode,
2324
})),
24-
});
25+
})
2526

2627
function prepareLevels(materials, repetitions, optionsNumber) {
2728
let levels = _.shuffle(_.flatMap(materials, material =>
@@ -30,10 +31,10 @@ function prepareLevels(materials, repetitions, optionsNumber) {
3031
name: material.name,
3132
images: material.images,
3233
isCorrectAnswer: true
33-
})))));
34+
})))))
3435

35-
levels = _.map(levels, level => _.map(level, material => ({...material, image: _.sample(material.images)})));
36-
return _(levels);
36+
levels = _.map(levels, level => _.map(level, material => ({...material, image: _.sample(material.images)})))
37+
return _(levels)
3738
}
3839

3940
const GameScreen = ({navigation}) => {
@@ -43,7 +44,7 @@ const GameScreen = ({navigation}) => {
4344
const isTestMode = mode === ModeTypes.test
4445

4546
const materials = isTestMode ? _.filter(config.materials, 'isInTestMode') : config.materials,
46-
repetitions = isTestMode ? config.testConfig.numberOfRepetitions : config.numberOfRepetitions;
47+
repetitions = isTestMode ? config.testConfig.numberOfRepetitions : config.numberOfRepetitions
4748

4849
return <Game
4950
levels={prepareLevels(materials, repetitions, config.picturesNumber)}
@@ -61,7 +62,7 @@ const GameScreen = ({navigation}) => {
6162
}
6263
</ConfigConsumer>
6364
)
64-
};
65+
}
6566

6667

6768
const AppNavigator = StackNavigator(
@@ -73,21 +74,21 @@ const AppNavigator = StackNavigator(
7374
{
7475
headerMode: "none",
7576
initialRouteName: "Splash"
76-
});
77+
})
7778

7879

7980
export default class App extends React.Component {
8081
state = {
8182
fontLoaded: false,
82-
};
83+
}
8384

8485
async loadConfig() {
8586
const {id, mode = ModeTypes.learning} = await readActiveConfig()
8687
console.log("Active config id: ", id, "in mode:", mode === ModeTypes.learning ? "learning" : "test")
8788

8889
const configs = await readConfigs()
8990

90-
const activeConfig = configs.find(config => config.id === id) || defaultConfig;
91+
const activeConfig = configs.find(config => config.id === id) || defaultConfig
9192

9293
console.log("Active config:", activeConfig)
9394
return {
@@ -103,23 +104,54 @@ export default class App extends React.Component {
103104
console.log("Loaded all assets")
104105
}
105106

107+
async requestExternalStoragePermission() {
108+
try {
109+
const granted = await PermissionsAndroid.request(
110+
PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
111+
{
112+
'title': 'Przyjazne Słowa - uprawnienia do zapisu',
113+
'message': "Aplikacja Przyjazne Słowa wymaga uprawnień do zapisu danych w pamięci urządzenia, aby móc komunikować się z aplikacją Przyjazne Słowa - Menadżer"
114+
}
115+
)
116+
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
117+
console.log("You can use the camera")
118+
return true;
119+
} else {
120+
console.log("Camera permission denied")
121+
return false;
122+
}
123+
} catch (err) {
124+
console.warn(err)
125+
return false;
126+
}
127+
}
128+
106129
async componentDidMount() {
107-
Analytics.trackEvent("App loaded");
130+
Analytics.trackEvent("App loaded")
131+
const hasPermissions = await this.requestExternalStoragePermission();
132+
133+
if(!hasPermissions) {
134+
this.setState({noPermissions: true})
135+
return;
136+
}
108137

109-
await this.loadAssets();
110-
const {config, mode} = await this.loadConfig();
138+
await this.loadAssets()
139+
const {config, mode} = await this.loadConfig()
111140
this.setState({
112141
assetsLoaded: true,
113142
config: configFromDbToGameScreen(config),
114143
mode
115-
});
144+
})
116145
}
117146

118147
render() {
148+
if(this.state.noPermissions) {
149+
return <ErrorScreen/>
150+
}
119151
return !this.state.assetsLoaded ? <Text>Loading</Text> : (
120152
<ConfigProvider config={this.state.config} mode={this.state.mode}>
121153
<AppNavigator/>
122154
</ConfigProvider>
123-
);
155+
)
124156
}
125157
}

app/containers/ErrorScreen.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React from 'react'
2+
import {Button, StatusBar, TouchableOpacity, Linking} from 'react-native'
3+
import {Layout} from "./Game"
4+
import {View} from "glamorous-native"
5+
import CapriolaText from "../components/ui/CapriolaText"
6+
7+
export default ErrorScreen = () =>
8+
<Layout>
9+
<View flex={1} alignItems={"center"} justifyContent={"space-around"}>
10+
<CapriolaText>Nie można wczytać pliku z konfiguracją - brak uprawnień do zapisu pliku.</CapriolaText>
11+
<CapriolaText>Uruchom ponownie aplikację i zaakceptuj prośbę o uzyskanie uprawnień.</CapriolaText>
12+
<CapriolaText>W razie problemów skontaktuj się z nami:</CapriolaText>
13+
<TouchableOpacity
14+
onPress={() => Linking.openURL('mailto:autyzmpg@gmail.com?subject=Uprawnienia+do+zapisu')}>
15+
<CapriolaText>autyzmpg@gmail.com</CapriolaText>
16+
</TouchableOpacity>
17+
18+
</View>
19+
</Layout>

0 commit comments

Comments
 (0)