FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

refactor(image-cache): updates for Android · NativeScript/NativeScript@5701d21 · GitHub

Commit 5701d21

Browse files
authored andcommitted
refactor(image-cache): updates for Android
Update Android `constructor()`. Move `key` and `image` check to `set()`. Update `trace.write`.
1 parent c8ded5f commit 5701d21

2 files changed

Lines changed: 17 additions & 22 deletions

File tree

‎tns-core-modules/ui/image-cache/image-cache-common.ts‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,7 @@ export class Cache extends observable.Observable implements definition.Cache {
141141
public _onDownloadCompleted(key: string, image: any) {
142142
var request = <DownloadRequest>this._pendingDownloads[key];
143143

144-
if (request.key && image) {
145-
this.set(request.key, image);
146-
}
147-
144+
this.set(request.key, image);
148145
this._currentDownloads--;
149146

150147
if (request.completed) {

‎tns-core-modules/ui/image-cache/image-cache.android.ts‎

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,18 @@ export class Cache extends common.Cache {
4646
onComplete: function (result: any, context: any) {
4747
var instance = that.get();
4848
if (instance) {
49-
if (result && result != null) {
50-
instance._onDownloadCompleted(context, result);
51-
} else {
52-
instance._onDownloadError(context);
53-
}
49+
if (result) {
50+
instance._onDownloadCompleted(context, result);
51+
} else {
52+
instance._onDownloadError(context, new Error("No result in CompletionCallback"));
53+
}
5454
}
5555
},
56-
onError: function (context: any) {
57-
var instance = that.get();
58-
if (instance) {
59-
instance._onDownloadError(context);
60-
}
56+
onError: function (err: string, context: any) {
57+
var instance = that.get();
58+
if (instance) {
59+
instance._onDownloadError(context, new Error(err));
60+
}
6161
}
6262
});
6363
}
@@ -72,15 +72,13 @@ export class Cache extends common.Cache {
7272
}
7373

7474
public set(key: string, image: any): void {
75-
try {
76-
if (key && key != null && image && image != null) {
77-
this._cache.put(key, image);
78-
}
79-
} catch (err) {
80-
if (trace.isEnabled()) {
81-
trace.write("Cache set error: " + err, trace.categories.Debug);
75+
try {
76+
if (key && image) {
77+
this._cache.put(key, image);
78+
}
79+
} catch (err) {
80+
trace.write("Cache set error: " + err, trace.categories.Error, trace.messageType.error);
8281
}
83-
}
8482
}
8583

8684
public remove(key: string): void {

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL