Application Android et IOS pour l'amicale des élèves
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

HomeScreen.js 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // @flow
  2. import * as React from 'react';
  3. import {Image, Linking, TouchableOpacity, View} from 'react-native';
  4. import {Body, Button, Card, CardItem, Left, Text, Thumbnail} from 'native-base';
  5. import i18n from "i18n-js";
  6. import CustomMaterialIcon from '../components/CustomMaterialIcon';
  7. import FetchedDataSectionList from "../components/FetchedDataSectionList";
  8. import Autolink from 'react-native-autolink';
  9. import ThemeManager from "../utils/ThemeManager";
  10. const ICON_AMICALE = require('../assets/amicale.png');
  11. const NAME_AMICALE = 'Amicale INSA Toulouse';
  12. const DATA_URL = "https://srv-falcon.etud.insa-toulouse.fr/~amicale_app/facebook/facebook_data.json";
  13. /**
  14. * Opens a link in the device's browser
  15. * @param link The link to open
  16. */
  17. function openWebLink(link) {
  18. Linking.openURL(link).catch((err) => console.error('Error opening link', err));
  19. }
  20. /**
  21. * Class defining the app's home screen
  22. */
  23. export default class HomeScreen extends FetchedDataSectionList {
  24. constructor() {
  25. super(DATA_URL, 0);
  26. }
  27. getHeaderTranslation() {
  28. return i18n.t("screens.home");
  29. }
  30. getUpdateToastTranslations() {
  31. return [i18n.t("homeScreen.listUpdated"), i18n.t("homeScreen.listUpdateFail")];
  32. }
  33. getKeyExtractor(item: Object) {
  34. return item !== undefined ? item.id : undefined;
  35. }
  36. createDataset(fetchedData: Object) {
  37. let data = [];
  38. if (fetchedData.data !== undefined)
  39. data = fetchedData.data;
  40. return [
  41. {
  42. title: '',
  43. data: data,
  44. extraData: super.state,
  45. keyExtractor: this.getKeyExtractor
  46. }
  47. ];
  48. }
  49. /**
  50. * Converts a dateString using Unix Timestamp to a formatted date
  51. * @param dateString {string} The Unix Timestamp representation of a date
  52. * @return {string} The formatted output date
  53. */
  54. static getFormattedDate(dateString: string) {
  55. let date = new Date(Number.parseInt(dateString) * 1000);
  56. return date.toLocaleString();
  57. }
  58. getRenderItem(item: Object, section: Object, data: Object) {
  59. return (
  60. <Card style={{
  61. flex: 0,
  62. marginLeft: 10,
  63. marginRight: 10
  64. }}>
  65. <CardItem>
  66. <Left>
  67. <Thumbnail source={ICON_AMICALE} square/>
  68. <Body>
  69. <Text>{NAME_AMICALE}</Text>
  70. <Text note>{HomeScreen.getFormattedDate(item.created_time)}</Text>
  71. </Body>
  72. </Left>
  73. </CardItem>
  74. <CardItem>
  75. <Body>
  76. {item.full_picture !== '' && item.full_picture !== undefined ?
  77. <TouchableOpacity onPress={() => openWebLink(item.full_picture)}
  78. style={{width: '100%', height: 250}}>
  79. <Image source={{uri: item.full_picture}}
  80. style={{flex: 1, resizeMode: "contain"}}
  81. resizeMode="contain"
  82. />
  83. </TouchableOpacity>
  84. : <View/>}
  85. {item.message !== undefined ?
  86. <Autolink
  87. text={item.message}
  88. hashtag="facebook"
  89. style={{color: ThemeManager.getCurrentThemeVariables().textColor}}
  90. /> : <View/>
  91. }
  92. </Body>
  93. </CardItem>
  94. <CardItem>
  95. <Left>
  96. <Button transparent
  97. onPress={() => openWebLink(item.permalink_url)}>
  98. <CustomMaterialIcon
  99. icon="facebook"
  100. color="#57aeff"
  101. width={20}/>
  102. <Text>En savoir plus</Text>
  103. </Button>
  104. </Left>
  105. </CardItem>
  106. </Card>
  107. );
  108. }
  109. }