1.ImageKnife新增暂停加载全局接口,恢复加载全局接口。

Signed-off-by: zhoulisheng <635547767@qq.com>
This commit is contained in:
zhoulisheng 2023-11-15 10:52:00 +08:00
parent 3077af9dc3
commit 980be617ba
12 changed files with 162 additions and 86 deletions

View File

@ -3,7 +3,7 @@
"bundleName": "com.openharmony.imageknife",
"vendor": "example",
"versionCode": 1000000,
"versionName": "2.1.1-rc.1",
"versionName": "2.1.1-rc.2",
"icon": "$media:app_icon",
"label": "$string:app_name",
"distributedNotificationEnabled": true

View File

@ -1,3 +1,8 @@
## 2.1.1-rc.2
- 门面类ImageKnife新增pauseRequests接口,全局暂停请求
- 门面类ImageKnife新增resumeRequests接口,全局恢复暂停
## 2.1.1-rc.1
- 新增自定义key参数配置

View File

@ -37,7 +37,7 @@ ohpm install @ohos/imageknife
"author": "",
"license": "",
"dependencies": {
"@ohos/imageknife": "^2.1.1-rc.1"
"@ohos/imageknife": "^2.1.1-rc.2"
}
}
```
@ -462,15 +462,17 @@ request.skipMemoryCache(true)
| skipMemoryCache(skip: boolean) | skip: boolean | 配置是否跳过内存缓存 |
| retrieveDataFromCache(flag: boolean) | flag: boolean | 配置仅从缓存中加载数据 |
| signature | ObjectKey | 自定义key |
同时支持[图片变换相关](#图片变换相关)接口。
### ImageKnife 启动器/门面类
| 方法名 | 入参 | 接口描述 |
|---------------------------------|------------------------|-------------------|
| call(request: RequestOption) | request: RequestOption | 根据用户配置参数具体执行加载流程 |
| 方法名 | 入参 | 接口描述 |
| ------------------------------- | ---------------------- | ---------------------------------- |
| call(request: RequestOption) | request: RequestOption | 根据用户配置参数具体执行加载流程 |
| preload(request: RequestOption) | request: RequestOption | 根据用户配置参数具体执行预加载流程 |
| pauseRequests() | | 全局暂停请求 |
| resumeRequests() | | 全局恢复暂停 |
### 缓存策略相关

View File

@ -4,7 +4,7 @@
"name": "entry",
"description": "example description",
"repository": {},
"version": "2.1.1-rc.1",
"version": "2.1.1-rc.2",
"dependencies": {
"@ohos/imageknife": "file:../imageknife",
"@ohos/disklrucache": "^2.0.2-rc.0"

View File

@ -220,6 +220,11 @@ struct IndexFunctionDemo {
console.log("pages/manyPhotoShowPage 页面跳转")
router.pushUrl({ url: "pages/manyPhotoShowPage" });
}).margin({ top: 15 })
Button("图片加载暂停和恢复")
.onClick(() => {
console.log("pages/manyPhotoShowPage 页面跳转")
router.pushUrl({ url: "pages/photosPausedResumedPage" });
}).margin({ top: 15 })
Button("部分url测试")
.onClick(() => {
console.log("pages/tempUrlTestPage 页面跳转")

View File

@ -31,36 +31,6 @@ struct ManyPhotoShowPage {
build() {
Column() {
// Button('点击暂停加载')
// .margin({top:10,bottom:5})
// .onClick(()=>{
// let imageKnife = ImageKnifeGlobal.getInstance().getImageKnife();
// if(imageKnife!= undefined){
// imageKnife.pauseRequests()
// }
// })
//
// Button('点击重新加载')
// .margin({top:10,bottom:5})
// .onClick(()=>{
// let imageKnife = ImageKnifeGlobal.getInstance().getImageKnife();
// if(imageKnife!= undefined){
// imageKnife.resumeRequests()
// }
// })
//
// Button('设置磁盘存储为50M')
// .margin({top:10,bottom:5})
// .onClick(()=>{
// if(ImageKnifeGlobal.getInstance().getImageKnife() != undefined) {
// let disk: DiskLruCache | undefined = (ImageKnifeGlobal.getInstance().getImageKnife())?.getDiskMemoryCache();
// if(disk != undefined) {
// disk.setMaxSize(50 * 1024 * 1024)
// Prompt.showToast({ message: "设置成功" })
// }
// }
// })
List({ space: 20, scroller: this.elementScroller }) {
LazyForEach(this.data, (item: Material, index) => {
ListItem() {

View File

@ -0,0 +1,93 @@
/*
* Copyright (C) 2021 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, ScaleType} from '@ohos/imageknife'
import {ImageKnifeOption} from '@ohos/imageknife'
import {ImageKnifeGlobal} from '@ohos/imageknife'
import {RotateImageTransformation} from '@ohos/imageknife'
import {Material} from './model/Material'
import {TestDataSource} from './model/TestDataSource'
import {DiskLruCache} from '@ohos/disklrucache'
import ArkWorker from '@ohos.worker'
import Prompt from '@system.prompt'
@Entry
@Component
struct photosPausedResumedPage {
private data: TestDataSource = new TestDataSource();
private elementScroller: Scroller = new Scroller()
build() {
Column() {
Button('点击暂停加载')
.margin({top:10,bottom:5})
.onClick(()=>{
let imageKnife = ImageKnifeGlobal.getInstance().getImageKnife();
if(imageKnife!= undefined){
imageKnife.pauseRequests()
}
})
Button('点击重新加载')
.margin({top:10,bottom:5})
.onClick(()=>{
let imageKnife = ImageKnifeGlobal.getInstance().getImageKnife();
if(imageKnife!= undefined){
imageKnife.resumeRequests()
}
})
List({ space: 20, scroller: this.elementScroller }) {
LazyForEach(this.data, (item: Material, index) => {
ListItem() {
Column() {
Stack({ alignContent: Alignment.BottomEnd }) {
// 滤镜图片
ImageKnifeComponent({ imageKnifeOption: {
loadSrc: item.thumbnail,
mainScaleType: ScaleType.FIT_XY,
} })
}
.width(56).height(56)
//滤镜标题
Text(item.name)
.fontSize(10)
.maxLines(1)
.fontColor(Color.White)
.textAlign(TextAlign.Center)
.layoutWeight(1)
.width('100%')
.backgroundColor(Color.Orange)
}
.width(56)
.height(72)
.clip(true)
.borderRadius(4)
}
}, (item: Material) => item.material_id)
}
.listDirection(Axis.Horizontal)
.width('100%')
.height(72)
}
}
}

View File

@ -26,6 +26,7 @@
"pages/imageknifeTestCaseIndex",
"pages/dataShareUriLoadPage",
"pages/manyPhotoShowPage",
"pages/photosPausedResumedPage",
"pages/tempUrlTestPage",
"pages/drawFactoryTestPage",
"pages/testSingleFrameGifPage",

View File

@ -14,7 +14,7 @@
"main": "index.ets",
"repository": "https://gitee.com/openharmony-tpc/ImageKnife",
"type": "module",
"version": "2.1.1-rc.1",
"version": "2.1.1-rc.2",
"dependencies": {
"@ohos/disklrucache": "^2.0.2-rc.0",
"@ohos/svg": "^2.1.1-rc.0",

View File

@ -211,52 +211,52 @@ export class ImageKnife {
return this.parseSource(request);
}
// // 暂停所有请求
// async pauseRequests(): Promise<void> {
// await this.mutex.lock(async () => {
// this.isPaused = true;
//
// // 将未删除的所有request [run pend] 放入 [pause]
// this.pausedMaps.clear()
// console.log('dodo pauseRequests start1 pausedMaps size=' + this.pausedMaps.size() + ' runMaps Size=' + this.runningMaps.size() + ' pendMaps Size=' + this.pendingMaps.size())
//
// // 将run存入pause
// let runNode = this.runningMaps.getHead();
// while (runNode) {
// let request = runNode.value;
// this.pausedMaps.put(request.uuid, request)
// runNode = runNode.next;
// }
// this.runningMaps.clear();
// console.log('dodo pauseRequests start2 pausedMaps size=' + this.pausedMaps.size() + ' runMaps Size=' + this.runningMaps.size() + ' pendMaps Size=' + this.pendingMaps.size())
//
// let pendNode = this.pendingMaps.getHead();
// while (pendNode) {
// let request = pendNode.value;
// this.pausedMaps.put(request.uuid, request)
// pendNode = pendNode.next
// }
// this.pendingMaps.clear()
// console.log('dodo pauseRequests start3 pausedMaps size=' + this.pausedMaps.size() + ' runMaps Size=' + this.runningMaps.size() + ' pendMaps Size=' + this.pendingMaps.size())
// })
// }
//
// // 恢复所有被暂停的请求
// async resumeRequests(): Promise<void> {
// await this.mutex.lock(async () => {
// this.isPaused = false;
// console.log('dodo resumeRequest start1 pausedMaps size=' + this.pausedMaps.size() + ' runMaps Size=' + this.runningMaps.size() + ' pendMaps Size=' + this.pendingMaps.size())
// // 重启了之后需要把paused 里面的所有request重新发送
// let headNode = this.pausedMaps.getHead();
// while (headNode) {
// let request = headNode.value
// this.loadCacheManager(request)
// headNode = headNode.next
// }
// this.pausedMaps.clear()
// console.log('dodo resumeRequest start1 pausedMaps size=' + this.pausedMaps.size() + ' runMaps Size=' + this.runningMaps.size() + ' pendMaps Size=' + this.pendingMaps.size())
// })
// }
// 暂停所有请求
async pauseRequests(): Promise<void> {
await this.mutex.lock(async () => {
this.isPaused = true;
// 将未删除的所有request [run pend] 放入 [pause]
this.pausedMaps.clear()
LogUtil.log('dodo pauseRequests start1 pausedMaps size=' + this.pausedMaps.size() + ' runMaps Size=' + this.runningMaps.size() + ' pendMaps Size=' + this.pendingMaps.size())
// 将run存入pause
let runNode = this.runningMaps.getHead();
while (runNode) {
let request = runNode.value;
this.pausedMaps.put(request.uuid, request)
runNode = runNode.next;
}
this.runningMaps.clear();
LogUtil.log('dodo pauseRequests start2 pausedMaps size=' + this.pausedMaps.size() + ' runMaps Size=' + this.runningMaps.size() + ' pendMaps Size=' + this.pendingMaps.size())
let pendNode = this.pendingMaps.getHead();
while (pendNode) {
let request = pendNode.value;
this.pausedMaps.put(request.uuid, request)
pendNode = pendNode.next
}
this.pendingMaps.clear()
LogUtil.log('dodo pauseRequests start3 pausedMaps size=' + this.pausedMaps.size() + ' runMaps Size=' + this.runningMaps.size() + ' pendMaps Size=' + this.pendingMaps.size())
})
}
// 恢复所有被暂停的请求
async resumeRequests(): Promise<void> {
await this.mutex.lock(async () => {
this.isPaused = false;
LogUtil.log('dodo resumeRequest start1 pausedMaps size=' + this.pausedMaps.size() + ' runMaps Size=' + this.runningMaps.size() + ' pendMaps Size=' + this.pendingMaps.size())
// 重启了之后需要把paused 里面的所有request重新发送
let headNode = this.pausedMaps.getHead();
while (headNode) {
let request = headNode.value
this.loadCacheManager(request)
headNode = headNode.next
}
this.pausedMaps.clear()
LogUtil.log('dodo resumeRequest start1 pausedMaps size=' + this.pausedMaps.size() + ' runMaps Size=' + this.runningMaps.size() + ' pendMaps Size=' + this.pendingMaps.size())
})
}
// 删除 请求
remove(uuid: string) {

View File

@ -16,7 +16,7 @@ import {ImageKnife} from './ImageKnife'
import { DiskStrategy } from "../cache/diskstrategy/DiskStrategy"
import { AsyncCallback } from "../imageknife/interface/AsyncCallback"
import { AsyncSuccess } from "../imageknife/interface/AsyncSuccess"
import { IAllCacheInfoCallback } from "../imageknife/interface/IAllCacheInfoCallback"
import { IAllCacheInfoCallback } from "../imageknife/interface/IAllCacheInfoCallback"
import { AUTOMATIC } from "../cache/diskstrategy/enum/AUTOMATIC"
import { BaseTransform } from "../imageknife/transform/BaseTransform"
import { RotateImageTransformation } from "../imageknife/transform/RotateImageTransformation"

View File

@ -6,6 +6,6 @@
"name": "imageknife",
"description": "example description",
"repository": {},
"version": "2.1.1-rc.1",
"version": "2.1.1-rc.2",
"dependencies": {}
}