show notifications for video downloads. fix double playback.

This commit is contained in:
Akinwale Ariwodola 2020-01-14 03:28:53 +01:00
parent 86b2f25b66
commit f2b0d3417b
8 changed files with 63 additions and 48 deletions

View file

@ -11,7 +11,7 @@ import {
selectSubscriptionClaims,
selectUnreadSubscriptions,
} from 'lbryinc';
import { doPushDrawerStack } from 'redux/actions/drawer';
import { doPushDrawerStack, doSetPlayerVisible } from 'redux/actions/drawer';
import { doSetClientSetting, doSetSortByItem, doSetTimeItem } from 'redux/actions/settings';
import { makeSelectClientSetting, selectSortByItem, selectTimeItem } from 'redux/selectors/settings';
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)),
removeUnreadSubscriptions: () => dispatch(doRemoveUnreadSubscriptions()),
setClientSetting: (key, value) => dispatch(doSetClientSetting(key, value)),
setPlayerVisible: () => dispatch(doSetPlayerVisible(false)),
setSortByItem: item => dispatch(doSetSortByItem(item)),
setTimeItem: item => dispatch(doSetTimeItem(item)),
});
export default connect(
select,
perform
perform,
)(DiscoverPage);

View file

@ -86,9 +86,11 @@ class DiscoverPage extends React.PureComponent {
}
onComponentFocused = () => {
const { pushDrawerStack } = this.props;
const { pushDrawerStack, setPlayerVisible } = this.props;
// pushDrawerStack();
NativeModules.Firebase.setCurrentScreen('Your tags');
setPlayerVisible();
};
handleSortByItemSelected = item => {
@ -135,7 +137,7 @@ class DiscoverPage extends React.PureComponent {
Alert.alert(
__('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 },
);
}
}

View file

@ -41,7 +41,7 @@ import {
import { doDeleteFile, doStopDownloadingFile } from 'redux/actions/file';
import { doPushDrawerStack, doPopDrawerStack, doSetPlayerVisible } from 'redux/actions/drawer';
import { doToggleFullscreenMode } from 'redux/actions/settings';
import { selectDrawerStack, selectIsPlayerVisible } from 'redux/selectors/drawer';
import { selectDrawerStack, makeSelectPlayerVisible } from 'redux/selectors/drawer';
import FilePage from './view';
const select = (state, props) => {
@ -61,7 +61,7 @@ const select = (state, props) => {
fileInfo: makeSelectFileInfoForUri(contentUri)(state),
rewardedContentClaimIds: selectRewardContentClaimIds(state, selectProps),
channelUri: makeSelectChannelForClaimUri(contentUri, true)(state),
isPlayerVisible: selectIsPlayerVisible(state),
isPlayerVisible: makeSelectPlayerVisible(uri)(state), // use navigation uri for this selector
position: makeSelectContentPositionForUri(contentUri)(state),
purchasedUris: selectPurchasedUris(state),
failedPurchaseUris: selectFailedPurchaseUris(state),
@ -96,7 +96,7 @@ const perform = dispatch => ({
resolveUris: uris => dispatch(doResolveUris(uris)),
sendTip: (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)),
toggleFullscreenMode: mode => dispatch(doToggleFullscreenMode(mode)),
});

View file

@ -116,6 +116,9 @@ class FilePage extends React.PureComponent {
onComponentFocused = () => {
StatusBar.setHidden(false);
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('onStoragePermissionRefused', this.handleStoragePermissionRefused);
@ -123,6 +126,7 @@ class FilePage extends React.PureComponent {
const { uri, uriVars } = navigation.state.params;
this.setState({ uri, uriVars });
setPlayerVisible(true, uri);
if (!isResolvingUri && !claim) resolveUri(uri);
this.fetchFileInfo(uri, this.props);
@ -672,7 +676,7 @@ class FilePage extends React.PureComponent {
if (isPlayable) {
this.startTime = Date.now();
this.setState({ downloadPressed: true, autoPlayMedia: true, stopDownloadConfirmed: false });
setPlayerVisible();
// setPlayerVisible(purchaseUrl);
}
if (isViewable) {
this.setState({ downloadPressed: true });
@ -686,7 +690,7 @@ class FilePage extends React.PureComponent {
let purchaseUrl;
if (navigation.state.params) {
const { uri, fullUri } = navigation.state.params;
purchaseUrl = fullUri || uri || permanentUrl;
purchaseUrl = fullUri || permanentUrl || uri;
}
if (!purchaseUrl && permanentUrl) {
purchaseUrl = permanentUrl;
@ -712,7 +716,7 @@ class FilePage extends React.PureComponent {
};
performDownload = () => {
const { claim, costInfo, purchaseUri } = this.props;
const { claim, costInfo, fileGet, fileInfo, purchasedUris } = this.props;
this.setState(
{
downloadPressed: true,
@ -720,7 +724,13 @@ class FilePage extends React.PureComponent {
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();
},
);
@ -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) => {
const { pushDrawerStack } = this.props;
const isWebViewable = mediaType === 'text';
@ -1294,14 +1292,6 @@ class FilePage extends React.PureComponent {
/>
</View>
<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 && (
<SubscribeButton
style={filePageStyle.actionButton}

View file

@ -11,8 +11,8 @@ export const doPopDrawerStack = () => dispatch =>
type: Constants.ACTION_POP_DRAWER_STACK,
});
export const doSetPlayerVisible = visible => dispatch =>
export const doSetPlayerVisible = (visible, uri) => dispatch =>
dispatch({
type: Constants.ACTION_SET_PLAYER_VISIBLE,
data: { visible },
data: { visible, uri },
});

View file

@ -4,13 +4,27 @@ const reducers = {};
const defaultState = {
stack: [{ route: Constants.DRAWER_ROUTE_DISCOVER, params: {} }], // Discover is always the first drawer route
playerVisible: false,
playerVisibleByUri: {},
currentRoute: null,
};
reducers[Constants.ACTION_SET_PLAYER_VISIBLE] = (state, action) =>
Object.assign({}, state, {
playerVisible: action.data.visible,
reducers[Constants.ACTION_SET_PLAYER_VISIBLE] = (state, action) => {
const { visible, uri } = action.data;
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) => {
const { routeName, params } = action.data;

View file

@ -4,14 +4,25 @@ export const selectState = state => state.drawer || {};
export const selectDrawerStack = createSelector(
selectState,
state => state.stack
state => state.stack,
);
export const selectIsPlayerVisible = createSelector(
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(
selectState,
state => {
@ -20,10 +31,10 @@ export const selectLastDrawerRoute = createSelector(
}
return null;
}
},
);
export const selectCurrentRoute = createSelector(
selectState,
state => state.currentRoute
state => state.currentRoute,
);

View file

@ -1,7 +1,7 @@
import { NavigationActions, StackActions } from 'react-navigation';
import { buildURI, isURIValid, normalizeURI } from 'lbry-redux';
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
const tagNameLength = 10;
@ -54,7 +54,6 @@ export function dispatchNavigateToUri(dispatch, nav, uri, isNavigatingBack, full
if (!isNavigatingBack) {
dispatch(doPushDrawerStack(uri));
dispatch(doSetPlayerVisible(true));
}
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];
// Currently on a file page, so we can ignore (if the URI is the same) or replace (different URIs)
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);
return;
}
}
}
const navigateAction = NavigationActions.navigate({ routeName: 'File', key: 'file', params });
const navigateAction = NavigationActions.navigate({ routeName: 'File', key: uri, params });
dispatch(navigateAction);
}
@ -138,19 +137,17 @@ export function navigateToUri(navigation, uri, additionalParams, isNavigatingBac
const { store } = window;
const params = Object.assign({ uri, uriVars, fullUri: fullUri }, additionalParams);
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);
if (store && store.dispatch && !isNavigatingBack) {
store.dispatch(doPushDrawerStack(uri));
store.dispatch(doSetPlayerVisible(true));
}
return;
}
navigation.navigate({ routeName: 'File', key: 'file', params });
navigation.navigate({ routeName: 'File', key: uri, params });
if (store && store.dispatch && !isNavigatingBack) {
store.dispatch(doPushDrawerStack(uri));
store.dispatch(doSetPlayerVisible(true));
}
}