forked from vergnet/application-amicale
Fixed crash on nightmode change, sync reminder notification with server
This commit is contained in:
parent
75ab575322
commit
f228ed0cee
4 changed files with 38 additions and 4 deletions
2
App.js
2
App.js
|
@ -85,7 +85,7 @@ export default class App extends React.Component<Props, State> {
|
||||||
if (this.state.isLoading) {
|
if (this.state.isLoading) {
|
||||||
return (
|
return (
|
||||||
<AppLoading
|
<AppLoading
|
||||||
startAsync={this.loadAssetsAsync}
|
startAsync={() => this.loadAssetsAsync()}
|
||||||
onFinish={() => this.onLoadFinished()}
|
onFinish={() => this.onLoadFinished()}
|
||||||
onError={console.warn}
|
onError={console.warn}
|
||||||
/>
|
/>
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 76 KiB After Width: | Height: | Size: 79 KiB |
|
@ -23,6 +23,7 @@ import CustomMaterialIcon from "../components/CustomMaterialIcon";
|
||||||
import AsyncStorageManager from "../utils/AsyncStorageManager";
|
import AsyncStorageManager from "../utils/AsyncStorageManager";
|
||||||
import Touchable from "react-native-platform-touchable";
|
import Touchable from "react-native-platform-touchable";
|
||||||
import {Platform} from "react-native";
|
import {Platform} from "react-native";
|
||||||
|
import NotificationsManager from "../utils/NotificationsManager";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
navigation: Object,
|
navigation: Object,
|
||||||
|
@ -53,6 +54,10 @@ export default class SettingsScreen extends React.Component<Props, State> {
|
||||||
this.setState({
|
this.setState({
|
||||||
proxiwashNotifPickerSelected: value
|
proxiwashNotifPickerSelected: value
|
||||||
});
|
});
|
||||||
|
let intVal = 0;
|
||||||
|
if (value !== 'never')
|
||||||
|
intVal = parseInt(value);
|
||||||
|
NotificationsManager.setMachineReminderNotificationTime(intVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -70,9 +75,6 @@ export default class SettingsScreen extends React.Component<Props, State> {
|
||||||
onValueChange={(value) => this.onProxiwashNotifPickerValueChange(value)}
|
onValueChange={(value) => this.onProxiwashNotifPickerValueChange(value)}
|
||||||
>
|
>
|
||||||
<Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.never')} value="never"/>
|
<Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.never')} value="never"/>
|
||||||
<Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.1')} value="1"/>
|
|
||||||
<Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.2')} value="2"/>
|
|
||||||
<Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.3')} value="3"/>
|
|
||||||
<Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.5')} value="5"/>
|
<Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.5')} value="5"/>
|
||||||
<Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.10')} value="10"/>
|
<Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.10')} value="10"/>
|
||||||
<Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.20')} value="20"/>
|
<Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.20')} value="20"/>
|
||||||
|
|
|
@ -159,4 +159,36 @@ export default class NotificationsManager {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send the selected reminder time for notifications to the server
|
||||||
|
* @param time
|
||||||
|
*/
|
||||||
|
static setMachineReminderNotificationTime(time: number) {
|
||||||
|
console.log(time);
|
||||||
|
let token = AsyncStorageManager.getInstance().preferences.expoToken.current;
|
||||||
|
if (token === '') {
|
||||||
|
throw Error('Expo token not available');
|
||||||
|
}
|
||||||
|
let data = {
|
||||||
|
function: 'set_machine_reminder',
|
||||||
|
token: token,
|
||||||
|
time: time,
|
||||||
|
};
|
||||||
|
fetch(EXPO_TOKEN_SERVER, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: new Headers({
|
||||||
|
Accept: 'application/json',
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
}),
|
||||||
|
body: JSON.stringify(data) // <-- Post parameters
|
||||||
|
})
|
||||||
|
.then((response) => response.text())
|
||||||
|
.then((responseText) => {
|
||||||
|
console.log(responseText);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.log(error);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue