diff --git a/src/component/fileDownloadButton/view.js b/src/component/fileDownloadButton/view.js index 06a458f..d2f7ae8 100644 --- a/src/component/fileDownloadButton/view.js +++ b/src/component/fileDownloadButton/view.js @@ -49,6 +49,9 @@ class FileDownloadButton extends React.PureComponent { onButtonLayout, } = this.props; + console.log('uri=' + uri); + console.log(fileInfo); + 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...'); diff --git a/src/page/file/view.js b/src/page/file/view.js index 5b077c0..77ef5fb 100644 --- a/src/page/file/view.js +++ b/src/page/file/view.js @@ -179,7 +179,8 @@ class FilePage extends React.PureComponent { (this.state.fileGetStarted || prevPurchasedUris.length !== purchasedUris.length) && NativeModules.UtilityModule ) { - if (purchasedUris.includes(uri)) { + const { permanent_url: permanentUrl } = claim; + if (purchasedUris.includes(uri) || purchasedUris.includes(permanentUrl)) { const { nout, txid } = claim; const outpoint = `${txid}:${nout}`; NativeModules.UtilityModule.queueDownload(outpoint); @@ -252,15 +253,7 @@ class FilePage extends React.PureComponent { const mediaType = Lbry.getMediaType(contentType); const isViewable = mediaType === 'image' || mediaType === 'text'; if (claim && costInfo && costInfo.cost === 0 && !this.state.autoGetAttempted && isViewable) { - this.setState( - { - autoGetAttempted: true, - downloadPressed: true, - autoPlayMedia: true, - stopDownloadConfirmed: false, - }, - () => purchaseUri(claim.permanent_url, costInfo, true) - ); + this.setState({ autoGetAttempted: true }, () => this.checkStoragePermissionForDownload()); } } @@ -429,7 +422,7 @@ class FilePage extends React.PureComponent { // update the configured download folder and then download NativeModules.UtilityModule.getDownloadDirectory().then(downloadDirectory => { Lbry.settings_set({ - key: 'download_directory', + key: 'download_dir', value: downloadDirectory, }) .then(() => this.performDownload()) @@ -616,12 +609,12 @@ class FilePage extends React.PureComponent { }; onFileDownloadButtonPressed = () => { - const { costInfo, contentType, purchaseUri, setPlayerVisible } = this.props; - const { uri } = this.state; + const { claim, costInfo, contentType, purchaseUri, setPlayerVisible } = this.props; const mediaType = Lbry.getMediaType(contentType); const isPlayable = mediaType === 'video' || mediaType === 'audio'; const isViewable = mediaType === 'image' || mediaType === 'text'; + const { permanent_url: uri } = claim; NativeModules.Firebase.track('purchase_uri', { uri: uri }); if (!isPlayable) { @@ -645,16 +638,14 @@ class FilePage extends React.PureComponent { }; checkStoragePermissionForDownload = () => { - this.setState({ downloadPressed: true }, () => { - // check if we the permission to write to external storage has been granted - NativeModules.UtilityModule.canReadWriteStorage().then(canReadWrite => { - if (!canReadWrite) { - // request permission - NativeModules.UtilityModule.requestStoragePermission(); - } else { - this.performDownload(); - } - }); + // check if we the permission to write to external storage has been granted + NativeModules.UtilityModule.canReadWriteStorage().then(canReadWrite => { + if (!canReadWrite) { + // request permission + NativeModules.UtilityModule.requestStoragePermission(); + } else { + this.performDownload(); + } }); }; @@ -957,8 +948,7 @@ class FilePage extends React.PureComponent { {((isPlayable && !completed && !canLoadMedia) || canOpen || - (!completed && !this.state.streamingMode)) && - !this.state.downloadPressed && ( + (!completed && !this.state.streamingMode)) && (