1.更新占位图解析
2.新增重试占位图解析 Signed-off-by: zhoulisheng1 <zhoulisheng1@huawei.com>
This commit is contained in:
parent
164fa1c515
commit
c1c3ce210f
|
@ -13,12 +13,14 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import {RequestOption} from "../../imageknife/RequestOption"
|
||||
import {FileTypeUtil} from "../../imageknife/utils/FileTypeUtil"
|
||||
import {ImageKnifeData} from "../ImageKnifeData"
|
||||
import {ParseImageUtil} from '../utils/ParseImageUtil'
|
||||
import {ParseResClient} from '../resourcemanage/ParseResClient'
|
||||
import image from "@ohos.multimedia.image"
|
||||
import { RequestOption } from '../../imageknife/RequestOption'
|
||||
import { FileTypeUtil } from '../../imageknife/utils/FileTypeUtil'
|
||||
import { ImageKnifeData, ImageKnifeType } from '../ImageKnifeData'
|
||||
import { ParseImageUtil } from '../utils/ParseImageUtil'
|
||||
import { SupportFormat } from '../utils/FileTypeUtil'
|
||||
import { SVGParseImpl } from '../utils/svg/SVGParseImpl'
|
||||
import { ParseResClient } from '../resourcemanage/ParseResClient'
|
||||
import image from '@ohos.multimedia.image'
|
||||
|
||||
export class ErrorHolderManager {
|
||||
private options: RequestOption;
|
||||
|
@ -30,7 +32,7 @@ export class ErrorHolderManager {
|
|||
static execute(option: RequestOption) {
|
||||
let manager = new ErrorHolderManager(option);
|
||||
return new Promise(manager.process.bind(manager))
|
||||
.then(option.errorholderOnComplete.bind(option)).catch(option.errorholderOnError.bind(option));
|
||||
.then(option.errorholderOnComplete.bind(option)).catch(option.errorholderOnError.bind(option));
|
||||
}
|
||||
|
||||
process(onComplete, onError) {
|
||||
|
@ -40,9 +42,7 @@ export class ErrorHolderManager {
|
|||
private displayErrorholder(onComplete, onError) {
|
||||
console.log("displayErrorholder")
|
||||
if ((typeof (this.options.errorholderSrc as image.PixelMap).isEditable) == 'boolean') {
|
||||
let imageKnifeData = new ImageKnifeData();
|
||||
imageKnifeData.imageKnifeType = ImageKnifeData.PIXELMAP
|
||||
imageKnifeData.imageKnifeValue = this.options.placeholderSrc as PixelMap
|
||||
let imageKnifeData = ImageKnifeData.createImagePixelMap(ImageKnifeType.PIXELMAP, this.options.errorholderSrc as PixelMap)
|
||||
onComplete(imageKnifeData);
|
||||
} else if (typeof this.options.errorholderSrc == 'string') {
|
||||
|
||||
|
@ -53,22 +53,21 @@ export class ErrorHolderManager {
|
|||
let suc = (arraybuffer) => {
|
||||
let fileTypeUtil = new FileTypeUtil();
|
||||
let typeValue = fileTypeUtil.getFileType(arraybuffer);
|
||||
if ("gif" == typeValue || "svg" == typeValue) {
|
||||
let imageKnifeData = new ImageKnifeData();
|
||||
imageKnifeData.imageKnifeType = "Resource"
|
||||
imageKnifeData.imageKnifeValue = this.options.errorholderSrc as Resource
|
||||
imageKnifeData.imageKnifeSourceType = typeValue;
|
||||
onComplete(imageKnifeData);
|
||||
} else {
|
||||
let parseImageUtils = new ParseImageUtil();
|
||||
let success = (value: PixelMap) => {
|
||||
let imageKnifeData = new ImageKnifeData();
|
||||
imageKnifeData.imageKnifeType = "PixelMap"
|
||||
imageKnifeData.imageKnifeValue = value
|
||||
imageKnifeData.imageKnifeSourceType = typeValue;
|
||||
onComplete(imageKnifeData);
|
||||
}
|
||||
parseImageUtils.parseImage(arraybuffer, success, onError)
|
||||
switch (typeValue) {
|
||||
case SupportFormat.svg:
|
||||
this.svgProcess(onComplete, onError, arraybuffer, typeValue)
|
||||
break;
|
||||
case SupportFormat.jpg:
|
||||
case SupportFormat.png:
|
||||
case SupportFormat.bmp:
|
||||
case SupportFormat.gif:
|
||||
case SupportFormat.tiff:
|
||||
case SupportFormat.webp:
|
||||
this.mediaImageProcess(onComplete, onError, arraybuffer, typeValue)
|
||||
break;
|
||||
default:
|
||||
onError("ErrorHolderManager 文件类型不支持")
|
||||
break;
|
||||
}
|
||||
}
|
||||
resourceFetch.loadResource(res, suc, onError)
|
||||
|
@ -77,4 +76,24 @@ export class ErrorHolderManager {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private svgProcess(onComplete, onError, arraybuffer, typeValue) {
|
||||
let svgParseImpl = new SVGParseImpl()
|
||||
let size = { width: this.options.size.width, height: this.options.size.height }
|
||||
svgParseImpl.parseSvg(arraybuffer, size).then((value: PixelMap) => {
|
||||
let imageKnifeData = ImageKnifeData.createImagePixelMap(ImageKnifeType.PIXELMAP, value)
|
||||
onComplete(imageKnifeData)
|
||||
}).catch(err => {
|
||||
onError(err)
|
||||
})
|
||||
}
|
||||
|
||||
private mediaImageProcess(onComplete, onError, arraybuffer, typeValue) {
|
||||
let parseImageUtil = new ParseImageUtil()
|
||||
let success = (value: PixelMap) => {
|
||||
let imageKnifeData = ImageKnifeData.createImagePixelMap(ImageKnifeType.PIXELMAP, value)
|
||||
onComplete(imageKnifeData)
|
||||
}
|
||||
parseImageUtil.parseImage(arraybuffer, success, onError)
|
||||
}
|
||||
}
|
|
@ -16,9 +16,11 @@ import {RequestOption} from "../../imageknife/RequestOption"
|
|||
import {ResourceTypeEts} from "../../imageknife/constants/ResourceTypeEts"
|
||||
import {Base64} from "../../cache/Base64"
|
||||
import {FileTypeUtil} from "../../imageknife/utils/FileTypeUtil"
|
||||
import {ImageKnifeData} from "../ImageKnifeData"
|
||||
import {ImageKnifeData,ImageKnifeType} from "../ImageKnifeData"
|
||||
import {ParseImageUtil} from '../utils/ParseImageUtil'
|
||||
import {ParseResClient} from '../resourcemanage/ParseResClient'
|
||||
import { SupportFormat } from '../utils/FileTypeUtil'
|
||||
import { SVGParseImpl } from '../utils/svg/SVGParseImpl'
|
||||
import resourceManager from '@ohos.resourceManager';
|
||||
import image from "@ohos.multimedia.image"
|
||||
|
||||
|
@ -42,9 +44,7 @@ export class PlaceHolderManager {
|
|||
private displayPlaceholder(onComplete, onError) {
|
||||
console.log("displayPlaceholder")
|
||||
if ((typeof (this.options.placeholderSrc as image.PixelMap).isEditable) == 'boolean') {
|
||||
let imageKnifeData = new ImageKnifeData();
|
||||
imageKnifeData.imageKnifeType = ImageKnifeData.PIXELMAP
|
||||
imageKnifeData.imageKnifeValue = this.options.placeholderSrc as PixelMap
|
||||
let imageKnifeData = ImageKnifeData.createImagePixelMap(ImageKnifeType.PIXELMAP, this.options.placeholderSrc as PixelMap)
|
||||
onComplete(imageKnifeData);
|
||||
} else if (typeof this.options.placeholderSrc == 'string') {
|
||||
|
||||
|
@ -55,16 +55,21 @@ export class PlaceHolderManager {
|
|||
let suc = (arraybuffer) => {
|
||||
let fileTypeUtil = new FileTypeUtil();
|
||||
let typeValue = fileTypeUtil.getFileType(arraybuffer);
|
||||
if ("gif" == typeValue || "svg" == typeValue) {
|
||||
let imageKnifeData = this.createImageKnifeData("Resource", this.options.placeholderSrc as Resource, typeValue);
|
||||
onComplete(imageKnifeData);
|
||||
} else {
|
||||
let parseImageUtils = new ParseImageUtil();
|
||||
let success = (value: PixelMap) => {
|
||||
let imageKnifeData = this.createImageKnifeData('PixelMap', value, typeValue);
|
||||
onComplete(imageKnifeData);
|
||||
}
|
||||
parseImageUtils.parseImage(arraybuffer, success, onError)
|
||||
switch (typeValue) {
|
||||
case SupportFormat.svg:
|
||||
this.svgProcess(onComplete, onError, arraybuffer, typeValue)
|
||||
break;
|
||||
case SupportFormat.jpg:
|
||||
case SupportFormat.png:
|
||||
case SupportFormat.bmp:
|
||||
case SupportFormat.gif:
|
||||
case SupportFormat.tiff:
|
||||
case SupportFormat.webp:
|
||||
this.mediaImageProcess(onComplete, onError, arraybuffer, typeValue)
|
||||
break;
|
||||
default:
|
||||
onError("PlaceHolderManager 文件类型不支持")
|
||||
break;
|
||||
}
|
||||
}
|
||||
resourceFetch.loadResource(res, suc, onError)
|
||||
|
@ -73,11 +78,26 @@ export class PlaceHolderManager {
|
|||
}
|
||||
}
|
||||
}
|
||||
private createImageKnifeData(imageKnifeType:string, imageKnifeValue:PixelMap|string|Resource, imageKnifeSourceType:string):ImageKnifeData{
|
||||
let imageKnifeData = new ImageKnifeData();
|
||||
imageKnifeData.imageKnifeType = imageKnifeType;
|
||||
imageKnifeData.imageKnifeValue = imageKnifeValue;
|
||||
imageKnifeData.imageKnifeSourceType = imageKnifeSourceType;
|
||||
return imageKnifeData;
|
||||
|
||||
|
||||
|
||||
private svgProcess(onComplete, onError, arraybuffer, typeValue) {
|
||||
let svgParseImpl = new SVGParseImpl()
|
||||
let size = { width: this.options.size.width, height: this.options.size.height }
|
||||
svgParseImpl.parseSvg(arraybuffer, size).then((value: PixelMap) => {
|
||||
let imageKnifeData = ImageKnifeData.createImagePixelMap(ImageKnifeType.PIXELMAP, value)
|
||||
onComplete(imageKnifeData)
|
||||
}).catch(err => {
|
||||
onError(err)
|
||||
})
|
||||
}
|
||||
|
||||
private mediaImageProcess(onComplete, onError, arraybuffer, typeValue) {
|
||||
let parseImageUtil = new ParseImageUtil()
|
||||
let success = (value: PixelMap) => {
|
||||
let imageKnifeData = ImageKnifeData.createImagePixelMap(ImageKnifeType.PIXELMAP, value)
|
||||
onComplete(imageKnifeData)
|
||||
}
|
||||
parseImageUtil.parseImage(arraybuffer, success, onError)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,103 @@
|
|||
/*
|
||||
* 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 {RequestOption} from "../../imageknife/RequestOption"
|
||||
import {ResourceTypeEts} from "../../imageknife/constants/ResourceTypeEts"
|
||||
import {Base64} from "../../cache/Base64"
|
||||
import {FileTypeUtil} from "../../imageknife/utils/FileTypeUtil"
|
||||
import {ImageKnifeData,ImageKnifeType} from "../ImageKnifeData"
|
||||
import {ParseImageUtil} from '../utils/ParseImageUtil'
|
||||
import {ParseResClient} from '../resourcemanage/ParseResClient'
|
||||
import { SupportFormat } from '../utils/FileTypeUtil'
|
||||
import { SVGParseImpl } from '../utils/svg/SVGParseImpl'
|
||||
import resourceManager from '@ohos.resourceManager';
|
||||
import image from "@ohos.multimedia.image"
|
||||
|
||||
export class RetryHolderManager {
|
||||
private options: RequestOption;
|
||||
|
||||
constructor(option: RequestOption) {
|
||||
this.options = option;
|
||||
}
|
||||
|
||||
static execute(option: RequestOption) {
|
||||
let manager = new RetryHolderManager(option);
|
||||
return new Promise(manager.process.bind(manager))
|
||||
.then(option.retryholderOnComplete.bind(option)).catch(option.retryholderOnError.bind(option));
|
||||
}
|
||||
|
||||
process(onComplete, onError) {
|
||||
this.displayRetryholder(onComplete, onError);
|
||||
}
|
||||
|
||||
private displayRetryholder(onComplete, onError) {
|
||||
console.log("displayRetryholder")
|
||||
if ((typeof (this.options.retryholderSrc as image.PixelMap).isEditable) == 'boolean') {
|
||||
let imageKnifeData = ImageKnifeData.createImagePixelMap(ImageKnifeType.PIXELMAP, this.options.placeholderSrc as PixelMap)
|
||||
onComplete(imageKnifeData);
|
||||
} else if (typeof this.options.placeholderSrc == 'string') {
|
||||
|
||||
} else {
|
||||
let res = this.options.retryholderSrc as Resource;
|
||||
if (typeof res.id != 'undefined' && typeof res.id != 'undefined') {
|
||||
let resourceFetch = new ParseResClient();
|
||||
let suc = (arraybuffer) => {
|
||||
let fileTypeUtil = new FileTypeUtil();
|
||||
let typeValue = fileTypeUtil.getFileType(arraybuffer);
|
||||
switch (typeValue) {
|
||||
case SupportFormat.svg:
|
||||
this.svgProcess(onComplete, onError, arraybuffer, typeValue)
|
||||
break;
|
||||
case SupportFormat.jpg:
|
||||
case SupportFormat.png:
|
||||
case SupportFormat.bmp:
|
||||
case SupportFormat.gif:
|
||||
case SupportFormat.tiff:
|
||||
case SupportFormat.webp:
|
||||
this.mediaImageProcess(onComplete, onError, arraybuffer, typeValue)
|
||||
break;
|
||||
default:
|
||||
onError("PlaceHolderManager 文件类型不支持")
|
||||
break;
|
||||
}
|
||||
}
|
||||
resourceFetch.loadResource(res, suc, onError)
|
||||
} else {
|
||||
onError("PlaceHolderManager 输入参数有问题!")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private svgProcess(onComplete, onError, arraybuffer, typeValue) {
|
||||
let svgParseImpl = new SVGParseImpl()
|
||||
let size = { width: this.options.size.width, height: this.options.size.height }
|
||||
svgParseImpl.parseSvg(arraybuffer, size).then((value: PixelMap) => {
|
||||
let imageKnifeData = ImageKnifeData.createImagePixelMap(ImageKnifeType.PIXELMAP, value)
|
||||
onComplete(imageKnifeData)
|
||||
}).catch(err => {
|
||||
onError(err)
|
||||
})
|
||||
}
|
||||
|
||||
private mediaImageProcess(onComplete, onError, arraybuffer, typeValue) {
|
||||
let parseImageUtil = new ParseImageUtil()
|
||||
let success = (value: PixelMap) => {
|
||||
let imageKnifeData = ImageKnifeData.createImagePixelMap(ImageKnifeType.PIXELMAP, value)
|
||||
onComplete(imageKnifeData)
|
||||
}
|
||||
parseImageUtil.parseImage(arraybuffer, success, onError)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue