Pārlūkot izejas kodu

Cambios hasta registrarse en DB

ErnestoOrtiz2 3 gadus atpakaļ
vecāks
revīzija
0538f925c1

+ 85
- 8
App.js Parādīt failu

@@ -1,3 +1,4 @@
1
+<<<<<<< HEAD
1 2
 import { StatusBar } from 'expo-status-bar';
2 3
 import React from 'react';
3 4
 import { StyleSheet, Text, View } from 'react-native';
@@ -10,13 +11,89 @@ export default function App() {
10 11
       <StatusBar style="auto" />
11 12
     </View>
12 13
   );
14
+=======
15
+import React, { Component } from 'react';
16
+import firebase from 'firebase'
17
+import { NavigationContainer } from '@react-navigation/native';
18
+import { createStackNavigator } from '@react-navigation/stack';
19
+
20
+import RegisterScreen from './screens/RegisterScreen';
21
+import LoginScreen from './screens/LoginScreen';
22
+import { firebaseConfig } from './config/firebaseConfig';
23
+import { Text, View } from 'react-native';
24
+import { styles } from './config/styles';
25
+
26
+
27
+/*const seConfig = {
28
+  apiKey: "AIzaSyDW-ABAQ3r_WR7C7WC_3VprL77NcAoitJI",
29
+  authDomain: "freehand-d8ecd.firebaseapp.com",
30
+  projectId: "freehand-d8ecd",
31
+  storageBucket: "freehand-d8ecd.appspot.com",
32
+  messagingSenderId: "48371388186",
33
+  appId: "1:48371388186:web:9a5a4bf1218e17ac6326a3"
34
+};
35
+*/
36
+// Initialize Firebase
37
+//const app = firebase.initializeApp(seConfig);
38
+if (firebase.apps.length === 0) {
39
+  firebase.initializeApp(firebaseConfig)
40
+>>>>>>> master
13 41
 }
14 42
 
15
-const styles = StyleSheet.create({
16
-  container: {
17
-    flex: 1,
18
-    backgroundColor: '#fff',
19
-    alignItems: 'center',
20
-    justifyContent: 'center',
21
-  },
22
-});
43
+const Stack = createStackNavigator();
44
+
45
+export default class App extends Component {
46
+  constructor(props){
47
+    super(props);
48
+    this.state = {
49
+      loaded: false,
50
+    }
51
+  }
52
+  
53
+  componentDidMount(){
54
+    firebase.auth().onAuthStateChanged((user) => {
55
+      if (!user){
56
+        this.setState({
57
+          loggedIn: false,
58
+          loaded: true,
59
+        })
60
+      }
61
+      else{
62
+        this.setState({
63
+          loggedIn: true,
64
+          loaded: true,
65
+        })
66
+      }
67
+    })
68
+  }
69
+
70
+  render() {
71
+
72
+    const { loggedIn, loaded } = this.state
73
+
74
+    if(!loaded){
75
+      return(
76
+        <View style={styles.regcontainer}>
77
+          <Text>Hopper</Text>
78
+        </View>
79
+      );
80
+    }
81
+
82
+    if(!loggedIn){
83
+      return (
84
+        <NavigationContainer>
85
+          <Stack.Navigator>
86
+            <Stack.Screen name={" "} options={{headerShown: false}} component={LoginScreen}/>
87
+            <Stack.Screen name={"Register"} options={{headerTransparent: true, headerTitle: " "}} component={RegisterScreen}/>
88
+          </Stack.Navigator>
89
+        </NavigationContainer>
90
+      );
91
+    }
92
+
93
+    return(
94
+      <View style={styles.regcontainer}>
95
+        <Text>Cheese</Text>
96
+      </View>
97
+    );
98
+  }
99
+}

+ 1
- 0
README.md Parādīt failu

@@ -0,0 +1 @@
1
+#Probando

Binārs
assets/open-hand.png Parādīt failu


Binārs
assets/yellow-white.jpg Parādīt failu


+ 15
- 0
components/CustomButton.js Parādīt failu

@@ -0,0 +1,15 @@
1
+import React from 'react';
2
+import { Text, TouchableOpacity } from 'react-native';
3
+
4
+import { styles } from '../config/styles';
5
+import colors from '../config/colors';
6
+
7
+function CustomButton( {title, onPress, color = "skyblue", marginTop} ) {
8
+    return (
9
+        <TouchableOpacity style={[styles.regbutton, { backgroundColor: colors[color] }, { marginTop: marginTop }]} onPress={onPress}>
10
+            <Text style={styles.regbuttontext}>{title}</Text>
11
+        </TouchableOpacity>
12
+    );
13
+}
14
+
15
+export default CustomButton;

+ 5
- 0
config/colors.js Parādīt failu

@@ -0,0 +1,5 @@
1
+export default {
2
+        softpink: '#FFF0F5',
3
+        skyblue: '#87CEFA',
4
+        white: '#FFFFFF'
5
+}

+ 8
- 0
config/firebaseConfig.js Parādīt failu

@@ -0,0 +1,8 @@
1
+export const firebaseConfig = {
2
+  apiKey: "AIzaSyDW-ABAQ3r_WR7C7WC_3VprL77NcAoitJI",
3
+  authDomain: "freehand-d8ecd.firebaseapp.com",
4
+  projectId: "freehand-d8ecd",
5
+  storageBucket: "freehand-d8ecd.appspot.com",
6
+  messagingSenderId: "48371388186",
7
+  appId: "1:48371388186:web:9a5a4bf1218e17ac6326a3"
8
+};

+ 61
- 0
config/styles.js Parādīt failu

@@ -0,0 +1,61 @@
1
+import { StyleSheet } from "react-native"
2
+
3
+import colors from "./colors"
4
+
5
+export const styles = StyleSheet.create({
6
+    stdcontainer: {
7
+        flex: 1,
8
+        justifyContent: 'flex-start',
9
+        alignItems: 'center'
10
+    },
11
+
12
+    regcontainer: {
13
+        flex: 1,
14
+        justifyContent: 'center',
15
+        alignItems: 'center',
16
+    },
17
+
18
+    regbutton:{
19
+        backgroundColor: colors.skyblue,
20
+        justifyContent: 'center',
21
+        alignItems: 'center',
22
+        width: '50%',
23
+        height: '5%',
24
+    },
25
+
26
+    regtxtfield: {
27
+        backgroundColor: colors.softpink,
28
+        width: '75%',
29
+        height: '5%',
30
+        borderRadius: 25,
31
+        paddingLeft: 20,
32
+        paddingRight: 20,
33
+        margin: 20,
34
+    },
35
+
36
+    regbuttontext: {
37
+        color: colors.white,
38
+        fontSize: 17
39
+    },
40
+
41
+    logo: {
42
+        width: "25%",
43
+        height: "25%",
44
+        top: 50,
45
+        marginBottom: 200
46
+    },
47
+
48
+    loginbutton: {
49
+        position: 'absolute',
50
+        bottom: 50,
51
+    },
52
+
53
+    picker: {
54
+        width: '50%',
55
+    },
56
+
57
+    qsttxt: {
58
+        marginTop: 20,
59
+        fontWeight: "bold"
60
+    }
61
+})

+ 1505
- 1
package-lock.json
Failā izmaiņas netiks attēlotas, jo tās ir par lielu
Parādīt failu


+ 4
- 0
package.json Parādīt failu

@@ -8,8 +8,12 @@
8 8
     "eject": "expo eject"
9 9
   },
10 10
   "dependencies": {
11
+    "@react-native-picker/picker": "^2.1.0",
12
+    "@react-navigation/native": "^6.0.4",
13
+    "@react-navigation/stack": "^6.0.9",
11 14
     "expo": "~42.0.1",
12 15
     "expo-status-bar": "~1.0.4",
16
+    "firebase": "8.2.3",
13 17
     "react": "16.13.1",
14 18
     "react-dom": "16.13.1",
15 19
     "react-native": "https://github.com/expo/react-native/archive/sdk-42.0.0.tar.gz",

+ 92
- 0
screens/Home_page.js Parādīt failu

@@ -0,0 +1,92 @@
1
+import React, {useState, useEffect} from 'react'
2
+import { Button, Text, View, StyleSheet} from 'react-native'
3
+import {FlatList, ListViewBase } from 'react-native'
4
+import {TouchableOpacity} from 'react-native-gesture-handler'
5
+import {List, Divider} from 'react-native-paper'
6
+import Loading from '../components/Loading'
7
+import firebase from 'firebase';
8
+
9
+
10
+export default function Home_page({navigation}) {
11
+  const [threads, setThreads] = useState([]);  
12
+  const [loading, setLoading] = useState(true);
13
+
14
+  useEffect(() => {
15
+
16
+    const fire = firebase.firestore()
17
+    .collection('THREADS')
18
+    
19
+    .onSnapshot(querySnapshot => {
20
+      const threads = querySnapshot.docs.map(documentSnapshot => {
21
+        return{
22
+          _id:documentSnapshot.id,
23
+          name:'',
24
+          ...documentSnapshot.data()
25
+        };
26
+
27
+      });
28
+
29
+      setThreads(threads);
30
+
31
+      if(loading){
32
+        setLoading(false);
33
+      }
34
+
35
+    });
36
+
37
+    return () => fire();
38
+  }, []);
39
+  
40
+  if (loading) {
41
+    return <Loading />;
42
+  }
43
+  
44
+  return (
45
+      <View style={styles.container}>
46
+        <FlatList
47
+          data={threads}
48
+          keyExtractor = {item => item._id}
49
+          ItemSeparatorComponent={() => <Divider />}
50
+          renderItem = {({item}) => (
51
+
52
+            <TouchableOpacity
53
+            onPress={() => navigation.navigate('Room', {thread: item})}
54
+            
55
+            >
56
+            <List.Item
57
+              title={item.name}
58
+              description='Item description'
59
+              titleNumberOfLines={1}
60
+              titleStyle={styles.listTitle}
61
+              descriptionStyle={styles.listDescription}
62
+              descriptionNumberOfLines={1}
63
+            />
64
+          </TouchableOpacity>
65
+        )}
66
+      />
67
+
68
+      <Button
69
+        title='Add Room'
70
+        onPress={() => navigation.navigate('Add')}
71
+      />
72
+
73
+        <Button
74
+        title ='Room'
75
+        onPress= {() => navigation.navigate('Room')}
76
+        />
77
+
78
+      </View>
79
+    );
80
+  }
81
+  const styles = StyleSheet.create({
82
+    container: {
83
+      backgroundColor: '#f5f5f5',
84
+      flex: 1
85
+    },
86
+    listTitle: {
87
+      fontSize: 22
88
+    },
89
+    listDescription: {
90
+      fontSize: 16
91
+    }
92
+  });

+ 38
- 0
screens/LoginScreen.js Parādīt failu

@@ -0,0 +1,38 @@
1
+import React, { Component } from "react";
2
+import { TextInput, TouchableWithoutFeedback, Keyboard, ImageBackground, Image } from "react-native";
3
+import firebase from "firebase";
4
+
5
+import { styles } from "../config/styles";
6
+import CustomButton from "../components/CustomButton";
7
+
8
+
9
+export default class LoginScreen extends Component {
10
+    constructor(props) {
11
+        super(props);
12
+        this.state = {
13
+            email: '',
14
+            password: '',
15
+        };
16
+        this.onLogin = this.onLogin.bind(this)
17
+    };
18
+
19
+    onLogin() {
20
+        const { email, password } = this.state;
21
+        firebase.auth().signInWithEmailAndPassword(email, password).then((result) => {console.log(result)}).catch((error) => {console.log(error)})
22
+    }
23
+
24
+    render() {
25
+        
26
+        return (
27
+            <TouchableWithoutFeedback style={styles.stdcontainer} onPress={Keyboard.dismiss} accessible={false}>
28
+                <ImageBackground style={styles.stdcontainer} source={require('../assets/yellow-white.jpg')}>
29
+                    <Image style={styles.logo} resizeMode="contain" source={require("../assets/open-hand.png")}/>
30
+                    <TextInput style={styles.regtxtfield} placeholder="Email" onChangeText={(email) => this.setState({ email })}/>
31
+                    <TextInput style={styles.regtxtfield} placeholder="Password" onChangeText={(password) => this.setState({ password })} secureTextEntry={ true }/>
32
+                    <CustomButton marginTop={70} title="Login" onPress={() => this.onLogin()}/>
33
+                    <CustomButton marginTop={25} title="Register" onPress={() => this.props.navigation.navigate('Register')}/>
34
+                </ImageBackground>
35
+            </TouchableWithoutFeedback>
36
+        );
37
+    }
38
+}

+ 56
- 0
screens/RegisterScreen.js Parādīt failu

@@ -0,0 +1,56 @@
1
+import React, { Component } from "react";
2
+import { TextInput, TouchableWithoutFeedback, Keyboard, ImageBackground, Text, View } from "react-native";
3
+import firebase from "firebase";
4
+import { Picker } from "@react-native-picker/picker";
5
+
6
+import { styles } from "../config/styles";
7
+import CustomButton from "../components/CustomButton";
8
+
9
+export default class RegisterScreen extends Component {
10
+    constructor(props) {
11
+        super(props);
12
+        this.state = {
13
+            username: '',
14
+            email: '',
15
+            password: '',
16
+            interpreter: false,
17
+        };
18
+        this.onRegister = this.onRegister.bind(this)
19
+    };
20
+
21
+    onRegister() {
22
+        const { username, email, password, interpreter } = this.state;
23
+        firebase.auth().createUserWithEmailAndPassword(email, password)
24
+            .then((result) => {
25
+                firebase.firestore().collection("Users")
26
+                    .doc(firebase.auth().currentUser.uid)
27
+                    .set({
28
+                        username,
29
+                        email,
30
+                        interpreter,
31
+                    })
32
+                console.log(result)
33
+            })
34
+            .catch((error) => {
35
+                console.log(error)
36
+            })
37
+    }
38
+
39
+    render() {
40
+        return (
41
+            <TouchableWithoutFeedback style={styles.regcontainer} onPress={Keyboard.dismiss} accessible={false}>
42
+                <ImageBackground style={styles.regcontainer} source={require('../assets/yellow-white.jpg')}>
43
+                    <TextInput style={styles.regtxtfield} placeholder="Userame" onChangeText={(username) => this.setState({ username })}/>
44
+                    <TextInput style={styles.regtxtfield} placeholder="Email" onChangeText={(email) => this.setState({ email })}/>
45
+                    <TextInput style={styles.regtxtfield} placeholder="Password" onChangeText={(password) => this.setState({ password })} secureTextEntry={ true }/>
46
+                    <Text style={styles.qsttxt}>Are you an interpreter?</Text>
47
+                    <Picker style={styles.picker} selectedValue={this.state.interpreter} onValueChange={(itemValue,itemIndex) => this.setState({interpreter: itemValue})}>
48
+                        <Picker.Item label="Yes" value={true}/>
49
+                        <Picker.Item label="No" value={false}/>
50
+                    </Picker>
51
+                    <CustomButton  marginTop={50} title="Register" onPress={() => this.onRegister()}/>
52
+                </ImageBackground>
53
+            </TouchableWithoutFeedback>
54
+        );
55
+    }
56
+}

+ 62
- 0
sorting.py Parādīt failu

@@ -0,0 +1,62 @@
1
+"""
2
+Carlos J Corrada Bravo
3
+Este programa calcula el promedio de tiempo de ejecución de cuatro algoritmos de ordenamiento
4
+La variable maxValor define el valor maximo de los elementos de la lista
5
+La variable largoLista define el largo de las listas a ordenar
6
+La variable veces define las veces que se va a hacer el ordenamiento 
7
+Al final se imprimen los promedios de cada algortimo
8
+"""
9
+from random import randint
10
+import time
11
+
12
+def mergeSort(lista):
13
+	#definan el algoritmo de ordenamiento mergesort
14
+	return lista
15
+
16
+def heapSort(lista):
17
+	#definan el algoritmo de ordenamiento heapsort
18
+	return lista
19
+
20
+def quickSort(lista):
21
+	#definan el algoritmo de ordenamiento quicksort
22
+	return lista
23
+
24
+def shellSort(lista):
25
+	#definan el algoritmo de ordenamiento shellsort
26
+	return lista
27
+
28
+maxValor=1000 	#define el valor maximo de los elementos de la lista
29
+largoLista=1000 #define el largo de las listas a ordenar
30
+veces=100 		#define las veces que se va a hacer el ordenamiento 
31
+
32
+acumulaMerge=0 	#variable para acumular el tiempo de ejecucion del mergesort
33
+acumulaHeap=0 	#variable para acumular el tiempo de ejecucion del heapsort
34
+acumulaQuick=0 	#variable para acumular el tiempo de ejecucion del quicksort
35
+acumulaShell=0 	#variable para acumular el tiempo de ejecucion del shellsort
36
+
37
+for i in range(veces):
38
+	lista = [randint(0,maxValor) for r in range(largoLista)] #creamos una lista con valores al azar
39
+
40
+	t1 = time.clock() 				#seteamos el tiempo al empezar
41
+	mergeSort(lista) 				#ejecutamos el algoritmo mergeSort
42
+	acumulaMerge+=time.clock()-t1 	#acumulamos el tiempo de ejecucion
43
+	
44
+	t1 = time.clock()				#seteamos el tiempo al empezar
45
+	heapSort(lista)					#ejecutamos el algoritmo heapSort
46
+	acumulaHeap+=time.clock()-t1 	#acumulamos el tiempo de ejecucion
47
+	
48
+	t1 = time.clock()				#seteamos el tiempo al empezar
49
+	quickSort(lista)				#ejecutamos el algoritmo quickSort
50
+	acumulaQuick+=time.clock()-t1 	#acumulamos el tiempo de ejecucion
51
+	
52
+	t1 = time.clock()				#seteamos el tiempo al empezar
53
+	shellSort(lista)				#ejecutamos el algoritmo shellSort
54
+	acumulaShell+=time.clock()-t1 	#acumulamos el tiempo de ejecucion
55
+
56
+#imprimos los resultados
57
+print "Promedio de tiempo de ejecucion de "+ str(veces) +" listas de largo " + str(largoLista)
58
+print "MergeSort " + str(acumulaMerge/veces) + " segundos"
59
+print "HeapSort " + str(acumulaHeap/veces) + " segundos"
60
+print "QuickSort " + str(acumulaQuick/veces) + " segundos"
61
+print "ShellSort " + str(acumulaShell/veces) + " segundos"
62
+