2022-09-30 17:40:03 +02:00
|
|
|
import React from 'react';
|
2023-08-22 10:32:40 +02:00
|
|
|
import {
|
|
|
|
|
Image,
|
|
|
|
|
ImageBackground,
|
|
|
|
|
Text,
|
|
|
|
|
TouchableOpacity,
|
|
|
|
|
View,
|
|
|
|
|
} from 'react-native';
|
|
|
|
|
// Common Styles
|
2022-09-30 17:40:03 +02:00
|
|
|
import commonStyles from '../../Resources/CommonStyles';
|
2022-10-06 17:20:07 +02:00
|
|
|
// Redux
|
2023-08-22 10:32:40 +02:00
|
|
|
import {connect} from 'react-redux';
|
|
|
|
|
import {initContact} from '../Store/Actions/contacts';
|
|
|
|
|
import {initDirectories} from '../Store/Actions/directories';
|
|
|
|
|
import {initDocuments} from '../Store/Actions/documents';
|
|
|
|
|
// SplashScreen
|
2023-01-03 12:55:28 +01:00
|
|
|
import * as SplashScreen from 'expo-splash-screen';
|
2022-09-30 17:40:03 +02:00
|
|
|
// Style
|
|
|
|
|
import styles from '../../Resources/Styles/HomeStyle';
|
|
|
|
|
// Translations
|
2023-08-22 10:32:40 +02:00
|
|
|
import i18n from '../../I18n';
|
2022-09-30 17:40:03 +02:00
|
|
|
// 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) {
|
2023-08-22 10:32:40 +02:00
|
|
|
return {
|
|
|
|
|
btns: state.app.HomeBtns,
|
|
|
|
|
directories: state.directories,
|
|
|
|
|
locale: state.locale.locale,
|
|
|
|
|
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 => {
|
2023-08-22 10:32:40 +02:00
|
|
|
return {
|
|
|
|
|
initBtns: () => dispatch({type: 'INIT_HOME_BTNS'}),
|
|
|
|
|
initDocuments: (lang, directories) =>
|
|
|
|
|
dispatch(initDocuments(lang, directories)),
|
|
|
|
|
initContact: currentUser => dispatch(initContact(currentUser)),
|
|
|
|
|
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 {
|
2023-08-22 10:32:40 +02:00
|
|
|
state = {
|
|
|
|
|
lastSyncCall: '1970-01-01',
|
|
|
|
|
};
|
2022-10-04 17:48:38 +02:00
|
|
|
|
2023-08-22 10:32:40 +02:00
|
|
|
componentDidMount() {
|
|
|
|
|
if (!SyncController.isInstalled()) {
|
|
|
|
|
return this.openSync();
|
2022-12-30 16:44:51 +01:00
|
|
|
}
|
2023-08-22 10:32:40 +02:00
|
|
|
this.props.initBtns();
|
|
|
|
|
this.props.initContact(this.props.currentUser);
|
|
|
|
|
this.props.initDirectories(this.props.locale, this.props.currentUser);
|
|
|
|
|
this.props.initDocuments(this.props.locale, this.props.directories.global);
|
2022-12-30 16:44:51 +01:00
|
|
|
|
2023-08-22 10:32:40 +02:00
|
|
|
SplashScreen.hideAsync();
|
|
|
|
|
}
|
2022-12-30 16:44:51 +01:00
|
|
|
|
2023-08-22 10:32:40 +02:00
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-10-06 17:20:07 +02:00
|
|
|
|
2023-08-22 10:32:40 +02:00
|
|
|
openSync() {
|
|
|
|
|
this.props.navigation.navigate('SyncScreen', {forceSync: true});
|
|
|
|
|
}
|
2022-10-04 17:48:38 +02:00
|
|
|
|
2023-08-22 10:32:40 +02:00
|
|
|
render() {
|
|
|
|
|
i18n.locale = this.props.locale;
|
|
|
|
|
return (
|
|
|
|
|
<ImageBackground
|
|
|
|
|
source={{uri: FileSystem.documentDirectory + 'BackgroundImage.png'}}
|
|
|
|
|
style={commonStyles.background}
|
|
|
|
|
resizeMode="cover">
|
|
|
|
|
<View style={styles.container}>
|
|
|
|
|
{this.renderBtns()}
|
|
|
|
|
<TouchableOpacity
|
|
|
|
|
key={'OnlyVideos'}
|
|
|
|
|
onPress={() => {
|
|
|
|
|
this.props.initDocuments(
|
|
|
|
|
this.props.locale,
|
|
|
|
|
this.props.directories.global,
|
|
|
|
|
);
|
|
|
|
|
this.props.navigation.navigate('OnlyVideosScreen');
|
|
|
|
|
}}
|
|
|
|
|
style={styles.button}>
|
|
|
|
|
<Image
|
|
|
|
|
source={{
|
|
|
|
|
uri: FileSystem.documentDirectory + 'HomeButtonImage.png',
|
|
|
|
|
}}
|
|
|
|
|
style={styles.btnImg}
|
|
|
|
|
/>
|
|
|
|
|
<Text style={styles.btnTxt}>{i18n.t('global.videos')}</Text>
|
|
|
|
|
</TouchableOpacity>
|
|
|
|
|
<TouchableOpacity
|
|
|
|
|
key={'Contacts'}
|
|
|
|
|
onPress={() => this.props.navigation.navigate('ContactScreen')}
|
|
|
|
|
style={styles.button}>
|
|
|
|
|
<Image
|
|
|
|
|
source={{
|
|
|
|
|
uri: FileSystem.documentDirectory + 'HomeButtonImage.png',
|
|
|
|
|
}}
|
|
|
|
|
style={styles.btnImg}
|
|
|
|
|
/>
|
|
|
|
|
<Text style={styles.btnTxt}>{i18n.t('global.contacts')}</Text>
|
|
|
|
|
</TouchableOpacity>
|
|
|
|
|
</View>
|
|
|
|
|
</ImageBackground>
|
|
|
|
|
);
|
|
|
|
|
}
|
2022-12-29 12:44:26 +01:00
|
|
|
|
2023-08-22 10:32:40 +02: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 (
|
|
|
|
|
<TouchableOpacity
|
|
|
|
|
key={index}
|
|
|
|
|
onPress={() => this.openFolder(item.id)}
|
|
|
|
|
style={styles.button}>
|
|
|
|
|
<Image
|
|
|
|
|
source={{uri: FileSystem.documentDirectory + 'HomeButtonImage.png'}}
|
|
|
|
|
style={styles.btnImg}
|
|
|
|
|
/>
|
|
|
|
|
<Text style={styles.btnTxt}>{name}</Text>
|
|
|
|
|
</TouchableOpacity>
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
openFolder(id) {
|
|
|
|
|
this.props.initDocuments(this.props.locale, this.props.directories.global);
|
|
|
|
|
const folder = this.props.directories.treeview.filter(tmp => tmp.id === id);
|
|
|
|
|
this.props.navigation.navigate('DirectoriesScreen', {folder: folder});
|
|
|
|
|
}
|
2022-09-30 17:40:03 +02:00
|
|
|
}
|
|
|
|
|
|
2023-08-22 10:32:40 +02:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(HomeScreen);
|