-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathIllnesses_Info.js
executable file
·150 lines (115 loc) · 5.49 KB
/
Illnesses_Info.js
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
141
142
143
144
145
146
147
148
149
150
import React from 'react';
import { Platform, StyleSheet, View, Text, Linking, ScrollView, Dimensions, StatusBar } from 'react-native';
import { Button } from 'native-base';
import SafariView from 'react-native-safari-view';
import { Player } from '@react-native-community/audio-toolkit';
import AsyncStorage from '@react-native-community/async-storage';
import I18n from './locales/i18n.js';
var object = require('./locales/en.json');
var string = "";
const { height } = Dimensions.get('window');
export default class IllnessesInfoScreen extends React.PureComponent {
//creates audio player as state for whole component
p: Player | null;
//an object that contains the settings necessary for the audio player to function properly
playbackOptions = {
autoDestroy: false,
continuesToPlayInBackground: false
};
static navigationOptions = () => ({
title: 'Healthy Host',
headerTintColor: 'white',
headerStyle: {
backgroundColor: 'royalblue'
}
});
handleURL = (URL) => {
//opens link in phone web browser
if (Platform.OS === 'ios') {
SafariView.show({
url: URL
});
} else {
Linking.openURL(URL);
}
};
//function will retrieve the saved language preference of the application and set it into the "string" variable
retrieveLanguage = async () => {
try {
string = await AsyncStorage.getItem('language');
} catch (error) {
alert(error);
}
}
//will destroy the player once the user leaves the screen
componentWillUnmount() {
this.p.destroy();
}
makePage = (illness) => {
Output = []
var curr = 0;
var objectSize = Object.keys(object.Illnesses).length;
for (i = 0; i < objectSize; i++) {
var string = I18n.t('Illnesses.' + i + '.Name');
var n = string.localeCompare(illness);
if (n == 0) {
curr = i;
break;
}
}
Output.push(<Text key={0} style={{ textAlign: "center", padding: 10, fontSize: 40, color: "black", fontWeight: "bold" }}>{illness}</Text>);
Output.push(<Text key={1} style={{ textAlign: "center", padding: 10, fontSize: 30, color: "black", fontWeight: "bold" }}>{I18n.t('Text.Description')}</Text>);
Output.push(<Text key={2} style={{ padding: 10, fontSize: 22, color: "black" }}>{I18n.t('Illnesses.' + curr + '.Description')}</Text>);
Output.push(<Text key={3} style={{ textAlign: "center", padding: 10, fontSize: 30, color: "black", fontWeight: "bold" }}>{I18n.t('Text.Symptoms')}</Text>);
Output.push(<Text key={4} style={{ padding: 10, fontSize: 22, color: "black" }}>{I18n.t('Illnesses.' + curr + '.Symptoms')}</Text>);
Output.push(<Text key={5} style={{ textAlign: "center", padding: 10, fontSize: 30, color: "black", fontWeight: "bold" }}>{I18n.t('Text.Treatment')}</Text>);
Output.push(<Text key={6} style={{ padding: 10, fontSize: 22, color: "black" }}>{I18n.t('Illnesses.' + curr + '.Treatment')}</Text>);
Output.push(<Text key={7} style={{ textAlign: "center", padding: 10, fontSize: 30, color: "black", fontWeight: "bold" }}>{I18n.t('Text.Add_Info')}</Text>);
Output.push(<Text key={8} onPress={() => { this.handleURL(I18n.t('Illnesses.' + curr + '.Add_Info')) }} style={{ padding: 10, fontSize: 22, color: "red" }}>{I18n.t('Illnesses.' + curr + '.Add_Info')}</Text>);
return Output;
}
makeAudioButtons = () => {
Output = []
Output.push(<Button key={0} onPress={() => this.p.play()} style={{ backgroundColor: '#DCDCDC', alignSelf: "center", width: '25%', justifyContent: "center", margin: 10, borderRadius: 15 }}><Text style={{ color: 'black', fontSize: 20 }}>Play</Text></Button>);
Output.push(<Button key={1} onPress={() => this.p.pause()} style={{ backgroundColor: '#DCDCDC', alignSelf: "center", width: '25%', justifyContent: "center", margin: 10, borderRadius: 15 }}><Text style={{ color: 'black', fontSize: 20 }}>Pause</Text></Button>);
Output.push(<Button key={2} onPress={() => this.p.stop()} style={{ backgroundColor: '#DCDCDC', alignSelf: "center", width: '25%', justifyContent: "center", margin: 10, borderRadius: 15 }}><Text style={{ color: 'black', fontSize: 20 }}>Stop</Text></Button>);
return Output;
};
state = {
screenHeight: height,
};
onContentSizeChange = (contentWidth, contentHeight) => {
this.setState({ screenHeight: contentHeight });
};
render() {
//calls this function to retrieve the language setting
this.retrieveLanguage();
const { navigation } = this.props;
const illness = navigation.getParam('illness');
//creates variable named "audio" and concatinates "string" with temporary modified version of the disease parameter
var audio = string + "_" + illness.toLowerCase().replace(/ /g, "_").normalize("NFD").replace(/[\u0300-\u036f]/g, "").replace(/[&\/\\#,+()$~%.'":*?<>{}]/g, '') + ".aac";
//sets the state as a new audio player with the provided parameters
this.p = new Player(audio, this.playbackOptions);
return (
<ScrollView style={{ flex: 1 }} contentContainerStyle={styles.scrollview} scrollEnabled={true} onContentSizeChange={this.onContentSizeChange}>
<StatusBar barStyle="light-content" />
<View style={{ flex: 1 }}>
<View style={{ flexDirection: 'row', justifyContent: "center" }}>
{this.makeAudioButtons()}
</View>
{this.makePage(illness)}
</View>
</ScrollView>
);
}
}
const styles = StyleSheet.create({
scrollview: {
flexGrow: 1,
},
content: {
flexGrow: 1,
justifyContent: "space-between",
padding: 10,
},
});