From 55f61a85f01f2d1b786c4cd0f4e8cc46a986717b Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Mon, 13 Jan 2020 12:04:06 +0100 Subject: [PATCH 1/6] 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 }) => ( Date: Mon, 13 Jan 2020 16:44:51 +0100 Subject: [PATCH 2/6] fix media player source and button display --- src/page/file/view.js | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/page/file/view.js b/src/page/file/view.js index ac2c4e9..234bff3 100644 --- a/src/page/file/view.js +++ b/src/page/file/view.js @@ -163,7 +163,6 @@ class FilePage extends React.PureComponent { notify, drawerStack: prevDrawerStack, } = this.props; - const { uri } = navigation.state.params; const { currentRoute: prevRoute, failedPurchaseUris, @@ -174,6 +173,7 @@ class FilePage extends React.PureComponent { drawerStack, resolveUris, } = nextProps; + const uri = this.getPurchaseUrl(); if (Constants.ROUTE_FILE === currentRoute && currentRoute !== prevRoute) { this.onComponentFocused(); @@ -207,7 +207,7 @@ class FilePage extends React.PureComponent { NativeModules.UtilityModule.checkDownloads(); } - if (!this.state.streamingMode && isPlayable) { + if ((!fileInfo || (fileInfo && !fileInfo.completed)) && !this.state.streamingMode && isPlayable) { if (streamingUrl) { this.setState({ streamingMode: true, currentStreamUrl: streamingUrl }); } else if (fileInfo && fileInfo.streaming_url) { @@ -235,14 +235,6 @@ class FilePage extends React.PureComponent { const { fileInfo: prevFileInfo } = this.props; const { fileInfo } = nextProps; - if (this.state.playbackStarted && nextProps.position) { - return false; - } - - if (prevFileInfo && fileInfo && prevFileInfo.download_path === fileInfo.download_path) { - return false; - } - return ( Object.keys(this.difference(nextProps, this.props)).length > 0 || Object.keys(this.difference(nextState, this.state)).length > 0 @@ -467,8 +459,8 @@ class FilePage extends React.PureComponent { playerUriForFileInfo = fileInfo => { const { streamingUrl } = this.props; - if (!this.state.playbackStarted && fileInfo && fileInfo.download_path && fileInfo.completed) { - // take playbackStarted in the state into account because if the download completes while + if (!this.state.streamingMode && fileInfo && fileInfo.download_path && fileInfo.completed) { + // take streamingMode 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); } @@ -741,8 +733,11 @@ class FilePage extends React.PureComponent { const localFileUri = this.localUriForFileInfo(fileInfo); const mediaType = Lbry.getMediaType(contentType); const isViewable = mediaType === 'image' || mediaType === 'text'; + const isPlayable = mediaType === 'video' || mediaType === 'audio'; if (isViewable) { this.openFile(localFileUri, mediaType, contentType); + } else if (isPlayable) { + notify({ message: __('Please press the Play button.') }); } else { notify({ message: __('This file cannot be displayed in the LBRY app.') }); } @@ -1216,7 +1211,6 @@ class FilePage extends React.PureComponent { {!completed && fileInfo && - !fileInfo.stopped && fileInfo.written_bytes > 0 && fileInfo.written_bytes < fileInfo.total_bytes && !this.state.stopDownloadConfirmed && ( -- 2.45.2 From f2b0d3417b346842d472be5a4aaa31670d0144f1 Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Tue, 14 Jan 2020 03:28:53 +0100 Subject: [PATCH 3/6] show notifications for video downloads. fix double playback. --- src/page/discover/index.js | 5 +++-- src/page/discover/view.js | 8 +++++--- src/page/file/index.js | 6 +++--- src/page/file/view.js | 38 +++++++++++++---------------------- src/redux/actions/drawer.js | 4 ++-- src/redux/reducers/drawer.js | 18 +++++++++++++++-- src/redux/selectors/drawer.js | 19 ++++++++++++++---- src/utils/helper.js | 13 +++++------- 8 files changed, 63 insertions(+), 48 deletions(-) diff --git a/src/page/discover/index.js b/src/page/discover/index.js index c93178f..662adad 100644 --- a/src/page/discover/index.js +++ b/src/page/discover/index.js @@ -11,7 +11,7 @@ import { selectSubscriptionClaims, selectUnreadSubscriptions, } from 'lbryinc'; -import { doPushDrawerStack } from 'redux/actions/drawer'; +import { doPushDrawerStack, doSetPlayerVisible } from 'redux/actions/drawer'; import { doSetClientSetting, doSetSortByItem, doSetTimeItem } from 'redux/actions/settings'; import { makeSelectClientSetting, selectSortByItem, selectTimeItem } from 'redux/selectors/settings'; import Constants from 'constants'; // eslint-disable-line node/no-deprecated-api @@ -41,11 +41,12 @@ const perform = dispatch => ({ pushDrawerStack: () => dispatch(doPushDrawerStack(Constants.DRAWER_ROUTE_DISCOVER)), removeUnreadSubscriptions: () => dispatch(doRemoveUnreadSubscriptions()), setClientSetting: (key, value) => dispatch(doSetClientSetting(key, value)), + setPlayerVisible: () => dispatch(doSetPlayerVisible(false)), setSortByItem: item => dispatch(doSetSortByItem(item)), setTimeItem: item => dispatch(doSetTimeItem(item)), }); export default connect( select, - perform + perform, )(DiscoverPage); diff --git a/src/page/discover/view.js b/src/page/discover/view.js index 59275ea..e5a46aa 100644 --- a/src/page/discover/view.js +++ b/src/page/discover/view.js @@ -86,9 +86,11 @@ class DiscoverPage extends React.PureComponent { } onComponentFocused = () => { - const { pushDrawerStack } = this.props; + const { pushDrawerStack, setPlayerVisible } = this.props; // pushDrawerStack(); + NativeModules.Firebase.setCurrentScreen('Your tags'); + setPlayerVisible(); }; handleSortByItemSelected = item => { @@ -135,7 +137,7 @@ class DiscoverPage extends React.PureComponent { Alert.alert( __('Enjoying LBRY?'), __( - 'Are you enjoying your experience with the LBRY app? You can leave a review for us on the Play Store.' + 'Are you enjoying your experience with the LBRY app? You can leave a review for us on the Play Store.', ), [ { @@ -151,7 +153,7 @@ class DiscoverPage extends React.PureComponent { }, }, ], - { cancelable: false } + { cancelable: false }, ); } } diff --git a/src/page/file/index.js b/src/page/file/index.js index 74f60ee..83d83c9 100644 --- a/src/page/file/index.js +++ b/src/page/file/index.js @@ -41,7 +41,7 @@ import { import { doDeleteFile, doStopDownloadingFile } from 'redux/actions/file'; import { doPushDrawerStack, doPopDrawerStack, doSetPlayerVisible } from 'redux/actions/drawer'; import { doToggleFullscreenMode } from 'redux/actions/settings'; -import { selectDrawerStack, selectIsPlayerVisible } from 'redux/selectors/drawer'; +import { selectDrawerStack, makeSelectPlayerVisible } from 'redux/selectors/drawer'; import FilePage from './view'; const select = (state, props) => { @@ -61,7 +61,7 @@ const select = (state, props) => { fileInfo: makeSelectFileInfoForUri(contentUri)(state), rewardedContentClaimIds: selectRewardContentClaimIds(state, selectProps), channelUri: makeSelectChannelForClaimUri(contentUri, true)(state), - isPlayerVisible: selectIsPlayerVisible(state), + isPlayerVisible: makeSelectPlayerVisible(uri)(state), // use navigation uri for this selector position: makeSelectContentPositionForUri(contentUri)(state), purchasedUris: selectPurchasedUris(state), failedPurchaseUris: selectFailedPurchaseUris(state), @@ -96,7 +96,7 @@ const perform = dispatch => ({ resolveUris: uris => dispatch(doResolveUris(uris)), sendTip: (amount, claimId, isSupport, successCallback, errorCallback) => dispatch(doSendTip(amount, claimId, isSupport, successCallback, errorCallback)), - setPlayerVisible: () => dispatch(doSetPlayerVisible(true)), + setPlayerVisible: (visible, uri) => dispatch(doSetPlayerVisible(visible, uri)), stopDownload: (uri, fileInfo) => dispatch(doStopDownloadingFile(uri, fileInfo)), toggleFullscreenMode: mode => dispatch(doToggleFullscreenMode(mode)), }); diff --git a/src/page/file/view.js b/src/page/file/view.js index 33bcc79..071fe2b 100644 --- a/src/page/file/view.js +++ b/src/page/file/view.js @@ -116,6 +116,9 @@ class FilePage extends React.PureComponent { onComponentFocused = () => { StatusBar.setHidden(false); NativeModules.Firebase.setCurrentScreen('File').then(result => { + const { setPlayerVisible } = this.props; + setPlayerVisible(false); // reset visible state for all other file pages that may be active + DeviceEventEmitter.addListener('onStoragePermissionGranted', this.handleStoragePermissionGranted); DeviceEventEmitter.addListener('onStoragePermissionRefused', this.handleStoragePermissionRefused); @@ -123,6 +126,7 @@ class FilePage extends React.PureComponent { const { uri, uriVars } = navigation.state.params; this.setState({ uri, uriVars }); + setPlayerVisible(true, uri); if (!isResolvingUri && !claim) resolveUri(uri); this.fetchFileInfo(uri, this.props); @@ -672,7 +676,7 @@ class FilePage extends React.PureComponent { if (isPlayable) { this.startTime = Date.now(); this.setState({ downloadPressed: true, autoPlayMedia: true, stopDownloadConfirmed: false }); - setPlayerVisible(); + // setPlayerVisible(purchaseUrl); } if (isViewable) { this.setState({ downloadPressed: true }); @@ -686,7 +690,7 @@ class FilePage extends React.PureComponent { let purchaseUrl; if (navigation.state.params) { const { uri, fullUri } = navigation.state.params; - purchaseUrl = fullUri || uri || permanentUrl; + purchaseUrl = fullUri || permanentUrl || uri; } if (!purchaseUrl && permanentUrl) { purchaseUrl = permanentUrl; @@ -712,7 +716,7 @@ class FilePage extends React.PureComponent { }; performDownload = () => { - const { claim, costInfo, purchaseUri } = this.props; + const { claim, costInfo, fileGet, fileInfo, purchasedUris } = this.props; this.setState( { downloadPressed: true, @@ -720,7 +724,13 @@ class FilePage extends React.PureComponent { stopDownloadConfirmed: false, }, () => { - this.confirmPurchaseUri(claim.permanent_url, costInfo, true); + const url = this.getPurchaseUrl(); + if (fileInfo || purchasedUris.includes(url)) { + // file already in library or URI already purchased, use fileGet directly + this.setState({ fileGetStarted: true }, () => fileGet(url, true)); + } else { + this.confirmPurchaseUri(url, costInfo, true); + } NativeModules.UtilityModule.checkDownloads(); }, ); @@ -746,18 +756,6 @@ class FilePage extends React.PureComponent { } }; - onSaveFilePressed = () => { - const { costInfo, fileGet, fileInfo, navigation, purchasedUris, purchaseUri } = this.props; - const { uri } = navigation.state.params; - - if (fileInfo || purchasedUris.includes(uri)) { - // file already in library or URI already purchased, use fileGet directly - this.setState({ fileGetStarted: true }, () => fileGet(uri, true)); - } else { - this.checkStoragePermissionForDownload(); - } - }; - openFile = (localFileUri, mediaType, contentType) => { const { pushDrawerStack } = this.props; const isWebViewable = mediaType === 'text'; @@ -1294,14 +1292,6 @@ class FilePage extends React.PureComponent { /> - {false && ((isPlayable && !fileInfo) || (isPlayable && fileInfo && !fileInfo.download_path)) && ( -