-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
156 lines (145 loc) · 4.27 KB
/
Copy pathApp.js
File metadata and controls
156 lines (145 loc) · 4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import React, { Component } from 'react';
import { Platform, StyleSheet, Text, TextInput,
DatePickerIOS, Button, View } from 'react-native';
import { formatToSeconds } from './utils'
import axios from 'axios';
import TrackPlayer from 'react-native-track-player';
import BackgroundTimer from 'react-native-background-timer';
import BackgroundTaskRunner from './BackgroundTaskRunner';
type Props = {};
export default class App extends Component<Props> {
constructor(props) {
super(props);
this.state = {
currentTime: '',
username: '',
date: new Date()
};
}
componentDidMount() {
this.tick = setInterval(() => this.handleCurrentTime(), 1000)
this.interval = BackgroundTimer.setTimeout(() => {
console.log('okay baby')
}, 10000);
}
handleCurrentTime(){
this.setState({
currentTime: new Date().toLocaleTimeString('en-US', {hour12: false})
});
}
handleValidation(){
let formIsValid = true;
if(this.state.username == 'undefined' || !this.state.username || this.state.date == 'undefined' || !this.state.date){
formIsValid = false
alert("Invalid form")
} else {
formIsValid = true
}
return formIsValid
}
createPlayer(timeLeft) {
axios.get('https://api.soundcloud.com/resolve?url=https://soundcloud.com/' + this.state.username + '/likes&client_id=4d2526333de7872dbd870ebe98115a5c')
.then(function (playlist) {
const track = playlist.data[0]
const streamUrl = track.stream_url + '?client_id=4d2526333de7872dbd870ebe98115a5c';
const streamTitle = track.title + '?client_id=4d2526333de7872dbd870ebe98115a5c';
const streamUser = track.stream_url + '?client_id=4d2526333de7872dbd870ebe98115a5c';
TrackPlayer.setupPlayer().then(async () => {
await TrackPlayer.add({
id: 'trackId',
url: streamUrl,
title: streamTitle,
artist: streamUser
});
});
TrackPlayer.updateOptions({
stopWithApp: false
})
BackgroundTimer.setTimeout(() => {
TrackPlayer.play()
console.log('this is working')
}, window.timeLeft * 1000)
alert('alarm set to' + ' ' + track.title +
', by ' + track.user.username + ' playing in' + window.timeLeft + ' seconds')
})
.catch(function(error) {
alert(error)
})
}
logCurrent() {
console.log(this.state.currentTime)
}
calculateTimeLeft() {
const nowInSeconds = formatToSeconds(this.state.currentTime.toString())
let alarmTimeInSeconds = formatToSeconds(this.state.date.toLocaleTimeString('en-US', {
hour12: false
}).toString())
window.timeLeft = alarmTimeInSeconds - nowInSeconds
console.log(window.timeLeft)
this.createPlayer(window.timeLeft)
}
render() {
return (
<View style={styles.mainContainer}>
<View style={styles.container}>
<Text style={styles.header}>
Soundcloud Likes Alarm
</Text>
<TextInput
style={styles.textInput}
placeholder="Username"
onChangeText={(username) => this.setState({username})}/>
<DatePickerIOS
style={styles.datePicker}
date={this.state.date}
mode="time"
onDateChange={(date) => this.setState({date})}/>
<Button
title="Set Alarm"
style={styles.button}
onPress={(currentTime) => this.calculateTimeLeft(currentTime)}/>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
mainContainer: {
backgroundColor: 'white',
alignItems: 'center',
justifyContent: 'center',
flex: 1,
flexDirection: 'column',
flexWrap: 'wrap',
height: '100%'
},
container: {
width: '80%',
alignItems: 'center',
justifyContent: 'center',
marginBottom: 40
},
header: {
fontSize: 30,
marginBottom: 40,
fontWeight: 'bold'
},
datePicker: {
height: 'auto',
width: '100%',
backgroundColor: '#fff'
},
textInput: {
width: '100%',
height: 40,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
textAlign: 'center',
borderRadius: 0,
marginBottom: 40
},
button: {
backgroundColor: 'yellow'
}
})