2019-06-29 13:37:21 +02:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import * as React from 'react';
|
2019-07-30 13:59:28 +02:00
|
|
|
import {Image, Linking, TouchableOpacity, View} from 'react-native';
|
2019-10-09 19:58:22 +02:00
|
|
|
import {Body, Button, Card, CardItem, Left, Text, Thumbnail, H1, H3} 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-30 13:59:28 +02:00
|
|
|
import Autolink from 'react-native-autolink';
|
2019-08-05 14:52:18 +02:00
|
|
|
import ThemeManager from "../utils/ThemeManager";
|
2019-11-07 11:46:01 +01:00
|
|
|
import DashboardItem from "../components/DashboardItem";
|
2019-11-07 17:58:02 +01:00
|
|
|
// import DATA from "../dashboard_data.json";
|
2019-10-08 19:16:42 +02:00
|
|
|
|
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-10-06 10:54:01 +02:00
|
|
|
const DATA_URL = "https://srv-falcon.etud.insa-toulouse.fr/~amicale_app/dashboard/dashboard_data.json";
|
|
|
|
|
|
|
|
const SECTIONS_ID = [
|
|
|
|
'dashboard',
|
|
|
|
'news_feed'
|
|
|
|
];
|
2019-07-28 12:40:35 +02:00
|
|
|
|
2019-10-16 16:57:37 +02:00
|
|
|
const REFRESH_TIME = 1000 * 20; // Refresh every 20 seconds
|
2019-10-09 19:58:22 +02:00
|
|
|
|
2019-11-01 06:55:37 +01:00
|
|
|
const CARD_BORDER_RADIUS = 10;
|
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-30 20:40:17 +02:00
|
|
|
constructor() {
|
2019-11-07 17:58:02 +01:00
|
|
|
super(DATA_URL, REFRESH_TIME);
|
2019-07-30 20:40:17 +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-31 14:34:38 +02:00
|
|
|
getUpdateToastTranslations() {
|
|
|
|
return [i18n.t("homeScreen.listUpdated"), i18n.t("homeScreen.listUpdateFail")];
|
2019-07-25 17:52:16 +02:00
|
|
|
}
|
|
|
|
|
2019-07-30 13:59:28 +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-30 13:59:28 +02:00
|
|
|
createDataset(fetchedData: Object) {
|
2019-11-07 17:58:02 +01:00
|
|
|
// fetchedData = DATA;
|
2019-10-06 10:54:01 +02:00
|
|
|
let newsData = [];
|
|
|
|
let dashboardData = [];
|
|
|
|
if (fetchedData['news_feed'] !== undefined)
|
|
|
|
newsData = fetchedData['news_feed']['data'];
|
|
|
|
if (fetchedData['dashboard'] !== undefined)
|
|
|
|
dashboardData = this.generateDashboardDataset(fetchedData['dashboard']);
|
2019-07-26 14:14:01 +02:00
|
|
|
return [
|
|
|
|
{
|
|
|
|
title: '',
|
2019-10-06 10:54:01 +02:00
|
|
|
data: dashboardData,
|
|
|
|
extraData: super.state,
|
|
|
|
keyExtractor: this.getKeyExtractor,
|
|
|
|
id: SECTIONS_ID[0]
|
|
|
|
},
|
|
|
|
{
|
2019-10-06 12:30:29 +02:00
|
|
|
title: i18n.t('homeScreen.newsFeed'),
|
2019-10-06 10:54:01 +02:00
|
|
|
data: newsData,
|
2019-07-31 14:22:36 +02:00
|
|
|
extraData: super.state,
|
2019-10-06 10:54:01 +02:00
|
|
|
keyExtractor: this.getKeyExtractor,
|
|
|
|
id: SECTIONS_ID[1]
|
2019-07-25 17:52:16 +02:00
|
|
|
}
|
2019-07-26 14:14:01 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2019-10-06 10:54:01 +02:00
|
|
|
generateDashboardDataset(dashboardData: Object) {
|
2019-10-08 19:16:42 +02:00
|
|
|
let dataset = [
|
|
|
|
{
|
2019-11-07 17:36:20 +01:00
|
|
|
id: 'event',
|
2019-10-09 19:58:22 +02:00
|
|
|
content: undefined
|
2019-10-08 19:16:42 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'middle',
|
|
|
|
content: [{}, {}]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'bottom',
|
2019-11-07 17:36:20 +01:00
|
|
|
content: [{}, {}]
|
2019-10-08 19:16:42 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
];
|
2019-10-06 10:54:01 +02:00
|
|
|
for (let [key, value] of Object.entries(dashboardData)) {
|
2019-10-08 19:16:42 +02:00
|
|
|
switch (key) {
|
|
|
|
case 'today_events':
|
|
|
|
dataset[0]['content'] = value;
|
|
|
|
break;
|
2019-11-07 17:36:20 +01:00
|
|
|
case 'available_machines':
|
2019-10-08 19:16:42 +02:00
|
|
|
dataset[1]['content'][0] = {id: key, data: value};
|
|
|
|
break;
|
2019-11-07 17:36:20 +01:00
|
|
|
case 'available_tutorials':
|
2019-10-08 19:16:42 +02:00
|
|
|
dataset[1]['content'][1] = {id: key, data: value};
|
|
|
|
break;
|
2019-11-07 17:36:20 +01:00
|
|
|
case 'proximo_articles':
|
|
|
|
dataset[2]['content'][0] = {id: key, data: value};
|
2019-10-08 19:16:42 +02:00
|
|
|
break;
|
2019-11-07 17:36:20 +01:00
|
|
|
case 'today_menu':
|
|
|
|
dataset[2]['content'][1] = {id: key, data: value};
|
|
|
|
break;
|
|
|
|
|
2019-10-08 19:16:42 +02:00
|
|
|
}
|
2019-10-06 10:54:01 +02:00
|
|
|
}
|
|
|
|
return dataset
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-26 14:14:01 +02:00
|
|
|
/**
|
|
|
|
* 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-10-06 10:54:01 +02:00
|
|
|
getRenderSectionHeader(title: string) {
|
|
|
|
if (title === '') {
|
|
|
|
return <View/>;
|
|
|
|
} else {
|
|
|
|
return (
|
|
|
|
<View style={{
|
|
|
|
backgroundColor: ThemeManager.getCurrentThemeVariables().containerBgColor
|
|
|
|
}}>
|
|
|
|
<H1 style={{
|
|
|
|
marginLeft: 'auto',
|
|
|
|
marginRight: 'auto',
|
|
|
|
marginTop: 10,
|
|
|
|
marginBottom: 10
|
|
|
|
}}>{title}</H1>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-08 19:16:42 +02:00
|
|
|
getDashboardItem(item: Object) {
|
|
|
|
let content = item['content'];
|
2019-11-07 17:36:20 +01:00
|
|
|
if (item['id'] === 'event')
|
2019-11-07 11:46:01 +01:00
|
|
|
return this.getDashboardEventItem(content);
|
2019-10-08 19:16:42 +02:00
|
|
|
else if (item['id'] === 'middle')
|
|
|
|
return this.getDashboardMiddleItem(content);
|
|
|
|
else
|
2019-11-07 17:36:20 +01:00
|
|
|
return this.getDashboardBottomItem(content);
|
2019-10-08 19:16:42 +02:00
|
|
|
}
|
|
|
|
|
2019-10-09 19:58:22 +02:00
|
|
|
/**
|
|
|
|
* Convert the date string given by in the event list json to a date object
|
|
|
|
* @param dateString
|
|
|
|
* @return {Date}
|
|
|
|
*/
|
|
|
|
stringToDate(dateString: ?string): ?Date {
|
|
|
|
let date = new Date();
|
|
|
|
if (dateString === undefined || dateString === null)
|
|
|
|
date = undefined;
|
|
|
|
else if (dateString.split(' ').length > 1) {
|
|
|
|
let timeStr = dateString.split(' ')[1];
|
|
|
|
date.setHours(parseInt(timeStr.split(':')[0]), parseInt(timeStr.split(':')[1]), 0);
|
|
|
|
} else
|
|
|
|
date = undefined;
|
|
|
|
return date;
|
|
|
|
}
|
2019-10-08 19:16:42 +02:00
|
|
|
|
2019-10-09 19:58:22 +02:00
|
|
|
/**
|
|
|
|
* Get the time limit depending on the current day:
|
|
|
|
* 17:30 for every day of the week except for thursday 11:30
|
|
|
|
* 00:00 on weekends
|
|
|
|
*/
|
|
|
|
getTodayEventTimeLimit() {
|
|
|
|
let now = new Date();
|
|
|
|
if (now.getDay() === 4) // Thursday
|
|
|
|
now.setHours(11, 30, 0);
|
|
|
|
else if (now.getDay() === 6 || now.getDay() === 0) // Weekend
|
|
|
|
now.setHours(0, 0, 0);
|
|
|
|
else
|
|
|
|
now.setHours(17, 30, 0);
|
|
|
|
return now;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the duration (in milliseconds) of an event
|
|
|
|
* @param event {Object}
|
|
|
|
* @return {number} The number of milliseconds
|
|
|
|
*/
|
|
|
|
getEventDuration(event: Object): number {
|
|
|
|
let start = this.stringToDate(event['date_begin']);
|
|
|
|
let end = this.stringToDate(event['date_end']);
|
|
|
|
let duration = 0;
|
|
|
|
if (start !== undefined && start !== null && end !== undefined && end !== null)
|
|
|
|
duration = end - start;
|
|
|
|
return duration;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get events starting after the limit
|
|
|
|
*
|
|
|
|
* @param events
|
|
|
|
* @param limit
|
|
|
|
* @return {Array<Object>}
|
|
|
|
*/
|
|
|
|
getEventsAfterLimit(events: Object, limit: Date): Array<Object> {
|
|
|
|
let validEvents = [];
|
|
|
|
for (let event of events) {
|
|
|
|
let startDate = this.stringToDate(event['date_begin']);
|
|
|
|
if (startDate !== undefined && startDate !== null && startDate >= limit) {
|
|
|
|
validEvents.push(event);
|
2019-10-08 19:16:42 +02:00
|
|
|
}
|
|
|
|
}
|
2019-10-09 19:58:22 +02:00
|
|
|
return validEvents;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the event with the longest duration in the given array.
|
|
|
|
* If all events have the same duration, return the first in the array.
|
|
|
|
* @param events
|
|
|
|
*/
|
|
|
|
getLongestEvent(events: Array<Object>): Object {
|
|
|
|
let longestEvent = events[0];
|
|
|
|
let longestTime = 0;
|
|
|
|
for (let event of events) {
|
|
|
|
let time = this.getEventDuration(event);
|
|
|
|
if (time > longestTime) {
|
|
|
|
longestTime = time;
|
|
|
|
longestEvent = event;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return longestEvent;
|
2019-10-08 19:16:42 +02:00
|
|
|
}
|
|
|
|
|
2019-10-09 19:58:22 +02:00
|
|
|
/**
|
|
|
|
* Get events that have not yet ended/started
|
|
|
|
*
|
|
|
|
* @param events
|
|
|
|
*/
|
|
|
|
getFutureEvents(events: Array<Object>): Array<Object> {
|
|
|
|
let validEvents = [];
|
|
|
|
let now = new Date();
|
|
|
|
for (let event of events) {
|
|
|
|
let startDate = this.stringToDate(event['date_begin']);
|
|
|
|
let endDate = this.stringToDate(event['date_end']);
|
|
|
|
if (startDate !== undefined && startDate !== null) {
|
|
|
|
if (startDate > now)
|
|
|
|
validEvents.push(event);
|
|
|
|
else if (endDate !== undefined && endDate !== null) {
|
2019-10-09 20:03:33 +02:00
|
|
|
if (endDate > now || endDate < startDate) // Display event if it ends the following day
|
2019-10-09 19:58:22 +02:00
|
|
|
validEvents.push(event);
|
|
|
|
}
|
|
|
|
}
|
2019-10-06 10:54:01 +02:00
|
|
|
}
|
2019-10-09 19:58:22 +02:00
|
|
|
return validEvents;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param events
|
|
|
|
* @return {Object}
|
|
|
|
*/
|
|
|
|
getDisplayEvent(events: Array<Object>): Object {
|
|
|
|
let displayEvent = undefined;
|
|
|
|
if (events.length > 1) {
|
|
|
|
let eventsAfterLimit = this.getEventsAfterLimit(events, this.getTodayEventTimeLimit());
|
|
|
|
if (eventsAfterLimit.length > 0) {
|
|
|
|
if (eventsAfterLimit.length === 1)
|
|
|
|
displayEvent = eventsAfterLimit[0];
|
|
|
|
else
|
|
|
|
displayEvent = this.getLongestEvent(events);
|
|
|
|
} else {
|
|
|
|
displayEvent = this.getLongestEvent(events);
|
|
|
|
}
|
|
|
|
} else if (events.length === 1) {
|
|
|
|
displayEvent = events[0];
|
2019-10-06 10:54:01 +02:00
|
|
|
}
|
2019-10-09 19:58:22 +02:00
|
|
|
return displayEvent;
|
|
|
|
}
|
|
|
|
|
2019-10-06 10:54:01 +02:00
|
|
|
|
2019-11-07 11:46:01 +01:00
|
|
|
getDashboardEventItem(content: Array<Object>) {
|
2019-10-08 19:16:42 +02:00
|
|
|
let icon = 'calendar-range';
|
|
|
|
let color = ThemeManager.getCurrentThemeVariables().planningColor;
|
|
|
|
let title = i18n.t('homeScreen.dashboard.todayEventsTitle');
|
|
|
|
let subtitle = '';
|
2019-10-09 19:58:22 +02:00
|
|
|
let futureEvents = this.getFutureEvents(content);
|
2019-11-01 06:49:57 +01:00
|
|
|
let isAvailable = futureEvents.length > 0;
|
2019-10-08 19:16:42 +02:00
|
|
|
if (isAvailable) {
|
|
|
|
subtitle =
|
|
|
|
<Text>
|
2019-10-09 19:58:22 +02:00
|
|
|
<Text style={{fontWeight: "bold"}}>{futureEvents.length}</Text>
|
|
|
|
<Text>
|
|
|
|
{
|
|
|
|
futureEvents.length > 1 ?
|
|
|
|
i18n.t('homeScreen.dashboard.todayEventsSubtitlePlural') :
|
|
|
|
i18n.t('homeScreen.dashboard.todayEventsSubtitle')
|
|
|
|
}
|
|
|
|
</Text>
|
2019-10-08 19:16:42 +02:00
|
|
|
</Text>;
|
|
|
|
} else
|
|
|
|
subtitle = i18n.t('homeScreen.dashboard.todayEventsSubtitleNA');
|
|
|
|
let clickAction = () => this.props.navigation.navigate('Planning');
|
|
|
|
|
2019-10-09 19:58:22 +02:00
|
|
|
let displayEvent = this.getDisplayEvent(futureEvents);
|
2019-10-08 19:16:42 +02:00
|
|
|
|
|
|
|
return (
|
2019-11-07 11:46:01 +01:00
|
|
|
<DashboardItem
|
|
|
|
subtitle={subtitle}
|
|
|
|
color={color}
|
|
|
|
icon={icon}
|
|
|
|
clickAction={() => clickAction()}
|
|
|
|
title={title}
|
|
|
|
isAvailable={isAvailable}
|
|
|
|
displayEvent={displayEvent}
|
|
|
|
/>
|
2019-10-08 19:16:42 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-11-07 17:36:20 +01:00
|
|
|
getDashboardBottomItem(content: Array<Object>) {
|
2019-10-08 19:16:42 +02:00
|
|
|
let proximoData = content[0]['data'];
|
|
|
|
let menuData = content[1]['data'];
|
|
|
|
let proximoIcon = 'shopping';
|
|
|
|
let proximoColor = ThemeManager.getCurrentThemeVariables().proximoColor;
|
|
|
|
let proximoTitle = i18n.t('homeScreen.dashboard.proximoTitle');
|
|
|
|
let isProximoAvailable = parseInt(proximoData) > 0;
|
|
|
|
let proximoSubtitle = '';
|
|
|
|
if (isProximoAvailable) {
|
|
|
|
proximoSubtitle =
|
|
|
|
<Text>
|
|
|
|
<Text style={{fontWeight: "bold"}}>{proximoData}</Text>
|
2019-10-09 19:58:22 +02:00
|
|
|
<Text>
|
|
|
|
{
|
|
|
|
proximoData > 1 ?
|
2019-11-07 11:46:01 +01:00
|
|
|
i18n.t('homeScreen.dashboard.proximoSubtitlePlural') :
|
|
|
|
i18n.t('homeScreen.dashboard.proximoSubtitle')
|
2019-10-09 19:58:22 +02:00
|
|
|
}
|
|
|
|
</Text>
|
2019-10-08 19:16:42 +02:00
|
|
|
</Text>;
|
|
|
|
} else
|
|
|
|
proximoSubtitle = i18n.t('homeScreen.dashboard.proximoSubtitleNA');
|
|
|
|
let proximoClickAction = () => this.props.navigation.navigate('Proximo');
|
|
|
|
|
|
|
|
|
|
|
|
let menuIcon = 'silverware-fork-knife';
|
|
|
|
let menuColor = ThemeManager.getCurrentThemeVariables().menuColor;
|
|
|
|
let menuTitle = i18n.t('homeScreen.dashboard.menuTitle');
|
|
|
|
let isMenuAvailable = menuData.length > 0;
|
|
|
|
let menuSubtitle = '';
|
|
|
|
if (isMenuAvailable) {
|
|
|
|
menuSubtitle = i18n.t('homeScreen.dashboard.menuSubtitle');
|
|
|
|
} else
|
|
|
|
menuSubtitle = i18n.t('homeScreen.dashboard.menuSubtitleNA');
|
|
|
|
let menuClickAction = () => this.props.navigation.navigate('SelfMenuScreen');
|
|
|
|
return (
|
|
|
|
<View style={{
|
|
|
|
flexDirection: 'row',
|
|
|
|
marginLeft: 10,
|
|
|
|
marginRight: 10,
|
|
|
|
}}>
|
2019-11-07 11:46:01 +01:00
|
|
|
<DashboardItem
|
|
|
|
isSquare={true}
|
|
|
|
subtitle={menuSubtitle}
|
|
|
|
color={menuColor}
|
|
|
|
icon={menuIcon}
|
|
|
|
clickAction={() => menuClickAction()}
|
|
|
|
title={menuTitle}
|
2019-11-07 17:36:20 +01:00
|
|
|
isAvailable={isMenuAvailable}
|
|
|
|
isSquareLeft={true}/>
|
|
|
|
<DashboardItem
|
|
|
|
isSquare={true}
|
|
|
|
subtitle={proximoSubtitle}
|
|
|
|
color={proximoColor}
|
|
|
|
icon={proximoIcon}
|
|
|
|
clickAction={() => proximoClickAction()}
|
|
|
|
title={proximoTitle}
|
|
|
|
isAvailable={isProximoAvailable}/>
|
2019-10-08 19:16:42 +02:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-11-07 17:36:20 +01:00
|
|
|
getDashboardMiddleItem(content: Array<Object>) {
|
|
|
|
let proxiwashData = content[0]['data'];
|
|
|
|
let tutorinsaData = content[1]['data'];
|
2019-10-08 19:16:42 +02:00
|
|
|
|
2019-11-07 17:36:20 +01:00
|
|
|
let proxiwashIcon = 'washing-machine';
|
|
|
|
let proxiwashColor = ThemeManager.getCurrentThemeVariables().proxiwashColor;
|
|
|
|
let proxiwashTitle = i18n.t('homeScreen.dashboard.proxiwashTitle');
|
|
|
|
let proxiwashIsAvailable = parseInt(proxiwashData['dryers']) > 0 || parseInt(proxiwashData['washers']) > 0;
|
|
|
|
let proxiwashSubtitle;
|
|
|
|
let dryerColor = parseInt(proxiwashData['dryers']) > 0 ?
|
2019-10-09 19:58:22 +02:00
|
|
|
ThemeManager.getCurrentThemeVariables().textColor :
|
|
|
|
ThemeManager.getCurrentThemeVariables().listNoteColor;
|
2019-11-07 17:36:20 +01:00
|
|
|
let washerColor = parseInt(proxiwashData['washers']) > 0 ?
|
2019-10-09 19:58:22 +02:00
|
|
|
ThemeManager.getCurrentThemeVariables().textColor :
|
|
|
|
ThemeManager.getCurrentThemeVariables().listNoteColor;
|
2019-11-07 17:36:20 +01:00
|
|
|
let availableDryers = proxiwashData['dryers'];
|
|
|
|
let availableWashers = proxiwashData['washers'];
|
|
|
|
if (proxiwashIsAvailable) {
|
|
|
|
proxiwashSubtitle =
|
2019-10-09 19:58:22 +02:00
|
|
|
<Text>
|
2019-11-07 17:36:20 +01:00
|
|
|
<Text style={{
|
|
|
|
fontWeight: parseInt(proxiwashData['dryers']) > 0 ?
|
|
|
|
'bold' :
|
|
|
|
'normal',
|
|
|
|
color: dryerColor
|
|
|
|
}}>
|
|
|
|
{availableDryers}
|
|
|
|
</Text>
|
|
|
|
<Text>
|
|
|
|
{
|
|
|
|
availableDryers > 1 ?
|
|
|
|
i18n.t('homeScreen.dashboard.proxiwashSubtitle1Plural') :
|
|
|
|
i18n.t('homeScreen.dashboard.proxiwashSubtitle1')
|
|
|
|
}
|
|
|
|
</Text>
|
|
|
|
{"\n"}
|
|
|
|
<Text style={{
|
|
|
|
fontWeight: parseInt(proxiwashData['washers']) > 0 ?
|
|
|
|
'bold' :
|
|
|
|
'normal',
|
|
|
|
color: washerColor
|
|
|
|
}}>
|
|
|
|
{availableWashers}
|
|
|
|
</Text>
|
|
|
|
<Text>
|
|
|
|
{
|
|
|
|
availableWashers > 1 ?
|
|
|
|
i18n.t('homeScreen.dashboard.proxiwashSubtitle2Plural') :
|
|
|
|
i18n.t('homeScreen.dashboard.proxiwashSubtitle2')
|
|
|
|
}
|
|
|
|
</Text>
|
|
|
|
</Text>;
|
|
|
|
} else
|
|
|
|
proxiwashSubtitle = i18n.t('homeScreen.dashboard.proxiwashSubtitleNA');
|
|
|
|
let proxiwashClickAction = () => this.props.navigation.navigate('Proxiwash');
|
|
|
|
|
|
|
|
let tutorinsaIcon = 'school';
|
|
|
|
let tutorinsaColor = ThemeManager.getCurrentThemeVariables().tutorinsaColor;
|
|
|
|
let tutorinsaTitle = 'Tutor\'INSA';
|
|
|
|
let tutorinsaIsAvailable = tutorinsaData > 0;
|
|
|
|
let tutorinsaSubtitle;
|
|
|
|
if (tutorinsaIsAvailable) {
|
|
|
|
tutorinsaSubtitle =
|
|
|
|
<Text>
|
|
|
|
<Text style={{fontWeight: "bold"}}>{tutorinsaData}</Text>
|
2019-10-09 19:58:22 +02:00
|
|
|
<Text>
|
|
|
|
{
|
2019-11-07 17:36:20 +01:00
|
|
|
tutorinsaData > 1 ?
|
|
|
|
i18n.t('homeScreen.dashboard.tutorinsaSubtitlePlural') :
|
|
|
|
i18n.t('homeScreen.dashboard.tutorinsaSubtitle')
|
2019-10-09 19:58:22 +02:00
|
|
|
}
|
2019-10-08 19:16:42 +02:00
|
|
|
</Text>
|
|
|
|
</Text>;
|
|
|
|
} else
|
2019-11-07 17:36:20 +01:00
|
|
|
tutorinsaSubtitle = i18n.t('homeScreen.dashboard.tutorinsaSubtitleNA');
|
|
|
|
let tutorinsaClickAction = () => this.props.navigation.navigate('TutorInsaScreen');
|
|
|
|
|
2019-10-08 19:16:42 +02:00
|
|
|
return (
|
2019-11-07 17:36:20 +01:00
|
|
|
<View style={{
|
|
|
|
flexDirection: 'row',
|
|
|
|
marginLeft: 10,
|
|
|
|
marginRight: 10,
|
|
|
|
}}>
|
|
|
|
<DashboardItem
|
|
|
|
isSquare={true}
|
|
|
|
subtitle={proxiwashSubtitle}
|
|
|
|
color={proxiwashColor}
|
|
|
|
icon={proxiwashIcon}
|
|
|
|
clickAction={() => proxiwashClickAction()}
|
|
|
|
title={proxiwashTitle}
|
|
|
|
isAvailable={proxiwashIsAvailable}
|
|
|
|
isSquareLeft={true}/>
|
|
|
|
<DashboardItem
|
|
|
|
isSquare={true}
|
|
|
|
subtitle={tutorinsaSubtitle}
|
|
|
|
color={tutorinsaColor}
|
|
|
|
icon={tutorinsaIcon}
|
|
|
|
clickAction={() => tutorinsaClickAction()}
|
|
|
|
title={tutorinsaTitle}
|
|
|
|
isAvailable={tutorinsaIsAvailable}/>
|
|
|
|
</View>
|
2019-10-08 19:16:42 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
getRenderItem(item: Object, section: Object, data: Object) {
|
|
|
|
if (section['id'] === SECTIONS_ID[0]) {
|
|
|
|
return this.getDashboardItem(item);
|
2019-10-06 10:54:01 +02:00
|
|
|
} else {
|
|
|
|
return (
|
|
|
|
<Card style={{
|
|
|
|
flex: 0,
|
|
|
|
marginLeft: 10,
|
2019-11-01 06:55:37 +01:00
|
|
|
marginRight: 10,
|
|
|
|
borderRadius: CARD_BORDER_RADIUS,
|
2019-10-06 10:54:01 +02:00
|
|
|
}}>
|
2019-11-01 06:55:37 +01:00
|
|
|
<CardItem style={{
|
|
|
|
backgroundColor: 'transparent'
|
|
|
|
}}>
|
2019-10-06 10:54:01 +02:00
|
|
|
<Left>
|
|
|
|
<Thumbnail source={ICON_AMICALE} square/>
|
|
|
|
<Body>
|
|
|
|
<Text>{NAME_AMICALE}</Text>
|
|
|
|
<Text note>{HomeScreen.getFormattedDate(item.created_time)}</Text>
|
|
|
|
</Body>
|
|
|
|
</Left>
|
|
|
|
</CardItem>
|
2019-11-01 06:55:37 +01:00
|
|
|
<CardItem style={{
|
|
|
|
backgroundColor: 'transparent'
|
|
|
|
}}>
|
2019-07-25 17:52:16 +02:00
|
|
|
<Body>
|
2019-10-06 10:54:01 +02:00
|
|
|
{item.full_picture !== '' && item.full_picture !== undefined ?
|
|
|
|
<TouchableOpacity onPress={() => openWebLink(item.full_picture)}
|
2019-11-01 06:55:37 +01:00
|
|
|
style={{width: '100%', height: 250, marginBottom: 5}}>
|
2019-10-06 10:54:01 +02:00
|
|
|
<Image source={{uri: item.full_picture}}
|
|
|
|
style={{flex: 1, resizeMode: "contain"}}
|
|
|
|
resizeMode="contain"
|
|
|
|
/>
|
|
|
|
</TouchableOpacity>
|
|
|
|
: <View/>}
|
|
|
|
{item.message !== undefined ?
|
|
|
|
<Autolink
|
|
|
|
text={item.message}
|
|
|
|
hashtag="facebook"
|
|
|
|
style={{color: ThemeManager.getCurrentThemeVariables().textColor}}
|
|
|
|
/> : <View/>
|
|
|
|
}
|
2019-07-25 17:52:16 +02:00
|
|
|
</Body>
|
2019-10-06 10:54:01 +02:00
|
|
|
</CardItem>
|
2019-11-01 06:55:37 +01:00
|
|
|
<CardItem style={{
|
|
|
|
backgroundColor: 'transparent'
|
|
|
|
}}>
|
2019-10-06 10:54:01 +02:00
|
|
|
<Left>
|
|
|
|
<Button transparent
|
|
|
|
onPress={() => openWebLink(item.permalink_url)}>
|
|
|
|
<CustomMaterialIcon
|
|
|
|
icon="facebook"
|
|
|
|
color="#57aeff"
|
|
|
|
width={20}/>
|
|
|
|
<Text>En savoir plus</Text>
|
|
|
|
</Button>
|
|
|
|
</Left>
|
|
|
|
</CardItem>
|
|
|
|
</Card>
|
|
|
|
);
|
|
|
|
}
|
2019-07-25 17:52:16 +02:00
|
|
|
}
|
|
|
|
|
2019-06-25 22:20:24 +02:00
|
|
|
}
|