Skip to content

Commit

Permalink
added voice n shit
Browse files Browse the repository at this point in the history
  • Loading branch information
bocradu committed Oct 23, 2016
1 parent 7c302ea commit fcc5a0e
Show file tree
Hide file tree
Showing 11 changed files with 169 additions and 58 deletions.
1 change: 1 addition & 0 deletions registr/android/app/build.gradle
Expand Up @@ -129,6 +129,7 @@ dependencies {
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+" // From node_modules
compile project(':VoiceModule')
}

// Run this once to be able to run the application with BUCK
Expand Down
1 change: 1 addition & 0 deletions registr/android/app/src/main/AndroidManifest.xml
Expand Up @@ -6,6 +6,7 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="22" />
Expand Down
@@ -1,6 +1,8 @@
package com.registr;

import com.facebook.react.ReactActivity;
import com.wmjmc.reactspeech.VoicePackage;
import com.facebook.ReactPackage.MainReactPackage;

public class MainActivity extends ReactActivity {

Expand All @@ -12,4 +14,11 @@ public class MainActivity extends ReactActivity {
protected String getMainComponentName() {
return "registr";
}

@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new VoicePackage());
}
}
3 changes: 2 additions & 1 deletion registr/android/settings.gradle
@@ -1,3 +1,4 @@
rootProject.name = 'registr'

include ':app'
include ':VoiceModule', ':app'
project(':VoiceModule').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-android-voice')
4 changes: 3 additions & 1 deletion registr/package.json
Expand Up @@ -10,8 +10,10 @@
"firebase": "^3.5.1",
"react": "15.3.2",
"react-native": "0.35.0",
"react-native-android-voice": "^0.3.0",
"react-native-datepicker": "^1.3.2",
"react-native-form-generator": "^0.9.9"
"react-native-form-generator": "^0.9.9",
"react-native-voice": "^0.1.6"
},
"jest": {
"preset": "jest-react-native"
Expand Down
48 changes: 27 additions & 21 deletions registr/src/app.js
@@ -1,6 +1,6 @@
import React, { Component } from 'react';
import {
View, NetInfo, AsyncStorage, Alert
View, NetInfo, AsyncStorage
} from 'react-native';
import firebase from 'firebase';
import { Header, Spinner } from './components/common';
Expand Down Expand Up @@ -31,7 +31,6 @@ class App extends Component {
this.setState({ loggedIn: false });
}
});

}


Expand All @@ -44,25 +43,32 @@ class App extends Component {
}

onConnected(isConnected) {
AsyncStorage.getItem('onlinestatuslist').then((value) => {
let onlinestatuslist = [];
if (value !== null) {
onlinestatuslist = JSON.parse(value);
}
onlinestatuslist.push(isConnected);
AsyncStorage.setItem('onlinestatuslist', JSON.stringify(onlinestatuslist))
.then(() => {
Alert.alert(
'Alert Title',
JSON.stringify(onlinestatuslist),
[
{ text: 'Ask me later', onPress: () => console.log('Ask me later pressed') },
{ text: 'Cancel', onPress: () => console.log('Cancel Pressed'), style: 'cancel' },
{ text: 'OK', onPress: () => console.log('OK Pressed') },
]
); })
.catch();
}).done();
if (isConnected) {
const { currentUser } = firebase.auth();
const userName = currentUser.email.substring(0, currentUser.email.indexOf('@'));
AsyncStorage.getItem('employees').then(value => {
const jsonObj = JSON.parse(value);
try {
for (let i = 0; i < jsonObj.length; i++) {
console.log(jsonObj[i]);
firebase.database().ref(`user/${userName}/employees`)
.push({
firstName: jsonObj[i].firstName,
lastName: jsonObj[i].lastName,
personalId: jsonObj[i].personalId,
address: jsonObj[i].address,
gender: jsonObj[i].gender,
birthday: jsonObj[i].birthday
});
}

EmployeeList.onRemovePress();
}
catch (err) {
console.log(`Error while pushing data: ${err}`);
}
});
}
}

onSaveSuccess() {
Expand Down
Binary file added registr/src/components/common/icons/mic.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion registr/src/components/common/index.js
Expand Up @@ -7,4 +7,4 @@ export * from './spinner';
export * from './select';
export * from './datePicker';
export * from './listItem';

export * from './voiceTextBox';
49 changes: 49 additions & 0 deletions registr/src/components/common/voiceTextBox.js
@@ -0,0 +1,49 @@
import React from 'react';
import { TextInput, View, Text, TouchableOpacity, Image } from 'react-native';
import icon from './icons/mic.png';

const VoiceTextBox = ({ label, value, onChangeText, placeholder, onPress }) => {
const { labelStyle, textBoxStyle, containerStyle } = styles;
return (
<View style={containerStyle}>
<Text style={labelStyle}>{label}</Text>
<TextInput
autoCorrect={false}
onChangeText={onChangeText}
placeholder={placeholder}
style={textBoxStyle}
value={value}
/>
<TouchableOpacity onPress={onPress}>
<Image
style={styles.button}
source={icon}
/>
</TouchableOpacity>
</View>
);
};

const styles = {
labelStyle: {
fontSize: 18,
paddingLeft: 20,
flex: 1
},
textBoxStyle: {
color: 'blue',
paddingLeft: 5,
paddingRight: 5,
fontSize: 18,
lineHeight: 23,
flex: 2
},
containerStyle: {
height: 40,
flex: 1,
flexDirection: 'row',
alignItems: 'center'
}
};

export { VoiceTextBox };
65 changes: 39 additions & 26 deletions registr/src/components/employeeList.js
@@ -1,7 +1,8 @@
import React, { Component } from 'react';
import { ScrollView, AsyncStorage } from 'react-native';
import { ScrollView, AsyncStorage, NetInfo, Alert } from 'react-native';
import firebase from 'firebase';
import { Button, Card, CardSection, ListItem } from './common';
import * as firebase from 'firebase';


class EmployeeList extends Component {
constructor({ onNextPage }) {
Expand All @@ -28,29 +29,41 @@ class EmployeeList extends Component {
}

onSubmitPress() {
const { currentUser } = firebase.auth();
const userName = currentUser.email.substring(0, currentUser.email.indexOf('@'));
AsyncStorage.getItem('employees').then(value => {
const jsonObj = JSON.parse(value);
try {
for (let i = 0; i < jsonObj.length; i++) {
console.log(jsonObj[i]);
firebase.database().ref(`user/${userName}/employees`)
.push({
firstName: jsonObj[i].firstName,
lastName: jsonObj[i].lastName,
personalId: jsonObj[i].personalId,
address: jsonObj[i].address,
gender: jsonObj[i].gender,
birthday: jsonObj[i].birthday
});
}

AsyncStorage.removeItem('employees');
this.setState({ employees: [] });
}
catch (err) {
console.log(`Error while pushing data: ${err}`);
NetInfo.isConnected.fetch().then(isConnected => {
if (isConnected) {
const { currentUser } = firebase.auth();
const userName = currentUser.email.substring(0, currentUser.email.indexOf('@'));
AsyncStorage.getItem('employees').then(value => {
const jsonObj = JSON.parse(value);
try {
for (let i = 0; i < jsonObj.length; i++) {
console.log(jsonObj[i]);
firebase.database().ref(`user/${userName}/employees`)
.push({
firstName: jsonObj[i].firstName,
lastName: jsonObj[i].lastName,
personalId: jsonObj[i].personalId,
address: jsonObj[i].address,
gender: jsonObj[i].gender,
birthday: jsonObj[i].birthday
});
}
AsyncStorage.removeItem('employees');
this.setState({ employees: [] });
}
catch (err) {
console.log(`Error while pushing data: ${err}`);
}
});
} else {
Alert.alert(
'Connectivity error',
'No internet connection detected. Employees will be submited after a connection is established',
[
{ text: 'Cancel', onPress: () => console.log('Cancel Pressed'), style: 'cancel' },
{ text: 'OK', onPress: () => console.log('OK Pressed') },
]
);
}
});
}
Expand All @@ -60,7 +73,7 @@ class EmployeeList extends Component {
this.setState({ employees: [] });
}

renderButton() {
renderButton() {
if (this.state.employees.length === 0) {
return;
}
Expand Down
45 changes: 37 additions & 8 deletions registr/src/components/newEmployeeForm.js
@@ -1,6 +1,17 @@
import React, { Component } from 'react';
import { AsyncStorage, Text, Picker } from 'react-native';
import { Button, Card, CardSection, Spinner, TextBox, Select, DateTime } from './common';
import { AsyncStorage, Text, Picker, ToastAndroid } from 'react-native';
import SpeechAndroid from 'react-native-android-voice';
import {
VoiceTextBox,
Button,
Card,
CardSection,
Spinner,
TextBox,
Select,
DateTime
} from './common';


const Item = Picker.Item;

Expand All @@ -21,6 +32,12 @@ class NewEmployeeForm extends Component {
};
}

async onVoiceButtonPress() {
SpeechAndroid.startSpeech('Speak yo', SpeechAndroid.GERMAN)
.then(text => { ToastAndroid.show(text, ToastAndroid.LONG); })
.catch(error => { ToastAndroid.show(error, ToastAndroid.LONG); });
}

onButtonPress() {
if (this.validateFields()) {
this.setState({ loading: true });
Expand Down Expand Up @@ -52,6 +69,14 @@ class NewEmployeeForm extends Component {
this.state.onNextPage();
}


onSaveFail(error) {
this.setState({
loading: false,
error: `An error occuerd! ${error}`
});
}

validateFields() {
if (this.isEmpty(this.state.firstName) ||
this.isEmpty(this.state.lastName) ||
Expand All @@ -66,12 +91,6 @@ class NewEmployeeForm extends Component {
}
return true;
}
onSaveFail(error) {
this.setState({
loading: false,
error: `An error occuerd! ${error}`
});
}

isEmpty(str) {
return (!str || str.length === 0);
Expand All @@ -95,6 +114,16 @@ class NewEmployeeForm extends Component {
render() {
return (
<Card>
<CardSection>
<VoiceTextBox
label={'First name'}
onChangeText={firstName => this.setState({ firstName })}
placeholder={'eg. John'}
value={this.state.firstName}
onPress={this.onVoiceButtonPress.bind(this)}
/>
</CardSection>

<CardSection>
<TextBox
label={'First name'}
Expand Down

0 comments on commit fcc5a0e

Please sign in to comment.