-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
165 lines (144 loc) · 5.86 KB
/
App.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import React from 'react';
import { Text, View, StatusBar, TouchableOpacity, TouchableWithoutFeedback, ActivityIndicator, Image, Linking, SafeAreaView } from 'react-native';
import Navigator from './Navigator';
import Setup from './layouts/Settings/Setup';
import Browser from './layouts/Settings/Browser';
import Svg, { Path, Line, Circle, Polyline, Rect } from 'react-native-svg';
import * as Font from 'expo-font';
import * as Localization from 'expo-localization';
import * as ScreenOrientation from 'expo-screen-orientation';
import API from './api';
TouchableOpacity.defaultProps = TouchableOpacity.defaultProps || {};
TouchableOpacity.defaultProps.delayPressIn = 0;
TouchableWithoutFeedback.defaultProps = TouchableWithoutFeedback.defaultProps || {};
TouchableWithoutFeedback.defaultProps.delayPressIn = 0;
export default class App extends React.Component {
constructor(props){
super(props);
this.state = {
screen: "loading",
moreSignin: false,
activity: false,
premium: API.premium
}
API.event.on("premium", () => {
console.log("$$$$$", API.premium)
this.setState({premium: API.premium});
})
}
async componentDidMount(){
setTimeout(() => {
if(this.state.screen == "loading"){
this.setState({screen: "login"});
}
}, 2000);
this.checkIdentifier();
ScreenOrientation.unlockAsync();
API.event.on("refresh", (type) => {
if(type == "signout"){
this.setState({screen: "login"});
}else if(type == "setup"){
this.checkIdentifier();
}
})
}
checkIdentifier(){
API.getData("user").then(user => {
if(user){
API.user = JSON.parse(user);
this.setState({screen: "logged"});
API.initSpeech();
}else{
console.log("You need to setup your app!!");
this.setState({screen: "login"});
}
});
}
setupComplete(param){
console.log("setup complete", param);
}
signInScreen(){
return (
<>
<SafeAreaView style={{justifyContent: "center", alignItems: "center", flex: 1, backgroundColor: API.config.backgroundColor}}>
<Image source={require("./assets/title_screen.png")} style={{width: 200, height: 200}}/>
<View style={{ justifyContent: "center", alignItems: "center", flexDirection: "column", padding: 20}}>
<Text style={[API.styles.pHome, {marginBottom: 0, marginHorizontal: 0, textAlign: "center"}]}>{API.t("setup_welcome_description")}</Text>
</View>
{this.renderSignInButtons()}
<TouchableOpacity onPress={() => this.setState({screen: "policy"})} style={{marginTop: 15, marginBottom: 30}}>
<Text style={[API.styles.pHome, {textAlign: "center"}]}>
By starting you accept our <Text style={{fontWeight: "600"}}>Terms of Use</Text> and <Text style={{fontWeight: "600"}}>Privacy Policy</Text>.
</Text>
</TouchableOpacity>
</SafeAreaView>
{this.state.activity &&
<View style={{backgroundColor: "rgba(0,0,0,0.3)", width: "100%", height: "100%", position: "absolute", top: 0, left: 0, justifyContent: "center", alignItems: "center"}}>
<View style={{width: 60, height: 60, backgroundColor: "#fff", alignItems: "center", justifyContent: "center", borderRadius: 30}}>
<ActivityIndicator color={API.config.backgroundColor}/>
</View>
<TouchableOpacity style={{marginTop: 30, position: "absolute", bottom: 30}} onPress={() => this.setState({activity: false})}>
<Text style={{color: "#fff", fontWeight: "bold", fontSize: 18}}>{API.t("alert_cancel")}</Text>
</TouchableOpacity>
</View>
}
</>
)
}
renderSignInButtons(){
return(
<>
<TouchableOpacity
style={{ width: 240, height: 46, alignItems: "center", borderRadius: 25, backgroundColor: "#fff", justifyContent: "center", flexDirection: "row"}}
onPress={() => { this.setState({screen: "logged"}) }}>
<Svg height={24} width={24} viewBox="0 0 24 24" style={{marginRight: 5}} strokeWidth="2" stroke="#333" fill="none" strokeLinecap="round" strokeLinejoin="round">
<Path d="M0 0h24v24H0z" stroke="none"/>
<Path d="M20 12v6a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2h9"/>
<Polyline points="9 11 12 14 20 6"/>
</Svg>
<Text style={{fontSize: 19, fontWeight: "500"}}>{API.t("button_get_started")}</Text>
</TouchableOpacity>
</>
);
}
renderLoading(type){
if(type == "premium"){
setTimeout(() => {
this.setState({premium: "none"});
}, 3000);
}
return (
<View style={{flex: 1, backgroundColor: API.config.backgroundColor, justifyContent: "center", alignItems: "center"}}>
<StatusBar backgroundColor={API.config.backgroundColor} barStyle={"light-content"} />
<View style={{width: 60, height: 60, backgroundColor: "#fff", alignItems: "center", justifyContent: "center", borderRadius: 30}}>
<ActivityIndicator color={API.config.backgroundColor}/>
</View>
</View>
)
}
render() {
let screen = this.state.screen;
if(screen == "login"){
return this.signInScreen();
}else if(screen == "policy"){
return (<Browser link={"https://dreamoriented.org/privacypolicy/"} back={() => this.setState({screen: "login"})}/>);
}else if(screen == "logged"){
if(API.user.name){
if(this.state.premium == "determining"){
return this.renderLoading("premium");
}else{
return (
<View style={{flex: 1}}>
<StatusBar backgroundColor="#ffffff" barStyle={"dark-content"} />
<Navigator/>
</View>
);
}
}else{
return (<Setup done={this.setupComplete.bind(this)}/>);
}
}else if(screen == "loading"){
return this.renderLoading();
}
}
}