-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathUPnPRenderersScreen.js
138 lines (126 loc) · 5.42 KB
/
UPnPRenderersScreen.js
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
/*
* The MIT License (MIT)
*
* Copyright (c) 2020 Richard Backhouse
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
import React from 'react';
import {
View,
TouchableOpacity,
Text,
Alert,
ActivityIndicator
} from 'react-native';
import UPnPManager from './UPnPManager';
import Icon from 'react-native-vector-icons/FontAwesome';
import { SwipeListView, SwipeRow } from 'react-native-swipe-list-view';
import { StyleManager } from './Styles';
import ActionButton from 'react-native-action-button';
import IonIcon from 'react-native-vector-icons/Ionicons';
export default class ConnectionsScreen extends React.Component {
static navigationOptions = {
title: 'Renderers'
};
state = {
upnpRenderers: [],
selected: (new Map(): Map<string, boolean>),
loading: false
}
componentDidMount() {
this.onUPnPRendererDiscover = UPnPManager.addListener(
"OnRendererDiscover",
(renderer) => {
this.state.upnpRenderers = this.state.upnpRenderers.filter((u) => {
return !(u.udn === renderer.udn);
});
if (renderer.action === "find") {
renderer.key = renderer.udn;
this.state.upnpRenderers.push(renderer);
}
this.setState({upnpServers: this.state.upnpRenderers});
}
);
this.load();
}
componentWillUnmount() {
this.onUPnPRendererDiscover.remove();
}
load() {
let upnpRenderers = UPnPManager.getRenderers();
upnpRenderers.forEach((u) => {
u.key = u.udn;
});
this.setState({upnpRenderers: upnpRenderers});
}
connectRow(rowMap, item) {
if (rowMap[item.udn]) {
rowMap[item.udn].closeRow();
}
UPnPManager.connectRenderer(item.udn);
}
renderSeparator = () => {
const common = StyleManager.getStyles("styles");
return (
<View
style={common.separator}
/>
);
};
render() {
const styles = StyleManager.getStyles("connectionsStyles");
const common = StyleManager.getStyles("styles");
const navigation = this.props.navigation;
return (
<View style={common.container1}>
<SwipeListView
useSectionList
sections={[
{title: 'UPnP Renderers', data: this.state.upnpRenderers}
]}
renderItem={(data, map) => {
const openVal = -75;
const item = data.item;
const selected = this.state.selected.get(item.udn) === true ? "flex" : "none";
return (
<SwipeRow rightOpenValue={openVal}>
<View style={common.rowBack}>
<TouchableOpacity style={[common.backRightBtn, common.backRightBtnRight]} onPress={ _ => this.connectRow(map, item) }>
<Text style={common.backTextWhite}>Connect</Text>
</TouchableOpacity>
</View>
<View style={[common.container3, common.rowFront]}>
<View style={common.container4}>
<Text style={styles.item}>{item.name}</Text>
</View>
<Icon name="check" size={15} style={[{ display: selected }, common.icon]}/>
</View>
</SwipeRow>
);}}
renderSectionHeader={({section}) => <Text style={common.sectionHeaderAlt}>{section.title}</Text>}
ItemSeparatorComponent={this.renderSeparator}
/>
{this.state.loading &&
<View style={common.loading}>
<ActivityIndicator size="large" color="#0000ff"/>
</View>
}
<ActionButton buttonColor="rgba(231,76,60,1)" hideShadow={true}>
<ActionButton.Item buttonColor='#1abc9c' title="Rescan" size={40} textStyle={common.actionButtonText} onPress={() => {this.onRescan();}}>
<IonIcon name="ios-refresh" size={20} color="white"/>
</ActionButton.Item>
</ActionButton>
</View>
);
}
}