diff --git a/OAT.xml b/OAT.xml index 960f796..866ae86 100644 --- a/OAT.xml +++ b/OAT.xml @@ -36,6 +36,7 @@ + diff --git a/audiopicker/build-profile.json5 b/audiopicker/build-profile.json5 index a285b90..b695582 100644 --- a/audiopicker/build-profile.json5 +++ b/audiopicker/build-profile.json5 @@ -17,9 +17,6 @@ } }, ], - "entryModules": [ - "audiopicker" - ], "targets": [ { "name": "default" diff --git a/audiopicker/src/main/ets/audiopreference/AudioPickerPreference.ets b/audiopicker/src/main/ets/audiopreference/AudioPickerPreference.ets index de835a0..3fbc6d6 100644 --- a/audiopicker/src/main/ets/audiopreference/AudioPickerPreference.ets +++ b/audiopicker/src/main/ets/audiopreference/AudioPickerPreference.ets @@ -7,7 +7,7 @@ import { MusicApp } from '../common/global/globalmodel/GlobalModel'; import { createOrGet, globalKeys } from '../common/global/GlobalThisHelper' import { PreferenceManager } from '../common/preference/PreferenceManager' -const key_Permission_TipLog = 'Key_Permission_TipLog' +const keyPermissionTipLog = 'Key_Permission_TipLog' const logger: Logger = new Logger('AudioPickerPreference') const app: MusicApp = createOrGet(MusicApp, globalKeys.app, ['phone']); @@ -20,7 +20,7 @@ export class AudioPickerPreference { * @param isFirstStartUp */ public saveSafetyTipStatus(isFirstStartUp: boolean): void { - this.preferenceManager.put(key_Permission_TipLog, isFirstStartUp, true, + this.preferenceManager.put(keyPermissionTipLog, isFirstStartUp, true, this.preferenceManager.preferKeys.audioPicker).then((res) => { logger.info(`saveSafetyTipStatus Success ? : ${res}`) }).catch((err: BusinessError) => { @@ -35,7 +35,7 @@ export class AudioPickerPreference { */ public getSafetyTipStatus(): Promise { return new Promise((resolve) => { - this.preferenceManager.get(key_Permission_TipLog, false, + this.preferenceManager.get(keyPermissionTipLog, false, this.preferenceManager.preferKeys.audioPicker).then((res) => { resolve(res as boolean) }).catch((err: BusinessError) => { diff --git a/audiopicker/src/main/ets/constant/Constants.ets b/audiopicker/src/main/ets/constant/Constants.ets index 5c5e363..0a57f40 100644 --- a/audiopicker/src/main/ets/constant/Constants.ets +++ b/audiopicker/src/main/ets/constant/Constants.ets @@ -13,15 +13,15 @@ export class Constants { /** * Bundle name of audioPicker */ - static readonly AUDIO_PICKER_BUNDLE = 'com.ohos.filepicker'; + public static readonly AUDIO_PICKER_BUNDLE = 'com.ohos.filepicker'; /** * AudioPicker每页请求数量 */ - static readonly PICKER_PAGE_SIZE: number = 100 + public static readonly PICKER_PAGE_SIZE: number = 100 /** * 每次请求参数 */ - static readonly PAGE_COUNT: number = 1 + public static readonly PAGE_COUNT: number = 1 } \ No newline at end of file diff --git a/audiopicker/src/main/ets/localresource/LocalResourceManager.ets b/audiopicker/src/main/ets/localresource/LocalResourceManager.ets index 4c3248d..5e0fc27 100644 --- a/audiopicker/src/main/ets/localresource/LocalResourceManager.ets +++ b/audiopicker/src/main/ets/localresource/LocalResourceManager.ets @@ -31,7 +31,7 @@ export class LocalResourceManager { public terminateSelfWithResult(localAudioFile: Array): Promise> { //赋予权限就放在audiopicker模块,直接调系统接口 return new Promise(async (resolve) => { - let uriList: Array = [] + let uriList: string[] = [] for(let item of localAudioFile) { try { await fileShare.grantUriPermission(item.uri, Constants.AUDIO_PICKER_BUNDLE, wantConstant diff --git a/audiopicker/src/main/ets/localresource/localaudio/LocalAudioFile.ets b/audiopicker/src/main/ets/localresource/localaudio/LocalAudioFile.ets index ed70d18..89d6cb0 100644 --- a/audiopicker/src/main/ets/localresource/localaudio/LocalAudioFile.ets +++ b/audiopicker/src/main/ets/localresource/localaudio/LocalAudioFile.ets @@ -5,17 +5,17 @@ import { image } from '@kit.ImageKit'; export class LocalAudioFile { // 文件uri - uri: string = '' + public uri: string = '' // 名称 - name: string = '' + public name: string = '' // 歌手 - artist: string = '' + public artist: string = '' // 专辑 - album: string = '' + public album: string = '' // 显示名字 - displayName: string = '' + public displayName: string = '' // 缩略图 - getThumbnail?: image.PixelMap | Resource + public getThumbnail?: image.PixelMap | Resource constructor(uri: string, name: string, artist: string, album: string, displayName: string, getThumbnail?: image.PixelMap | Resource) { diff --git a/audiopicker/src/main/ets/localresource/localaudio/LocalAudioManager.ets b/audiopicker/src/main/ets/localresource/localaudio/LocalAudioManager.ets index 519bba2..57afa88 100644 --- a/audiopicker/src/main/ets/localresource/localaudio/LocalAudioManager.ets +++ b/audiopicker/src/main/ets/localresource/localaudio/LocalAudioManager.ets @@ -59,7 +59,7 @@ export class LocalAudioManager { * 将FileAsset转换为LocalAudioFile */ transferFileAssetsToLocalAudioFiles(): Promise> { - let localAudioFile: Array = [] + let localAudioFile: LocalAudioFile[] = [] return new Promise(async (resolve) => { if (this.fileAssets) { logger.info('fileAsset.length :' + this.fileAssets.length); diff --git a/audiopicker/src/main/ets/pages/card/AudioPickerView.ets b/audiopicker/src/main/ets/pages/card/AudioPickerView.ets index b1cdabf..4928caf 100644 --- a/audiopicker/src/main/ets/pages/card/AudioPickerView.ets +++ b/audiopicker/src/main/ets/pages/card/AudioPickerView.ets @@ -2,8 +2,8 @@ * Copyright (c) Huawei Technologies Co., Ltd. 2024-2024. All rights reserved. */ import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession' -import { image } from '@kit.ImageKit'; import { CustomContentDialog } from '@ohos.arkui.advanced.Dialog'; +import { ability, Context, Want } from '@kit.AbilityKit'; import { Logger } from '../../common/util/HiLogger' import { createOrGet, globalKeys } from '../../common/global/GlobalThisHelper' @@ -31,14 +31,14 @@ export struct AudioPickerView { // 是否展示加载更多 @State showLoadMore: boolean = false @State requestCounts: number = 0 - @State thumbnail: Array = [] - @State uriArr: Array = [] + @State isSelect: boolean = false // load more 提前的条目数量 private loadMoreAdvance: number = 3 private pageNo: number = 0; // 设备信息 private globalDeviceInfo: DeviceInfo = createOrGet(DeviceInfo, globalKeys.deviceInfo) session: UIExtensionContentSession | undefined + want: Want | undefined scroller: Scroller = new Scroller() context: Context = getContext(this) // 弹窗知道了按钮回调 @@ -154,16 +154,20 @@ export struct AudioPickerView { * 返回赋予临时权限的uri列表回调 */ async settingTerminateSelfWithResult() { - this.uriArr = await this.localResourceManager.terminateSelfWithResult(this.isSelectedAudioPickerList) - logger.info('uriArr length: ' + this.uriArr.length) + let uriArr = await this.localResourceManager.terminateSelfWithResult(this.isSelectedAudioPickerList) + logger.info('uriArr length: ' + uriArr.length) if (this.session) { - this.session?.terminateSelfWithResult({ - resultCode: this.uriArr ? 0 : -1, + let abilityResult: ability.AbilityResult = { + resultCode: (uriArr === undefined) ? -1 : 0, want: { parameters: { - 'uriArr': this.uriArr + 'ability.params.stream': uriArr, + 'uriArr': uriArr } } + } + this.session?.terminateSelfWithResult(abilityResult, (err) => { + logger.error('terminateSelfWithResult is called: ' + err) }) } else { logger.error(`oncancel session: ${this.session}`) @@ -238,6 +242,14 @@ export struct AudioPickerView { } else { this.isSelectedAudioPickerList = this.isSelectedAudioPickerList.filter(val => val != item) } + let key_pick_num = this.want?.parameters?.key_pick_num + if (key_pick_num) { + if (this.isSelectedAudioPickerList.length < key_pick_num) { + this.isSelect = true + } else { + this.isSelect = false + } + } }) .unselectedColor($r('sys.color.ohos_id_color_switch_outline_off')) .width(20) diff --git a/audiopicker/src/main/ets/pages/model/AudioPickerViewData.ets b/audiopicker/src/main/ets/pages/model/AudioPickerViewData.ets index 6f90917..b628958 100644 --- a/audiopicker/src/main/ets/pages/model/AudioPickerViewData.ets +++ b/audiopicker/src/main/ets/pages/model/AudioPickerViewData.ets @@ -11,13 +11,13 @@ import { BaseState, ViewState } from '../../basemvvm/ViewState' @Observed export class AudioPickerViewData extends AbsBaseViewData { // 页面加载状态 - viewState: ViewState = new ViewState(BaseState.DEFAULT) + public viewState: ViewState = new ViewState(BaseState.DEFAULT) // 页面错误码 - errCode: number = -2 + public errCode: number = -2 // 是否加载更多 - hasMoreData: boolean = false + public hasMoreData: boolean = false // 是否正在加载更多 - isLoadMore: boolean = false + public isLoadMore: boolean = false constructor() { super()