-
Notifications
You must be signed in to change notification settings - Fork 0
/
DownloadListItem.tsx
182 lines (177 loc) · 5.08 KB
/
DownloadListItem.tsx
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
import React, {Component} from 'react';
import {StyleSheet, Text, View, TouchableOpacity, Image, Button} from 'react-native';
import { DownloadStatus } from 'vdocipher-rn-bridge/type';
const statusDescription = (downloadStatus: DownloadStatus) => {
if (downloadStatus.status === 'downloading') {
return 'Downloading ' + downloadStatus.downloadPercent + '%';
} else if (downloadStatus.status === 'failed') {
return (
'Error ' +
downloadStatus.reason +
(downloadStatus.reasonDescription
? ': ' + downloadStatus.reasonDescription
: '')
);
} else {
return downloadStatus.status;
}
};
export default function DownloadListItem(props:{
title: string;
downloadStatus?: DownloadStatus;
onDownload: () => void;
onPlay: () => void;
onStop: () => void;
onResume: () => void;
onInfo: () => void;
onDelete: () => void;
} ) {
const {title, downloadStatus, onDownload, onPlay, onStop, onResume, onInfo, onDelete} =
props;
const {mediaInfo, status, downloadPercent, reason, reasonDescription} =
downloadStatus || {};
const playEnabled =
downloadStatus !== undefined && downloadStatus.status === 'completed';
const stopOrResumeEnabled =
downloadStatus !== undefined && downloadStatus.status !== 'completed' && downloadStatus.status !== 'removing';
const playOpacity = playEnabled ? 1 : 0.4;
const deleteEnabled = downloadStatus !== undefined;
const deleteOpacity = deleteEnabled ? 1 : 0.4;
const statusView = downloadStatus ? (
<View style={styles.statusViewContainer}>
<Text style={{fontSize: 20}}>{mediaInfo?.title}</Text>
<Text style={{fontSize: 14, fontWeight: 'bold'}}>
{statusDescription(downloadStatus).toUpperCase()}
</Text>
</View>
) : (
<View style={styles.statusViewContainer}>
<Text style={{fontSize: 20}}>
Tap the download icon to save this sample to local storage.
</Text>
</View>
);
return (
<View style={styles.container}>
<View style={styles.header}>
<Text
style={{flex: 1, paddingLeft: 8, fontSize: 22, fontWeight: 'bold'}}>
{title}
</Text>
<TouchableOpacity onPress={onDownload} activeOpacity={0.8}>
<Image source={require('./baseline_save_alt_black_18.png')} />
</TouchableOpacity>
</View>
<View
style={{
flexDirection: 'row',
flex: 1,
alignItems: 'center',
borderRadius: 2,
overflow: 'hidden',
}}>
{statusView}
</View>
<View style={styles.actionsContainer}>
<TouchableOpacity
onPress={onPlay}
activeOpacity={0.8}
disabled={!playEnabled}
style={{
width: 80,
height: 80,
justifyContent: 'center',
alignItems: 'center',
}}>
<Image
style={{opacity: playOpacity}}
source={require('./round_play_arrow_black_24.png')}
/>
</TouchableOpacity>
<View style={{
width: 80,
height: 80,
justifyContent: 'center',
alignItems: 'center',
}}>
<Button
disabled={!stopOrResumeEnabled}
title={"Stop"}
onPress={onStop}
/>
</View>
<View style={{
width: 80,
height: 80,
justifyContent: 'center',
alignItems: 'center',
}}>
<Button
disabled={!stopOrResumeEnabled}
title={"Resume"}
onPress={onResume}
/>
</View>
{/* <TouchableOpacity
onPress={onInfo}
activeOpacity={0.8}
disabled={true}
style={{
width: 80,
height: 80,
justifyContent: 'center',
alignItems: 'center',
}}>
<Image
style={{opacity: 0.4}}
source={require('./baseline_info_black_18.png')}
/>
</TouchableOpacity> */}
<TouchableOpacity
onPress={onDelete}
activeOpacity={0.8}
disabled={!deleteEnabled}
style={{
width: 80,
height: 80,
justifyContent: 'center',
alignItems: 'center',
}}>
<Image
style={{opacity: deleteOpacity}}
source={require('./baseline_delete_black_18.png')}
/>
</TouchableOpacity>
</View>
</View>
);
}
const styles = StyleSheet.create({
container: {
backgroundColor: 'lightsteelblue',
borderColor: 'lightsteelblue',
borderRadius: 2,
borderWidth: 4,
},
header: {
flexDirection: 'row',
flex: 1,
alignItems: 'center',
borderRadius: 2,
overflow: 'hidden',
},
statusViewContainer: {
padding: 10,
width: '100%',
backgroundColor: 'aliceblue',
height: 90,
},
actionsContainer: {
flexDirection: 'row',
flex: 1,
justifyContent: 'flex-end',
alignItems: 'center',
borderRadius: 2,
overflow: 'hidden',
},
});