Skip to content

Commit d24f27e

Browse files
authored
Merge pull request #68 from nativescript-community/copilot/fix-custom-glide-url-issue
Fix file:// URL handling, cache eviction, cache detection, and force reload with efficient disk cache tracking in Android image loader
2 parents 82e7f87 + 75f8701 commit d24f27e

16 files changed

+774
-759
lines changed

demo-snippets/vue/Pipeline.vue

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
<StackLayout padding="12">
55
<Label text="ImagePipeline API" class="h2" />
66
<TextField v-model="url" hint="Image URL" keyboardType="url" />
7-
<NSImg ref="opacityImg" height="100" width="100%" :src="url" @finalImageSet="onFinalImageSet" @failure="onFailure" />
7+
<NSImg ref="opacityImg" :decodeWidth="decodeWidth" height="100" width="100%" :src="url" @finalImageSet="onFinalImageSet" @failure="onFailure" />
88
<WrapLayout marginTop="8">
9+
<Button text="switchDecodeWidth" @tap="switchDecodeWidth" />
910
<Button text="prefetchToMemory" @tap="prefetchMem" />
1011
<Button text="prefetchToDisk" @tap="prefetchDisk" />
1112
<Button text="evictFromCache" @tap="evictFromCache" />
@@ -32,12 +33,16 @@ import { getImagePipeline } from '@nativescript-community/ui-image';
3233
export default {
3334
data() {
3435
return {
35-
url: 'https://images.pexels.com/photos/842711/pexels-photo-842711.jpeg',
36+
decodeWidth: 100,
37+
url: '~/assets/images/dessert.jpg',
3638
logs: [] as string[],
3739
result: ''
3840
};
3941
},
4042
methods: {
43+
switchDecodeWidth() {
44+
this.decodeWidth = this.decodeWidth === 10 ? 100 : 10;
45+
},
4146
onFinalImageSet(e: any) {
4247
const info = e.imageInfo;
4348
this.addLog('loaded: ' + (info ? `${info.getWidth()}x${info.getHeight()}` : 'unknown') + ' from: ' + e.source);
@@ -57,7 +62,7 @@ export default {
5762
try {
5863
await getImagePipeline().prefetchToMemoryCache(this.url, {
5964
decodeWidth: 300,
60-
decodeHeight: 300,
65+
decodeHeight: 300
6166
});
6267
this.addLog('prefetchToMemoryCache success');
6368
this.result = 'prefetchToMemoryCache success';

packages/image/platforms/android/java/com/nativescript/image/CacheKeyStore.java

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,20 @@ public class CacheKeyStore {
1616
public static class StoredKeys {
1717
public final Key sourceKey;
1818
public final Key signature;
19-
public final int width;
20-
public final int height;
21-
public final Transformation<?> transformation; // optional in-memory only
22-
public final byte[] transformationKeyBytes; // raw bytes written by transformation.updateDiskCacheKey
23-
public final Class<?> decodedResourceClass;
24-
public final Options options; // may be null or placeholder for in-memory
25-
public final byte[] optionsKeyBytes; // raw bytes from options.updateDiskCacheKey
26-
2719
public StoredKeys(
2820
Key sourceKey,
29-
Key signature,
30-
int width,
31-
int height,
32-
Transformation<?> transformation,
33-
byte[] transformationKeyBytes,
34-
Class<?> decodedResourceClass,
35-
Options options,
36-
byte[] optionsKeyBytes) {
21+
Key signature) {
3722
this.sourceKey = sourceKey;
3823
this.signature = signature;
39-
this.width = width;
40-
this.height = height;
41-
this.transformation = transformation;
42-
this.transformationKeyBytes = transformationKeyBytes;
43-
this.decodedResourceClass = decodedResourceClass;
44-
this.options = options;
45-
this.optionsKeyBytes = optionsKeyBytes;
24+
}
25+
26+
public String toString() {
27+
return "CacheKeyStore.StoredKeys {"
28+
+ "sourceKey="
29+
+ sourceKey
30+
+ ", signature="
31+
+ signature
32+
+ '}';
4633
}
4734
}
4835

@@ -62,4 +49,5 @@ public void remove(String id) {
6249
public void clearAll() {
6350
map.clear();
6451
}
52+
6553
}

packages/image/platforms/android/java/com/nativescript/image/CapturingEngineKeyFactory.java

Lines changed: 0 additions & 43 deletions
This file was deleted.

packages/image/platforms/android/java/com/nativescript/image/CustomDataCacheKey.java

Lines changed: 0 additions & 58 deletions
This file was deleted.

packages/image/platforms/android/java/com/nativescript/image/CustomGlideModule.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import com.bumptech.glide.load.engine.cache.DiskCache;
1414
import com.bumptech.glide.load.engine.cache.DiskLruCacheWrapper;
1515
import com.bumptech.glide.load.engine.cache.MemoryCache;
16-
import com.bumptech.glide.load.engine.CapturingEngineKeyFactory;
16+
import com.bumptech.glide.load.engine.cache.ModelSignatureDiskLruCacheWrapper;
1717
import com.bumptech.glide.load.model.GlideUrl;
1818
import com.bumptech.glide.module.AppGlideModule;
1919
import com.bumptech.glide.RequestBuilder;
@@ -91,7 +91,7 @@ public void applyOptions(@NonNull Context context, @NonNull GlideBuilder builder
9191
builder.setDiskCache(new DiskCache.Factory() {
9292
@Override
9393
public DiskCache build() {
94-
DiskCache dc = DiskLruCacheWrapper.create(getCacheDirectory(context, config.getDiskCacheName()), config.getDiskCacheSize());
94+
ModelSignatureDiskLruCacheWrapper dc = ModelSignatureDiskLruCacheWrapper.create(getCacheDirectory(context, config.getDiskCacheName()), config.getDiskCacheSize());
9595
EvictionManager.get().setDiskCache(dc);
9696
return dc;
9797
}

0 commit comments

Comments
 (0)