Skip to content

Commit

Permalink
feat(): auto memory management ... 🥳clean up!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
triniwiz committed Dec 1, 2019
1 parent 9c99e3e commit 936ecd4
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

```ts
import { ImageCacheIt } from 'nativescript-image-cache-it';
// **new** call in your app.ts/ main.ts/ app.js to enable image-cache to hook into the device's lowmemory events
ImageCacheIt.enableAutoMM();
```

Set image url to load.
Expand Down
2 changes: 2 additions & 0 deletions demo/app/app.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as application from 'tns-core-modules/application';
import { ImageCacheIt } from 'nativescript-image-cache-it';

ImageCacheIt.enableAutoMM();
application.run({moduleName: 'main-page'});
8 changes: 8 additions & 0 deletions src/image-cache-it.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,14 @@ export class ImageCacheIt extends ImageCacheItBase {
resolve();
});
}

public static enableAutoMM() {
(com as any).github.triniwiz.imagecacheit.ImageView.enableAutoMM(app.android.nativeApp)
}

public static disableAutoMM() {
(com as any).github.triniwiz.imagecacheit.ImageView.disableAutoMM(app.android.nativeApp)
}
}


Expand Down
19 changes: 19 additions & 0 deletions src/image-cache-it.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { layout } from 'tns-core-modules/ui/core/view';
import * as fs from 'tns-core-modules/file-system';
import * as types from 'tns-core-modules/utils/types';
import { Length } from 'tns-core-modules/ui/styling/style-properties';
import * as app from 'tns-core-modules/application';

declare var SDWebImageManager, SDWebImageOptions, SDImageCacheType, SDImageCache;

Expand Down Expand Up @@ -429,6 +430,24 @@ export class ImageCacheIt extends ImageCacheItBase {
});
}

private static autoMMCallback;

public static enableAutoMM() {
ImageCacheIt.autoMMCallback = (args) => {
const manager = SDWebImageManager.sharedManager;
if (manager) {
manager.clearMemory();
}
};
app.on(app.lowMemoryEvent as any, ImageCacheIt.autoMMCallback);
}

public static disableAutoMM() {
if (ImageCacheIt.autoMMCallback) {
app.off(app.lowMemoryEvent as any, ImageCacheIt.autoMMCallback);
}
}

public static getItem(src: string): Promise<any> {
return new Promise<any>((resolve, reject) => {
const manager = SDWebImageManager.sharedManager;
Expand Down
4 changes: 4 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ export declare class ImageCacheIt extends ImageCacheItBase {
public static hasItem(src: string): Promise<any>;

public static clear(src: string): Promise<any>;

public static enableAutoMM(): void;

public static disableAutoMM(): void;
}
4 changes: 2 additions & 2 deletions src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nativescript-image-cache-it",
"version": "5.0.0-alpha.22",
"version": "5.0.0-alpha.23",
"description": "Image caching plugin for NativeScript",
"main": "image-cache-it",
"typings": "index.d.ts",
Expand All @@ -22,7 +22,7 @@
"plugin.link": "npm link && cd ../demo && npm link nativescript-image-cache-it && cd ../demo-ng && npm link nativescript-image-cache-it && cd ../src",
"plugin.tscwatch": "npm run tsc -- -w",
"demo.ios": "npm i && npm run tsc && cd ../demo && tns run ios",
"demo.android": "npm i && npm run tsc && cd ../demo && tns run android",
"demo.android": "npm i && npm run tsc && cd ../demo && tns run android --no-hmr",
"demo.reset": "cd ../demo && rimraf platforms",
"demo.ng.ios": "npm i && npm run tsc && cd ../demo-ng && tns run ios",
"demo.ng.android": "npm i && npm run tsc && cd ../demo-ng && tns run android",
Expand Down
Binary file modified src/platforms/android/imagecacheit-release.aar
Binary file not shown.
5 changes: 3 additions & 2 deletions src/platforms/android/include.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ repositories {

dependencies {
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'com.github.bumptech.glide:okhttp3-integration:4.9.0'
implementation 'com.github.bumptech.glide:okhttp3-integration:4.10.0'
implementation 'jp.wasabeef:glide-transformations:4.1.0'
implementation 'jp.co.cyberagent.android:gpuimage:2.0.3'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
implementation 'com.github.bumptech.glide:glide:4.10.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0'
annotationProcessor 'androidx.annotation:annotation:1.1.0'
}

0 comments on commit 936ecd4

Please sign in to comment.