-
Notifications
You must be signed in to change notification settings - Fork 1
/
Welcome_BackUp.js
203 lines (179 loc) · 5.29 KB
/
Welcome_BackUp.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
'use strict';
import React from 'react';
import {
StyleSheet,
View,
Text,
Image,
Component,
ScrollView,
ListView,
RefreshControl,
AlertIOS,
TouchableHighlight
} from 'react-native';
var styles = StyleSheet.create({
description: {
fontSize: 20,
textAlign: 'center',
color: '#FFFFFF'
},
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#012a77',
},
row: {
flex: 1,
padding: 26,
borderWidth: 1,
borderColor: '#DDDDDD'
},
newsTitle: {
fontSize: 16,
fontWeight: 'bold'
},
newsPreviewStyle: {
fontSize: 14,
marginTop: 15
}
});
var DOMParser = require('xmldom').DOMParser;
var objs = [];
var newsPreview=[];
var newsURL = [];
var result = [];
var NewsDetail = require('./Classes/NewsDetail.js');
var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
class Welcome extends Component {
constructor(props) {
super(props);
this._renderRow = this._renderRow.bind(this);
this.showNewsDetail = this.showNewsDetail.bind(this);
this.state = {
refreshing: false,
dataSource: ds.cloneWithRows([])
};
}
showNewsDetail(result, n) {
this.props.navigator.push({
title: 'Подробнее',
component: NewsDetail,
passProps: {link : result[n].linkURL}
});
}
_renderRow(rowData, sectionID, rowID) {
var n = rowID;
return (
<TouchableHighlight onPress={() => this.showNewsDetail(result, n)} underlayColor='#DDDDDD'>
<View style={styles.row}>
<Text style={styles.newsTitle}>{rowData.title}</Text>
<Text style={styles.newsPreviewStyle}>{rowData.preview}</Text>
</View>
</TouchableHighlight>
)
}
/*parseVideos(responseText) {
console.log("Parsing the feed...");
var doc = new DOMParser().parseFromString(responseText, 'text/xml');
var videos = doc.getElementsByTagName('title_news');
var thumbs = doc.getElementsByTagName('preview_news');
for (var i=0; i < videos.length; i++) {
objs.push(videos[i].textContent),
newsPreview.push(thumbs[i].textContent)
}
for (var y=0; y < objs.length; y++) {
result.push({ title: objs[y], preview: newsPreview[y]})
}
console.log('Finished parsing. Got this on TITLE: ' + objs);
console.log('Finished parsing. Got this on PREVIEW: ' + result);
this.setState({
dataSource: this.state.dataSource.cloneWithRows(result)
});
}*/
fetchVideos() {
console.log('Fetching video feed...');
var url = "http://kpfu.ru/portal/PRIVATEOFFICE_ANDROID.news?p_news=2";
fetch(url)
.then((response) => response.text())
.then((responseText) => {
console.log("Parsing the feed...");
var doc = new DOMParser().parseFromString(responseText, 'text/xml');
var videos = doc.getElementsByTagName('title_news');
var thumbs = doc.getElementsByTagName('preview_news');
var linksToTheNews = doc.getElementsByTagName('url_news');
for (var i=0; i < videos.length; i++) {
objs.push(videos[i].textContent),
newsPreview.push(thumbs[i].textContent),
newsURL.push(linksToTheNews[i].textContent)
}
for (var y=0; y < objs.length; y++) {
result.push({ title: objs[y], preview: newsPreview[y], linkURL: newsURL[y]})
}
console.log('Finished parsing. Got this on TITLE: ' + objs);
console.log('Finished parsing. Got this on PREVIEW: ' + result);
this.setState({
dataSource: this.state.dataSource.cloneWithRows(result)
});
})
.catch((error) => {
console.log('Error fetching the feed: ', error);
});
}
refresOnReload() {
this.setState({
dataSource: ds.cloneWithRows([]),
refreshing: true
});
objs = [];
newsPreview=[];
newsURL=[];
result = [];
var url = "http://kpfu.ru/portal/PRIVATEOFFICE_ANDROID.news?p_news=2";
fetch(url)
.then((response) => response.text())
.then((responseText) => {
console.log("Parsing the feed...");
var doc = new DOMParser().parseFromString(responseText, 'text/xml');
var videos = doc.getElementsByTagName('title_news');
var thumbs = doc.getElementsByTagName('preview_news');
var linksToTheNews = doc.getElementsByTagName('url_news');
for (var i=0; i < videos.length; i++) {
objs.push(videos[i].textContent),
newsPreview.push(thumbs[i].textContent),
newsURL.push(linksToTheNews[i].textContent)
}
for (var y=0; y < objs.length; y++) {
result.push({ title: objs[y], preview: newsPreview[y], linkURL: newsURL[y]})
}
console.log('Finished parsing. Got this: ' + result);
this.setState({
dataSource: this.state.dataSource.cloneWithRows(result),
refreshing: false
});
})
.catch((error) => {
console.log('Error fetching the feed: ', error);
});
}
componentDidMount() {
this.fetchVideos();
}
render() {
return (
<ListView
refreshControl={
<RefreshControl
refreshing={this.state.refreshing}
onRefresh={this.refresOnReload.bind(this)}
/>
}
dataSource={this.state.dataSource}
renderRow={this._renderRow}
enableEmptySections
/>
);
}
}
module.exports = Welcome;