mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00

- Use relative imports in place of most of our absolute ones. - Add "private" ambient modules for modules that we need to import using an absolute path (e.g. when app/.../test-something.ts needs to import ui/styling/style-scope)
67 lines
1.9 KiB
TypeScript
67 lines
1.9 KiB
TypeScript
import Common = require("./application-settings-common");
|
|
import utils = require("utils/utils");
|
|
|
|
var sharedPreferences = utils.ad.getApplicationContext().getSharedPreferences("prefs.db", 0);
|
|
|
|
export var hasKey = function (key: string): boolean {
|
|
Common.checkKey(key);
|
|
return sharedPreferences.contains(key);
|
|
}
|
|
|
|
// getters
|
|
export var getBoolean = function (key: string, defaultValue?: boolean): boolean {
|
|
Common.checkKey(key);
|
|
if (hasKey(key)) {
|
|
return sharedPreferences.getBoolean(key, false);
|
|
}
|
|
return defaultValue;
|
|
}
|
|
|
|
export var getString = function (key: string, defaultValue?: string): string {
|
|
Common.checkKey(key);
|
|
if (hasKey(key)) {
|
|
return sharedPreferences.getString(key, "");
|
|
}
|
|
return defaultValue;
|
|
}
|
|
|
|
export var getNumber = function (key: string, defaultValue?: number): number {
|
|
Common.checkKey(key);
|
|
if (hasKey(key)) {
|
|
return sharedPreferences.getFloat(key, float(0.0));
|
|
}
|
|
return defaultValue;
|
|
}
|
|
|
|
// setters
|
|
export var setBoolean = function (key: string, value: boolean): void {
|
|
Common.checkKey(key);
|
|
Common.ensureValidValue(value, "boolean");
|
|
var editor = sharedPreferences.edit();
|
|
editor.putBoolean(key, value);
|
|
editor.commit();
|
|
}
|
|
|
|
export var setString = function (key: string, value: string): void {
|
|
Common.checkKey(key);
|
|
Common.ensureValidValue(value, "string");
|
|
var editor = sharedPreferences.edit();
|
|
editor.putString(key, value);
|
|
editor.commit();
|
|
}
|
|
|
|
export var setNumber = function (key: string, value: number): void {
|
|
Common.checkKey(key);
|
|
Common.ensureValidValue(value, "number");
|
|
var editor = sharedPreferences.edit();
|
|
editor.putFloat(key, float(value));
|
|
editor.commit();
|
|
}
|
|
|
|
export var remove = function (key: string): void {
|
|
Common.checkKey(key);
|
|
var editor = sharedPreferences.edit();
|
|
editor.remove(key);
|
|
editor.commit();
|
|
}
|