diff --git a/frameworks/js/src/PhotoPickerComponent.ets b/frameworks/js/src/PhotoPickerComponent.ets index 23dd5e9f554e0d6a084a516db3ccfdf9c92ca6d5..bcae0b92b4bb5d30bfe3a3bfb94feb590a64062f 100644 --- a/frameworks/js/src/PhotoPickerComponent.ets +++ b/frameworks/js/src/PhotoPickerComponent.ets @@ -45,6 +45,10 @@ export struct PhotoPickerComponent { onExceedMaxSelected?: ExceedMaxSelectedCallback; onCurrentAlbumDeleted?: CurrentAlbumDeletedCallback; onVideoPlayStateChanged?: VideoPlayStateChangedCallback; + badgeConfig?: BadgeConfig; + batchBadgeConfigSize: number = 1000; + maxBadgeConfigSize: number = 200000; + badgeConfigIsSending: boolean = false; @ObjectLink @Watch('onChanged') pickerController: PickerController; private proxy: UIExtensionProxy | undefined; @State revokeIndex = 0; @@ -72,6 +76,16 @@ export struct PhotoPickerComponent { } } + private onChangedBadgeConfigs(data?: Map) { + console.log('controller onChanged: SET_BADGE_CONFIGS,badgeConfigIsSending:',this.badgeConfigIsSending) + if (this.badgeConfigIsSending !== true) { + this.badgeConfig = data.get('SET_BADGE_CONFIGS'); + this.badgeConfigIsSending = true; + this.badgeConfig.uris?.splice(this.maxBadgeConfigSize); + this.proxy.send({needSendBadgeConfigs: true, BadgeOptionType: data.get('BADGE_CONFIGS_OPTION_TYPE')}); + } + } + private otherOnChange(data?: Map) { if (data?.has('EXIT_PHOTO_BROWSER')) { this.handleExitPhotoBrowser(); @@ -86,6 +100,8 @@ export struct PhotoPickerComponent { } else if (data?.has('SAVE_TRUSTED_PHOTO_ASSETS')) { this.onSaveTrustedPhotoAssets(data); console.info('PhotoPickerComponent onChanged: SAVE_REPLACE_PHOTO_ASSETS'); + } else if (data?.has('SET_BADGE_CONFIGS')) { + this.onChangedBadgeConfigs(data); } else { console.info('PhotoPickerComponent onChanged: other case'); } @@ -242,12 +258,17 @@ export struct PhotoPickerComponent { } else if (dataType === 'remoteReady') { if (this.onPickerControllerReady) { this.onPickerControllerReady(); + if(this.badgeConfig && this.badgeConfig.uris.length > 0) { + console.log('handleOnReceive: send msg to photo:uri.length:',this.badgeConfig?.uris?.length) + this.badgeConfigIsSending = true; + this.proxy.send({needSendBadgeConfigs : true, BadgeOptionType : BadgeOptionType.SET_DATA}); + } console.info('PhotoPickerComponent onReceive: onPickerControllerReady'); } } else if (dataType === 'onPhotoBrowserChanged') { this.handlePhotoBrowserChange(wantParam); } else if (dataType === 'onVideoPlayStateChanged') { - this.handleVideoPlayStateChange(wantParam) + this.handleVideoPlayStateChange(wantParam); } else if (dataType === 'replaceCallback') { this.handleReplaceCallback(wantParam); } else if (dataType === 'createCallback') { @@ -257,6 +278,9 @@ export struct PhotoPickerComponent { } else if (dataType === 'onBackground') { console.info('PhotoPickerComponent onReceive: onBackground'); this.revokeIndex = 0; + } else if (dataType === 'onBadgeConfigSend') { + this.handleBadgeConfigSend(wantParam) + console.info('PhotoPickerComponent onReceive: onBadgeConfigSend'); } else { this.handleOtherOnReceive(wantParam); console.info('PhotoPickerComponent onReceive: other case'); @@ -264,6 +288,20 @@ export struct PhotoPickerComponent { console.info('PhotoPickerComponent onReceive' + this.pickerController.encrypt(JSON.stringify(wantParam))); } + private handleBadgeConfigSend(wantParam: Record): void { + let index = wantParam.nextIndex as string; + if (this.badgeConfig && this.badgeConfig.uris.length > 0) { + const unitBadgeConfig = this.badgeConfig.uris.slice(this.batchBadgeConfigSize * size, this.batchBadgeConfigSize * (index + 1)); + console.log('handleBadgeConfigSend: send piece msg to photo index-:',index,'----',unitBadgeConfig.length) + this.proxy.send({badgeConfig : unitBadgeConfig, index: index, + isOver : index >= Math.ceil(this.badgeConfig.uris.length / this.batchBadgeConfigSize) ? true : false, + badgeConfigType : this.badgeConfig.badgeType}); + } + if (index >= Math.ceil(this.badgeConfig.uris.length / this.batchBadgeConfigSize)) { + this.badgeConfigIsSending = false; + } + } + private handleOtherOnReceive(wantParam: Record): void { let dataType = wantParam.dataType as string; if (dataType === 'exceedMaxSelected') { @@ -370,7 +408,7 @@ export struct PhotoPickerComponent { private handleVideoPlayStateChange(wantParam: Record): void { if (this.onVideoPlayStateChanged) { - this.onVideoPlayStateChanged(wantParam.state as VideoPlayerState) + this.onVideoPlayStateChanged(wantParam.state as VideoPlayerState); } console.info('PhotoPickerComponent onReceive: onVideoPlayStateChanged = ' + JSON.stringify(wantParam)); } @@ -436,7 +474,7 @@ export struct PhotoPickerComponent { singleLineConfig.itemDisplayRatio; singleLineConfig.itemBorderRadius = this.getSingleLineConfigItemBorderRadius(singleLineConfig.itemBorderRadius); singleLineConfig.itemGap = this.getLength(singleLineConfig.itemGap); - return singleLineConfig + return singleLineConfig; } private getSingleLineConfigItemBorderRadius(itemBorderRadius?: Length | BorderRadiuses | @@ -587,6 +625,11 @@ export class PickerController { this.data = new Map([['SET_ALBUM_URI', albumUri]]); console.info('PhotoPickerComponent SET_ALBUM_URI' + this.encrypt(JSON.stringify(albumUri))); } + } else if (type === DataType.SET_BADGE_CONFIGS) { + let uris: string = data as string; + if (uris !== undefined) { + this.data = new Map([['SET_BADGE_CONFIGS', uris], ['BADGE_CONFIGS_OPTION_TYPE',BadgeOptionType.SET_DATA]]); + console.info('PhotoPickerComponent SET_BADGE_CONFIGS' + this.encrypt(JSON.stringify(uris))); } else if (type === DataType.SET_SELECTED_INFO) { let uriAndPickerIndexLists: Array = data as Array; if (uriAndPickerIndexLists !== undefined) { @@ -598,6 +641,32 @@ export class PickerController { } } + addData(type: DataType, data: Object) { + if (data === undefined) { + return; + } + if (type === DataType.SET_BADGE_CONFIGS) { + let uris = data as string; + if (uris !== undefined) { + this.data = new Map([['SET_BADGE_CONFIGS', e], ['BADGE_CONFIGS_OPTION_TYPE', BadgeOptionType.ADD_DATA]]); + } + return; + } + } + + deleteData(type: DataType, data: Object) { + if (data === undefined) { + return; + } + if (type === DataType.SET_BADGE_CONFIGS) { + let uris = data as string; + if (uris !== undefined) { + this.data = new Map([['SET_BADGE_CONFIGS', e], ['BADGE_CONFIGS_OPTION_TYPE', BadgeOptionType.DELETE_DATA]]); + } + return; + } + } + setMaxSelected(maxSelected: MaxSelected) { if (maxSelected) { this.data = new Map([['SET_MAX_SELECT_COUNT', maxSelected]]); @@ -800,6 +869,10 @@ class PhotoBrowserUIElementVisibility { isVisible?: boolean; } +export class BadgeConfig { + badgeConfigType?: BadgeTypes, + uris?: string[] +} class PreselectedInfo { uri:string; preselectablePickerIndex?: number = -1; @@ -875,4 +948,14 @@ export enum SaveMode { export enum ItemDisplayRatio { SQUARE_RATIO = 0, ORIGINAL_SIZE_RATIO = 1 +} + +export enum BadgeTypes { + BADGE_UPLOADED = 1 +} + +export enum BadgeOptionType { + SET_DATA = 1, + ADD_DATA = 2, + DELETE_DATA = 3 } \ No newline at end of file diff --git a/frameworks/js/src/photopickercomponent.js b/frameworks/js/src/photopickercomponent.js index 5adc8ae9a7bbf9dceb5682a9da145172035c2265..b1de33b20ef411f84c9d54685fcef650cc413e71 100644 --- a/frameworks/js/src/photopickercomponent.js +++ b/frameworks/js/src/photopickercomponent.js @@ -53,6 +53,10 @@ export class PhotoPickerComponent extends ViewPU { this.onExceedMaxSelected = void 0; this.onCurrentAlbumDeleted = void 0; this.onVideoPlayStateChanged = void 0; + this.badgeConfig = void 0; + this.batchBadgeConfigSize = 1000; + this.maxBadgeConfigSize = 200000; + this.badgeConfigIsSending = void 0; this.__pickerController = new SynchedPropertyNesedObjectPU(o.pickerController, this, 'pickerController'); this.proxy = void 0; this.__revokeIndex = new ObservedPropertySimplePU(0, this, 'revokeIndex'); @@ -73,7 +77,13 @@ export class PhotoPickerComponent extends ViewPU { void 0 !== e.onExceedMaxSelected && (this.onExceedMaxSelected = e.onExceedMaxSelected); void 0 !== e.onCurrentAlbumDeleted && (this.onCurrentAlbumDeleted = e.onCurrentAlbumDeleted); void 0 !== e.onVideoPlayStateChanged && (this.onVideoPlayStateChanged = e.onVideoPlayStateChanged); + void 0 !== e.pickerOptions.badgeConfig && (this.badgeConfig = e.pickerOptions.badgeConfig); this.__pickerController.set(e.pickerController); + if (this.badgeConfig && this.badgeConfig.uris !== undefined) { + console.log('badgeConfig.uris.length:' + this.badgeConfig.uris.length); + console.log('badgeConfig.badge_type:' + this.badgeConfig.badgeType); + this.badgeConfig.uris.splice(this.maxBadgeConfigSize); + } void 0 !== e.proxy && (this.proxy = e.proxy); if (e.revokeIndex !== undefined) { this.revokeIndex = e.revokeIndex; @@ -134,6 +144,18 @@ export class PhotoPickerComponent extends ViewPU { } } + onChangedBadgeConfigs(o) { + console.log('PhotoPickerComponent onChanged: onChangedBadgeConfigs'); + if (this.badgeConfigIsSending !== true) { + console.log('badgeConfigType:' + o.get('BADGE_CONFIGS_OPTION_TYPE')); + this.badgeConfig = o.get('SET_BADGE_CONFIGS'); + this.badgeConfigIsSending = true; + this.badgeConfig.uris?.splice(this.maxBadgeConfigSize); + this.proxy.send({needSendBadgeConfigs: true, BadgeOptionType: o.get('BADGE_CONFIGS_OPTION_TYPE')}); + console.log('badgeConfig.uris.length:' + this.badgeConfig?.uris?.length || '--'); + } + } + otherOnChange(o) { if (null == o ? void 0 : o.has('SET_PHOTO_BROWSER_UI_ELEMENT_VISIBILITY')) { this.onSetPhotoBrowserUIElementVisibility(o); @@ -146,6 +168,8 @@ export class PhotoPickerComponent extends ViewPU { } else if (null == o ? void 0 : o.has('SAVE_REPLACE_PHOTO_ASSETS')) { this.onSaveTrustedPhotoAssets(o); console.info('PhotoPickerComponent onChanged: SAVE_REPLACE_PHOTO_ASSETS'); + } else if (null == o ? void 0 : o.has('SET_BADGE_CONFIGS')) { + this.onChangedBadgeConfigs(o); } else { console.info('PhotoPickerComponent onChanged: other case'); } @@ -308,6 +332,12 @@ export class PhotoPickerComponent extends ViewPU { } else if ('remoteReady' === o) { if (this.onPickerControllerReady) { this.onPickerControllerReady(); + if (this.badgeConfig && this.badgeConfig?.uris?.length > 0) { + console.log('i need send msg to photo' + this.badgeConfig?.uris?.length + '---' + + this.badgeConfig?.badgeType + '---' + new Date().getTime().toString()); + this.badgeConfigIsSending = true; + this.proxy.send({needSendBadgeConfigs: true, BadgeOptionType: BadgeOptionType.SET_DATA}); + } console.info('PhotoPickerComponent onReceive: onPickerControllerReady'); } } else if ('replaceCallback' === o) { @@ -320,6 +350,8 @@ export class PhotoPickerComponent extends ViewPU { this.handlePhotoBrowserChange(e); } else if ('onVideoPlayStateChanged' === o) { this.handleVideoPlayStateChanged(e); + } else if ('onBadgeConfigSend' === o) { + this.handleBadgeConfigSend(e); } else { this.handleOtherOnReceive(e); console.info('PhotoPickerComponent onReceive: other case'); @@ -327,6 +359,23 @@ export class PhotoPickerComponent extends ViewPU { console.info('PhotoPickerComponent onReceive' + this.pickerController.encrypt(JSON.stringify(e))); } + handleBadgeConfigSend(e) { + let index = e.nextIndex; + if (this.badgeConfig && this.badgeConfig?.uris?.length > 0) { + console.log('handleBadgeConfigSend uris.length: ' + this.badgeConfig.uris.length); + const unitBadgeConfig = this.badgeConfig.uris.slice(this.batchBadgeConfigSize * index, this.batchBadgeConfigSize * (index + 1)); + console.log('index,unitunitBadgeConfig.length' + unitBadgeConfig?.length + 'index: ' + index + + 'this.badgeConfig.uris.length: ' + this.badgeConfig?.uris?.length + ); + this.proxy.send({badgeConfig : unitBadgeConfig, index: index, + isOver : index >= Math.ceil(this.badgeConfig.uris.length / this.batchBadgeConfigSize) ? true : false, + badgeConfigType : this.badgeConfig.badgeType}); + } + if (index >= Math.ceil(this.badgeConfig.uris.length / this.batchBadgeConfigSize)) { + this.badgeConfigIsSending = false; + } + } + handleOtherOnReceive(e) { let o = e.dataType; if ('exceedMaxSelected' === o) { @@ -607,6 +656,13 @@ let PickerController = class { this.data = new Map([['SET_ALBUM_URI', e]]); console.info('PhotoPickerComponent SET_ALBUM_URI' + this.encrypt(JSON.stringify(e))); } + } else if (e === DataType.SET_BADGE_CONFIGS) { + let e = o; + if (e !== undefined) { + this.data = new Map([['SET_BADGE_CONFIGS', e], ['BADGE_CONFIGS_OPTION_TYPE', BadgeOptionType.SET_DATA]]); + console.info('PhotoPickerComponent SET_BADGE_CONFIGS' + this.encrypt(JSON.stringify(e))); + console.info('PhotoPickerComponent BADGE_CONFIGS_OPTION_TYPE: set_data'); + } } else if (e === DataType.SET_SELECTED_INFO) { if (o instanceof Array) { let e = o; @@ -617,6 +673,37 @@ let PickerController = class { } } else { console.info('PhotoPickerComponent setData: other case'); + } + } + + addData(e, o) { + if (o === undefined) { + return; + } + if (e === DataType.SET_BADGE_CONFIGS) { + let e = o; + if (e !== undefined) { + this.data = new Map([['SET_BADGE_CONFIGS', e], ['BADGE_CONFIGS_OPTION_TYPE', BadgeOptionType.ADD_DATA]]); + console.info('PhotoPickerComponent SET_BADGE_CONFIGS' + this.encrypt(JSON.stringify(e))); + console.info('PhotoPickerComponent BADGE_CONFIGS_OPTION_TYPE: add_data'); + } + return; + } + } + + deleteData(e, o) { + if (o === undefined) { + return; + } + if (e === DataType.SET_BADGE_CONFIGS) { + let e = o; + if (e !== undefined) { + this.data = new Map([['SET_BADGE_CONFIGS', e], ['BADGE_CONFIGS_OPTION_TYPE', BadgeOptionType.DELETE_DATA]]); + console.info('PhotoPickerComponent SET_BADGE_CONFIGS' + this.encrypt(JSON.stringify(e))); + console.info('PhotoPickerComponent BADGE_CONFIGS_OPTION_TYPE: delete_data'); + + } + return; } } @@ -786,11 +873,16 @@ export class SingleLineConfig { } } +export class BadgeConfig { + +} + export var DataType; !function(e) { e[e.SET_SELECTED_URIS = 1] = 'SET_SELECTED_URIS'; e[e.SET_ALBUM_URI = 2] = 'SET_ALBUM_URI'; e[e.SET_SELECTED_INFO = 3] = 'SET_SELECTED_INFO'; + e[e.SET_BADGE_CONFIGS = 4] = 'SET_BADGE_CONFIGS'; }(DataType || (DataType = {})); export var ItemType; @@ -871,6 +963,18 @@ export var ItemDisplayRatio; e[e.ORIGINAL_SIZE_RATIO = 1] = 'ORIGINAL_SIZE_RATIO'; }(ItemDisplayRatio || (ItemDisplayRatio = {})); +export var BadgeTypes; +!function(e) { + e[e.BADGE_UPLOADED = 1] = 'BADGE_UPLOADED'; +}(BadgeTypes || (BadgeTypes = {})); + +export var BadgeOptionType; +!function(e) { + e[e.SET_DATA = 1] = 'SET_DATA'; + e[e.ADD_DATA = 2] = 'ADD_DATA'; + e[e.DELETE_DATA = 3] = 'DELETE_DATA'; +}(BadgeOptionType || (BadgeOptionType = {})); + export default { PhotoPickerComponent, PickerController, PickerOptions, DataType, BaseItemInfo, ItemInfo, PhotoBrowserInfo, AnimatorParams, MaxSelected, ItemType, ClickType, PickerOrientation, SelectMode, PickerColorMode, ReminderMode, MaxCountType, PhotoBrowserRange, PhotoBrowserUIElement, - VideoPlayerState, SaveMode, SingleLineConfig, ItemDisplayRatio }; \ No newline at end of file + VideoPlayerState, SaveMode, SingleLineConfig, ItemDisplayRatio, BadgeOptionType, BadgeTypes, BadgeConfig }; \ No newline at end of file