From 0d12aada092654873478f626723fa022bd33bea5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=8E=E6=9C=88=E6=B8=85=E9=A3=8E?= <2928139825@qq.com> Date: Fri, 8 Sep 2023 15:30:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=AF=B4=E6=98=8E=EF=BC=9A?= =?UTF-8?q?=201=E3=80=81=E4=BC=98=E5=8C=96=E4=BA=86=E5=86=85=E5=AD=98?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E7=AD=96=E7=95=A5=EF=BC=8C=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E4=BA=86=E5=86=85=E5=AD=98=E7=BC=93=E5=AD=98=E7=AD=96=E7=95=A5?= =?UTF-8?q?=E7=BB=99=E5=B8=83=E5=B0=94=E5=80=BC=E4=B8=8D=E7=94=9F=E6=95=88?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 明月清风 <2928139825@qq.com> --- AppScope/app.json5 | 2 +- CHANGELOG.md | 6 ++ entry/oh-package.json5 | 2 +- entry/src/main/ets/pages/OptionTestPage.ets | 77 +++++++++++++++++++ .../ets/pages/imageknifeTestCaseIndex.ets | 5 ++ .../resources/base/profile/main_pages.json | 5 +- imageknife/oh-package.json5 | 2 +- .../imageknife/ImageKnifeComponent.ets | 15 ++-- oh-package.json5 | 2 +- 9 files changed, 104 insertions(+), 12 deletions(-) create mode 100644 entry/src/main/ets/pages/OptionTestPage.ets diff --git a/AppScope/app.json5 b/AppScope/app.json5 index f67021a..dc0364a 100644 --- a/AppScope/app.json5 +++ b/AppScope/app.json5 @@ -3,7 +3,7 @@ "bundleName": "com.openharmony.imageknife", "vendor": "example", "versionCode": 1000000, - "versionName": "2.0.4", + "versionName": "2.0.5", "icon": "$media:app_icon", "label": "$string:app_name", "distributedNotificationEnabled": true diff --git a/CHANGELOG.md b/CHANGELOG.md index 30accad..da5c300 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 2.0.5 + +- 修复若干问题: + +​ 优化了内存缓存策略,修复了内存缓存策略给布尔值不生效的问题 + ## 2.0.4 - 修复若干问题: diff --git a/entry/oh-package.json5 b/entry/oh-package.json5 index d6c5af6..f4efcc7 100644 --- a/entry/oh-package.json5 +++ b/entry/oh-package.json5 @@ -4,7 +4,7 @@ "name": "entry", "description": "example description", "repository": {}, - "version": "2.0.4", + "version": "2.0.5", "dependencies": { "@ohos/imageknife": "file:../imageknife", "@ohos/disklrucache": "^2.0.0" diff --git a/entry/src/main/ets/pages/OptionTestPage.ets b/entry/src/main/ets/pages/OptionTestPage.ets new file mode 100644 index 0000000..6306ab2 --- /dev/null +++ b/entry/src/main/ets/pages/OptionTestPage.ets @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { ImageKnifeComponent, ImageKnifeOption,NONE } from '@ohos/imageknife' + +@Entry +@Component +struct OptionTestPage { + @State imageKnifeOption1: ImageKnifeOption = + { + loadSrc: $r('app.media.icon'), + placeholderSrc: $r('app.media.icon_loading'), + errorholderSrc: $r('app.media.icon_failed'), + }; + @State imageKnifeOption2: ImageKnifeOption = + { + loadSrc: $r('app.media.icon'), + placeholderSrc: $r('app.media.icon_loading'), + errorholderSrc: $r('app.media.icon_failed') + }; + + build() { + Scroll() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + + Text("示例加载图片不进行缓存").fontSize(15) + Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Button("加载") + .onClick(() => { + this.imageKnifeOption1 = { + loadSrc: 'https://img-blog.csdn.net/20140514114029140', + placeholderSrc: $r('app.media.icon_loading'), + errorholderSrc: $r('app.media.icon_failed'), + onlyRetrieveFromCache: false, + isCacheable: false, + strategy: new NONE() + } + }).margin({ top: 5, left: 3 }) + ImageKnifeComponent({ imageKnifeOption: this.imageKnifeOption1 }).width(300).height(300) + }.width('100%').backgroundColor(Color.Pink) + + Text("示例:加载图片进行缓存").fontSize(15) + Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Button("加载") + .onClick(() => { + this.imageKnifeOption2 = { + loadSrc: 'https://img-blog.csdn.net/20140514114029140', + placeholderSrc: $r('app.media.icon_loading'), + errorholderSrc: $r('app.media.icon_failed'), + onlyRetrieveFromCache: true, + isCacheable: true, + strategy: new NONE() + } + }).margin({ top: 5, left: 3 }) + ImageKnifeComponent({ imageKnifeOption: this.imageKnifeOption2 }).width(300).height(300) + }.width('100%').backgroundColor(Color.Pink) + + + } + + }.width('100%') + .height('100%') + + } +} \ No newline at end of file diff --git a/entry/src/main/ets/pages/imageknifeTestCaseIndex.ets b/entry/src/main/ets/pages/imageknifeTestCaseIndex.ets index 6812123..c8518a5 100644 --- a/entry/src/main/ets/pages/imageknifeTestCaseIndex.ets +++ b/entry/src/main/ets/pages/imageknifeTestCaseIndex.ets @@ -144,6 +144,11 @@ struct IndexFunctionDemo { console.log("加载媒体库uri") router.pushUrl({ url: "pages/dataShareUriLoadPage" }); }).margin({ top: 5, left: 3 }) + Button("测试Option缓存是否生效") + .onClick(() => { + console.log("加载媒体库uri") + router.pushUrl({ url: "pages/OptionTestPage" }); + }).margin({ top: 5, left: 3 }) }.width('100%').height(60).backgroundColor(Color.Pink) Text("测试pngj和裁剪").fontSize(15) diff --git a/entry/src/main/resources/base/profile/main_pages.json b/entry/src/main/resources/base/profile/main_pages.json index 5a9b46a..2d9020b 100644 --- a/entry/src/main/resources/base/profile/main_pages.json +++ b/entry/src/main/resources/base/profile/main_pages.json @@ -29,6 +29,7 @@ "pages/tempUrlTestPage", "pages/drawFactoryTestPage", "pages/testSingleFrameGifPage", - "pages/testGifLoadWithWorkerPage" + "pages/testGifLoadWithWorkerPage", + "pages/OptionTestPage" ] -} +} \ No newline at end of file diff --git a/imageknife/oh-package.json5 b/imageknife/oh-package.json5 index efcec38..9d2e473 100644 --- a/imageknife/oh-package.json5 +++ b/imageknife/oh-package.json5 @@ -14,7 +14,7 @@ "main": "index.ets", "repository": "https://gitee.com/openharmony-tpc/ImageKnife", "type": "module", - "version": "2.0.4", + "version": "2.0.5", "dependencies": { "@ohos/disklrucache": "^2.0.0", "@ohos/svg": "^2.0.0", diff --git a/imageknife/src/main/ets/components/imageknife/ImageKnifeComponent.ets b/imageknife/src/main/ets/components/imageknife/ImageKnifeComponent.ets index c077af6..66144e6 100644 --- a/imageknife/src/main/ets/components/imageknife/ImageKnifeComponent.ets +++ b/imageknife/src/main/ets/components/imageknife/ImageKnifeComponent.ets @@ -33,7 +33,6 @@ export struct ImageKnifeComponent { private lastHeight: number = 0 private currentWidth: number = 0 private currentHeight: number = 0 - // 定时器id private gifTimerId: number = 0 // 完整gif播放时间 @@ -178,16 +177,20 @@ export struct ImageKnifeComponent { } configCacheStrategy(request: RequestOption) { - if (this.imageKnifeOption.onlyRetrieveFromCache) { + if (this.imageKnifeOption.onlyRetrieveFromCache != null && this.imageKnifeOption.onlyRetrieveFromCache != undefined) { request.retrieveDataFromCache(this.imageKnifeOption.onlyRetrieveFromCache) } - request.skipMemoryCache(!this.imageKnifeOption.isCacheable) - - if (this.imageKnifeOption.strategy) { + if (this.imageKnifeOption.isCacheable != null && this.imageKnifeOption.isCacheable != undefined) { + request.skipMemoryCache(!this.imageKnifeOption.isCacheable) + console.log("内存缓存策略" + this.imageKnifeOption.isCacheable) + } + + + if (this.imageKnifeOption.strategy != null && this.imageKnifeOption.strategy != undefined) { request.diskCacheStrategy(this.imageKnifeOption.strategy) } - if (this.imageKnifeOption.allCacheInfoCallback) { + if (this.imageKnifeOption.allCacheInfoCallback != null && this.imageKnifeOption.allCacheInfoCallback != undefined) { request.addAllCacheInfoCallback(this.imageKnifeOption.allCacheInfoCallback) } } diff --git a/oh-package.json5 b/oh-package.json5 index 2a552ce..1f4b581 100644 --- a/oh-package.json5 +++ b/oh-package.json5 @@ -6,6 +6,6 @@ "name": "imageknife", "description": "example description", "repository": {}, - "version": "2.0.4", + "version": "2.0.5", "dependencies": {} }