First run changes #103

Merged
akinwale merged 3 commits from first-run-changes into master 2019-12-28 15:45:13 +01:00
5 changed files with 118 additions and 68 deletions
Showing only changes of commit c1f73c2766 - Show all commits

View file

@ -45,6 +45,7 @@ class FileDownloadButton extends React.PureComponent {
doPause, doPause,
style, style,
openFile, openFile,
onFileActionPress,
onButtonLayout, onButtonLayout,
} = this.props; } = this.props;
@ -72,19 +73,7 @@ class FileDownloadButton extends React.PureComponent {
text={isPlayable ? __('Play') : isViewable ? __('View') : __('Download')} text={isPlayable ? __('Play') : isViewable ? __('View') : __('Download')}
onLayout={onButtonLayout} onLayout={onButtonLayout}
style={[style, fileDownloadButtonStyle.container]} style={[style, fileDownloadButtonStyle.container]}
onPress={() => { onPress={onFileActionPress}
NativeModules.Firebase.track('purchase_uri', { uri: uri });
purchaseUri(uri, costInfo, !isPlayable);
if (NativeModules.UtilityModule) {
NativeModules.UtilityModule.checkDownloads();
}
if (isPlayable && onPlay) {
this.props.onPlay();
}
if (isViewable && onView) {
this.props.onView();
}
}}
/> />
); );
} else if (fileInfo && fileInfo.download_path) { } else if (fileInfo && fileInfo.download_path) {

View file

@ -52,8 +52,9 @@ function checkMessageAndSave(message, messagesFilePath) {
); */ ); */
}) })
.catch(err => { .catch(err => {
if (err) { if (err && !isProduction) {
throw err; // only do this when not in production
console.error(err);
} }
}); });
} }

View file

@ -57,6 +57,7 @@ window.__ = __;
const globalExceptionHandler = (error, isFatal) => { const globalExceptionHandler = (error, isFatal) => {
if (error && NativeModules.Firebase) { if (error && NativeModules.Firebase) {
console.log(error);
NativeModules.Firebase.logException(isFatal, error.message ? error.message : 'No message', JSON.stringify(error)); NativeModules.Firebase.logException(isFatal, error.message ? error.message : 'No message', JSON.stringify(error));
} }
}; };

View file

@ -101,11 +101,12 @@ class FilePage extends React.PureComponent {
onComponentFocused = () => { onComponentFocused = () => {
StatusBar.setHidden(false); StatusBar.setHidden(false);
NativeModules.Firebase.setCurrentScreen('File'); NativeModules.Firebase.setCurrentScreen('File').then(result => {
DeviceEventEmitter.addListener('onDownloadStarted', this.handleDownloadStarted); DeviceEventEmitter.addListener('onDownloadStarted', this.handleDownloadStarted);
DeviceEventEmitter.addListener('onDownloadUpdated', this.handleDownloadUpdated); DeviceEventEmitter.addListener('onDownloadUpdated', this.handleDownloadUpdated);
DeviceEventEmitter.addListener('onDownloadCompleted', this.handleDownloadCompleted); DeviceEventEmitter.addListener('onDownloadCompleted', this.handleDownloadCompleted);
DeviceEventEmitter.addListener('onStoragePermissionGranted', this.handleStoragePermissionGranted);
DeviceEventEmitter.addListener('onStoragePermissionRefused', this.handleStoragePermissionRefused);
const { fetchMyClaims, fileInfo, isResolvingUri, resolveUri, navigation } = this.props; const { fetchMyClaims, fileInfo, isResolvingUri, resolveUri, navigation } = this.props;
const { uri, uriVars } = navigation.state.params; const { uri, uriVars } = navigation.state.params;
@ -118,12 +119,9 @@ class FilePage extends React.PureComponent {
fetchMyClaims(); fetchMyClaims();
if (NativeModules.Firebase) {
NativeModules.Firebase.track('open_file_page', { uri: uri }); NativeModules.Firebase.track('open_file_page', { uri: uri });
}
if (NativeModules.UtilityModule) {
NativeModules.UtilityModule.keepAwakeOn(); NativeModules.UtilityModule.keepAwakeOn();
} });
}; };
componentDidMount() { componentDidMount() {
@ -236,9 +234,9 @@ class FilePage extends React.PureComponent {
resolveUri(uri); resolveUri(uri);
} }
if (title && !this.state.didSearchRecommended) { /* if (title && !this.state.didSearchRecommended) {
this.setState({ didSearchRecommended: true }, () => searchRecommended(title)); this.setState({ didSearchRecommended: true }, () => searchRecommended(title));
} } */
// Returned to the page. If mediaLoaded, and currentMediaInfo is different, update // Returned to the page. If mediaLoaded, and currentMediaInfo is different, update
if (this.state.mediaLoaded && window.currentMediaInfo && window.currentMediaInfo.uri !== this.state.uri) { if (this.state.mediaLoaded && window.currentMediaInfo && window.currentMediaInfo.uri !== this.state.uri) {
@ -402,6 +400,8 @@ class FilePage extends React.PureComponent {
DeviceEventEmitter.removeListener('onDownloadStarted', this.handleDownloadStarted); DeviceEventEmitter.removeListener('onDownloadStarted', this.handleDownloadStarted);
DeviceEventEmitter.removeListener('onDownloadUpdated', this.handleDownloadUpdated); DeviceEventEmitter.removeListener('onDownloadUpdated', this.handleDownloadUpdated);
DeviceEventEmitter.removeListener('onDownloadCompleted', this.handleDownloadCompleted); DeviceEventEmitter.removeListener('onDownloadCompleted', this.handleDownloadCompleted);
DeviceEventEmitter.removeListener('onStoragePermissionGranted', this.handleStoragePermissionGranted);
DeviceEventEmitter.removeListener('onStoragePermissionRefused', this.handleStoragePermissionRefused);
} }
handleDownloadStarted = evt => { handleDownloadStarted = evt => {
@ -422,6 +422,32 @@ class FilePage extends React.PureComponent {
completeDownload(uri, outpoint, fileInfo); completeDownload(uri, outpoint, fileInfo);
}; };
handleStoragePermissionGranted = () => {
// permission was allowed. proceed to download
const { notify } = this.props;
// update the configured download folder and then download
NativeModules.UtilityModule.getDownloadDirectory().then(downloadDirectory => {
Lbry.settings_set({
key: 'download_directory',
value: downloadDirectory,
})
.then(() => this.performDownload())
.catch(() => {
notify({ message: 'The file could not be downloaded to the default download directory.', isError: true });
});
});
};
handleStoragePermissionRefused = () => {
const { notify } = this.props;
this.setState({ downloadPressed: false });
notify({
message: __('The file could not be downloaded because the permission to write to storage was not granted.'),
isError: true,
});
};
localUriForFileInfo = fileInfo => { localUriForFileInfo = fileInfo => {
if (!fileInfo) { if (!fileInfo) {
return null; return null;
@ -589,14 +615,50 @@ class FilePage extends React.PureComponent {
)); ));
}; };
onFileDownloadButtonPlayed = () => { onFileDownloadButtonPressed = () => {
const { setPlayerVisible } = this.props; const { costInfo, contentType, purchaseUri, setPlayerVisible } = this.props;
const { uri } = this.state;
const mediaType = Lbry.getMediaType(contentType);
const isPlayable = mediaType === 'video' || mediaType === 'audio';
const isViewable = mediaType === 'image' || mediaType === 'text';
NativeModules.Firebase.track('purchase_uri', { uri: uri });
if (!isPlayable) {
this.checkStoragePermissionForDownload();
} else {
purchaseUri(uri, costInfo, !isPlayable);
}
if (isPlayable) {
this.startTime = Date.now(); this.startTime = Date.now();
this.setState({ downloadPressed: true, autoPlayMedia: true, stopDownloadConfirmed: false }); this.setState({ downloadPressed: true, autoPlayMedia: true, stopDownloadConfirmed: false });
setPlayerVisible(); setPlayerVisible();
}
if (isViewable) {
this.setState({ downloadPressed: true });
}
}; };
onDownloadPressed = () => { onDownloadPressed = () => {
this.checkStoragePermissionForDownload();
};
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();
}
});
});
};
performDownload = () => {
const { claim, costInfo, purchaseUri } = this.props; const { claim, costInfo, purchaseUri } = this.props;
this.setState( this.setState(
{ {
@ -604,7 +666,10 @@ class FilePage extends React.PureComponent {
autoPlayMedia: false, autoPlayMedia: false,
stopDownloadConfirmed: false, stopDownloadConfirmed: false,
}, },
() => purchaseUri(claim.permanent_url, costInfo, true) () => {
purchaseUri(claim.permanent_url, costInfo, true);
NativeModules.UtilityModule.checkDownloads();
}
); );
}; };
@ -621,14 +686,7 @@ class FilePage extends React.PureComponent {
// file already in library or URI already purchased, use fileGet directly // file already in library or URI already purchased, use fileGet directly
this.setState({ fileGetStarted: true }, () => fileGet(uri, true)); this.setState({ fileGetStarted: true }, () => fileGet(uri, true));
} else { } else {
this.setState( this.checkStoragePermissionForDownload();
{
downloadPressed: true,
autoPlayMedia: false,
stopDownloadConfirmed: false,
},
() => purchaseUri(uri, costInfo, true)
);
} }
}; };
@ -665,17 +723,6 @@ class FilePage extends React.PureComponent {
} }
}; };
onMediaContainerPressed = () => {
const { costInfo, contentType, purchaseUri } = this.props;
const { uri } = this.state;
const mediaType = Lbry.getMediaType(contentType);
const isPlayable = mediaType === 'video' || mediaType === 'audio';
purchaseUri(uri, costInfo, isPlayable);
if (isPlayable) {
this.onFileDownloadButtonPlayed();
}
};
render() { render() {
const { const {
balance, balance,
@ -835,10 +882,12 @@ class FilePage extends React.PureComponent {
if (fileInfo && !this.state.autoDownloadStarted && this.state.uriVars && this.state.uriVars.download === 'true') { if (fileInfo && !this.state.autoDownloadStarted && this.state.uriVars && this.state.uriVars.download === 'true') {
this.setState({ autoDownloadStarted: true }, () => { this.setState({ autoDownloadStarted: true }, () => {
if (!isPlayable) {
this.checkStoragePermissionForDownload();
} else {
purchaseUri(uri, costInfo, !isPlayable); purchaseUri(uri, costInfo, !isPlayable);
if (NativeModules.UtilityModule) {
NativeModules.UtilityModule.checkDownloads();
} }
NativeModules.UtilityModule.checkDownloads();
}); });
} }
@ -872,7 +921,7 @@ class FilePage extends React.PureComponent {
<TouchableOpacity <TouchableOpacity
activeOpacity={0.5} activeOpacity={0.5}
style={filePageStyle.mediaContainer} style={filePageStyle.mediaContainer}
onPress={this.onMediaContainerPressed} onPress={this.onFileDownloadButtonPressed}
> >
{(canOpen || (!fileInfo || (isPlayable && !canLoadMedia)) || (!canOpen && fileInfo)) && ( {(canOpen || (!fileInfo || (isPlayable && !canLoadMedia)) || (!canOpen && fileInfo)) && (
<FileItemMedia <FileItemMedia
@ -916,8 +965,7 @@ class FilePage extends React.PureComponent {
openFile={() => this.openFile(localFileUri, mediaType)} openFile={() => this.openFile(localFileUri, mediaType)}
isPlayable={isPlayable} isPlayable={isPlayable}
isViewable={isViewable} isViewable={isViewable}
onPlay={this.onFileDownloadButtonPlayed} onFileActionPress={this.onFileDownloadButtonPressed}
onView={() => this.setState({ downloadPressed: true })}
onButtonLayout={() => this.setState({ downloadButtonShown: true })} onButtonLayout={() => this.setState({ downloadButtonShown: true })}
/> />
)} )}
@ -1159,7 +1207,7 @@ class FilePage extends React.PureComponent {
{isSearchingRecommendContent && ( {isSearchingRecommendContent && (
<ActivityIndicator size="small" color={Colors.NextLbryGreen} style={filePageStyle.relatedLoading} /> <ActivityIndicator size="small" color={Colors.NextLbryGreen} style={filePageStyle.relatedLoading} />
)} )}
{!isSearchingRecommendContent && recommendedContent && recommendedContent.length > 0 && ( {false && !isSearchingRecommendContent && recommendedContent && recommendedContent.length > 0 && (
<RelatedContent navigation={navigation} uri={uri} fullUri={fullUri} /> <RelatedContent navigation={navigation} uri={uri} fullUri={fullUri} />
)} )}
</ScrollView> </ScrollView>

View file

@ -228,7 +228,13 @@ class FirstRunScreen extends React.PureComponent {
handleContinuePressed = () => { handleContinuePressed = () => {
const { notify, user, hasSyncedWallet } = this.props; const { notify, user, hasSyncedWallet } = this.props;
const pageIndex = FirstRunScreen.pages.indexOf(this.state.currentPage); const pageIndex = FirstRunScreen.pages.indexOf(this.state.currentPage);
if (Constants.FIRST_RUN_PAGE_WALLET === this.state.currentPage) {
if (Constants.FIRST_RUN_PAGE_WELCOME === this.state.currentPage) {
// only show the welcome screen on first run
this.closeFinalPage();
}
/* if (Constants.FIRST_RUN_PAGE_WALLET === this.state.currentPage) {
// do apply sync to check if the password is valid // do apply sync to check if the password is valid
if (hasSyncedWallet) { if (hasSyncedWallet) {
this.checkWalletPassword(); this.checkWalletPassword();
@ -256,7 +262,7 @@ class FirstRunScreen extends React.PureComponent {
} else { } else {
this.showNextPage(); this.showNextPage();
} }
} } */
}; };
handleEmailCollectPageContinue() { handleEmailCollectPageContinue() {
@ -500,7 +506,12 @@ class FirstRunScreen extends React.PureComponent {
{Constants.FIRST_RUN_PAGE_SKIP_ACCOUNT !== this.state.currentPage && {Constants.FIRST_RUN_PAGE_SKIP_ACCOUNT !== this.state.currentPage &&
Constants.FIRST_RUN_PAGE_EMAIL_VERIFY !== this.state.currentPage && ( Constants.FIRST_RUN_PAGE_EMAIL_VERIFY !== this.state.currentPage && (
<Text style={firstRunStyle.buttonText}> <Text style={firstRunStyle.buttonText}>
{Constants.FIRST_RUN_PAGE_WALLET === this.state.currentPage ? __('Use LBRY') : __('Continue')} » {[Constants.FIRST_RUN_PAGE_WALLET, Constants.FIRST_RUN_PAGE_WELCOME].includes(
this.state.currentPage
)
? __('Use LBRY')
: __('Continue')}{' '}
»
</Text> </Text>
)} )}
</TouchableOpacity> </TouchableOpacity>