Skip to content

Commit 4cf1220

Browse files
committed
Initial commit
0 parents  commit 4cf1220

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+5978
-0
lines changed

.gitignore

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
node_modules/
2+
google-services.json
3+
package-lock.json
4+
config.json
5+
eas.json
6+
package-lock.json/
7+
.expo/
8+
dist/
9+
npm-debug.*
10+
*.jks
11+
*.p8
12+
*.p12
13+
*.key
14+
*.mobileprovision
15+
*.orig.*
16+
web-build/
17+
assets/emake-69f91-firebase-adminsdk-dt5x3-02cdbb564a.json
18+
19+
# macOS
20+
.DS_Store
21+
22+
# Temporary files created by Metro to check the health of the file watcher
23+
.metro-health-check*

App.js

+327
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,327 @@
1+
import React, { useEffect, useState } from 'react'
2+
import { Provider } from 'react-native-paper'
3+
import { NavigationContainer } from '@react-navigation/native'
4+
import { createStackNavigator } from '@react-navigation/stack'
5+
import {
6+
StartScreen,
7+
Login,
8+
Dashboard,
9+
Config,
10+
Notificações,
11+
Perfil,
12+
Dados,
13+
Documentos,
14+
Boletim,
15+
Turmas,
16+
Calendario
17+
} from './src/screens'
18+
19+
import AsyncStorage from '@react-native-async-storage/async-storage'
20+
21+
import * as Notifications from 'expo-notifications'
22+
23+
const Stack = createStackNavigator()
24+
25+
import SUAP from './src/services/SUAP'
26+
27+
import axios from 'axios'
28+
29+
import * as Keychain from 'react-native-keychain'
30+
31+
32+
Notifications.setNotificationHandler({
33+
handleNotification: async () => ({
34+
shouldShowAlert: true,
35+
shouldPlaySound: true,
36+
shouldSetBadge: true,
37+
}),
38+
});
39+
40+
import messaging from '@react-native-firebase/messaging';
41+
import loading from './src/screens/loading'
42+
43+
import register from './src/services/BoletimChecker'
44+
import { ImageBackground, View } from 'react-native'
45+
import Header from './src/components/Header'
46+
47+
import { BlurView } from '@react-native-community/blur';
48+
import { Image } from 'react-native'
49+
import { Modal } from 'react-native'
50+
import { TouchableOpacity } from 'react-native'
51+
import { Linking } from 'react-native'
52+
53+
import { ProgressBar, MD3Colors } from 'react-native-paper';
54+
55+
import * as Updates from 'expo-updates';
56+
57+
const version = 1;
58+
59+
export default function App() {
60+
61+
const [exists, setExists] = useState(undefined);
62+
63+
const [update, setUpdate] = useState(false);
64+
65+
const [percent, setPercent] = useState(0);
66+
67+
const [updating, setUpdating] = useState(false);
68+
69+
async function onFetchUpdateAsync() {
70+
try {
71+
const update = await Updates.checkForUpdateAsync();
72+
73+
if (update.isAvailable) {
74+
setUpdate(true);
75+
}
76+
} catch (error) {
77+
alert(`Ocorreu um eror ao atualizar. Por favor, contate o desenvolvedor no instagram: @emake.app - ${error}`);
78+
}
79+
}
80+
81+
const tryLogin = (user, password) => {
82+
83+
SUAP.Login(user, password).then(async data => {
84+
if (!data) {
85+
setExists(false)
86+
} else {
87+
88+
Keychain.setGenericPassword(user, password);
89+
90+
AsyncStorage.setItem("userinfo", JSON.stringify({
91+
user: user,
92+
password: password,
93+
token: data.access,
94+
}));
95+
96+
setExists(true)
97+
98+
Notifications.getDevicePushTokenAsync().then(tokenn => {
99+
100+
AsyncStorage.setItem("token", tokenn.data)
101+
102+
axios.post("https://vps.paulo-valadares.com/postToken", {
103+
user: user,
104+
password: password,
105+
token: tokenn.data,
106+
})
107+
})
108+
}
109+
}).catch(err => {
110+
setExists(true);
111+
})
112+
}
113+
114+
useEffect(() => {
115+
setInterval(() => {
116+
if (update) return;
117+
118+
onFetchUpdateAsync();
119+
}, 15000);
120+
121+
onFetchUpdateAsync();
122+
123+
register.register();
124+
125+
AsyncStorage.getItem("token").then(token => {
126+
console.log(token)
127+
if (!token) {
128+
console.log("GETTING TOKEN")
129+
messaging().getToken().then(tokenn => {
130+
console.log(tokenn)
131+
AsyncStorage.setItem("token", tokenn)
132+
})
133+
}
134+
})
135+
136+
AsyncStorage.getItem("userinfo").then(res => {
137+
if (!res) {
138+
AsyncStorage.getItem("firstTime").then(res2 => {
139+
if (!res2) {
140+
setExists(null);
141+
142+
AsyncStorage.setItem("firstTime", "true");
143+
} else {
144+
setExists(false);
145+
}
146+
})
147+
return;
148+
}
149+
const parse = JSON.parse(res);
150+
151+
tryLogin(parse.user, parse.password);
152+
153+
setExists(true);
154+
})
155+
156+
messaging()
157+
.getInitialNotification()
158+
.then(remoteMessage => {
159+
if (remoteMessage) {
160+
console.log(
161+
'Notification caused app to open from quit state:',
162+
remoteMessage.notification,
163+
);
164+
}
165+
});
166+
167+
messaging().onNotificationOpenedApp(remoteMessage => {
168+
console.log(
169+
'Notification caused app to open from background state:',
170+
remoteMessage.notification,
171+
);
172+
});
173+
174+
messaging().setBackgroundMessageHandler(async remoteMessage => {
175+
console.log('Message handled in the background!', remoteMessage);
176+
});
177+
178+
const unsubscribe = messaging().onMessage(async remoteMessage => {
179+
console.log('A new FCM message arrived!', JSON.stringify(remoteMessage));
180+
});
181+
182+
return unsubscribe;
183+
}, []);
184+
185+
if (exists === undefined) return loading()
186+
187+
if (update) return (
188+
189+
<View style={{
190+
flex: 1,
191+
backgroundColor: "#29473b",
192+
justifyContent: "center",
193+
alignItems: "center"
194+
}}>
195+
196+
<Image
197+
source={require('./assets/logo.png')}
198+
blurRadius={2.5}
199+
/>
200+
201+
<Modal
202+
animationType="fade"
203+
transparent={true}
204+
visible={true}
205+
>
206+
<View style={{
207+
flex: 1,
208+
alignItems: 'center',
209+
marginTop: "25%"
210+
}}>
211+
<View style={{
212+
backgroundColor: 'rgba(255, 255, 255, 0.8)',
213+
width: '80%',
214+
borderRadius: 10,
215+
alignItems: 'center',
216+
shadowColor: "black",
217+
shadowOffset: { width: -5, height: 10 },
218+
shadowOpacity: 1,
219+
shadowRadius: 10,
220+
elevation: 10,
221+
flex: 0.25,
222+
justifyContent: "space-around"
223+
}}>
224+
<Header customStyle={{
225+
fontSize: 22,
226+
color: "#004AAD",
227+
fontWeight: "bold",
228+
flex: 0.5,
229+
width: "100%",
230+
textAlign: "center"
231+
}}>
232+
Atualize para continuar utilizando!
233+
</Header>
234+
235+
<TouchableOpacity style={{
236+
width: "100%",
237+
flex: 0.2,
238+
}} onPress={async () => {
239+
try {
240+
Updates.fetchUpdateAsync();
241+
242+
const inter = setInterval(() => {
243+
setPercent(p => {
244+
if (p === 100) {
245+
clearInterval(inter);
246+
247+
setUpdate(false);
248+
249+
Updates.reloadAsync();
250+
return 100
251+
} else {
252+
return p + 2;
253+
}
254+
})
255+
}, 200)
256+
257+
setUpdating(true);
258+
} catch (error) {
259+
alert(`Ocorreu um eror ao atualizar. Por favor, contate o desenvolvedor no instagram: @emake.app - ${error}`);
260+
}
261+
}}>
262+
<Header customStyle={{
263+
fontSize: 20,
264+
color: "blue",
265+
fontWeight: "bold",
266+
textAlign: "center"
267+
}}>{updating ? "Atualizando..." : "Clique para atualizar"}</Header>
268+
</TouchableOpacity>
269+
270+
{updating && <View style={{
271+
flex: 0.15,
272+
width: "100%",
273+
flexDirection: "row",
274+
justifyContent: "space-around",
275+
alignItems: "center"
276+
}}>
277+
<View style={{
278+
flex: 0.9
279+
}}>
280+
<ProgressBar progress={percent / 100} color="blue" style={{
281+
alignSelf: "center",
282+
borderRadius: 10,
283+
backgroundColor: "white",
284+
height: "100%",
285+
width: "100%"
286+
}} />
287+
</View>
288+
289+
<Header customStyle={{
290+
fontSize: 20,
291+
color: "blue",
292+
fontWeight: "bold",
293+
textAlign: "center"
294+
}}>{Math.floor(percent)}%</Header>
295+
</View>}
296+
</View>
297+
</View>
298+
</Modal >
299+
</View >
300+
)
301+
302+
return (<Provider>
303+
<NavigationContainer>
304+
<Stack.Navigator
305+
initialRouteName={update ? "UpdateScreen" : exists === true ? "Dashboard" : exists === null ? "Initial" : "Login"}
306+
screenOptions={{
307+
headerShown: false,
308+
cardStyle: { backgroundColor: 'rgb(28, 28, 28)' },
309+
detachPreviousScreen: true,
310+
presentation: 'transparentModal'
311+
}}
312+
>
313+
<Stack.Screen name="StartScreen" headerShown={true} component={StartScreen} />
314+
<Stack.Screen name="Login" headerShown={true} component={Login} />
315+
<Stack.Screen name="Dashboard" headerShown={true} component={Dashboard} />
316+
<Stack.Screen name="Config" headerShown={true} component={Config} />
317+
<Stack.Screen name="Notificações" headerShown={true} component={Notificações} />
318+
<Stack.Screen name="Perfil" headerShown={true} component={Perfil} />
319+
<Stack.Screen name="Dados" headerShown={true} component={Dados} />
320+
<Stack.Screen name="Documentos" headerShown={true} component={Documentos} />
321+
<Stack.Screen name="Boletim" headerShown={true} component={Boletim} />
322+
<Stack.Screen name="Turmas" headerShown={true} component={Turmas} />
323+
<Stack.Screen name="Calendario" headerShown={true} component={Calendario} />
324+
</Stack.Navigator>
325+
</NavigationContainer>
326+
</Provider>)
327+
}

0 commit comments

Comments
 (0)