Skip to content

Commit

Permalink
lol added music
Browse files Browse the repository at this point in the history
  • Loading branch information
githubschman committed Mar 12, 2018
1 parent 924a026 commit e7b4155
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 10 deletions.
1 change: 1 addition & 0 deletions android/app/build.gradle
Expand Up @@ -139,6 +139,7 @@ android {
}

dependencies {
compile project(':react-native-sound')
compile project(':react-native-code-push')
compile project(':react-native-google-analytics-bridge')
compile project(':react-native-onesignal')
Expand Down
2 changes: 2 additions & 0 deletions android/app/src/main/java/me/jsapp/myapp/MainApplication.java
Expand Up @@ -4,6 +4,7 @@
import android.util.Log;

import com.facebook.react.ReactApplication;
import com.zmxv.RNSound.RNSoundPackage;
import com.microsoft.codepush.react.CodePush;
import com.idehub.GoogleAnalyticsBridge.GoogleAnalyticsBridgePackage;
import com.geektime.rnonesignalandroid.ReactNativeOneSignalPackage;
Expand Down Expand Up @@ -38,6 +39,7 @@ protected boolean getUseDeveloperSupport() {
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new RNSoundPackage(),
new CodePush(getResources().getString(R.string.reactNativeCodePush_androidDeploymentKey), getApplicationContext(), BuildConfig.DEBUG),
new GoogleAnalyticsBridgePackage(),
new ReactNativeOneSignalPackage(),
Expand Down
2 changes: 2 additions & 0 deletions android/settings.gradle
@@ -1,4 +1,6 @@
rootProject.name = 'MyApp'
include ':react-native-sound'
project(':react-native-sound').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sound/android')
include ':react-native-code-push'
project(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app')
include ':react-native-google-analytics-bridge'
Expand Down
98 changes: 96 additions & 2 deletions ios/MyApp.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -29,6 +29,7 @@
"react-native-onesignal": "^3.0.0",
"react-native-scrollable-tab-view": "^0.7.1",
"react-native-share": "1.0.19",
"react-native-sound": "^0.10.9",
"react-native-vector-icons": "^4.0.0"
},
"devDependencies": {
Expand Down
100 changes: 94 additions & 6 deletions src/components/home_screen/windowsill.js
@@ -1,4 +1,5 @@
import React, { Component } from 'react'
const Sound = require('react-native-sound');
import {
Text,
View,
Expand All @@ -13,24 +14,22 @@ import {
Alert,
InteractionManager,
} from 'react-native';

// backgrounds:
import BackgroundImage from '../../views/background'
import SingleBackgroundImage from '../../views/single_background'
// all pictures
const pix = require("../../assets/images/plantpicturecollection");

import Icon from 'react-native-vector-icons/Ionicons';
import Share from 'react-native-share'
import { Actions } from 'react-native-mobx'
import _ from 'lodash'
import moment from 'moment'
import { observer,inject } from 'mobx-react/native'
import { getColor } from '../config'
import { firebaseApp } from '../../firebase'
import { createStageArr, decreaseInventory, newMessage, thumbNail, sillType, plantPic } from '../../../utils'
import { hour, setUpPlant, Planter } from '../../planterconfig';

// all pictures
const pix = require("../../assets/images/plantpicturecollection");


require('../../../secrets')
Expand Down Expand Up @@ -60,7 +59,10 @@ export default class WindowSill extends Component {
watered: false, // temporary watered on local state for graphics reasons
sillPic: 'default',
toggleInfo: false,
wateringCan: false
wateringCan: false,
song: {},
songIsPlaying: false,
allSongs: {}
}

this.store = this.props.appStore
Expand Down Expand Up @@ -88,9 +90,78 @@ export default class WindowSill extends Component {
}
};
xhr.send();
}
}

preloadSoungs() {

// rain-night
// rain
// snow-night
// snow
// default
// default-night

let snow = new Sound('snow.mp3', Sound.MAIN_BUNDLE, (error) => {
if (error) {
console.log('failed to load the sound', error);
return;
}
});

let rain = new Sound('rain.mp3', Sound.MAIN_BUNDLE, (error) => {
if (error) {
console.log('failed to load the sound', error);
return;
}
});

let rainNight = new Sound('rain-night.mp3', Sound.MAIN_BUNDLE, (error) => {
if (error) {
console.log('failed to load the sound', error);
return;
}
});

let snowNight = new Sound('snow-night.mp3', Sound.MAIN_BUNDLE, (error) => {
if (error) {
console.log('failed to load the sound', error);
return;
}
});

let clearNight = new Sound('clear-night.mp3', Sound.MAIN_BUNDLE, (error) => {
if (error) {
console.log('failed to load the sound', error);
return;
}
});

let defaultSoundPath = (Math.floor(Math.random() * 100) % 2) ? 'sunny-day.mp3' : 'sunny-day2.mp3';

let defaultSound = new Sound(defaultSoundPath, Sound.MAIN_BUNDLE, (error) => {
if (error) {
console.log('failed to load the sound', error);
return;
}
});

this.setState({allSongs: {
'snow-night': snowNight,
'snow': snow,
'rain-night': rainNight,
'rain': rain,
'default': defaultSound,
'default-night': clearNight
}})

}

componentDidMount() {

// Preloading all the songs (and sounds)
Sound.setCategory('Playback');
this.preloadSoungs()

let fetchingWeather = this.store.fetchWeather(this.userRef);
let checkingUserLevel = this.store.checkUserLevel(this.userRef);

Expand Down Expand Up @@ -119,16 +190,33 @@ export default class WindowSill extends Component {
this.store.checkWeatherAgainstPlants(plantId, this.userRef, this.store.weather);
plantId++;
}

this.setState({sillPic: sillType(this.store.weather.temp, this.store.weather.sun)});
if (this.store.weatherPic !== this.state.sillPic) {
this.store.weatherPic = this.state.sillPic;
}

this.setState({song: this.state.allSongs[this.store.weatherPic]});

this.refresh((result) => {this.setState({connected: result})});

// if ya boy is on the move
navigator.geolocation.getCurrentPosition((loc)=>{
this.store.user_long = String(loc.coords.longitude);
this.store.user_lat = String(loc.coords.latitude);
}, null, { enableHighAccuracy: true});

if (!this.state.songIsPlaying){
this.state.song.play((success) => {
if (success) {
console.log('successfully finished playing');
}
});
this.setState({songIsPlaying: true});
// loops song forever
this.state.song.setNumberOfLoops(-1);
}

}

componentDidUpdate() {
Expand Down
3 changes: 1 addition & 2 deletions utils/index.js
Expand Up @@ -11,7 +11,6 @@ export const decreaseInventory = (item, props, userRef) => {
}

export const sillType = (temp, sun) => {


// FOR AM OR PM SILLS
let date = new Date();
Expand All @@ -38,4 +37,4 @@ export const sillType = (temp, sun) => {
}

return str;
}
}
4 changes: 4 additions & 0 deletions yarn.lock
Expand Up @@ -3274,6 +3274,10 @@ react-native-share@1.0.19:
version "1.0.19"
resolved "https://registry.yarnpkg.com/react-native-share/-/react-native-share-1.0.19.tgz#82c210efb156175d67ee271efee29ed9cf8e1449"

react-native-sound@^0.10.9:
version "0.10.9"
resolved "https://registry.yarnpkg.com/react-native-sound/-/react-native-sound-0.10.9.tgz#6b00b0f4afd017cde09fbb9d171df1b5d5b851a8"

react-native-tabs@^1.0.9:
version "1.0.9"
resolved "https://registry.yarnpkg.com/react-native-tabs/-/react-native-tabs-1.0.9.tgz#75d3c35e8b5b6970869eab282372cb32e2a782cd"
Expand Down

0 comments on commit e7b4155

Please sign in to comment.