mirror of
https://github.com/balzack/databag.git
synced 2025-02-11 19:19:16 +00:00
adding download button to viewing assets
This commit is contained in:
parent
169bf5906a
commit
0ac7dffd29
@ -7,6 +7,7 @@ import { styles } from './AudioAsset.styled';
|
|||||||
import Icons from 'react-native-vector-icons/MaterialCommunityIcons';
|
import Icons from 'react-native-vector-icons/MaterialCommunityIcons';
|
||||||
import audio from 'images/audio.png';
|
import audio from 'images/audio.png';
|
||||||
import { useKeepAwake } from '@sayem314/react-native-keep-awake';
|
import { useKeepAwake } from '@sayem314/react-native-keep-awake';
|
||||||
|
import MatIcons from 'react-native-vector-icons/MaterialCommunityIcons';
|
||||||
|
|
||||||
export function AudioAsset({ asset, dismiss }) {
|
export function AudioAsset({ asset, dismiss }) {
|
||||||
|
|
||||||
@ -30,9 +31,15 @@ export function AudioAsset({ asset, dismiss }) {
|
|||||||
<Icons name="pause-circle-outline" size={92} color={Colors.text} />
|
<Icons name="pause-circle-outline" size={92} color={Colors.text} />
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
)}
|
)}
|
||||||
|
{ state.url && (
|
||||||
|
<TouchableOpacity style={styles.share} onPress={actions.download}>
|
||||||
|
<MatIcons name="share-variant-outline" size={32} color={Colors.text} />
|
||||||
|
</TouchableOpacity>
|
||||||
|
)}
|
||||||
<TouchableOpacity style={styles.close} onPress={dismiss}>
|
<TouchableOpacity style={styles.close} onPress={dismiss}>
|
||||||
<Icons name="window-close" size={32} color={Colors.text} />
|
<Icons name="window-close" size={32} color={Colors.text} />
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
|
|
||||||
{ state.url && (
|
{ state.url && (
|
||||||
<Video ref={player} source={{ uri: state.url }} repeat={true}
|
<Video ref={player} source={{ uri: state.url }} repeat={true}
|
||||||
paused={!state.playing} onLoad={actions.loaded} style={styles.player} />
|
paused={!state.playing} onLoad={actions.loaded} style={styles.player} />
|
||||||
|
@ -25,14 +25,23 @@ export const styles = StyleSheet.create({
|
|||||||
paddingRight: 48,
|
paddingRight: 48,
|
||||||
color: Colors.text,
|
color: Colors.text,
|
||||||
},
|
},
|
||||||
close: {
|
share: {
|
||||||
position: 'absolute',
|
|
||||||
top: 0,
|
|
||||||
right: 0,
|
|
||||||
paddingTop: 4,
|
paddingTop: 4,
|
||||||
paddingBottom: 4,
|
paddingBottom: 4,
|
||||||
paddingLeft: 8,
|
paddingLeft: 8,
|
||||||
paddingRight: 8,
|
paddingRight: 8,
|
||||||
|
position: 'absolute',
|
||||||
|
top: 0,
|
||||||
|
left: 0,
|
||||||
|
},
|
||||||
|
close: {
|
||||||
|
paddingTop: 4,
|
||||||
|
paddingBottom: 4,
|
||||||
|
paddingLeft: 8,
|
||||||
|
paddingRight: 8,
|
||||||
|
position: 'absolute',
|
||||||
|
top: 0,
|
||||||
|
right: 0,
|
||||||
},
|
},
|
||||||
player: {
|
player: {
|
||||||
display: 'none',
|
display: 'none',
|
||||||
|
@ -2,6 +2,7 @@ import { useState, useRef, useEffect, useContext } from 'react';
|
|||||||
import { ConversationContext } from 'context/ConversationContext';
|
import { ConversationContext } from 'context/ConversationContext';
|
||||||
import { Image } from 'react-native';
|
import { Image } from 'react-native';
|
||||||
import { useWindowDimensions } from 'react-native';
|
import { useWindowDimensions } from 'react-native';
|
||||||
|
import Share from 'react-native-share';
|
||||||
|
|
||||||
export function useAudioAsset(asset) {
|
export function useAudioAsset(asset) {
|
||||||
|
|
||||||
@ -47,6 +48,9 @@ export function useAudioAsset(asset) {
|
|||||||
}, [asset]);
|
}, [asset]);
|
||||||
|
|
||||||
const actions = {
|
const actions = {
|
||||||
|
download: () => {
|
||||||
|
Share.open({ url: state.url });
|
||||||
|
},
|
||||||
play: () => {
|
play: () => {
|
||||||
updateState({ playing: true });
|
updateState({ playing: true });
|
||||||
},
|
},
|
||||||
|
@ -4,6 +4,7 @@ import { styles } from './ImageAsset.styled';
|
|||||||
import Colors from 'constants/Colors';
|
import Colors from 'constants/Colors';
|
||||||
import Ionicons from 'react-native-vector-icons/AntDesign';
|
import Ionicons from 'react-native-vector-icons/AntDesign';
|
||||||
import FastImage from 'react-native-fast-image'
|
import FastImage from 'react-native-fast-image'
|
||||||
|
import MatIcons from 'react-native-vector-icons/MaterialCommunityIcons';
|
||||||
|
|
||||||
export function ImageAsset({ asset, dismiss }) {
|
export function ImageAsset({ asset, dismiss }) {
|
||||||
const { state, actions } = useImageAsset(asset);
|
const { state, actions } = useImageAsset(asset);
|
||||||
@ -19,6 +20,11 @@ export function ImageAsset({ asset, dismiss }) {
|
|||||||
resizeMode={FastImage.resizeMode.contain} />
|
resizeMode={FastImage.resizeMode.contain} />
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{ state.loaded && state.controls && (
|
||||||
|
<TouchableOpacity style={styles.share} onPress={actions.download}>
|
||||||
|
<MatIcons name="share-variant-outline" size={32} color={Colors.white} />
|
||||||
|
</TouchableOpacity>
|
||||||
|
)}
|
||||||
{ state.loaded && state.controls && (
|
{ state.loaded && state.controls && (
|
||||||
<TouchableOpacity style={styles.close} onPress={dismiss}>
|
<TouchableOpacity style={styles.close} onPress={dismiss}>
|
||||||
<Ionicons name={'close'} size={32} color={Colors.white} />
|
<Ionicons name={'close'} size={32} color={Colors.white} />
|
||||||
|
@ -41,15 +41,25 @@ export const styles = StyleSheet.create({
|
|||||||
top: 0,
|
top: 0,
|
||||||
left: 0,
|
left: 0,
|
||||||
},
|
},
|
||||||
|
share: {
|
||||||
|
position: 'absolute',
|
||||||
|
opacity: 0.9,
|
||||||
|
top: 0,
|
||||||
|
left: 0,
|
||||||
|
margin: 16,
|
||||||
|
padding: 4,
|
||||||
|
borderRadius: 4,
|
||||||
|
backgroundColor: Colors.grey,
|
||||||
|
},
|
||||||
close: {
|
close: {
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
opacity: 0.9,
|
opacity: 0.9,
|
||||||
top: 0,
|
top: 0,
|
||||||
right: 0,
|
right: 0,
|
||||||
|
margin: 16,
|
||||||
|
padding: 4,
|
||||||
borderRadius: 4,
|
borderRadius: 4,
|
||||||
backgroundColor: Colors.grey,
|
backgroundColor: Colors.grey,
|
||||||
padding: 4,
|
}
|
||||||
margin: 16,
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ import { useState, useRef, useEffect, useContext } from 'react';
|
|||||||
import { ConversationContext } from 'context/ConversationContext';
|
import { ConversationContext } from 'context/ConversationContext';
|
||||||
import { Image } from 'react-native';
|
import { Image } from 'react-native';
|
||||||
import { useWindowDimensions } from 'react-native';
|
import { useWindowDimensions } from 'react-native';
|
||||||
|
import Share from 'react-native-share';
|
||||||
|
|
||||||
export function useImageAsset(asset) {
|
export function useImageAsset(asset) {
|
||||||
|
|
||||||
@ -67,11 +68,13 @@ export function useImageAsset(asset) {
|
|||||||
const { width, height } = e.nativeEvent;
|
const { width, height } = e.nativeEvent;
|
||||||
updateState({ imageRatio: width / height });
|
updateState({ imageRatio: width / height });
|
||||||
},
|
},
|
||||||
|
download: () => {
|
||||||
|
Share.open({ url: state.url })
|
||||||
|
},
|
||||||
loaded: () => {
|
loaded: () => {
|
||||||
updateState({ loaded: true });
|
updateState({ loaded: true });
|
||||||
},
|
},
|
||||||
failed: (e) => {
|
failed: (e) => {
|
||||||
console.log("FAILEE!!!", e);
|
|
||||||
updateState({ failed: true });
|
updateState({ failed: true });
|
||||||
},
|
},
|
||||||
showControls: () => {
|
showControls: () => {
|
||||||
|
@ -302,6 +302,12 @@ export function useTopicItem(item, hosting, remove, contentKey) {
|
|||||||
return <Text>{ clickable }</Text>;
|
return <Text>{ clickable }</Text>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getExtension = async (path, type) => {
|
||||||
|
if (type === 'video') {
|
||||||
|
return 'mp4';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const actions = {
|
const actions = {
|
||||||
showCarousel: async (index) => {
|
showCarousel: async (index) => {
|
||||||
const assets = state.assets.map((asset) => ({ ...asset, error: false, decrypted: null }));
|
const assets = state.assets.map((asset) => ({ ...asset, error: false, decrypted: null }));
|
||||||
@ -340,7 +346,20 @@ export function useTopicItem(item, hosting, remove, contentKey) {
|
|||||||
updateState({ assets: [ ...assets ]});
|
updateState({ assets: [ ...assets ]});
|
||||||
};
|
};
|
||||||
|
|
||||||
asset.decrypted = path;
|
if (asset.type === 'image') {
|
||||||
|
const prefix = await RNFS.read(path, 64, 0, "base64");
|
||||||
|
const ext = prefix.startsWith('R0lGODlh') ? '.gif' : '.jpg';
|
||||||
|
const exists = await RNFS.exists(path + ext);
|
||||||
|
if (exists) {
|
||||||
|
RNFS.unlink(path + ext);
|
||||||
|
}
|
||||||
|
await RNFS.moveFile(path, path + ext);
|
||||||
|
asset.decrypted = path + ext;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
asset.decrypted = path;
|
||||||
|
}
|
||||||
|
|
||||||
assets[cur] = { ...asset };
|
assets[cur] = { ...asset };
|
||||||
updateState({ assets: [ ...assets ]});
|
updateState({ assets: [ ...assets ]});
|
||||||
};
|
};
|
||||||
@ -397,6 +416,7 @@ export function useTopicItem(item, hosting, remove, contentKey) {
|
|||||||
const src = blob.path();
|
const src = blob.path();
|
||||||
const dir = src.split('/').slice(0,-1).join('/')
|
const dir = src.split('/').slice(0,-1).join('/')
|
||||||
const dst = dir + '/' + asset + '.' + getExtension(type);
|
const dst = dir + '/' + asset + '.' + getExtension(type);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await fs.unlink(dst);
|
await fs.unlink(dst);
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,7 @@ import Icons from 'react-native-vector-icons/MaterialCommunityIcons';
|
|||||||
import { useKeepAwake } from '@sayem314/react-native-keep-awake';
|
import { useKeepAwake } from '@sayem314/react-native-keep-awake';
|
||||||
import FastImage from 'react-native-fast-image'
|
import FastImage from 'react-native-fast-image'
|
||||||
import { SafeAreaView } from 'react-native-safe-area-context';
|
import { SafeAreaView } from 'react-native-safe-area-context';
|
||||||
|
import MatIcons from 'react-native-vector-icons/MaterialCommunityIcons';
|
||||||
import { useEffect } from 'react';
|
|
||||||
|
|
||||||
export function VideoAsset({ asset, dismiss }) {
|
export function VideoAsset({ asset, dismiss }) {
|
||||||
|
|
||||||
@ -38,9 +37,14 @@ export function VideoAsset({ asset, dismiss }) {
|
|||||||
<Icons name="pause-circle-outline" size={92} color={Colors.white} />
|
<Icons name="pause-circle-outline" size={92} color={Colors.white} />
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
)}
|
)}
|
||||||
|
{ (state.controls || !state.playing) && state.videoLoaded && (
|
||||||
|
<TouchableOpacity style={styles.share} onPress={actions.download}>
|
||||||
|
<MatIcons name="share-variant-outline" size={32} color={Colors.white} />
|
||||||
|
</TouchableOpacity>
|
||||||
|
)}
|
||||||
{ (state.controls || !state.playing) && state.videoLoaded && (
|
{ (state.controls || !state.playing) && state.videoLoaded && (
|
||||||
<TouchableOpacity style={styles.close} onPress={dismiss}>
|
<TouchableOpacity style={styles.close} onPress={dismiss}>
|
||||||
<Icons name="window-close" size={32} color={Colors.white} />
|
<Icons name="window-close" size={32} color={Colors.white} />
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
)}
|
)}
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
|
@ -47,6 +47,13 @@ export const styles = StyleSheet.create({
|
|||||||
paddingRight: 16,
|
paddingRight: 16,
|
||||||
paddingTop: 16,
|
paddingTop: 16,
|
||||||
},
|
},
|
||||||
|
share: {
|
||||||
|
position: 'absolute',
|
||||||
|
top: 0,
|
||||||
|
left: 0,
|
||||||
|
paddingLeft: 16,
|
||||||
|
paddingTop: 16,
|
||||||
|
},
|
||||||
loading: {
|
loading: {
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
|
@ -2,6 +2,7 @@ import { useState, useRef, useEffect, useContext } from 'react';
|
|||||||
import { ConversationContext } from 'context/ConversationContext';
|
import { ConversationContext } from 'context/ConversationContext';
|
||||||
import { Image } from 'react-native';
|
import { Image } from 'react-native';
|
||||||
import { useWindowDimensions } from 'react-native';
|
import { useWindowDimensions } from 'react-native';
|
||||||
|
import Share from 'react-native-share';
|
||||||
|
|
||||||
export function useVideoAsset(asset) {
|
export function useVideoAsset(asset) {
|
||||||
|
|
||||||
@ -71,6 +72,9 @@ export function useVideoAsset(asset) {
|
|||||||
}, [asset]);
|
}, [asset]);
|
||||||
|
|
||||||
const actions = {
|
const actions = {
|
||||||
|
download: () => {
|
||||||
|
Share.open({ url: state.url });
|
||||||
|
},
|
||||||
setThumbSize: (e) => {
|
setThumbSize: (e) => {
|
||||||
const { width, height } = e.nativeEvent || {};
|
const { width, height } = e.nativeEvent || {};
|
||||||
updateState({ thumbLoaded: true, thumbRatio: width / height });
|
updateState({ thumbLoaded: true, thumbRatio: width / height });
|
||||||
|
Loading…
Reference in New Issue
Block a user