mirror of
https://gitee.com/openharmony/applications_photos
synced 2024-11-23 07:00:09 +00:00
picker支持预选择
Signed-off-by: f00610455 <fanjingyu2@huawei.com>
This commit is contained in:
parent
bc287a5870
commit
e25e4bda36
@ -385,6 +385,49 @@ export class ThirdSelectManager extends SelectManager {
|
||||
return super.clickedSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化图库图片预选择
|
||||
*
|
||||
* @param targetIdList 预选择图库资源Id
|
||||
*/
|
||||
public initPreSelectPhotos(targetIdList: string[]): void {
|
||||
this.deSelectAll();
|
||||
if (this.getMediaItemFunc) {
|
||||
targetIdList.forEach((targetId: string): void => {
|
||||
let containUri = this.selectedMap.has(targetId);
|
||||
if (!containUri) {
|
||||
this.getMediaItemFunc(targetId, (item) => {
|
||||
this.toggleWithItem(targetId, true, item);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 针对指定mediaItem预加载缓存
|
||||
*
|
||||
* @param targetId 图库资源Id
|
||||
* @param isSelected 图库资源是否被选中
|
||||
* @param mediaItem mediaItem
|
||||
* @returns 是否成功
|
||||
*/
|
||||
public toggleWithItem(targetId: string, isSelected: boolean, mediaItem: MediaItem): boolean {
|
||||
if (mediaItem) {
|
||||
let containUri = this.selectedMap.has(targetId);
|
||||
if (isSelected && !containUri) {
|
||||
this.selectedMap.set(targetId, mediaItem);
|
||||
this.indexMap.set(mediaItem, undefined);
|
||||
}
|
||||
if (!isSelected && containUri) {
|
||||
this.selectedMap.delete(targetId);
|
||||
this.indexMap.delete(mediaItem);
|
||||
}
|
||||
return super.toggle(targetId, isSelected, undefined);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public toggle(targetId: string, isSelected: boolean, targetIndex?: number): boolean {
|
||||
if (this.getMediaItemFunc) {
|
||||
let containsUri = this.selectedMap.has(targetId);
|
||||
|
@ -42,6 +42,7 @@ export class SelectParams {
|
||||
cameraAble: boolean;
|
||||
/* whether picker can edit */
|
||||
editAble: boolean;
|
||||
preselectedUris?: string[];
|
||||
uri: string;
|
||||
itemDisplayName: string;
|
||||
itemId: string;
|
||||
|
@ -606,6 +606,20 @@ export struct ThirdSelectPhotoGridBase {
|
||||
}
|
||||
Log.info(TAG, `isEmpty: ${this.isEmpty}`)
|
||||
this.dataSource.onDataReloaded();
|
||||
this.modifyPhotoSelectStatus();
|
||||
}
|
||||
|
||||
/**
|
||||
* 图库预选择
|
||||
*/
|
||||
private modifyPhotoSelectStatus(): void {
|
||||
if (this.selectParams?.preselectedUris?.length > 0) {
|
||||
if (this.selectParams.preselectedUris.length > this.selectParams.maxSelectCount) {
|
||||
this.selectParams.preselectedUris = this.selectParams.preselectedUris.slice(0, this.selectParams.maxSelectCount);
|
||||
}
|
||||
this.selectManager.initPreSelectPhotos(this.selectParams.preselectedUris);
|
||||
this.selectParams.preselectedUris = [];
|
||||
}
|
||||
}
|
||||
|
||||
private initSelectManager() {
|
||||
|
@ -51,6 +51,7 @@ let isShowMenuFromThirdView: boolean;
|
||||
export default class MainAbility extends Ability {
|
||||
private formCurrentUri: string = '';
|
||||
private formAlbumUri: string = '';
|
||||
private preselectedUris: Array<string> = [];
|
||||
private isOnDestroy: boolean = false;
|
||||
private localStorage: LocalStorage = new LocalStorage();
|
||||
|
||||
@ -119,6 +120,7 @@ export default class MainAbility extends Ability {
|
||||
mCallerBundleName = wantParam[Constants.KEY_WANT_PARAMETERS_CALLER_BUNDLE_NAME] as string;
|
||||
mMaxSelectCount = wantParam?.maxSelectCount as number;
|
||||
mFilterMediaType = wantParam?.filterMediaType as string;
|
||||
this.preselectedUris = wantParam?.preselectedUris as Array<string>;
|
||||
AppStorage.SetOrCreate('entryFromHap', Constants.ENTRY_FROM_MULTIPLE_SELECT);
|
||||
SmartPickerUtils.initIfNeeded(this.context, want, this.localStorage);
|
||||
} else if (wantParamUri === Constants.WANT_PARAM_URI_FORM) {
|
||||
@ -254,7 +256,8 @@ export default class MainAbility extends Ability {
|
||||
isMultiPick: true,
|
||||
filterMediaType: mFilterMediaType,
|
||||
isFirstEnter: true,
|
||||
maxSelectCount: mMaxSelectCount
|
||||
maxSelectCount: mMaxSelectCount,
|
||||
preselectedUris: this.preselectedUris,
|
||||
}
|
||||
};
|
||||
router.replaceUrl(options);
|
||||
|
Loading…
Reference in New Issue
Block a user