display open file button. code cleanup.
This commit is contained in:
parent
c47c7cd925
commit
f5cb8e44d1
3 changed files with 30 additions and 20 deletions
|
@ -43,7 +43,17 @@ class FileDownloadButton extends React.PureComponent {
|
|||
onButtonLayout,
|
||||
} = this.props;
|
||||
|
||||
if ((fileInfo && !fileInfo.stopped) || loading || downloading) {
|
||||
if (fileInfo && fileInfo.download_path && fileInfo.completed) {
|
||||
return (
|
||||
<TouchableOpacity
|
||||
onLayout={onButtonLayout}
|
||||
style={[style, fileDownloadButtonStyle.container]}
|
||||
onPress={openFile}
|
||||
>
|
||||
<Text style={fileDownloadButtonStyle.text}>{isViewable ? __('View') : __('Open')}</Text>
|
||||
</TouchableOpacity>
|
||||
);
|
||||
} else if ((fileInfo && !fileInfo.stopped) || loading || downloading) {
|
||||
const progress = fileInfo && fileInfo.written_bytes ? (fileInfo.written_bytes / fileInfo.total_bytes) * 100 : 0,
|
||||
label = fileInfo ? __('%progress%% complete', { progress: progress.toFixed(0) }) : __('Connecting...');
|
||||
|
||||
|
@ -70,16 +80,6 @@ class FileDownloadButton extends React.PureComponent {
|
|||
onPress={onFileActionPress}
|
||||
/>
|
||||
);
|
||||
} else if (fileInfo && fileInfo.download_path) {
|
||||
return (
|
||||
<TouchableOpacity
|
||||
onLayout={onButtonLayout}
|
||||
style={[style, fileDownloadButtonStyle.container]}
|
||||
onPress={openFile}
|
||||
>
|
||||
<Text style={fileDownloadButtonStyle.text}>{isViewable ? __('View') : __('Open')}</Text>
|
||||
</TouchableOpacity>
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
|
@ -706,6 +706,18 @@ class FilePage extends React.PureComponent {
|
|||
navigateBack(navigation, drawerStack, popDrawerStack);
|
||||
};
|
||||
|
||||
onOpenFilePressed = () => {
|
||||
const { contentType, fileInfo, notify } = this.props;
|
||||
const localFileUri = this.localUriForFileInfo(fileInfo);
|
||||
const mediaType = Lbry.getMediaType(contentType);
|
||||
const isViewable = mediaType === 'image' || mediaType === 'text';
|
||||
if (isViewable) {
|
||||
this.openFile(localFileUri, mediaType, contentType);
|
||||
} else {
|
||||
notify({ message: __('This file cannot be displayed in the LBRY app.') });
|
||||
}
|
||||
};
|
||||
|
||||
onSaveFilePressed = () => {
|
||||
const { costInfo, fileGet, fileInfo, navigation, purchasedUris, purchaseUri } = this.props;
|
||||
const { uri } = navigation.state.params;
|
||||
|
@ -1131,13 +1143,12 @@ class FilePage extends React.PureComponent {
|
|||
|
||||
{!canEdit && !isPlayable && (
|
||||
<View style={filePageStyle.sharedLargeButton}>
|
||||
{!fileInfo ||
|
||||
(fileInfo.written_bytes <= 0 && !completed && (
|
||||
<TouchableOpacity style={filePageStyle.innerLargeButton} onPress={this.onDownloadPressed}>
|
||||
<Icon name={'download'} size={16} style={filePageStyle.largeButtonIcon} />
|
||||
<Text style={filePageStyle.largeButtonText}>{__('Download')}</Text>
|
||||
</TouchableOpacity>
|
||||
))}
|
||||
{(!fileInfo || (fileInfo.written_bytes <= 0 && !completed)) && (
|
||||
<TouchableOpacity style={filePageStyle.innerLargeButton} onPress={this.onDownloadPressed}>
|
||||
<Icon name={'download'} size={16} style={filePageStyle.largeButtonIcon} />
|
||||
<Text style={filePageStyle.largeButtonText}>{__('Download')}</Text>
|
||||
</TouchableOpacity>
|
||||
)}
|
||||
|
||||
{!completed &&
|
||||
fileInfo &&
|
||||
|
@ -1151,7 +1162,7 @@ class FilePage extends React.PureComponent {
|
|||
</TouchableOpacity>
|
||||
)}
|
||||
|
||||
{completed && fileInfo && fileInfo.written_bytes >= fileInfo.total_bytes && (
|
||||
{completed && fileInfo && (
|
||||
<TouchableOpacity style={filePageStyle.innerLargeButton} onPress={this.onOpenFilePressed}>
|
||||
<Icon name={'folder-open'} size={16} style={filePageStyle.largeButtonIcon} />
|
||||
<Text style={filePageStyle.largeButtonText}>{__('Open')}</Text>
|
||||
|
|
|
@ -126,7 +126,6 @@ class PhoneVerifyPage extends React.PureComponent {
|
|||
};
|
||||
|
||||
onPressFlag = () => {
|
||||
console.log('setting country picker visible...');
|
||||
this.setState({ countryPickerVisible: true });
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue