Skip to content

Commit

Permalink
Weather Displaying
Browse files Browse the repository at this point in the history
  • Loading branch information
ChaseTeichmann committed Oct 30, 2019
1 parent dc6fdfb commit ae914bb
Show file tree
Hide file tree
Showing 5 changed files with 190 additions and 67 deletions.
2 changes: 1 addition & 1 deletion Routinely/app/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default createAppContainer(
Auth: AuthStack,
},
{
initialRouteName: 'App',
initialRouteName: 'Auth',
},
),
);
39 changes: 11 additions & 28 deletions Routinely/app/screens/alarm.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import React, {Component} from 'react';
import {View, StyleSheet, TouchableHighlight, Image} from 'react-native';
import {
View,
StyleSheet,
TouchableHighlight,
Image,
FlatList,
Text,
TouchableOpacity,
Button,
} from 'react-native';
import DayPicker from '../components/alarm_components/DayPicker';
import RepeatDiv from '../components/alarm_components/RepeatDiv';
import SnoozeDuration from '../components/alarm_components/SnoozeDuration';
Expand All @@ -22,33 +31,7 @@ class AlarmScreen extends Component {
<Divider />
<ColorPicker />
<Divider />
<View style={styles.container}>
<View style={{flexDirection: 'row'}}>
<TouchableHighlight
onPress={() => this.props.navigation.navigate('Calendar')}>
<Image
style={styles.contain}
source={require('../components/img/calendar.png')}
/>
</TouchableHighlight>
<TouchableHighlight
onPress={() => this.props.navigation.navigate('Alarm')}>
<Image
style={styles.contain}
source={require('../components/img/alarm.png')}
/>
</TouchableHighlight>
<TouchableHighlight
onPress={() => {
this.signOut;
}}>
<Image
style={styles.contain}
source={require('../components/img/logout.png')}
/>
</TouchableHighlight>
</View>
</View>
<Button onPress={() => this.props.navigation.navigate('AlarmRinging')} title="Ring"/>
</View>
);
}
Expand Down
116 changes: 114 additions & 2 deletions Routinely/app/screens/alarmRinging.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,90 @@
import React, {Component} from 'react';
import {View, StyleSheet, Button} from 'react-native';
import {View, StyleSheet, Button, Text} from 'react-native';
import DisplayTime from '../components/alarmRinging_components/DisplayTime';

class AlarmRingingScreen extends Component {
constructor(props) {
super(props);
this.state = {
dataSource: [],
loading: true,
};
}
componentDidMount(): void {
fetch(
'https://weatherbit-v1-mashape.p.rapidapi.com/forecast/hourly?lang=en&hours=12&units=I&lat=39.9625984&lon=-76.727745',
{
method: 'GET',
headers: {
'x-rapidapi-host': 'weatherbit-v1-mashape.p.rapidapi.com',
'x-rapidapi-key':
'9f78f19a5fmshb5fb8f8cf101477p17766bjsne3fe3b3d556f',
},
},
)
.then(response => response.json())
.then(responseJson => {
console.log(responseJson.city_name);
this.setState({
loading: false,
dataSource: responseJson,
city: responseJson.city_name,
state: responseJson.state_code,
temperatureNow: responseJson.data[0].temp,
precipitationNow: responseJson.data[0].precip,
weatherConditionsNow: responseJson.data[0].weather.description,

temperature6Hrs: responseJson.data[5].temp,
precipitation6Hrs: responseJson.data[5].precip,
weatherConditions6Hrs: responseJson.data[5].weather.description,

temperature12Hrs: responseJson.data[11].temp,
precipitation12Hrs: responseJson.data[11].precip,
weatherConditions12Hrs: responseJson.data[11].weather.description,
});
})
.catch(error => console.log(error)); //to catch the errors if any
}
render() {
return (
<View>
<DisplayTime />
<Text style={styles.location}>
{this.state.city}, {this.state.state}
</Text>
<View style={styles.row}>
<View style={styles.forecast}>
<Text style={styles.time}>Right Now</Text>
<Text style={styles.conditions}>
{this.state.weatherConditionsNow}
</Text>
<Text style={styles.temp}>Temp {this.state.temperatureNow}</Text>
<Text style={styles.rain}>
Rain: {this.state.precipitationNow}%
</Text>
</View>
<View style={styles.forecast}>
<Text style={styles.time}>6 Hrs</Text>
<Text style={styles.conditions}>
{this.state.weatherConditions6Hrs}
</Text>
<Text style={styles.temp}>Temp {this.state.temperature6Hrs}</Text>
<Text style={styles.rain}>
Rain: {this.state.precipitation6Hrs}%
</Text>
</View>
<View style={styles.forecast}>
<Text style={styles.time}>12 Hrs</Text>
<Text style={styles.conditions}>
{' '}
{this.state.weatherConditions12Hrs}
</Text>
<Text style={styles.temp}>Temp {this.state.temperature12Hrs}</Text>
<Text style={styles.rain}>
Rain: {this.state.precipitation12Hrs}%
</Text>
</View>
</View>
<Button
title="Calendar"
onPress={() => this.props.navigation.navigate('Calendar')}
Expand All @@ -20,6 +98,40 @@ class AlarmRingingScreen extends Component {
}
}

const styles = StyleSheet.create({});
const styles = StyleSheet.create({
location: {
textAlign: 'center',
},
row: {
flexDirection: 'row',
textAlign: 'center',
},
forecast: {
textAlign: 'center',
flexDirection: 'column',
padding: 5,
margin: 10,
borderWidth: 1,
borderRadius: 15,
},
time: {
textAlign: 'center',
fontSize: 12,
},
temp: {
textAlign: 'center',
fontSize: 14,
},
rain: {
textAlign: 'center',
fontSize: 14,
},
conditions: {
textAlign: 'center',
fontSize: 12,
paddingBottom: 3,
paddingTop: 3,
},
});

export default AlarmRingingScreen;
97 changes: 62 additions & 35 deletions Routinely/app/screens/calendar.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
import React, {Component} from 'react';
import {Alert, Button, FlatList, Image, Platform, StyleSheet, Text, TouchableHighlight, TouchableOpacity, View,} from 'react-native';
import {AgendaList,CalendarProvider, ExpandableCalendar,} from 'react-native-calendars';
import {
Alert,
Button,
FlatList,
Image,
Platform,
StyleSheet,
Text,
TouchableHighlight,
TouchableOpacity,
View,
} from 'react-native';
import {
AgendaList,
CalendarProvider,
ExpandableCalendar,
} from 'react-native-calendars';
import _ from 'lodash';
import moment from 'moment';
import firebase from '@react-native-firebase/app';
Expand All @@ -16,9 +31,7 @@ const dates = [fastDate, today].concat(futureDates);
//need to figure out if we can order the events when we are listing them by date
//the day also is not acting correctly and the am/pm isnt either

var events = [

];
var events = [];

const utcDateToString = (momentInUTC: moment): string => {
// console.warn(s);
Expand All @@ -30,7 +43,7 @@ const user = firebase.auth().currentUser;
const eventsRef = firestore()
.collection('users')
.doc(user.email)
.collection('events');
.collection('events');

//const eventsRef = eRef.collection('event');

Expand Down Expand Up @@ -62,23 +75,22 @@ class CalendarScreen extends Component {
event: '',
};

getEvents = async eventRetrieved => {
getEvents = async eventRetrieved => {
try {
eventsRef.onSnapshot(querySnapshot=>{
querySnapshot.forEach(event => {
eventsRef.onSnapshot(querySnapshot => {
querySnapshot.forEach(event => {
this.state.eventList.push(event.data());
console.log("this is the event " +event.get('chosenDate').toDate());
console.log('this is the event ' + event.get('chosenDate').toDate());
});
eventRetrieved(this.state.eventList);
eventRetrieved(this.state.eventList);
});

} catch (error) {
console.log('problem retrieving tasks');
}
};

onEventsRetrieved = eventList => {
console.log("event list:" +eventList);
console.log('event list:' + eventList);
this.setState(prevState => ({
eventList: (prevState.eventList = eventList),
}));
Expand Down Expand Up @@ -107,20 +119,20 @@ class CalendarScreen extends Component {
getMarkedDates = () => {
const marked = {};
const mark = this.state.eventList;
mark.forEach(event =>{
mark.forEach(event => {
// only mark dates with data
const month = event.chosenDate.toDate().getUTCMonth() + 1; //months from 1-12
const day = event.chosenDate.toDate().getUTCDate();
const year = event.chosenDate.toDate().getUTCFullYear();
const markdate = year + "-" + month + "-" + day;

const markdate = year + '-' + month + '-' + day;

marked[markdate] = {marked: true};
console.log('successfully added');
})
console.log('Marked:' +marked);
});
console.log('Marked:' + marked);
return marked;
};
};

getTheme = () => {
const themeColor = '#0059ff';
Expand Down Expand Up @@ -194,22 +206,37 @@ class CalendarScreen extends Component {
data={this.state.eventList}
keyExtractor={item => item.id}
renderItem={({item}) => {
return (
<TouchableOpacity
onPress={() => this.itemPressed(item.title+ ' ' +item.notes)}
style={styles.item}>
<View>
<Text style={styles.itemHourText}>{item.hour}</Text>
<Text style={styles.itemDurationText}>{item.duration}</Text>
</View>
<Text style={styles.itemTitleText}>{item.title} </Text>
<Text style={styles.itemHourText}>{item.notes} </Text>
<Text style={styles.itemHourText}>{item.chosenDate.toDate().getUTCMonth()+1} - {item.chosenDate.toDate().getUTCDate()} - {item.chosenDate.toDate().getUTCFullYear()} </Text>
<Text style={styles.itemHourText}>{item.chosenDate.toDate().getHours() > 12 ? (item.chosenDate.toDate().getHours() - 12) : item.chosenDate.toDate().getHours()}:{item.chosenDate.toDate().getMinutes() < 10 ? ("0"+(item.chosenDate.toDate().getMinutes())):(item.chosenDate.toDate().getMinutes())} {item.chosenDate.toDate().getHours() > 12 ?'pm':'am'}</Text>
</TouchableOpacity>
);
}}
/>
return (
<TouchableOpacity
onPress={() =>
this.itemPressed(item.title + ' ' + item.notes)
}
style={styles.item}>
<View>
<Text style={styles.itemHourText}>{item.hour}</Text>
<Text style={styles.itemDurationText}>{item.duration}</Text>
</View>
<Text style={styles.itemTitleText}>{item.title} </Text>
<Text style={styles.itemHourText}>{item.notes} </Text>
<Text style={styles.itemHourText}>
{item.chosenDate.toDate().getUTCMonth() + 1} -{' '}
{item.chosenDate.toDate().getUTCDate()} -{' '}
{item.chosenDate.toDate().getUTCFullYear()}{' '}
</Text>
<Text style={styles.itemHourText}>
{item.chosenDate.toDate().getHours() > 12
? item.chosenDate.toDate().getHours() - 12
: item.chosenDate.toDate().getHours()}
:
{item.chosenDate.toDate().getMinutes() < 10
? '0' + item.chosenDate.toDate().getMinutes()
: item.chosenDate.toDate().getMinutes()}{' '}
{item.chosenDate.toDate().getHours() > 12 ? 'pm' : 'am'}
</Text>
</TouchableOpacity>
);
}}
/>
<View style={styles.plus}>
<View>
<TouchableHighlight
Expand Down
3 changes: 2 additions & 1 deletion Routinely/app/screens/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class LoginScreen extends Component {
loggedIn: false,
email: '',
password: '',
datasource: [],
loading: true,
};
}

Expand Down Expand Up @@ -92,7 +94,6 @@ class LoginScreen extends Component {
console.error(error);
}
};

render() {
return (
<ImageBackground
Expand Down

0 comments on commit ae914bb

Please sign in to comment.