-
Notifications
You must be signed in to change notification settings - Fork 6
/
Improper_Usage.js
executable file
·112 lines (87 loc) · 3.58 KB
/
Improper_Usage.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
import React from 'react';
import { StyleSheet, View, Text, ScrollView, Dimensions, StatusBar } from 'react-native';
import { Button } from 'native-base';
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 ImproperUsageScreen 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'
}
});
//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();
}
//This funciton only applies to the "Hmong" language for now
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 });
};
makeList = () => {
Output = []
var objectSize = Object.keys(object.Antibiotics[0].DONT).length;
for (i = 0; i < objectSize; i++) {
Output.push(<Text key={i} style={{ color: 'black', fontSize: 20, padding: 15 }}>{I18n.t('Antibiotics.0.DONT.' + i)}</Text>);
}
return Output;
}
render() {
this.retrieveLanguage();
//creates variable named "audio" and concatinates "string" with temporary modified version of the disease parameter
var audio = string + "_improper_usage.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.makeList()}
</View>
</ScrollView>
);
}
}
const styles = StyleSheet.create({
scrollview: {
flexGrow: 1,
},
content: {
flexGrow: 1,
justifyContent: "space-between",
padding: 10,
},
});