Improved async storage usage

This commit is contained in:
Arnaud Vergnet 2020-07-23 12:03:51 +02:00
parent 2b7e6b4541
commit 6254ce1814
19 changed files with 168 additions and 164 deletions

18
App.js
View file

@ -56,7 +56,6 @@ export default class App extends React.Component<Props, State> {
createDrawerNavigator: () => React.Node;
urlHandler: URLHandler;
storageManager: AsyncStorageManager;
constructor() {
super();
@ -64,7 +63,6 @@ export default class App extends React.Component<Props, State> {
this.navigatorRef = React.createRef();
this.defaultHomeRoute = null;
this.defaultHomeData = {};
this.storageManager = AsyncStorageManager.getInstance();
this.urlHandler = new URLHandler(this.onInitialURLParsed, this.onDetectURL);
this.urlHandler.listen();
setSafeBounceHeight(Platform.OS === 'ios' ? 100 : 20);
@ -133,9 +131,9 @@ export default class App extends React.Component<Props, State> {
showUpdate: false,
showAprilFools: false,
});
this.storageManager.savePref(this.storageManager.preferences.showIntro.key, '0');
this.storageManager.savePref(this.storageManager.preferences.updateNumber.key, Update.number.toString());
this.storageManager.savePref(this.storageManager.preferences.showAprilFoolsStart.key, '0');
AsyncStorageManager.set(AsyncStorageManager.PREFERENCES.showIntro.key, false);
AsyncStorageManager.set(AsyncStorageManager.PREFERENCES.updateNumber.key, Update.number);
AsyncStorageManager.set(AsyncStorageManager.PREFERENCES.showAprilFoolsStart.key, false);
};
/**
@ -144,7 +142,7 @@ export default class App extends React.Component<Props, State> {
* @returns {Promise<void>}
*/
loadAssetsAsync = async () => {
await this.storageManager.loadPreferences();
await AsyncStorageManager.getInstance().loadPreferences();
try {
await ConnectionManager.getInstance().recoverLogin();
} catch (e) {
@ -169,9 +167,11 @@ export default class App extends React.Component<Props, State> {
this.setState({
isLoading: false,
currentTheme: ThemeManager.getCurrentTheme(),
showIntro: this.storageManager.preferences.showIntro.current === '1',
showUpdate: this.storageManager.preferences.updateNumber.current !== Update.number.toString(),
showAprilFools: AprilFoolsManager.getInstance().isAprilFoolsEnabled() && this.storageManager.preferences.showAprilFoolsStart.current === '1',
showIntro: AsyncStorageManager.getBool(AsyncStorageManager.PREFERENCES.showIntro.key),
showUpdate: AsyncStorageManager.getNumber(AsyncStorageManager.PREFERENCES.updateNumber.key)
!== Update.number,
showAprilFools: AprilFoolsManager.getInstance().isAprilFoolsEnabled()
&& AsyncStorageManager.getBool(AsyncStorageManager.PREFERENCES.showAprilFoolsStart.key),
});
SplashScreen.hide();
}

View file

@ -13,117 +13,86 @@ export default class AsyncStorageManager {
static instance: AsyncStorageManager | null = null;
/**
* Get this class instance or create one if none is found
* @returns {AsyncStorageManager}
*/
static getInstance(): AsyncStorageManager {
return AsyncStorageManager.instance === null ?
AsyncStorageManager.instance = new AsyncStorageManager() :
AsyncStorageManager.instance;
}
// Object storing preferences keys, default and current values for use in the app
preferences = {
static PREFERENCES = {
debugUnlocked: {
key: 'debugUnlocked',
default: '0',
current: '',
},
showIntro: {
key: 'showIntro',
default: '1',
current: '',
},
updateNumber: {
key: 'updateNumber',
default: '0',
current: '',
},
proxiwashNotifications: {
key: 'proxiwashNotifications',
default: '5',
current: '',
},
nightModeFollowSystem: {
key: 'nightModeFollowSystem',
default: '1',
current: '',
},
nightMode: {
key: 'nightMode',
default: '1',
current: '',
},
defaultStartScreen: {
key: 'defaultStartScreen',
default: 'home',
current: '',
},
servicesShowBanner: {
key: 'servicesShowBanner',
default: '1',
current: '',
},
proxiwashShowBanner: {
key: 'proxiwashShowBanner',
default: '1',
current: '',
},
homeShowBanner: {
key: 'homeShowBanner',
default: '1',
current: '',
},
eventsShowBanner: {
key: 'eventsShowBanner',
default: '1',
current: '',
},
planexShowBanner: {
key: 'planexShowBanner',
default: '1',
current: '',
},
loginShowBanner: {
key: 'loginShowBanner',
default: '1',
current: '',
},
voteShowBanner: {
key: 'voteShowBanner',
default: '1',
current: '',
},
equipmentShowBanner: {
key: 'equipmentShowBanner',
default: '1',
current: '',
},
gameStartShowBanner: {
key: 'gameStartShowBanner',
default: '1',
current: '',
},
proxiwashWatchedMachines: {
key: 'proxiwashWatchedMachines',
default: '[]',
current: '',
},
showAprilFoolsStart: {
key: 'showAprilFoolsStart',
default: '1',
current: '',
},
planexCurrentGroup: {
key: 'planexCurrentGroup',
default: '',
current: '',
},
planexFavoriteGroups: {
key: 'planexFavoriteGroups',
default: '[]',
current: '',
},
dashboardItems: {
key: 'dashboardItems',
@ -134,14 +103,28 @@ export default class AsyncStorageManager {
SERVICES_KEY.TUTOR_INSA,
SERVICES_KEY.RU,
]),
current: '',
},
gameScores: {
key: 'gameScores',
default: '[]',
current: '',
},
};
}
#currentPreferences: {[key: string]: string};
constructor() {
this.#currentPreferences = {};
}
/**
* Get this class instance or create one if none is found
* @returns {AsyncStorageManager}
*/
static getInstance(): AsyncStorageManager {
return AsyncStorageManager.instance === null ?
AsyncStorageManager.instance = new AsyncStorageManager() :
AsyncStorageManager.instance;
}
/**
* Set preferences object current values from AsyncStorage.
@ -152,9 +135,8 @@ export default class AsyncStorageManager {
async loadPreferences() {
let prefKeys = [];
// Get all available keys
for (let [key, value] of Object.entries(this.preferences)) {
//$FlowFixMe
prefKeys.push(value.key);
for (let key in AsyncStorageManager.PREFERENCES) {
prefKeys.push(key);
}
// Get corresponding values
let resultArray: Array<Array<string>> = await AsyncStorage.multiGet(prefKeys);
@ -163,21 +145,92 @@ export default class AsyncStorageManager {
let key: string = resultArray[i][0];
let val: string | null = resultArray[i][1];
if (val === null)
val = this.preferences[key].default;
this.preferences[key].current = val;
val = AsyncStorageManager.PREFERENCES[key].default;
this.#currentPreferences[key] = val;
}
}
/**
* Save the value associated to the given key to preferences.
* Saves the value associated to the given key to preferences.
* This updates the preferences object and saves it to AsyncStorage.
*
* @param key
* @param val
* @param value
*/
savePref(key: string, val: string) {
this.preferences[key].current = val;
AsyncStorage.setItem(key, val);
setPreference(key: string, value: any) {
if (AsyncStorageManager.PREFERENCES[key] != null) {
let convertedValue = "";
if (typeof value === "string")
convertedValue = value;
else if (typeof value === "boolean" || typeof value === "number")
convertedValue = value.toString();
else
convertedValue = JSON.stringify(value);
this.#currentPreferences[key] = convertedValue;
AsyncStorage.setItem(key, convertedValue);
}
}
/**
* Gets the value at the given key.
* If the key is not available, returns null
*
* @param key
* @returns {string|null}
*/
getPreference(key: string) {
return this.#currentPreferences[key];
}
/**
* aves the value associated to the given key to preferences.
*
* @param key
* @param value
*/
static set(key: string, value: any) {
AsyncStorageManager.getInstance().setPreference(key, value);
}
/**
* Gets the string value of the given preference
*
* @param key
* @returns {boolean}
*/
static getString(key: string) {
return AsyncStorageManager.getInstance().getPreference(key);
}
/**
* Gets the boolean value of the given preference
*
* @param key
* @returns {boolean}
*/
static getBool(key: string) {
const value = AsyncStorageManager.getString(key);
return value === "1" || value === "true";
}
/**
* Gets the number value of the given preference
*
* @param key
* @returns {boolean}
*/
static getNumber(key: string) {
return parseFloat(AsyncStorageManager.getString(key));
}
/**
* Gets the object value of the given preference
*
* @param key
* @returns {boolean}
*/
static getObject(key: string) {
return JSON.parse(AsyncStorageManager.getString(key));
}
}

View file

@ -7,14 +7,15 @@ import {getSublistWithIds} from "../utils/Utils";
import AsyncStorageManager from "./AsyncStorageManager";
export default class DashboardManager extends ServicesManager{
export default class DashboardManager extends ServicesManager {
constructor(nav: StackNavigationProp) {
super(nav)
}
getCurrentDashboard(): Array<ServiceItem> {
const dashboardIdList = JSON.parse(AsyncStorageManager.getInstance().preferences.dashboardItems.current);
const dashboardIdList = AsyncStorageManager
.getObject(AsyncStorageManager.PREFERENCES.dashboardItems.key);
const allDatasets = [
...this.amicaleDataset,
...this.studentsDataset,

View file

@ -228,10 +228,11 @@ export default class ThemeManager {
* @returns {boolean} Night mode state
*/
static getNightMode(): boolean {
return (AsyncStorageManager.getInstance().preferences.nightMode.current === '1' &&
(AsyncStorageManager.getInstance().preferences.nightModeFollowSystem.current !== '1' ||
colorScheme === 'no-preference')) ||
(AsyncStorageManager.getInstance().preferences.nightModeFollowSystem.current === '1' && colorScheme === 'dark');
return (AsyncStorageManager.getBool(AsyncStorageManager.PREFERENCES.nightMode.key) &&
(!AsyncStorageManager.getBool(AsyncStorageManager.PREFERENCES.nightModeFollowSystem.key)
|| colorScheme === 'no-preference')) ||
(AsyncStorageManager.getBool(AsyncStorageManager.PREFERENCES.nightModeFollowSystem.key)
&& colorScheme === 'dark');
}
/**
@ -273,8 +274,7 @@ export default class ThemeManager {
* @param isNightMode True to enable night mode, false to disable
*/
setNightMode(isNightMode: boolean) {
let nightModeKey = AsyncStorageManager.getInstance().preferences.nightMode.key;
AsyncStorageManager.getInstance().savePref(nightModeKey, isNightMode ? '1' : '0');
AsyncStorageManager.set(AsyncStorageManager.PREFERENCES.nightMode.key, isNightMode);
if (this.updateThemeCallback != null)
this.updateThemeCallback();
}

View file

@ -202,7 +202,7 @@ export default class TabNavigator extends React.Component<Props> {
if (props.defaultHomeRoute != null)
this.defaultRoute = 'home';
else
this.defaultRoute = AsyncStorageManager.getInstance().preferences.defaultStartScreen.current.toLowerCase();
this.defaultRoute = AsyncStorageManager.getString(AsyncStorageManager.PREFERENCES.defaultStartScreen.key).toLowerCase();
this.createHomeStackComponent = () => HomeStackComponent(props.defaultHomeRoute, props.defaultHomeData);
}

View file

@ -43,10 +43,11 @@ class DebugScreen extends React.Component<Props, State> {
constructor(props) {
super(props);
this.modalInputValue = "";
let copy = {...AsyncStorageManager.getInstance().preferences};
let currentPreferences : Array<PreferenceItem> = [];
Object.values(copy).map((object: any) => {
currentPreferences.push(object);
Object.values(AsyncStorageManager.PREFERENCES).map((object: any) => {
let newObject: PreferenceItem = {...object};
newObject.current = AsyncStorageManager.getString(newObject.key);
currentPreferences.push(newObject);
});
this.state = {
modalCurrentDisplayItem: {},
@ -139,7 +140,7 @@ class DebugScreen extends React.Component<Props, State> {
currentPreferences[this.findIndexOfKey(key)].current = value;
return {currentPreferences};
});
AsyncStorageManager.getInstance().savePref(key, value);
AsyncStorageManager.set(key, value);
this.modalRef.close();
}

View file

@ -42,7 +42,7 @@ const LIST_ITEM_HEIGHT = 64;
class EquipmentListScreen extends React.Component<Props, State> {
state = {
mascotDialogVisible: AsyncStorageManager.getInstance().preferences.equipmentShowBanner.current === "1"
mascotDialogVisible: AsyncStorageManager.getBool(AsyncStorageManager.PREFERENCES.equipmentShowBanner.key),
}
data: Array<Device>;
@ -146,10 +146,7 @@ class EquipmentListScreen extends React.Component<Props, State> {
};
hideMascotDialog = () => {
AsyncStorageManager.getInstance().savePref(
AsyncStorageManager.getInstance().preferences.equipmentShowBanner.key,
'0'
);
AsyncStorageManager.set(AsyncStorageManager.PREFERENCES.equipmentShowBanner.key, false);
this.setState({mascotDialogVisible: false})
};

View file

@ -48,7 +48,7 @@ class LoginScreen extends React.Component<Props, State> {
loading: false,
dialogVisible: false,
dialogError: 0,
mascotDialogVisible: AsyncStorageManager.getInstance().preferences.loginShowBanner.current === "1"
mascotDialogVisible: AsyncStorageManager.getBool(AsyncStorageManager.PREFERENCES.loginShowBanner.key),
};
onEmailChange: (value: string) => null;
@ -82,10 +82,7 @@ class LoginScreen extends React.Component<Props, State> {
}
hideMascotDialog = () => {
AsyncStorageManager.getInstance().savePref(
AsyncStorageManager.getInstance().preferences.loginShowBanner.key,
'0'
);
AsyncStorageManager.set(AsyncStorageManager.PREFERENCES.loginShowBanner.key, false);
this.setState({mascotDialogVisible: false})
};
@ -111,11 +108,8 @@ class LoginScreen extends React.Component<Props, State> {
* Saves in user preferences to not show the login banner again.
*/
handleSuccess = () => {
// Do not show the login banner again
AsyncStorageManager.getInstance().savePref(
AsyncStorageManager.getInstance().preferences.homeShowBanner.key,
'0'
);
// Do not show the home login banner again
AsyncStorageManager.set(AsyncStorageManager.PREFERENCES.homeShowBanner.key, false);
if (this.nextScreen == null)
this.props.navigation.goBack();
else

View file

@ -108,7 +108,7 @@ export default class VoteScreen extends React.Component<Props, State> {
state = {
hasVoted: false,
mascotDialogVisible: AsyncStorageManager.getInstance().preferences.voteShowBanner.current === "1",
mascotDialogVisible: AsyncStorageManager.getBool(AsyncStorageManager.PREFERENCES.voteShowBanner.key),
};
teams: Array<team>;
@ -326,10 +326,7 @@ export default class VoteScreen extends React.Component<Props, State> {
};
hideMascotDialog = () => {
AsyncStorageManager.getInstance().savePref(
AsyncStorageManager.getInstance().preferences.voteShowBanner.key,
'0'
);
AsyncStorageManager.set(AsyncStorageManager.PREFERENCES.voteShowBanner.key, false);
this.setState({mascotDialogVisible: false})
};

View file

@ -46,13 +46,13 @@ class GameStartScreen extends React.Component<Props, State> {
isHighScore: boolean;
state = {
mascotDialogVisible: AsyncStorageManager.getInstance().preferences.gameStartShowBanner.current === "1",
mascotDialogVisible: AsyncStorageManager.getBool(AsyncStorageManager.PREFERENCES.gameStartShowBanner.key),
}
constructor(props: Props) {
super(props);
this.gridManager = new GridManager(4, 4, props.theme);
this.scores = JSON.parse(AsyncStorageManager.getInstance().preferences.gameScores.current);
this.scores = AsyncStorageManager.getObject(AsyncStorageManager.PREFERENCES.gameScores.key);
this.scores.sort((a, b) => b - a);
if (this.props.route.params != null)
this.recoverGameScore();
@ -72,17 +72,11 @@ class GameStartScreen extends React.Component<Props, State> {
}
if (this.scores.length > 3)
this.scores.splice(3, 1);
AsyncStorageManager.getInstance().savePref(
AsyncStorageManager.getInstance().preferences.gameScores.key,
JSON.stringify(this.scores)
);
AsyncStorageManager.set(AsyncStorageManager.PREFERENCES.gameScores.key, this.scores);
}
hideMascotDialog = () => {
AsyncStorageManager.getInstance().savePref(
AsyncStorageManager.getInstance().preferences.gameStartShowBanner.key,
'0'
);
AsyncStorageManager.set(AsyncStorageManager.PREFERENCES.gameStartShowBanner.key, false);
this.setState({mascotDialogVisible: false})
};

View file

@ -112,7 +112,8 @@ class HomeScreen extends React.Component<Props, State> {
});
this.state = {
dialogVisible: false,
mascotDialogVisible: AsyncStorageManager.getInstance().preferences.homeShowBanner.current === "1"
mascotDialogVisible: AsyncStorageManager.getBool(
AsyncStorageManager.PREFERENCES.homeShowBanner.key)
&& !this.isLoggedIn,
}
}
@ -184,10 +185,7 @@ class HomeScreen extends React.Component<Props, State> {
};
hideMascotDialog = () => {
AsyncStorageManager.getInstance().savePref(
AsyncStorageManager.getInstance().preferences.homeShowBanner.key,
'0'
);
AsyncStorageManager.set(AsyncStorageManager.PREFERENCES.homeShowBanner.key, false);
this.setState({mascotDialogVisible: false})
};

View file

@ -38,7 +38,7 @@ class DashboardEditScreen extends React.Component<Props, State> {
constructor(props: Props) {
super(props);
let dashboardManager = new DashboardManager(this.props.navigation);
this.initialDashboardIdList = JSON.parse(AsyncStorageManager.getInstance().preferences.dashboardItems.current);
this.initialDashboardIdList = AsyncStorageManager.getObject(AsyncStorageManager.PREFERENCES.dashboardItems.key);
this.initialDashboard = dashboardManager.getCurrentDashboard();
this.state = {
currentDashboard: [...this.initialDashboard],
@ -92,10 +92,7 @@ class DashboardEditScreen extends React.Component<Props, State> {
currentDashboard: currentDashboard,
currentDashboardIdList: currentDashboardIdList,
});
AsyncStorageManager.getInstance().savePref(
AsyncStorageManager.getInstance().preferences.dashboardItems.key,
JSON.stringify(currentDashboardIdList)
);
AsyncStorageManager.set(AsyncStorageManager.PREFERENCES.dashboardItems.key, currentDashboardIdList);
}
undoDashboard = () => {
@ -103,10 +100,7 @@ class DashboardEditScreen extends React.Component<Props, State> {
currentDashboard: [...this.initialDashboard],
currentDashboardIdList: [...this.initialDashboardIdList]
});
AsyncStorageManager.getInstance().savePref(
AsyncStorageManager.getInstance().preferences.dashboardItems.key,
JSON.stringify(this.initialDashboardIdList)
);
AsyncStorageManager.set(AsyncStorageManager.PREFERENCES.dashboardItems.key, this.initialDashboardIdList);
}
getListHeader() {

View file

@ -37,18 +37,18 @@ class SettingsScreen extends React.Component<Props, State> {
*/
constructor() {
super();
let notifReminder = AsyncStorageManager.getInstance().preferences.proxiwashNotifications.current;
let notifReminder = AsyncStorageManager.getString(AsyncStorageManager.PREFERENCES.proxiwashNotifications.key);
this.savedNotificationReminder = parseInt(notifReminder);
if (isNaN(this.savedNotificationReminder))
this.savedNotificationReminder = 0;
this.state = {
nightMode: ThemeManager.getNightMode(),
nightModeFollowSystem: AsyncStorageManager.getInstance().preferences.nightModeFollowSystem.current === '1' &&
Appearance.getColorScheme() !== 'no-preference',
nightModeFollowSystem: AsyncStorageManager.getBool(AsyncStorageManager.PREFERENCES.nightModeFollowSystem.key)
&& Appearance.getColorScheme() !== 'no-preference',
notificationReminderSelected: this.savedNotificationReminder,
startScreenPickerSelected: AsyncStorageManager.getInstance().preferences.defaultStartScreen.current,
isDebugUnlocked: AsyncStorageManager.getInstance().preferences.debugUnlocked.current === '1'
startScreenPickerSelected: AsyncStorageManager.getString(AsyncStorageManager.PREFERENCES.defaultStartScreen.key),
isDebugUnlocked: AsyncStorageManager.getBool(AsyncStorageManager.PREFERENCES.debugUnlocked.key)
};
}
@ -57,8 +57,7 @@ class SettingsScreen extends React.Component<Props, State> {
*/
unlockDebugMode = () => {
this.setState({isDebugUnlocked: true});
let key = AsyncStorageManager.getInstance().preferences.debugUnlocked.key;
AsyncStorageManager.getInstance().savePref(key, '1');
AsyncStorageManager.set(AsyncStorageManager.PREFERENCES.debugUnlocked.key, true);
}
/**
@ -67,9 +66,8 @@ class SettingsScreen extends React.Component<Props, State> {
* @param value The value to store
*/
onProxiwashNotifPickerValueChange = (value: number) => {
let key = AsyncStorageManager.getInstance().preferences.proxiwashNotifications.key;
AsyncStorageManager.getInstance().savePref(key, value.toString());
this.setState({notificationReminderSelected: value})
this.setState({notificationReminderSelected: value});
AsyncStorageManager.set(AsyncStorageManager.PREFERENCES.proxiwashNotifications.key, value);
};
/**
@ -79,11 +77,8 @@ class SettingsScreen extends React.Component<Props, State> {
*/
onStartScreenPickerValueChange = (value: string) => {
if (value != null) {
let key = AsyncStorageManager.getInstance().preferences.defaultStartScreen.key;
AsyncStorageManager.getInstance().savePref(key, value);
this.setState({
startScreenPickerSelected: value
});
this.setState({startScreenPickerSelected: value});
AsyncStorageManager.set(AsyncStorageManager.PREFERENCES.defaultStartScreen.key, value);
}
};
@ -139,8 +134,7 @@ class SettingsScreen extends React.Component<Props, State> {
onToggleNightModeFollowSystem = () => {
const value = !this.state.nightModeFollowSystem;
this.setState({nightModeFollowSystem: value});
let key = AsyncStorageManager.getInstance().preferences.nightModeFollowSystem.key;
AsyncStorageManager.getInstance().savePref(key, value ? '1' : '0');
AsyncStorageManager.set(AsyncStorageManager.PREFERENCES.nightModeFollowSystem.key, value);
if (value) {
const nightMode = Appearance.getColorScheme() === 'dark';
ThemeManager.getInstance().setNightMode(nightMode);

View file

@ -53,7 +53,7 @@ class GroupSelectionScreen extends React.Component<Props, State> {
super(props);
this.state = {
currentSearchString: '',
favoriteGroups: JSON.parse(AsyncStorageManager.getInstance().preferences.planexFavoriteGroups.current),
favoriteGroups: AsyncStorageManager.getObject(AsyncStorageManager.PREFERENCES.planexFavoriteGroups.key),
};
}
@ -172,9 +172,7 @@ class GroupSelectionScreen extends React.Component<Props, State> {
else
this.addGroupToFavorites(newFavorites, group);
this.setState({favoriteGroups: newFavorites})
AsyncStorageManager.getInstance().savePref(
AsyncStorageManager.getInstance().preferences.planexFavoriteGroups.key,
JSON.stringify(newFavorites));
AsyncStorageManager.set(AsyncStorageManager.PREFERENCES.planexFavoriteGroups.key, newFavorites);
}
/**

View file

@ -135,7 +135,7 @@ class PlanexScreen extends React.Component<Props, State> {
this.webScreenRef = React.createRef();
this.barRef = React.createRef();
let currentGroup = AsyncStorageManager.getInstance().preferences.planexCurrentGroup.current;
let currentGroup = AsyncStorageManager.getString(AsyncStorageManager.PREFERENCES.planexCurrentGroup.key);
if (currentGroup === '')
currentGroup = {name: "SELECT GROUP", id: -1, isFav: false};
else {
@ -144,8 +144,9 @@ class PlanexScreen extends React.Component<Props, State> {
}
this.state = {
mascotDialogVisible:
AsyncStorageManager.getInstance().preferences.planexShowBanner.current === '1' &&
AsyncStorageManager.getInstance().preferences.defaultStartScreen.current !== 'Planex',
AsyncStorageManager.getBool(AsyncStorageManager.PREFERENCES.planexShowBanner.key)
&& AsyncStorageManager.getString(AsyncStorageManager.PREFERENCES.defaultStartScreen.key)
.toLowerCase() !== 'planex',
dialogVisible: false,
dialogTitle: "",
dialogMessage: "",
@ -167,10 +168,7 @@ class PlanexScreen extends React.Component<Props, State> {
*/
onMascotDialogCancel = () => {
this.setState({mascotDialogVisible: false});
AsyncStorageManager.getInstance().savePref(
AsyncStorageManager.getInstance().preferences.planexShowBanner.key,
'0'
);
AsyncStorageManager.set(AsyncStorageManager.PREFERENCES.planexShowBanner.key, false);
};
@ -208,10 +206,7 @@ class PlanexScreen extends React.Component<Props, State> {
selectNewGroup(group: group) {
this.sendMessage('setGroup', group.id);
this.setState({currentGroup: group});
AsyncStorageManager.getInstance().savePref(
AsyncStorageManager.getInstance().preferences.planexCurrentGroup.key,
JSON.stringify(group)
);
AsyncStorageManager.set(AsyncStorageManager.PREFERENCES.planexCurrentGroup.key, group);
this.props.navigation.setOptions({title: group.name});
this.generateInjectedJS(group.id);
}

View file

@ -56,7 +56,7 @@ class PlanningScreen extends React.Component<Props, State> {
refreshing: false,
agendaItems: {},
calendarShowing: false,
mascotDialogVisible: AsyncStorageManager.getInstance().preferences.eventsShowBanner.current === "1"
mascotDialogVisible: AsyncStorageManager.getBool(AsyncStorageManager.PREFERENCES.eventsShowBanner.key)
};
currentDate = getDateOnlyString(getCurrentDateString());
@ -111,10 +111,7 @@ class PlanningScreen extends React.Component<Props, State> {
*/
onHideMascotDialog = () => {
this.setState({mascotDialogVisible: false});
AsyncStorageManager.getInstance().savePref(
AsyncStorageManager.getInstance().preferences.eventsShowBanner.key,
'0'
);
AsyncStorageManager.set(AsyncStorageManager.PREFERENCES.eventsShowBanner.key, false);
};
/**

View file

@ -66,8 +66,8 @@ class ProxiwashScreen extends React.Component<Props, State> {
state = {
refreshing: false,
modalCurrentDisplayItem: null,
machinesWatched: JSON.parse(AsyncStorageManager.getInstance().preferences.proxiwashWatchedMachines.current),
mascotDialogVisible: AsyncStorageManager.getInstance().preferences.proxiwashShowBanner.current === "1",
machinesWatched: AsyncStorageManager.getObject(AsyncStorageManager.PREFERENCES.proxiwashWatchedMachines.key),
mascotDialogVisible: AsyncStorageManager.getBool(AsyncStorageManager.PREFERENCES.proxiwashShowBanner.key),
};
/**
@ -90,10 +90,7 @@ class ProxiwashScreen extends React.Component<Props, State> {
*/
onHideMascotDialog = () => {
this.setState({mascotDialogVisible: false});
AsyncStorageManager.getInstance().savePref(
AsyncStorageManager.getInstance().preferences.proxiwashShowBanner.key,
'0'
);
AsyncStorageManager.set(AsyncStorageManager.PREFERENCES.proxiwashShowBanner.key, false);
};
/**
@ -185,10 +182,7 @@ class ProxiwashScreen extends React.Component<Props, State> {
saveNewWatchedList(list: Array<Machine>) {
this.setState({machinesWatched: list});
AsyncStorageManager.getInstance().savePref(
AsyncStorageManager.getInstance().preferences.proxiwashWatchedMachines.key,
JSON.stringify(list),
);
AsyncStorageManager.set(AsyncStorageManager.PREFERENCES.proxiwashWatchedMachines.key, list);
}
/**

View file

@ -38,7 +38,7 @@ class ServicesScreen extends React.Component<Props, State> {
finalDataset: Array<listItem>
state = {
mascotDialogVisible: AsyncStorageManager.getInstance().preferences.servicesShowBanner.current === "1"
mascotDialogVisible: AsyncStorageManager.getBool(AsyncStorageManager.PREFERENCES.servicesShowBanner.key),
}
constructor(props) {
@ -60,10 +60,7 @@ class ServicesScreen extends React.Component<Props, State> {
*/
onHideMascotDialog = () => {
this.setState({mascotDialogVisible: false});
AsyncStorageManager.getInstance().savePref(
AsyncStorageManager.getInstance().preferences.servicesShowBanner.key,
'0'
);
AsyncStorageManager.set(AsyncStorageManager.PREFERENCES.servicesShowBanner.key, false);
};
getAboutButton = () =>

View file

@ -43,7 +43,7 @@ export async function askPermissions() {
* @param date The date to trigger the notification at
*/
function createNotifications(machineID: string, date: Date) {
let reminder = parseInt(AsyncStorageManager.getInstance().preferences.proxiwashNotifications.current);
let reminder = AsyncStorageManager.getNumber(AsyncStorageManager.PREFERENCES.proxiwashNotifications.key);
if (!isNaN(reminder) && reminder > 0) {
let id = reminderIdFactor * parseInt(machineID);
let reminderDate = new Date(date);