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.

AboutScreen.js 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. // @flow
  2. import * as React from 'react';
  3. import {FlatList, Linking, Platform, View} from 'react-native';
  4. import {Body, Button, Card, CardItem, Container, H1, Left, Right, Text, Thumbnail} from 'native-base';
  5. import CustomHeader from "../../components/CustomHeader";
  6. import i18n from "i18n-js";
  7. import appJson from '../../app';
  8. import packageJson from '../../package';
  9. import CustomMaterialIcon from "../../components/CustomMaterialIcon";
  10. import AsyncStorageManager from "../../utils/AsyncStorageManager";
  11. import {Modalize} from "react-native-modalize";
  12. import ThemeManager from "../../utils/ThemeManager";
  13. const links = {
  14. appstore: 'https://apps.apple.com/us/app/campus-amicale-insat/id1477722148',
  15. playstore: 'https://play.google.com/store/apps/details?id=fr.amicaleinsat.application',
  16. git: 'https://git.etud.insa-toulouse.fr/vergnet/application-amicale/src/branch/master/README.md',
  17. bugsMail: 'mailto:vergnet@etud.insa-toulouse.fr?' +
  18. 'subject=' +
  19. '[BUG] Application Amicale INSA Toulouse' +
  20. '&body=' +
  21. 'Coucou Arnaud ça bug c\'est nul,\n\n' +
  22. 'Informations sur ton système si tu sais (iOS ou Android, modèle du tel, version):\n\n\n' +
  23. 'Nature du problème :\n\n\n' +
  24. 'Étapes pour reproduire ce pb :\n\n\n\n' +
  25. 'Stp corrige le pb, bien cordialement.',
  26. bugsGit: 'https://git.etud.insa-toulouse.fr/vergnet/application-amicale/issues',
  27. changelog: 'https://git.etud.insa-toulouse.fr/vergnet/application-amicale/src/branch/master/Changelog.md',
  28. license: 'https://git.etud.insa-toulouse.fr/vergnet/application-amicale/src/branch/master/LICENSE',
  29. authorMail: "mailto:vergnet@etud.insa-toulouse.fr?" +
  30. "subject=" +
  31. "Application Amicale INSA Toulouse" +
  32. "&body=" +
  33. "Coucou !\n\n",
  34. authorLinkedin: 'https://www.linkedin.com/in/arnaud-vergnet-434ba5179/',
  35. yohanMail: "mailto:ysimard@etud.insa-toulouse.fr?" +
  36. "subject=" +
  37. "Application Amicale INSA Toulouse" +
  38. "&body=" +
  39. "Coucou !\n\n",
  40. yohanLinkedin: 'https://www.linkedin.com/in/yohan-simard',
  41. react: 'https://facebook.github.io/react-native/',
  42. };
  43. type Props = {
  44. navigation: Object,
  45. };
  46. type State = {
  47. isDebugUnlocked: boolean,
  48. };
  49. /**
  50. * Opens a link in the device's browser
  51. * @param link The link to open
  52. */
  53. function openWebLink(link) {
  54. Linking.openURL(link).catch((err) => console.error('Error opening link', err));
  55. }
  56. /**
  57. * Class defining an about screen. This screen shows the user information about the app and it's author.
  58. */
  59. export default class AboutScreen extends React.Component<Props, State> {
  60. debugTapCounter = 0;
  61. modalRef: { current: null | Modalize };
  62. state = {
  63. isDebugUnlocked: AsyncStorageManager.getInstance().preferences.debugUnlocked.current === '1'
  64. };
  65. /**
  66. * Data to be displayed in the app card
  67. */
  68. appData: Array<Object> = [
  69. {
  70. onPressCallback: () => openWebLink(Platform.OS === "ios" ? links.appstore : links.playstore),
  71. icon: Platform.OS === "ios" ? 'apple' : 'google-play',
  72. text: Platform.OS === "ios" ? i18n.t('aboutScreen.appstore') : i18n.t('aboutScreen.playstore'),
  73. showChevron: true
  74. },
  75. {
  76. onPressCallback: () => this.openBugReportModal(),
  77. icon: 'bug',
  78. text: i18n.t('aboutScreen.bugs'),
  79. showChevron: true
  80. },
  81. {
  82. onPressCallback: () => openWebLink(links.git),
  83. icon: 'git',
  84. text: 'Git',
  85. showChevron: true
  86. },
  87. {
  88. onPressCallback: () => openWebLink(links.changelog),
  89. icon: 'refresh',
  90. text: i18n.t('aboutScreen.changelog'),
  91. showChevron: true
  92. },
  93. {
  94. onPressCallback: () => openWebLink(links.license),
  95. icon: 'file-document',
  96. text: i18n.t('aboutScreen.license'),
  97. showChevron: true
  98. },
  99. {
  100. onPressCallback: () => this.props.navigation.navigate('DebugScreen'),
  101. icon: 'bug-check',
  102. text: i18n.t('aboutScreen.debug'),
  103. showChevron: true,
  104. showOnlyDebug: true
  105. },
  106. ];
  107. /**
  108. * Data to be displayed in the author card
  109. */
  110. authorData: Array<Object> = [
  111. {
  112. onPressCallback: () => this.tryUnlockDebugMode(),
  113. icon: 'account-circle',
  114. text: 'Arnaud VERGNET',
  115. showChevron: false
  116. },
  117. {
  118. onPressCallback: () => openWebLink(links.authorMail),
  119. icon: 'email',
  120. text: i18n.t('aboutScreen.authorMail'),
  121. showChevron: true
  122. },
  123. {
  124. onPressCallback: () => openWebLink(links.authorLinkedin),
  125. icon: 'linkedin',
  126. text: 'Linkedin',
  127. showChevron: true
  128. },
  129. ];
  130. /**
  131. * Data to be displayed in the additional developer card
  132. */
  133. additionalDevData: Array<Object> = [
  134. {
  135. onPressCallback: () => console.log('Meme this'),
  136. icon: 'account',
  137. text: 'Yohan SIMARD',
  138. showChevron: false
  139. },
  140. {
  141. onPressCallback: () => openWebLink(links.yohanMail),
  142. icon: 'email',
  143. text: i18n.t('aboutScreen.authorMail'),
  144. showChevron: true
  145. },
  146. {
  147. onPressCallback: () => openWebLink(links.yohanLinkedin),
  148. icon: 'linkedin',
  149. text: 'Linkedin',
  150. showChevron: true
  151. },
  152. ];
  153. /**
  154. * Data to be displayed in the technologies card
  155. */
  156. technoData: Array<Object> = [
  157. {
  158. onPressCallback: () => openWebLink(links.react),
  159. icon: 'react',
  160. text: i18n.t('aboutScreen.reactNative'),
  161. showChevron: true
  162. },
  163. {
  164. onPressCallback: () => this.props.navigation.navigate('AboutDependenciesScreen', {data: packageJson.dependencies}),
  165. icon: 'developer-board',
  166. text: i18n.t('aboutScreen.libs'),
  167. showChevron: true
  168. },
  169. ];
  170. dataOrder: Array<Object> = [
  171. {
  172. id: 'app',
  173. },
  174. {
  175. id: 'team',
  176. },
  177. {
  178. id: 'techno',
  179. },
  180. ];
  181. getCardItem: Function;
  182. getMainCard: Function;
  183. constructor(props: any) {
  184. super(props);
  185. this.modalRef = React.createRef();
  186. this.getCardItem = this.getCardItem.bind(this);
  187. this.getMainCard = this.getMainCard.bind(this);
  188. }
  189. getAppCard() {
  190. return (
  191. <Card>
  192. <CardItem>
  193. <Left>
  194. <Thumbnail square source={require('../../assets/android.icon.png')}/>
  195. <Body>
  196. <H1>{appJson.expo.name}</H1>
  197. <Text note>
  198. v.{appJson.expo.version}
  199. </Text>
  200. </Body>
  201. </Left>
  202. </CardItem>
  203. <FlatList
  204. data={this.appData}
  205. extraData={this.state}
  206. keyExtractor={(item) => item.icon}
  207. listKey={"app"}
  208. renderItem={this.getCardItem}
  209. />
  210. </Card>
  211. );
  212. }
  213. getTeamCard() {
  214. return (
  215. <Card>
  216. <CardItem>
  217. <Left>
  218. <CustomMaterialIcon
  219. icon={'account-multiple'}
  220. fontSize={40}
  221. width={40}
  222. color={ThemeManager.getCurrentThemeVariables().brandPrimary}/>
  223. <Body>
  224. <H1>{i18n.t('aboutScreen.team')}</H1>
  225. </Body>
  226. </Left>
  227. </CardItem>
  228. <CardItem header>
  229. <Text>{i18n.t('aboutScreen.author')}</Text>
  230. </CardItem>
  231. <FlatList
  232. data={this.authorData}
  233. extraData={this.state}
  234. keyExtractor={(item) => item.icon}
  235. listKey={"team1"}
  236. renderItem={this.getCardItem}
  237. />
  238. <CardItem header>
  239. <Text>{i18n.t('aboutScreen.additionalDev')}</Text>
  240. </CardItem>
  241. <FlatList
  242. data={this.additionalDevData}
  243. extraData={this.state}
  244. keyExtractor={(item) => item.icon}
  245. listKey={"team2"}
  246. renderItem={this.getCardItem}
  247. />
  248. </Card>
  249. );
  250. }
  251. getTechnoCard() {
  252. return (
  253. <Card>
  254. <CardItem header>
  255. <Text>{i18n.t('aboutScreen.technologies')}</Text>
  256. </CardItem>
  257. <FlatList
  258. data={this.technoData}
  259. extraData={this.state}
  260. keyExtractor={(item) => item.icon}
  261. listKey={"techno"}
  262. renderItem={this.getCardItem}
  263. />
  264. </Card>
  265. );
  266. }
  267. /**
  268. * Get a clickable card item to be rendered inside a card.
  269. *
  270. * @returns {React.Node}
  271. */
  272. getCardItem({item}: Object) {
  273. let shouldShow = !item.showOnlyInDebug || (item.showOnlyInDebug && this.state.isDebugUnlocked);
  274. if (shouldShow) {
  275. return (
  276. <CardItem button
  277. onPress={item.onPressCallback}>
  278. <Left>
  279. <CustomMaterialIcon icon={item.icon}/>
  280. <Text>{item.text}</Text>
  281. </Left>
  282. {item.showChevron ?
  283. <Right>
  284. <CustomMaterialIcon icon="chevron-right"
  285. fontSize={20}/>
  286. </Right>
  287. :
  288. <Right/>
  289. }
  290. </CardItem>)
  291. ;
  292. } else {
  293. return <View/>
  294. }
  295. }
  296. tryUnlockDebugMode() {
  297. this.debugTapCounter = this.debugTapCounter + 1;
  298. if (this.debugTapCounter >= 4) {
  299. this.unlockDebugMode();
  300. }
  301. }
  302. unlockDebugMode() {
  303. this.setState({isDebugUnlocked: true});
  304. let key = AsyncStorageManager.getInstance().preferences.debugUnlocked.key;
  305. AsyncStorageManager.getInstance().savePref(key, '1');
  306. }
  307. getBugReportModal() {
  308. const onPressMail = openWebLink.bind(this, links.bugsMail);
  309. const onPressGit = openWebLink.bind(this, links.bugsGit);
  310. return (
  311. <Modalize ref={this.modalRef}
  312. adjustToContentHeight
  313. modalStyle={{backgroundColor: ThemeManager.getCurrentThemeVariables().containerBgColor}}>
  314. <View style={{
  315. flex: 1,
  316. padding: 20
  317. }}>
  318. <H1>{i18n.t('aboutScreen.bugs')}</H1>
  319. <Text>
  320. {i18n.t('aboutScreen.bugsDescription')}
  321. </Text>
  322. <Button
  323. style={{
  324. marginTop: 20,
  325. marginLeft: 'auto',
  326. marginRight: 'auto',
  327. }}
  328. onPress={onPressMail}>
  329. <CustomMaterialIcon
  330. icon={'email'}
  331. color={'#fff'}/>
  332. <Text>{i18n.t('aboutScreen.bugsMail')}</Text>
  333. </Button>
  334. <Button
  335. style={{
  336. marginTop: 20,
  337. marginLeft: 'auto',
  338. marginRight: 'auto',
  339. }}
  340. onPress={onPressGit}>
  341. <CustomMaterialIcon
  342. icon={'git'}
  343. color={'#fff'}/>
  344. <Text>{i18n.t('aboutScreen.bugsGit')}</Text>
  345. </Button>
  346. </View>
  347. </Modalize>
  348. );
  349. }
  350. openBugReportModal() {
  351. if (this.modalRef.current) {
  352. this.modalRef.current.open();
  353. }
  354. }
  355. getMainCard({item}: Object) {
  356. switch (item.id) {
  357. case 'app':
  358. return this.getAppCard();
  359. case 'team':
  360. return this.getTeamCard();
  361. case 'techno':
  362. return this.getTechnoCard();
  363. }
  364. return <View/>;
  365. }
  366. render() {
  367. const nav = this.props.navigation;
  368. return (
  369. <Container>
  370. {this.getBugReportModal()}
  371. <CustomHeader navigation={nav} title={i18n.t('screens.about')} hasBackButton={true}/>
  372. <FlatList
  373. style={{padding: 5}}
  374. data={this.dataOrder}
  375. extraData={this.state}
  376. keyExtractor={(item) => item.id}
  377. renderItem={this.getMainCard}
  378. />
  379. </Container>
  380. );
  381. }
  382. }