2022-09-30 17:40:03 +02:00
|
|
|
import React from 'react';
|
|
|
|
|
import { View, ImageBackground, TouchableOpacity, Text, Image } from 'react-native';
|
|
|
|
|
// Common Styles
|
|
|
|
|
import commonStyles from '../../Resources/CommonStyles';
|
2022-10-06 17:20:07 +02:00
|
|
|
// Redux
|
|
|
|
|
import { connect } from 'react-redux';
|
2022-12-28 16:32:30 +01:00
|
|
|
import { initDocuments } from '../Store/Actions/documents';
|
2022-12-28 17:53:43 +01:00
|
|
|
import { initContact } from '../Store/Actions/contacts';
|
2022-12-30 16:44:51 +01:00
|
|
|
import { initDirectories } from '../Store/Actions/directories';
|
2022-09-30 17:40:03 +02:00
|
|
|
// Style
|
|
|
|
|
import styles from '../../Resources/Styles/HomeStyle';
|
|
|
|
|
// Translations
|
|
|
|
|
import i18n from "../../I18n";
|
|
|
|
|
// FileSytem
|
|
|
|
|
import * as FileSystem from 'expo-file-system';
|
2022-12-30 16:44:51 +01:00
|
|
|
// NetInfo
|
|
|
|
|
import NetInfo from '@react-native-community/netinfo';
|
|
|
|
|
// Controller
|
|
|
|
|
import SyncController from '../Controllers/SyncController';
|
2022-10-06 17:20:07 +02:00
|
|
|
|
|
|
|
|
function mapStateToProps(state) {
|
|
|
|
|
return {
|
2022-12-29 12:44:26 +01:00
|
|
|
btns: state.app.HomeBtns,
|
2022-12-28 17:53:43 +01:00
|
|
|
directories: state.directories,
|
2022-12-28 13:27:14 +01:00
|
|
|
locale: state.locale.locale,
|
2022-12-28 17:53:43 +01:00
|
|
|
currentUser: state.app.currentUser
|
2022-10-06 17:20:07 +02:00
|
|
|
};
|
|
|
|
|
}
|
2022-09-30 17:40:03 +02:00
|
|
|
|
2022-12-28 16:32:30 +01:00
|
|
|
const mapDispatchToProps = dispatch => {
|
|
|
|
|
return {
|
2022-12-29 12:44:26 +01:00
|
|
|
initBtns: () => dispatch({ type: 'INIT_HOME_BTNS' }),
|
2022-12-28 17:53:43 +01:00
|
|
|
initDocuments: (lang, directories) => dispatch(initDocuments(lang, directories)),
|
|
|
|
|
initContact: currentUser => dispatch(initContact(currentUser)),
|
2022-12-30 16:44:51 +01:00
|
|
|
initDirectories: (lang, user) => dispatch(initDirectories(lang, user)),
|
|
|
|
|
|
2022-12-28 16:32:30 +01:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2022-09-30 17:40:03 +02:00
|
|
|
class HomeScreen extends React.Component {
|
2022-10-04 17:48:38 +02:00
|
|
|
|
2022-12-30 16:44:51 +01:00
|
|
|
state = {
|
|
|
|
|
lastSyncCall: '1970-01-01',
|
|
|
|
|
};
|
|
|
|
|
|
2022-10-06 17:20:07 +02:00
|
|
|
componentDidMount() {
|
2022-12-30 16:44:51 +01:00
|
|
|
if (!SyncController.isInstalled()) {
|
|
|
|
|
return this.openSync();
|
|
|
|
|
}
|
2022-12-29 12:44:26 +01:00
|
|
|
this.props.initBtns();
|
2022-12-28 17:53:43 +01:00
|
|
|
this.props.initContact(this.props.currentUser);
|
2022-12-30 16:44:51 +01:00
|
|
|
this.props.initDirectories(this.props.locale.value, this.props.currentUser);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsubscribe() {
|
|
|
|
|
NetInfo.addEventListener(state => {
|
|
|
|
|
if (state.isConnected === true) {
|
|
|
|
|
let seconds =
|
|
|
|
|
Math.abs(new Date(this.state.lastSyncCall) - Date.now()) / 1000;
|
|
|
|
|
if (seconds > 30) {
|
|
|
|
|
this.setState({ lastSyncCall: Date.now() });
|
|
|
|
|
SyncController.needSync(this.openSync.bind(this));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
openSync() {
|
|
|
|
|
this.props.navigation.navigate('SyncScreen', { forceSync: true });
|
2022-10-06 17:20:07 +02:00
|
|
|
}
|
|
|
|
|
|
2022-09-30 17:40:03 +02:00
|
|
|
render() {
|
2022-10-06 17:20:07 +02:00
|
|
|
i18n.locale = this.props.locale;
|
2022-09-30 17:40:03 +02:00
|
|
|
return (
|
2022-12-30 10:02:07 +01:00
|
|
|
<ImageBackground source={{ uri: FileSystem.documentDirectory + 'BackgroundImage.png' }} style={commonStyles.background} resizeMode='cover'>
|
2022-09-30 17:40:03 +02:00
|
|
|
<View style={styles.container}>
|
2022-12-29 12:44:26 +01:00
|
|
|
{this.renderBtns()}
|
2022-12-30 10:02:07 +01:00
|
|
|
<TouchableOpacity
|
2023-01-02 14:47:07 +01:00
|
|
|
key={'OnlyVideos'}
|
2022-12-30 10:02:07 +01:00
|
|
|
onPress={() => {
|
|
|
|
|
this.props.initDocuments(this.props.locale, this.props.directories.global);
|
|
|
|
|
this.props.navigation.navigate('OnlyVideosScreen');
|
|
|
|
|
}}
|
|
|
|
|
style={styles.button}>
|
2022-10-06 16:25:15 +02:00
|
|
|
<Image source={{ uri: FileSystem.documentDirectory + 'HomeButtonImage.png' }} style={styles.btnImg} />
|
2022-09-30 17:40:03 +02:00
|
|
|
<Text style={styles.btnTxt}>{i18n.t('global.videos')}</Text>
|
|
|
|
|
</TouchableOpacity>
|
2023-01-02 14:47:07 +01:00
|
|
|
<TouchableOpacity key={'Contacts'} onPress={() => this.props.navigation.navigate('ContactScreen')} style={styles.button}>
|
2022-09-30 17:40:03 +02:00
|
|
|
<Image source={{ uri: FileSystem.documentDirectory + 'HomeButtonImage.png' }} style={styles.btnImg} />
|
|
|
|
|
<Text style={styles.btnTxt}>{i18n.t('global.contacts')}</Text>
|
|
|
|
|
</TouchableOpacity>
|
|
|
|
|
</View>
|
|
|
|
|
</ImageBackground>
|
|
|
|
|
);
|
|
|
|
|
}
|
2022-10-04 17:48:38 +02:00
|
|
|
|
2022-12-29 12:44:26 +01:00
|
|
|
renderBtns() {
|
|
|
|
|
let locale = this.props.locale;
|
|
|
|
|
let objBtns = this.props.btns;
|
|
|
|
|
let array = Object.keys(objBtns).map(function (key) { return objBtns[key]; });
|
|
|
|
|
return array.map((item, index) => {
|
|
|
|
|
let names = JSON.parse(item.name);
|
|
|
|
|
let name = (locale in names) ? names[locale] : names.fr;
|
|
|
|
|
return (
|
2023-01-02 14:47:07 +01:00
|
|
|
<TouchableOpacity key={index} onPress={() => this.openFolder(item.id)} style={styles.button}>
|
2022-12-29 12:44:26 +01:00
|
|
|
<Image source={{ uri: FileSystem.documentDirectory + 'HomeButtonImage.png' }} style={styles.btnImg} />
|
|
|
|
|
<Text style={styles.btnTxt}>{name}</Text>
|
|
|
|
|
</TouchableOpacity>
|
|
|
|
|
)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-04 17:48:38 +02:00
|
|
|
openFolder(id) {
|
2022-12-29 12:44:26 +01:00
|
|
|
const folder = this.props.directories.treeview.filter(tmp => tmp.id === id);
|
|
|
|
|
this.props.initDocuments(this.props.locale, this.props.directories.global);
|
2022-10-06 17:20:07 +02:00
|
|
|
this.props.navigation.navigate('DirectoriesScreen', { folder: folder });
|
2022-10-04 17:48:38 +02:00
|
|
|
}
|
2022-09-30 17:40:03 +02:00
|
|
|
}
|
|
|
|
|
|
2022-12-28 16:32:30 +01:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(HomeScreen);
|