Skip to content

Commit

Permalink
Merge pull request NativeScript#1407 from NativeScript/atanasovg/snap…
Browse files Browse the repository at this point in the history
…shot-refactorings

Atanasovg/snapshot refactorings
  • Loading branch information
atanasovg committed Jan 25, 2016
2 parents d330a75 + a760328 commit 62d85b0
Show file tree
Hide file tree
Showing 38 changed files with 1,044 additions and 746 deletions.
4 changes: 3 additions & 1 deletion CrossPlatformModules.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,8 @@
<TypeScriptCompile Include="ui\utils.ios.ts">
<DependentUpon>utils.d.ts</DependentUpon>
</TypeScriptCompile>
<TypeScriptCompile Include="utils\debug.d.ts" />
<TypeScriptCompile Include="utils\debug.ts" />
<TypeScriptCompile Include="utils\module-merge.ts" />
<TypeScriptCompile Include="utils\utils.android.ts">
<DependentUpon>utils.d.ts</DependentUpon>
Expand Down Expand Up @@ -2139,7 +2141,7 @@
<AutoAssignPort>True</AutoAssignPort>
<DevelopmentServerPort>0</DevelopmentServerPort>
<DevelopmentServerVPath>/</DevelopmentServerVPath>
<IISUrl>http://localhost:3128/</IISUrl>
<IISUrl>http://localhost:60276/</IISUrl>
<NTLMAuthentication>False</NTLMAuthentication>
<UseCustomServer>False</UseCustomServer>
<CustomServerUrl>
Expand Down
3 changes: 1 addition & 2 deletions application-settings/application-settings-common.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

export var checkKey = function(key: string) : void {
export var checkKey = function(key: string) : void {
if ("string" !== typeof key) {
throw new Error("key: '" + key + "' must be a string");
}
Expand Down
36 changes: 23 additions & 13 deletions application-settings/application-settings.android.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,42 @@
import Common = require("./application-settings-common");
import common = require("./application-settings-common");
import utils = require("utils/utils");

var sharedPreferences = utils.ad.getApplicationContext().getSharedPreferences("prefs.db", 0);
var sharedPreferences;
function ensureSharedPreferences() {
if (!sharedPreferences) {
sharedPreferences = utils.ad.getApplicationContext().getSharedPreferences("prefs.db", 0);
}
}

function verify(key: string) {
common.checkKey(key);
ensureSharedPreferences();
}

export var hasKey = function (key: string): boolean {
Common.checkKey(key);
verify(key);
return sharedPreferences.contains(key);
}

// getters
export var getBoolean = function (key: string, defaultValue?: boolean): boolean {
Common.checkKey(key);
verify(key);
if (hasKey(key)) {
return sharedPreferences.getBoolean(key, false);
}
return defaultValue;
}

export var getString = function (key: string, defaultValue?: string): string {
Common.checkKey(key);
verify(key);
if (hasKey(key)) {
return sharedPreferences.getString(key, "");
}
return defaultValue;
}

export var getNumber = function (key: string, defaultValue?: number): number {
Common.checkKey(key);
verify(key);
if (hasKey(key)) {
return sharedPreferences.getFloat(key, float(0.0));
}
Expand All @@ -35,31 +45,31 @@ export var getNumber = function (key: string, defaultValue?: number): number {

// setters
export var setBoolean = function (key: string, value: boolean): void {
Common.checkKey(key);
Common.ensureValidValue(value, "boolean");
verify(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");
verify(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");
verify(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);
verify(key);
var editor = sharedPreferences.edit();
editor.remove(key);
editor.commit();
Expand Down
33 changes: 21 additions & 12 deletions application/application-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import definition = require("application");
import observable = require("data/observable");
import frame = require("ui/frame");
import cssSelector = require("ui/styling/css-selector");
import * as fileSystemModule from "file-system";
import * as styleScopeModule from "ui/styling/style-scope";

Expand All @@ -21,6 +22,8 @@ export var mainEntry: frame.NavigationEntry;

export var cssFile: string = "app.css"

export var cssSelectorsCache: Array<cssSelector.CssSelector> = undefined;

export var resources: any = {};

export var onUncaughtError: (error: definition.NativeScriptError) => void = undefined;
Expand All @@ -39,18 +42,24 @@ export var android = undefined;

export var ios = undefined;

export function loadCss() {
if (definition.cssFile) {
var fs: typeof fileSystemModule = require("file-system");
var styleScope: typeof styleScopeModule = require("ui/styling/style-scope");

var cssFileName = fs.path.join(fs.knownFolders.currentApp().path, definition.cssFile);
if (fs.File.exists(cssFileName)) {
var file = fs.File.fromPath(cssFileName);
var applicationCss = file.readTextSync();
if (applicationCss) {
definition.cssSelectorsCache = styleScope.StyleScope.createSelectorsFromCss(applicationCss, cssFileName);
}
export function loadCss(cssFile?: string): Array<cssSelector.CssSelector> {
if (!cssFile) {
return undefined;
}

var result: Array<cssSelector.CssSelector>;

var fs: typeof fileSystemModule = require("file-system");
var styleScope: typeof styleScopeModule = require("ui/styling/style-scope");

var cssFileName = fs.path.join(fs.knownFolders.currentApp().path, cssFile);
if (fs.File.exists(cssFileName)) {
var file = fs.File.fromPath(cssFileName);
var applicationCss = file.readTextSync();
if (applicationCss) {
result = styleScope.StyleScope.createSelectorsFromCss(applicationCss, cssFileName);
}
}

return result;
}
Loading

0 comments on commit 62d85b0

Please sign in to comment.