1.ArkTs整改11 整改imageknife->resourcemanager

Signed-off-by: zhoulisheng1 <zhoulisheng1@huawei.com>
This commit is contained in:
zhoulisheng1 2023-09-19 16:51:01 +08:00
parent 76ab03262f
commit 3595190083
3 changed files with 19 additions and 20 deletions

View File

@ -13,9 +13,8 @@
* limitations under the License.
*/
import {RequestOption} from "../RequestOption"
import { BusinessError } from '@ohos.base'
// 本地资源解析抽象接口
export interface IResourceFetch {
loadResource(res: Resource, onCompleteFunction, onErrorFunction);
export interface IResourceFetch<T> {
loadResource:(res: Resource, onCompleteFunction:(value:T)=>void | PromiseLike<T>, onErrorFunction:(reason?:BusinessError|string)=>void)=>void;
}

View File

@ -13,14 +13,13 @@
* limitations under the License.
*/
import type {IResourceFetch} from '../resourcemanage/IResourceFetch'
import {IResourceFetch} from '../resourcemanage/IResourceFetch'
import {ResourceTypeEts} from '../../imageknife/constants/ResourceTypeEts'
import resourceManager from '@ohos.resourceManager';
import { ImageKnifeGlobal } from '../ImageKnifeGlobal';
export class ParseResClient implements IResourceFetch {
loadResource(res: Resource, onCompleteFunction, onErrorFunction) {
import { BusinessError } from '@ohos.base'
export class ParseResClient implements IResourceFetch<ArrayBuffer> {
loadResource(res: Resource, onCompleteFunction:(value:ArrayBuffer)=>void | PromiseLike<ArrayBuffer>, onErrorFunction:(reason?:BusinessError|string)=>void) {
let resId = res.id;
let resType = res.type;
if (resType == ResourceTypeEts.MEDIA) {
@ -30,7 +29,7 @@ export class ParseResClient implements IResourceFetch {
let arrayBuffer = this.typedArrayToBuffer(data);
onCompleteFunction(arrayBuffer)
})
.catch(err => {
.catch( (err:BusinessError) => {
onErrorFunction(err)
})
}

View File

@ -13,31 +13,32 @@
* limitations under the License.
*/
import type {IResourceFetch} from '../resourcemanage/IResourceFetch'
import {ResourceTypeEts} from '../../imageknife/constants/ResourceTypeEts'
import {Base64} from '../../cache/Base64'
import { IResourceFetch } from '../resourcemanage/IResourceFetch'
import { ResourceTypeEts } from '../../imageknife/constants/ResourceTypeEts'
import { Base64 } from '../../cache/Base64'
import { BusinessError } from '@ohos.base'
import resourceManager from '@ohos.resourceManager';
import { ImageKnifeGlobal } from '../ImageKnifeGlobal';
export class ParseResClientBase64 implements IResourceFetch {
loadResource(res: Resource, onCompleteFunction, onErrorFunction) {
export class ParseResClientBase64 implements IResourceFetch<ArrayBuffer> {
loadResource(res: Resource, onCompleteFunction: (value: ArrayBuffer) => void | PromiseLike<ArrayBuffer>, onErrorFunction: (reason?: BusinessError | string) => void) {
let resId = res.id;
let resType = res.type;
if (resType == ResourceTypeEts.MEDIA) {
((ImageKnifeGlobal.getInstance().getHapContext() as Record<string,Object>).resourceManager as resourceManager.ResourceManager)
((ImageKnifeGlobal.getInstance()
.getHapContext() as Record<string, Object>).resourceManager as resourceManager.ResourceManager)
.getMediaContentBase64(resId)
.then(data => {
let matchReg = ';base64,';
var firstIndex = data.indexOf(matchReg)
let firstIndex = data.indexOf(matchReg)
data = data.substring(firstIndex + matchReg.length, data.length)
let arrayBuffer = Base64.getInstance()
.decode(data);
onCompleteFunction(arrayBuffer)
})
.catch(err => {
.catch((err: BusinessError) => {
onErrorFunction(err)
})
})
}
else if (resType == ResourceTypeEts.RAWFILE) {
onErrorFunction('ParseResClientBase64 本地资源是rawfile暂时无法解析出错')