-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
129 lines (124 loc) · 5.59 KB
/
App.js
File metadata and controls
129 lines (124 loc) · 5.59 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
import React, { Component } from 'react';
import { Text, View, TouchableOpacity, Image, ScrollView } from 'react-native';
import Video from 'react-native-video';
import styles from './src/styles';
import Header from './src/components/Header';
import Footer from './src/components/Footer';
import Acitvity from './src/components/Activity';
export default class App extends Component {
state = {
radioStationList: [],
isLoading: true,
radioStationActive: false,
selectedRadioStation: null
}
componentDidMount() {
this.getMovies();
}
async getMovies() {
try {
const radioStationData = await fetch('http://www.radio-browser.info/webservice/json/stations/bycountryexact/lithuania');
const responseRadioStationList = await radioStationData.json();
this.setState({
radioStationList: responseRadioStationList,
isLoading: false
});
} catch (error) {
console.error(error);
}
}
handleRadioStation = (item) => {
const { radioStationList, radioStationActive, selectedRadioStation } = this.state;
const filteredRadioStation = radioStationList.filter(radioStation => radioStation === item);
if (radioStationActive && filteredRadioStation[0].id === selectedRadioStation[0].id) {
this.setState({
radioStationActive: false
});
} else {
this.setState({
radioStationActive: true,
selectedRadioStation: filteredRadioStation
});
}
}
render() {
const { radioStationList, isLoading, radioStationActive, selectedRadioStation } = this.state;
return (
<View style={styles.main}>
<Header />
{!isLoading ? (
<ScrollView style={[radioStationActive ? styles.radioStationList : null]}>
{radioStationList.map(radioStation => (
<View key={radioStation.id}>
<TouchableOpacity onPress={() => this.handleRadioStation(radioStation)}>
<View style={styles.radioStationListItem}>
<Text style={styles.radioStationName} numberOfLines={1}>
{radioStation.name}
</Text>
<Text style={styles.radioStationFrequency} numberOfLines={1}>
{radioStation.votes}
,
{' '}
{radioStation.votes[0]}
</Text>
</View>
<View style={styles.seperator} />
</TouchableOpacity>
{radioStationActive && radioStation.id === selectedRadioStation[0].id ? (
<View style={styles.radioStationDetails}>
<TouchableOpacity>
<Image
style={{ width: 35, height: 35 }}
source={require('./src/assets/minus.png')}
/>
</TouchableOpacity>
{radioStation.favicon === '' ? (
<Image
style={styles.radioStationLogo}
source={require('./src/assets/radioFallBackImage.jpg')}
/>
) : (
<Image
style={styles.radioStationLogo}
source={{ uri: `${radioStation.favicon}` }}
/>
)}
<TouchableOpacity>
<Image
style={{ width: 35, height: 35 }}
source={require('./src/assets/plus.png')}
/>
</TouchableOpacity>
</View>
) : (
null
)}
</View>
))}
</ScrollView>
) : (
<Acitvity />
)}
{radioStationActive ? (
<Footer name={selectedRadioStation[0].name} />
) : (
null
)}
{radioStationActive ? (
<Video
source={{ uri: selectedRadioStation[0].url }}
ref={(ref) => {
this.player = ref;
}}
audioOnly
onBuffer={this.onBuffer}
onError={this.videoError}
style={styles.backgroundVideo}
/>
) : (
null
)}
</View>
);
}
}