Playable downloads #111
8 changed files with 63 additions and 48 deletions
|
@ -11,7 +11,7 @@ import {
|
||||||
selectSubscriptionClaims,
|
selectSubscriptionClaims,
|
||||||
selectUnreadSubscriptions,
|
selectUnreadSubscriptions,
|
||||||
} from 'lbryinc';
|
} from 'lbryinc';
|
||||||
import { doPushDrawerStack } from 'redux/actions/drawer';
|
import { doPushDrawerStack, doSetPlayerVisible } from 'redux/actions/drawer';
|
||||||
import { doSetClientSetting, doSetSortByItem, doSetTimeItem } from 'redux/actions/settings';
|
import { doSetClientSetting, doSetSortByItem, doSetTimeItem } from 'redux/actions/settings';
|
||||||
import { makeSelectClientSetting, selectSortByItem, selectTimeItem } from 'redux/selectors/settings';
|
import { makeSelectClientSetting, selectSortByItem, selectTimeItem } from 'redux/selectors/settings';
|
||||||
import Constants from 'constants'; // eslint-disable-line node/no-deprecated-api
|
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)),
|
pushDrawerStack: () => dispatch(doPushDrawerStack(Constants.DRAWER_ROUTE_DISCOVER)),
|
||||||
removeUnreadSubscriptions: () => dispatch(doRemoveUnreadSubscriptions()),
|
removeUnreadSubscriptions: () => dispatch(doRemoveUnreadSubscriptions()),
|
||||||
setClientSetting: (key, value) => dispatch(doSetClientSetting(key, value)),
|
setClientSetting: (key, value) => dispatch(doSetClientSetting(key, value)),
|
||||||
|
setPlayerVisible: () => dispatch(doSetPlayerVisible(false)),
|
||||||
setSortByItem: item => dispatch(doSetSortByItem(item)),
|
setSortByItem: item => dispatch(doSetSortByItem(item)),
|
||||||
setTimeItem: item => dispatch(doSetTimeItem(item)),
|
setTimeItem: item => dispatch(doSetTimeItem(item)),
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(
|
export default connect(
|
||||||
select,
|
select,
|
||||||
perform
|
perform,
|
||||||
)(DiscoverPage);
|
)(DiscoverPage);
|
||||||
|
|
|
@ -86,9 +86,11 @@ class DiscoverPage extends React.PureComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
onComponentFocused = () => {
|
onComponentFocused = () => {
|
||||||
const { pushDrawerStack } = this.props;
|
const { pushDrawerStack, setPlayerVisible } = this.props;
|
||||||
// pushDrawerStack();
|
// pushDrawerStack();
|
||||||
|
|
||||||
NativeModules.Firebase.setCurrentScreen('Your tags');
|
NativeModules.Firebase.setCurrentScreen('Your tags');
|
||||||
|
setPlayerVisible();
|
||||||
};
|
};
|
||||||
|
|
||||||
handleSortByItemSelected = item => {
|
handleSortByItemSelected = item => {
|
||||||
|
@ -135,7 +137,7 @@ class DiscoverPage extends React.PureComponent {
|
||||||
Alert.alert(
|
Alert.alert(
|
||||||
__('Enjoying LBRY?'),
|
__('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 },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ import {
|
||||||
import { doDeleteFile, doStopDownloadingFile } from 'redux/actions/file';
|
import { doDeleteFile, doStopDownloadingFile } from 'redux/actions/file';
|
||||||
import { doPushDrawerStack, doPopDrawerStack, doSetPlayerVisible } from 'redux/actions/drawer';
|
import { doPushDrawerStack, doPopDrawerStack, doSetPlayerVisible } from 'redux/actions/drawer';
|
||||||
import { doToggleFullscreenMode } from 'redux/actions/settings';
|
import { doToggleFullscreenMode } from 'redux/actions/settings';
|
||||||
import { selectDrawerStack, selectIsPlayerVisible } from 'redux/selectors/drawer';
|
import { selectDrawerStack, makeSelectPlayerVisible } from 'redux/selectors/drawer';
|
||||||
import FilePage from './view';
|
import FilePage from './view';
|
||||||
|
|
||||||
const select = (state, props) => {
|
const select = (state, props) => {
|
||||||
|
@ -61,7 +61,7 @@ const select = (state, props) => {
|
||||||
fileInfo: makeSelectFileInfoForUri(contentUri)(state),
|
fileInfo: makeSelectFileInfoForUri(contentUri)(state),
|
||||||
rewardedContentClaimIds: selectRewardContentClaimIds(state, selectProps),
|
rewardedContentClaimIds: selectRewardContentClaimIds(state, selectProps),
|
||||||
channelUri: makeSelectChannelForClaimUri(contentUri, true)(state),
|
channelUri: makeSelectChannelForClaimUri(contentUri, true)(state),
|
||||||
isPlayerVisible: selectIsPlayerVisible(state),
|
isPlayerVisible: makeSelectPlayerVisible(uri)(state), // use navigation uri for this selector
|
||||||
position: makeSelectContentPositionForUri(contentUri)(state),
|
position: makeSelectContentPositionForUri(contentUri)(state),
|
||||||
purchasedUris: selectPurchasedUris(state),
|
purchasedUris: selectPurchasedUris(state),
|
||||||
failedPurchaseUris: selectFailedPurchaseUris(state),
|
failedPurchaseUris: selectFailedPurchaseUris(state),
|
||||||
|
@ -96,7 +96,7 @@ const perform = dispatch => ({
|
||||||
resolveUris: uris => dispatch(doResolveUris(uris)),
|
resolveUris: uris => dispatch(doResolveUris(uris)),
|
||||||
sendTip: (amount, claimId, isSupport, successCallback, errorCallback) =>
|
sendTip: (amount, claimId, isSupport, successCallback, errorCallback) =>
|
||||||
dispatch(doSendTip(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)),
|
stopDownload: (uri, fileInfo) => dispatch(doStopDownloadingFile(uri, fileInfo)),
|
||||||
toggleFullscreenMode: mode => dispatch(doToggleFullscreenMode(mode)),
|
toggleFullscreenMode: mode => dispatch(doToggleFullscreenMode(mode)),
|
||||||
});
|
});
|
||||||
|
|
|
@ -116,6 +116,9 @@ class FilePage extends React.PureComponent {
|
||||||
onComponentFocused = () => {
|
onComponentFocused = () => {
|
||||||
StatusBar.setHidden(false);
|
StatusBar.setHidden(false);
|
||||||
NativeModules.Firebase.setCurrentScreen('File').then(result => {
|
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('onStoragePermissionGranted', this.handleStoragePermissionGranted);
|
||||||
DeviceEventEmitter.addListener('onStoragePermissionRefused', this.handleStoragePermissionRefused);
|
DeviceEventEmitter.addListener('onStoragePermissionRefused', this.handleStoragePermissionRefused);
|
||||||
|
|
||||||
|
@ -123,6 +126,7 @@ class FilePage extends React.PureComponent {
|
||||||
const { uri, uriVars } = navigation.state.params;
|
const { uri, uriVars } = navigation.state.params;
|
||||||
this.setState({ uri, uriVars });
|
this.setState({ uri, uriVars });
|
||||||
|
|
||||||
|
setPlayerVisible(true, uri);
|
||||||
if (!isResolvingUri && !claim) resolveUri(uri);
|
if (!isResolvingUri && !claim) resolveUri(uri);
|
||||||
|
|
||||||
this.fetchFileInfo(uri, this.props);
|
this.fetchFileInfo(uri, this.props);
|
||||||
|
@ -672,7 +676,7 @@ class FilePage extends React.PureComponent {
|
||||||
if (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(purchaseUrl);
|
||||||
}
|
}
|
||||||
if (isViewable) {
|
if (isViewable) {
|
||||||
this.setState({ downloadPressed: true });
|
this.setState({ downloadPressed: true });
|
||||||
|
@ -686,7 +690,7 @@ class FilePage extends React.PureComponent {
|
||||||
let purchaseUrl;
|
let purchaseUrl;
|
||||||
if (navigation.state.params) {
|
if (navigation.state.params) {
|
||||||
const { uri, fullUri } = navigation.state.params;
|
const { uri, fullUri } = navigation.state.params;
|
||||||
purchaseUrl = fullUri || uri || permanentUrl;
|
purchaseUrl = fullUri || permanentUrl || uri;
|
||||||
}
|
}
|
||||||
if (!purchaseUrl && permanentUrl) {
|
if (!purchaseUrl && permanentUrl) {
|
||||||
purchaseUrl = permanentUrl;
|
purchaseUrl = permanentUrl;
|
||||||
|
@ -712,7 +716,7 @@ class FilePage extends React.PureComponent {
|
||||||
};
|
};
|
||||||
|
|
||||||
performDownload = () => {
|
performDownload = () => {
|
||||||
const { claim, costInfo, purchaseUri } = this.props;
|
const { claim, costInfo, fileGet, fileInfo, purchasedUris } = this.props;
|
||||||
this.setState(
|
this.setState(
|
||||||
{
|
{
|
||||||
downloadPressed: true,
|
downloadPressed: true,
|
||||||
|
@ -720,7 +724,13 @@ class FilePage extends React.PureComponent {
|
||||||
stopDownloadConfirmed: false,
|
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();
|
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) => {
|
openFile = (localFileUri, mediaType, contentType) => {
|
||||||
const { pushDrawerStack } = this.props;
|
const { pushDrawerStack } = this.props;
|
||||||
const isWebViewable = mediaType === 'text';
|
const isWebViewable = mediaType === 'text';
|
||||||
|
@ -1294,14 +1292,6 @@ class FilePage extends React.PureComponent {
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
<View style={filePageStyle.subscriptionRow}>
|
<View style={filePageStyle.subscriptionRow}>
|
||||||
{false && ((isPlayable && !fileInfo) || (isPlayable && fileInfo && !fileInfo.download_path)) && (
|
|
||||||
<Button
|
|
||||||
style={[filePageStyle.actionButton, filePageStyle.saveFileButton]}
|
|
||||||
theme={'light'}
|
|
||||||
icon={'download'}
|
|
||||||
onPress={this.onSaveFilePressed}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
{channelName && (
|
{channelName && (
|
||||||
<SubscribeButton
|
<SubscribeButton
|
||||||
style={filePageStyle.actionButton}
|
style={filePageStyle.actionButton}
|
||||||
|
|
|
@ -11,8 +11,8 @@ export const doPopDrawerStack = () => dispatch =>
|
||||||
type: Constants.ACTION_POP_DRAWER_STACK,
|
type: Constants.ACTION_POP_DRAWER_STACK,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const doSetPlayerVisible = visible => dispatch =>
|
export const doSetPlayerVisible = (visible, uri) => dispatch =>
|
||||||
dispatch({
|
dispatch({
|
||||||
type: Constants.ACTION_SET_PLAYER_VISIBLE,
|
type: Constants.ACTION_SET_PLAYER_VISIBLE,
|
||||||
data: { visible },
|
data: { visible, uri },
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,13 +4,27 @@ const reducers = {};
|
||||||
const defaultState = {
|
const defaultState = {
|
||||||
stack: [{ route: Constants.DRAWER_ROUTE_DISCOVER, params: {} }], // Discover is always the first drawer route
|
stack: [{ route: Constants.DRAWER_ROUTE_DISCOVER, params: {} }], // Discover is always the first drawer route
|
||||||
playerVisible: false,
|
playerVisible: false,
|
||||||
|
playerVisibleByUri: {},
|
||||||
currentRoute: null,
|
currentRoute: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
reducers[Constants.ACTION_SET_PLAYER_VISIBLE] = (state, action) =>
|
reducers[Constants.ACTION_SET_PLAYER_VISIBLE] = (state, action) => {
|
||||||
Object.assign({}, state, {
|
const { visible, uri } = action.data;
|
||||||
playerVisible: action.data.visible,
|
const playerVisibleByUri = Object.assign({}, state.playerVisibleByUri);
|
||||||
|
|
||||||
|
if (!uri) {
|
||||||
|
Object.keys(playerVisibleByUri).forEach(playerUri => {
|
||||||
|
playerVisibleByUri[playerUri] = visible;
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
playerVisibleByUri[uri] = visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Object.assign({}, state, {
|
||||||
|
playerVisible: action.data.visible,
|
||||||
|
playerVisibleByUri,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
reducers[Constants.ACTION_PUSH_DRAWER_STACK] = (state, action) => {
|
reducers[Constants.ACTION_PUSH_DRAWER_STACK] = (state, action) => {
|
||||||
const { routeName, params } = action.data;
|
const { routeName, params } = action.data;
|
||||||
|
|
|
@ -4,12 +4,23 @@ export const selectState = state => state.drawer || {};
|
||||||
|
|
||||||
export const selectDrawerStack = createSelector(
|
export const selectDrawerStack = createSelector(
|
||||||
selectState,
|
selectState,
|
||||||
state => state.stack
|
state => state.stack,
|
||||||
);
|
);
|
||||||
|
|
||||||
export const selectIsPlayerVisible = createSelector(
|
export const selectIsPlayerVisible = createSelector(
|
||||||
selectState,
|
selectState,
|
||||||
state => state.playerVisible
|
state => state.playerVisible,
|
||||||
|
);
|
||||||
|
|
||||||
|
export const selectPlayerVisibleByUri = createSelector(
|
||||||
|
selectState,
|
||||||
|
state => state.playerVisibleByUri,
|
||||||
|
);
|
||||||
|
|
||||||
|
export const makeSelectPlayerVisible = uri =>
|
||||||
|
createSelector(
|
||||||
|
selectPlayerVisibleByUri,
|
||||||
|
byUri => (byUri ? byUri[uri] : false),
|
||||||
);
|
);
|
||||||
|
|
||||||
export const selectLastDrawerRoute = createSelector(
|
export const selectLastDrawerRoute = createSelector(
|
||||||
|
@ -20,10 +31,10 @@ export const selectLastDrawerRoute = createSelector(
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
export const selectCurrentRoute = createSelector(
|
export const selectCurrentRoute = createSelector(
|
||||||
selectState,
|
selectState,
|
||||||
state => state.currentRoute
|
state => state.currentRoute,
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { NavigationActions, StackActions } from 'react-navigation';
|
import { NavigationActions, StackActions } from 'react-navigation';
|
||||||
import { buildURI, isURIValid, normalizeURI } from 'lbry-redux';
|
import { buildURI, isURIValid, normalizeURI } from 'lbry-redux';
|
||||||
import { Lbryio } from 'lbryinc';
|
import { Lbryio } from 'lbryinc';
|
||||||
import { doPopDrawerStack, doPushDrawerStack, doSetPlayerVisible } from 'redux/actions/drawer';
|
import { doPopDrawerStack, doPushDrawerStack } from 'redux/actions/drawer';
|
||||||
import Constants, { DrawerRoutes, InnerDrawerRoutes } from 'constants'; // eslint-disable-line node/no-deprecated-api
|
import Constants, { DrawerRoutes, InnerDrawerRoutes } from 'constants'; // eslint-disable-line node/no-deprecated-api
|
||||||
|
|
||||||
const tagNameLength = 10;
|
const tagNameLength = 10;
|
||||||
|
@ -54,7 +54,6 @@ export function dispatchNavigateToUri(dispatch, nav, uri, isNavigatingBack, full
|
||||||
|
|
||||||
if (!isNavigatingBack) {
|
if (!isNavigatingBack) {
|
||||||
dispatch(doPushDrawerStack(uri));
|
dispatch(doPushDrawerStack(uri));
|
||||||
dispatch(doSetPlayerVisible(true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nav && nav.routes && nav.routes.length > 0 && nav.routes[0].routeName === 'Main') {
|
if (nav && nav.routes && nav.routes.length > 0 && nav.routes[0].routeName === 'Main') {
|
||||||
|
@ -64,14 +63,14 @@ export function dispatchNavigateToUri(dispatch, nav, uri, isNavigatingBack, full
|
||||||
const fileRoute = discoverRoute.routes[discoverRoute.index];
|
const fileRoute = discoverRoute.routes[discoverRoute.index];
|
||||||
// Currently on a file page, so we can ignore (if the URI is the same) or replace (different URIs)
|
// Currently on a file page, so we can ignore (if the URI is the same) or replace (different URIs)
|
||||||
if (uri !== fileRoute.params.uri) {
|
if (uri !== fileRoute.params.uri) {
|
||||||
const stackAction = StackActions.replace({ routeName: 'File', newKey: 'file', params });
|
const stackAction = StackActions.replace({ routeName: 'File', newKey: uri, params });
|
||||||
dispatch(stackAction);
|
dispatch(stackAction);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const navigateAction = NavigationActions.navigate({ routeName: 'File', key: 'file', params });
|
const navigateAction = NavigationActions.navigate({ routeName: 'File', key: uri, params });
|
||||||
dispatch(navigateAction);
|
dispatch(navigateAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,19 +137,17 @@ export function navigateToUri(navigation, uri, additionalParams, isNavigatingBac
|
||||||
const { store } = window;
|
const { store } = window;
|
||||||
const params = Object.assign({ uri, uriVars, fullUri: fullUri }, additionalParams);
|
const params = Object.assign({ uri, uriVars, fullUri: fullUri }, additionalParams);
|
||||||
if (navigation.state.routeName === 'File') {
|
if (navigation.state.routeName === 'File') {
|
||||||
const stackAction = StackActions.replace({ routeName: 'File', newKey: 'file', params });
|
const stackAction = StackActions.replace({ routeName: 'File', newKey: uri, params });
|
||||||
navigation.dispatch(stackAction);
|
navigation.dispatch(stackAction);
|
||||||
if (store && store.dispatch && !isNavigatingBack) {
|
if (store && store.dispatch && !isNavigatingBack) {
|
||||||
store.dispatch(doPushDrawerStack(uri));
|
store.dispatch(doPushDrawerStack(uri));
|
||||||
store.dispatch(doSetPlayerVisible(true));
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
navigation.navigate({ routeName: 'File', key: 'file', params });
|
navigation.navigate({ routeName: 'File', key: uri, params });
|
||||||
if (store && store.dispatch && !isNavigatingBack) {
|
if (store && store.dispatch && !isNavigatingBack) {
|
||||||
store.dispatch(doPushDrawerStack(uri));
|
store.dispatch(doPushDrawerStack(uri));
|
||||||
store.dispatch(doSetPlayerVisible(true));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue