From adc9550e587fbb0bf9a08dbb2ea8aba7b8855fdc Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Sat, 8 Sep 2018 10:11:52 +0100 Subject: [PATCH] display the play / download button again upon a failure condition --- app/src/component/fileDownloadButton/index.js | 2 +- app/src/component/fileDownloadButton/view.js | 5 +++-- app/src/page/file/view.js | 8 +++++++- app/src/redux/actions/file.js | 20 +++++++++++++++---- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/app/src/component/fileDownloadButton/index.js b/app/src/component/fileDownloadButton/index.js index fb7256d..c6e8563 100644 --- a/app/src/component/fileDownloadButton/index.js +++ b/app/src/component/fileDownloadButton/index.js @@ -17,7 +17,7 @@ const select = (state, props) => ({ }); const perform = dispatch => ({ - purchaseUri: uri => dispatch(doPurchaseUri(uri)), + purchaseUri: (uri, failureCallback) => dispatch(doPurchaseUri(uri, null, failureCallback)), restartDownload: (uri, outpoint) => dispatch(doStartDownload(uri, outpoint)), fetchCostInfo: uri => dispatch(doFetchCostInfoForUri(uri)), }); diff --git a/app/src/component/fileDownloadButton/view.js b/app/src/component/fileDownloadButton/view.js index 2f9fbe8..827f2f1 100644 --- a/app/src/component/fileDownloadButton/view.js +++ b/app/src/component/fileDownloadButton/view.js @@ -43,7 +43,8 @@ class FileDownloadButton extends React.PureComponent { doPause, style, openFile, - onButtonLayout + onButtonLayout, + onStartDownloadFailed } = this.props; if (loading || downloading) { @@ -73,7 +74,7 @@ class FileDownloadButton extends React.PureComponent { if (NativeModules.Mixpanel) { NativeModules.Mixpanel.track('Purchase Uri', { Uri: uri }); } - purchaseUri(uri); + purchaseUri(uri, onStartDownloadFailed); if (isPlayable && onPlay) { this.props.onPlay(); } diff --git a/app/src/page/file/view.js b/app/src/page/file/view.js index 9871982..2cd0d9d 100644 --- a/app/src/page/file/view.js +++ b/app/src/page/file/view.js @@ -397,7 +397,13 @@ class FilePage extends React.PureComponent { this.startTime = Date.now(); this.setState({ downloadPressed: true, autoPlayMedia: true }); }} - onButtonLayout={() => this.setState({ downloadButtonShown: true })} />} + onButtonLayout={() => this.setState({ downloadButtonShown: true })} + onStartDownloadFailed={() => { + this.startTime = null; + setTimeout(() => { + this.setState({ downloadPressed: false, fileViewLogged: false, mediaLoaded: false }); + }, 500); + }} />} {!fileInfo && } {canLoadMedia && fileInfo && { dispatch({ type: ACTIONS.LOADING_VIDEO_STARTED, @@ -188,6 +188,10 @@ export function doLoadVideo(uri) { message: `File timeout for uri ${uri}`, displayType: ['toast'] })); + + if (failureCallback) { + failureCallback(); + } } else { dispatch(doDownloadFile(uri, streamInfo)); } @@ -203,11 +207,15 @@ export function doLoadVideo(uri) { message: `Failed to download ${uri}, please try again. If this problem persists, visit https://lbry.io/faq/support for support.`, displayType: ['toast'] })); + + if (failureCallback) { + failureCallback(); + } }); }; } -export function doPurchaseUri(uri, specificCostInfo) { +export function doPurchaseUri(uri, specificCostInfo, failureCallback) { return (dispatch, getState) => { const state = getState(); const balance = selectBalance(state); @@ -226,11 +234,11 @@ export function doPurchaseUri(uri, specificCostInfo) { `This will purchase "${title}" for ${formattedCost} ${unit}`, [ { text: 'OK', onPress: () => dispatch(doLoadVideo(uri)) }, - { text: 'Cancel', style: 'cancel' } + { text: 'Cancel', style: 'cancel', onPress: () => failureCallback && failureCallback() } ], { cancelable: true }); } else { - dispatch(doLoadVideo(uri)); + dispatch(doLoadVideo(uri, failureCallback)); } } @@ -260,6 +268,10 @@ export function doPurchaseUri(uri, specificCostInfo) { message: 'Insufficient credits', displayType: ['toast'] })); + if (failureCallback) { + failureCallback(); + } + Promise.resolve(); return; }