diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index 09bc1fea6dbe0f0fbc80cdc9fb8b8c0dd9365eb4..6345db69c75847efcedbc5bd3e966248a2201fb6 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -21,6 +21,7 @@ import { DataUtils } from '../utils/DataUtils'; export default class EntryAbility extends UIAbility { private readonly tag: string = 'EntryAbility'; + private readonly splitSymbol: string = ';'; onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { DataUtils.context = this.context; @@ -40,10 +41,14 @@ export default class EntryAbility extends UIAbility { if (want.parameters !== undefined) { let title = want.parameters[CommonConstants.KEY_TITLE]; let description = want.parameters[CommonConstants.KEY_DESCRIPTION]; - let pathsArr = want.parameters[CommonConstants.KEY_PICTURE_PATHS]; + let filesName = want.parameters[CommonConstants.KEY_PICTURE_PATHS] as string; AppStorage.setOrCreate(CommonConstants.KEY_TITLE, title); AppStorage.setOrCreate(CommonConstants.KEY_DESCRIPTION, description); - AppStorage.setOrCreate(CommonConstants.KEY_PICTURE_PATHS, pathsArr); + let filesArr = filesName.split(this.splitSymbol); + if (filesArr === undefined) { + filesArr = []; + } + AppStorage.setOrCreate(CommonConstants.KEY_PICTURE_PATHS, filesArr); } else { Logger.warn(this.tag, 'want.parameters is undefined!'); } @@ -54,7 +59,11 @@ export default class EntryAbility extends UIAbility { onContinue(wantParam: Record): AbilityConstant.OnContinueResult { wantParam[CommonConstants.KEY_TITLE] = AppStorage.get(CommonConstants.KEY_TITLE); wantParam[CommonConstants.KEY_DESCRIPTION] = AppStorage.get(CommonConstants.KEY_DESCRIPTION); - wantParam[CommonConstants.KEY_PICTURE_PATHS] = AppStorage.get(CommonConstants.KEY_PICTURE_PATHS); + let nameArr = AppStorage.get(CommonConstants.KEY_PICTURE_PATHS) as string[]; + if (nameArr === undefined) { + nameArr = []; + } + wantParam[CommonConstants.KEY_PICTURE_PATHS] = nameArr.join(this.splitSymbol); return AbilityConstant.OnContinueResult.AGREE; } diff --git a/entry/src/main/ets/model/CameraService.ets b/entry/src/main/ets/model/CameraService.ets index 34c1c45b34448f4d14bf88c903ee7c5d30bd292f..25357c2bbea6310b7fa13db8a0bb8bcb6bd40a32 100644 --- a/entry/src/main/ets/model/CameraService.ets +++ b/entry/src/main/ets/model/CameraService.ets @@ -117,41 +117,24 @@ class CameraService { * @param photoOutput */ private photoOutPutCallBack(): void { - // Save Photo - this.photoOutput?.on('photoAvailable', (errCode: BusinessError, photo: camera.Photo): void => { - if (errCode || photo === undefined) { - Logger.error(this.tag, 'getPhoto failed'); - return; - } - let imageObj = photo.main; - imageObj.getComponent(image.ComponentType.JPEG, (errCode: BusinessError, component: image.Component): void => { - Logger.info(this.tag, 'getComponent start'); - if (component.byteBuffer) { - let buffer = component.byteBuffer; - FileUtils.savePicture(buffer).then(() => { - imageObj.release(); - }); - } else { - Logger.error(this.tag, `byteBuffer is null fail err: ${JSON.stringify(errCode)}`) - } - }); - }); - // Saving Moving Photo + // Saving camera Photo this.photoOutput?.on('photoAssetAvailable', async (err: BusinessError, photoAsset: photoAccessHelper.PhotoAsset): Promise => { if (err) { - Logger.error(this.tag, `getPhoto failed err: ${err}`); + Logger.error(this.tag, `getPhoto failed err: ${err.code}`); return; } - let accessHelper: photoAccessHelper.PhotoAccessHelper = - photoAccessHelper.getPhotoAccessHelper(this.currentContext); - let albumFetchResult: photoAccessHelper.FetchResult = - await accessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); - let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); - let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = - new photoAccessHelper.MediaAlbumChangeRequest(album); - albumChangeRequest.addAssets([photoAsset]); - await accessHelper.applyChanges(albumChangeRequest); + try { + let accessHelper: photoAccessHelper.PhotoAccessHelper = + photoAccessHelper.getPhotoAccessHelper(this.currentContext); + let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = + new photoAccessHelper.MediaAssetChangeRequest(photoAsset); + assetChangeRequest.saveCameraPhoto(); + await accessHelper.applyChanges(assetChangeRequest); + Logger.info(this.tag, 'apply saveCameraPhoto successfully'); + } catch (err) { + Logger.error(this.tag, `apply saveCameraPhoto failed with error: ${err.code}, ${err.message}`); + } }); } @@ -174,7 +157,6 @@ class CameraService { Logger.info(this.tag, `cameraInput success: ` + JSON.stringify(this.cameraInput)) if (this.cameraInput) { this.photoSession?.addInput(this.cameraInput) - Logger.info(this.tag, `cameraInput failed:` + JSON.stringify(this.cameraInput)) } // Add preview output to session this.photoSession?.addOutput(this.previewOutput) diff --git a/entry/src/main/ets/model/SelectedDataSource.ets b/entry/src/main/ets/model/SelectedDataSource.ets index 463eed6ea6188c056ee9ea5ec09c5b0da394bd8b..e1d4f1913ed1b20420ff3dbf026a5c9d969a421d 100644 --- a/entry/src/main/ets/model/SelectedDataSource.ets +++ b/entry/src/main/ets/model/SelectedDataSource.ets @@ -20,7 +20,9 @@ export class SelectedDataSource implements IDataSource { unshiftData(pixelMap: PixelMap) { this.data.unshift(pixelMap); - this.notifyAddData(0); + for (let i = 0; i < this.data.length; i++) { + this.notifyAddData(i); + } } deleteData(index: number) { diff --git a/entry/src/main/ets/pages/GraphicCreationPage.ets b/entry/src/main/ets/pages/GraphicCreationPage.ets index 107c4f5de7bf0179f68923dac9cad442d180ddc2..52969c32350f61708d2b05d0f323c9ec2310ae04 100644 --- a/entry/src/main/ets/pages/GraphicCreationPage.ets +++ b/entry/src/main/ets/pages/GraphicCreationPage.ets @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { router } from '@kit.ArkUI'; +import { promptAction, router } from '@kit.ArkUI'; import { CollaborationServiceFilter, CollaborationServiceStateDialog, @@ -33,15 +33,16 @@ import { DataUtils } from '../utils/DataUtils'; struct GraphicCreationPage { private readonly tag: string = 'GraphicCreationPage'; @StorageLink(CommonConstants.BREAKPOINT_NAME) currentBreakpoint: string = CommonConstants.BREAKPOINT_SM; + @StorageLink(CommonConstants.KEY_TITLE) title: string = ''; + @StorageLink(CommonConstants.KEY_DESCRIPTION) description: string = ''; @State photoUriArr: string[] = []; @State selectedData: SelectedDataSource = new SelectedDataSource(); @State currentIndex: number = -1; - @State title: string = AppStorage.get(CommonConstants.KEY_TITLE) as string; - @State description: string = AppStorage.get(CommonConstants.KEY_DESCRIPTION) as string; @State categoryArr: Resource[] = [$r('app.string.category_1'), $r('app.string.category_2'), $r('app.string.category_3'), $r('app.string.category_4')]; @State selectedUri: string[] = []; + @State isShow: boolean = false; async aboutToAppear() { UIUtils.setWindowFullScreen(getContext(this), true); @@ -50,17 +51,28 @@ struct GraphicCreationPage { if (this.photoUriArr === undefined) { this.photoUriArr = new Array(); } - FileUtils.getCloudFile().then((pixelMapArr: PixelMap[]) => { - pixelMapArr.forEach((pixelMap) => { - this.selectedData.addData(pixelMap); - }) - }); for (let i = 0; i < this.photoUriArr.length; i++) { FileUtils.createPixelMapFromUri(this.photoUriArr[i]).then((pixelMap) => { if (pixelMap !== undefined) { this.selectedData.addData(pixelMap); - FileUtils.sendCloudFile(getContext(this), pixelMap, i); + } + }); + } + + if (this.photoUriArr.length === 0) { + FileUtils.getCloudFile(getContext(this), (uriArr?: string[]) => { + if (uriArr === undefined) { + return; + } + this.photoUriArr = uriArr.concat(); + for (let i = 0; i < this.photoUriArr.length; i++) { + FileUtils.createPixelMapFromUri(this.photoUriArr[i]).then((pixelMap) => { + if (pixelMap === undefined) { + return; + } + this.selectedData.addData(pixelMap); + }); } }); } @@ -147,7 +159,21 @@ struct GraphicCreationPage { .fontFamily($r('sys.string.ohos_id_text_font_family_medium')) .backgroundColor($r('sys.color.ohos_id_color_button_normal')) .height($r('app.float.finish_btn_height')) - .bindMenu(this.CollaborationMenu()) + .bindMenu(this.isShow, this.CollaborationMenu(), { + onDisappear: () => { + this.isShow = false; + } + }) + .onClick(() => { + if (this.photoUriArr.length === CommonConstants.LIMIT_PICKER_NUM) { + promptAction.showToast({ + message: $r('app.string.toast_picker_limit'), + duration: DataUtils.fromResToNumber($r('app.float.show_DELAY_TIME')), + }); + } else { + this.isShow = true; + } + }) } .alignItems(VerticalAlign.Center) .width($r('app.string.full_screen')) @@ -290,15 +316,25 @@ struct GraphicCreationPage { doInsertPicture(stateCode: number, bufferType: string, buffer: ArrayBuffer): void { if (stateCode !== 0) { Logger.error(this.tag, `doInsertPicture stateCode: ${stateCode}}`); - return + return; } Logger.info(this.tag, `doInsertPicture bufferType: ${bufferType}}`); if (bufferType === CommonConstants.BUFFER_TYPE) { - FileUtils.createPixelMap(buffer).then((pixelMap) => { - if (pixelMap !== undefined) { - this.selectedData.unshiftData(pixelMap); - FileUtils.sendCloudFile(getContext(this), pixelMap, this.selectedData.totalCount() - 1); + if (this.photoUriArr.length === CommonConstants.LIMIT_PICKER_NUM) { + promptAction.showToast({ + message: $r('app.string.toast_picker_limit'), + duration: DataUtils.fromResToNumber($r('app.float.show_DELAY_TIME')), + }); + return; + } + FileUtils.saveFile(getContext(this), buffer).then(async (uri: string) => { + let pixelMap = await FileUtils.createPixelMapFromUri(uri); + if (pixelMap === undefined) { + return; } + this.selectedData.unshiftData(pixelMap); + FileUtils.copyToDistributedDir(getContext(this), uri); + this.photoUriArr.unshift(uri); }); } } @@ -318,7 +354,7 @@ struct GraphicCreationPage { .color($r('sys.color.ohos_id_color_sub_background')) } .padding({ left: $r('app.float.margin_16'), right: $r('app.float.margin_16'), }) - .margin({top: $r('app.float.margin_12'), bottom: $r('app.float.margin_12')}) + .margin({ top: $r('app.float.margin_12'), bottom: $r('app.float.margin_12') }) } @Builder diff --git a/entry/src/main/ets/pages/PreviewMovingPhotoPage.ets b/entry/src/main/ets/pages/PreviewMovingPhotoPage.ets index d1272eb34cf328e6ee28131652994945efed5890..ff20fbce8b0e2766dfe8b6fa7910548f6e71acf1 100644 --- a/entry/src/main/ets/pages/PreviewMovingPhotoPage.ets +++ b/entry/src/main/ets/pages/PreviewMovingPhotoPage.ets @@ -20,6 +20,7 @@ import { CommonConstants } from '../common/CommonConstants'; import { router } from '@kit.ArkUI'; import { UIUtils } from '../utils/UIUtils'; import { BreakpointType } from '../utils/BreakpointSystem'; +import { FileUtils } from '../utils/FileUtils'; const PHOTO_SELECT_EVENT_ID: number = 80001; let context = getContext(this); @@ -86,7 +87,6 @@ struct PreviewMovingPhotoPage { .height($r('app.string.full_screen')) } - @Builder setActions() { Flex({ @@ -150,7 +150,7 @@ struct PreviewMovingPhotoPage { .onClick(() => { router.back({ url: "pages/ImageEditPage" - }) + }); }) Image($r('app.media.selected')) @@ -160,6 +160,8 @@ struct PreviewMovingPhotoPage { .onClick(() => { if (this.photoUri !== '') { this.photoUriArr.unshift(this.photoUri); + FileUtils.unshiftFiles(this.photoUri); + FileUtils.sendCloudFile(getContext(this), [this.photoUri]); } router.replaceUrl({ url: 'pages/GraphicCreationPage', diff --git a/entry/src/main/ets/pages/PreviewPhotoPage.ets b/entry/src/main/ets/pages/PreviewPhotoPage.ets index d8220b62869cb1618984a44e3b967e284517792a..1d50befddc835f88183ec2b0ab756a605b4c0abc 100644 --- a/entry/src/main/ets/pages/PreviewPhotoPage.ets +++ b/entry/src/main/ets/pages/PreviewPhotoPage.ets @@ -138,7 +138,7 @@ struct PreviewPhotoPage { .onClick(() => { router.back({ url: "pages/ImageEditPage" - }) + }); }) Image($r('app.media.selected')) @@ -148,6 +148,8 @@ struct PreviewPhotoPage { .onClick(() => { if (this.photoUri !== '') { this.photoUriArr.unshift(this.photoUri); + FileUtils.unshiftFiles(this.photoUri); + FileUtils.sendCloudFile(getContext(this), [this.photoUri]); } router.replaceUrl({ url: 'pages/GraphicCreationPage', diff --git a/entry/src/main/ets/utils/FileUtils.ets b/entry/src/main/ets/utils/FileUtils.ets index 3b655403668208924bb1814ace967c3e9de96adf..0ba8e3843d249c8216eca27035c780df03380e57 100644 --- a/entry/src/main/ets/utils/FileUtils.ets +++ b/entry/src/main/ets/utils/FileUtils.ets @@ -18,6 +18,8 @@ import { CommonConstants } from '../common/CommonConstants'; import Logger from './Logger'; import { photoAccessHelper } from '@kit.MediaLibraryKit'; import fileIo from '@ohos.file.fs'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { fileUri } from '@kit.CoreFileKit'; export class FileUtils { static readonly tag: string = 'FileUtils'; @@ -28,52 +30,134 @@ export class FileUtils { desiredDynamicRange: image.DecodingDynamicRange.AUTO, index: 0 }; + /** * send picture to cloud + * * @param context - * @param photo - * @param index + * @param uriArr */ - static async sendCloudFile(context: Context, photo: PixelMap, index: number) { - let jsonStr = AppStorage.get(CommonConstants.KEY_PICTURE_PATHS); - let pathsArr:string[] = []; - if (jsonStr !== undefined) { - pathsArr = JSON.parse(jsonStr); - Logger.debug(FileUtils.tag, `sendCloudFile pathsArr 000 : ${JSON.stringify(pathsArr)}`); + static sendCloudFile(context: Context, uriArr: string[]) { + uriArr.forEach((uri: string) => { + FileUtils.copyToDistributedDir(context, uri); + }); + } + + static copyToDistributedDir(context: Context, uri: string) { + let fileUriObject = new fileUri.FileUri(uri); + let fileName = fileUriObject.name; + let distributedPathDir: string = context.distributedFilesDir; + let destUri: string = fileUri.getUriFromPath(distributedPathDir + `/${fileName}`); + let options: fs.CopyOptions = { + "progressListener": (progress: fs.Progress) => { + if (progress.processedSize === progress.totalSize) { + Logger.info(FileUtils.tag, 'copyToDistributedDir success copied!'); + } + } } + try { + fs.copy(uri, destUri, options).then(() => { + Logger.info(FileUtils.tag, 'copyToDistributedDir success copying!'); + }).catch((error: BusinessError) => { + let err: BusinessError = error as BusinessError; + Logger.error(FileUtils.tag, `copyToDistributedDir failed copy. Code: ${err.code}, message: ${err.message}`); + }); + } catch (err) { + Logger.error(FileUtils.tag, `copyToDistributedDir failed copy. Code: ${err.code}, message: ${err.message}`); + } + } - let pathDir: string = context.distributedFilesDir; - let filePath: string = `${pathDir}/picture_${index}.jpg`; - pathsArr.push(filePath); - AppStorage.setOrCreate(CommonConstants.KEY_PICTURE_PATHS, JSON.stringify(pathsArr)); - Logger.debug(FileUtils.tag, `sendCloudFile pathsArr 1111 : ${JSON.stringify(pathsArr)}`); - const imagePacker = image.createImagePacker(); - const packOptions: image.PackingOption = { - format: FileUtils.formatValue, - quality: FileUtils.qualityValue + static addAllFiles(uriArr: string[]) { + let nameArr = AppStorage.get(CommonConstants.KEY_PICTURE_PATHS) as string[]; + if (nameArr === undefined) { + nameArr = []; } - await imagePacker.packing(photo, packOptions).then(async (data: ArrayBuffer) => { - let file = fs.openSync(filePath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); - fs.writeSync(file.fd, data); - Logger.debug(FileUtils.tag, `sendCloudFile file size: ${fileIo.statSync(filePath).size}`); - fs.closeSync(file.fd); + nameArr.length = 0; + uriArr.forEach((uri: string) => { + let fileUriObject = new fileUri.FileUri(uri); + nameArr.push(fileUriObject.name); }); + AppStorage.setOrCreate(CommonConstants.KEY_PICTURE_PATHS, nameArr); } - static async getCloudFile(): Promise { - let pixelMapArr: PixelMap[] = []; - let str = AppStorage.get(CommonConstants.KEY_PICTURE_PATHS) as string; - let pathsArr = JSON.parse(str) as Array; - Logger.error(FileUtils.tag, `sendCloudFile pathsArr 1111 : ${JSON.stringify(pathsArr)}`); - pathsArr.forEach((uri) => { - FileUtils.createPixelMapFromUri(uri).then((pixelMap) => { - if (pixelMap !== undefined) { - pixelMapArr.push(pixelMap); + static unshiftFiles(uri: string) { + let nameArr = AppStorage.get(CommonConstants.KEY_PICTURE_PATHS) as string[]; + if (nameArr === undefined) { + nameArr = []; + } + let fileUriObject = new fileUri.FileUri(uri); + nameArr.unshift(fileUriObject.name); + AppStorage.setOrCreate(CommonConstants.KEY_PICTURE_PATHS, nameArr); + } + + static deleteFiles(index: number) { + let nameArr = AppStorage.get(CommonConstants.KEY_PICTURE_PATHS) as string[]; + if (nameArr === undefined) { + nameArr = []; + } + nameArr.splice(index, 1); + AppStorage.setOrCreate(CommonConstants.KEY_PICTURE_PATHS, nameArr); + } + + static getCloudFile(context: Context, callback: Function) { + let nameArr = AppStorage.get(CommonConstants.KEY_PICTURE_PATHS) as string[]; + if (nameArr === undefined) { + nameArr = []; + } + if (nameArr.length === 0) { + callback(); + } else { + FileUtils.copyToFilesDir(context, nameArr, 0, ()=> { + let filesDir: string = context.filesDir; + let uriArr:string[] = []; + nameArr.forEach((fileName: string)=> { + let destUri: string = fileUri.getUriFromPath(filesDir + `/${fileName}`); + uriArr.push(destUri); + }) + callback(uriArr); + }); + } + } + + private static copyToFilesDir(context: Context, nameArr: string[], state: number, callback: Function) { + if (state === nameArr.length) { + return; + } + let fileName = nameArr[state]; + let filesDir: string = context.filesDir; + let distributedFilesDir: string = context.distributedFilesDir; + let srcUri: string = fileUri.getUriFromPath(distributedFilesDir + `/${fileName}`); + let destUri: string = fileUri.getUriFromPath(filesDir + `/${fileName}`); + + let options: fs.CopyOptions = { + "progressListener": (progress: fs.Progress) => { + if (progress.processedSize === progress.totalSize) { + Logger.info(FileUtils.tag, 'copyToFilesDir success copied!'); + FileUtils.handleNextCopy(context, nameArr, state, callback); } - }) - }); - Logger.debug(FileUtils.tag, `getCloudFile pathsArr: ${pathsArr.length} pixelMapArr: ${pixelMapArr.length}`); - return pixelMapArr; + } + } + try { + fs.copy(srcUri, destUri, options).then(() => { + Logger.info(FileUtils.tag, 'copyToFilesDir success copying!'); + }).catch((error: BusinessError) => { + let err: BusinessError = error as BusinessError; + Logger.error(FileUtils.tag, `copyToFilesDir failed to copy. Code: ${err.code}, message: ${err.message}`); + FileUtils.handleNextCopy(context, nameArr, state, callback); + }); + } catch (err) { + Logger.error(FileUtils.tag, `copyToFilesDir failed to copy. Code: ${err.code}, message: ${err.message}`); + FileUtils.handleNextCopy(context, nameArr, state, callback); + } + } + + private static handleNextCopy(context: Context, nameArr: string[], state: number, callback: Function) { + if (state === nameArr.length - 1) { + callback(); + } else { + let next = state + 1; + FileUtils.copyToFilesDir(context, nameArr, next, callback); + } } /** @@ -121,4 +205,14 @@ export class FileUtils { Logger.debug(FileUtils.tag, `savePicture uri: ${photoUri}}`); return photoUri; } + + static async saveFile(context: Context, buffer: ArrayBuffer): Promise { + let filesDir: string = context.filesDir; + let photoUri: string = fileUri.getUriFromPath(filesDir + `/${Date.now().toString()}.${FileUtils.extensionValue}`); + let file: fileIo.File = fileIo.openSync(photoUri, fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE); + await fileIo.write(file.fd, buffer); + Logger.debug(FileUtils.tag, `saveFile uri: ${photoUri}}`); + fileIo.closeSync(file); + return photoUri; + } } \ No newline at end of file diff --git a/entry/src/main/ets/utils/UIUtils.ets b/entry/src/main/ets/utils/UIUtils.ets index a0556916b15afc8427a8a93fd88831093892839f..1445fa65faff69fd69218842b0a89423730057fc 100644 --- a/entry/src/main/ets/utils/UIUtils.ets +++ b/entry/src/main/ets/utils/UIUtils.ets @@ -12,11 +12,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { window } from '@kit.ArkUI'; +import { promptAction, window } from '@kit.ArkUI'; import { picker } from '@kit.CoreFileKit'; import { CommonConstants } from '../common/CommonConstants'; import { BusinessError } from '@kit.BasicServicesKit'; import Logger from './Logger'; +import { DataUtils } from './DataUtils'; export class UIUtils { static readonly tag: string = 'UIUtils'; @@ -50,10 +51,17 @@ export class UIUtils { * * @param callback */ - static showPickerView(callback: Function) { + static showPickerView(selectedNum: number, callback: Function) { + if (selectedNum >= CommonConstants.LIMIT_PICKER_NUM) { + promptAction.showToast({ + message: $r('app.string.toast_picker_limit'), + duration: DataUtils.fromResToNumber($r('app.float.show_DELAY_TIME')), + }); + return; + } const photoSelectOptions = new picker.PhotoSelectOptions(); photoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE; - photoSelectOptions.maxSelectNumber = CommonConstants.LIMIT_PICKER_NUM; + photoSelectOptions.maxSelectNumber = CommonConstants.LIMIT_PICKER_NUM - selectedNum; const photoViewPicker = new picker.PhotoViewPicker(); photoViewPicker.select(photoSelectOptions).then(async (photoSelectResult: picker.PhotoSelectResult) => { let uriArr = photoSelectResult.photoUris; diff --git a/entry/src/main/ets/view/CameraView.ets b/entry/src/main/ets/view/CameraView.ets index 8f9984cc7b325127345f953b91b51197d16f7f9b..b542fe74d8b093be9871860c6815773823c8f001 100644 --- a/entry/src/main/ets/view/CameraView.ets +++ b/entry/src/main/ets/view/CameraView.ets @@ -32,7 +32,7 @@ export struct CameraView { @Link currentBreakpoint: string; @Link photoUriArr: string[]; @Link cameraIndex: number; - private readonly tag:string = 'CameraView'; + private readonly tag: string = 'CameraView'; private isLocalCamera: boolean = true; private currentUri: string = ''; private mXComponentController: XComponentController = new XComponentController(); @@ -263,7 +263,8 @@ export struct CameraView { this.isTakeMovingPhoto = this.isMovingPhoto; setTimeout(() => { this.getThumbnail(true); - }, DataUtils.fromResToNumber($r('app.float.DELAY_TIME'))); + }, this.isTakeMovingPhoto ? DataUtils.fromResToNumber($r('app.float.living_delay_time')) : + DataUtils.fromResToNumber($r('app.float.normal_delay_time'))); }); //camera selected diff --git a/entry/src/main/ets/view/ListAddPictureView.ets b/entry/src/main/ets/view/ListAddPictureView.ets index 8a5b47b2b98ef4c234905e9a7a529db822565a9e..439e3ec66b4b1e750ffd2f7338314b0f9fc7442d 100644 --- a/entry/src/main/ets/view/ListAddPictureView.ets +++ b/entry/src/main/ets/view/ListAddPictureView.ets @@ -58,8 +58,9 @@ export struct ListAddPictureView { }.align(Alignment.Center) }.onClick(() => { // Show picker - UIUtils.showPickerView(async (uriArr: string[]) => { + UIUtils.showPickerView(this.photoUriArr.length, async (uriArr: string[]) => { Logger.debug(this.tag, `picker view uriArr: ${uriArr.length}`); + FileUtils.sendCloudFile(getContext(this), uriArr.concat()); while (uriArr.length > 0) { let uri = uriArr.pop(); if (uri === undefined) { @@ -71,6 +72,7 @@ export struct ListAddPictureView { } }); this.photoUriArr.unshift(uri); + FileUtils.unshiftFiles(uri); } if (this.swiperController !== undefined) { this.currentIndex = 0; @@ -103,16 +105,15 @@ export struct ListAddPictureView { Image($r("app.media.close_mark_circle_fill")) .width($r('app.float.rounded_size_22')) .height($r('app.float.rounded_size_22')) - // .fillColor($r('sys.color.ohos_id_color_mask_thin')) .margin({ top: $r('app.float.margin_4'), right: $r('app.float.margin_4') }) .onClick(() => { // Delete selected picture let index = this.selectedData.getItemIndex(item); this.photoUriArr.splice(index, 1); + FileUtils.deleteFiles(index); this.selectedData.deleteData(index); if (this.swiperController !== undefined) { - this.currentIndex = Math.max(0, index - 1) - this.swiperController?.changeIndex(this.currentIndex); + this.currentIndex = Math.max(0, index - 1); } }) } diff --git a/entry/src/main/ets/view/NavigationBarView.ets b/entry/src/main/ets/view/NavigationBarView.ets index 09d47918c861ae516b347ab7737a47768c1aee76..8f82872d0de693feeb0b0b2305cd32cfa020a416 100644 --- a/entry/src/main/ets/view/NavigationBarView.ets +++ b/entry/src/main/ets/view/NavigationBarView.ets @@ -17,6 +17,7 @@ import { BreakpointType } from '../utils/BreakpointSystem'; import { DataUtils } from '../utils/DataUtils'; import { UIUtils } from '../utils/UIUtils'; import { router } from '@kit.ArkUI'; +import { FileUtils } from '../utils/FileUtils'; @Component export struct NavigationBarView { @@ -90,19 +91,13 @@ export struct NavigationBarView { } ).getValue(this.currentBreakpoint)) .onClick(() => { - UIUtils.showPickerView((uriArr: string[]) => { - let pickerUriArr: string[] = []; - while (uriArr.length > 0) { - let uri = uriArr.pop() - if (uri === undefined) { - continue - } - pickerUriArr.unshift(uri) - } + UIUtils.showPickerView(0, (uriArr: string[]) => { + FileUtils.sendCloudFile(getContext(this), uriArr); + FileUtils.addAllFiles(uriArr); router.pushUrl({ url: 'pages/ImageEditPage', - params: pickerUriArr - }) + params: uriArr + }); }); }); } diff --git a/entry/src/main/resources/base/element/float.json b/entry/src/main/resources/base/element/float.json index 3e174d9bcbcae41f0fd3df09a5eb5dacb3da5e9f..45e9aad34db98ccb771d1d9692d29bf5acf6e41b 100644 --- a/entry/src/main/resources/base/element/float.json +++ b/entry/src/main/resources/base/element/float.json @@ -117,9 +117,17 @@ "value": "280" }, { - "name": "DELAY_TIME", + "name": "normal_delay_time", "value": "500" }, + { + "name": "living_delay_time", + "value": "1500" + }, + { + "name": "show_DELAY_TIME", + "value": "2000" + }, { "name": "font_size_10", "value": "10" diff --git a/entry/src/main/resources/base/element/string.json b/entry/src/main/resources/base/element/string.json index 4792dcb4924060253f3a1cf3cd9ee451473ed0c7..fc147addac805041bc25d45ed1f395c68a8896a8 100644 --- a/entry/src/main/resources/base/element/string.json +++ b/entry/src/main/resources/base/element/string.json @@ -22,7 +22,7 @@ }, { "name": "read_desc", - "value": "需要获取图片" + "value": "读取和存储图片使用" }, { "name": "write_desc", @@ -215,6 +215,10 @@ { "name": "btn_edite_label", "value": "编辑" + }, + { + "name": "toast_picker_limit", + "value": "最多选择18张图片!" } ] } \ No newline at end of file