Skip to content

Commit

Permalink
feat(application-settings): implemented allKeys method (#6371)
Browse files Browse the repository at this point in the history
  • Loading branch information
surdu authored and Alexander Vakrilov committed Oct 12, 2018
1 parent 56a1b12 commit 829d18b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/app/application-settings/application-settings-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,17 @@ export var testFlush = function () {
TKUnit.assert(appSettings.hasKey(stringKey), "There is no key: " + stringKey);
};

export var testAllKeys = function () {
appSettings.setString(stringKey, "String value");
appSettings.setBoolean(boolKey, true);
appSettings.setNumber(numberKey, 22);

var allKeys = appSettings.getAllKeys();
TKUnit.assert(allKeys.indexOf(stringKey) !== -1, `${stringKey} is missing from .allKeys()`);
TKUnit.assert(allKeys.indexOf(boolKey) !== -1, `${boolKey} is missing from .allKeys()`);
TKUnit.assert(allKeys.indexOf(numberKey) !== -1, `${numberKey} is missing from .allKeys()`);
}

export var testInvalidKey = function () {
try {
appSettings.hasKey(undefined);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,15 @@ export function clear(): void {
export var flush = function (): boolean {
return sharedPreferences.edit().commit();
}

export function getAllKeys(): Array<string> {
var mappedPreferences = sharedPreferences.getAll();
var iterator = mappedPreferences.keySet().iterator();
var result = [];
while (iterator.hasNext()) {
let key = iterator.next();
result.push(key);
}

return result;
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,9 @@ export function clear(): void;
* @return {boolean} flag indicating if changes were saved successfully to disk.
*/
export function flush(): boolean;

/**
* Get all stored keys
* @return Array containing all stored keys
*/
export function getAllKeys(): Array<string>;
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,7 @@ export var clear = function (): void {
export var flush = function (): boolean {
return userDefaults.synchronize();
}

export function getAllKeys(): Array<string> {
return utils.ios.collections.nsArrayToJSArray(userDefaults.dictionaryRepresentation().allKeys);
}

0 comments on commit 829d18b

Please sign in to comment.