2019-06-29 13:37:21 +02:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import * as React from 'react';
|
2019-07-26 14:14:01 +02:00
|
|
|
import {Image, Linking} from 'react-native';
|
|
|
|
import {Text, Button, Card, CardItem, Left, Body, Thumbnail} from 'native-base';
|
2019-06-25 22:20:24 +02:00
|
|
|
import i18n from "i18n-js";
|
2019-07-25 17:52:16 +02:00
|
|
|
import CustomMaterialIcon from '../components/CustomMaterialIcon';
|
2019-07-26 14:14:01 +02:00
|
|
|
import FetchedDataSectionList from "../components/FetchedDataSectionList";
|
2019-07-25 17:52:16 +02:00
|
|
|
|
|
|
|
const ICON_AMICALE = require('../assets/amicale.png');
|
2019-07-26 14:14:01 +02:00
|
|
|
const NAME_AMICALE = 'Amicale INSA Toulouse';
|
2019-07-28 12:40:35 +02:00
|
|
|
const FB_URL = "https://etud.insa-toulouse.fr/~vergnet/appli-amicale/facebook_data.json";
|
|
|
|
|
2019-07-25 17:52:16 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Opens a link in the device's browser
|
|
|
|
* @param link The link to open
|
|
|
|
*/
|
|
|
|
function openWebLink(link) {
|
|
|
|
Linking.openURL(link).catch((err) => console.error('Error opening link', err));
|
|
|
|
}
|
|
|
|
|
2019-06-29 15:43:57 +02:00
|
|
|
/**
|
|
|
|
* Class defining the app's home screen
|
|
|
|
*/
|
2019-07-26 14:14:01 +02:00
|
|
|
export default class HomeScreen extends FetchedDataSectionList {
|
2019-07-25 17:52:16 +02:00
|
|
|
|
2019-07-26 14:14:01 +02:00
|
|
|
getHeaderTranslation() {
|
|
|
|
return i18n.t("screens.home");
|
|
|
|
}
|
2019-07-25 17:52:16 +02:00
|
|
|
|
2019-07-26 14:14:01 +02:00
|
|
|
getUpdateToastTranslations () {
|
|
|
|
return [i18n.t("homeScreen.listUpdated"),i18n.t("homeScreen.listUpdateFail")];
|
2019-07-25 17:52:16 +02:00
|
|
|
}
|
|
|
|
|
2019-07-26 14:14:01 +02:00
|
|
|
getKeyExtractor(item : Object) {
|
2019-07-28 12:40:35 +02:00
|
|
|
return item !== undefined ? item.id : undefined;
|
2019-07-25 17:52:16 +02:00
|
|
|
}
|
|
|
|
|
2019-07-26 14:14:01 +02:00
|
|
|
createDataset(fetchedData : Object) {
|
|
|
|
let data = [];
|
|
|
|
if (fetchedData.data !== undefined)
|
|
|
|
data = fetchedData.data;
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
title: '',
|
|
|
|
data: data,
|
|
|
|
extraData: super.state
|
2019-07-25 17:52:16 +02:00
|
|
|
}
|
2019-07-26 14:14:01 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
getFetchUrl() {
|
|
|
|
return FB_URL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts a dateString using Unix Timestamp to a formatted date
|
|
|
|
* @param dateString {string} The Unix Timestamp representation of a date
|
|
|
|
* @return {string} The formatted output date
|
|
|
|
*/
|
|
|
|
static getFormattedDate(dateString: string) {
|
|
|
|
let date = new Date(Number.parseInt(dateString) * 1000);
|
|
|
|
return date.toLocaleString();
|
|
|
|
}
|
2019-07-25 17:52:16 +02:00
|
|
|
|
2019-07-26 14:14:01 +02:00
|
|
|
getRenderItem(item: Object, section : Object, data : Object) {
|
2019-07-25 17:52:16 +02:00
|
|
|
return (
|
|
|
|
<Card style={{flex: 0}}>
|
|
|
|
<CardItem>
|
|
|
|
<Left>
|
|
|
|
<Thumbnail source={ICON_AMICALE}/>
|
|
|
|
<Body>
|
2019-07-26 14:14:01 +02:00
|
|
|
<Text>{NAME_AMICALE}</Text>
|
|
|
|
<Text note>{HomeScreen.getFormattedDate(item.created_time)}</Text>
|
2019-07-25 17:52:16 +02:00
|
|
|
</Body>
|
|
|
|
</Left>
|
|
|
|
</CardItem>
|
|
|
|
<CardItem>
|
|
|
|
<Body>
|
|
|
|
<Image source={{uri: item.full_picture}}
|
|
|
|
style={{width: '100%', height: 200, flex: 1}}/>
|
|
|
|
<Text>{item.message}</Text>
|
|
|
|
</Body>
|
|
|
|
</CardItem>
|
|
|
|
<CardItem>
|
|
|
|
<Left>
|
2019-07-25 19:26:13 +02:00
|
|
|
<Button transparent
|
2019-07-26 14:14:01 +02:00
|
|
|
onPress={() => openWebLink(item.permalink_url)}>
|
2019-07-25 17:52:16 +02:00
|
|
|
<CustomMaterialIcon
|
|
|
|
icon="facebook"
|
|
|
|
color="#57aeff"
|
|
|
|
width={20}/>
|
|
|
|
<Text>En savoir plus</Text>
|
|
|
|
</Button>
|
|
|
|
</Left>
|
|
|
|
</CardItem>
|
|
|
|
</Card>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-06-25 22:20:24 +02:00
|
|
|
}
|