Compare commits

..
15 changed files with 118 additions and 209 deletions

No files matched your search

+34 -50
View File
@@ -1,13 +1,10 @@
import React from 'react';
import { normalizeURI, parseURI } from 'lbry-redux';
import { ActivityIndicator, Platform, Text, TouchableOpacity, View } from 'react-native';
import { navigateToUri, formatTitle, getDownloadProgress, getStorageForFileInfo } from 'utils/helper';
import { navigateToUri, formatBytes } from 'utils/helper';
import Colors from 'styles/colors';
import ChannelIconItem from 'component/channelIconItem';
import channelIconStyle from 'styles/channelIcon';
import Constants from 'constants'; // eslint-disable-line node/no-deprecated-api
import DateTime from 'component/dateTime';
import FastImage from 'react-native-fast-image';
import FileItemMedia from 'component/fileItemMedia';
import FilePrice from 'component/filePrice';
import Icon from 'react-native-vector-icons/FontAwesome5';
@@ -18,10 +15,27 @@ import fileListStyle from 'styles/fileList';
class FileListItem extends React.PureComponent {
state = {
autoStyle: null,
url: null,
};
getStorageForFileInfo = fileInfo => {
if (!fileInfo.completed) {
const written = formatBytes(fileInfo.written_bytes);
const total = formatBytes(fileInfo.total_bytes);
return `(${written} / ${total})`;
}
return formatBytes(fileInfo.written_bytes);
};
formatTitle = title => {
if (!title) {
return title;
}
return title.length > 80 ? title.substring(0, 77).trim() + '...' : title;
};
getDownloadProgress = fileInfo => {
return Math.ceil((fileInfo.written_bytes / fileInfo.total_bytes) * 100);
};
@@ -31,11 +45,6 @@ class FileListItem extends React.PureComponent {
if (!claim && !batchResolve) {
resolveUri(uri);
}
this.setState({
autoStyle:
ChannelIconItem.AUTO_THUMB_STYLES[Math.floor(Math.random() * ChannelIconItem.AUTO_THUMB_STYLES.length)],
});
}
componentDidUpdate() {
@@ -126,13 +135,10 @@ class FileListItem extends React.PureComponent {
return null;
}
const isChannel = name && name.startsWith('@');
const hasThumbnail = !!thumbnail;
return (
<View style={style}>
<TouchableOpacity
style={[style, isChannel ? fileListStyle.channelContainer : null]}
style={style}
onPress={this.onPressHandler}
onLongPress={() => {
if (onLongPress) {
@@ -140,35 +146,13 @@ class FileListItem extends React.PureComponent {
}
}}
>
{!isChannel && (
<FileItemMedia
style={fileListStyle.thumbnail}
duration={duration}
resizeMode="cover"
title={title || name || normalizeURI(uri).substring(7)}
thumbnail={thumbnail}
/>
)}
{isChannel && (
<View style={fileListStyle.thumbnail}>
<View style={[fileListStyle.channelThumbnailContainer, this.state.autoStyle]}>
{hasThumbnail && (
<FastImage
style={fileListStyle.channelThumbnail}
resizeMode={FastImage.resizeMode.cover}
source={{ uri: thumbnail }}
/>
)}
{!hasThumbnail && (
<Text style={channelIconStyle.autothumbCharacter}>
{title ? title.substring(0, 1).toUpperCase() : claim.name.substring(1, 2).toUpperCase()}
</Text>
)}
</View>
</View>
)}
<FileItemMedia
style={fileListStyle.thumbnail}
duration={duration}
resizeMode="cover"
title={title || name || normalizeURI(uri).substring(7)}
thumbnail={thumbnail}
/>
{selected && (
<View style={fileListStyle.selectedOverlay}>
<Icon name={'check-circle'} solid color={Colors.NextLbryGreen} size={32} />
@@ -210,7 +194,7 @@ class FileListItem extends React.PureComponent {
{(title || name) && (
<View style={fileListStyle.titleContainer}>
<Text style={featuredResult ? fileListStyle.featuredTitle : fileListStyle.title}>
{formatTitle(title) || formatTitle(name)}
{this.formatTitle(title) || this.formatTitle(name)}
</Text>
{isRewardContent && <Icon style={fileListStyle.rewardIcon} name="award" size={12} />}
</View>
@@ -222,17 +206,17 @@ class FileListItem extends React.PureComponent {
</View>
)}
{(channel || isChannel) && !hideChannel && (
{channel && !hideChannel && (
<Link
style={fileListStyle.publisher}
text={isChannel ? name : channel}
text={channel}
onPress={() => {
navigateToUri(
navigation,
normalizeURI(isChannel ? uri : shortChannelUri || fullChannelUri),
normalizeURI(shortChannelUri || fullChannelUri),
null,
false,
isChannel ? claim && claim.permanent_url : fullChannelUri,
fullChannelUri,
);
}}
/>
@@ -240,7 +224,7 @@ class FileListItem extends React.PureComponent {
<View style={fileListStyle.info}>
{fileInfo && !isNaN(fileInfo.written_bytes) && fileInfo.written_bytes > 0 && (
<Text style={fileListStyle.infoText}>{getStorageForFileInfo(fileInfo)}</Text>
<Text style={fileListStyle.infoText}>{this.getStorageForFileInfo(fileInfo)}</Text>
)}
<DateTime style={fileListStyle.publishInfo} textStyle={fileListStyle.infoText} timeAgo uri={uri} />
</View>
@@ -253,7 +237,7 @@ class FileListItem extends React.PureComponent {
color={Colors.NextLbryGreen}
height={3}
style={fileListStyle.progress}
progress={getDownloadProgress(fileInfo)}
progress={this.getDownloadProgress(fileInfo)}
/>
)}
</View>
@@ -12,7 +12,7 @@ import {
} from 'lbry-redux';
import { selectBlackListedOutpoints, selectFilteredOutpoints, selectRewardContentClaimIds } from 'lbryinc';
import { selectShowNsfw } from 'redux/selectors/settings';
import ClaimResultItem from './view';
import FileResultItem from './view';
const select = (state, props) => ({
blackListedOutpoints: selectBlackListedOutpoints(state),
@@ -37,4 +37,4 @@ const perform = dispatch => ({
export default connect(
select,
perform,
)(ClaimResultItem);
)(FileResultItem);
@@ -1,13 +1,10 @@
import React from 'react';
import { normalizeURI, parseURI } from 'lbry-redux';
import { ActivityIndicator, Platform, Text, TouchableOpacity, View } from 'react-native';
import { navigateToUri, formatTitle, getDownloadProgress, getStorageForFileInfo } from 'utils/helper';
import { navigateToUri, formatBytes } from 'utils/helper';
import Colors from 'styles/colors';
import ChannelIconItem from 'component/channelIconItem';
import channelIconStyle from 'styles/channelIcon';
import Constants from 'constants'; // eslint-disable-line node/no-deprecated-api
import DateTime from 'component/dateTime';
import FastImage from 'react-native-fast-image';
import FileItemMedia from 'component/fileItemMedia';
import FilePrice from 'component/filePrice';
import Icon from 'react-native-vector-icons/FontAwesome5';
@@ -15,28 +12,29 @@ import Link from 'component/link';
import NsfwOverlay from 'component/nsfwOverlay';
import ProgressBar from 'component/progressBar';
import fileListStyle from 'styles/fileList';
import seedrandom from 'seedrandom';
class ClaimResultItem extends React.PureComponent {
state = {
autoStyle: null,
class FileResultItem extends React.PureComponent {
getStorageForFileInfo = fileInfo => {
if (!fileInfo.completed) {
const written = formatBytes(fileInfo.written_bytes);
const total = formatBytes(fileInfo.total_bytes);
return `(${written} / ${total})`;
}
return formatBytes(fileInfo.written_bytes);
};
componentDidMount() {
const { result } = this.props;
if (!result || !result.name || !result.claimId) {
this.setState({
autoStyle:
ChannelIconItem.AUTO_THUMB_STYLES[Math.floor(Math.random() * ChannelIconItem.AUTO_THUMB_STYLES.length)],
});
} else {
// result property set, use deterministic random style
const rng = seedrandom(normalizeURI(`${result.name}#${result.claimId}`));
const index = Math.floor(rng.quick() * ChannelIconItem.AUTO_THUMB_STYLES.length);
this.setState({ autoStyle: ChannelIconItem.AUTO_THUMB_STYLES[index] });
formatTitle = title => {
if (!title) {
return title;
}
}
return title.length > 80 ? title.substring(0, 77).trim() + '...' : title;
};
getDownloadProgress = fileInfo => {
return Math.ceil((fileInfo.written_bytes / fileInfo.total_bytes) * 100);
};
onPressHandler = () => {
const { autoplay, navigation, result } = this.props;
@@ -60,8 +58,6 @@ class ClaimResultItem extends React.PureComponent {
title,
} = result;
const isChannel = name && name.startsWith('@');
const hasThumbnail = !!thumbnailUrl;
const obscure = obscureNsfw && nsfw;
const url = normalizeURI(`${name}#${claimId}`);
const hasChannel = !!channel;
@@ -70,39 +66,14 @@ class ClaimResultItem extends React.PureComponent {
return (
<View style={style}>
<TouchableOpacity
style={[style, isChannel ? fileListStyle.channelContainer : null]}
onPress={this.onPressHandler}
>
{!isChannel && (
<FileItemMedia
style={fileListStyle.thumbnail}
duration={duration}
resizeMode="cover"
title={title || name || normalizeURI(url).substring(7)}
thumbnail={thumbnailUrl}
/>
)}
{isChannel && (
<View style={fileListStyle.thumbnail}>
<View style={[fileListStyle.channelThumbnailContainer, this.state.autoStyle]}>
{hasThumbnail && (
<FastImage
style={fileListStyle.channelThumbnail}
resizeMode={FastImage.resizeMode.cover}
source={{ uri: thumbnailUrl }}
/>
)}
{!hasThumbnail && (
<Text style={channelIconStyle.autothumbCharacter}>
{title ? title.substring(0, 1).toUpperCase() : name.substring(1, 2).toUpperCase()}
</Text>
)}
</View>
</View>
)}
<TouchableOpacity style={style} onPress={this.onPressHandler}>
<FileItemMedia
style={fileListStyle.thumbnail}
duration={duration}
resizeMode="cover"
title={title || name || normalizeURI(url).substring(7)}
thumbnail={thumbnailUrl}
/>
{fileInfo && fileInfo.completed && fileInfo.download_path && (
<Icon
style={featuredResult ? fileListStyle.featuredDownloadedIcon : fileListStyle.downloadedIcon}
@@ -123,32 +94,25 @@ class ClaimResultItem extends React.PureComponent {
{(title || name) && (
<View style={fileListStyle.titleContainer}>
<Text style={featuredResult ? fileListStyle.featuredTitle : fileListStyle.title}>
{formatTitle(title) || formatTitle(name)}
{this.formatTitle(title) || this.formatTitle(name)}
</Text>
{isRewardContent && <Icon style={fileListStyle.rewardIcon} name="award" size={12} />}
</View>
)}
{hasChannel ||
(isChannel && (
<Link
style={fileListStyle.publisher}
text={isChannel ? name : channel}
onPress={() => {
navigateToUri(
navigation,
normalizeURI(isChannel ? url : channelUrl),
null,
false,
isChannel ? url : channelUrl,
);
}}
/>
))}
{hasChannel && (
<Link
style={fileListStyle.publisher}
text={channel}
onPress={() => {
navigateToUri(navigation, normalizeURI(channelUrl), null, false, channelUrl);
}}
/>
)}
<View style={fileListStyle.info}>
{fileInfo && !isNaN(fileInfo.written_bytes) && fileInfo.written_bytes > 0 && (
<Text>{getStorageForFileInfo(fileInfo)}</Text>
<Text>{this.getStorageForFileInfo(fileInfo)}</Text>
)}
<DateTime
style={fileListStyle.publishInfo}
@@ -166,7 +130,7 @@ class ClaimResultItem extends React.PureComponent {
color={Colors.NextLbryGreen}
height={3}
style={fileListStyle.progress}
progress={getDownloadProgress(fileInfo)}
progress={this.getDownloadProgress(fileInfo)}
/>
)}
</View>
@@ -179,4 +143,4 @@ class ClaimResultItem extends React.PureComponent {
}
}
export default ClaimResultItem;
export default FileResultItem;
+2 -2
View File
@@ -4,7 +4,7 @@ import { normalizeURI } from 'lbry-redux';
import { navigateToUri } from 'utils/helper';
import Colors from 'styles/colors';
import FileListItem from 'component/fileListItem';
import ClaimResultItem from 'component/claimResultItem';
import FileResultItem from 'component/fileResultItem';
import fileListStyle from 'styles/fileList';
import relatedContentStyle from 'styles/relatedContent';
@@ -30,7 +30,7 @@ export default class RelatedContent extends React.PureComponent {
{isSearching && <ActivityIndicator size={'small'} color={Colors.NextLbryGreen} />}
{recommendedContent &&
recommendedContent.map(result => (
<ClaimResultItem
<FileResultItem
style={fileListStyle.item}
key={result.claimId}
result={result}
@@ -3,8 +3,6 @@ import { buildURI, normalizeURI } from 'lbry-redux';
import { ActivityIndicator, FlatList, Image, Text, View } from 'react-native';
import { navigateToUri } from 'utils/helper';
import Colors from 'styles/colors';
import ChannelIconItem from 'component/channelIconItem';
import channelIconStyle from 'styles/channelIcon';
import discoverStyle from 'styles/discover';
import FileItem from 'component/fileItem';
import SubscribeButton from 'component/subscribeButton';
@@ -13,20 +11,11 @@ import Link from 'component/link';
import Tag from 'component/tag';
class SuggestedSubscriptionItem extends React.PureComponent {
state = {
autoStyle: null,
};
componentDidMount() {
const { claim, uri, resolveUri } = this.props;
if (!claim) {
resolveUri(uri);
}
this.setState({
autoStyle:
ChannelIconItem.AUTO_THUMB_STYLES[Math.floor(Math.random() * ChannelIconItem.AUTO_THUMB_STYLES.length)],
});
}
render() {
@@ -39,7 +28,6 @@ class SuggestedSubscriptionItem extends React.PureComponent {
}
}
const hasThumbnail = !!thumbnail;
if (isResolvingUri) {
return (
<View style={subscriptionsStyle.itemLoadingContainer}>
@@ -50,15 +38,12 @@ class SuggestedSubscriptionItem extends React.PureComponent {
return (
<View style={subscriptionsStyle.suggestedItem}>
<View style={[subscriptionsStyle.suggestedItemThumbnailContainer, this.state.autoStyle]}>
{hasThumbnail && (
<Image style={subscriptionsStyle.suggestedItemThumbnail} resizeMode={'cover'} source={{ uri: thumbnail }} />
)}
{!hasThumbnail && (
<Text style={channelIconStyle.autothumbCharacter}>
{title ? title.substring(0, 1).toUpperCase() : claim ? claim.name.substring(1, 2).toUpperCase() : ''}
</Text>
)}
<View style={subscriptionsStyle.suggestedItemThumbnailContainer}>
<Image
style={subscriptionsStyle.suggestedItemThumbnail}
resizeMode={'cover'}
source={thumbnail ? { uri: thumbnail } : require('../../assets/default_avatar.jpg')}
/>
</View>
<View style={subscriptionsStyle.suggestedItemDetails}>
+2 -3
View File
@@ -21,7 +21,6 @@ import ChannelRewardsDriver from 'component/channelRewardsDriver';
import Colors from 'styles/colors';
import Constants from 'constants'; // eslint-disable-line node/no-deprecated-api
import EmptyStateView from 'component/emptyStateView';
import FastImage from 'react-native-fast-image';
import FloatingWalletBalance from 'component/floatingWalletBalance';
import Icon from 'react-native-vector-icons/FontAwesome5';
import Link from 'component/link';
@@ -868,9 +867,9 @@ export default class ChannelCreator extends React.PureComponent {
>
<View style={[channelCreatorStyle.channelListAvatar, itemAutoStyle]}>
{itemThumbnailUrl && (
<FastImage
<Image
style={channelCreatorStyle.avatarImage}
resizeMode={FastImage.resizeMode.cover}
resizeMode={'cover'}
source={{ uri: itemThumbnailUrl }}
/>
)}
+23 -4
View File
@@ -109,6 +109,7 @@ class FilePage extends React.PureComponent {
onComponentFocused = () => {
StatusBar.setHidden(false);
console.log('fileComponent Focused...');
NativeModules.Firebase.setCurrentScreen('File').then(result => {
DeviceEventEmitter.addListener('onStoragePermissionGranted', this.handleStoragePermissionGranted);
DeviceEventEmitter.addListener('onStoragePermissionRefused', this.handleStoragePermissionRefused);
@@ -652,13 +653,13 @@ class FilePage extends React.PureComponent {
const isPlayable = mediaType === 'video' || mediaType === 'audio';
const isViewable = mediaType === 'image' || mediaType === 'text';
const { permanent_url: uri } = claim;
NativeModules.Firebase.track('purchase_uri', { uri: uri });
const purchaseUrl = this.getPurchaseUrl();
NativeModules.Firebase.track('purchase_uri', { uri: purchaseUrl });
if (!isPlayable) {
this.checkStoragePermissionForDownload();
} else {
this.confirmPurchaseUri(uri, costInfo, !isPlayable);
this.confirmPurchaseUri(purchaseUrl, costInfo, !isPlayable);
}
if (isPlayable) {
@@ -671,6 +672,19 @@ class FilePage extends React.PureComponent {
}
};
getPurchaseUrl = () => {
const { claim, navigation } = this.props;
const { permanent_url: permanentUrl } = claim;
let purchaseUrl;
if (navigation.state.params) {
const { uri, fullUri } = navigation.state.params;
purchaseUrl = fullUri || uri || permanentUrl;
}
return purchaseUrl;
};
onDownloadPressed = () => {
this.checkStoragePermissionForDownload();
};
@@ -796,6 +810,11 @@ class FilePage extends React.PureComponent {
'<html>' +
' <head>' +
' <meta charset="utf-8"/>' +
' <meta name="viewport" content="width=device-width, user-scalable=no"/>' +
' <style type="text/css">' +
' body { margin: 16px }' +
' img { width: 100%; }' +
' </style>' +
' </head>' +
' <body>' +
' <div id="content"></div>' +
@@ -842,7 +861,7 @@ class FilePage extends React.PureComponent {
<View style={filePageStyle.pageContainer}>
<UriBar value={uri} navigation={navigation} />
{isResolvingUri && (
<View stylebuildWeb={filePageStyle.busyContainer}>
<View style={filePageStyle.busyContainer}>
<ActivityIndicator size="large" color={Colors.NextLbryGreen} />
<Text style={filePageStyle.infoText}>{__('Loading decentralized data...')}</Text>
</View>
+2 -7
View File
@@ -15,7 +15,7 @@ import Colors from 'styles/colors';
import Constants from 'constants'; // eslint-disable-line node/no-deprecated-api
import PageHeader from 'component/pageHeader';
import FileListItem from 'component/fileListItem';
import ClaimResultItem from 'component/claimResultItem';
import FileResultItem from 'component/fileResultItem';
import FloatingWalletBalance from 'component/floatingWalletBalance';
import UriBar from 'component/uriBar';
import searchStyle from 'styles/search';
@@ -213,12 +213,7 @@ class SearchPage extends React.PureComponent {
ListEmptyComponent={!isSearching ? this.listEmptyComponent() : null}
ListHeaderComponent={this.listHeaderComponent(this.state.showTagResult, this.state.currentQuery)}
renderItem={({ item }) => (
<ClaimResultItem
key={item.claimId}
result={item}
style={searchStyle.resultItem}
navigation={navigation}
/>
<FileResultItem key={item.claimId} result={item} style={searchStyle.resultItem} navigation={navigation} />
)}
/>
)}
+1 -1
View File
@@ -73,7 +73,7 @@ class SubscriptionsPage extends React.PureComponent {
};
componentDidMount() {
this.onComponentFocused();
// this.onComponentFocused();
}
componentWillReceiveProps(nextProps) {
+2
View File
@@ -24,6 +24,8 @@ const Colors = {
StatsAudio: '#f6a637',
StatsImage: '#ff4a7d',
StatsOther: '#26bcf7',
ThumbnailPlaceholder: '#d5d5d5',
};
export default Colors;
+1 -15
View File
@@ -32,24 +32,13 @@ const fileListStyle = StyleSheet.create({
color: Colors.White,
},
thumbnail: {
backgroundColor: Colors.ThumbnailPlaceholder,
width: thumbnailWidth,
height: thumbnailHeight,
marginRight: screenWidthPixels <= 720 ? 10 : 12,
alignItems: 'center',
justifyContent: 'center',
},
channelThumbnailContainer: {
width: thumbnailHeight, // maintain same width and height
height: thumbnailHeight,
borderRadius: 140,
overflow: 'hidden',
alignItems: 'center',
justifyContent: 'center',
},
channelThumbnail: {
width: '100%',
height: '100%',
},
selectedOverlay: {
position: 'absolute',
left: 0,
@@ -75,9 +64,6 @@ const fileListStyle = StyleSheet.create({
marginTop: screenWidthPixels <= 720 ? 1 : 3,
color: Colors.LbryGreen,
},
channelContainer: {
alignItems: 'center',
},
loading: {
position: 'absolute',
},
-1
View File
@@ -65,7 +65,6 @@ const filePageStyle = StyleSheet.create({
titleRow: {
flexDirection: 'row',
marginTop: 12,
marginBottom: 2,
marginLeft: 12,
marginRight: 12,
alignItems: 'center',
+2 -2
View File
@@ -46,8 +46,8 @@ const floatingButtonStyle = StyleSheet.create({
fontSize: 16,
},
bottomRight: {
right: 10,
bottom: 10,
right: 0,
bottom: 0,
},
rewardIcon: {
color: Colors.White,
-2
View File
@@ -199,8 +199,6 @@ const subscriptionsStyle = StyleSheet.create({
height: 70,
borderRadius: 140,
overflow: 'hidden',
alignItems: 'center',
justifyContent: 'center',
},
suggestedItemThumbnail: {
width: '100%',
-22
View File
@@ -370,25 +370,3 @@ export function uploadImageAsset(filePath, success, failure) {
export function formatLbryUrlForWeb(url) {
return url.replace('lbry://', '/').replace(/#/g, ':');
}
export function getDownloadProgress(fileInfo) {
return Math.ceil((fileInfo.written_bytes / fileInfo.total_bytes) * 100);
}
export function getStorageForFileInfo(fileInfo) {
if (!fileInfo.completed) {
const written = formatBytes(fileInfo.written_bytes);
const total = formatBytes(fileInfo.total_bytes);
return `(${written} / ${total})`;
}
return formatBytes(fileInfo.written_bytes);
}
export function formatTitle(title) {
if (!title) {
return title;
}
return title.length > 80 ? title.substring(0, 77).trim() + '...' : title;
}