From f2b0d3417b346842d472be5a4aaa31670d0144f1 Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Tue, 14 Jan 2020 03:28:53 +0100 Subject: [PATCH] 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)) && ( -