|
@@ -7,10 +7,12 @@ import WebSectionList from "../../components/WebSectionList";
|
7
|
7
|
import NotificationsManager from "../../utils/NotificationsManager";
|
8
|
8
|
import AsyncStorageManager from "../../utils/AsyncStorageManager";
|
9
|
9
|
import * as Expo from "expo";
|
10
|
|
-import {Card, Banner, Avatar} from 'react-native-paper';
|
|
10
|
+import {Avatar, Banner, Button, Card, Text} from 'react-native-paper';
|
11
|
11
|
import HeaderButton from "../../components/HeaderButton";
|
12
|
12
|
import ProxiwashListItem from "../../components/ProxiwashListItem";
|
13
|
13
|
import ProxiwashConstants from "../../constants/ProxiwashConstants";
|
|
14
|
+import {Modalize} from "react-native-modalize";
|
|
15
|
+import ThemeManager from "../../utils/ThemeManager";
|
14
|
16
|
|
15
|
17
|
const DATA_URL = "https://etud.insa-toulouse.fr/~amicale_app/washinsa/washinsa.json";
|
16
|
18
|
|
|
@@ -27,6 +29,7 @@ type Props = {
|
27
|
29
|
type State = {
|
28
|
30
|
refreshing: boolean,
|
29
|
31
|
firstLoading: boolean,
|
|
32
|
+ modalCurrentDisplayItem: React.Node,
|
30
|
33
|
machinesWatched: Array<string>,
|
31
|
34
|
bannerVisible: boolean,
|
32
|
35
|
};
|
|
@@ -38,6 +41,8 @@ type State = {
|
38
|
41
|
*/
|
39
|
42
|
export default class ProxiwashScreen extends React.Component<Props, State> {
|
40
|
43
|
|
|
44
|
+ modalRef: { current: null | Modalize };
|
|
45
|
+
|
41
|
46
|
onAboutPress: Function;
|
42
|
47
|
getRenderItem: Function;
|
43
|
48
|
getRenderSectionHeader: Function;
|
|
@@ -52,6 +57,7 @@ export default class ProxiwashScreen extends React.Component<Props, State> {
|
52
|
57
|
fetchedData: {},
|
53
|
58
|
// machinesWatched: JSON.parse(dataString),
|
54
|
59
|
machinesWatched: [],
|
|
60
|
+ modalCurrentDisplayItem: null,
|
55
|
61
|
bannerVisible: AsyncStorageManager.getInstance().preferences.proxiwashShowBanner.current === '1',
|
56
|
62
|
};
|
57
|
63
|
|
|
@@ -60,6 +66,7 @@ export default class ProxiwashScreen extends React.Component<Props, State> {
|
60
|
66
|
*/
|
61
|
67
|
constructor() {
|
62
|
68
|
super();
|
|
69
|
+ this.modalRef = React.createRef();
|
63
|
70
|
stateStrings[ProxiwashConstants.machineStates.TERMINE] = i18n.t('proxiwashScreen.states.finished');
|
64
|
71
|
stateStrings[ProxiwashConstants.machineStates.DISPONIBLE] = i18n.t('proxiwashScreen.states.ready');
|
65
|
72
|
stateStrings[ProxiwashConstants.machineStates["EN COURS"]] = i18n.t('proxiwashScreen.states.running');
|
|
@@ -238,29 +245,40 @@ export default class ProxiwashScreen extends React.Component<Props, State> {
|
238
|
245
|
];
|
239
|
246
|
}
|
240
|
247
|
|
241
|
|
- /**
|
242
|
|
- * Show an alert fo a machine, allowing to enable/disable notifications if running
|
243
|
|
- *
|
244
|
|
- * @param title
|
245
|
|
- * @param item
|
246
|
|
- * @param isDryer
|
247
|
|
- */
|
248
|
|
- showAlert(title: string, item: Object, isDryer: boolean) {
|
249
|
|
- let buttons = [{text: i18n.t("proxiwashScreen.modal.ok")}];
|
|
248
|
+ showModal(title: string, item: Object, isDryer: boolean) {
|
|
249
|
+ this.setState({
|
|
250
|
+ modalCurrentDisplayItem: this.getModalContent(title, item, isDryer)
|
|
251
|
+ });
|
|
252
|
+ if (this.modalRef.current) {
|
|
253
|
+ this.modalRef.current.open();
|
|
254
|
+ }
|
|
255
|
+ }
|
|
256
|
+
|
|
257
|
+ onSetupNotificationsPress(machineId: string) {
|
|
258
|
+ if (this.modalRef.current) {
|
|
259
|
+ this.modalRef.current.close();
|
|
260
|
+ }
|
|
261
|
+ this.setupNotifications(machineId)
|
|
262
|
+ }
|
|
263
|
+
|
|
264
|
+ getModalContent(title: string, item: Object, isDryer: boolean) {
|
|
265
|
+ let button = {
|
|
266
|
+ text: i18n.t("proxiwashScreen.modal.ok"),
|
|
267
|
+ icon: '',
|
|
268
|
+ onPress: undefined
|
|
269
|
+ };
|
250
|
270
|
let message = modalStateStrings[ProxiwashConstants.machineStates[item.state]];
|
251
|
|
- const onPress = this.setupNotifications.bind(this, item.number);
|
|
271
|
+ const onPress = this.onSetupNotificationsPress.bind(this, item.number);
|
252
|
272
|
if (ProxiwashConstants.machineStates[item.state] === ProxiwashConstants.machineStates["EN COURS"]) {
|
253
|
|
- buttons = [
|
|
273
|
+ button =
|
254
|
274
|
{
|
255
|
275
|
text: this.isMachineWatched(item.number) ?
|
256
|
276
|
i18n.t("proxiwashScreen.modal.disableNotifications") :
|
257
|
277
|
i18n.t("proxiwashScreen.modal.enableNotifications"),
|
|
278
|
+ icon: '',
|
258
|
279
|
onPress: onPress
|
259
|
|
- },
|
260
|
|
- {
|
261
|
|
- text: i18n.t("proxiwashScreen.modal.cancel")
|
262
|
280
|
}
|
263
|
|
- ];
|
|
281
|
+ ;
|
264
|
282
|
message = i18n.t('proxiwashScreen.modal.running',
|
265
|
283
|
{
|
266
|
284
|
start: item.startTime,
|
|
@@ -273,13 +291,39 @@ export default class ProxiwashScreen extends React.Component<Props, State> {
|
273
|
291
|
else
|
274
|
292
|
message += '\n' + i18n.t('proxiwashScreen.washersTariff');
|
275
|
293
|
}
|
276
|
|
- Alert.alert(
|
277
|
|
- title,
|
278
|
|
- message,
|
279
|
|
- buttons
|
|
294
|
+ return (
|
|
295
|
+ <View style={{
|
|
296
|
+ flex: 1,
|
|
297
|
+ padding: 20
|
|
298
|
+ }}>
|
|
299
|
+ <Card.Title
|
|
300
|
+ title={title}
|
|
301
|
+ left={() => <Avatar.Icon
|
|
302
|
+ icon={isDryer ? 'tumble-dryer' : 'washing-machine'}
|
|
303
|
+ color={ThemeManager.getCurrentThemeVariables().text}
|
|
304
|
+ style={{backgroundColor: 'transparent'}}/>}
|
|
305
|
+
|
|
306
|
+ />
|
|
307
|
+ <Card.Content>
|
|
308
|
+ <Text>{message}</Text>
|
|
309
|
+ </Card.Content>
|
|
310
|
+
|
|
311
|
+ {button.onPress !== undefined ?
|
|
312
|
+ <Card.Actions>
|
|
313
|
+ <Button
|
|
314
|
+ icon={button.icon}
|
|
315
|
+ mode="contained"
|
|
316
|
+ onPress={button.onPress}
|
|
317
|
+ style={{marginLeft: 'auto', marginRight: 'auto'}}
|
|
318
|
+ >
|
|
319
|
+ {button.text}
|
|
320
|
+ </Button>
|
|
321
|
+ </Card.Actions> : null}
|
|
322
|
+ </View>
|
280
|
323
|
);
|
281
|
324
|
}
|
282
|
325
|
|
|
326
|
+
|
283
|
327
|
onAboutPress() {
|
284
|
328
|
this.props.navigation.navigate('ProxiwashAboutScreen');
|
285
|
329
|
}
|
|
@@ -305,10 +349,18 @@ export default class ProxiwashScreen extends React.Component<Props, State> {
|
305
|
349
|
icon={() => <Avatar.Icon
|
306
|
350
|
icon={'information'}
|
307
|
351
|
size={40}
|
308
|
|
- />}
|
|
352
|
+ />}
|
309
|
353
|
>
|
310
|
354
|
{i18n.t('proxiwashScreen.enableNotificationsTip')}
|
311
|
355
|
</Banner>
|
|
356
|
+ <Modalize ref={this.modalRef}
|
|
357
|
+ adjustToContentHeight
|
|
358
|
+ handlePosition={'inside'}
|
|
359
|
+ modalStyle={{backgroundColor: ThemeManager.getCurrentThemeVariables().surface}}
|
|
360
|
+ handleStyle={{backgroundColor: ThemeManager.getCurrentThemeVariables().text}}
|
|
361
|
+ >
|
|
362
|
+ {this.state.modalCurrentDisplayItem}
|
|
363
|
+ </Modalize>
|
312
|
364
|
<WebSectionList
|
313
|
365
|
createDataset={this.createDataset}
|
314
|
366
|
navigation={nav}
|
|
@@ -374,7 +426,7 @@ export default class ProxiwashScreen extends React.Component<Props, State> {
|
374
|
426
|
const isMachineRunning = ProxiwashConstants.machineStates[item.state] === ProxiwashConstants.machineStates["EN COURS"];
|
375
|
427
|
const machineName = (section.title === i18n.t('proxiwashScreen.dryers') ? i18n.t('proxiwashScreen.dryer') : i18n.t('proxiwashScreen.washer')) + ' n°' + item.number;
|
376
|
428
|
const isDryer = section.title === i18n.t('proxiwashScreen.dryers');
|
377
|
|
- const onPress = this.showAlert.bind(this, machineName, item, isDryer);
|
|
429
|
+ const onPress = this.showModal.bind(this, machineName, item, isDryer);
|
378
|
430
|
let width = item.donePercent !== '' ? (parseInt(item.donePercent)).toString() + '%' : 0;
|
379
|
431
|
if (ProxiwashConstants.machineStates[item.state] === '0')
|
380
|
432
|
width = '100%';
|