-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature/settings — Persist settings accross restart and apply them wh…
…en starting.
- Loading branch information
Showing
4 changed files
with
83 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
(function () { | ||
'use strict'; | ||
|
||
angular | ||
.module('app') | ||
.factory('settingService', factory); | ||
|
||
function factory($log, localStorageService, defaultCacheName, CacheFactory, ImgCache, $q, $ionicConfig) { | ||
|
||
var defaults = { | ||
enableAnimations: true | ||
}; | ||
|
||
var service = { | ||
settings: _.defaults(localStorageService.get('settings'), defaults), | ||
update: update, | ||
clearCache: clearCache | ||
}; | ||
|
||
return service; | ||
|
||
//////////// | ||
|
||
function update(){ | ||
var settings = service.settings; | ||
|
||
// enableAnimations property | ||
settings.enableAnimations ? enableAnimations() : disableAnimations(); | ||
|
||
// Persist in local storage | ||
localStorageService.set('settings', settings); | ||
$log.info('Settings persisted'); | ||
} | ||
|
||
function clearCache() { | ||
return $q(function (resolve, reject) { | ||
|
||
CacheFactory.get(defaultCacheName).removeAll(); | ||
$log.info('HTTP cache is now empty'); | ||
ImgCache.clearCache(ok, reject); | ||
|
||
///////////// | ||
|
||
function ok() { | ||
$log.info('Image cache is now empty'); | ||
resolve(); | ||
} | ||
}); | ||
} | ||
|
||
function enableAnimations(){ | ||
$ionicConfig.views.transition('platform'); | ||
} | ||
|
||
function disableAnimations(){ | ||
$ionicConfig.views.transition('none'); | ||
} | ||
|
||
} | ||
|
||
})(); | ||
|