From 55f61a85f01f2d1b786c4cd0f4e8cc46a986717b Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Mon, 13 Jan 2020 12:04:06 +0100 Subject: [PATCH] enable download button for video and audio content --- src/component/claimResultItem/view.js | 2 +- src/component/relatedContent/view.js | 1 + src/page/file/view.js | 36 ++++++++++++++++++--------- src/page/search/view.js | 1 + src/styles/filePage.js | 2 +- 5 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/component/claimResultItem/view.js b/src/component/claimResultItem/view.js index f94a8f3..f1ebc9e 100644 --- a/src/component/claimResultItem/view.js +++ b/src/component/claimResultItem/view.js @@ -141,7 +141,7 @@ class ClaimResultItem extends React.PureComponent { {fileInfo && !isNaN(fileInfo.written_bytes) && fileInfo.written_bytes > 0 && ( - {getStorageForFileInfo(fileInfo)} + {getStorageForFileInfo(fileInfo)} )} ( 0 || Object.keys(this.difference(nextState, this.state)).length > 0 @@ -368,12 +380,12 @@ class FilePage extends React.PureComponent { const { deletePurchasedUri, fileInfo, navigation, notify, stopDownload } = this.props; Alert.alert( - 'Stop download', - 'Are you sure you want to stop downloading this file?', + __('Stop download'), + __('Are you sure you want to stop downloading this file?'), [ - { text: 'No' }, + { text: __('No') }, { - text: 'Yes', + text: __('Yes'), onPress: () => { const { uri } = navigation.state.params; stopDownload(uri, fileInfo); @@ -391,7 +403,7 @@ class FilePage extends React.PureComponent { // there can be a bit of lag between the user pressing Yes and the UI being updated // after the file_set_status and file_delete operations, so let the user know notify({ - message: 'The download will stop momentarily. You do not need to wait to discover something else.', + message: __('The download will stop momentarily. You do not need to wait to discover something else.'), }); }, }, @@ -416,8 +428,6 @@ class FilePage extends React.PureComponent { if (window.currentMediaInfo) { window.currentMediaInfo = null; } - window.player = null; - DeviceEventEmitter.removeListener('onStoragePermissionGranted', this.handleStoragePermissionGranted); DeviceEventEmitter.removeListener('onStoragePermissionRefused', this.handleStoragePermissionRefused); } @@ -434,7 +444,7 @@ class FilePage extends React.PureComponent { }) .then(() => this.performDownload()) .catch(() => { - notify({ message: 'The file could not be downloaded to the default download directory.', isError: true }); + notify({ message: __('The file could not be downloaded to the default download directory.'), isError: true }); }); }); }; @@ -452,12 +462,14 @@ class FilePage extends React.PureComponent { if (!fileInfo) { return null; } - return 'file:///' + fileInfo.download_path; + return 'file://' + fileInfo.download_path; }; playerUriForFileInfo = fileInfo => { const { streamingUrl } = this.props; - if (fileInfo && fileInfo.download_path) { + if (!this.state.playbackStarted && fileInfo && fileInfo.download_path && fileInfo.completed) { + // take playbackStarted in the state into account because if the download completes while + // the media is already streaming, it will restart from the beginning return this.getEncodedDownloadPath(fileInfo); } if (streamingUrl) { @@ -564,7 +576,7 @@ class FilePage extends React.PureComponent { NativeModules.Firebase.track('play', payload); // only fetch recommended content after playback has started - this.setState({ showRecommended: true }); + this.setState({ playbackStarted: true, showRecommended: true }); }; onPlaybackFinished = () => { @@ -1193,7 +1205,7 @@ class FilePage extends React.PureComponent { {__('Tip')} - {!canEdit && !isPlayable && ( + {!canEdit && ( {(!fileInfo || (fileInfo.written_bytes <= 0 && !completed)) && ( diff --git a/src/page/search/view.js b/src/page/search/view.js index d9f7f4b..6e94974 100644 --- a/src/page/search/view.js +++ b/src/page/search/view.js @@ -239,6 +239,7 @@ class SearchPage extends React.PureComponent { renderItem={({ item }) => (