-
Notifications
You must be signed in to change notification settings - Fork 0
/
DownloadingProgressInfo.tsx
115 lines (87 loc) · 3.23 KB
/
DownloadingProgressInfo.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
import React, { createRef, RefObject, Component } from 'react'
import { ButtonPretty } from './ButtonPretty'
import { StyleSheet, Text, View, Platform,StatusBar, TextInput, FlatList, Image, Modal, Switch,AsyncStorage, Alert, AlertButton, StyleProp, ViewStyle, TextStyle, TextStyleAndroid, ImageSourcePropType } from 'react-native';
import { IDownloadProg } from './ghost-yvdl';
import { st } from './SvgMi';
const downloadProgressInfo_Style:StyleProp<ViewStyle> = {
width: "100%",
flex:1 ,
flexDirection:"row",
justifyContent: "space-between" ,
paddingHorizontal:4,
paddingVertical:2 ,
marginBottom: 2 ,
alignContent: "center",
alignItems: "center" ,
alignSelf: "stretch" ,
}
const speed_style = {
fontSize: 11 ,
minWidth: 80 ,
//background-color: red;
// color: "#0df259" ,
color:'lightseagreen',
marginLeft: 6 ,
}
const percent_style ={
minWidth: 50,
fontWeight:"bold",
// background-color: red;
fontSize: 12 ,
color: "white" ,
}
const pretty_preset = {
spanStyle:{fontSize:11,color:"#eee"},
iconChild :true,
style:{flexDirection:"row-reverse",elevation:2,borderWidth:0.5,borderColor:"#444", marginRight:-2,} ,
Wraper_rest_color:"#242424" ,
wraper_pressed_color:"#444444"
}
type DownloadingProgressInfo_props={
key?:any
download_prog:IDownloadProg;
onCancel?():void
}
type DownloadingProgressInfo_state={
download_prog:IDownloadProg;
speed:number;
onCancel():void
}
export default class DownloadingProgressInfo extends Component<DownloadingProgressInfo_props,DownloadingProgressInfo_state>{ // it showns speed: | percent | cancelButton
constructor(props: DownloadingProgressInfo_props){
super(props)
this.state={
speed: 1 ,
download_prog:props.download_prog,
onCancel:props.onCancel
}
this.last_download_prog ={d:0,t:props.download_prog.t},
this.timer = setInterval(() => {
let new_speed= (this.state.download_prog.d-this.last_download_prog.d)
//console.log("state.download_prog.d:" + this.props.download_prog.d)
//console.log("state.last_download_pro.d:" +this.last_download_prog.d)
//console.log("new speed:" + new_speed)
this.last_download_prog=this.props.download_prog
this.setState({ speed:Math.floor(new_speed/1024)})
}, 1000);
}
last_download_prog:IDownloadProg
timer:any
componentWillUnmount(){
clearInterval(this.timer)
}
render(){
return(
<View style = {downloadProgressInfo_Style} >
<Text style={speed_style} >{this.state.speed} Kb/s</Text>
<Text style={percent_style} >{Math.ceil (100*(this.props.download_prog.d/this.props.download_prog.t)) || "0"} %</Text>
{/* <button className='cancelButton'>Cancel</button> */}
<ButtonPretty {...pretty_preset} onClick={this.props.onCancel} caption="Cancel"
iconMiProps={{xmldata: st.cancel}}
>
</ButtonPretty>
<ButtonPretty />
</View>
)
}
}