check storage permission for channel creator and publish pages
This commit is contained in:
parent
8365fa3fa0
commit
3e81d4ef8d
3 changed files with 84 additions and 9 deletions
|
@ -1,5 +1,5 @@
|
|||
import React from 'react';
|
||||
import { CLAIM_VALUES, formatCredits, isNameValid, regexInvalidURI } from 'lbry-redux';
|
||||
import { CLAIM_VALUES, Lbry, formatCredits, isNameValid, regexInvalidURI } from 'lbry-redux';
|
||||
import {
|
||||
ActivityIndicator,
|
||||
Alert,
|
||||
|
@ -225,9 +225,9 @@ export default class ChannelCreator extends React.PureComponent {
|
|||
error => {
|
||||
notify({ message: `The image could not be uploaded: ${error}` });
|
||||
this.setState({ uploadingImage: false });
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
} else {
|
||||
// could not determine the file path
|
||||
|
@ -489,12 +489,12 @@ export default class ChannelCreator extends React.PureComponent {
|
|||
claim_id: claimId,
|
||||
amount: newChannelBid,
|
||||
},
|
||||
optionalParams
|
||||
optionalParams,
|
||||
);
|
||||
this.setState({ updateChannelStarted: true }, () => updateChannel(params));
|
||||
} else {
|
||||
this.setState({ creatingChannel: true }, () =>
|
||||
createChannel(channelName, newChannelBid, optionalParams).then(success, failure)
|
||||
createChannel(channelName, newChannelBid, optionalParams).then(success, failure),
|
||||
);
|
||||
}
|
||||
};
|
||||
|
@ -527,7 +527,7 @@ export default class ChannelCreator extends React.PureComponent {
|
|||
avatarImagePickerOpen: false,
|
||||
coverImagePickerOpen: true,
|
||||
},
|
||||
() => NativeModules.UtilityModule.openDocumentPicker('image/*')
|
||||
() => this.checkStoragePermission(),
|
||||
);
|
||||
};
|
||||
|
||||
|
@ -543,7 +543,7 @@ export default class ChannelCreator extends React.PureComponent {
|
|||
avatarImagePickerOpen: true,
|
||||
coverImagePickerOpen: false,
|
||||
},
|
||||
() => NativeModules.UtilityModule.openDocumentPicker('image/*')
|
||||
() => this.checkStoragePermission(),
|
||||
);
|
||||
};
|
||||
|
||||
|
@ -673,7 +673,7 @@ export default class ChannelCreator extends React.PureComponent {
|
|||
},
|
||||
},
|
||||
],
|
||||
{ cancelable: true }
|
||||
{ cancelable: true },
|
||||
);
|
||||
};
|
||||
|
||||
|
@ -749,6 +749,42 @@ export default class ChannelCreator extends React.PureComponent {
|
|||
this.addOrRemoveItem(channel);
|
||||
};
|
||||
|
||||
checkStoragePermission = () => {
|
||||
// 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 {
|
||||
NativeModules.UtilityModule.openDocumentPicker('image/*');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
handleStoragePermissionGranted = () => {
|
||||
// update the configured download folder
|
||||
NativeModules.UtilityModule.getDownloadDirectory().then(downloadDirectory => {
|
||||
Lbry.settings_set({
|
||||
key: 'download_dir',
|
||||
value: downloadDirectory,
|
||||
})
|
||||
.then(() => {})
|
||||
.catch(() => {});
|
||||
});
|
||||
|
||||
// open picker for images
|
||||
NativeModules.UtilityModule.openDocumentPicker('image/*');
|
||||
};
|
||||
|
||||
handleStoragePermissionRefused = () => {
|
||||
const { notify } = this.props;
|
||||
notify({
|
||||
message: __('Pictures from your device cannot be used because the permission to read storage was not granted.'),
|
||||
isError: true,
|
||||
});
|
||||
this.setState({ avatarImagePickerOpen: false, coverImagePickerOpen: false });
|
||||
};
|
||||
|
||||
render() {
|
||||
const { abandoningClaimIds, balance, fetchingChannels, updatingChannel, channels = [], navigation } = this.props;
|
||||
const {
|
||||
|
|
|
@ -16,6 +16,7 @@ import {
|
|||
} from 'react-native';
|
||||
import { FlatGrid } from 'react-native-super-grid';
|
||||
import {
|
||||
Lbry,
|
||||
isNameValid,
|
||||
batchActions,
|
||||
buildURI,
|
||||
|
@ -160,6 +161,8 @@ class PublishPage extends React.PureComponent {
|
|||
DeviceEventEmitter.removeListener('onAllGalleryThumbnailsChecked', this.handleAllGalleryThumbnailsChecked);
|
||||
DeviceEventEmitter.removeListener('onDocumentPickerFilePicked', this.onFilePicked);
|
||||
DeviceEventEmitter.removeListener('onDocumentPickerCanceled', this.onPickerCanceled);
|
||||
DeviceEventEmitter.removeListener('onStoragePermissionGranted', this.handleStoragePermissionGranted);
|
||||
DeviceEventEmitter.removeListener('onStoragePermissionRefused', this.handleStoragePermissionRefused);
|
||||
}
|
||||
|
||||
handleGalleryThumbnailChecked = evt => {
|
||||
|
@ -182,12 +185,27 @@ class PublishPage extends React.PureComponent {
|
|||
this.setState({ ...publishFormState, advancedMode });
|
||||
};
|
||||
|
||||
checkStoragePermission = () => {
|
||||
// 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();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
onComponentFocused = () => {
|
||||
const { balance, hasFormState, pushDrawerStack, setPlayerVisible, navigation } = this.props;
|
||||
NativeModules.Firebase.setCurrentScreen('Publish').then(result => {
|
||||
pushDrawerStack(Constants.DRAWER_ROUTE_PUBLISH, navigation.state.params ? navigation.state.params : null);
|
||||
setPlayerVisible();
|
||||
|
||||
DeviceEventEmitter.addListener('onStoragePermissionGranted', this.handleStoragePermissionGranted);
|
||||
DeviceEventEmitter.addListener('onStoragePermissionRefused', this.handleStoragePermissionRefused);
|
||||
|
||||
this.checkStoragePermission();
|
||||
|
||||
NativeModules.Gallery.canUseCamera().then(canUseCamera => this.setState({ canUseCamera }));
|
||||
NativeModules.Gallery.getThumbnailPath().then(thumbnailPath => this.setState({ thumbnailPath }));
|
||||
this.setState(
|
||||
|
@ -893,6 +911,28 @@ class PublishPage extends React.PureComponent {
|
|||
);
|
||||
};
|
||||
|
||||
handleStoragePermissionGranted = () => {
|
||||
// update the configured download folder
|
||||
NativeModules.UtilityModule.getDownloadDirectory().then(downloadDirectory => {
|
||||
Lbry.settings_set({
|
||||
key: 'download_dir',
|
||||
value: downloadDirectory,
|
||||
})
|
||||
.then(() => {})
|
||||
.catch(() => {});
|
||||
});
|
||||
};
|
||||
|
||||
handleStoragePermissionRefused = () => {
|
||||
const { notify } = this.props;
|
||||
notify({
|
||||
message: __(
|
||||
'Content from your device cannot be published because the permission to read storage was not granted.',
|
||||
),
|
||||
isError: true,
|
||||
});
|
||||
};
|
||||
|
||||
render() {
|
||||
const { balance, navigation, notify, publishFormValues } = this.props;
|
||||
const {
|
||||
|
|
|
@ -24,7 +24,6 @@ const downloadsStyle = StyleSheet.create({
|
|||
paddingLeft: 16,
|
||||
paddingRight: 16,
|
||||
marginTop: 16,
|
||||
marginBottom: 60,
|
||||
},
|
||||
scrollPadding: {
|
||||
marginTop: -16,
|
||||
|
|
Loading…
Reference in a new issue