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.3KB

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