diff --git a/OAT.xml b/OAT.xml index bca7bab..475199a 100644 --- a/OAT.xml +++ b/OAT.xml @@ -30,6 +30,7 @@ + diff --git a/README_ZH.md b/README_ZH.md index 5042fe8..a1074b2 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -57,7 +57,7 @@ FilePicker应用是OpenHarmony中预置的系统应用,为用户提供文件 globalThis.context.startAbilityForResult( { bundleName: "com.ohos.filepicker", - abilityName: "com.ohos.filepicker.MainAbility", + abilityName: "MainAbility", parameters: { 'startMode': 'choose', //choose or save } @@ -69,7 +69,7 @@ globalThis.context.startAbilityForResult( globalThis.context.startAbilityForResult( { bundleName: "com.ohos.filepicker", - abilityName: "com.ohos.filepicker.MainAbility", + abilityName: "MainAbility", parameters: { 'startMode': 'save', //choose or save 'saveFile': 'test.jpg', diff --git a/build-profile.json5 b/build-profile.json5 index c899a57..2746a0e 100644 --- a/build-profile.json5 +++ b/build-profile.json5 @@ -1,19 +1,5 @@ { "app": { - "signingConfigs": [ - { - "name": "default", - "material": { - "certpath": "C:\\Users\\Administrator\\.ohos\\config\\openharmony\\auto_ohos.cer", - "storePassword": "0000001866B30A00583E19F2A7810409DC21FD1736310F045F4BBAD68308661D5508F6887C450EDE", - "keyAlias": "debugKey", - "keyPassword": "0000001839D4D8FF10ED142C94E5132CADD090081785A1D581C24FA2D1056AFF1718E4AA97DF4B32", - "profile": "C:\\Users\\Administrator\\.ohos\\config\\openharmony\\auto_ohos_default_com.ohos.filepicker.p7b", - "signAlg": "SHA256withECDSA", - "storeFile": "C:\\Users\\Administrator\\.ohos\\config\\openharmony\\auto_ohos.p12" - } - } - ], "compileSdkVersion": 9, "compatibleSdkVersion": 9, "products": [ @@ -59,6 +45,10 @@ ] } ] + }, + { + "name": "common", + "srcPath": "./common" } ] } \ No newline at end of file diff --git a/common/.gitignore b/common/.gitignore new file mode 100644 index 0000000..4f9a973 --- /dev/null +++ b/common/.gitignore @@ -0,0 +1,3 @@ +/node_modules +/.preview +/build \ No newline at end of file diff --git a/common/build-profile.json5 b/common/build-profile.json5 new file mode 100644 index 0000000..35dff6d --- /dev/null +++ b/common/build-profile.json5 @@ -0,0 +1,5 @@ +{ + "apiType": "stageMode", + "buildOption": { + } +} diff --git a/common/hvigorfile.js b/common/hvigorfile.js new file mode 100644 index 0000000..42ed4b4 --- /dev/null +++ b/common/hvigorfile.js @@ -0,0 +1,3 @@ +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +module.exports = require('@ohos/hvigor-ohos-plugin').harTasks + diff --git a/product/phone/src/main/ets/module/DisplayInfo.ets b/common/index.ets similarity index 77% rename from product/phone/src/main/ets/module/DisplayInfo.ets rename to common/index.ets index 6b764fa..73d578c 100644 --- a/product/phone/src/main/ets/module/DisplayInfo.ets +++ b/common/index.ets @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,9 +13,4 @@ * limitations under the License. */ -export class DisplayInfo { - width: number - height: number - mainDialogWidth: number - mainDialogHeight: number -} \ No newline at end of file +export { MainPage } from './src/main/ets/components/MainPage/MainPage' diff --git a/common/package-lock.json b/common/package-lock.json new file mode 100644 index 0000000..01b613f --- /dev/null +++ b/common/package-lock.json @@ -0,0 +1,5 @@ +{ + "name": "@ohos/common", + "version": "1.0.0", + "lockfileVersion": 1 +} diff --git a/common/package.json b/common/package.json new file mode 100644 index 0000000..37ed189 --- /dev/null +++ b/common/package.json @@ -0,0 +1,13 @@ +{ + "name": "@ohos/common", + "description": "a npm package which contains arkUI2.0 page", + "ohos": { + "org": "" + }, + "version": "1.0.0", + "main": "index.ets", + "types": "", + "repository": {}, + "license": "ISC", + "dependencies": {} +} diff --git a/common/src/main/ets/components/Data/Constants.ts b/common/src/main/ets/components/Data/Constants.ts new file mode 100644 index 0000000..0c05407 --- /dev/null +++ b/common/src/main/ets/components/Data/Constants.ts @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export enum MenuLevel { + MENU_FIRST_LEVEL_BY_TYPE = 1, + MENU_SECOND_LEVEL_BY_FOLD = 2, + MENU_THIRD_LEVEL_HAS_PIC = 3, + MENU_THIRD_LEVEL_HAS_DETAIL = 4, +} + +export enum MediaType { + MEDIA_TYPE_FILE = 1, + MEDIA_TYPE_IMAGE = 3, + MEDIA_TYPE_VIDEO = 4, + MEDIA_TYPE_AUDIO = 5, + MEDIA_TYPE_ALBUM = 8 +} + +export enum MediaName { + FILE = 'file', + IMAGE = 'image', + VIDEO = 'video', + AUDIO = 'audio', + FILE_TYPE = "fileType" +} + +export enum GridItemSize { + GRID_ITEM_HEIGHT = 126, + GRID_ITEM_WIDTH = 96, + GRID_ITEM_COLUMNS_GAP = 8, + GRID_ITEM_ROWS_GAP = 8, +} + +export enum TerminateReason { + SUCCESS = 0, + NO_ACTION = -1, +} diff --git a/feature/Constants.ets b/common/src/main/ets/components/Data/FileInfo.ts similarity index 52% rename from feature/Constants.ets rename to common/src/main/ets/components/Data/FileInfo.ts index 862769e..bbb3472 100644 --- a/feature/Constants.ets +++ b/common/src/main/ets/components/Data/FileInfo.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,22 +13,23 @@ * limitations under the License. */ -export enum menuLevel { - MENU_FIRST_LEVEL_BY_TYPE = 1, - MENU_SECOND_LEVEL_BY_FOLD = 2, - MENU_THIRD_LEVEL_HAS_PIC = 3, - MENU_THIRD_LEVEL_HAS_DETAIL = 4, -} +import { MediaType } from './Constants' -export enum mediaType { - MEDIA_TYPE_FILE = 1, - MEDIA_TYPE_IMAGE = 3, - MEDIA_TYPE_VIDEO = 4, - MEDIA_TYPE_AUDIO = 5, - MEDIA_TYPE_ALBUM = 8 -} +export class FileInfo { + name: string + path: string + type: number= MediaType.MEDIA_TYPE_ALBUM + size: string + dataAdded_time: string + modified_time: string + mediaType: string + thumbnail: Resource + font_color: Color | string | Resource + opacity: number + list_background: string | Resource + textBackground: string | Resource -export enum terminateReason { - SUCCESS = 0, - NO_ACTION = -1, + constructor(name: string) { + this.name = name + } } \ No newline at end of file diff --git a/product/pad/src/main/ets/module/DisplayInfo.ets b/common/src/main/ets/components/Data/TopPathInfo.ts similarity index 70% rename from product/pad/src/main/ets/module/DisplayInfo.ets rename to common/src/main/ets/components/Data/TopPathInfo.ts index 6b764fa..ff4093d 100644 --- a/product/pad/src/main/ets/module/DisplayInfo.ets +++ b/common/src/main/ets/components/Data/TopPathInfo.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,9 +13,13 @@ * limitations under the License. */ -export class DisplayInfo { - width: number - height: number - mainDialogWidth: number - mainDialogHeight: number +export class TopPathInfo { + name: string + path: string + opacity: number = 1 + + constructor(name: string, path: string) { + this.name = name + this.path = path + } } \ No newline at end of file diff --git a/common/LogUtils.ets b/common/src/main/ets/components/MainPage/MainPage.ets similarity index 59% rename from common/LogUtils.ets rename to common/src/main/ets/components/MainPage/MainPage.ets index 8e6bb82..3bfed58 100644 --- a/common/LogUtils.ets +++ b/common/src/main/ets/components/MainPage/MainPage.ets @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,10 +13,20 @@ * limitations under the License. */ -export function LogInfo(TAG: string, message: string | number): void { - console.info('filePicker_' + TAG + ': ' + message) -} +@Entry +@Component +export struct MainPage { + @State message: string = 'Hello World' -export function LogDebug(TAG: string, message: string | number): void { - console.debug('filePicker_' + TAG + ': ' + message) + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + } + .height('100%') + } } diff --git a/common/src/main/ets/components/Utils/AbilityUtils.ts b/common/src/main/ets/components/Utils/AbilityUtils.ts new file mode 100644 index 0000000..c42baed --- /dev/null +++ b/common/src/main/ets/components/Utils/AbilityUtils.ts @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { logInfo, logWarn } from './LogUtils' + +var TAG: string = 'AbilityUtils' + +export function terminateSelfWithResult(resultCode: number, result: string): void { + logInfo(TAG, 'terminateSelfWithResult') + let startMode: string = AppStorage.Get('startMode') + var abilityResult = { + resultCode: resultCode, + want: { + parameters: { + 'startMode': startMode, + 'result': result + } + } + } + globalThis.context.terminateSelfWithResult(abilityResult, (error) => { + if (error.code) { + logWarn(TAG, 'Operation failed. Cause: ' + JSON.stringify(error)) + return + } + logInfo(TAG, 'Operation succeeded') + }) +} \ No newline at end of file diff --git a/common/src/main/ets/components/Utils/FileManagerServiceUtils.ts b/common/src/main/ets/components/Utils/FileManagerServiceUtils.ts new file mode 100644 index 0000000..505b729 --- /dev/null +++ b/common/src/main/ets/components/Utils/FileManagerServiceUtils.ts @@ -0,0 +1,333 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { MediaType, MediaName } from '../Data/Constants'; +import { FileInfo } from '../Data/FileInfo' +import { logInfo } from './LogUtils' + +var TAG = 'FileManagerServiceUtils' +var isDebug: boolean = true; + +export function getFirstMenu(deviceName: string): Array { + let fileList: Array = []; + if (isDebug) { + let file1: FileInfo = new FileInfo('image_album'); + file1.type = MediaType.MEDIA_TYPE_ALBUM; + file1.path = 'dataability:///album'; + file1.size = ''; + file1.dataAdded_time = 'xxx'; + file1.modified_time = 'xxx'; + fileList.push(file1); + + let file2: FileInfo = new FileInfo('video_album'); + file2.type = MediaType.MEDIA_TYPE_ALBUM; + file2.path = 'dataability:///album'; + file2.size = ''; + file2.dataAdded_time = 'xxx'; + file2.modified_time = 'xxx'; + fileList.push(file2); + + let file4: FileInfo = new FileInfo('file_folder'); + file4.type = MediaType.MEDIA_TYPE_ALBUM; + file4.path = 'dataability:///album'; + file4.size = ''; + file4.dataAdded_time = 'xxx'; + file4.modified_time = 'xxx'; + fileList.push(file4); + + let file3: FileInfo = new FileInfo('audio_album'); + file3.type = MediaType.MEDIA_TYPE_ALBUM; + file3.path = 'dataability:///album'; + file3.size = ''; + file3.dataAdded_time = 'xxx'; + file3.modified_time = 'xxx'; + fileList.push(file3); + } else { + // var fileInfo = filemanager.getRoot(deviceName); + } + + fileList.forEach(item => { + if (item.name == 'image_album') { + item.name = "图片"; + item.mediaType = 'image'; + item.thumbnail = $r("app.media.ic_type_image") + } else if (item.name == 'video_album') { + item.name = "视频"; + item.mediaType = 'video'; + item.thumbnail = $r("app.media.ic_type_video") + } else if (item.name == 'audio_album') { + item.name = "音乐"; + item.mediaType = 'audio'; + item.thumbnail = $r("app.media.ic_type_audio") + } else if (item.name == 'file_folder') { + item.name = "文档"; + item.mediaType = 'file'; + item.thumbnail = $r("app.media.ic_public_file") + } + }); + + return fileList; +} + +export function getListFile(deviceName: string, mediaType: string, path: string): Array { + logInfo(TAG, "getListFile mediaType = " + mediaType + ';path = ' + path); + let fileList: Array = []; + if (isDebug) { + if (path == 'dataability:///album') { + if (mediaType == 'image') { + let fileInfo1: FileInfo = new FileInfo("微信的图片"); + fileInfo1.type = MediaType.MEDIA_TYPE_ALBUM; + fileInfo1.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/01'; + fileInfo1.dataAdded_time = 'xxx'; + fileInfo1.modified_time = 'xxx'; + fileList.push(fileInfo1); + let fileInfo2: FileInfo = new FileInfo("图片1"); + fileInfo2.type = MediaType.MEDIA_TYPE_ALBUM; + fileInfo2.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/02'; + fileInfo2.dataAdded_time = 'xxx'; + fileInfo2.modified_time = 'xxx'; + fileList.push(fileInfo2); + let fileInfo3: FileInfo = new FileInfo("图片2"); + fileInfo3.type = MediaType.MEDIA_TYPE_ALBUM; + fileInfo3.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/03'; + fileInfo3.dataAdded_time = 'xxx'; + fileInfo3.modified_time = 'xxx'; + fileList.push(fileInfo3); + let fileInfo4: FileInfo = new FileInfo("图片3"); + fileInfo4.type = MediaType.MEDIA_TYPE_ALBUM; + fileInfo4.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/04'; + fileInfo4.dataAdded_time = 'xxx'; + fileInfo4.modified_time = 'xxx'; + fileList.push(fileInfo4); + let fileInfo5: FileInfo = new FileInfo("图片4"); + fileInfo5.type = MediaType.MEDIA_TYPE_ALBUM; + fileInfo5.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/05'; + fileInfo5.dataAdded_time = 'xxx'; + fileInfo5.modified_time = 'xxx'; + fileList.push(fileInfo5); + let fileInfo6: FileInfo = new FileInfo("图片5"); + fileInfo6.type = MediaType.MEDIA_TYPE_ALBUM; + fileInfo6.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/06'; + fileInfo6.dataAdded_time = 'xxx'; + fileInfo6.modified_time = 'xxx'; + fileList.push(fileInfo6); + let fileInfo7: FileInfo = new FileInfo("图片6"); + fileInfo7.type = MediaType.MEDIA_TYPE_ALBUM; + fileInfo7.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/07'; + fileInfo7.dataAdded_time = 'xxx'; + fileInfo7.modified_time = 'xxx'; + fileList.push(fileInfo7); + let fileInfo8: FileInfo = new FileInfo("图片7"); + fileInfo8.type = MediaType.MEDIA_TYPE_ALBUM; + fileInfo8.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/08'; + fileInfo8.dataAdded_time = 'xxx'; + fileInfo8.modified_time = 'xxx'; + fileList.push(fileInfo8); + let fileInfo9: FileInfo = new FileInfo("图片8"); + fileInfo1.type = MediaType.MEDIA_TYPE_ALBUM; + fileInfo1.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/09'; + fileInfo1.dataAdded_time = 'xxx'; + fileInfo1.modified_time = 'xxx'; + fileList.push(fileInfo9); + let fileInfo10: FileInfo = new FileInfo("图片9"); + fileInfo10.type = MediaType.MEDIA_TYPE_ALBUM; + fileInfo10.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/10'; + fileInfo10.dataAdded_time = 'xxx'; + fileInfo10.modified_time = 'xxx'; + fileList.push(fileInfo10); + let fileInfo11: FileInfo = new FileInfo("图片10"); + fileInfo11.type = MediaType.MEDIA_TYPE_ALBUM; + fileInfo11.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/11'; + fileInfo11.dataAdded_time = 'xxx'; + fileInfo11.modified_time = 'xxx'; + fileList.push(fileInfo11); + } else if (mediaType == 'video') { + let fileInfo1: FileInfo = new FileInfo("视频0"); + fileInfo1.type = MediaType.MEDIA_TYPE_ALBUM; + fileInfo1.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/12'; + fileInfo1.dataAdded_time = 'xxx'; + fileInfo1.modified_time = 'xxx'; + fileList.push(fileInfo1); + let fileInfo2: FileInfo = new FileInfo("视频1"); + fileInfo2.type = MediaType.MEDIA_TYPE_ALBUM; + fileInfo2.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/13'; + fileInfo2.dataAdded_time = 'xxx'; + fileInfo2.modified_time = 'xxx'; + fileList.push(fileInfo2); + let fileInfo3: FileInfo = new FileInfo("视频2"); + fileInfo3.type = MediaType.MEDIA_TYPE_ALBUM; + fileInfo3.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/14'; + fileInfo3.dataAdded_time = 'xxx'; + fileInfo3.modified_time = 'xxx'; + fileList.push(fileInfo3); + let fileInfo4: FileInfo = new FileInfo("视频3"); + fileInfo4.type = MediaType.MEDIA_TYPE_ALBUM; + fileInfo4.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/15'; + fileInfo4.dataAdded_time = 'xxx'; + fileInfo4.modified_time = 'xxx'; + fileList.push(fileInfo4); + let fileInfo5: FileInfo = new FileInfo("视频4"); + fileInfo5.type = MediaType.MEDIA_TYPE_ALBUM; + fileInfo5.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/16'; + fileInfo5.dataAdded_time = 'xxx'; + fileInfo5.modified_time = 'xxx'; + fileList.push(fileInfo5); + } else if (mediaType == 'audio') { + let fileInfo1: FileInfo = new FileInfo("音乐0"); + fileInfo1.type = MediaType.MEDIA_TYPE_ALBUM; + fileInfo1.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/17'; + fileInfo1.dataAdded_time = 'xxx'; + fileInfo1.modified_time = 'xxx'; + fileList.push(fileInfo1); + let fileInfo2: FileInfo = new FileInfo("音乐1"); + fileInfo2.type = MediaType.MEDIA_TYPE_ALBUM; + fileInfo2.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/18'; + fileInfo2.dataAdded_time = 'xxx'; + fileInfo2.modified_time = 'xxx'; + fileList.push(fileInfo2); + let fileInfo3: FileInfo = new FileInfo("音乐2"); + fileInfo3.type = MediaType.MEDIA_TYPE_ALBUM; + fileInfo3.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/19'; + fileInfo3.dataAdded_time = 'xxx'; + fileInfo3.modified_time = 'xxx'; + fileList.push(fileInfo3); + let fileInfo4: FileInfo = new FileInfo("音乐3"); + fileInfo4.type = MediaType.MEDIA_TYPE_ALBUM; + fileInfo4.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/20'; + fileInfo4.dataAdded_time = 'xxx'; + fileInfo4.modified_time = 'xxx'; + fileList.push(fileInfo4); + let fileInfo5: FileInfo = new FileInfo("音乐4"); + fileInfo5.type = MediaType.MEDIA_TYPE_ALBUM; + fileInfo5.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/21'; + fileInfo5.dataAdded_time = 'xxx'; + fileInfo5.modified_time = 'xxx'; + fileList.push(fileInfo5); + } else if (mediaType == 'file') { + let fileInfo1: FileInfo = new FileInfo("文件夹0"); + fileInfo1.type = MediaType.MEDIA_TYPE_ALBUM; + fileInfo1.mediaType = mediaType; + fileInfo1.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/22'; + fileInfo1.dataAdded_time = 'xxx'; + fileInfo1.modified_time = 'xxx'; + fileList.push(fileInfo1); + let fileInfo2: FileInfo = new FileInfo("文件夹1"); + fileInfo2.type = MediaType.MEDIA_TYPE_ALBUM; + fileInfo2.mediaType = mediaType; + fileInfo2.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/23'; + fileInfo2.dataAdded_time = 'xxx'; + fileInfo2.modified_time = 'xxx'; + fileList.push(fileInfo2); + let fileInfo3: FileInfo = new FileInfo("文件夹2"); + fileInfo3.type = MediaType.MEDIA_TYPE_ALBUM; + fileInfo3.mediaType = mediaType; + fileInfo3.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/24'; + fileInfo3.dataAdded_time = 'xxx'; + fileInfo3.modified_time = 'xxx'; + fileList.push(fileInfo3); + let fileInfo4: FileInfo = new FileInfo("文件夹3"); + fileInfo4.type = MediaType.MEDIA_TYPE_ALBUM; + fileInfo4.mediaType = mediaType; + fileInfo4.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/25'; + fileInfo4.dataAdded_time = 'xxx'; + fileInfo4.modified_time = 'xxx'; + fileList.push(fileInfo4); + let fileInfo5: FileInfo = new FileInfo("文件夹4"); + fileInfo5.type = MediaType.MEDIA_TYPE_ALBUM; + fileInfo5.mediaType = mediaType; + fileInfo5.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/26'; + fileInfo5.dataAdded_time = 'xxx'; + fileInfo5.modified_time = 'xxx'; + fileList.push(fileInfo5); + let fileInfo6: FileInfo = new FileInfo("文本文档.txt"); + fileInfo6.type = MediaType.MEDIA_TYPE_FILE; + fileInfo6.mediaType = mediaType; + fileInfo6.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/27'; + fileInfo6.dataAdded_time = 'xxx'; + fileInfo6.modified_time = 'xxx'; + fileInfo6.size = '1,024 KB' + fileList.push(fileInfo6); + let fileInfo7: FileInfo = new FileInfo("验收文稿.ppt"); + fileInfo7.type = MediaType.MEDIA_TYPE_FILE; + fileInfo7.mediaType = mediaType; + fileInfo7.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/28'; + fileInfo7.dataAdded_time = 'xxx'; + fileInfo7.modified_time = 'xxx'; + fileInfo7.size = '4,562,000 KB' + fileList.push(fileInfo7); + } + } else { + if (mediaType == 'image') { + for (var index = 0; index < 10; index++) { + let file: FileInfo = new FileInfo("" + index + ".png"); + file.type = MediaType.MEDIA_TYPE_IMAGE; + file.path = path + index; + file.dataAdded_time = 'xxx'; + file.modified_time = 'xxx'; + fileList.push(file); + } + } else if (mediaType == 'video') { + for (var index = 0; index < 15; index++) { + let file: FileInfo = new FileInfo("" + index + ".wmv"); + file.type = MediaType.MEDIA_TYPE_VIDEO; + file.path = path + index; + file.dataAdded_time = 'xxx'; + file.modified_time = 'xxx'; + fileList.push(file); + } + } else if (mediaType == 'audio') { + for (var index = 0; index < 18; index++) { + let file: FileInfo = new FileInfo("" + index + ".mp3"); + file.type = MediaType.MEDIA_TYPE_AUDIO; + file.path = path + index; + file.dataAdded_time = 'xxx'; + file.modified_time = 'xxx'; + fileList.push(file); + } + } else if (mediaType == 'file') { + let fileInfo4: FileInfo = new FileInfo("文件夹3"); + fileInfo4.type = MediaType.MEDIA_TYPE_ALBUM; + fileInfo4.path = path + '5'; + fileInfo4.dataAdded_time = 'xxx'; + fileInfo4.modified_time = 'xxx'; + fileList.push(fileInfo4); + let fileInfo5: FileInfo = new FileInfo("文件夹4"); + fileInfo5.type = MediaType.MEDIA_TYPE_ALBUM; + fileInfo5.path = path + '6'; + fileInfo5.dataAdded_time = 'xxx'; + fileInfo5.modified_time = 'xxx'; + fileList.push(fileInfo5); + let fileInfo6: FileInfo = new FileInfo("文本文档.txt"); + fileInfo6.type = MediaType.MEDIA_TYPE_FILE; + fileInfo6.path = path + '7'; + fileInfo6.size = '1,000 KB' + fileInfo6.dataAdded_time = 'xxx'; + fileInfo6.modified_time = 'xxx'; + fileList.push(fileInfo6); + let fileInfo7: FileInfo = new FileInfo("验收文稿.ppt"); + fileInfo7.type = MediaType.MEDIA_TYPE_FILE; + fileInfo7.path = path + '8'; + fileInfo7.size = '520,000 KB' + fileInfo7.dataAdded_time = 'xxx'; + fileInfo7.modified_time = 'xxx'; + fileList.push(fileInfo7); + } + } + } else { + // fileList = filemanager.listfile(deviceName, mediaType, path); + } + logInfo(TAG, "get file list is " + fileList.length) + return fileList; +} \ No newline at end of file diff --git a/product/RK/src/main/ets/module/LogUtils.ets b/common/src/main/ets/components/Utils/LogUtils.ts similarity index 51% rename from product/RK/src/main/ets/module/LogUtils.ets rename to common/src/main/ets/components/Utils/LogUtils.ts index 8e6bb82..97589cf 100644 --- a/product/RK/src/main/ets/module/LogUtils.ets +++ b/common/src/main/ets/components/Utils/LogUtils.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,10 +13,19 @@ * limitations under the License. */ -export function LogInfo(TAG: string, message: string | number): void { - console.info('filePicker_' + TAG + ': ' + message) +export function logDebug(TAG: string, message: string | number): void { + console.debug('FilePicker_' + TAG + ': ' + message) } -export function LogDebug(TAG: string, message: string | number): void { - console.debug('filePicker_' + TAG + ': ' + message) +export function logInfo(TAG: string, message: string | number): void { + console.info('FilePicker_' + TAG + ': ' + message) +} + + +export function logWarn(TAG: string, message: string | number): void { + console.warn('FilePicker_' + TAG + ': ' + message) +} + +export function logError(TAG: string, message: string | number): void { + console.error('FilePicker_' + TAG + ': ' + message) } diff --git a/common/src/main/ets/components/Utils/Utils.ets b/common/src/main/ets/components/Utils/Utils.ets new file mode 100644 index 0000000..e4f2060 --- /dev/null +++ b/common/src/main/ets/components/Utils/Utils.ets @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { MediaName } from "../Data/Constants" +import { TopPathInfo } from '../data/toppathinfo' +import { logInfo } from './logutils' + +var TAG: string = 'Utils' + +var strTypeArr = [ + [MediaName.IMAGE, '图片'], + [MediaName.VIDEO, '视频'], + [MediaName.AUDIO, '音乐'], + [MediaName.FILE, '文档'], +] + +export function changeTypeToString(mediaType: string): string { + logInfo(TAG, 'changeTypeToString type = ' + mediaType) + for (var i = 0; i < strTypeArr.length; i++) { + if (strTypeArr[i][0] == mediaType) { + return strTypeArr[i][1] + } + } + return '' +} + +export function changeStringToType(name: string): string { + logInfo(TAG, 'changeStringToType type = ' + name) + for (var i = 0; i < strTypeArr.length; i++) { + if (strTypeArr[i][1] == name) { + return strTypeArr[i][0] + } + } + return '' +} + +var fileSuffixAndType = [ + ['.doc', $r("app.media.ic_file_doc"), $r("app.string.file_docx")], + ['.html', $r("app.media.ic_file_html"), $r("app.string.file_html")], + ['.pdf', $r("app.media.ic_file_pdf"), $r("app.string.file_pdf")], + ['.pptx', $r("app.media.ic_file_pptx"), $r("app.string.file_pptx")], + ['.ppt', $r("app.media.ic_file_pptx"), $r("app.string.file_pptx")], + ['.rar', $r("app.media.ic_file_rar"), $r("app.string.file_rar")], + ['.txt', $r("app.media.ic_file_txt"), $r("app.string.file_txt")], + ['.xls', $r("app.media.ic_file_xls"), $r("app.string.file_xls")], + ['.xml', $r("app.media.ic_file_xml"), $r("app.string.file_xml")], + ['.zip', $r("app.media.ic_file_zip"), $r("app.string.file_zip")], +] + +export function getShowIconBySuffix(suffix: string): string | Resource { + logInfo(TAG, 'getShowIconBySuffix suffix = ' + suffix) + for (var i = 0; i < fileSuffixAndType.length; i++) { + if (isTwoStringEqual(fileSuffixAndType[i][0].toString(), suffix)) { + return fileSuffixAndType[i][1] + } + } + return $r("app.media.ic_file_unknown") +} + +function isTwoStringEqual(src: string, tar: string) { + if (src.indexOf(tar) == 0 && tar.indexOf(src) == 0) { + return true; + } + return false; +} + +export function updateTopPathInfo(currentPathInfo: Array, name: string, path: string) { + currentPathInfo.forEach((item: TopPathInfo) => { + item.opacity = 0.4 + }) + + currentPathInfo.push(new TopPathInfo(name, path)) + AppStorage.Set('topPathInfo', currentPathInfo) + return currentPathInfo +} \ No newline at end of file diff --git a/common/src/main/ets/components/View/ChooseDialog.ets b/common/src/main/ets/components/View/ChooseDialog.ets new file mode 100644 index 0000000..4d15613 --- /dev/null +++ b/common/src/main/ets/components/View/ChooseDialog.ets @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { FileInfo } from '../Data/FileInfo' +import { logInfo } from '../Utils/LogUtils' + +let TAG: string = 'DialogUtils' + +@CustomDialog +export struct ChooseDialog { + controller: CustomDialogController + + build() { + Column() { + Row() { + Text('选择该文件') + } + + Row() { + Button() { + Text('取消') + .height('100%') + .fontSize(24) + .fontColor(Color.Blue) + } + .width(px2vp(200)) + .height(px2vp(50)) + .backgroundColor(Color.White) + .onClick(() => { + this.controller.close() + }) + + Divider() + .vertical(true) + .color(Color.Gray) + .height(40) + .margin({ top: 0, right: 10, bottom: 0, left: 10 }) + + Button() { + Text('确定') + .height('100%') + .fontSize(24) + .fontColor(Color.Blue) + } + .width(px2vp(200)) + .height(px2vp(50)) + .backgroundColor(Color.White) + .onClick(() => { + let choseItem: FileInfo = AppStorage.Get('selectedFileInfo') + if (choseItem != null) { + let files: Array = AppStorage.Get('choseFiles') + let flag: boolean = true + files.forEach((item: FileInfo) => { + logInfo(TAG, 'item.name = ' + item.name + '; item.path = ' + item.path) + logInfo(TAG, 'choseItem.name = ' + choseItem.name + '; choseItem.path = ' + choseItem.path) + if (item.name == choseItem.name && item.path == choseItem.path) { + flag = false + } + }) + if (flag) { + files.push(choseItem) + AppStorage.Set('choseFiles', files) + } + } + this.controller.close() + }) + } + .padding(20) + } + .padding({ + top: 25, + right: 0, + bottom: 15, + left: 0 + }) + } +} \ No newline at end of file diff --git a/common/src/main/ets/components/View/WarningDialog.ets b/common/src/main/ets/components/View/WarningDialog.ets new file mode 100644 index 0000000..e7024fc --- /dev/null +++ b/common/src/main/ets/components/View/WarningDialog.ets @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@CustomDialog +export struct WarningDialog { + @Link code: number + controller: CustomDialogController + cancel: () => void + confirm: () => void + + build() { + Column() { + Text('Warning Title').fontSize(20).margin(10) + if (this.code == 1) { + Text($r("app.string.save_file_has_same_file")).fontSize(16).margin(10) + } else if (this.code == 2) { + Text($r("app.string.save_file_no_media_permission")).fontSize(16).margin(10) + } else { + Text($r("app.string.save_file_unknown_reason")).fontSize(16).margin(10) + } + Flex({ justifyContent: FlexAlign.SpaceAround }) { + Button('cancel') + .onClick(() => { + this.controller.close() + this.cancel() + }) + .backgroundColor("0xffffff") + .fontColor(Color.Black) + Button('confirm') + .onClick(() => { + this.controller.close() + this.confirm() + }) + .backgroundColor("0xffffff") + .fontColor(Color.Red) + }.margin({ bottom: 10 }) + } + } +} \ No newline at end of file diff --git a/common/src/main/module.json5 b/common/src/main/module.json5 new file mode 100644 index 0000000..064cd17 --- /dev/null +++ b/common/src/main/module.json5 @@ -0,0 +1,11 @@ +{ + "module": { + "name": "common", + "type": "har", + "deviceTypes": [ + "phone", + "tablet" + ], + "uiSyntax": "ets" + } +} diff --git a/common/src/main/resources/base/element/string.json b/common/src/main/resources/base/element/string.json new file mode 100644 index 0000000..06ba688 --- /dev/null +++ b/common/src/main/resources/base/element/string.json @@ -0,0 +1,68 @@ +{ + "string": [ + { + "name": "page_show", + "value": "page from npm package" + }, + { + "name": "save_file_has_same_file", + "value": "Duplicate name file already exists" + }, + { + "name": "save_file_no_media_permission", + "value": "Saving to media library is not currently supported" + }, + { + "name": "save_file_unknown_reason", + "value": "Unknown error" + }, + { + "name": "file_unknown", + "value": "Unknown file" + }, + { + "name": "file_zip", + "value": "Compressed (zipped) file" + }, + { + "name": "file_xml", + "value": "XML document" + }, + { + "name": "file_xls", + "value": "Microsoft Excel worksheet" + }, + { + "name": "file_txt", + "value": "Txt document" + }, + { + "name": "file_rar", + "value": "Rar compressed file" + }, + { + "name": "file_pdf", + "value": "Adobe Acrobat Document" + }, + { + "name": "file_html", + "value": "HTML Document" + }, + { + "name": "file_pptx", + "value": "Microsoft PowerPoint Presentation" + }, + { + "name": "file_docx", + "value": "Microsoft Word Document" + }, + { + "name": "file_type", + "value": "file type" + }, + { + "name": "file_name", + "value": "file name : " + } + ] +} diff --git a/product/RK/src/main/resources/base/media/ic_file_doc.png b/common/src/main/resources/base/media/ic_file_doc.png similarity index 100% rename from product/RK/src/main/resources/base/media/ic_file_doc.png rename to common/src/main/resources/base/media/ic_file_doc.png diff --git a/product/RK/src/main/resources/base/media/ic_file_fold.png b/common/src/main/resources/base/media/ic_file_fold.png similarity index 100% rename from product/RK/src/main/resources/base/media/ic_file_fold.png rename to common/src/main/resources/base/media/ic_file_fold.png diff --git a/product/RK/src/main/resources/base/media/ic_file_html.png b/common/src/main/resources/base/media/ic_file_html.png similarity index 100% rename from product/RK/src/main/resources/base/media/ic_file_html.png rename to common/src/main/resources/base/media/ic_file_html.png diff --git a/product/RK/src/main/resources/base/media/ic_file_manager.png b/common/src/main/resources/base/media/ic_file_manager.png similarity index 100% rename from product/RK/src/main/resources/base/media/ic_file_manager.png rename to common/src/main/resources/base/media/ic_file_manager.png diff --git a/product/RK/src/main/resources/base/media/ic_file_pdf.png b/common/src/main/resources/base/media/ic_file_pdf.png similarity index 100% rename from product/RK/src/main/resources/base/media/ic_file_pdf.png rename to common/src/main/resources/base/media/ic_file_pdf.png diff --git a/product/RK/src/main/resources/base/media/ic_file_pptx.png b/common/src/main/resources/base/media/ic_file_pptx.png similarity index 100% rename from product/RK/src/main/resources/base/media/ic_file_pptx.png rename to common/src/main/resources/base/media/ic_file_pptx.png diff --git a/product/RK/src/main/resources/base/media/ic_file_rar.png b/common/src/main/resources/base/media/ic_file_rar.png similarity index 100% rename from product/RK/src/main/resources/base/media/ic_file_rar.png rename to common/src/main/resources/base/media/ic_file_rar.png diff --git a/product/RK/src/main/resources/base/media/ic_file_txt.png b/common/src/main/resources/base/media/ic_file_txt.png similarity index 100% rename from product/RK/src/main/resources/base/media/ic_file_txt.png rename to common/src/main/resources/base/media/ic_file_txt.png diff --git a/product/RK/src/main/resources/base/media/ic_file_unknown.png b/common/src/main/resources/base/media/ic_file_unknown.png similarity index 100% rename from product/RK/src/main/resources/base/media/ic_file_unknown.png rename to common/src/main/resources/base/media/ic_file_unknown.png diff --git a/product/RK/src/main/resources/base/media/ic_file_xls.png b/common/src/main/resources/base/media/ic_file_xls.png similarity index 100% rename from product/RK/src/main/resources/base/media/ic_file_xls.png rename to common/src/main/resources/base/media/ic_file_xls.png diff --git a/product/RK/src/main/resources/base/media/ic_file_xml.png b/common/src/main/resources/base/media/ic_file_xml.png similarity index 100% rename from product/RK/src/main/resources/base/media/ic_file_xml.png rename to common/src/main/resources/base/media/ic_file_xml.png diff --git a/product/RK/src/main/resources/base/media/ic_file_zip.png b/common/src/main/resources/base/media/ic_file_zip.png similarity index 100% rename from product/RK/src/main/resources/base/media/ic_file_zip.png rename to common/src/main/resources/base/media/ic_file_zip.png diff --git a/product/pad/src/main/resources/base/media/ic_photo.png b/common/src/main/resources/base/media/ic_photo.png similarity index 100% rename from product/pad/src/main/resources/base/media/ic_photo.png rename to common/src/main/resources/base/media/ic_photo.png diff --git a/common/src/main/resources/zh_CN/element/string.json b/common/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000..04f43ae --- /dev/null +++ b/common/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,64 @@ +{ + "string": [ + { + "name": "save_file_has_same_file", + "value": "已有重名文件" + }, + { + "name": "save_file_no_media_permission", + "value": "当前不支持保存到媒体库" + }, + { + "name": "save_file_unknown_reason", + "value": "未知错误" + }, + { + "name": "file_unknown", + "value": "未知文件" + }, + { + "name": "file_zip", + "value": "压缩(zipped)文件" + }, + { + "name": "file_xml", + "value": "XML文档" + }, + { + "name": "file_xls", + "value": "Microsoft Excel工作表" + }, + { + "name": "file_txt", + "value": "TXT文档" + }, + { + "name": "file_rar", + "value": "RAR压缩文件" + }, + { + "name": "file_pdf", + "value": "Adobe Acrobat Document" + }, + { + "name": "file_html", + "value": "HTML网页文件" + }, + { + "name": "file_pptx", + "value": "Microsoft PowerPoint演示文稿" + }, + { + "name": "file_docx", + "value": "Microsoft Word文档" + }, + { + "name": "file_type", + "value": "文件类型" + }, + { + "name": "file_name", + "value": "文件名:" + } + ] +} \ No newline at end of file diff --git a/feature/FileInfo.ets b/feature/FileInfo.ets deleted file mode 100644 index 3bea068..0000000 --- a/feature/FileInfo.ets +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { mediaType } from './Constants.ets' - -export class FileInfo { - name: string - path: string - type: number= mediaType.MEDIA_TYPE_ALBUM - size: string - dataAdded_time: string - modified_time: string - mediaType: string - thumbnail: Resource - font_color: Color | string | Resource - opacity: number - list_background: string | Resource - - constructor(name: string) { - this.name = name - } -} - -export class TopPathInfo { - name: string - path: string - opacity: number = 1 - - constructor(name: string, path: string) { - this.name = name - this.path = path - } -} \ No newline at end of file diff --git a/package.json b/package.json index 9adcf49..562cfc6 100644 --- a/package.json +++ b/package.json @@ -1,18 +1,18 @@ { - "license": "ISC", - "devDependencies": {}, - "name": "filepicker", - "ohos": { - "org": "huawei", - "directoryLevel": "project", - "buildTool": "hvigor" + "license":"ISC", + "devDependencies":{}, + "name":"filepicker", + "ohos":{ + "org":"huawei", + "directoryLevel":"project", + "buildTool":"hvigor" }, - "description": "example description", - "repository": {}, - "version": "1.0.0", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "1.0.6", - "hypium": "^1.0.0", - "@ohos/hvigor": "1.0.6" + "description":"example description", + "repository":{}, + "version":"1.0.0", + "dependencies":{ + "@ohos/hvigor-ohos-plugin":"1.0.6", + "hypium":"^1.0.0", + "@ohos/hvigor":"1.0.6" } -} +} \ No newline at end of file diff --git a/product/RK/package-lock.json b/product/RK/package-lock.json index e27c4f5..2e1ce21 100644 --- a/product/RK/package-lock.json +++ b/product/RK/package-lock.json @@ -1,5 +1,11 @@ { "name": "rk", "version": "1.0.0", - "lockfileVersion": 1 + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "@ohos/common": { + "version": "file:../../common" + } + } } diff --git a/product/RK/package.json b/product/RK/package.json index a04762c..85b19d5 100644 --- a/product/RK/package.json +++ b/product/RK/package.json @@ -1,14 +1,16 @@ { - "license": "ISC", - "devDependencies": {}, - "name": "rk", - "ohos": { - "org": "huawei", - "directoryLevel": "module", - "buildTool": "hvigor" - }, - "description": "example description", - "repository": {}, - "version": "1.0.0", - "dependencies": {} + "license": "ISC", + "devDependencies": {}, + "name": "rk", + "ohos": { + "org": "huawei", + "directoryLevel": "module", + "buildTool": "hvigor" + }, + "description": "example description", + "repository": {}, + "version": "1.0.0", + "dependencies": { + "@ohos/common": "file:../../common" + } } diff --git a/product/RK/src/main/ets/Application/AbilityStage.ts b/product/RK/src/main/ets/Application/AbilityStage.ts index 32dfe93..d637557 100644 --- a/product/RK/src/main/ets/Application/AbilityStage.ts +++ b/product/RK/src/main/ets/Application/AbilityStage.ts @@ -1,7 +1,25 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import AbilityStage from "@ohos.application.AbilityStage" +import { logInfo } from '../../../../../../common/src/main/ets/components/Utils/LogUtils' + +const TAG = "MyAbilityStage" export default class MyAbilityStage extends AbilityStage { onCreate() { - console.log("[Demo] MyAbilityStage onCreate") + logInfo(TAG, "onCreate") } } \ No newline at end of file diff --git a/product/RK/src/main/ets/MainAbility/MainAbility.ts b/product/RK/src/main/ets/MainAbility/MainAbility.ts index 70e8a04..b912996 100644 --- a/product/RK/src/main/ets/MainAbility/MainAbility.ts +++ b/product/RK/src/main/ets/MainAbility/MainAbility.ts @@ -1,7 +1,7 @@ import Ability from '@ohos.application.Ability' import display from '@ohos.display' import { Callback } from 'basic' -import { LogInfo, LogDebug } from '../module/LogUtils' +import { logInfo, logError, logWarn } from '../../../../../../common/src/main/ets/components/Utils/LogUtils' let displayWidth: number = 0 let displayHeight: number = 0 @@ -10,25 +10,22 @@ const TAG = "MainAbility" export default class MainAbility extends Ability { onCreate(want, launchParam) { - console.log("filePicker_MainAbility: onCreate") + logInfo(TAG, "onCreate") globalThis.abilityWant = want; globalThis.startMode = want.parameters.startMode globalThis.saveFile = want.parameters.saveFile globalThis.debugMode = want.parameters.debugMode - console.log('filePicker_MainAbility: startMode = ' + globalThis.startMode) - console.log('filePicker_MainAbility: file_name = ' + globalThis.saveFile) - console.log('filePicker_MainAbility: debugMode = ' + globalThis.debugMode) - + logInfo(TAG, `parameters ${JSON.stringify(want.parameters)}`) } onDestroy() { - console.log("[Demo] MainAbility onDestroy") + logInfo(TAG, "onDestroy") } onWindowStageCreate(windowStage) { // Main window is created, set main page for this ability - LogInfo(TAG, "[Demo] MainAbility onWindowStageCreate") + logInfo(TAG, "onWindowStageCreate") globalThis.context = this.context @@ -37,17 +34,17 @@ export default class MainAbility extends Ability { onWindowStageDestroy() { // Main window is destroyed, release UI related resources - console.log("[Demo] MainAbility onWindowStageDestroy") + logInfo(TAG, "onWindowStageDestroy") } onForeground() { // Ability has brought to foreground - console.log("[Demo] MainAbility onForeground") + logInfo(TAG, "onForeground") } onBackground() { // Ability has back to background - console.log("[Demo] MainAbility onBackground") + logInfo(TAG, "onBackground") } private requestPermissions(callback: Callback) { @@ -57,10 +54,10 @@ export default class MainAbility extends Ability { "ohos.permission.WRITE_MEDIA" ] globalThis.context.requestPermissionsFromUser(permissionList).then(function (data) { - LogInfo(TAG, 'filePicker_MainAbility: request permission data result = ' + data.authResults) + logInfo(TAG, 'request permission data result = ' + data.authResults) callback() }, (error) => { - LogInfo(TAG, 'filePicker_MainAbility: fail to request permission error code = ' + error.code) + logError(TAG, 'fail to request permission error code = ' + error.code) }) } @@ -74,10 +71,10 @@ export default class MainAbility extends Ability { globalThis.mainDialogWidth = dis.width globalThis.mainDialogHeight = (((displayHeight) - 180) * 0.7) / 1.3 - LogInfo(TAG, "cjl displayWidth = " + displayWidth + " displayHeight = " + displayHeight) + logInfo(TAG, "displayWidth = " + displayWidth + " displayHeight = " + displayHeight) windowStage.getMainWindow().then(win => { - LogInfo(TAG, "cjl windowStage.getMainWindow()") + logInfo(TAG, "windowStage.getMainWindow()") win.resetSize(displayWidth, displayHeight - 120) @@ -85,25 +82,25 @@ export default class MainAbility extends Ability { win.setBackgroundColor("#00FFFFFF", (err, data) => { if (err.code) { - LogInfo(TAG, "Fail to set the background color" + JSON.stringify(err)) + logWarn(TAG, "Fail to set the background color" + JSON.stringify(err)) } else { - LogInfo(TAG, "Success to set the background color" + JSON.stringify(data)) + logInfo(TAG, "Success to set the background color" + JSON.stringify(data)) } }) win.disableWindowDecor((err, data) => { if (err.code) { - LogInfo(TAG, 'Failed to set the disableWindowDecor. Data: ' + JSON.stringify(data)) + logWarn(TAG, "Fail to disable Window Decor" + JSON.stringify(err)) } else { - LogInfo(TAG, 'Succeeded in setting the disableWindowDecor. Data: ' + JSON.stringify(data)) + logInfo(TAG, "Success to disable Window Decor" + JSON.stringify(data)) } }) win.setWindowMode(102, (err, data) => { if (err.code) { - LogInfo(TAG, 'Failed to set the setWindowMode. Data: ' + JSON.stringify(data)) + logWarn(TAG, 'Failed to set the setWindowMode. Data: ' + JSON.stringify(data)) } else { - LogInfo(TAG, 'Succeeded in setting the setWindowMode. Data: ' + JSON.stringify(data)) + logInfo(TAG, 'Succeeded in setting the setWindowMode. Data: ' + JSON.stringify(data)) } }) diff --git a/product/RK/src/main/ets/module/AbilityUtils.ets b/product/RK/src/main/ets/module/AbilityUtils.ets deleted file mode 100644 index 837ef84..0000000 --- a/product/RK/src/main/ets/module/AbilityUtils.ets +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import display from '@ohos.display' -import featureAbility from '@ohos.ability.featureAbility' -import { LogInfo } from '../module/LogUtils.ets' -import { DisplayInfo } from './DisplayInfo.ets' - -var TAG: string = 'AbilityUtils' - -export function terminateSelfWithResult(resultCode: number, result: string): void { - LogInfo(TAG, 'terminateSelfWithResult') - let startMode: string = AppStorage.Get('startMode') - var abilityResult = { - resultCode: resultCode, - want: { - parameters: { - 'startMode': startMode, - 'result': result - } - } - } - globalThis.context.terminateSelfWithResult(abilityResult, (error) => { - if (error.code) { - LogInfo(TAG, 'Operation failed. Cause: ' + JSON.stringify(error)) - return - } - LogInfo(TAG, 'Operation succeeded') - }) -} - -export function initData(): void { - LogInfo(TAG, 'initData') - initWindowScale() - - getWantFromHap() -} - -function initWindowScale(): void { - display.getDefaultDisplay().then(dis => { - LogInfo(TAG, 'width = ' + dis.width + ';height= ' + dis.height) - let displayInfo: DisplayInfo = new DisplayInfo() - - if (dis.width > dis.height) { // 横屏 - displayInfo.width = dis.width - displayInfo.height = dis.height * 0.6 // 需要减去信号栏和导航栏的高度 - displayInfo.mainDialogHeight = displayInfo.height - vp2px(64 + 76) - displayInfo.mainDialogWidth = displayInfo.width - - } else { // 竖屏 - displayInfo.width = dis.width - displayInfo.height = dis.height * 0.65 // 需要减去信号栏和导航栏的高度 - displayInfo.mainDialogHeight = displayInfo.height - vp2px(64 + 76) - //displayInfo.mainDialogHeight = displayInfo.height - (64 + 76) * 2 - displayInfo.mainDialogWidth = displayInfo.width - } - - LogInfo(TAG, 'mainDialogWidth = ' + displayInfo.mainDialogWidth) - LogInfo(TAG, 'mainDialogHeight = ' + displayInfo.mainDialogHeight) - AppStorage.SetOrCreate('displayInfo', displayInfo) - }) -} - -function getWantFromHap(): void { - featureAbility.getWant() - .then((Want) => { - var mode: string = Want.parameters['startMode'] - if (mode == undefined) { - AppStorage.SetOrCreate('startMode', 'choose') - } else { - AppStorage.SetOrCreate('startMode', mode) - } - let save_name: string = Want.parameters['file_name'] - AppStorage.Set('saveName', save_name) - LogInfo(TAG, 'saveName = ' + save_name) - }).catch((error) => { - LogInfo(TAG, 'fail Data: ' + JSON.stringify(error)) - }) -} \ No newline at end of file diff --git a/product/RK/src/main/ets/module/Constants.ets b/product/RK/src/main/ets/module/Constants.ets deleted file mode 100644 index 6913acd..0000000 --- a/product/RK/src/main/ets/module/Constants.ets +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export enum menuLevel { - MENU_FIRST_LEVEL_BY_TYPE = 1, - MENU_SECOND_LEVEL_BY_FOLD = 2, - MENU_THIRD_LEVEL_HAS_PIC = 3, - MENU_THIRD_LEVEL_HAS_DETAIL = 4, -} - -export enum media_type { - MEDIA_TYPE_FILE = 1, - MEDIA_TYPE_IMAGE = 3, - MEDIA_TYPE_VIDEO = 4, - MEDIA_TYPE_AUDIO = 5, - MEDIA_TYPE_ALBUM = 8 -} - -export enum GridItemSize { - GRID_ITEM_HEIGHT = 126, - //GRID_ITEM_WIDTH = 112, - GRID_ITEM_WIDTH = 96, - GRID_ITEM_COLUMNS_GAP = 8, - GRID_ITEM_ROWS_GAP = 8, -} - -export enum terminate_reason { - SUCCESS = 0, - NO_ACTION = -1, -} \ No newline at end of file diff --git a/product/RK/src/main/ets/module/DialogUtils.ets b/product/RK/src/main/ets/module/DialogUtils.ets deleted file mode 100644 index be3355e..0000000 --- a/product/RK/src/main/ets/module/DialogUtils.ets +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { FileInfo } from './FileInfo.ets' - -@CustomDialog -export struct WarningDialog { - @Link code: number - controller: CustomDialogController - cancel: () => void - confirm: () => void - - build() { - Column() { - Text('Warning Title').fontSize(20).margin(10) - if (this.code == 1) { - Text($r("app.string.save_file_has_same_file")).fontSize(16).margin(10) - } else if (this.code == 2) { - Text($r("app.string.save_file_no_media_permission")).fontSize(16).margin(10) - } else { - Text($r("app.string.save_file_unknown_reason")).fontSize(16).margin(10) - } - Flex({ justifyContent: FlexAlign.SpaceAround }) { - Button('cancel') - .onClick(() => { - this.controller.close() - this.cancel() - }).backgroundColor(0xffffff).fontColor(Color.Black) - Button('confirm') - .onClick(() => { - this.controller.close() - this.confirm() - }).backgroundColor(0xffffff).fontColor(Color.Red) - }.margin({ bottom: 10 }) - } - } -} - -@CustomDialog -export struct ChooseDialog { - controller: CustomDialogController - - build() { - Column() { - Row() { - Text('选择该文件') - } - Row() { - Button() { - Text('取消') - .height('100%') - .fontSize(24) - .fontColor(Color.Blue) - } - .width(px2vp(200)) - .height(px2vp(50)) - .backgroundColor(Color.White) - .onClick(() => { - this.controller.close() - }) - - Divider() - .vertical(true) - .color(Color.Gray) - .height(40) - .margin({top: 0, right: 10, bottom: 0, left: 10}) - - Button() { - Text('确定') - .height('100%') - .fontSize(24) - .fontColor(Color.Blue) - } - .width(px2vp(200)) - .height(px2vp(50)) - .backgroundColor(Color.White) - .onClick(() => { - let item: FileInfo = AppStorage.Get('selectedFileInfo') - if (item != null) { - let files: Array = AppStorage.Get('choseFiles') - if (files.indexOf(item) == -1) { - files.push(item) - AppStorage.Set('choseFiles', files) - } - } - this.controller.close() - }) - } - .padding(20) - } - .padding({ - top: 25, - right: 0, - bottom: 15, - left: 0 - }) - } -} \ No newline at end of file diff --git a/product/RK/src/main/ets/module/DisplayInfo.ets b/product/RK/src/main/ets/module/DisplayInfo.ets deleted file mode 100644 index 6b764fa..0000000 --- a/product/RK/src/main/ets/module/DisplayInfo.ets +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export class DisplayInfo { - width: number - height: number - mainDialogWidth: number - mainDialogHeight: number -} \ No newline at end of file diff --git a/product/RK/src/main/ets/module/FileInfo.ets b/product/RK/src/main/ets/module/FileInfo.ets deleted file mode 100644 index 28d87de..0000000 --- a/product/RK/src/main/ets/module/FileInfo.ets +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { media_type } from './Constants.ets' - -export class FileInfo { - name: string - path: string - type: number= media_type.MEDIA_TYPE_ALBUM - size: string - dataAdded_time: string - modified_time: string - mediaType: string - thumbnail: Resource - font_color: Color | string | Resource - opacity: number - list_background: string | Resource - - constructor(name: string) { - this.name = name - } -} - -export class TopPathInfo { - name: string - path: string - opacity: number = 1 - - constructor(name: string, path: string) { - this.name = name - this.path = path - } -} \ No newline at end of file diff --git a/product/RK/src/main/ets/module/FileManagerServiceUtils.ets b/product/RK/src/main/ets/module/FileManagerServiceUtils.ets deleted file mode 100644 index 501d2d9..0000000 --- a/product/RK/src/main/ets/module/FileManagerServiceUtils.ets +++ /dev/null @@ -1,341 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { media_type } from './Constants.ets'; -import { FileInfo } from '../module/FileInfo.ets' -import { LogInfo } from '../module/LogUtils.ets' - -var TAG = 'FileManagerServiceUtils' -var isDebug: boolean = true; - -export function getFirstMenu(deviceName: string): Array { - let fileList: Array = []; - if (isDebug) { - let file1: FileInfo = new FileInfo('image_album'); - file1.type = media_type.MEDIA_TYPE_ALBUM; - file1.path = 'dataability:///album'; - file1.size = ''; - file1.dataAdded_time = 'xxx'; - file1.modified_time = 'xxx'; - fileList.push(file1); - - let file2: FileInfo = new FileInfo('video_album'); - file2.type = media_type.MEDIA_TYPE_ALBUM; - file2.path = 'dataability:///album'; - file2.size = ''; - file2.dataAdded_time = 'xxx'; - file2.modified_time = 'xxx'; - fileList.push(file2); - - let file4: FileInfo = new FileInfo('file_folder'); - file4.type = media_type.MEDIA_TYPE_ALBUM; - file4.path = 'dataability:///album'; - file4.size = ''; - file4.dataAdded_time = 'xxx'; - file4.modified_time = 'xxx'; - fileList.push(file4); - - let file3: FileInfo = new FileInfo('audio_album'); - file3.type = media_type.MEDIA_TYPE_ALBUM; - file3.path = 'dataability:///album'; - file3.size = ''; - file3.dataAdded_time = 'xxx'; - file3.modified_time = 'xxx'; - fileList.push(file3); - } else { - // var fileInfo = filemanager.getRoot(deviceName); - } - - fileList.forEach(item => { - if (item.name == 'image_album') { - item.name = "图片"; - item.mediaType = 'image'; - item.thumbnail = $r("app.media.ic_photo") - } else if (item.name == 'video_album') { - item.name = "视频"; - item.mediaType = 'video'; - item.thumbnail = $r("app.media.ic_video") - } else if (item.name == 'audio_album') { - item.name = "音频"; - item.mediaType = 'audio'; - item.thumbnail = $r("app.media.ic_audio") - } else if (item.name == 'file_folder') { - item.name = "文档"; - item.mediaType = 'file'; - item.thumbnail = $r("app.media.ic_document") - } - }); - - return fileList; -} - -export function getListFile(deviceName: string, mediaType: string, path: string): Array { - LogInfo(TAG, "getListFile mediaType = " + mediaType + ';path = ' + path); - let fileList: Array = []; - if (isDebug) { - if (path == 'dataability:///album') { - if (mediaType == 'image') { - let fileInfo1: FileInfo = new FileInfo("微信的图片"); - fileInfo1.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo1.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/01'; - fileInfo1.dataAdded_time = 'xxx'; - fileInfo1.modified_time = 'xxx'; - fileList.push(fileInfo1); - let fileInfo2: FileInfo = new FileInfo("图片1"); - fileInfo2.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo2.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/02'; - fileInfo2.dataAdded_time = 'xxx'; - fileInfo2.modified_time = 'xxx'; - fileList.push(fileInfo2); - let fileInfo3: FileInfo = new FileInfo("图片2"); - fileInfo3.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo3.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/03'; - fileInfo3.dataAdded_time = 'xxx'; - fileInfo3.modified_time = 'xxx'; - fileList.push(fileInfo3); - let fileInfo4: FileInfo = new FileInfo("图片3"); - fileInfo4.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo4.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/04'; - fileInfo4.dataAdded_time = 'xxx'; - fileInfo4.modified_time = 'xxx'; - fileList.push(fileInfo4); - let fileInfo5: FileInfo = new FileInfo("图片4"); - fileInfo5.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo5.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/05'; - fileInfo5.dataAdded_time = 'xxx'; - fileInfo5.modified_time = 'xxx'; - fileList.push(fileInfo5); - let fileInfo6: FileInfo = new FileInfo("图片5"); - fileInfo6.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo6.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/06'; - fileInfo6.dataAdded_time = 'xxx'; - fileInfo6.modified_time = 'xxx'; - fileList.push(fileInfo6); - let fileInfo7: FileInfo = new FileInfo("图片6"); - fileInfo7.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo7.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/07'; - fileInfo7.dataAdded_time = 'xxx'; - fileInfo7.modified_time = 'xxx'; - fileList.push(fileInfo7); - let fileInfo8: FileInfo = new FileInfo("图片7"); - fileInfo8.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo8.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/08'; - fileInfo8.dataAdded_time = 'xxx'; - fileInfo8.modified_time = 'xxx'; - fileList.push(fileInfo8); - let fileInfo9: FileInfo = new FileInfo("图片8"); - fileInfo1.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo1.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/09'; - fileInfo1.dataAdded_time = 'xxx'; - fileInfo1.modified_time = 'xxx'; - fileList.push(fileInfo9); - let fileInfo10: FileInfo = new FileInfo("图片9"); - fileInfo10.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo10.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/10'; - fileInfo10.dataAdded_time = 'xxx'; - fileInfo10.modified_time = 'xxx'; - fileList.push(fileInfo10); - let fileInfo11: FileInfo = new FileInfo("图片10"); - fileInfo11.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo11.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/11'; - fileInfo11.dataAdded_time = 'xxx'; - fileInfo11.modified_time = 'xxx'; - fileList.push(fileInfo11); - } else if (mediaType == 'video') { - let fileInfo1: FileInfo = new FileInfo("视频0"); - fileInfo1.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo1.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/12'; - fileInfo1.dataAdded_time = 'xxx'; - fileInfo1.modified_time = 'xxx'; - fileList.push(fileInfo1); - let fileInfo2: FileInfo = new FileInfo("视频1"); - fileInfo2.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo2.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/13'; - fileInfo2.dataAdded_time = 'xxx'; - fileInfo2.modified_time = 'xxx'; - fileList.push(fileInfo2); - let fileInfo3: FileInfo = new FileInfo("视频2"); - fileInfo3.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo3.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/14'; - fileInfo3.dataAdded_time = 'xxx'; - fileInfo3.modified_time = 'xxx'; - fileList.push(fileInfo3); - let fileInfo4: FileInfo = new FileInfo("视频3"); - fileInfo4.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo4.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/15'; - fileInfo4.dataAdded_time = 'xxx'; - fileInfo4.modified_time = 'xxx'; - fileList.push(fileInfo4); - let fileInfo5: FileInfo = new FileInfo("视频4"); - fileInfo5.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo5.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/16'; - fileInfo5.dataAdded_time = 'xxx'; - fileInfo5.modified_time = 'xxx'; - fileList.push(fileInfo5); - } else if (mediaType == 'audio') { - let fileInfo1: FileInfo = new FileInfo("音频0"); - fileInfo1.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo1.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/17'; - fileInfo1.dataAdded_time = 'xxx'; - fileInfo1.modified_time = 'xxx'; - fileList.push(fileInfo1); - let fileInfo2: FileInfo = new FileInfo("音频1"); - fileInfo2.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo2.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/18'; - fileInfo2.dataAdded_time = 'xxx'; - fileInfo2.modified_time = 'xxx'; - fileList.push(fileInfo2); - let fileInfo3: FileInfo = new FileInfo("音频2"); - fileInfo3.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo3.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/19'; - fileInfo3.dataAdded_time = 'xxx'; - fileInfo3.modified_time = 'xxx'; - fileList.push(fileInfo3); - let fileInfo4: FileInfo = new FileInfo("音频3"); - fileInfo4.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo4.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/20'; - fileInfo4.dataAdded_time = 'xxx'; - fileInfo4.modified_time = 'xxx'; - fileList.push(fileInfo4); - let fileInfo5: FileInfo = new FileInfo("音频4"); - fileInfo5.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo5.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/21'; - fileInfo5.dataAdded_time = 'xxx'; - fileInfo5.modified_time = 'xxx'; - fileList.push(fileInfo5); - } else if (mediaType == 'file') { - let fileInfo1: FileInfo = new FileInfo("文件夹0"); - fileInfo1.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo1.mediaType = mediaType; - fileInfo1.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/22'; - fileInfo1.dataAdded_time = 'xxx'; - fileInfo1.modified_time = 'xxx'; - fileList.push(fileInfo1); - let fileInfo2: FileInfo = new FileInfo("文件夹1"); - fileInfo2.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo2.mediaType = mediaType; - fileInfo2.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/23'; - fileInfo2.dataAdded_time = 'xxx'; - fileInfo2.modified_time = 'xxx'; - fileList.push(fileInfo2); - let fileInfo3: FileInfo = new FileInfo("文件夹2"); - fileInfo3.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo3.mediaType = mediaType; - fileInfo3.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/24'; - fileInfo3.dataAdded_time = 'xxx'; - fileInfo3.modified_time = 'xxx'; - fileList.push(fileInfo3); - let fileInfo4: FileInfo = new FileInfo("文件夹3"); - fileInfo4.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo4.mediaType = mediaType; - fileInfo4.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/25'; - fileInfo4.dataAdded_time = 'xxx'; - fileInfo4.modified_time = 'xxx'; - fileList.push(fileInfo4); - let fileInfo5: FileInfo = new FileInfo("文件夹4"); - fileInfo5.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo5.mediaType = mediaType; - fileInfo5.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/26'; - fileInfo5.dataAdded_time = 'xxx'; - fileInfo5.modified_time = 'xxx'; - fileList.push(fileInfo5); - let fileInfo6: FileInfo = new FileInfo("文本文档.txt"); - fileInfo6.type = media_type.MEDIA_TYPE_FILE; - fileInfo6.mediaType = mediaType; - fileInfo6.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/27'; - fileInfo6.dataAdded_time = 'xxx'; - fileInfo6.modified_time = 'xxx'; - fileInfo6.size = '1,024 KB' - fileList.push(fileInfo6); - let fileInfo7: FileInfo = new FileInfo("验收文稿.ppt"); - fileInfo7.type = media_type.MEDIA_TYPE_FILE; - fileInfo7.mediaType = mediaType; - fileInfo7.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/28'; - fileInfo7.dataAdded_time = 'xxx'; - fileInfo7.modified_time = 'xxx'; - fileInfo7.size = '4,562,000 KB' - fileList.push(fileInfo7); - } - } else { - if (mediaType == 'image') { - for (var index = 0; index < 10; index++) { - let file: FileInfo = new FileInfo("" + index + ".png"); - file.type = media_type.MEDIA_TYPE_IMAGE; - file.path = path + index; - file.dataAdded_time = 'xxx'; - file.modified_time = 'xxx'; - fileList.push(file); - } - } else if (mediaType == 'video') { - for (var index = 0; index < 15; index++) { - let file: FileInfo = new FileInfo("" + index + ".wmv"); - file.type = media_type.MEDIA_TYPE_VIDEO; - file.path = path + index; - file.dataAdded_time = 'xxx'; - file.modified_time = 'xxx'; - fileList.push(file); - } - } else if (mediaType == 'audio') { - for (var index = 0; index < 18; index++) { - let file: FileInfo = new FileInfo("" + index + ".mp3"); - file.type = media_type.MEDIA_TYPE_AUDIO; - file.path = path + index; - file.dataAdded_time = 'xxx'; - file.modified_time = 'xxx'; - fileList.push(file); - } - } else if (mediaType == 'file') { - let fileInfo4: FileInfo = new FileInfo("文件夹3"); - fileInfo4.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo4.path = path + '5'; - fileInfo4.dataAdded_time = 'xxx'; - fileInfo4.modified_time = 'xxx'; - fileList.push(fileInfo4); - let fileInfo5: FileInfo = new FileInfo("文件夹4"); - fileInfo5.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo5.path = path + '6'; - fileInfo5.dataAdded_time = 'xxx'; - fileInfo5.modified_time = 'xxx'; - fileList.push(fileInfo5); - let fileInfo6: FileInfo = new FileInfo("文本文档.txt"); - fileInfo6.type = media_type.MEDIA_TYPE_FILE; - fileInfo6.path = path + '7'; - fileInfo6.size = '1,000 KB' - fileInfo6.dataAdded_time = 'xxx'; - fileInfo6.modified_time = 'xxx'; - fileList.push(fileInfo6); - let fileInfo7: FileInfo = new FileInfo("验收文稿.ppt"); - fileInfo7.type = media_type.MEDIA_TYPE_FILE; - fileInfo7.path = path + '8'; - fileInfo7.size = '520,000 KB' - fileInfo7.dataAdded_time = 'xxx'; - fileInfo7.modified_time = 'xxx'; - fileList.push(fileInfo7); - } - } - } else { - // fileList = filemanager.listfile(deviceName, mediaType, path); - } - LogInfo(TAG, "get file list is " + fileList.length) - return fileList; -} - -//保存某个文件,返回是否保存成功,或有错误提示,还需要增加三方应用包名 -export function saveFile(deviceName: string, name: string, path: string): boolean { - LogInfo(TAG, 'saveFile'); - - return true; - -} diff --git a/product/RK/src/main/ets/module/Utils.ets b/product/RK/src/main/ets/module/Utils.ets deleted file mode 100644 index ca959af..0000000 --- a/product/RK/src/main/ets/module/Utils.ets +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { TopPathInfo } from '../module/FileInfo.ets' -import { LogInfo } from '../module/LogUtils.ets' - -var TAG: string = 'Utils' - -export function getRootPath(): Array { - var root_path: Array = [] - root_path.push(new TopPathInfo('文件类型', '')) - return root_path -} - -var strTypeArr = [ - ['image', '图片'], - ['video', '视频'], - ['audio', '音频'], - ['file', '文档'], -] - -export function changeTypeToString(type: string): string { - LogInfo(TAG, 'changeTypeToString type = ' + type) - for (var i = 0; i < strTypeArr.length; i++) { - if (strTypeArr[i][0] == type) { - return strTypeArr[i][1] - } - } - return '' -} - -export function changeStringToType(type: string): string { - LogInfo(TAG, 'changeStringToType type = ' + type) - for (var i = 0; i < strTypeArr.length; i++) { - if (strTypeArr[i][1] == type) { - return strTypeArr[i][0] - } - } - return '' -} - -export function getItemNumberInGrid(itemWidth: number, itemGap: number, parentWidth: number): string { - LogInfo(TAG, 'getItemNumberInGrid') - let columnTemples: string = '' - let remainderWidth: number = parentWidth - itemWidth - columnTemples += '1fr' - while (itemWidth + itemGap < remainderWidth) { - remainderWidth = remainderWidth - (itemWidth + itemGap) - columnTemples += ' 1fr' - } - LogInfo(TAG, 'columnTemples = ' + columnTemples) - return columnTemples -} - -var fileSuffixAndType = [ - ['.doc', $r("app.media.ic_file_doc"), $r("app.string.file_docx")], - ['.html', $r("app.media.ic_file_html"), $r("app.string.file_html")], - ['.pdf', $r("app.media.ic_file_pdf"), $r("app.string.file_pdf")], - ['.pptx', $r("app.media.ic_file_pptx"), $r("app.string.file_pptx")], - ['.ppt', $r("app.media.ic_file_pptx"), $r("app.string.file_pptx")], - ['.rar', $r("app.media.ic_file_rar"), $r("app.string.file_rar")], - ['.txt', $r("app.media.ic_file_txt"), $r("app.string.file_txt")], - ['.xls', $r("app.media.ic_file_xls"), $r("app.string.file_xls")], - ['.xml', $r("app.media.ic_file_xml"), $r("app.string.file_xml")], - ['.zip', $r("app.media.ic_file_zip"), $r("app.string.file_zip")], -] - -export function getShowIconBySuffix(suffix: string): string | Resource { - LogInfo(TAG, 'getShowIconBySuffix suffix = ' + suffix) - for (var i = 0; i < fileSuffixAndType.length; i++) { - if (isTwoStringEqual(fileSuffixAndType[i][0].toString(),suffix)) { - return fileSuffixAndType[i][1] - } - } - return $r("app.media.ic_file_unknown") -} - -export function getShowTextBySuffix(suffix: string): string | Resource { - LogInfo(TAG, 'getShowTextBySuffix suffix = ' + suffix) - for (var i = 0; i < fileSuffixAndType.length; i++) { - if (fileSuffixAndType[i][0] == suffix) { - return fileSuffixAndType[i][2] - } - } - return $r("app.string.file_unknown") -} - -export function getWarningDialogMessage(code: number): string | Resource { - switch (code) { - case 1: - return $r("app.string.save_file_has_same_file") - case 2: - return $r("app.string.save_file_no_media_permission") - default: - return $r("app.string.save_file_unknown_reason") - } -} - -export function isTwoStringEqual(src: string, tar: string) { - if (src.indexOf(tar) == 0 && tar.indexOf(src) == 0) { - return true; - } - return false; -} - -export function updateTopPathInfo(currentPathInfo: Array, name: string, path: string) { - currentPathInfo.forEach((item: TopPathInfo) => { - item.opacity = 0.4 - }) - - currentPathInfo.push(new TopPathInfo(name, path)) - AppStorage.Set('topPathInfo', currentPathInfo) - return currentPathInfo -} \ No newline at end of file diff --git a/product/RK/src/main/ets/pages/FirstLevelByType.ets b/product/RK/src/main/ets/pages/FirstLevelByType.ets index f1a7477..bae0f3b 100644 --- a/product/RK/src/main/ets/pages/FirstLevelByType.ets +++ b/product/RK/src/main/ets/pages/FirstLevelByType.ets @@ -13,78 +13,77 @@ * limitations under the License. */ -import { FileInfo } from '../module/FileInfo' -import { LogInfo } from '../module/LogUtils' -import { menuLevel } from '../module/Constants' +import { FileInfo } from '../../../../../../common/src/main/ets/components/Data/FileInfo' +import { MenuLevel } from '../../../../../../common/src/main/ets/components/Data/Constants' @Component export struct FirstLevelByType { - private TAG: string = 'FirstLevelByType' - private mWorker - private mFileList: FileInfo[] - @Link mType: string - @Link mMenuLevel: number - @Link mCurrentPath: string + private TAG: string = 'FirstLevelByType' + private mWorker + private mFileList: FileInfo[] + @Link mType: string + @Link mMenuLevel: number + @Link mCurrentPath: string - build() { - Column() { - ForEach(this.mFileList, (item: FileInfo, index: number) => { + build() { Column() { - RowView({ - item: item, - mMenuLevel: $mMenuLevel, - mType: $mType, - mCurrentPath: $mCurrentPath - }) + ForEach(this.mFileList, (item: FileInfo, index: number) => { + Column() { + RowView({ + item: item, + mMenuLevel: $mMenuLevel, + mType: $mType, + mCurrentPath: $mCurrentPath + }) - Divider() - .color('#000000') - .opacity(0.1) - .visibility(this.mFileList.length == index + 1 ? Visibility.Hidden : Visibility.Visible) - .margin({ left: 40 * 1.3 }) + Divider() + .color('#000000') + .opacity(0.1) + .visibility(this.mFileList.length == index + 1 ? Visibility.Hidden : Visibility.Visible) + .margin({ left: 40 * 1.3 }) + } + .width('100%') + .height(56 * 1.3) + }, item => item.name.toString()) } + .padding({ top: 4 * 1.3, bottom: 4 * 1.3, right: 12 * 1.3, left: 12 * 1.3 }) + .alignItems(HorizontalAlign.Start) // 导致圆角消失 + .border({ radius: 24 }) + .opacity(0.9) + .backgroundColor('#FFFFFF') .width('100%') - .height(56 * 1.3) - }, item => item.name.toString()) } - .padding({ top: 4 * 1.3, bottom: 4 * 1.3, right: 12 * 1.3, left: 12 * 1.3 }) - .alignItems(HorizontalAlign.Start) // 导致圆角消失 - .border({ radius: 24 }) - .opacity(0.9) - .backgroundColor('#FFFFFF') - .width('100%') - } } @Component struct RowView { - private item: FileInfo = new FileInfo('') - @Link mMenuLevel: number - @Link mType: string - @Link mCurrentPath: string + private item: FileInfo = new FileInfo('') + @Link mMenuLevel: number + @Link mType: string + @Link mCurrentPath: string - build() { - Row() { - Image($r("app.media.ic_type_smallfile")) - .width(24 * 1.3) - .height(24 * 1.3) - Text(this.item.name) - .fontSize(16 * 1.3) - .fontColor('#182431') - .fontWeight(FontWeight.Medium) - .margin({ left: 16 * 1.3 }) - Blank() - Image($r("app.media.ic_right")) - .width(12 * 1.3) - .height(24 * 1.3) + build() { + Row() { + Image($r("app.media.ic_type_smallfile")) + .width(24 * 1.3) + .height(24 * 1.3) + Text(this.item.name) + .fontSize(16 * 1.3) + .fontColor('#182431') + .fontWeight(FontWeight.Medium) + .margin({ left: 16 * 1.3 }) + Blank() + Image($r("app.media.ic_right")) + .width(12 * 1.3) + .height(24 * 1.3) + } + .height(56 * 1.3) + .width('100%') // TODO + .backgroundColor(this.item.list_background) + .onClick(() => { + this.mType = this.item.mediaType + this.mCurrentPath = this.item.path + this.mMenuLevel = MenuLevel.MENU_SECOND_LEVEL_BY_FOLD + }) } - .height(56 * 1.3) - .width('100%') // TODO - .backgroundColor(this.item.list_background) - .onClick(() => { - this.mType = this.item.mediaType - this.mCurrentPath = this.item.path - this.mMenuLevel = menuLevel.MENU_SECOND_LEVEL_BY_FOLD - }) - } } \ No newline at end of file diff --git a/product/RK/src/main/ets/pages/SecondLevelByFold.ets b/product/RK/src/main/ets/pages/SecondLevelByFold.ets index 9549479..b1404a2 100644 --- a/product/RK/src/main/ets/pages/SecondLevelByFold.ets +++ b/product/RK/src/main/ets/pages/SecondLevelByFold.ets @@ -13,125 +13,125 @@ * limitations under the License. */ -import { FileInfo } from '../module/FileInfo' -import { changeTypeToString, updateTopPathInfo } from '../module/Utils' -import { LogInfo, LogDebug } from '../module/LogUtils' -import { menuLevel } from '../module/Constants' -import { getListFile } from '../module/FileManagerServiceUtils' +import { MenuLevel } from '../../../../../../common/src/main/ets/components/Data/Constants' +import { FileInfo } from '../../../../../../common/src/main/ets/components/Data/FileInfo' +import { getListFile } from '../../../../../../common/src/main/ets/components/Utils/FileManagerServiceUtils' +import { logDebug, logInfo } from '../../../../../../common/src/main/ets/components/Utils/LogUtils' +import { changeTypeToString, updateTopPathInfo } from '../../../../../../common/src/main/ets/components/utils/Utils' let TAG: string = 'SecondLevelByFold' @Component export struct SecondLevelByFold { - private mWorker - @Link mFileList: FileInfo[] - @Link @Watch('fileTypeChange') mType: string - @Link mMenuLevel: number - @Link mCurrentPath: string + private mWorker + @Link mFileList: FileInfo[] + @Link @Watch('fileTypeChange') mType: string + @Link mMenuLevel: number + @Link mCurrentPath: string - aboutToAppear(): void{ - LogInfo(TAG, 'aboutToAppear') - if (globalThis.debugMode) { - this.mFileList = getListFile('local', this.mType, this.mCurrentPath) - LogDebug(TAG, 'mFileList length = ' + this.mFileList.length) - } else { - this.mWorker.postMessage({ - request_data: 'listFile', - device_name: 'local', - menu_level: this.mMenuLevel, - media_type: this.mType, - path: this.mCurrentPath - }) - } - - updateTopPathInfo([], '文件类型', '') - updateTopPathInfo(AppStorage.Get('topPathInfo'), changeTypeToString(this.mType), this.mCurrentPath) - } - - fileTypeChange() { - LogInfo(TAG, 'fileTypeChange ' + this.mType) - if (globalThis.debugMode) { - this.mFileList = getListFile('local', this.mType, this.mCurrentPath) - } else { - this.mWorker.postMessage({ - request_data: 'listFile', - device_name: 'local', - menu_level: this.mMenuLevel, - media_type: this.mType, - path: this.mCurrentPath - }) - } - } - - build() { - Column() { - ForEach(this.mFileList, (item: FileInfo, index: number) => { - Column() { - SecondRowView({ - item: item, - mMenuLevel: $mMenuLevel, - mCurrentPath: $mCurrentPath, - isType: $mType - }) - - Divider() - .color('#000000') - .opacity(0.05) - .visibility(this.mFileList.length == index + 1 ? Visibility.Hidden : Visibility.Visible) - .margin({ left: 40 * 1.3 }) + aboutToAppear(): void{ + logInfo(TAG, 'aboutToAppear') + if (globalThis.debugMode) { + this.mFileList = getListFile('local', this.mType, this.mCurrentPath) + logDebug(TAG, 'mFileList length = ' + this.mFileList.length) + } else { + this.mWorker.postMessage({ + request_data: 'listFile', + device_name: 'local', + menu_level: this.mMenuLevel, + MediaType: this.mType, + path: this.mCurrentPath + }) } - .width('100%') - .height(56 * 1.3) - }, item => item.name.toString()) + + updateTopPathInfo([], '文件类型', '') + updateTopPathInfo(AppStorage.Get('topPathInfo'), changeTypeToString(this.mType), this.mCurrentPath) + } + + fileTypeChange() { + logInfo(TAG, 'fileTypeChange ' + this.mType) + if (globalThis.debugMode) { + this.mFileList = getListFile('local', this.mType, this.mCurrentPath) + } else { + this.mWorker.postMessage({ + request_data: 'listFile', + device_name: 'local', + menu_level: this.mMenuLevel, + MediaType: this.mType, + path: this.mCurrentPath + }) + } + } + + build() { + Column() { + ForEach(this.mFileList, (item: FileInfo, index: number) => { + Column() { + SecondRowView({ + item: item, + mMenuLevel: $mMenuLevel, + mCurrentPath: $mCurrentPath, + isType: $mType + }) + + Divider() + .color('#000000') + .opacity(0.05) + .visibility(this.mFileList.length == index + 1 ? Visibility.Hidden : Visibility.Visible) + .margin({ left: 40 * 1.3 }) + } + .width('100%') + .height(56 * 1.3) + }, item => item.name.toString()) + } + .padding({ top: 4 * 1.3, bottom: 4 * 1.3, left: 12 * 1.3, right: 12 * 1.3 }) + .width('100%') + .alignItems(HorizontalAlign.Start) + .border({ radius: 24 }) + .opacity(0.9) + .backgroundColor(Color.White) } - .padding({ top: 4 * 1.3, bottom: 4 * 1.3, left: 12 * 1.3, right: 12 * 1.3 }) - .width('100%') - .alignItems(HorizontalAlign.Start) - .border({ radius: 24 }) - .opacity(0.9) - .backgroundColor(Color.White) - } } @Component struct SecondRowView { - private item: FileInfo = new FileInfo('') - @Link mMenuLevel: number - @Link mCurrentPath: string - @Link isType: string + private item: FileInfo = new FileInfo('') + @Link mMenuLevel: number + @Link mCurrentPath: string + @Link isType: string - build() { - Row() { - Image($r("app.media.ic_type_smallfile")) - .width(24 * 1.3) - .height(24 * 1.3) - Text(this.item.name) - .fontSize(16 * 1.3) - .fontColor('#182431') - .fontWeight(FontWeight.Medium) - .margin({ left: 17 * 1.3 }) - Blank() - Image($r("app.media.ic_right")) - .width(12 * 1.3) - .height(24 * 1.3) - } - .height(56 * 1.3) - .width('100%') // TODO - .backgroundColor(this.item.list_background) - .onClick(() => { - LogInfo(TAG, 'onClick this.mCurrentPath = ' + this.mCurrentPath) - this.mCurrentPath = this.item.path - updateTopPathInfo(AppStorage.Get('topPathInfo'), this.item.name, this.mCurrentPath) - - if (this.item.path.includes('dataability:///album') == false) { - if (this.isType != 'file') { - LogInfo(TAG, 'MENU_THIRD_LEVEL_HAS_PIC - onClick') - this.mMenuLevel = menuLevel.MENU_THIRD_LEVEL_HAS_PIC - } else { - this.mMenuLevel = menuLevel.MENU_THIRD_LEVEL_HAS_DETAIL - LogInfo(TAG, 'MENU_THIRD_LEVEL_HAS_DETAIL - onClick') + build() { + Row() { + Image($r("app.media.ic_type_smallfile")) + .width(24 * 1.3) + .height(24 * 1.3) + Text(this.item.name) + .fontSize(16 * 1.3) + .fontColor('#182431') + .fontWeight(FontWeight.Medium) + .margin({ left: 17 * 1.3 }) + Blank() + Image($r("app.media.ic_right")) + .width(12 * 1.3) + .height(24 * 1.3) } - } - }) - } + .height(56 * 1.3) + .width('100%') // TODO + .backgroundColor(this.item.list_background) + .onClick(() => { + logInfo(TAG, 'onClick this.mCurrentPath = ' + this.mCurrentPath) + this.mCurrentPath = this.item.path + updateTopPathInfo(AppStorage.Get('topPathInfo'), this.item.name, this.mCurrentPath) + + if (this.item.path.includes('dataability:///album') == false) { + if (this.isType != 'file') { + logInfo(TAG, 'MENU_THIRD_LEVEL_HAS_PIC - onClick') + this.mMenuLevel = MenuLevel.MENU_THIRD_LEVEL_HAS_PIC + } else { + this.mMenuLevel = MenuLevel.MENU_THIRD_LEVEL_HAS_DETAIL + logInfo(TAG, 'MENU_THIRD_LEVEL_HAS_DETAIL - onClick') + } + } + }) + } } \ No newline at end of file diff --git a/product/RK/src/main/ets/pages/ThirdLevelHasDetail.ets b/product/RK/src/main/ets/pages/ThirdLevelHasDetail.ets index 364bbf2..03c7e0e 100644 --- a/product/RK/src/main/ets/pages/ThirdLevelHasDetail.ets +++ b/product/RK/src/main/ets/pages/ThirdLevelHasDetail.ets @@ -13,209 +13,210 @@ * limitations under the License. */ -import { FileInfo } from '../module/FileInfo' -import { LogInfo } from '../module/LogUtils' -import { getShowIconBySuffix, updateTopPathInfo } from '../module/Utils' -import { media_type } from '../module/Constants' -import { ChooseDialog } from '../module/DialogUtils' -import { getListFile } from '../module/FileManagerServiceUtils' +import { MediaType } from '../../../../../../common/src/main/ets/components/Data/Constants' +import { FileInfo } from '../../../../../../common/src/main/ets/components/Data/FileInfo' +import { logInfo } from '../../../../../../common/src/main/ets/components/Utils/LogUtils' +import { getListFile } from '../../../../../../common/src/main/ets/components/Utils/FileManagerServiceUtils' +import { getShowIconBySuffix, updateTopPathInfo } from '../../../../../../common/src/main/ets/components/utils/utils' +import { ChooseDialog } from '../../../../../../common/src/main/ets/components/View/ChooseDialog' let TAG: string = 'ThirdLevelHasDetail' @Component export struct ThirdLevelHasDetail { - private mCurrentMode: string - private mWorker - @Link mFileInfo: Array - @Link @Watch('refreshFiles') mCurrentPath: string - @Link mMenuLevel: number - @Link mType: string + private mCurrentMode: string + private mWorker + @Link mFileInfo: Array + @Link @Watch('refreshFiles') mCurrentPath: string + @Link mMenuLevel: number + @Link mType: string - private aboutToAppear(): void{ - LogInfo(TAG, 'aboutToAppear') - if (globalThis.debugMode) { - this.mFileInfo = getListFile('local', this.mType, this.mCurrentPath) - } else { - this.mWorker.postMessage({ - request_data: 'listFile', - device_name: 'local', - menu_level: this.mMenuLevel, - media_type: this.mType, - path: this.mCurrentPath - }) - } - } - - private aboutToDisappear() { - LogInfo(TAG, 'aboutToDisappear') - AppStorage.Set('choseFiles', []) - } - - refreshFiles() { - LogInfo(TAG, 'refreshFiles') - AppStorage.Set('choseFiles', []) - - this.mWorker.postMessage({ - request_data: 'listFile', - device_name: 'local', - menu_level: this.mMenuLevel, - media_type: this.mType, - path: this.mCurrentPath - }) - } - - build() { - Column() { - Flex({ - direction: FlexDirection.Row, - wrap: FlexWrap.Wrap, - justifyContent: FlexAlign.Start, - alignItems: ItemAlign.Start - }) { - ForEach(this.mFileInfo, (item: FileInfo, index: number) => { - Column() { - DetailRowView({ - item: item, - mMenuLevel: $mMenuLevel, - mCurrentPath: $mCurrentPath + private aboutToAppear(): void{ + logInfo(TAG, 'aboutToAppear') + if (globalThis.debugMode) { + this.mFileInfo = getListFile('local', this.mType, this.mCurrentPath) + } else { + this.mWorker.postMessage({ + request_data: 'listFile', + device_name: 'local', + menu_level: this.mMenuLevel, + MediaType: this.mType, + path: this.mCurrentPath }) - - Divider() - .color('#000000') - .opacity(0.05) - .visibility(this.mFileInfo.length == index + 1 ? Visibility.Hidden : Visibility.Visible) - .margin({ left: 64 * 1.3, right: 12 * 1.3 }) - } - }, (item: FileInfo) => item.name) - } + } + } + + private aboutToDisappear() { + logInfo(TAG, 'aboutToDisappear') + AppStorage.Set('choseFiles', []) + } + + refreshFiles() { + logInfo(TAG, 'refreshFiles') + AppStorage.Set('choseFiles', []) + if (!globalThis.debugMode) { + this.mWorker.postMessage({ + request_data: 'listFile', + device_name: 'local', + menu_level: this.mMenuLevel, + MediaType: this.mType, + path: this.mCurrentPath + }) + } + } + + build() { + Column() { + Flex({ + direction: FlexDirection.Row, + wrap: FlexWrap.Wrap, + justifyContent: FlexAlign.Start, + alignItems: ItemAlign.Start + }) { + ForEach(this.mFileInfo, (item: FileInfo, index: number) => { + Column() { + DetailRowView({ + item: item, + mMenuLevel: $mMenuLevel, + mCurrentPath: $mCurrentPath + }) + + Divider() + .color('#000000') + .opacity(0.05) + .visibility(this.mFileInfo.length == index + 1 ? Visibility.Hidden : Visibility.Visible) + .margin({ left: 64 * 1.3, right: 12 * 1.3 }) + } + }, (item: FileInfo) => item.name) + } + } + .padding({ bottom: 4 * 1.3 }) + .alignItems(HorizontalAlign.Start) + .border({ radius: 24 }) + .opacity(0.9) + .backgroundColor(Color.White) } - .padding({ bottom: 4 * 1.3 }) - .alignItems(HorizontalAlign.Start) - .border({ radius: 24 }) - .opacity(0.9) - .backgroundColor(Color.White) - } } @Component struct DetailRowView { - private dialogController: CustomDialogController = new CustomDialogController({ - builder: ChooseDialog(), - cancel: () => { - }, - autoCancel: true - }) - @State item: FileInfo = new FileInfo('') - @Link mCurrentPath: string - @Link mMenuLevel: number - @StorageLink('choseFiles') tmpChoseFiles: Array = [] - - build() { - Row() { - if (this.item.type == media_type.MEDIA_TYPE_ALBUM) { - Row() { - Image($r("app.media.ic_type_bigfile")) - .width(40 * 1.3) - .height(40 * 1.3) - .margin({ left: 10 * 1.3 }) - Text(this.item.name) - .fontSize(16 * 1.3) - .fontColor('#182431') - .fontWeight(FontWeight.Medium) - .margin({ left: 16 * 1.3 }) - .maxLines(1) - .textOverflow({ overflow: TextOverflow.Ellipsis }) - Blank() - Image($r("app.media.ic_right")) - .width(12 * 1.3) - .height(24 * 1.3) - .margin({ right: 12 * 1.3 }) - } - .margin({ right: 12 * 1.3 }) - .height(64 * 1.3) - .width('100%') - .backgroundColor(this.item.list_background) - } else { - Row() { - Image(getShowIconBySuffix(this.item.name.substring(this.item.name.lastIndexOf('.')))) - .width(40 * 1.3) - .height(40 * 1.3) - .margin({ left: 8 * 1.3 }) - Column() { - Text(this.item.name) - .height(22 * 1.3) - .fontSize(16 * 1.3) - .fontColor(this.item.font_color) - .fontWeight(FontWeight.Medium) - .maxLines(1) - .textOverflow({ overflow: TextOverflow.Ellipsis }) - .margin({ top: 10 * 1.3 }) - .height(22 * 1.3) - .width(248 * 1.3) - Row() { - Text('' + this.item.modified_time) - .fontSize(14 * 1.3) - .fontColor(this.item.font_color) - .fontWeight(FontWeight.Regular) - .maxLines(1) - .textOverflow({ overflow: TextOverflow.Ellipsis }) - Text('-') - .fontSize(14 * 1.3) - .fontColor(this.item.font_color) - .margin({ left: 8 * 1.3 }) - Text('' + this.item.size) - .fontSize(14 * 1.3) - .fontColor(this.item.font_color) - .fontWeight(FontWeight.Regular) - .margin({ left: 8 * 1.3 }) - .maxLines(1) - .textOverflow({ overflow: TextOverflow.Ellipsis }) - } - .width(248 * 1.3) - .height(19 * 1.3) - .margin({ top: 2 * 1.3 }) - .opacity(0.6) - } - .height(64 * 1.3) - .alignItems(HorizontalAlign.Start) - .margin({ left: 16 * 1.3 }) - } - .width('100%') - .height(64 * 1.3) // TODO - - } - } - .margin({ top: 4 * 1.3, left: 4 * 1.3, right: 4 * 1.3 }) - .border({ radius: 20 }) - .backgroundColor(this.item.list_background) - .onClick(() => { - if (this.item.type == media_type.MEDIA_TYPE_ALBUM) { - LogInfo(TAG, 'fold onClick') - this.mCurrentPath = this.item.path - updateTopPathInfo(AppStorage.Get('topPathInfo'), this.item.name, this.item.path) - } else { - var index = this.tmpChoseFiles.indexOf(this.item) - if (index == -1) { - this.item.font_color = Color.Black - this.item.opacity = 0.1 - this.item.list_background = 'rgba(46,136,255,0.1)' - this.tmpChoseFiles.push(this.item) - } else { - this.item.font_color = Color.Black - this.item.opacity = 1 - this.item.list_background = '' - this.tmpChoseFiles.splice(index, 1) - } - } + private dialogController: CustomDialogController = new CustomDialogController({ + builder: ChooseDialog(), + cancel: () => { + }, + autoCancel: true }) - .gesture( - LongPressGesture({ repeat: false }) - .onAction((event: GestureEvent) => { - if (this.item.type != media_type.MEDIA_TYPE_ALBUM) { - AppStorage.SetOrCreate('selectedFileInfo', this.item) - this.dialogController.open() + @State item: FileInfo = new FileInfo('') + @Link mCurrentPath: string + @Link mMenuLevel: number + @StorageLink('choseFiles') tmpChoseFiles: Array = [] + + build() { + Row() { + if (this.item.type == MediaType.MEDIA_TYPE_ALBUM) { + Row() { + Image($r("app.media.ic_type_bigfile")) + .width(40 * 1.3) + .height(40 * 1.3) + .margin({ left: 10 * 1.3 }) + Text(this.item.name) + .fontSize(16 * 1.3) + .fontColor('#182431') + .fontWeight(FontWeight.Medium) + .margin({ left: 16 * 1.3 }) + .maxLines(1) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + Blank() + Image($r("app.media.ic_right")) + .width(12 * 1.3) + .height(24 * 1.3) + .margin({ right: 12 * 1.3 }) + } + .margin({ right: 12 * 1.3 }) + .height(64 * 1.3) + .width('100%') + .backgroundColor(this.item.list_background) + } else { + Row() { + Image(getShowIconBySuffix(this.item.name.substring(this.item.name.lastIndexOf('.')))) + .width(40 * 1.3) + .height(40 * 1.3) + .margin({ left: 8 * 1.3 }) + Column() { + Text(this.item.name) + .height(22 * 1.3) + .fontSize(16 * 1.3) + .fontColor(this.item.font_color) + .fontWeight(FontWeight.Medium) + .maxLines(1) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + .margin({ top: 10 * 1.3 }) + .height(22 * 1.3) + .width(248 * 1.3) + Row() { + Text('' + this.item.modified_time) + .fontSize(14 * 1.3) + .fontColor(this.item.font_color) + .fontWeight(FontWeight.Regular) + .maxLines(1) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + Text('-') + .fontSize(14 * 1.3) + .fontColor(this.item.font_color) + .margin({ left: 8 * 1.3 }) + Text('' + this.item.size) + .fontSize(14 * 1.3) + .fontColor(this.item.font_color) + .fontWeight(FontWeight.Regular) + .margin({ left: 8 * 1.3 }) + .maxLines(1) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + } + .width(248 * 1.3) + .height(19 * 1.3) + .margin({ top: 2 * 1.3 }) + .opacity(0.6) + } + .height(64 * 1.3) + .alignItems(HorizontalAlign.Start) + .margin({ left: 16 * 1.3 }) + } + .width('100%') + .height(64 * 1.3) // TODO + + } } - }) - ) - } + .margin({ top: 4 * 1.3, left: 4 * 1.3, right: 4 * 1.3 }) + .border({ radius: 20 }) + .backgroundColor(this.item.list_background) + .onClick(() => { + if (this.item.type == MediaType.MEDIA_TYPE_ALBUM) { + logInfo(TAG, 'fold onClick') + this.mCurrentPath = this.item.path + updateTopPathInfo(AppStorage.Get('topPathInfo'), this.item.name, this.item.path) + } else { + var index = this.tmpChoseFiles.indexOf(this.item) + if (index == -1) { + this.item.font_color = Color.Black + this.item.opacity = 0.1 + this.item.list_background = 'rgba(46,136,255,0.1)' + this.tmpChoseFiles.push(this.item) + } else { + this.item.font_color = Color.Black + this.item.opacity = 1 + this.item.list_background = '' + this.tmpChoseFiles.splice(index, 1) + } + } + }) + .gesture( + LongPressGesture({ repeat: false }) + .onAction((event: GestureEvent) => { + if (this.item.type != MediaType.MEDIA_TYPE_ALBUM) { + AppStorage.SetOrCreate('selectedFileInfo', this.item) + this.dialogController.open() + } + }) + ) + } } \ No newline at end of file diff --git a/product/RK/src/main/ets/pages/ThirdLevelHasPic.ets b/product/RK/src/main/ets/pages/ThirdLevelHasPic.ets index 44941b7..7b65f0f 100644 --- a/product/RK/src/main/ets/pages/ThirdLevelHasPic.ets +++ b/product/RK/src/main/ets/pages/ThirdLevelHasPic.ets @@ -13,145 +13,146 @@ * limitations under the License. */ -import { FileInfo } from '../module/FileInfo' -import { LogInfo, LogDebug } from '../module/LogUtils' -import { getListFile } from '../module/FileManagerServiceUtils' -import { ChooseDialog } from '../module/DialogUtils' +import { FileInfo } from '../../../../../../common/src/main/ets/components/Data/FileInfo' +import { getListFile } from '../../../../../../common/src/main/ets/components/Utils/FileManagerServiceUtils' +import { logDebug, logInfo } from '../../../../../../common/src/main/ets/components/Utils/LogUtils' +import { ChooseDialog } from '../../../../../../common/src/main/ets/components/View/ChooseDialog' let TAG: string = 'ThirdLevelHasPic' @Component export struct ThirdLevelHasPic { - private mColumnTemplate: string - private mCurrentMode: string - private mCurrentIndex: number - private mWorker - @Link mFileList: Array - @Link mMenuLevel: number - @Link mType: string - @Link mCurrentPath: string - @StorageLink('choseFiles') tmpFiles: Array = [] + private mColumnTemplate: string + private mCurrentMode: string + private mCurrentIndex: number + private mWorker + @Link mFileList: Array + @Link mMenuLevel: number + @Link mType: string + @Link mCurrentPath: string + @StorageLink('choseFiles') tmpFiles: Array = [] - aboutToAppear() { - if (globalThis.debugMode) { - this.mFileList = getListFile('local', this.mType, this.mCurrentPath) - LogDebug(TAG, 'mFileList length = ' + this.mFileList.length) - } else { - this.mWorker.postMessage({ - request_data: 'listFile', - device_name: 'local', - menu_level: this.mMenuLevel, - media_type: this.mType, - path: this.mCurrentPath, - offset: 0, - count: 100 - }) - } - } - - private aboutToDisappear() { - LogInfo(TAG, 'aboutToDisappear') - AppStorage.Set('choseFiles', []) - } - - build() { - if (globalThis.startMode == 'choose') { - Column() { - Flex({ - direction: FlexDirection.Row, - wrap: FlexWrap.Wrap, - justifyContent: FlexAlign.Start, - alignItems: ItemAlign.Start - }) { - ForEach(this.mFileList, (item: FileInfo) => { - GridItemView({ gridItem: item }) - }, item => item.name) + aboutToAppear() { + logInfo(TAG, 'aboutToAppear send message to worker') + if (globalThis.debugMode) { + this.mFileList = getListFile('local', this.mType, this.mCurrentPath) + logDebug(TAG, 'mFileList length = ' + this.mFileList.length) + } else { + this.mWorker.postMessage({ + request_data: 'listFile', + device_name: 'local', + menu_level: this.mMenuLevel, + MediaType: this.mType, + path: this.mCurrentPath, + offset: 0, + count: 100 + }) } - .margin({ top: 8 * 1.3 }) - } - .alignItems(HorizontalAlign.Start) - .border({ radius: 24 }) - .opacity(0.9) - .backgroundColor(Color.White) } - } + private aboutToDisappear() { + logInfo(TAG, 'aboutToDisappear') + AppStorage.Set('choseFiles', []) + } + + build() { + if (globalThis.startMode == 'choose') { + Column() { + Flex({ + direction: FlexDirection.Row, + wrap: FlexWrap.Wrap, + justifyContent: FlexAlign.Start, + alignItems: ItemAlign.Start + }) { + ForEach(this.mFileList, (item: FileInfo) => { + GridItemView({ gridItem: item }) + }, item => item.name) + } + .margin({ top: 8 * 1.3 }) + } + .alignItems(HorizontalAlign.Start) + .border({ radius: 24 }) + .opacity(0.9) + .backgroundColor(Color.White) + } + + } } @Component struct GridItemView { - private dialogController: CustomDialogController = new CustomDialogController({ - builder: ChooseDialog(), - cancel: () => { - }, - autoCancel: true - }) - @State gridItem: FileInfo = new FileInfo('') - - build() { - Flex({ - direction: FlexDirection.Column, - alignItems: ItemAlign.Center, - justifyContent: FlexAlign.Center - }) { - Image(`${this.gridItem.path}/thumbnail/160/160`) - .borderRadius(12) - .objectFit(ImageFit.Contain) - .width(80 * 1.3) - .height(80 * 1.3) - .margin({ - left: 8 * 1.3, - right: 8 * 1.3, - top: 4 * 1.3 - }) - Row() { - Text(this.gridItem.name) - .width(82 * 1.3) - .fontSize(12 * 1.3) - .fontColor(this.gridItem.list_background == 'rgba(46,136,255,0.1)' ? Color.White : Color.Black) - .fontWeight(FontWeight.Regular) - .opacity(0.9) - .textAlign(TextAlign.Center) - .maxLines(2) - .textOverflow({ overflow: TextOverflow.Ellipsis }) - .margin({ top: 2 * 1.3 }) - .padding({ right: 4 * 1.3, left: 4 * 1.3 }) - } - .borderRadius(12) - .backgroundColor(this.gridItem.list_background == 'rgba(46,136,255,0.1)' ? 0x2E8BFF : '') - .alignItems(VerticalAlign.Top) - .width(82 * 1.3) - .height(36 * 1.3) - .margin({ top: 4 * 1.3 }) - } - .padding({ bottom: 8 * 1.3 }) - .width(96 * 1.3) - .height(126 * 1.3) - .margin({ bottom: 12 * 1.3, left: 12 * 1.3 }) - .border({ radius: 20 }) - .backgroundColor(this.gridItem.list_background) - .gesture( - LongPressGesture({ repeat: false }) - .onAction((event: GestureEvent) => { - AppStorage.SetOrCreate('selectedFileInfo', this.gridItem) - this.dialogController.open() - }) - ) - .onClick(() => { - let choseFiles: Array = AppStorage.Get('choseFiles') - let index: number = choseFiles.indexOf(this.gridItem) - if (index == -1) { - this.gridItem.opacity = 0.1 - this.gridItem.font_color = '#FFFFFF' - this.gridItem.list_background = 'rgba(46,136,255,0.1)' - choseFiles.push(this.gridItem) - } else { - choseFiles.splice(index) - this.gridItem.opacity = 1 - this.gridItem.font_color = '#000000' - this.gridItem.list_background = '' - } + private dialogController: CustomDialogController = new CustomDialogController({ + builder: ChooseDialog(), + cancel: () => { + }, + autoCancel: true }) + @State gridItem: FileInfo = new FileInfo('') - } + build() { + Flex({ + direction: FlexDirection.Column, + alignItems: ItemAlign.Center, + justifyContent: FlexAlign.Center + }) { + Image(`${this.gridItem.path}/thumbnail/160/160`) + .borderRadius(12) + .objectFit(ImageFit.Contain) + .width(80 * 1.3) + .height(80 * 1.3) + .margin({ + left: 8 * 1.3, + right: 8 * 1.3, + top: 4 * 1.3 + }) + Row() { + Text(this.gridItem.name) + .width(82 * 1.3) + .fontSize(12 * 1.3) + .fontColor(this.gridItem.list_background == 'rgba(46,136,255,0.1)' ? Color.White : Color.Black) + .fontWeight(FontWeight.Regular) + .opacity(0.9) + .textAlign(TextAlign.Center) + .maxLines(2) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + .margin({ top: 2 * 1.3 }) + .padding({ right: 4 * 1.3, left: 4 * 1.3 }) + } + .borderRadius(12) + .backgroundColor(this.gridItem.list_background == 'rgba(46,136,255,0.1)' ? 0x2E8BFF : '') + .alignItems(VerticalAlign.Top) + .width(82 * 1.3) + .height(36 * 1.3) + .margin({ top: 4 * 1.3 }) + } + .padding({ bottom: 8 * 1.3 }) + .width(96 * 1.3) + .height(126 * 1.3) + .margin({ bottom: 12 * 1.3, left: 12 * 1.3 }) + .border({ radius: 20 }) + .backgroundColor(this.gridItem.list_background) + .gesture( + LongPressGesture({ repeat: false }) + .onAction((event: GestureEvent) => { + AppStorage.SetOrCreate('selectedFileInfo', this.gridItem) + this.dialogController.open() + }) + ) + .onClick(() => { + let choseFiles: Array = AppStorage.Get('choseFiles') + let index: number = choseFiles.indexOf(this.gridItem) + if (index == -1) { + this.gridItem.opacity = 0.1 + this.gridItem.font_color = '#FFFFFF' + this.gridItem.list_background = 'rgba(46,136,255,0.1)' + choseFiles.push(this.gridItem) + } else { + choseFiles.splice(index) + this.gridItem.opacity = 1 + this.gridItem.font_color = '#000000' + this.gridItem.list_background = '' + } + }) + + } } \ No newline at end of file diff --git a/product/RK/src/main/ets/pages/index.ets b/product/RK/src/main/ets/pages/index.ets index 7b584bc..2b7dec8 100644 --- a/product/RK/src/main/ets/pages/index.ets +++ b/product/RK/src/main/ets/pages/index.ets @@ -18,429 +18,432 @@ import { FirstLevelByType } from './FirstLevelByType' import { SecondLevelByFold } from './SecondLevelByFold' import { ThirdLevelHasDetail } from '../pages/ThirdLevelHasDetail' import { ThirdLevelHasPic } from '../pages/ThirdLevelHasPic' -import { FileInfo, TopPathInfo } from '../module/FileInfo' -import { menuLevel, terminate_reason, media_type } from '../module/Constants' -import { LogInfo, LogDebug } from '../module/LogUtils' -import { changeStringToType, updateTopPathInfo } from '../module/Utils' -import { terminateSelfWithResult } from '../module/AbilityUtils' -import { WarningDialog } from '../module/DialogUtils' -import { getFirstMenu } from '../module/FileManagerServiceUtils' +import { MenuLevel, TerminateReason, MediaType } from '../../../../../../common/src/main/ets/components/Data/Constants' +import { FileInfo } from '../../../../../../common/src/main/ets/components/Data/FileInfo' +import { TopPathInfo } from '../../../../../../common/src/main/ets/components/Data/TopPathInfo' +import { terminateSelfWithResult } from '../../../../../../common/src/main/ets/components/utils/AbilityUtils' +import { getFirstMenu } from '../../../../../../common/src/main/ets/components/Utils/FileManagerServiceUtils' +import { logInfo, logDebug, logError } from '../../../../../../common/src/main/ets/components/Utils/LogUtils' +import { changeStringToType, updateTopPathInfo } from '../../../../../../common/src/main/ets/components/utils/Utils' +import { WarningDialog } from '../../../../../../common/src/main/ets/components/View/WarningDialog' @Entry @Component struct allIndex { - build() { - Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.End, justifyContent: FlexAlign.SpaceBetween }) { - Stack({ alignContent: Alignment.Bottom }) { - Column() { + private TAG: string= 'Main' + + build() { + Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.End, justifyContent: FlexAlign.SpaceBetween }) { + Stack({ alignContent: Alignment.Bottom }) { + Column() { + } + .onClick(() => { + globalThis.context.terminateSelf((err, data) => { + logInfo(this.TAG, 'terminateSelf success') + }) + }) + .width('100%') + .height('100%') + + Index() + } + .width('100%') + .height('100%') } - .onClick(() => { - globalThis.context.terminateSelf((err, data) => { - console.log('terminateSelf success') - }) - }) + .backgroundColor('rgba(0,0,0,0.1)') + .position({ x: 0, y: 0 }) .width('100%') .height('100%') - - Index() - } - .width('100%') - .height('100%') } - .backgroundColor('rgba(0,0,0,0.1)') - .position({ x: 0, y: 0 }) - .width('100%') - .height('100%') - } } @Component struct Index { - private TAG: string= 'Main' - private mWorker - private customDialogController: CustomDialogController = new CustomDialogController({ - builder: WarningDialog({ code: $code }) - }) - @State mFirstMenuData: FileInfo[] = [] - @State mSecondMenuData: FileInfo[] = [] - @State mThirdMenuPicData: FileInfo[]= [] - @State mThirdMenuDetailData: FileInfo[]= [] - @State mType: string = '' - @State mMenuLevel: number = menuLevel.MENU_FIRST_LEVEL_BY_TYPE - @State mCurrentPath: string= '' - @State code: number = 2; - @StorageLink('startMode') mCurrentMode: string = 'choose' - @StorageLink('topPathInfo') topPathInfo: Array = updateTopPathInfo([], '文件类型', '') - scroller: Scroller = new Scroller() + private TAG: string= 'Main' + private mWorker + private customDialogController: CustomDialogController = new CustomDialogController({ + builder: WarningDialog({ code: $code }) + }) + @State mFirstMenuData: FileInfo[] = [] + @State mSecondMenuData: FileInfo[] = [] + @State mThirdMenuPicData: FileInfo[]= [] + @State mThirdMenuDetailData: FileInfo[]= [] + @State mType: string = '' + @State mMenuLevel: number = MenuLevel.MENU_FIRST_LEVEL_BY_TYPE + @State mCurrentPath: string= '' + @State code: number = 2; + @StorageLink('startMode') mCurrentMode: string = 'choose' + @StorageLink('topPathInfo') topPathInfo: Array = updateTopPathInfo([], '文件类型', '') + scroller: Scroller = new Scroller() - aboutToAppear() { - LogInfo(this.TAG, 'aboutToAppear') - if (globalThis.debugMode) { - this.mFirstMenuData = getFirstMenu('') - LogDebug(this.TAG, 'mFirstMenuData length = ' + this.mFirstMenuData.length) - } else { - this.initWork() - LogInfo(this.TAG, 'send message to worker') - this.mWorker.postMessage({ - request_data: 'getRoot', - device_name: 'local', - menu_level: this.mMenuLevel, - media_type: this.mType, - path: this.mCurrentPath - }) - } - } - - private initWork() { - if (this.mWorker == undefined) { - LogInfo(this.TAG, 'initWorker') - this.mWorker = new worker.Worker('RK/ets/workers/DataWorker.js', { type: 'classic', name: 'filePicker' }) - this.mWorker.onerror = this.onError.bind(this) - this.mWorker.onmessageerror = this.onMessageError.bind(this) - this.mWorker.onexit = this.onExit.bind(this) - this.mWorker.onmessage = this.onMessage.bind(this) - } - } - - private onError(e): void{ - LogInfo(this.TAG, 'onError = ' + JSON.stringify(e)) - } - - private onMessageError(e): void{ - LogInfo(this.TAG, 'onMessageError = ' + JSON.stringify(e)) - } - - private onExit(): void{ - LogInfo(this.TAG, 'onExit') - this.mWorker = undefined - } - - private onMessage(result) { - LogInfo(this.TAG, 'main thread onMessage') - var params = result.data.params - var file = JSON.parse(String.fromCharCode.apply(null, new Uint16Array(result.data.data))) - if (params.request_data == 'createFile') { - if (file.code == undefined) { - terminateSelfWithResult(terminate_reason.SUCCESS, file) - } else { - if (params.path == 'dataability:///album') { - this.code = 2; - this.customDialogController.open() + aboutToAppear() { + if (globalThis.debugMode) { + this.mFirstMenuData = getFirstMenu('') + logDebug(this.TAG, 'mFirstMenuData length = ' + this.mFirstMenuData.length) } else { - this.code = file.code - this.customDialogController.open() + logInfo(this.TAG, 'aboutToAppear') + this.initWork() + logInfo(this.TAG, 'send message to worker') + this.mWorker.postMessage({ + request_data: 'getRoot', + device_name: 'local', + menu_level: this.mMenuLevel, + MediaType: this.mType, + path: this.mCurrentPath + }) } - } - return } - if (Array.isArray(file)) { - let listData: Array = [] - for (var index = 0;index < file.length; index++) { - var info = file[index] - let item = new FileInfo(info.name) - item.path = info.path - item.type = info.type - item.size = info.size - item.dataAdded_time = info.added_time - item.modified_time = info.modified_time - if (params.menu_level == menuLevel.MENU_FIRST_LEVEL_BY_TYPE) { - if (item.name == 'image_album') { - item.name = '图片' - item.mediaType = 'image' - item.thumbnail = $r("app.media.ic_type_image") - } else if (item.name == 'video_album') { - item.name = '视频' - item.mediaType = 'video' - item.thumbnail = $r("app.media.ic_type_video") - } else if (item.name == 'audio_album') { - item.name = '音乐' - item.mediaType = 'audio' - item.thumbnail = $r("app.media.ic_type_audio") - } else if (item.name == 'file_folder') { - item.name = '文档' - item.mediaType = 'file' - item.thumbnail = $r("app.media.ic_type_file") - } - } - if (params.menu_level == menuLevel.MENU_THIRD_LEVEL_HAS_DETAIL) { - if (this.mCurrentMode == 'save' && item.type != media_type.MEDIA_TYPE_ALBUM) { - break - } + private initWork() { + if (this.mWorker == undefined) { + logInfo(this.TAG, 'initWorker') + this.mWorker = new worker.Worker('RK/ets/workers/DataWorker.js', { type: 'classic', name: 'filePicker' }) + this.mWorker.onerror = this.onError.bind(this) + this.mWorker.onmessageerror = this.onMessageError.bind(this) + this.mWorker.onexit = this.onExit.bind(this) + this.mWorker.onmessage = this.onMessage.bind(this) } - listData.push(item) - } - if (params.menu_level == menuLevel.MENU_FIRST_LEVEL_BY_TYPE && params.request_data == 'getRoot') { - LogDebug(this.TAG, 'mFirstMenuData length = ' + listData.length) - this.mFirstMenuData = listData - } else if (params.menu_level == menuLevel.MENU_SECOND_LEVEL_BY_FOLD) { - LogDebug(this.TAG, 'mSecondMenuData length = ' + listData.length) - this.mSecondMenuData = listData - } else if (params.menu_level == menuLevel.MENU_THIRD_LEVEL_HAS_PIC) { - LogDebug(this.TAG, 'mThirdMenuPicData length = ' + listData.length) - this.mThirdMenuPicData = listData - } else if (params.menu_level == menuLevel.MENU_THIRD_LEVEL_HAS_DETAIL) { - LogDebug(this.TAG, 'mThirdMenuDetailData length = ' + listData.length) - if (listData.length > 0) { - this.mThirdMenuDetailData = listData - } else { - this.mThirdMenuDetailData = [] - } - } } - } - build() { - Column() { - TopBarArea() + private onError(e): void{ + logError(this.TAG, 'onError = ' + JSON.stringify(e)) + } - Column() { - Column() { - Row() { - List() { - ForEach(this.topPathInfo, (item: TopPathInfo) => { - ListItem() { - Row() { - if (item.name != '文件类型') { - Image($r("app.media.ic_public_right")) - .width(12 * 1.3) - .height(24 * 1.3) - .margin({ - left: 4 * 1.3, - right: 4 * 1.3 - }) - } + private onMessageError(e): void{ + logError(this.TAG, 'onMessageError = ' + JSON.stringify(e)) + } - Text(item.name) - .height(24 * 1.3) - .fontColor('#000000') - .fontSize(16 * 1.3) - .fontWeight(FontWeight.Medium) - .opacity(item.opacity) - .onClick(() => { - LogInfo(this.TAG, item.name + ' onClick') - if (item.name == '文件类型') { - updateTopPathInfo([], '文件类型', '') - this.mMenuLevel = menuLevel.MENU_FIRST_LEVEL_BY_TYPE - this.mType = '' - } else if (this.mMenuLevel == menuLevel.MENU_THIRD_LEVEL_HAS_DETAIL) { - this.mCurrentPath = item.path - LogInfo(this.TAG, 'item.path' + item.path) - let topPathInfo: Array = AppStorage.Get('topPathInfo') - let index: number = topPathInfo.indexOf(item) - if (index != -1) { - var deleteNum = topPathInfo.length - index + 1 - topPathInfo.splice(index + 1, deleteNum) - topPathInfo[topPathInfo.length - 1].opacity = 1 - AppStorage.Set('topPathInfo', topPathInfo) - } - } else if (this.mMenuLevel == menuLevel.MENU_THIRD_LEVEL_HAS_PIC) { - this.mMenuLevel = menuLevel.MENU_SECOND_LEVEL_BY_FOLD - this.mType = changeStringToType(item.name) - LogInfo(this.TAG, 'item.path 2 ' + item.path) - this.mCurrentPath = item.path - } - }) - } + private onExit(): void{ + logInfo(this.TAG, 'onExit') + this.mWorker = undefined + } + + private onMessage(result) { + logInfo(this.TAG, 'main thread onMessage') + var params = result.data.params + var file = JSON.parse(String.fromCharCode.apply(null, new Uint16Array(result.data.data))) + if (params.request_data == 'createFile') { + if (file.code == undefined) { + terminateSelfWithResult(TerminateReason.SUCCESS, file) + } else { + if (params.path == 'dataability:///album') { + this.code = 2; + this.customDialogController.open() + } else { + this.code = file.code + this.customDialogController.open() } - }, item => item.name.toString()) } - .padding({ right: 24 * 1.3 }) - .listDirection(Axis.Horizontal) - } - .alignItems(VerticalAlign.Center) - .width('100%') - .height(48 * 1.3) - .margin({ left: 12 * 1.3, top: 4 * 1.3 }) - .padding({ top: 13 * 1.3, bottom: 13 * 1.3 }) + return + } + if (Array.isArray(file)) { + let listData: Array = [] + for (var index = 0;index < file.length; index++) { + var info = file[index] + let item = new FileInfo(info.name) + item.path = info.path + item.type = info.type + item.size = info.size + item.dataAdded_time = info.added_time + item.modified_time = info.modified_time + if (params.menu_level == MenuLevel.MENU_FIRST_LEVEL_BY_TYPE) { + if (item.name == 'image_album') { + item.name = '图片' + item.mediaType = 'image' + item.thumbnail = $r("app.media.ic_type_image") + } else if (item.name == 'video_album') { + item.name = '视频' + item.mediaType = 'video' + item.thumbnail = $r("app.media.ic_type_video") + } else if (item.name == 'audio_album') { + item.name = '音乐' + item.mediaType = 'audio' + item.thumbnail = $r("app.media.ic_type_audio") + } else if (item.name == 'file_folder') { + item.name = '文档' + item.mediaType = 'file' + item.thumbnail = $r("app.media.ic_type_file") + } + } + + if (params.menu_level == MenuLevel.MENU_THIRD_LEVEL_HAS_DETAIL) { + if (this.mCurrentMode == 'save' && item.type != MediaType.MEDIA_TYPE_ALBUM) { + break + } + } + listData.push(item) + } + if (params.menu_level == MenuLevel.MENU_FIRST_LEVEL_BY_TYPE && params.request_data == 'getRoot') { + logDebug(this.TAG, 'mFirstMenuData length = ' + listData.length) + this.mFirstMenuData = listData + } else if (params.menu_level == MenuLevel.MENU_SECOND_LEVEL_BY_FOLD) { + logDebug(this.TAG, 'mSecondMenuData length = ' + listData.length) + this.mSecondMenuData = listData + } else if (params.menu_level == MenuLevel.MENU_THIRD_LEVEL_HAS_PIC) { + logDebug(this.TAG, 'mThirdMenuPicData length = ' + listData.length) + this.mThirdMenuPicData = listData + } else if (params.menu_level == MenuLevel.MENU_THIRD_LEVEL_HAS_DETAIL) { + logDebug(this.TAG, 'mThirdMenuDetailData length = ' + listData.length) + if (listData.length > 0) { + this.mThirdMenuDetailData = listData + } else { + this.mThirdMenuDetailData = [] + } + } + } + } + + build() { + Column() { + TopBarArea() - Scroll(this.scroller) { Column() { - if (this.mMenuLevel == menuLevel.MENU_FIRST_LEVEL_BY_TYPE) { - FirstLevelByType({ - mFileList: this.mFirstMenuData, - mType: $mType, - mMenuLevel: $mMenuLevel, - mCurrentPath: $mCurrentPath, - mWorker: this.mWorker, - }) - } else if (this.mMenuLevel == menuLevel.MENU_SECOND_LEVEL_BY_FOLD) { - SecondLevelByFold({ - mType: $mType, - mMenuLevel: $mMenuLevel, - mCurrentPath: $mCurrentPath, - mWorker: this.mWorker, - mFileList: $mSecondMenuData - }) - } else if (this.mMenuLevel == menuLevel.MENU_THIRD_LEVEL_HAS_PIC) { - ThirdLevelHasPic({ - mType: $mType, - mMenuLevel: $mMenuLevel, - mCurrentPath: $mCurrentPath, - mWorker: this.mWorker, - mFileList: $mThirdMenuPicData - }) - } else if (this.mMenuLevel == menuLevel.MENU_THIRD_LEVEL_HAS_DETAIL) { - ThirdLevelHasDetail({ - mType: $mType, - mMenuLevel: $mMenuLevel, - mCurrentPath: $mCurrentPath, - mWorker: this.mWorker, - mFileInfo: $mThirdMenuDetailData - }) - } - Row() { - }.width('100%').height(53 * 1.3) + Column() { + Row() { + List() { + ForEach(this.topPathInfo, (item: TopPathInfo) => { + ListItem() { + Row() { + if (item.name != '文件类型') { + Image($r("app.media.ic_public_right")) + .width(12 * 1.3) + .height(24 * 1.3) + .margin({ + left: 4 * 1.3, + right: 4 * 1.3 + }) + } + + Text(item.name) + .height(24 * 1.3) + .fontColor('#000000') + .fontSize(16 * 1.3) + .fontWeight(FontWeight.Medium) + .opacity(item.opacity) + .onClick(() => { + logInfo(this.TAG, item.name + ' onClick') + if (item.name == '文件类型') { + updateTopPathInfo([], '文件类型', '') + this.mMenuLevel = MenuLevel.MENU_FIRST_LEVEL_BY_TYPE + this.mType = '' + } else if (this.mMenuLevel == MenuLevel.MENU_THIRD_LEVEL_HAS_DETAIL) { + this.mCurrentPath = item.path + logInfo(this.TAG, 'item.path' + item.path) + let topPathInfo: Array = AppStorage.Get('topPathInfo') + let index: number = topPathInfo.indexOf(item) + if (index != -1) { + var deleteNum = topPathInfo.length - index + 1 + topPathInfo.splice(index + 1, deleteNum) + topPathInfo[topPathInfo.length - 1].opacity = 1 + AppStorage.Set('topPathInfo', topPathInfo) + } + } else if (this.mMenuLevel == MenuLevel.MENU_THIRD_LEVEL_HAS_PIC) { + this.mMenuLevel = MenuLevel.MENU_SECOND_LEVEL_BY_FOLD + this.mType = changeStringToType(item.name) + logInfo(this.TAG, 'item.path 2 ' + item.path) + this.mCurrentPath = item.path + } + }) + } + } + }, item => item.name.toString()) + } + .padding({ right: 24 * 1.3 }) + .listDirection(Axis.Horizontal) + } + .alignItems(VerticalAlign.Center) + .width('100%') + .height(48 * 1.3) + .margin({ left: 12 * 1.3, top: 4 * 1.3 }) + .padding({ top: 13 * 1.3, bottom: 13 * 1.3 }) + + Scroll(this.scroller) { + Column() { + if (this.mMenuLevel == MenuLevel.MENU_FIRST_LEVEL_BY_TYPE) { + FirstLevelByType({ + mFileList: this.mFirstMenuData, + mType: $mType, + mMenuLevel: $mMenuLevel, + mCurrentPath: $mCurrentPath, + mWorker: this.mWorker, + }) + } else if (this.mMenuLevel == MenuLevel.MENU_SECOND_LEVEL_BY_FOLD) { + SecondLevelByFold({ + mType: $mType, + mMenuLevel: $mMenuLevel, + mCurrentPath: $mCurrentPath, + mWorker: this.mWorker, + mFileList: $mSecondMenuData + }) + } else if (this.mMenuLevel == MenuLevel.MENU_THIRD_LEVEL_HAS_PIC) { + ThirdLevelHasPic({ + mType: $mType, + mMenuLevel: $mMenuLevel, + mCurrentPath: $mCurrentPath, + mWorker: this.mWorker, + mFileList: $mThirdMenuPicData + }) + } else if (this.mMenuLevel == MenuLevel.MENU_THIRD_LEVEL_HAS_DETAIL) { + ThirdLevelHasDetail({ + mType: $mType, + mMenuLevel: $mMenuLevel, + mCurrentPath: $mCurrentPath, + mWorker: this.mWorker, + mFileInfo: $mThirdMenuDetailData + }) + } + Row() { + }.width('100%').height(53 * 1.3) + } + .alignItems(HorizontalAlign.Start) + } + .scrollBar(BarState.Off) + .scrollable(ScrollDirection.Vertical) + } + .alignItems(HorizontalAlign.Start) } .alignItems(HorizontalAlign.Start) - } - .scrollBar(BarState.Off) - .scrollable(ScrollDirection.Vertical) - } - .alignItems(HorizontalAlign.Start) - } - .alignItems(HorizontalAlign.Start) - .height(globalThis.mainDialogHeight - 182) + .height(globalThis.mainDialogHeight - 140 * 1.3) - BottomBar({ - mCurrentPath: $mCurrentPath, - mMenuLevel: $mMenuLevel, - mType: $mType, - mWorker: this.mWorker - }) + BottomBar({ + mCurrentPath: $mCurrentPath, + mMenuLevel: $mMenuLevel, + mType: $mType, + mWorker: this.mWorker + }) + } + .padding({ left: 12 * 1.3, right: 12 * 1.3 }) + .width('100%') + .height(globalThis.mainDialogHeight) + .border({ radius: 24 }) + .backgroundColor('#F1F3F5') } - .padding({ left: 12 * 1.3, right: 12 * 1.3 }) - .width('100%') - .height(globalThis.mainDialogHeight) - .border({ radius: 24 }) - .backgroundColor('#F1F3F5') - } } @Component struct TopBarArea { - build() { - Row() { - Text('文件类型') - .width(98 * 1.3) - .height(33 * 1.3) - .fontSize(24 * 1.3) - .fontColor('#182431') - .fontWeight(FontWeight.Medium) - .margin({ left: 12 * 1.3 }) + build() { + Row() { + Text('文件类型') + .width(98 * 1.3) + .height(33 * 1.3) + .fontSize(24 * 1.3) + .fontColor('#182431') + .fontWeight(FontWeight.Medium) + .margin({ left: 12 * 1.3 }) + } + .height(64 * 1.3) + .width('100%') + .border({ radius: 24 }) + .padding({ top: 8 * 1.3 }) } - .height(64 * 1.3) - .width('100%') - .border({ radius: 24 }) - .padding({ top: 8 * 1.3 }) - } } @Component struct BottomBar { - private TAG: string = 'BottomBar' - private mWorker - @State currentChoseFiles: Array = [] - @Link mType: string - @Link mMenuLevel: number - @Link mCurrentPath: string - @StorageLink('choseFiles') @Watch('choseFileChange') choseFiles: Array = [] + private TAG: string = 'BottomBar' + private mWorker + @State currentChoseFiles: Array = [] + @Link mType: string + @Link mMenuLevel: number + @Link mCurrentPath: string + @StorageLink('choseFiles') @Watch('choseFileChange') choseFiles: Array = [] - aboutToAppear() { - LogInfo(this.TAG, 'current choose file number = ' + this.currentChoseFiles.length) - } - - private choseFileChange() { - this.currentChoseFiles = [] - let files: Array = AppStorage.Get('choseFiles') - files.forEach((item: FileInfo) => { - this.currentChoseFiles.push(item.name) - }) - LogInfo(this.TAG, 'current choose file number = ' + this.currentChoseFiles.length) - } - - build() { - Row() { - Button() { - Text('取消') - .width(110 * 1.3) - .height(22 * 1.3) - .fontSize(16 * 1.3) - .fontWeight(FontWeight.Medium) - .fontColor('#007DFF') - .textAlign(TextAlign.Center) - } - .width(150 * 1.3) - .height(40 * 1.3) - .margin({ left: 12 * 1.3, top: 12 * 1.3, bottom: 24 * 1.3 }) - .backgroundColor('#E5E8EA') - .onClick((event: ClickEvent) => { - terminateSelfWithResult(terminate_reason.NO_ACTION, '') - AppStorage.Set('choseFiles', []) - }) - - if (globalThis.startMode == 'save') { - Button() { - Text($r("app.string.btn_upload")) - .width(110 * 1.3) - .height(22 * 1.3) - .fontSize(16 * 1.3) - .fontWeight(FontWeight.Medium) - .fontColor('#007DFF') - .textAlign(TextAlign.Center) - .opacity(this.choseFiles.length != 0 ? 1 : 0.4) - } - .backgroundColor(this.choseFiles.length != 0 ? '#E5E8EA' : '#ECEEF0') - .margin({ - left: 12 * 1.3, - top: 12 * 1.3, - bottom: 24 * 1.3 - }) - .height(40 * 1.3) - .width(150 * 1.3) - .stateEffect(this.mMenuLevel == menuLevel.MENU_FIRST_LEVEL_BY_TYPE ? false : true) - .onClick((event: ClickEvent) => { - this.mWorker.postMessage({ - request_data: 'createFile', - device_name: 'local', - menu_level: this.mMenuLevel, - media_type: this.mType, - path: this.mCurrentPath, - save_name: globalThis.saveFile, - }) - }) - } else { - Button() { - Text($r("app.string.btn_upload")) - .width(110 * 1.3) - .height(22 * 1.3) - .fontSize(16 * 1.3) - .fontWeight(FontWeight.Medium) - .fontColor('#007DFF') - .textAlign(TextAlign.Center) - .opacity(this.choseFiles.length != 0 ? 1 : 0.4) - } - .backgroundColor(this.choseFiles.length != 0 ? '#E5E8EA' : '#ECEEF0') - .stateEffect(this.choseFiles.length != 0) - .margin({ - left: 12 * 1.3, - top: 12 * 1.3, - bottom: 24 * 1.3 - }) - .height(40 * 1.3) - .width(150 * 1.3) - .onClick(() => { - let result: string = '' - this.choseFiles.forEach((item: FileInfo) => { - result += item.path + ';' - }) - terminateSelfWithResult(terminate_reason.SUCCESS, result) - AppStorage.Set('choseFiles', []) - }) - } + aboutToAppear() { + logInfo(this.TAG, 'current choose file number = ' + this.currentChoseFiles.length) + } + + private choseFileChange() { + this.currentChoseFiles = [] + let files: Array = AppStorage.Get('choseFiles') + files.forEach((item: FileInfo) => { + this.currentChoseFiles.push(item.name) + }) + logInfo(this.TAG, 'current choose file number = ' + this.currentChoseFiles.length) + } + + build() { + Row() { + Button() { + Text('取消') + .width(110 * 1.3) + .height(22 * 1.3) + .fontSize(16 * 1.3) + .fontWeight(FontWeight.Medium) + .fontColor('#007DFF') + .textAlign(TextAlign.Center) + } + .width(150 * 1.3) + .height(40 * 1.3) + .margin({ left: 12 * 1.3, top: 12 * 1.3, bottom: 24 * 1.3 }) + .backgroundColor('#E5E8EA') + .onClick((event: ClickEvent) => { + terminateSelfWithResult(TerminateReason.NO_ACTION, '') + AppStorage.Set('choseFiles', []) + }) + + if (globalThis.startMode == 'save') { + Button() { + Text($r("app.string.btn_upload")) + .width(110 * 1.3) + .height(22 * 1.3) + .fontSize(16 * 1.3) + .fontWeight(FontWeight.Medium) + .fontColor('#007DFF') + .textAlign(TextAlign.Center) + .opacity(this.choseFiles.length != 0 ? 1 : 0.4) + } + .backgroundColor(this.choseFiles.length != 0 ? '#E5E8EA' : '#ECEEF0') + .margin({ + left: 12 * 1.3, + top: 12 * 1.3, + bottom: 24 * 1.3 + }) + .height(40 * 1.3) + .width(150 * 1.3) + .stateEffect(this.mMenuLevel == MenuLevel.MENU_FIRST_LEVEL_BY_TYPE ? false : true) + .onClick((event: ClickEvent) => { + this.mWorker.postMessage({ + request_data: 'createFile', + device_name: 'local', + menu_level: this.mMenuLevel, + MediaType: this.mType, + path: this.mCurrentPath, + save_name: globalThis.saveFile, + }) + }) + } else { + Button() { + Text($r("app.string.btn_upload")) + .width(110 * 1.3) + .height(22 * 1.3) + .fontSize(16 * 1.3) + .fontWeight(FontWeight.Medium) + .fontColor('#007DFF') + .textAlign(TextAlign.Center) + .opacity(this.choseFiles.length != 0 ? 1 : 0.4) + } + .backgroundColor(this.choseFiles.length != 0 ? '#E5E8EA' : '#ECEEF0') + .stateEffect(this.choseFiles.length != 0) + .margin({ + left: 12 * 1.3, + top: 12 * 1.3, + bottom: 24 * 1.3 + }) + .height(40 * 1.3) + .width(150 * 1.3) + .onClick(() => { + let result: string = '' + this.choseFiles.forEach((item: FileInfo) => { + result += item.path + ';' + }) + terminateSelfWithResult(TerminateReason.SUCCESS, result) + AppStorage.Set('choseFiles', []) + }) + } + } + .height(76 * 1.3) + .width('100%') + .backgroundColor('#F1F3F5') } - .height(76 * 1.3) - .width('100%') - .backgroundColor('#F1F3F5') - } } \ No newline at end of file diff --git a/product/RK/src/main/ets/workers/DataWorker.js b/product/RK/src/main/ets/workers/DataWorker.js index 62bf691..1bcec9a 100644 --- a/product/RK/src/main/ets/workers/DataWorker.js +++ b/product/RK/src/main/ets/workers/DataWorker.js @@ -13,14 +13,14 @@ * limitations under the License. */ -import { LogInfo, LogDebug } from '../module/LogUtils.ets' -import worker from '@ohos.worker' import filemanager from '@ohos.filemanager' +import worker from '@ohos.worker' +import { logInfo, logDebug, logError } from '../../../../../../common/src/main/ets/components/utils/logutils' var TAG = 'DataWorker' const parentPort = worker.parentPort parentPort.onmessage = function (e) { - LogInfo(TAG, 'onMessage') + logInfo(TAG, 'onMessage') let data = e.data if (data.request_data == 'getRoot') { getRootData(data) @@ -32,74 +32,55 @@ parentPort.onmessage = function (e) { } parentPort.onmessageerror = function () { - LogInfo(TAG, 'onmessageerror') + logInfo(TAG, 'onmessageerror') } parentPort.onerror = function (data) { - LogInfo(TAG, 'onerror') + logInfo(TAG, 'onerror') } function getRootData(data) { - // let options = { - // "dev": { - // "name": "external_storage" - // } - // } - filemanager.getRoot() - .then(file => { - handleData(file, data) - }) - .catch((error) => { - LogDebug(TAG, 'getRoot 2 error' + error) - }); + filemanager.getRoot().then(file => { + handleData(file, data) + }).catch((error) => { + logError(TAG, 'getRoot 2 error' + error) + }); } function getListFileData(data) { - LogDebug(TAG, 'getListFileData 1') + logDebug(TAG, 'getListFileData 1') if (data.offset == undefined || data.count == undefined) { - LogDebug(TAG, 'path = ' + data.path + " type = " + data.media_type) - - // let options = { - // "dev": { - // "name": "external_storage" - // } - // } - filemanager.listFile(data.path, data.media_type) - .then(file => { - handleData(file, data) - }) - .catch((error) => { - LogDebug(TAG, 'getListFileData 2 error' + error) - }) + logDebug(TAG, 'path = ' + data.path + " type = " + data.MediaType) + filemanager.listFile(data.path, data.MediaType).then(file => { + handleData(file, data) + }).catch((error) => { + logError(TAG, 'getListFileData 2 error' + error) + }) } else { - filemanager.listFile(data.path, data.media_type, { + filemanager.listFile(data.path, data.MediaType, { 'offset': data.offset, 'count': data.count + }).then(file => { + handleData(file, data) + }).catch((error) => { + logError(TAG, 'getListFileData 3 error' + error) }) - .then(file => { - handleData(file, data) - }) - .catch((error) => { - LogDebug(TAG, 'getListFileData 3 error' + error) - }) } } function createFile(data) { - filemanager.createFile(data.path, data.save_name) - .then((uri) => { - handleData(uri, data) - }) - .catch((err) => { - handleData(err, data) - }) + filemanager.createFile(data.path, data.save_name).then((uri) => { + handleData(uri, data) + }).catch((err) => { + handleData(err, data) + }) } function handleData(file, data) { - LogInfo(TAG, 'handleData') + logInfo(TAG, 'handleData') var info = JSON.stringify(file) - LogInfo(TAG, 'info = ' + info.length) + logInfo(TAG, 'info = ' + info.length) var buf = new ArrayBuffer(info.length * 2) var bufView = new Uint16Array(buf) for (var index = 0; index < info.length; index++) { diff --git a/product/RK/src/main/resources/base/element/string.json b/product/RK/src/main/resources/base/element/string.json index 33d0707..e2a8d48 100644 --- a/product/RK/src/main/resources/base/element/string.json +++ b/product/RK/src/main/resources/base/element/string.json @@ -23,58 +23,6 @@ { "name": "btn_save", "value": "save" - }, - { - "name": "file_unknown", - "value": "Unknown file" - }, - { - "name": "save_file_has_same_file", - "value": "Duplicate name file already exists" - }, - { - "name": "save_file_no_media_permission", - "value": "Saving to media library is not currently supported" - }, - { - "name": "save_file_unknown_reason", - "value": "Unknown error" - }, - { - "name": "file_zip", - "value": "Compressed (zipped) file" - }, - { - "name": "file_xml", - "value": "XML document" - }, - { - "name": "file_xls", - "value": "Microsoft Excel worksheet" - }, - { - "name": "file_txt", - "value": "Txt document" - }, - { - "name": "file_rar", - "value": "Rar compressed file" - }, - { - "name": "file_pdf", - "value": "Adobe Acrobat Document" - }, - { - "name": "file_html", - "value": "HTML Document" - }, - { - "name": "file_pptx", - "value": "Microsoft PowerPoint Presentation" - }, - { - "name": "file_docx", - "value": "Microsoft Word Document" } ] } \ No newline at end of file diff --git a/product/RK/src/main/resources/zh_CN/element/string.json b/product/RK/src/main/resources/zh_CN/element/string.json index b11b8cf..5f4994e 100644 --- a/product/RK/src/main/resources/zh_CN/element/string.json +++ b/product/RK/src/main/resources/zh_CN/element/string.json @@ -23,58 +23,6 @@ { "name": "btn_save", "value": "保存" - }, - { - "name": "file_unknown", - "value": "未知文件" - }, - { - "name": "save_file_has_same_file", - "value": "已有重名文件" - }, - { - "name": "save_file_no_media_permission", - "value": "当前不支持保存到媒体库" - }, - { - "name": "save_file_unknown_reason", - "value": "未知错误" - }, - { - "name": "file_zip", - "value": "压缩(zipped)文件" - }, - { - "name": "file_xml", - "value": "XML文档" - }, - { - "name": "file_xls", - "value": "Microsoft Excel工作表" - }, - { - "name": "file_txt", - "value": "TXT文档" - }, - { - "name": "file_rar", - "value": "RAR压缩文件" - }, - { - "name": "file_pdf", - "value": "Adobe Acrobat Document" - }, - { - "name": "file_html", - "value": "HTML网页文件" - }, - { - "name": "file_pptx", - "value": "Microsoft PowerPoint演示文稿" - }, - { - "name": "file_docx", - "value": "Microsoft Word文档" } ] } \ No newline at end of file diff --git a/product/pad/package-lock.json b/product/pad/package-lock.json index 5690c19..3421ba5 100644 --- a/product/pad/package-lock.json +++ b/product/pad/package-lock.json @@ -1,5 +1,11 @@ { "name": "pad", "version": "1.0.0", - "lockfileVersion": 1 + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "@ohos/common": { + "version": "file:../../common" + } + } } diff --git a/product/pad/package.json b/product/pad/package.json index 9e36a59..6886c01 100644 --- a/product/pad/package.json +++ b/product/pad/package.json @@ -10,5 +10,7 @@ "description": "example description", "repository": {}, "version": "1.0.0", - "dependencies": {} + "dependencies": { + "@ohos/common": "file:../../common" + } } diff --git a/product/pad/src/main/ets/Application/AbilityStage.ts b/product/pad/src/main/ets/Application/AbilityStage.ts index 32dfe93..d637557 100644 --- a/product/pad/src/main/ets/Application/AbilityStage.ts +++ b/product/pad/src/main/ets/Application/AbilityStage.ts @@ -1,7 +1,25 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import AbilityStage from "@ohos.application.AbilityStage" +import { logInfo } from '../../../../../../common/src/main/ets/components/Utils/LogUtils' + +const TAG = "MyAbilityStage" export default class MyAbilityStage extends AbilityStage { onCreate() { - console.log("[Demo] MyAbilityStage onCreate") + logInfo(TAG, "onCreate") } } \ No newline at end of file diff --git a/product/pad/src/main/ets/MainAbility/MainAbility.ts b/product/pad/src/main/ets/MainAbility/MainAbility.ts index e75f049..e6b39a5 100644 --- a/product/pad/src/main/ets/MainAbility/MainAbility.ts +++ b/product/pad/src/main/ets/MainAbility/MainAbility.ts @@ -1,30 +1,42 @@ -import Ability from '@ohos.application.Ability' -import display from '@ohos.display' -import { Callback } from 'basic' +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -let displayWidth: number = 0 -let displayHeight: number = 0 +import Ability from '@ohos.application.Ability'; +import { Callback } from 'basic'; +import { logInfo, logError } from '../../../../../../common/src/main/ets/components/Utils/LogUtils'; + +const TAG: string = 'MainAbility' export default class MainAbility extends Ability { onCreate(want, launchParam) { - console.log("filePicker_MainAbility: onCreate") + logInfo(TAG, "onCreate") globalThis.abilityWant = want; globalThis.startMode = want.parameters.startMode globalThis.saveFile = want.parameters.saveFile globalThis.debugMode = want.parameters.debugMode - console.log('filePicker_MainAbility: startMode = ' + globalThis.startMode) - console.log('filePicker_MainAbility: file_name = ' + globalThis.saveFile) - console.log('filePicker_MainAbility: debugMode = ' + globalThis.debugMode) + logInfo(TAG, `parameters ${JSON.stringify(want.parameters)}`) } onDestroy() { - console.log("[Demo] MainAbility onDestroy") + logInfo(TAG, "onDestroy") } onWindowStageCreate(windowStage) { // Main window is created, set main page for this ability - console.log("filePicker_MainAbility: onWindowStageCreate") + logInfo(TAG, "onWindowStageCreate") globalThis.context = this.context this.requestPermissions(() => this.displayWindow(windowStage)) @@ -32,17 +44,17 @@ export default class MainAbility extends Ability { onWindowStageDestroy() { // Main window is destroyed, release UI related resources - console.log("[Demo] MainAbility onWindowStageDestroy") + logInfo(TAG, "onWindowStageDestroy") } onForeground() { // Ability has brought to foreground - console.log("[Demo] MainAbility onForeground") + logInfo(TAG, "onForeground") } onBackground() { // Ability has back to background - console.log("[Demo] MainAbility onBackground") + logInfo(TAG, "onBackground") } private requestPermissions(callback: Callback) { @@ -52,35 +64,19 @@ export default class MainAbility extends Ability { "ohos.permission.WRITE_MEDIA" ] globalThis.context.requestPermissionsFromUser(permissionList).then(function (data) { - console.log('filePicker_MainAbility: request permission data result = ' + data.authResults) + logInfo(TAG, `request permission data result = ${data.authResults}`) callback() }, (error) => { - console.log('filePicker_MainAbility: fail to request permission error code = ' + error.code) + logError(TAG, `fail to request permission error code = ${error.code}`) }) } private displayWindow(windowStage) { + logInfo(TAG, "displayWindow()") windowStage.setUIContent(this.context, "pages/index", null) - - display.getDefaultDisplay().then(dis => { - displayWidth = dis.width - displayHeight = dis.height - }) - windowStage.getMainWindow().then(win => { - console.log("filePicker_MainAbility: windowStage.getMainWindow()") - win.setWindowMode(102, (err, data) => { - }) - - win.resetSize(vp2px(752), vp2px(446)) - - let positionX: number = (displayWidth - vp2px(752)) / 2 - let positionY: number = (displayHeight - vp2px(446)) / 2 - win.moveTo(positionX, positionY) - - win.on('windowSizeChange', () => { - win.resetSize(vp2px(752), vp2px(446)) - }) + logInfo(TAG, "windowStage.getMainWindow()") + win.resetSize(vp2px(752), vp2px(450)) }) } }; diff --git a/product/pad/src/main/ets/module/AbilityUtils.ets b/product/pad/src/main/ets/module/AbilityUtils.ets deleted file mode 100644 index c62af28..0000000 --- a/product/pad/src/main/ets/module/AbilityUtils.ets +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import display from '@ohos.display' -import featureAbility from '@ohos.ability.featureAbility' -import { LogInfo } from '../../../../../../common/LogUtils' -import { DisplayInfo } from './DisplayInfo' - -var TAG: string = 'AbilityUtils' - -export function terminateSelfWithResult(resultCode: number, result: string): void { - LogInfo(TAG, 'terminateSelfWithResult') - let startMode: string = AppStorage.Get('startMode') - var abilityResult = { - resultCode: resultCode, - want: { - parameters: { - 'startMode': startMode, - 'result': result - } - } - } - globalThis.context.terminateSelfWithResult(abilityResult, (error) => { - if (error.code) { - LogInfo(TAG, 'Operation failed. Cause: ' + JSON.stringify(error)) - return - } - LogInfo(TAG, 'Operation succeeded') - }) -} - -export function initData(): void { - LogInfo(TAG, 'initData') - initWindowScale() - - getWantFromHap() -} - -function initWindowScale(): void { - display.getDefaultDisplay().then(dis => { - LogInfo(TAG, 'width = ' + dis.width + ';height= ' + dis.height) - let displayInfo: DisplayInfo = new DisplayInfo() - - if (dis.width > dis.height) { // 横屏 - displayInfo.width = dis.width - displayInfo.height = dis.height * 0.7 // 需要减去信号栏和导航栏的高度 - displayInfo.mainDialogHeight = displayInfo.height - vp2px(64 + 76) - displayInfo.mainDialogWidth = displayInfo.width - - } else { // 竖屏 - displayInfo.width = dis.width - displayInfo.height = dis.height * 0.7 // 需要减去信号栏和导航栏的高度 - displayInfo.mainDialogHeight = displayInfo.height - vp2px(64 + 76) - displayInfo.mainDialogWidth = displayInfo.width - } - - LogInfo(TAG, 'mainDialogWidth = ' + displayInfo.mainDialogWidth) - LogInfo(TAG, 'mainDialogHeight = ' + displayInfo.mainDialogHeight) - AppStorage.SetOrCreate('displayInfo', displayInfo) - - }) -} - -function getWantFromHap(): void { - featureAbility.getWant() - .then((Want) => { - var mode: string = Want.parameters['startMode'] - if (mode == undefined) { - AppStorage.SetOrCreate('startMode', 'choose') - } else { - AppStorage.SetOrCreate('startMode', mode) - } - let save_name: string = Want.parameters['file_name'] - AppStorage.Set('saveName', save_name) - LogInfo(TAG, 'saveName = ' + save_name) - }).catch((error) => { - LogInfo(TAG, 'fail Data: ' + JSON.stringify(error)) - }) -} \ No newline at end of file diff --git a/product/pad/src/main/ets/module/Constants.ets b/product/pad/src/main/ets/module/Constants.ets deleted file mode 100644 index abd0b1a..0000000 --- a/product/pad/src/main/ets/module/Constants.ets +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export enum menuLevel { - MENU_FIRST_LEVEL_BY_TYPE = 1, - MENU_SECOND_LEVEL_BY_FOLD = 2, - MENU_THIRD_LEVEL_HAS_PIC = 3, - MENU_THIRD_LEVEL_HAS_DETAIL = 4, -} - -export enum media_type { - MEDIA_TYPE_FILE = 1, - MEDIA_TYPE_IMAGE = 3, - MEDIA_TYPE_VIDEO = 4, - MEDIA_TYPE_AUDIO = 5, - MEDIA_TYPE_ALBUM = 8 -} - -export enum GridItemSize { - GRID_ITEM_HEIGHT = 126, - GRID_ITEM_WIDTH = 96, - GRID_ITEM_COLUMNS_GAP = 8, - GRID_ITEM_ROWS_GAP = 8, -} - -export enum terminate_reason { - SUCCESS = 0, - NO_ACTION = -1, -} - -export enum pad_size { - MAIN_DIALOG_WIDTH = 752, - MAIN_DIALOG_HEIGHT = 502, - LEFT_DIALOG_WIDTH = 200, - LEFT_DIALOG_HEIGHT = 332, - RIGHT_DIALOG_WIDTH = 544, - RIGHT_DIALOG_HEIGHT = 332, - BOTTOM_WIDTH = 744, - BOTTOM_HEIGHT = 120, - - IC_PUBLIC_FOLDER_WIDTH = 24, - IC_PUBLIC_FOLDER_HEIGHT = 24, - ONE = 1, - TWO = 2, - FOUR = 4, - EIGHT = 8, - NINE = 9, - TEN = 10, - ELEVEN = 11, - TWELVE = 12, - FOURTEEN = 14, - SIXTEEN = 16, - SEVENTEEN = 17, - EIGHTEEN = 18, - NINETEEN = 19, - TWENTY = 20, - TWENTY_ONE = 21, - TWENTY_TWO = 22, - TWENTY_FOUR = 24, - TWENTY_SEVEN = 27, - TWENTY_NINE = 29, - THIRTY = 30, - THIRTY_TWO = 32, - FORTY = 40, - FORTY_SIX = 46, - FIFTY_SIX = 56, - SIXTY_FOUR = 64, - EIGHTY = 80, - EIGHTY_TWO = 82, - EIGHTY_EIGHT = 88, - NINETY_SIX = 96, - ONE_HUNDRED_AND_FOUR = 104, - ONE_HUNDRED_AND_THIRTY_FOUR = 134, - ONE_HUNDRED_AND_SEVENTY_SIX = 176, - ONE_HUNDRED_AND_SEVENTY_EIGHT = 178, - TWO_HUNDRED_AND_SIXTY = 260, - THREE_HUNDRED_AND_FORTY = 340, - FOUR_HUNDRED = 400, - FIVE_HUNDRED_AND_FOUR = 504, - SIX_HUNDRED_AND_NINE = 609, - SEVEN_HUNDRED_AND_FOURTEEN = 714, -} - -export enum mediaName { - IMAGE = 'ͼƬ', - VIDEO = 'Ƶ', - AUDIO = '', - DOCUMENT = 'ĵ', - FILE_TYPE = "ļ" -} \ No newline at end of file diff --git a/product/pad/src/main/ets/module/Constants.ts b/product/pad/src/main/ets/module/Constants.ts new file mode 100644 index 0000000..014d5a3 --- /dev/null +++ b/product/pad/src/main/ets/module/Constants.ts @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export enum PadSize { + MAIN_DIALOG_WIDTH = 752, + MAIN_DIALOG_HEIGHT = 502, + LEFT_DIALOG_WIDTH = 200, + LEFT_DIALOG_HEIGHT = 332, + RIGHT_DIALOG_WIDTH = 544, + RIGHT_DIALOG_HEIGHT = 332, + GRID_WIDTH = 512, + BOTTOM_WIDTH = 744, + BOTTOM_HEIGHT = 120, + + IC_PUBLIC_FOLDER_WIDTH = 24, + IC_PUBLIC_FOLDER_HEIGHT = 24, + ONE = 1, + TWO = 2, + FOUR = 4, + EIGHT = 8, + NINE = 9, + TEN = 10, + ELEVEN = 11, + TWELVE = 12, + FOURTEEN = 14, + SIXTEEN = 16, + SEVENTEEN = 17, + EIGHTEEN = 18, + NINETEEN = 19, + TWENTY = 20, + TWENTY_ONE = 21, + TWENTY_TWO = 22, + TWENTY_FOUR = 24, + TWENTY_SEVEN = 27, + TWENTY_NINE = 29, + THIRTY = 30, + THIRTY_TWO = 32, + THIRTY_EIGHT = 38, + FORTY = 40, + FORTY_SIX = 46, + FIFTY_SIX = 56, + SIXTY_FOUR = 64, + EIGHTY = 80, + EIGHTY_TWO = 82, + EIGHTY_EIGHT = 88, + NINETY_SIX = 96, + ONE_HUNDRED_AND_FOUR = 104, + ONE_HUNDRED_AND_THIRTY_FOUR = 134, + ONE_HUNDRED_AND_THIRTY_SIX = 136, + ONE_HUNDRED_AND_SEVENTY_SIX = 176, + ONE_HUNDRED_AND_SEVENTY_EIGHT = 178, + TWO_HUNDRED_AND_SIXTY = 260, + THREE_HUNDRED_AND_FORTY = 340, + FOUR_HUNDRED = 400, + FIVE_HUNDRED_AND_FOUR = 504, + SIX_HUNDRED_AND_NINE = 609, + SEVEN_HUNDRED_AND_FOURTEEN = 714, +} \ No newline at end of file diff --git a/product/pad/src/main/ets/module/DialogUtils.ets b/product/pad/src/main/ets/module/DialogUtils.ets deleted file mode 100644 index 6bec0a8..0000000 --- a/product/pad/src/main/ets/module/DialogUtils.ets +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { FileInfo } from '../../../../../../feature/FileInfo' -import { LogInfo } from '../../../../../../common/LogUtils' - -let TAG: string = 'DialogUtils' - -@CustomDialog -export struct WarningDialog { - @Link code: number - controller: CustomDialogController - cancel: () => void - confirm: () => void - - build() { - Column() { - Text('Warning Title').fontSize(20).margin(10) - if (this.code == 1) { - Text($r("app.string.save_file_has_same_file")).fontSize(16).margin(10) - } else if (this.code == 2) { - Text($r("app.string.save_file_no_media_permission")).fontSize(16).margin(10) - } else { - Text($r("app.string.save_file_unknown_reason")).fontSize(16).margin(10) - } - Flex({ justifyContent: FlexAlign.SpaceAround }) { - Button('cancel') - .onClick(() => { - this.controller.close() - this.cancel() - }).backgroundColor(0xffffff).fontColor(Color.Black) - Button('confirm') - .onClick(() => { - this.controller.close() - this.confirm() - }).backgroundColor(0xffffff).fontColor(Color.Red) - }.margin({ bottom: 10 }) - } - } -} - -@CustomDialog -export struct ChooseDialog { - controller: CustomDialogController - - build() { - Column() { - Row() { - Text('选择该文件') - } - Row() { - Button() { - Text('取消') - .height('100%') - .fontSize(24) - .fontColor(Color.Blue) - } - .width(px2vp(200)) - .height(px2vp(50)) - .backgroundColor(Color.White) - .onClick(() => { - this.controller.close() - }) - - Divider() - .vertical(true) - .color(Color.Gray) - .height(40) - .margin({top: 0, right: 10, bottom: 0, left: 10}) - - Button() { - Text('确定') - .height('100%') - .fontSize(24) - .fontColor(Color.Blue) - } - .width(px2vp(200)) - .height(px2vp(50)) - .backgroundColor(Color.White) - .onClick(() => { - let choseItem: FileInfo = AppStorage.Get('selectedFileInfo') - if (choseItem != null) { - let files: Array = AppStorage.Get('choseFiles') - let flag: boolean = true - files.forEach((item: FileInfo) => { - LogInfo(TAG, 'item.name = ' + item.name + '; item.path = ' + item.path) - LogInfo(TAG, 'choseItem.name = ' + choseItem.name + '; choseItem.path = ' + choseItem.path) - if (item.name == choseItem.name && item.path == choseItem.path) { - flag = false - } - }) - if (flag) { - files.push(choseItem) - AppStorage.Set('choseFiles', files) - } - } - this.controller.close() - }) - } - .padding(20) - } - .padding({ - top: 25, - right: 0, - bottom: 15, - left: 0 - }) - } -} \ No newline at end of file diff --git a/product/pad/src/main/ets/module/FileInfo.ets b/product/pad/src/main/ets/module/FileInfo.ets deleted file mode 100644 index 28d87de..0000000 --- a/product/pad/src/main/ets/module/FileInfo.ets +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { media_type } from './Constants.ets' - -export class FileInfo { - name: string - path: string - type: number= media_type.MEDIA_TYPE_ALBUM - size: string - dataAdded_time: string - modified_time: string - mediaType: string - thumbnail: Resource - font_color: Color | string | Resource - opacity: number - list_background: string | Resource - - constructor(name: string) { - this.name = name - } -} - -export class TopPathInfo { - name: string - path: string - opacity: number = 1 - - constructor(name: string, path: string) { - this.name = name - this.path = path - } -} \ No newline at end of file diff --git a/product/pad/src/main/ets/module/FileManagerServiceUtils.ets b/product/pad/src/main/ets/module/FileManagerServiceUtils.ets deleted file mode 100644 index 054ee6d..0000000 --- a/product/pad/src/main/ets/module/FileManagerServiceUtils.ets +++ /dev/null @@ -1,341 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { media_type } from './Constants'; -import { FileInfo } from '../../../../../../feature/FileInfo' -import { LogInfo } from '../../../../../../common/LogUtils' - -var TAG = 'FileManagerServiceUtils' -var isDebug: boolean = true; - -export function getFirstMenu(deviceName: string): Array { - let fileList: Array = []; - if (isDebug) { - let file1: FileInfo = new FileInfo('image_album'); - file1.type = media_type.MEDIA_TYPE_ALBUM; - file1.path = 'dataability:///album'; - file1.size = ''; - file1.dataAdded_time = 'xxx'; - file1.modified_time = 'xxx'; - fileList.push(file1); - - let file2: FileInfo = new FileInfo('video_album'); - file2.type = media_type.MEDIA_TYPE_ALBUM; - file2.path = 'dataability:///album'; - file2.size = ''; - file2.dataAdded_time = 'xxx'; - file2.modified_time = 'xxx'; - fileList.push(file2); - - let file4: FileInfo = new FileInfo('file_folder'); - file4.type = media_type.MEDIA_TYPE_ALBUM; - file4.path = 'dataability:///album'; - file4.size = ''; - file4.dataAdded_time = 'xxx'; - file4.modified_time = 'xxx'; - fileList.push(file4); - - let file3: FileInfo = new FileInfo('audio_album'); - file3.type = media_type.MEDIA_TYPE_ALBUM; - file3.path = 'dataability:///album'; - file3.size = ''; - file3.dataAdded_time = 'xxx'; - file3.modified_time = 'xxx'; - fileList.push(file3); - } else { - // var fileInfo = filemanager.getRoot(deviceName); - } - - fileList.forEach(item => { - if (item.name == 'image_album') { - item.name = "图片"; - item.mediaType = 'image'; - item.thumbnail = $r("app.media.ic_type_image") - } else if (item.name == 'video_album') { - item.name = "视频"; - item.mediaType = 'video'; - item.thumbnail = $r("app.media.ic_type_video") - } else if (item.name == 'audio_album') { - item.name = "音乐"; - item.mediaType = 'audio'; - item.thumbnail = $r("app.media.ic_type_audio") - } else if (item.name == 'file_folder') { - item.name = "文档"; - item.mediaType = 'file'; - item.thumbnail = $r("app.media.ic_public_file") - } - }); - - return fileList; -} - -export function getListFile(deviceName: string, mediaType: string, path: string): Array { - LogInfo(TAG, "getListFile mediaType = " + mediaType + ';path = ' + path); - let fileList: Array = []; - if (isDebug) { - if (path == 'dataability:///album') { - if (mediaType == 'image') { - let fileInfo1: FileInfo = new FileInfo("微信的图片"); - fileInfo1.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo1.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/01'; - fileInfo1.dataAdded_time = 'xxx'; - fileInfo1.modified_time = 'xxx'; - fileList.push(fileInfo1); - let fileInfo2: FileInfo = new FileInfo("图片1"); - fileInfo2.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo2.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/02'; - fileInfo2.dataAdded_time = 'xxx'; - fileInfo2.modified_time = 'xxx'; - fileList.push(fileInfo2); - let fileInfo3: FileInfo = new FileInfo("图片2"); - fileInfo3.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo3.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/03'; - fileInfo3.dataAdded_time = 'xxx'; - fileInfo3.modified_time = 'xxx'; - fileList.push(fileInfo3); - let fileInfo4: FileInfo = new FileInfo("图片3"); - fileInfo4.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo4.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/04'; - fileInfo4.dataAdded_time = 'xxx'; - fileInfo4.modified_time = 'xxx'; - fileList.push(fileInfo4); - let fileInfo5: FileInfo = new FileInfo("图片4"); - fileInfo5.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo5.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/05'; - fileInfo5.dataAdded_time = 'xxx'; - fileInfo5.modified_time = 'xxx'; - fileList.push(fileInfo5); - let fileInfo6: FileInfo = new FileInfo("图片5"); - fileInfo6.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo6.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/06'; - fileInfo6.dataAdded_time = 'xxx'; - fileInfo6.modified_time = 'xxx'; - fileList.push(fileInfo6); - let fileInfo7: FileInfo = new FileInfo("图片6"); - fileInfo7.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo7.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/07'; - fileInfo7.dataAdded_time = 'xxx'; - fileInfo7.modified_time = 'xxx'; - fileList.push(fileInfo7); - let fileInfo8: FileInfo = new FileInfo("图片7"); - fileInfo8.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo8.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/08'; - fileInfo8.dataAdded_time = 'xxx'; - fileInfo8.modified_time = 'xxx'; - fileList.push(fileInfo8); - let fileInfo9: FileInfo = new FileInfo("图片8"); - fileInfo1.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo1.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/09'; - fileInfo1.dataAdded_time = 'xxx'; - fileInfo1.modified_time = 'xxx'; - fileList.push(fileInfo9); - let fileInfo10: FileInfo = new FileInfo("图片9"); - fileInfo10.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo10.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/10'; - fileInfo10.dataAdded_time = 'xxx'; - fileInfo10.modified_time = 'xxx'; - fileList.push(fileInfo10); - let fileInfo11: FileInfo = new FileInfo("图片10"); - fileInfo11.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo11.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/11'; - fileInfo11.dataAdded_time = 'xxx'; - fileInfo11.modified_time = 'xxx'; - fileList.push(fileInfo11); - } else if (mediaType == 'video') { - let fileInfo1: FileInfo = new FileInfo("视频0"); - fileInfo1.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo1.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/12'; - fileInfo1.dataAdded_time = 'xxx'; - fileInfo1.modified_time = 'xxx'; - fileList.push(fileInfo1); - let fileInfo2: FileInfo = new FileInfo("视频1"); - fileInfo2.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo2.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/13'; - fileInfo2.dataAdded_time = 'xxx'; - fileInfo2.modified_time = 'xxx'; - fileList.push(fileInfo2); - let fileInfo3: FileInfo = new FileInfo("视频2"); - fileInfo3.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo3.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/14'; - fileInfo3.dataAdded_time = 'xxx'; - fileInfo3.modified_time = 'xxx'; - fileList.push(fileInfo3); - let fileInfo4: FileInfo = new FileInfo("视频3"); - fileInfo4.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo4.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/15'; - fileInfo4.dataAdded_time = 'xxx'; - fileInfo4.modified_time = 'xxx'; - fileList.push(fileInfo4); - let fileInfo5: FileInfo = new FileInfo("视频4"); - fileInfo5.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo5.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/16'; - fileInfo5.dataAdded_time = 'xxx'; - fileInfo5.modified_time = 'xxx'; - fileList.push(fileInfo5); - } else if (mediaType == 'audio') { - let fileInfo1: FileInfo = new FileInfo("音频0"); - fileInfo1.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo1.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/17'; - fileInfo1.dataAdded_time = 'xxx'; - fileInfo1.modified_time = 'xxx'; - fileList.push(fileInfo1); - let fileInfo2: FileInfo = new FileInfo("音频1"); - fileInfo2.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo2.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/18'; - fileInfo2.dataAdded_time = 'xxx'; - fileInfo2.modified_time = 'xxx'; - fileList.push(fileInfo2); - let fileInfo3: FileInfo = new FileInfo("音频2"); - fileInfo3.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo3.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/19'; - fileInfo3.dataAdded_time = 'xxx'; - fileInfo3.modified_time = 'xxx'; - fileList.push(fileInfo3); - let fileInfo4: FileInfo = new FileInfo("音频3"); - fileInfo4.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo4.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/20'; - fileInfo4.dataAdded_time = 'xxx'; - fileInfo4.modified_time = 'xxx'; - fileList.push(fileInfo4); - let fileInfo5: FileInfo = new FileInfo("音频4"); - fileInfo5.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo5.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/21'; - fileInfo5.dataAdded_time = 'xxx'; - fileInfo5.modified_time = 'xxx'; - fileList.push(fileInfo5); - } else if (mediaType == 'file') { - let fileInfo1: FileInfo = new FileInfo("文件夹0"); - fileInfo1.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo1.mediaType = mediaType; - fileInfo1.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/22'; - fileInfo1.dataAdded_time = 'xxx'; - fileInfo1.modified_time = 'xxx'; - fileList.push(fileInfo1); - let fileInfo2: FileInfo = new FileInfo("文件夹1"); - fileInfo2.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo2.mediaType = mediaType; - fileInfo2.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/23'; - fileInfo2.dataAdded_time = 'xxx'; - fileInfo2.modified_time = 'xxx'; - fileList.push(fileInfo2); - let fileInfo3: FileInfo = new FileInfo("文件夹2"); - fileInfo3.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo3.mediaType = mediaType; - fileInfo3.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/24'; - fileInfo3.dataAdded_time = 'xxx'; - fileInfo3.modified_time = 'xxx'; - fileList.push(fileInfo3); - let fileInfo4: FileInfo = new FileInfo("文件夹3"); - fileInfo4.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo4.mediaType = mediaType; - fileInfo4.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/25'; - fileInfo4.dataAdded_time = 'xxx'; - fileInfo4.modified_time = 'xxx'; - fileList.push(fileInfo4); - let fileInfo5: FileInfo = new FileInfo("文件夹4"); - fileInfo5.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo5.mediaType = mediaType; - fileInfo5.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/26'; - fileInfo5.dataAdded_time = 'xxx'; - fileInfo5.modified_time = 'xxx'; - fileList.push(fileInfo5); - let fileInfo6: FileInfo = new FileInfo("文本文档.txt"); - fileInfo6.type = media_type.MEDIA_TYPE_FILE; - fileInfo6.mediaType = mediaType; - fileInfo6.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/27'; - fileInfo6.dataAdded_time = 'xxx'; - fileInfo6.modified_time = 'xxx'; - fileInfo6.size = '1,024 KB' - fileList.push(fileInfo6); - let fileInfo7: FileInfo = new FileInfo("验收文稿.ppt"); - fileInfo7.type = media_type.MEDIA_TYPE_FILE; - fileInfo7.mediaType = mediaType; - fileInfo7.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/28'; - fileInfo7.dataAdded_time = 'xxx'; - fileInfo7.modified_time = 'xxx'; - fileInfo7.size = '4,562,000 KB' - fileList.push(fileInfo7); - } - } else { - if (mediaType == 'image') { - for (var index = 0; index < 10; index++) { - let file: FileInfo = new FileInfo("" + index + ".png"); - file.type = media_type.MEDIA_TYPE_IMAGE; - file.path = path + index; - file.dataAdded_time = 'xxx'; - file.modified_time = 'xxx'; - fileList.push(file); - } - } else if (mediaType == 'video') { - for (var index = 0; index < 15; index++) { - let file: FileInfo = new FileInfo("" + index + ".wmv"); - file.type = media_type.MEDIA_TYPE_VIDEO; - file.path = path + index; - file.dataAdded_time = 'xxx'; - file.modified_time = 'xxx'; - fileList.push(file); - } - } else if (mediaType == 'audio') { - for (var index = 0; index < 18; index++) { - let file: FileInfo = new FileInfo("" + index + ".mp3"); - file.type = media_type.MEDIA_TYPE_AUDIO; - file.path = path + index; - file.dataAdded_time = 'xxx'; - file.modified_time = 'xxx'; - fileList.push(file); - } - } else if (mediaType == 'file') { - let fileInfo4: FileInfo = new FileInfo("文件夹3"); - fileInfo4.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo4.path = path + '5'; - fileInfo4.dataAdded_time = 'xxx'; - fileInfo4.modified_time = 'xxx'; - fileList.push(fileInfo4); - let fileInfo5: FileInfo = new FileInfo("文件夹4"); - fileInfo5.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo5.path = path + '6'; - fileInfo5.dataAdded_time = 'xxx'; - fileInfo5.modified_time = 'xxx'; - fileList.push(fileInfo5); - let fileInfo6: FileInfo = new FileInfo("文本文档.txt"); - fileInfo6.type = media_type.MEDIA_TYPE_FILE; - fileInfo6.path = path + '7'; - fileInfo6.size = '1,000 KB' - fileInfo6.dataAdded_time = 'xxx'; - fileInfo6.modified_time = 'xxx'; - fileList.push(fileInfo6); - let fileInfo7: FileInfo = new FileInfo("验收文稿.ppt"); - fileInfo7.type = media_type.MEDIA_TYPE_FILE; - fileInfo7.path = path + '8'; - fileInfo7.size = '520,000 KB' - fileInfo7.dataAdded_time = 'xxx'; - fileInfo7.modified_time = 'xxx'; - fileList.push(fileInfo7); - } - } - } else { - // fileList = filemanager.listfile(deviceName, mediaType, path); - } - LogInfo(TAG, "get file list is " + fileList.length) - return fileList; -} - -//保存某个文件,返回是否保存成功,或有错误提示,还需要增加三方应用包名 -export function saveFile(deviceName: string, name: string, path: string): boolean { - LogInfo(TAG, 'saveFile'); - - return true; - -} diff --git a/product/pad/src/main/ets/module/Utils.ets b/product/pad/src/main/ets/module/Utils.ets deleted file mode 100644 index cac2365..0000000 --- a/product/pad/src/main/ets/module/Utils.ets +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import resourceManager from '@ohos.resourceManager'; -import { TopPathInfo } from '../module/FileInfo' -import { LogInfo } from '../../../../../../common/LogUtils' -import { mediaName } from './Constants' - -var TAG: string = 'Utils' - -export function getRootPath(): Array { - var root_path: Array = [] - root_path.push(new TopPathInfo('文件类型', '')) - return root_path -} - -var strTypeArr = [ - ['image', '图片'], - ['video', '视频'], - ['audio', '音频'], - ['file', '文档'], -] - -export function changeTypeToString(type: string): string { - LogInfo(TAG, 'changeTypeToString type = ' + type) - for (var i = 0; i < strTypeArr.length; i++) { - if (strTypeArr[i][0] == type) { - return strTypeArr[i][1] - } - } - return '' -} - -export function changeStringToType(type: string): string { - LogInfo(TAG, 'changeStringToType type = ' + type) - for (var i = 0; i < strTypeArr.length; i++) { - if (strTypeArr[i][1] == type) { - return strTypeArr[i][0] - } - } - return '' -} - -export function getItemNumberInGrid(itemWidth: number, itemGap: number, parentWidth: number): string { - LogInfo(TAG, 'getItemNumberInGrid') - let columnTemples: string = '' - let remainderWidth: number = parentWidth - itemWidth - columnTemples += '1fr' - while (itemWidth + itemGap < remainderWidth) { - remainderWidth = remainderWidth - (itemWidth + itemGap) - columnTemples += ' 1fr' - } - LogInfo(TAG, 'columnTemples = ' + columnTemples) - return columnTemples -} - -var fileSuffixAndType = [ - ['.doc', $r("app.media.ic_file_doc"), $r("app.string.file_docx")], - ['.html', $r("app.media.ic_file_html"), $r("app.string.file_html")], - ['.pdf', $r("app.media.ic_file_pdf"), $r("app.string.file_pdf")], - ['.pptx', $r("app.media.ic_file_pptx"), $r("app.string.file_pptx")], - ['.ppt', $r("app.media.ic_file_pptx"), $r("app.string.file_pptx")], - ['.rar', $r("app.media.ic_file_rar"), $r("app.string.file_rar")], - ['.txt', $r("app.media.ic_file_txt"), $r("app.string.file_txt")], - ['.xls', $r("app.media.ic_file_xls"), $r("app.string.file_xls")], - ['.xml', $r("app.media.ic_file_xml"), $r("app.string.file_xml")], - ['.zip', $r("app.media.ic_file_zip"), $r("app.string.file_zip")], -] - -export function getShowIconBySuffix(suffix: string): string | Resource { - LogInfo(TAG, 'getShowIconBySuffix suffix = ' + suffix) - for (var i = 0; i < fileSuffixAndType.length; i++) { - if (isTwoStringEqual(fileSuffixAndType[i][0].toString(),suffix)) { - return fileSuffixAndType[i][1] - } - } - return $r("app.media.ic_file_unknown") -} - -export function getShowTextBySuffix(suffix: string): string | Resource { - LogInfo(TAG, 'getShowTextBySuffix suffix = ' + suffix) - for (var i = 0; i < fileSuffixAndType.length; i++) { - if (fileSuffixAndType[i][0] == suffix) { - return fileSuffixAndType[i][2] - } - } - return $r("app.string.file_unknown") -} - -export function getWarningDialogMessage(code: number): string | Resource { - switch (code) { - case 1: - return $r("app.string.save_file_has_same_file") - case 2: - return $r("app.string.save_file_no_media_permission") - default: - return $r("app.string.save_file_unknown_reason") - } -} - -export function isTwoStringEqual(src: string, tar: string) { - if (src.indexOf(tar) == 0 && tar.indexOf(src) == 0) { - return true; - } - return false; -} - -export function updateTopPathInfo(currentPathInfo: Array, name: string, path: string) { - currentPathInfo.forEach((item: TopPathInfo) => { - item.opacity = 0.4 - }) - - currentPathInfo.push(new TopPathInfo(name, path)) - AppStorage.Set('topPathInfo', currentPathInfo) - return currentPathInfo -} \ No newline at end of file diff --git a/product/pad/src/main/ets/pages/FirstLevelByType.ets b/product/pad/src/main/ets/pages/FirstLevelByType.ets index 57f6a53..c7446f3 100644 --- a/product/pad/src/main/ets/pages/FirstLevelByType.ets +++ b/product/pad/src/main/ets/pages/FirstLevelByType.ets @@ -13,97 +13,64 @@ * limitations under the License. */ -import { DisplayInfo } from '../module/DisplayInfo' -import { menuLevel, pad_size } from '../module/Constants' -import { FileInfo } from '../../../../../../feature/FileInfo' -import { LogInfo } from '../../../../../../common/LogUtils' +import { PadSize } from '../module/Constants' +import { MenuLevel } from '../../../../../../common/src/main/ets/components/Data/Constants' +import { FileInfo } from '../../../../../../common/src/main/ets/components/Data/FileInfo' +import { logInfo } from '../../../../../../common/src/main/ets/components/Utils/LogUtils' @Component export struct FirstLevelByType { - private TAG: string = 'FirstLevelByType' - private mWorker - private mFileList: FileInfo[] - private displayInfo: DisplayInfo = new DisplayInfo() + private TAG: string = 'FirstLevelByType' + private mWorker + private mFileList: FileInfo[] + @Link mType: string + @Link mMenuLevel: number + @Link mCurrentPath: string - @Link mType: string - @Link mMenuLevel: number - @Link mCurrentPath: string + aboutToAppear() { + logInfo(this.TAG, 'aboutToAppear mType = ' + this.mType) + logInfo(this.TAG, 'aboutToAppear mCurrentPath = ' + this.mCurrentPath) + } - aboutToAppear() { - LogInfo(this.TAG, 'aboutToAppear mType = ' + this.mType) - LogInfo(this.TAG, 'aboutToAppear mCurrentPath = ' + this.mCurrentPath) - this.displayInfo = AppStorage.Get('displayInfo') - } - - build() { - Grid() { - ForEach(this.mFileList, (item: FileInfo) => { - GridItem() { - Column() { - Image($r("app.media.ic_public_big_folder")) - .width(pad_size.EIGHTY) - .height(pad_size.EIGHTY) - .margin({ left: pad_size.TWELVE, top: pad_size.FOUR, right: pad_size.TWELVE }) - Text(item.name) - .width(pad_size.EIGHTY_EIGHT) - .fontSize(pad_size.FOURTEEN) - .fontWeight(FontWeight.Regular) - .fontColor('#000000') - .textAlign(TextAlign.Center) - .margin({ top: pad_size.FOUR, bottom: pad_size.TWENTY_SEVEN }) - } - .width(pad_size.ONE_HUNDRED_AND_FOUR) - .height(pad_size.ONE_HUNDRED_AND_THIRTY_FOUR) - .alignItems(HorizontalAlign.Center) - .onClick(() => { - this.mType = item.mediaType - this.mCurrentPath = item.path - this.mMenuLevel = menuLevel.MENU_SECOND_LEVEL_BY_FOLD - }) + build() { + Grid() { + ForEach(this.mFileList, (item: FileInfo) => { + GridItem() { + Column() { + Image($r("app.media.ic_public_big_folder")) + .width(PadSize.EIGHTY) + .height(PadSize.EIGHTY) + .margin({ + left: PadSize.TWELVE, + right: PadSize.TWELVE, + top: PadSize.FOUR, + bottom: PadSize.TWO + }) + Text(item.name) + .width(PadSize.EIGHTY_EIGHT) + .fontSize(PadSize.FOURTEEN) + .fontWeight(FontWeight.Regular) + .fontColor('#000000') + .textAlign(TextAlign.Center) + .padding(PadSize.FOUR) + .margin({ left: PadSize.FOUR, right: PadSize.FOUR, bottom: PadSize.FOUR }) + } + .width(PadSize.ONE_HUNDRED_AND_FOUR) + .height(PadSize.ONE_HUNDRED_AND_THIRTY_SIX) + .margin({ left: PadSize.SIXTEEN, right: PadSize.EIGHT, bottom: PadSize.TWENTY }) + .alignItems(HorizontalAlign.Center) + .onClick(() => { + this.mType = item.mediaType + this.mCurrentPath = item.path + this.mMenuLevel = MenuLevel.MENU_SECOND_LEVEL_BY_FOLD + }) + } + }, item => item.name) } - }, item => item.name) + .width(PadSize.GRID_WIDTH) + .columnsTemplate('1fr 1fr 1fr 1fr') + .columnsGap(1) + .rowsGap(1) + .margin({ top: PadSize.SIXTEEN }) } - .columnsTemplate('1fr 1fr 1fr 1fr') - .columnsGap(1) - .rowsGap(1) - .margin({ top: pad_size.SIXTEEN }) - } -} - -@Component -struct RowView { - private item: FileInfo = new FileInfo('') - private displayInfo: DisplayInfo = AppStorage.Get('displayInfo') - - @Link mMenuLevel: number - @Link mType: string - @Link mCurrentPath: string - - build() { - Row() { - Image($r("app.media.ic_file_manager")) - .width(22 * 2) - .height(19 * 2) - .margin({ left: 12 }) - Text(this.item.name) - .fontSize(16 * 2) - .fontColor('#182431') - .fontWeight(FontWeight.Medium) - .margin({ left: 16 }) - Blank() - Image($r("app.media.ic_right")) - .width(12 * 2) - .height(24 * 2) - .margin({ right: 24 * 2 }) - } - .height(56) - .width(this.displayInfo.mainDialogWidth) // TODO - .margin({ top: '16vp', bottom: '16vp' }) - .backgroundColor(this.item.list_background) - .onClick(() => { - this.mType = this.item.mediaType - this.mCurrentPath = this.item.path - this.mMenuLevel = menuLevel.MENU_SECOND_LEVEL_BY_FOLD - }) - } } \ No newline at end of file diff --git a/product/pad/src/main/ets/pages/SecondLevelByFold.ets b/product/pad/src/main/ets/pages/SecondLevelByFold.ets index 5bfe22c..6d71248 100644 --- a/product/pad/src/main/ets/pages/SecondLevelByFold.ets +++ b/product/pad/src/main/ets/pages/SecondLevelByFold.ets @@ -13,156 +13,109 @@ * limitations under the License. */ -import { FileInfo, TopPathInfo } from '../../../../../../feature/FileInfo' -import { changeTypeToString, updateTopPathInfo } from '../module/Utils' -import { LogInfo, LogDebug } from '../../../../../../common/LogUtils' -import { menuLevel, pad_size } from '../module/Constants' -import { DisplayInfo } from '../module/DisplayInfo' -import { getListFile } from '../module/FileManagerServiceUtils' +import { PadSize } from '../module/Constants' +import { MediaName, MenuLevel } from '../../../../../../common/src/main/ets/components/Data/Constants' +import { FileInfo } from '../../../../../../common/src/main/ets/components/Data/FileInfo' +import { getListFile } from '../../../../../../common/src/main/ets/components/Utils/FileManagerServiceUtils' +import { logDebug, logInfo } from '../../../../../../common/src/main/ets/components/Utils/LogUtils' +import { changeTypeToString, updateTopPathInfo } from '../../../../../../common/src/main/ets/components/utils/Utils' let TAG: string = 'SecondLevelByFold' @Component export struct SecondLevelByFold { - private mWorker - private displayInfo: DisplayInfo = new DisplayInfo() + private mWorker + @Link mFileList: FileInfo[] + @Link @Watch('fileTypeChange') mType: string + @Link mMenuLevel: number + @Link mCurrentPath: string - @Link mFileList: FileInfo[] - @Link @Watch('fileTypeChange') mType: string - @Link mMenuLevel: number - @Link mCurrentPath: string - - private aboutToAppear(): void{ - LogInfo(TAG, 'aboutToAppear') - this.displayInfo = AppStorage.Get('displayInfo') - - if (globalThis.debugMode) { - this.mFileList = getListFile('local', this.mType, this.mCurrentPath) - LogDebug(TAG, 'mFileList length = ' + this.mFileList.length) - } else { - LogInfo(TAG, 'aboutToAppear send message to worker') - this.mWorker.postMessage({ - request_data: 'listFile', - device_name: 'local', - menu_level: this.mMenuLevel, - media_type: this.mType, - path: this.mCurrentPath - }) - } - - updateTopPathInfo([], '文件类型', '') - updateTopPathInfo(AppStorage.Get('topPathInfo'), changeTypeToString(this.mType), this.mCurrentPath) - } - - fileTypeChange() { - LogInfo(TAG, 'fileTypeChange ' + this.mType) - if (globalThis.debugMode) { - this.mFileList = getListFile('local', this.mType, this.mCurrentPath) - } else { - LogInfo(TAG, 'fileTypeChange send message to worker') - this.mWorker.postMessage({ - request_data: 'listFile', - device_name: 'local', - menu_level: this.mMenuLevel, - media_type: this.mType, - path: this.mCurrentPath - }) - } - } - - build() { - if (globalThis.startMode == 'choose') { - Grid() { - ForEach(this.mFileList, fileItem => { - GridItem() { - Column() { - Image($r("app.media.ic_public_big_folder")) - .width(pad_size.EIGHTY) - .height(pad_size.EIGHTY) - .margin({ left: pad_size.TWELVE, top: pad_size.FOUR, right: pad_size.TWELVE }) - Row() { - Text(fileItem.name) - .width(pad_size.EIGHTY_EIGHT) - .fontSize(pad_size.FOURTEEN) - .fontWeight(FontWeight.Regular) - .fontColor('#000000') - .textAlign(TextAlign.Center) - .maxLines(pad_size.TWO) - .margin({ top: pad_size.FOUR, left: pad_size.FOUR, right: pad_size.FOUR }) - } - .alignItems(VerticalAlign.Top) - .width(pad_size.NINETY_SIX) - .height(pad_size.FORTY_SIX) - } - .width(pad_size.ONE_HUNDRED_AND_FOUR) - .height(pad_size.ONE_HUNDRED_AND_THIRTY_FOUR) - .alignItems(HorizontalAlign.Center) - } - .onClick(() => { - this.mCurrentPath = fileItem.path - LogInfo(TAG, 'fileItem.mediaType = ' + fileItem.mediaType) - if (fileItem.mediaType == 'file') { - this.mMenuLevel = menuLevel.MENU_THIRD_LEVEL_HAS_DETAIL - } else { - this.mMenuLevel = menuLevel.MENU_THIRD_LEVEL_HAS_PIC - } - updateTopPathInfo(AppStorage.Get('topPathInfo'), fileItem.name, fileItem.mCurrentPath) - }) - }, fileItem => fileItem.name) - } - .columnsTemplate('1fr 1fr 1fr 1fr') - .columnsGap(1) - .rowsGap(1) - .margin({ top: pad_size.SIXTEEN }) - } - } -} - -@Component -struct SecondRowView { - private item: FileInfo = new FileInfo('') - private displayInfo: DisplayInfo = AppStorage.Get('displayInfo') - - @Link mMenuLevel: number - @Link mCurrentPath: string - - build() { - Row() { - Image($r("app.media.ic_file_manager")) - .width(22 * 2) - .height(19 * 2) - .margin({ left: 12 }) - Text(this.item.name) - .fontSize(16 * 2) - .fontColor('#182431') - .fontWeight(FontWeight.Medium) - .margin({ left: 16 }) - Blank() - Image($r("app.media.ic_right")) - .width(12 * 2) - .height(24 * 2) - .margin({ right: 24 * 2 }) - } - .height(56) - .width(px2vp(this.displayInfo.mainDialogWidth)) // TODO - .margin({ top: '16vp', bottom: '16vp' }) - .backgroundColor(this.item.list_background) - .onClick(() => { - LogInfo(TAG, 'onClick this.mCurrentPath = ' + this.mCurrentPath) - this.mCurrentPath = this.item.path - let path: Array = AppStorage.Get('topPathInfo') - path.push(new TopPathInfo(this.item.name, this.mCurrentPath)) - AppStorage.Set('topPathInfo', path) - - if (this.item.path.includes('dataability:///album') == false) { - if (this.item.mediaType != 'file') { - LogInfo(TAG, 'MENU_THIRD_LEVEL_HAS_PIC - onClick') - this.mMenuLevel = menuLevel.MENU_THIRD_LEVEL_HAS_PIC + aboutToAppear(): void{ + logInfo(TAG, 'aboutToAppear') + if (globalThis.debugMode) { + this.mFileList = getListFile('local', this.mType, this.mCurrentPath) + logDebug(TAG, 'mFileList length = ' + this.mFileList.length) } else { - this.mMenuLevel = menuLevel.MENU_THIRD_LEVEL_HAS_DETAIL - LogInfo(TAG, 'MENU_THIRD_LEVEL_HAS_DETAIL - onClick') + this.mWorker.postMessage({ + request_data: 'listFile', + device_name: 'local', + menu_level: this.mMenuLevel, + MediaType: this.mType, + path: this.mCurrentPath + }) } - } - }) - } + + updateTopPathInfo([], '文件类型', '') + updateTopPathInfo(AppStorage.Get('topPathInfo'), changeTypeToString(this.mType), this.mCurrentPath) + } + + fileTypeChange() { + logInfo(TAG, 'fileTypeChange ' + this.mType) + if (globalThis.debugMode) { + this.mFileList = getListFile('local', this.mType, this.mCurrentPath) + } else { + this.mWorker.postMessage({ + request_data: 'listFile', + device_name: 'local', + menu_level: this.mMenuLevel, + MediaType: this.mType, + path: this.mCurrentPath + }) + } + } + + build() { + if (globalThis.startMode == 'choose') { + Grid() { + ForEach(this.mFileList, fileItem => { + GridItem() { + Column() { + Image($r("app.media.ic_public_big_folder")) + .width(PadSize.EIGHTY) + .height(PadSize.EIGHTY) + .margin({ + left: PadSize.TWELVE, + right: PadSize.TWELVE, + top: PadSize.FOUR, + bottom: PadSize.TWO + }) + Row() { + Text(fileItem.name) + .width(PadSize.EIGHTY_EIGHT) + .fontSize(PadSize.FOURTEEN) + .fontWeight(FontWeight.Regular) + .fontColor('#000000') + .textAlign(TextAlign.Center) + .maxLines(PadSize.TWO) + .margin(PadSize.FOUR) + } + .alignItems(VerticalAlign.Top) + .width(PadSize.NINETY_SIX) + .height(PadSize.FORTY_SIX) + .margin({ left: PadSize.FOUR, right: PadSize.FOUR, bottom: PadSize.FOUR }) + } + .width(PadSize.ONE_HUNDRED_AND_FOUR) + .height(PadSize.ONE_HUNDRED_AND_THIRTY_SIX) + .margin({ left: PadSize.SIXTEEN, right: PadSize.EIGHT, bottom: PadSize.TWENTY }) + .alignItems(HorizontalAlign.Center) + } + .onClick(() => { + this.mCurrentPath = fileItem.path + logInfo(TAG, 'fileItem.mediaType = ' + fileItem.mediaType) + if (fileItem.mediaType == MediaName.FILE) { + this.mMenuLevel = MenuLevel.MENU_THIRD_LEVEL_HAS_DETAIL + } else { + this.mMenuLevel = MenuLevel.MENU_THIRD_LEVEL_HAS_PIC + } + updateTopPathInfo(AppStorage.Get('topPathInfo'), fileItem.name, fileItem.mCurrentPath) + }) + }, fileItem => fileItem.name) + } + .width(PadSize.GRID_WIDTH) + .columnsTemplate('1fr 1fr 1fr 1fr') + .columnsGap(1) + .rowsGap(1) + .margin({ top: PadSize.SIXTEEN }) + } + } } \ No newline at end of file diff --git a/product/pad/src/main/ets/pages/ThirdLevelHasDetail.ets b/product/pad/src/main/ets/pages/ThirdLevelHasDetail.ets index 0e002b0..dd10cd7 100644 --- a/product/pad/src/main/ets/pages/ThirdLevelHasDetail.ets +++ b/product/pad/src/main/ets/pages/ThirdLevelHasDetail.ets @@ -13,192 +13,199 @@ * limitations under the License. */ -import { FileInfo } from '../../../../../../feature/FileInfo' -import { LogInfo } from '../../../../../../common/LogUtils' -import { getShowIconBySuffix, updateTopPathInfo } from '../module/Utils' -import { media_type, pad_size } from '../module/Constants' -import { ChooseDialog } from '../module/DialogUtils' -import { DisplayInfo } from '../module/DisplayInfo' -import { getListFile } from '../module/FileManagerServiceUtils' +import { MediaType } from '../../../../../../common/src/main/ets/components/Data/Constants' +import { FileInfo } from '../../../../../../common/src/main/ets/components/Data/FileInfo' +import { logInfo } from '../../../../../../common/src/main/ets/components/Utils/LogUtils' +import { getListFile } from '../../../../../../common/src/main/ets/components/Utils/FileManagerServiceUtils' +import { getShowIconBySuffix, updateTopPathInfo } from '../../../../../../common/src/main/ets/components/utils/utils' +import { ChooseDialog } from '../../../../../../common/src/main/ets/components/View/ChooseDialog' +import { PadSize } from '../module/Constants' @Component export struct ThirdLevelHasDetail { - private TAG: string = 'ThirdLevelHasDetail' - private mWorker - private displayInfo: DisplayInfo = new DisplayInfo() + private TAG: string = 'ThirdLevelHasDetail' + private mWorker + @Link mFileInfo: Array + @Link @Watch('refreshFiles') mCurrentPath: string + @Link mMenuLevel: number + @Link mType: string - @Link mFileInfo: Array - @Link @Watch('refreshFiles') mCurrentPath: string - @Link mMenuLevel: number - @Link mType: string - - private aboutToAppear(): void{ - LogInfo(this.TAG, 'aboutToAppear') - this.displayInfo = AppStorage.Get('displayInfo') - - if (globalThis.debugMode) { - this.mFileInfo = getListFile('local', this.mType, this.mCurrentPath) - } else { - this.mWorker.postMessage({ - request_data: 'listFile', - device_name: 'local', - menu_level: this.mMenuLevel, - media_type: this.mType, - path: this.mCurrentPath - }) - } - } - - private aboutToDisappear() { - LogInfo(this.TAG, 'aboutToDisappear') - AppStorage.Set('choseFiles', []) - } - - refreshFiles() { - LogInfo(this.TAG, 'refreshFiles') - AppStorage.Set('choseFiles', []) - - if (!globalThis.debugMode) { - this.mWorker.postMessage({ - request_data: 'listFile', - device_name: 'local', - menu_level: this.mMenuLevel, - media_type: this.mType, - path: this.mCurrentPath - }) - } - } - - build() { - Column() { - List() { - ForEach(this.mFileInfo, (item: FileInfo) => { - ListItem() { - DetailRowView({ - item: item, - mMenuLevel: $mMenuLevel, - mCurrentPath: $mCurrentPath + private aboutToAppear(): void{ + logInfo(this.TAG, 'aboutToAppear') + if (globalThis.debugMode) { + this.mFileInfo = getListFile('local', this.mType, this.mCurrentPath) + } else { + this.mWorker.postMessage({ + request_data: 'listFile', + device_name: 'local', + menu_level: this.mMenuLevel, + MediaType: this.mType, + path: this.mCurrentPath }) - } - }, (item: FileInfo) => item.name) - }.align(Alignment.Top) + } + } + + private aboutToDisappear() { + logInfo(this.TAG, 'aboutToDisappear') + AppStorage.Set('choseFiles', []) + } + + refreshFiles() { + logInfo(this.TAG, 'refreshFiles') + AppStorage.Set('choseFiles', []) + if (!globalThis.debugMode) { + this.mWorker.postMessage({ + request_data: 'listFile', + device_name: 'local', + menu_level: this.mMenuLevel, + MediaType: this.mType, + path: this.mCurrentPath + }) + } + } + + build() { + Column() { + List() { + ForEach(this.mFileInfo, (item: FileInfo) => { + ListItem() { + DetailRowView({ + listItem: item, + mMenuLevel: $mMenuLevel, + mCurrentPath: $mCurrentPath + }) + } + }, (item: FileInfo) => item.name) + }.align(Alignment.Top) + } + .height(PadSize.TWO_HUNDRED_AND_SIXTY) + .alignItems(HorizontalAlign.Start) + .opacity(0.9) + .backgroundColor(Color.White) + .border({ radius: PadSize.TWENTY_FOUR }) + .margin({ top: PadSize.SIXTEEN }) } - .height(pad_size.TWO_HUNDRED_AND_SIXTY) - .alignItems(HorizontalAlign.Start) - .opacity(0.9) - .backgroundColor(Color.White) - .border({ radius: pad_size.TWENTY_FOUR }) - .margin({ top: pad_size.SIXTEEN }) - } } @Component struct DetailRowView { - private TAG: string = 'DetailRowView' - private displayInfo: DisplayInfo = AppStorage.Get('displayInfo') - private dialogController: CustomDialogController = new CustomDialogController({ - builder: ChooseDialog(), - cancel: () => {}, - autoCancel: true - }) - - @State item: FileInfo = new FileInfo('') - @Link mCurrentPath: string - @Link mMenuLevel: number - @StorageLink('choseFiles') tmpChoseFiles: Array = [] - - build() { - Row() { - if (this.item.type == media_type.MEDIA_TYPE_ALBUM) { - Image($r("app.media.ic_file_fold")) - .width(pad_size.FORTY) - .height(pad_size.FORTY) - .margin({ left: pad_size.TWELVE }) - Text(this.item.name) - .fontSize(pad_size.SIXTEEN) - .fontColor('#182431') - .fontWeight(FontWeight.Medium) - .margin({ left: pad_size.SIXTEEN }) - .maxLines(pad_size.ONE) - .textOverflow({ overflow: TextOverflow.Ellipsis }) - Blank() - Image($r("app.media.ic_right")) - .width(pad_size.TWELVE) - .height(pad_size.TWENTY_FOUR) - .margin({ right: pad_size.TWENTY_FOUR }) - } else { - Image(getShowIconBySuffix(this.item.name.substring(this.item.name.lastIndexOf('.')))) - .width(pad_size.FORTY) - .height(pad_size.FORTY) - .margin({ left: pad_size.EIGHT }) - Column() { - Text(this.item.name) - .height(pad_size.TWENTY_TWO) - .fontSize(pad_size.SIXTEEN) - .fontWeight(FontWeight.Medium) - .fontColor(this.item.font_color) - .maxLines(1) - .textOverflow({ overflow: TextOverflow.Ellipsis }) - .margin({ top: pad_size.TEN }) - Row() { - Text('' + this.item.modified_time) - .fontSize(pad_size.FOURTEEN) - .fontWeight(FontWeight.Regular) - .fontColor(this.item.font_color) - .maxLines(pad_size.ONE) - .textOverflow({ overflow: TextOverflow.Ellipsis }) - Text('-') - .fontSize(pad_size.FOURTEEN) - .fontColor(this.item.font_color) - .margin({ left: pad_size.EIGHT }) - Text('' + this.item.size) - .fontSize(pad_size.FOURTEEN) - .fontWeight(FontWeight.Regular) - .fontColor(this.item.font_color) - .margin({ left: pad_size.EIGHT }) - .maxLines(pad_size.ONE) - .textOverflow({ overflow: TextOverflow.Ellipsis }) - } - .opacity(0.6) - .height(pad_size.NINETEEN) - .margin({ top: pad_size.TWO, bottom: pad_size.ELEVEN }) - } - .alignItems(HorizontalAlign.Start) - .margin({ left: pad_size.SIXTEEN }) - } - } - .width(pad_size.FIVE_HUNDRED_AND_FOUR) // TODO - .height(pad_size.SIXTY_FOUR) - .margin({ left: pad_size.SIXTEEN, right: pad_size.TWENTY_FOUR, bottom: pad_size.TWO }) - .border({ radius: pad_size.TWENTY }) - .backgroundColor(this.item.list_background) - .onClick(() => { - if (this.item.type == media_type.MEDIA_TYPE_ALBUM) { - this.mCurrentPath = this.item.path - updateTopPathInfo(AppStorage.Get('topPathInfo'), this.item.name, this.item.path) - } else { - var index = this.tmpChoseFiles.indexOf(this.item) - if (index == -1) { - this.item.opacity = 0.1 - this.item.font_color = Color.White - this.item.list_background = '#0A59F7' - this.tmpChoseFiles.push(this.item) - } else { - this.item.opacity = 1 - this.item.font_color = Color.Black - this.item.list_background = '' - this.tmpChoseFiles.splice(index, 1) - } - } + private TAG: string = 'DetailRowView' + private dialogController: CustomDialogController = new CustomDialogController({ + builder: ChooseDialog(), + cancel: () => { + }, + autoCancel: true }) - .gesture( - LongPressGesture({ repeat: false }) - .onAction((event: GestureEvent) => { - if (this.item.type != media_type.MEDIA_TYPE_ALBUM) { - AppStorage.SetOrCreate('selectedFileInfo', this.item) - this.dialogController.open() - } + @State listItem: FileInfo = new FileInfo('') + @Link mCurrentPath: string + @Link mMenuLevel: number + @StorageLink('choseFiles') @Watch('choseFilesChange') choseFiles: Array = [] + + private choseFilesChange() { + this.choseFiles.forEach((item: FileInfo) => { + logInfo(this.TAG, 'choseFilesChange item.name = ' + item.name + ' gridItem.name = ' + this.listItem.name) + logInfo(this.TAG, 'choseFilesChange item.path = ' + item.path + ' gridItem.path = ' + this.listItem.path) + if (item.name == this.listItem.name && item.path == this.listItem.path) { + this.listItem.list_background = '#19007DFF' + } else { + this.listItem.list_background = '' + } + }) - ) - } + } + + build() { + Stack() { + Divider() + .vertical(false) + .color("#0C000000") + .margin({ left: PadSize.EIGHTY, top: PadSize.SIXTY_FOUR, right: PadSize.TWENTY_FOUR }) + Row() { + if (this.listItem.type == MediaType.MEDIA_TYPE_ALBUM) { + Image($r("app.media.ic_file_fold")) + .width(PadSize.FORTY) + .height(PadSize.FORTY) + .margin({ left: PadSize.EIGHT }) + Text(this.listItem.name) + .fontSize(PadSize.SIXTEEN) + .fontColor('#182431') + .fontWeight(FontWeight.Medium) + .margin({ left: PadSize.SIXTEEN }) + .maxLines(PadSize.ONE) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + Blank() + Image($r("app.media.ic_right")) + .width(PadSize.TWELVE) + .height(PadSize.TWENTY_FOUR) + } else { + Image(getShowIconBySuffix(this.listItem.name.substring(this.listItem.name.lastIndexOf('.')))) + .width(PadSize.FORTY) + .height(PadSize.FORTY) + .margin({ left: PadSize.EIGHT }) + Column() { + Text(this.listItem.name) + .height(PadSize.TWENTY_TWO) + .fontSize(PadSize.SIXTEEN) + .fontWeight(FontWeight.Medium) + .fontColor(this.listItem.font_color) + .maxLines(1) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + .margin({ top: PadSize.TEN }) + Row() { + Text('' + this.listItem.modified_time) + .fontSize(PadSize.FOURTEEN) + .fontWeight(FontWeight.Regular) + .fontColor(this.listItem.font_color) + .maxLines(PadSize.ONE) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + Text('-') + .fontSize(PadSize.FOURTEEN) + .fontColor(this.listItem.font_color) + .margin({ left: PadSize.EIGHT }) + Text('' + this.listItem.size) + .fontSize(PadSize.FOURTEEN) + .fontWeight(FontWeight.Regular) + .fontColor(this.listItem.font_color) + .margin({ left: PadSize.EIGHT }) + .maxLines(PadSize.ONE) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + } + .opacity(0.6) + .height(PadSize.NINETEEN) + .margin({ top: PadSize.TWO, bottom: PadSize.ELEVEN }) + } + .alignItems(HorizontalAlign.Start) + .margin({ left: PadSize.SIXTEEN }) + } + } + .width(PadSize.FIVE_HUNDRED_AND_FOUR) // TODO + .height(PadSize.SIXTY_FOUR) + .margin({ left: PadSize.SIXTEEN, right: PadSize.TWENTY_FOUR, bottom: PadSize.ONE }) + .border({ radius: PadSize.TWENTY }) + .backgroundColor(this.listItem.list_background) + .onClick(() => { + if (this.listItem.type == MediaType.MEDIA_TYPE_ALBUM) { + this.mCurrentPath = this.listItem.path + updateTopPathInfo(AppStorage.Get('topPathInfo'), this.listItem.name, this.listItem.path) + } else { + var index = this.choseFiles.indexOf(this.listItem) + this.choseFiles.splice(0, this.choseFiles.length) + if (index == -1) { + this.listItem.list_background = '#19007DFF' + this.choseFiles.push(this.listItem) + } else { + this.listItem.list_background = '' + } + } + }) + .gesture(LongPressGesture({ repeat: false }) + .onAction((event: GestureEvent) => { + if (this.listItem.type != MediaType.MEDIA_TYPE_ALBUM) { + AppStorage.SetOrCreate('selectedFileInfo', this.listItem) + this.dialogController.open() + } + }) + ) + } + } } \ No newline at end of file diff --git a/product/pad/src/main/ets/pages/ThirdLevelHasPic.ets b/product/pad/src/main/ets/pages/ThirdLevelHasPic.ets index e03fca3..596bff1 100644 --- a/product/pad/src/main/ets/pages/ThirdLevelHasPic.ets +++ b/product/pad/src/main/ets/pages/ThirdLevelHasPic.ets @@ -13,169 +13,167 @@ * limitations under the License. */ -import { FileInfo } from '../../../../../../feature/FileInfo' -import { LogInfo, LogDebug } from '../../../../../../common/LogUtils' -import { pad_size } from '../module/Constants' -import { getListFile } from '../module/FileManagerServiceUtils' -import { ChooseDialog } from '../module/DialogUtils' -import { DisplayInfo } from '../module/DisplayInfo' +import { FileInfo } from '../../../../../../common/src/main/ets/components/Data/FileInfo' +import { getListFile } from '../../../../../../common/src/main/ets/components/Utils/FileManagerServiceUtils' +import { logDebug, logInfo } from '../../../../../../common/src/main/ets/components/Utils/LogUtils' +import { ChooseDialog } from '../../../../../../common/src/main/ets/components/View/ChooseDialog' +import { PadSize } from '../module/Constants' let TAG: string = 'ThirdLevelHasPic' @Component export struct ThirdLevelHasPic { - private mWorker - private mColumnTemplate: string - private mCurrentIndex: number - private displayInfo: DisplayInfo = new DisplayInfo() + private mWorker + private mColumnTemplate: string + private mCurrentIndex: number + @Link mFileList: Array + @Link mMenuLevel: number + @Link mType: string + @Link mCurrentPath: string - @Link mFileList: Array - @Link mMenuLevel: number - @Link mType: string - @Link mCurrentPath: string - - private aboutToAppear() { - LogInfo(TAG, 'aboutToAppear') - this.displayInfo = AppStorage.Get('displayInfo') - - if (globalThis.debugMode) { - this.mFileList = getListFile('local', this.mType, this.mCurrentPath) - LogDebug(TAG, 'mFileList length = ' + this.mFileList.length) - } else { - LogInfo(TAG, 'aboutToAppear send message to worker') - this.mWorker.postMessage({ - request_data: 'listFile', - device_name: 'local', - menu_level: this.mMenuLevel, - media_type: this.mType, - path: this.mCurrentPath, - offset: 0, - count: 100 - }) - } - } - - private aboutToDisappear() { - LogInfo(TAG, 'aboutToDisappear') - AppStorage.Set('choseFiles', []) - } - - build() { - if (globalThis.startMode == 'choose') { - Column() { - Grid() { - ForEach(this.mFileList, (item: FileInfo) => { - GridItem() { - GridItemView({ gridItem: item }) - } - }, item => item.name) + aboutToAppear() { + logInfo(TAG, 'aboutToAppear send message to worker') + if (globalThis.debugMode) { + this.mFileList = getListFile('local', this.mType, this.mCurrentPath) + logDebug(TAG, 'mFileList length = ' + this.mFileList.length) + } else { + this.mWorker.postMessage({ + request_data: 'listFile', + device_name: 'local', + menu_level: this.mMenuLevel, + MediaType: this.mType, + path: this.mCurrentPath, + offset: 0, + count: 100 + }) + } + } + + private aboutToDisappear() { + logInfo(TAG, 'aboutToDisappear') + AppStorage.Set('choseFiles', []) + } + + build() { + if (globalThis.startMode == 'choose') { + Column() { + Grid() { + ForEach(this.mFileList, (item: FileInfo) => { + GridItem() { + GridItemView({ gridItem: item }) + } + }, item => item.name) + } + .columnsTemplate('1fr 1fr 1fr 1fr') + + } + .width(PadSize.GRID_WIDTH) + .alignItems(HorizontalAlign.Start) + .border({ radius: PadSize.TWENTY_FOUR }) + .opacity(0.9) + .backgroundColor(Color.White) + .margin({ top: PadSize.SIXTEEN }) } - //.height(300) - //.height(this.displayInfo.mainDialogHeight - (48 * 2)) - .columnsTemplate('1fr 1fr 1fr 1fr') - // .height(px2vp(this.displayInfo.mainDialogHeight)) // 必须参数 - // .columnsTemplate(this.mColumnTemplate) - - } - .alignItems(HorizontalAlign.Start) - .border({ radius: pad_size.TWENTY_FOUR }) - .opacity(0.9) - .backgroundColor(Color.White) - .margin({ top: pad_size.SIXTEEN }) } - } } @Component struct GridItemView { - private dialogController: CustomDialogController = new CustomDialogController({ - builder: ChooseDialog(), - cancel: () => {}, - autoCancel: true - }) - @State gridItem: FileInfo = new FileInfo('') - @StorageLink('choseFiles') @Watch('choseFilesChange') choseFiles: Array = [] - - private choseFilesChange() { - this.choseFiles.forEach((item: FileInfo) => { - LogInfo(TAG, 'choseFilesChange item.name = ' + item.name + ' gridItem.name = ' + this.gridItem.name) - LogInfo(TAG, 'choseFilesChange item.path = ' + item.path + ' gridItem.path = ' + this.gridItem.path) - if (item.name == this.gridItem.name && item.path == this.gridItem.path) { - this.gridItem.opacity = 1 - this.gridItem.font_color = Color.White - this.gridItem.list_background = '#2E88FF' - return; - } + private dialogController: CustomDialogController = new CustomDialogController({ + builder: ChooseDialog(), + cancel: () => { + }, + autoCancel: true }) - } + @State gridItem: FileInfo = new FileInfo('') + @StorageLink('choseFiles') @Watch('choseFilesChange') choseFiles: Array = [] - build() { - Flex({ - direction: FlexDirection.Column, - alignItems: ItemAlign.Center, - justifyContent: FlexAlign.Center - }) { - Image(`${this.gridItem.path}/thumbnail/${pad_size.EIGHTY_TWO}/${pad_size.EIGHTY_TWO}`) - .objectFit(ImageFit.Contain) - .width(pad_size.EIGHTY_TWO) - .height(pad_size.EIGHTY_TWO) - .margin({ - left: pad_size.ELEVEN, - right: pad_size.ELEVEN, - top: pad_size.FOUR, - bottom: pad_size.TWO + private choseFilesChange() { + this.choseFiles.forEach((item: FileInfo) => { + logInfo(TAG, 'choseFilesChange item.name = ' + item.name + ' gridItem.name = ' + this.gridItem.name) + logInfo(TAG, 'choseFilesChange item.path = ' + item.path + ' gridItem.path = ' + this.gridItem.path) + if (item.name == this.gridItem.name && item.path == this.gridItem.path) { + this.gridItem.font_color = Color.White + this.gridItem.list_background = '#19007DFF' + this.gridItem.textBackground = "#007DFF" + return; + } else { + this.gridItem.font_color = Color.Black + this.gridItem.list_background = '' + this.gridItem.textBackground = "" + } }) - - Row() { - Text(this.gridItem.name) - .width(pad_size.EIGHTY_EIGHT) - .fontSize(pad_size.FOURTEEN) - .fontColor(this.gridItem.font_color) - .fontWeight(FontWeight.Regular) - .maxLines(2) - .opacity(0.9) - .textAlign(TextAlign.Center) - .textOverflow({ overflow: TextOverflow.Ellipsis }) - .margin({ top: pad_size.FOUR }) - } - .alignItems(VerticalAlign.Top) - .width(pad_size.NINETY_SIX) - .height(pad_size.FORTY_SIX) - .margin({ left: pad_size.FOUR, right: pad_size.FOUR, bottom: pad_size.FOUR }) } - .width(pad_size.ONE_HUNDRED_AND_FOUR) - .height(pad_size.ONE_HUNDRED_AND_THIRTY_FOUR) - .margin({ bottom: pad_size.SIXTEEN }) - .border({ radius: pad_size.TWELVE }) - .opacity(this.gridItem.opacity) - .backgroundColor(this.gridItem.list_background) - .gesture( - LongPressGesture({ repeat: false }) - .onAction((event: GestureEvent) => { - AppStorage.SetOrCreate('selectedFileInfo', this.gridItem) - this.dialogController.open() - }) - ) - .onClick(() => { - let choseFiles: Array = AppStorage.Get('choseFiles') - let index: number = -1 - choseFiles.forEach((item: FileInfo) => { - if (item.name == this.gridItem.name && item.path == this.gridItem.path) { - index = choseFiles.indexOf(item) - } - }) - if (index == -1) { - this.gridItem.opacity = 1 - this.gridItem.font_color = Color.White - this.gridItem.list_background = '#2E88FF' - choseFiles.push(this.gridItem) - } else { - choseFiles.splice(index, 1) - this.gridItem.opacity = 1 - this.gridItem.font_color = Color.Black - this.gridItem.list_background = '' - } - }) - } + build() { + Flex({ + direction: FlexDirection.Column, + alignItems: ItemAlign.Center, + justifyContent: FlexAlign.Center + }) { + Image(`${this.gridItem.path}/thumbnail/${PadSize.EIGHTY}/${PadSize.EIGHTY}`) + .objectFit(ImageFit.Contain) + .width(PadSize.EIGHTY) + .height(PadSize.EIGHTY) + .margin({ + left: PadSize.TWELVE, + right: PadSize.TWELVE, + top: PadSize.FOUR, + bottom: PadSize.TWO + }) + .border({ radius: PadSize.TWELVE, width: 0, style: BorderStyle.Solid }) + + Row() { + Text(this.gridItem.name) + .width(PadSize.EIGHTY_EIGHT) + .fontSize(PadSize.FOURTEEN) + .fontColor(this.gridItem.font_color) + .fontWeight(FontWeight.Regular) + .maxLines(2) + .opacity(0.9) + .textAlign(TextAlign.Center) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + .margin(PadSize.FOUR) + } + .alignItems(VerticalAlign.Top) + .width(PadSize.NINETY_SIX) + .height(PadSize.FORTY_SIX) + .margin({ left: PadSize.FOUR, right: PadSize.FOUR, bottom: PadSize.FOUR }) + .border({ radius: PadSize.TWELVE, width: 0, style: BorderStyle.Solid }) + .backgroundColor(this.gridItem.textBackground) + } + .width(PadSize.ONE_HUNDRED_AND_FOUR) + .height(PadSize.ONE_HUNDRED_AND_THIRTY_SIX) + .margin({ left: PadSize.SIXTEEN, right: PadSize.EIGHT, bottom: PadSize.TWENTY }) + .border({ radius: PadSize.TWELVE }) + .opacity(this.gridItem.opacity) + .backgroundColor(this.gridItem.list_background) + .gesture( + LongPressGesture({ repeat: false }) + .onAction((event: GestureEvent) => { + AppStorage.SetOrCreate('selectedFileInfo', this.gridItem) + this.dialogController.open() + }) + ) + .onClick(() => { + let choseFiles: Array = AppStorage.Get('choseFiles') + let index: number = -1 + choseFiles.forEach((item: FileInfo) => { + if (item.name == this.gridItem.name && item.path == this.gridItem.path) { + index = choseFiles.indexOf(item) + } + }) + choseFiles.splice(0, choseFiles.length) + if (index == -1) { + this.gridItem.font_color = Color.White + this.gridItem.list_background = '#19007DFF' + this.gridItem.textBackground = "#007DFF" + choseFiles.push(this.gridItem) + } else { + this.gridItem.font_color = Color.Black + this.gridItem.list_background = '' + this.gridItem.textBackground = "" + } + }) + } } \ No newline at end of file diff --git a/product/pad/src/main/ets/pages/index.ets b/product/pad/src/main/ets/pages/index.ets index ed56fbf..1ce9faf 100644 --- a/product/pad/src/main/ets/pages/index.ets +++ b/product/pad/src/main/ets/pages/index.ets @@ -19,575 +19,598 @@ import { FirstLevelByType } from './FirstLevelByType' import { SecondLevelByFold } from './SecondLevelByFold' import { ThirdLevelHasDetail } from '../pages/ThirdLevelHasDetail' import { ThirdLevelHasPic } from '../pages/ThirdLevelHasPic' -import { menuLevel, terminate_reason, media_type, pad_size, mediaName } from '../module/Constants' -import { changeStringToType, changeTypeToString, updateTopPathInfo } from '../module/Utils' -import { terminateSelfWithResult } from '../module/AbilityUtils' -import { WarningDialog } from '../module/DialogUtils' -import { LogInfo, LogDebug } from '../../../../../../common/LogUtils' -import { FileInfo, TopPathInfo } from '../../../../../../feature/FileInfo' -import { getFirstMenu } from '../module/FileManagerServiceUtils' +import { PadSize } from '../module/Constants' +import { MenuLevel, TerminateReason, MediaType, MediaName +} from '../../../../../../common/src/main/ets/components/Data/Constants' +import { FileInfo } from '../../../../../../common/src/main/ets/components/Data/FileInfo' +import { TopPathInfo } from '../../../../../../common/src/main/ets/components/Data/TopPathInfo' +import { terminateSelfWithResult } from '../../../../../../common/src/main/ets/components/utils/AbilityUtils' +import { getFirstMenu } from '../../../../../../common/src/main/ets/components/Utils/FileManagerServiceUtils' +import { logInfo, logDebug, logError } from '../../../../../../common/src/main/ets/components/Utils/LogUtils' +import { changeStringToType, changeTypeToString, updateTopPathInfo +} from '../../../../../../common/src/main/ets/components/utils/Utils' +import { WarningDialog } from '../../../../../../common/src/main/ets/components/View/WarningDialog' @Entry @Component struct Index { - private TAG: string= 'Main' - private mWorker - private customDialogController: CustomDialogController = new CustomDialogController({ - builder: WarningDialog({code: $code}) - }) + private TAG: string= 'Main' + private mWorker + private customDialogController: CustomDialogController = new CustomDialogController({ + builder: WarningDialog({ code: $code }) + }) + @State mFirstMenuData: FileInfo[] = [] + @State mSecondMenuData: FileInfo[] = [] + @State mThirdMenuPicData: FileInfo[]= [] + @State mThirdMenuDetailData: FileInfo[]= [] + @State mType: string = '' + @State mMenuLevel: number = MenuLevel.MENU_FIRST_LEVEL_BY_TYPE + @State mCurrentPath: string= '' + @State code: number = 2; + @StorageLink('topPathInfo') topPathInfo: Array = updateTopPathInfo([], '文件类型', '') - @State mFirstMenuData: FileInfo[] = [] - @State mSecondMenuData: FileInfo[] = [] - @State mThirdMenuPicData: FileInfo[]= [] - @State mThirdMenuDetailData: FileInfo[]= [] - @State mType: string = '' - @State mMenuLevel: number = menuLevel.MENU_FIRST_LEVEL_BY_TYPE - @State mCurrentPath: string= '' - @State code: number = 2; - @StorageLink('topPathInfo') topPathInfo: Array = updateTopPathInfo([], '文件类型', '') - - aboutToAppear() { - LogInfo(this.TAG, 'aboutToAppear') - if (globalThis.debugMode) { - this.mFirstMenuData = getFirstMenu('') - LogDebug(this.TAG, 'mFirstMenuData length = ' + this.mFirstMenuData.length) - } else { - this.initWorker() - LogInfo(this.TAG, 'send message to worker') - this.mWorker.postMessage({ - request_data: 'getRoot', - device_name: 'local', - menu_level: this.mMenuLevel, - media_type: this.mType, - path: this.mCurrentPath - }) - } - } - - private initWorker() { - if (this.mWorker == undefined) { - LogInfo(this.TAG, 'initWorker') - this.mWorker = new worker.Worker('pad/ets/workers/DataWorker.js', { type: 'classic', name: 'filePicker' }) - this.mWorker.onerror = this.onError.bind(this) - this.mWorker.onmessageerror = this.onMessageError.bind(this) - this.mWorker.onexit = this.onExit.bind(this) - this.mWorker.onmessage = this.onMessage.bind(this) - } - } - - private onError(e): void { - LogInfo(this.TAG, 'onError = ' + JSON.stringify(e)) - } - - private onMessageError(e): void { - LogInfo(this.TAG, 'onMessageError = ' + JSON.stringify(e)) - } - - private onExit(): void{ - LogInfo(this.TAG, 'onExit worker') - this.mWorker = undefined - } - - private onMessage(result) { - LogInfo(this.TAG, 'main thread onMessage') - var params = result.data.params - var file = JSON.parse(String.fromCharCode.apply(null, new Uint16Array(result.data.data))) - if (params.request_data == 'createFile') { - if (file.code == undefined) { - terminateSelfWithResult(terminate_reason.SUCCESS, file) - } else { - if (params.path == 'dataability:///album') { - this.code = 2; - this.customDialogController.open() + aboutToAppear() { + logInfo(this.TAG, 'aboutToAppear') + if (globalThis.debugMode) { + this.mFirstMenuData = getFirstMenu('') + logDebug(this.TAG, 'mFirstMenuData length = ' + this.mFirstMenuData.length) } else { - this.code = file.code - this.customDialogController.open() + this.initWorker() + logInfo(this.TAG, 'send message to worker') + this.mWorker.postMessage({ + request_data: 'getRoot', + device_name: 'local', + menu_level: this.mMenuLevel, + MediaType: this.mType, + path: this.mCurrentPath + }) } - } - return } - if (Array.isArray(file)) { - let listData: Array = [] - for (var index = 0; index < file.length; index++) { - var info = file[index] - let item = new FileInfo(info.name) - item.path = info.path - item.type = info.type - item.size = info.size - item.dataAdded_time = info.added_time - item.modified_time = info.modified_time - if (params.menu_level == menuLevel.MENU_FIRST_LEVEL_BY_TYPE) { - if (item.name == 'image_album') { - item.name = mediaName.IMAGE - item.mediaType = 'image' - item.thumbnail = $r("app.media.ic_type_image") - } else if (item.name == 'video_album') { - item.name = mediaName.VIDEO - item.mediaType = 'video' - item.thumbnail = $r("app.media.ic_type_video") - } else if (item.name == 'audio_album') { - item.name = mediaName.AUDIO - item.mediaType = 'audio' - item.thumbnail = $r("app.media.ic_type_audio") - } else if (item.name == 'file_folder') { - item.name = mediaName.DOCUMENT - item.mediaType = 'file' - item.thumbnail = $r("app.media.ic_public_file") - } - } - if (params.menu_level == menuLevel.MENU_THIRD_LEVEL_HAS_DETAIL) { - if (globalThis.startMode == 'save' && item.type != media_type.MEDIA_TYPE_ALBUM) { - break - } + private initWorker() { + if (this.mWorker == undefined) { + logInfo(this.TAG, 'initWorker') + this.mWorker = new worker.Worker('pad/ets/workers/DataWorker.js', { type: 'classic', name: 'filePicker' }) + this.mWorker.onerror = this.onError.bind(this) + this.mWorker.onmessageerror = this.onMessageError.bind(this) + this.mWorker.onexit = this.onExit.bind(this) + this.mWorker.onmessage = this.onMessage.bind(this) } - listData.push(item) - } - if (params.menu_level == menuLevel.MENU_FIRST_LEVEL_BY_TYPE && params.request_data == 'getRoot') { - LogDebug(this.TAG, 'mFirstMenuData length = ' + listData.length) - this.mFirstMenuData = listData - } else if (params.menu_level == menuLevel.MENU_SECOND_LEVEL_BY_FOLD) { - LogDebug(this.TAG, 'mSecondMenuData length = ' + listData.length) - this.mSecondMenuData = listData - } else if (params.menu_level == menuLevel.MENU_THIRD_LEVEL_HAS_PIC) { - LogDebug(this.TAG, 'mThirdMenuPicData length = ' + listData.length) - this.mThirdMenuPicData = listData - } else if (params.menu_level == menuLevel.MENU_THIRD_LEVEL_HAS_DETAIL) { - LogDebug(this.TAG, 'mThirdMenuDetailData length = ' + listData.length) - if (listData.length > 0) { - this.mThirdMenuDetailData = listData - } else { - this.mThirdMenuDetailData = [] - } - } } - } - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.Start }) { - Row() { - LeftDialogComponent({ - mType: $mType, - mMenuLevel: $mMenuLevel, - mCurrentPath: $mCurrentPath, - mFirstMenuData: $mFirstMenuData - }) + private onError(e): void { + logError(this.TAG, 'onError = ' + JSON.stringify(e)) + } - Column() { - Row() { - Row() { - Image($r("app.media.ic_public_back")) - .width(pad_size.TWENTY_FOUR) - .height(pad_size.TWENTY_FOUR) - .margin({ left: pad_size.TWENTY_FOUR }) - .onClick(() => { - if (this.mMenuLevel == menuLevel.MENU_SECOND_LEVEL_BY_FOLD) { - updateTopPathInfo([], '文件类型', '') - this.mMenuLevel = menuLevel.MENU_FIRST_LEVEL_BY_TYPE - this.mType = '' - } else if (this.mMenuLevel == menuLevel.MENU_THIRD_LEVEL_HAS_PIC || (this.mMenuLevel == menuLevel.MENU_THIRD_LEVEL_HAS_DETAIL)) { - this.topPathInfo.pop() - this.topPathInfo[this.topPathInfo.length - 1].opacity = 1 - if (this.topPathInfo.length > 1) { - var index = this.topPathInfo.length - 1 - this.mCurrentPath = this.topPathInfo[index].path - this.mMenuLevel = menuLevel.MENU_SECOND_LEVEL_BY_FOLD - } else { - this.mMenuLevel = menuLevel.MENU_FIRST_LEVEL_BY_TYPE - this.mType = '' + private onMessageError(e): void { + logError(this.TAG, 'onMessageError = ' + JSON.stringify(e)) + } + + private onExit(): void{ + logInfo(this.TAG, 'onExit worker') + this.mWorker = undefined + } + + private onMessage(result) { + logInfo(this.TAG, 'main thread onMessage') + var params = result.data.params + var file = JSON.parse(String.fromCharCode.apply(null, new Uint16Array(result.data.data))) + if (params.request_data == 'createFile') { + if (file.code == undefined) { + terminateSelfWithResult(TerminateReason.SUCCESS, file) + } else { + if (params.path == 'dataability:///album') { + this.code = 2; + this.customDialogController.open() + } else { + this.code = file.code + this.customDialogController.open() + } + } + return + } + if (Array.isArray(file)) { + let listData: Array = [] + for (var index = 0; index < file.length; index++) { + var info = file[index] + let item = new FileInfo(info.name) + item.path = info.path + item.type = info.type + item.size = info.size + item.dataAdded_time = info.added_time + item.modified_time = info.modified_time + if (params.menu_level == MenuLevel.MENU_FIRST_LEVEL_BY_TYPE) { + if (item.name == 'image_album') { + item.name = "图片" + item.mediaType = MediaName.IMAGE + item.thumbnail = $r("app.media.ic_type_image") + } else if (item.name == 'video_album') { + item.name = "视频" + item.mediaType = MediaName.VIDEO + item.thumbnail = $r("app.media.ic_type_video") + } else if (item.name == 'audio_album') { + item.name = "音乐" + item.mediaType = MediaName.AUDIO + item.thumbnail = $r("app.media.ic_type_audio") + } else if (item.name == 'file_folder') { + item.name = "文档" + item.mediaType = MediaName.FILE + item.thumbnail = $r("app.media.ic_public_file") } - } + } + + if (params.menu_level == MenuLevel.MENU_THIRD_LEVEL_HAS_DETAIL) { + if (globalThis.startMode == 'save' && item.type != MediaType.MEDIA_TYPE_ALBUM) { + break + } + } + listData.push(item) + } + if (params.menu_level == MenuLevel.MENU_FIRST_LEVEL_BY_TYPE && params.request_data == 'getRoot') { + logDebug(this.TAG, 'mFirstMenuData length = ' + listData.length) + this.mFirstMenuData = listData + } else if (params.menu_level == MenuLevel.MENU_SECOND_LEVEL_BY_FOLD) { + logDebug(this.TAG, 'mSecondMenuData length = ' + listData.length) + this.mSecondMenuData = listData + } else if (params.menu_level == MenuLevel.MENU_THIRD_LEVEL_HAS_PIC) { + logDebug(this.TAG, 'mThirdMenuPicData length = ' + listData.length) + this.mThirdMenuPicData = listData + } else if (params.menu_level == MenuLevel.MENU_THIRD_LEVEL_HAS_DETAIL) { + logDebug(this.TAG, 'mThirdMenuDetailData length = ' + listData.length) + if (listData.length > 0) { + this.mThirdMenuDetailData = listData + } else { + this.mThirdMenuDetailData = [] + } + } + } + } + + build() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.Start }) { + Row() { + LeftDialogComponent({ + mType: $mType, + mMenuLevel: $mMenuLevel, + mCurrentPath: $mCurrentPath, + mFirstMenuData: $mFirstMenuData }) - Image($r("app.media.ic_public_next")) - .width(pad_size.TWENTY_FOUR) - .height(pad_size.TWENTY_FOUR) - .margin({ left: pad_size.TWENTY_FOUR, right: pad_size.TWENTY_FOUR }) - } - - Row() { - List() { - ForEach(this.topPathInfo, (item: TopPathInfo) => { - ListItem() { + Column() { Row() { - if (item.name != '文件类型') { - Image($r("app.media.ic_public_right")) - .width(pad_size.TWELVE) - .height(pad_size.TWENTY_FOUR) - .margin({ left: pad_size.TWELVE, right: pad_size.TWELVE }) - } - Text(item.name) - .height(pad_size.TWENTY_FOUR) - .fontSize(pad_size.SIXTEEN) - .fontWeight(FontWeight.Medium) - .fontColor('#182431') - .opacity(item.opacity) - .onClick(() => { - if (item.name == mediaName.FILE_TYPE) { - updateTopPathInfo([], '文件类型', '') - this.mMenuLevel = menuLevel.MENU_FIRST_LEVEL_BY_TYPE - this.mType = '' - } else if (this.mMenuLevel == menuLevel.MENU_THIRD_LEVEL_HAS_DETAIL) { - this.mCurrentPath = item.path - LogInfo(this.TAG, 'item.path ' + item.path) - let topPathInfo: Array = AppStorage.Get('topPathInfo') - let index: number = topPathInfo.indexOf(item) - if (index != -1) { - var deleteNum = topPathInfo.length - index + 1 - topPathInfo.splice(index + 1, deleteNum) - topPathInfo[topPathInfo.length - 1].opacity = 1 - AppStorage.Set('topPathInfo', topPathInfo) + Row() { + Image($r("app.media.ic_public_back")) + .width(PadSize.TWENTY_FOUR) + .height(PadSize.TWENTY_FOUR) + .margin({ left: PadSize.TWENTY_FOUR }) + .onClick(() => { + if (this.mMenuLevel == MenuLevel.MENU_SECOND_LEVEL_BY_FOLD) { + updateTopPathInfo([], '文件类型', '') + this.mMenuLevel = MenuLevel.MENU_FIRST_LEVEL_BY_TYPE + this.mType = '' + } else if (this.mMenuLevel == MenuLevel.MENU_THIRD_LEVEL_HAS_PIC || (this.mMenuLevel == MenuLevel.MENU_THIRD_LEVEL_HAS_DETAIL)) { + this.topPathInfo.pop() + this.topPathInfo[this.topPathInfo.length - 1].opacity = 1 + if (this.topPathInfo.length > 1) { + var index = this.topPathInfo.length - 1 + this.mCurrentPath = this.topPathInfo[index].path + this.mMenuLevel = MenuLevel.MENU_SECOND_LEVEL_BY_FOLD + } else { + this.mMenuLevel = MenuLevel.MENU_FIRST_LEVEL_BY_TYPE + this.mType = '' + } + } + }) + + Image($r("app.media.ic_public_next")) + .width(PadSize.TWENTY_FOUR) + .height(PadSize.TWENTY_FOUR) + .margin({ left: PadSize.TWENTY_FOUR, right: PadSize.TWENTY_FOUR }) + } + + Row() { + List() { + ForEach(this.topPathInfo, (item: TopPathInfo) => { + ListItem() { + Row() { + if (item.name != '文件类型') { + Image($r("app.media.ic_public_right")) + .width(PadSize.TWELVE) + .height(PadSize.TWENTY_FOUR) + .margin({ left: PadSize.EIGHT, right: PadSize.EIGHT }) + } + Text(item.name) + .height(PadSize.TWENTY_FOUR) + .fontSize(PadSize.SIXTEEN) + .fontWeight(FontWeight.Medium) + .fontColor('#182431') + .opacity(item.opacity) + .onClick(() => { + if (item.name == '文件类型') { + updateTopPathInfo([], '文件类型', '') + this.mMenuLevel = MenuLevel.MENU_FIRST_LEVEL_BY_TYPE + this.mType = '' + } else if (this.mMenuLevel == MenuLevel.MENU_THIRD_LEVEL_HAS_DETAIL) { + this.mCurrentPath = item.path + logInfo(this.TAG, 'item.path ' + item.path) + let topPathInfo: Array = AppStorage.Get('topPathInfo') + let index: number = topPathInfo.indexOf(item) + if (index == 1) { + this.mMenuLevel = MenuLevel.MENU_SECOND_LEVEL_BY_FOLD + this.mType = changeStringToType(item.name) + this.mCurrentPath = item.path + } else if (index > 1) { + var deleteNum = topPathInfo.length - index + 1 + topPathInfo.splice(index + 1, deleteNum) + topPathInfo[topPathInfo.length - 1].opacity = 1 + AppStorage.Set('topPathInfo', topPathInfo) + } + } else if (this.mMenuLevel == MenuLevel.MENU_THIRD_LEVEL_HAS_PIC) { + let topPathInfo: Array = AppStorage.Get('topPathInfo') + let index: number = topPathInfo.indexOf(item) + if (index != -1) { + this.mMenuLevel = MenuLevel.MENU_SECOND_LEVEL_BY_FOLD + this.mType = changeStringToType(item.name) + this.mCurrentPath = item.path + } + } + }) + } + } + }, item => item.name) } - } else if (this.mMenuLevel == menuLevel.MENU_THIRD_LEVEL_HAS_PIC) { - let topPathInfo: Array = AppStorage.Get('topPathInfo') - let index: number = topPathInfo.indexOf(item) - if (index != -1) { - this.mMenuLevel = menuLevel.MENU_SECOND_LEVEL_BY_FOLD - this.mType = changeStringToType(item.name) - this.mCurrentPath = item.path - } - } - }) + .listDirection(Axis.Horizontal) + .margin({ left: PadSize.TWELVE, top: PadSize.SEVENTEEN, right: PadSize.TWELVE }) + } + .width(PadSize.FOUR_HUNDRED) + .height(PadSize.FIFTY_SIX) + .backdropBlur(PadSize.TWENTY) + .backgroundColor(Color.White) + .border({ radius: PadSize.TWENTY_FOUR, width: 0, style: BorderStyle.Solid }) + .shadow({ radius: 20, color: "#14000000" }) } - } - }, item => item.name) - } - .listDirection(Axis.Horizontal) - .margin({ left: pad_size.TWELVE, top: pad_size.SEVENTEEN }) - } - .width(pad_size.FOUR_HUNDRED) - .height(pad_size.FIFTY_SIX) - .backdropBlur(pad_size.TWENTY) - .backgroundColor(Color.White) - .border({ radius: pad_size.TWENTY_FOUR, width: 0.1, style: BorderStyle.Solid }) - } - .width(pad_size.RIGHT_DIALOG_WIDTH) - .height(pad_size.FIFTY_SIX) - .margin({ top: pad_size.SIXTEEN }) + .width(PadSize.RIGHT_DIALOG_WIDTH) + .height(PadSize.FIFTY_SIX) + .margin({ top: PadSize.SIXTEEN }) - Row() { - if (this.mMenuLevel == menuLevel.MENU_FIRST_LEVEL_BY_TYPE) { - FirstLevelByType({ - mFileList: this.mFirstMenuData, - mType: $mType, - mMenuLevel: $mMenuLevel, - mCurrentPath: $mCurrentPath, - mWorker: this.mWorker, - }) - } else if (this.mMenuLevel == menuLevel.MENU_SECOND_LEVEL_BY_FOLD) { - SecondLevelByFold({ - mType: $mType, - mMenuLevel: $mMenuLevel, - mCurrentPath: $mCurrentPath, - mWorker: this.mWorker, - mFileList: $mSecondMenuData - }) - } else if (this.mMenuLevel == menuLevel.MENU_THIRD_LEVEL_HAS_PIC) { - ThirdLevelHasPic({ - mType: $mType, - mMenuLevel: $mMenuLevel, - mCurrentPath: $mCurrentPath, - mWorker: this.mWorker, - mFileList: $mThirdMenuPicData - }) - } else if (this.mMenuLevel == menuLevel.MENU_THIRD_LEVEL_HAS_DETAIL) { - ThirdLevelHasDetail({ - mType: $mType, - mMenuLevel: $mMenuLevel, - mCurrentPath: $mCurrentPath, - mWorker: this.mWorker, - mFileInfo: $mThirdMenuDetailData - }) + Row() { + if (this.mMenuLevel == MenuLevel.MENU_FIRST_LEVEL_BY_TYPE) { + FirstLevelByType({ + mFileList: this.mFirstMenuData, + mType: $mType, + mMenuLevel: $mMenuLevel, + mCurrentPath: $mCurrentPath, + mWorker: this.mWorker, + }) + } else if (this.mMenuLevel == MenuLevel.MENU_SECOND_LEVEL_BY_FOLD) { + SecondLevelByFold({ + mType: $mType, + mMenuLevel: $mMenuLevel, + mCurrentPath: $mCurrentPath, + mWorker: this.mWorker, + mFileList: $mSecondMenuData + }) + } else if (this.mMenuLevel == MenuLevel.MENU_THIRD_LEVEL_HAS_PIC) { + ThirdLevelHasPic({ + mType: $mType, + mMenuLevel: $mMenuLevel, + mCurrentPath: $mCurrentPath, + mWorker: this.mWorker, + mFileList: $mThirdMenuPicData + }) + } else if (this.mMenuLevel == MenuLevel.MENU_THIRD_LEVEL_HAS_DETAIL) { + ThirdLevelHasDetail({ + mType: $mType, + mMenuLevel: $mMenuLevel, + mCurrentPath: $mCurrentPath, + mWorker: this.mWorker, + mFileInfo: $mThirdMenuDetailData + }) + } + } + .width(PadSize.RIGHT_DIALOG_WIDTH) + .height(PadSize.TWO_HUNDRED_AND_SIXTY) + } + .width(PadSize.RIGHT_DIALOG_WIDTH) + .height(PadSize.RIGHT_DIALOG_HEIGHT) } - } - .width(pad_size.RIGHT_DIALOG_WIDTH) - .height(pad_size.TWO_HUNDRED_AND_SIXTY) + .width(PadSize.BOTTOM_WIDTH) + + Divider().color('#D8D8D8').opacity(1).strokeWidth(1) + + ButtonArea({ + mWorker: this.mWorker, + mType: $mType, + mMenuLevel: $mMenuLevel, + mCurrentPath: $mCurrentPath + }) + } - .width(pad_size.RIGHT_DIALOG_WIDTH) - .height(pad_size.RIGHT_DIALOG_HEIGHT) - } - .width(pad_size.BOTTOM_WIDTH) - - Divider().color('#D8D8D8').opacity(1) - .strokeWidth(1) - - - BottomArea({ - mWorker: this.mWorker, - mType: $mType, - mMenuLevel: $mMenuLevel, - mCurrentPath: $mCurrentPath - }) - + .width(PadSize.MAIN_DIALOG_WIDTH) + .height(PadSize.MAIN_DIALOG_HEIGHT) + .border({ radius: PadSize.TWENTY_FOUR }) } - .width(pad_size.MAIN_DIALOG_WIDTH) - .height(pad_size.MAIN_DIALOG_HEIGHT) - .border({ radius: pad_size.TWENTY_FOUR }) - } } @Component struct LeftDialogComponent { - private TAG: string = 'LeftDialogComponent' - @Link @Watch('firstMenuDataChange') mFirstMenuData: FileInfo[] - @Link mType: string - @Link mMenuLevel: number - @Link mCurrentPath: string + private TAG: string = 'LeftDialogComponent' + @Link @Watch('firstMenuDataChange') mFirstMenuData: FileInfo[] + @Link mType: string + @Link mMenuLevel: number + @Link mCurrentPath: string + @StorageLink('topPathInfo') topPathInfo: Array = updateTopPathInfo([], '文件类型', '') - @StorageLink('topPathInfo') topPathInfo: Array = updateTopPathInfo([], '文件类型', '') - @StorageLink('selectedItem') selectedItem: FileInfo = new FileInfo('') - - aboutToAppear() { - LogInfo(this.TAG, 'aboutToAppear') - } - - firstMenuDataChange() { - LogInfo(this.TAG, 'firstMenuDataChange') - if (this.mFirstMenuData.length > 0) { - this.subscribeMultiInput() - } - } - - private subscribeMultiInput() { - LogInfo(this.TAG, 'subscribeMultiInput') - let mediaTypes: Array = [] - LogInfo(this.TAG, 'subscribeMultiInput mFirstMenuData = ' + this.mFirstMenuData.length) - this.mFirstMenuData.forEach((item: FileInfo) => { - mediaTypes.push(item.mediaType) - LogInfo(this.TAG, 'subscribeMultiInput mediaType = ' + item.mediaType) - }) - - let tabKeyOption = { - preKeys: [], finalKey: 2049, isFinalKeyDown: true, finalKeyDownDuration: 0 - } - let leftKeyOption = { - preKeys: [], finalKey: 2014, isFinalKeyDown: true, finalKeyDownDuration: 0 - } - let rightKeyOption = { - preKeys: [], finalKey: 2015, isFinalKeyDown: true, finalKeyDownDuration: 0 - } - let upKeyOption = { - preKeys: [], finalKey: 2012, isFinalKeyDown: true, finalKeyDownDuration: 0 - } - let downKeyOption = { - preKeys: [], finalKey: 2013, isFinalKeyDown: true, finalKeyDownDuration: 0 + aboutToAppear() { + logInfo(this.TAG, 'aboutToAppear') } - inputConsumer.on('key', tabKeyOption, (keyOption) => { - let index: number = mediaTypes.indexOf(this.mType) - index = (index + 1) % mediaTypes.length - this.processClickEvent(mediaTypes[index], this.mFirstMenuData[index].path, menuLevel.MENU_SECOND_LEVEL_BY_FOLD) - }) - inputConsumer.on('key', upKeyOption, (keyOption) => { - let index: number = mediaTypes.indexOf(this.mType) - index = (index - 1 + mediaTypes.length) % mediaTypes.length - this.processClickEvent(mediaTypes[index], this.mFirstMenuData[index].path, menuLevel.MENU_SECOND_LEVEL_BY_FOLD) - }) - inputConsumer.on('key', downKeyOption, (keyOption) => { - let index: number = mediaTypes.indexOf(this.mType) - index = (index + 1) % mediaTypes.length - this.processClickEvent(mediaTypes[index], this.mFirstMenuData[index].path, menuLevel.MENU_SECOND_LEVEL_BY_FOLD) - }) - } - - private processClickEvent(mediaType: string, currentPath: string, menuLevel: number) { - LogInfo(this.TAG, 'processClickEvent') - updateTopPathInfo([], '文件类型', '') - updateTopPathInfo(AppStorage.Get('topPathInfo'), changeTypeToString(mediaType), currentPath) - - this.mMenuLevel = menuLevel - this.mType = mediaType - this.mCurrentPath = currentPath - } - - build() { - Column() { - Row() { - Image($r("app.media.ic_public_folder")) - .width(pad_size.IC_PUBLIC_FOLDER_WIDTH) - .height(pad_size.IC_PUBLIC_FOLDER_HEIGHT) - .margin({ left: pad_size.TWELVE }) - Text($r("app.string.file_type")) - .fontSize(pad_size.SIXTEEN) - .fontWeight(FontWeight.Medium) - .fontColor('#182431') - .margin({ left: pad_size.SIXTEEN }) - Blank() - Image($r("app.media.ic_public_down")) - .width(pad_size.TWENTY_FOUR) - .height(pad_size.TWENTY_FOUR) - .margin({ right: pad_size.TWENTY }) - } - .width(pad_size.ONE_HUNDRED_AND_SEVENTY_SIX) - .height(pad_size.FIFTY_SIX) - .margin({ left: pad_size.TWELVE, top: pad_size.SIXTEEN, right: pad_size.TWELVE }) - .border({ radius: pad_size.TWENTY }) - .backgroundColor('#DCEAF9') - .onClick((event: ClickEvent) => { - if (this.mMenuLevel != menuLevel.MENU_FIRST_LEVEL_BY_TYPE) { - updateTopPathInfo([], '文件类型', '') - this.mMenuLevel = menuLevel.MENU_FIRST_LEVEL_BY_TYPE - this.mType = '' - this.mCurrentPath = '' + firstMenuDataChange() { + logInfo(this.TAG, 'firstMenuDataChange') + if (this.mFirstMenuData.length > 0) { + this.subscribeMultiInput() } - }) - - List() { - ForEach(this.mFirstMenuData, (item: FileInfo) => { - ListItem() { - Row() { - Image(item.thumbnail) - .width(pad_size.TWENTY_FOUR) - .height(pad_size.TWENTY_FOUR) - .margin({ left: pad_size.TWENTY_FOUR }) - Text(item.name) - .fontSize(pad_size.SIXTEEN) - .fontWeight(FontWeight.Medium) - .fontColor('#182431') - .margin({ left: pad_size.SIXTEEN }) - } - .width(pad_size.ONE_HUNDRED_AND_SEVENTY_SIX) - .height(pad_size.FIFTY_SIX) - .margin({ left: pad_size.TWELVE, right: pad_size.TWELVE }) - .linearGradient({ - angle: 90, - direction: GradientDirection.Left, - colors: this.selectedItem.name == item.name ? [[0xDCEAF9, 0.0], [0xF1F3F5, 1]] : [[0xF2F2F2, 0.0], [0xF2F2F2, 1.0]] - }) - .border({ radius: pad_size.TWENTY }) - .onClick((event: ClickEvent) => { - this.mCurrentPath = item.path - this.mMenuLevel = menuLevel.MENU_SECOND_LEVEL_BY_FOLD - this.mType = item.mediaType - updateTopPathInfo([], '文件类型', '') - updateTopPathInfo(AppStorage.Get('topPathInfo'), changeTypeToString(this.mType), this.mCurrentPath) - AppStorage.Set('selectedItem', item) - }) - } - }, item => item.name) - } } - .width(pad_size.LEFT_DIALOG_WIDTH) - .height(pad_size.LEFT_DIALOG_HEIGHT) - .backgroundColor("#F2F2F2") - } + + private subscribeMultiInput() { + logInfo(this.TAG, 'subscribeMultiInput') + let mediaTypes: Array = [] + logInfo(this.TAG, 'subscribeMultiInput mFirstMenuData = ' + this.mFirstMenuData.length) + this.mFirstMenuData.forEach((item: FileInfo) => { + mediaTypes.push(item.mediaType) + logInfo(this.TAG, 'subscribeMultiInput mediaType = ' + item.mediaType) + }) + + let tabKeyOption = { + preKeys: [], finalKey: 2049, isFinalKeyDown: true, finalKeyDownDuration: 0 + } + let leftKeyOption = { + preKeys: [], finalKey: 2014, isFinalKeyDown: true, finalKeyDownDuration: 0 + } + let rightKeyOption = { + preKeys: [], finalKey: 2015, isFinalKeyDown: true, finalKeyDownDuration: 0 + } + let upKeyOption = { + preKeys: [], finalKey: 2012, isFinalKeyDown: true, finalKeyDownDuration: 0 + } + let downKeyOption = { + preKeys: [], finalKey: 2013, isFinalKeyDown: true, finalKeyDownDuration: 0 + } + + inputConsumer.on('key', tabKeyOption, (keyOption) => { + let index: number = mediaTypes.indexOf(this.mType) + index = (index + 1) % mediaTypes.length + this.processClickEvent(mediaTypes[index], this.mFirstMenuData[index].path, MenuLevel.MENU_SECOND_LEVEL_BY_FOLD) + }) + inputConsumer.on('key', upKeyOption, (keyOption) => { + let index: number = mediaTypes.indexOf(this.mType) + index = (index - 1 + mediaTypes.length) % mediaTypes.length + this.processClickEvent(mediaTypes[index], this.mFirstMenuData[index].path, MenuLevel.MENU_SECOND_LEVEL_BY_FOLD) + }) + inputConsumer.on('key', downKeyOption, (keyOption) => { + let index: number = mediaTypes.indexOf(this.mType) + index = (index + 1) % mediaTypes.length + this.processClickEvent(mediaTypes[index], this.mFirstMenuData[index].path, MenuLevel.MENU_SECOND_LEVEL_BY_FOLD) + }) + } + + private processClickEvent(mediaType: string, currentPath: string, MenuLevel: number) { + logInfo(this.TAG, 'processClickEvent') + updateTopPathInfo([], '文件类型', '') + updateTopPathInfo(AppStorage.Get('topPathInfo'), changeTypeToString(mediaType), currentPath) + + this.mMenuLevel = MenuLevel + this.mType = mediaType + this.mCurrentPath = currentPath + } + + private checkSelectedItem(name: string): boolean { + if (this.topPathInfo.length <= 1) { + return false; + } + return this.topPathInfo[1].name == name + } + + build() { + Column() { + Row() { + Image($r("app.media.ic_public_folder")) + .width(PadSize.IC_PUBLIC_FOLDER_WIDTH) + .height(PadSize.IC_PUBLIC_FOLDER_HEIGHT) + .margin({ left: PadSize.TWELVE }) + Text($r("app.string.file_type")) + .fontSize(PadSize.SIXTEEN) + .fontWeight(FontWeight.Medium) + .fontColor('#182431') + .margin({ left: PadSize.SIXTEEN }) + Blank() + Image($r("app.media.ic_public_down")) + .width(PadSize.TWENTY_FOUR) + .height(PadSize.TWENTY_FOUR) + .margin({ right: PadSize.TWENTY }) + } + .width(PadSize.ONE_HUNDRED_AND_SEVENTY_SIX) + .height(PadSize.FIFTY_SIX) + .margin({ left: PadSize.TWELVE, top: PadSize.SIXTEEN, right: PadSize.TWELVE }) + .border({ radius: PadSize.TWENTY }) + .linearGradient({ + angle: 90, + direction: GradientDirection.Left, + colors: this.topPathInfo.length <= 1 ? [[0xDCEAF9, 0.0], [0xF1F3F5, 1]] : [[0xF8F9F9, 0.0], [0xF8F9F9, 1.0]] + }) + .onClick((event: ClickEvent) => { + if (this.mMenuLevel != MenuLevel.MENU_FIRST_LEVEL_BY_TYPE) { + updateTopPathInfo([], '文件类型', '') + this.mMenuLevel = MenuLevel.MENU_FIRST_LEVEL_BY_TYPE + this.mType = '' + this.mCurrentPath = '' + } + }) + + List() { + ForEach(this.mFirstMenuData, (item: FileInfo) => { + ListItem() { + Row() { + Image(item.thumbnail) + .width(PadSize.TWENTY_FOUR) + .height(PadSize.TWENTY_FOUR) + .margin({ left: PadSize.TWENTY_FOUR }) + Text(item.name) + .fontSize(PadSize.SIXTEEN) + .fontWeight(FontWeight.Medium) + .fontColor('#182431') + .margin({ left: PadSize.SIXTEEN }) + } + .width(PadSize.ONE_HUNDRED_AND_SEVENTY_SIX) + .height(PadSize.FIFTY_SIX) + .margin({ left: PadSize.TWELVE, right: PadSize.TWELVE }) + .linearGradient({ + angle: 90, + direction: GradientDirection.Left, + colors: this.checkSelectedItem(item.name) ? [[0xDCEAF9, 0.0], [0xF1F3F5, 1]] : [[0xF8F9F9, 0.0], [0xF8F9F9, 1.0]] + }) + .border({ radius: PadSize.TWENTY }) + .onClick((event: ClickEvent) => { + this.mCurrentPath = item.path + this.mMenuLevel = MenuLevel.MENU_SECOND_LEVEL_BY_FOLD + this.mType = item.mediaType + updateTopPathInfo([], '文件类型', '') + updateTopPathInfo(AppStorage.Get('topPathInfo'), changeTypeToString(this.mType), this.mCurrentPath) + }) + } + }, item => item.name) + } + } + .width(PadSize.LEFT_DIALOG_WIDTH) + .height(PadSize.LEFT_DIALOG_HEIGHT) + .backgroundColor("#FFF8F9F9") + } } @Component -struct BottomArea { - private TAG: string = 'BottomArea' - private mWorker - @State currentChoseFiles: Array = [] - @Link mType: string - @Link mMenuLevel: number - @Link mCurrentPath: string - @StorageLink('choseFiles') @Watch('choseFilesChange') choseFiles: Array = [] +struct ButtonArea { + private TAG: string = 'BottomArea' + private mWorker + @State currentChoseFiles: Array = [] + @Link mType: string + @Link mMenuLevel: number + @Link mCurrentPath: string + @StorageLink('choseFiles') @Watch('choseFilesChange') choseFiles: Array = [] - aboutToAppear() { - LogInfo(this.TAG, 'current choose file number = ' + this.currentChoseFiles.length) - } - - private choseFilesChange() { - this.currentChoseFiles = [] - let files: Array = AppStorage.Get('choseFiles') - files.forEach((item: FileInfo) => { - this.currentChoseFiles.push(item.name) - }) - LogInfo(this.TAG, 'current choose file number = ' + this.currentChoseFiles.length) - } - - build() { - Column() { - Row() { - Text($r("app.string.file_name")) - .fontSize(pad_size.SIXTEEN) - .fontWeight(FontWeight.Regular) - .fontColor('#000000') - .margin({ left: pad_size.EIGHT }) - Row() { - Text(this.currentChoseFiles.toString()) - .height(pad_size.THIRTY) - .maxLines(1) - .margin({ left: pad_size.SIXTEEN }) - } - .width(pad_size.SIX_HUNDRED_AND_NINE) - .height(pad_size.THIRTY_TWO) - .border({ width: pad_size.ONE, radius: pad_size.SIXTEEN }) - .margin({ left: pad_size.SIXTEEN, right: pad_size.TWENTY_FOUR }) - .opacity(0.2) - } - .width(pad_size.SEVEN_HUNDRED_AND_FOURTEEN) - .height(pad_size.SIXTY_FOUR) - .margin({ left: pad_size.TWENTY_ONE, right: pad_size.NINE }) - - Row() { - Button() { - Text($r('app.string.btn_cancel')) - .fontSize(pad_size.SIXTEEN) - .fontWeight(FontWeight.Medium) - .fontColor('#007DFF') - } - .width(pad_size.ONE_HUNDRED_AND_SEVENTY_EIGHT) - .height(pad_size.FORTY) - .backgroundColor('#d9e0dc') - .border({ radius: pad_size.TWENTY }) - .margin({ left: pad_size.THREE_HUNDRED_AND_FORTY }) - .onClick(() => { - terminateSelfWithResult(terminate_reason.NO_ACTION, '') - AppStorage.Set('choseFiles', []) - }) - - if (globalThis.startMode == 'save') { - Button() { - Text($r('app.string.btn_save')) - .fontSize(pad_size.SIXTEEN) - .fontWeight(FontWeight.Medium) - .fontColor('#007DFF') - } - .width(pad_size.ONE_HUNDRED_AND_SEVENTY_EIGHT) - .height(pad_size.FORTY) - .backgroundColor(this.mMenuLevel == menuLevel.MENU_FIRST_LEVEL_BY_TYPE ? '' : '#d9e0dc') - .border({ radius: pad_size.TWENTY }) - .margin({ left: pad_size.TWENTY_FOUR, right: pad_size.TWENTY_FOUR }) - .stateEffect(this.mMenuLevel == menuLevel.MENU_FIRST_LEVEL_BY_TYPE ? false : true) - .onClick(() => { - this.mWorker.postMessage({ - request_data: 'createFile', - device_name: 'local', - media_type: this.mType, - path: this.mCurrentPath, - save_name: globalThis.saveFile - }) - }) - } else { - Button() { - Text($r('app.string.btn_upload')) - .fontSize(pad_size.SIXTEEN) - .fontWeight(FontWeight.Medium) - .fontColor('#007DFF') - } - .width(pad_size.ONE_HUNDRED_AND_SEVENTY_EIGHT) - .height(pad_size.FORTY) - .backgroundColor(this.currentChoseFiles.length != 0 ? '#d9e0dc' : '') - .border({ radius: pad_size.TWENTY }) - .margin({ left: pad_size.TWENTY_FOUR, right: pad_size.TWENTY_FOUR }) - .stateEffect(this.currentChoseFiles.length != 0) - .onClick(() => { - let result: string = '' - this.choseFiles.forEach((item: FileInfo) => { - result += item.path + ';' - }) - terminateSelfWithResult(terminate_reason.SUCCESS, result) - AppStorage.Set('choseFiles', []) - }) - } - } + aboutToAppear() { + logInfo(this.TAG, 'current choose file number = ' + this.currentChoseFiles.length) } - .width(pad_size.MAIN_DIALOG_WIDTH) - .height(pad_size.BOTTOM_HEIGHT) - .margin({ bottom: pad_size.FOUR }) - .backgroundColor('#F2F2F2') - } -} + private choseFilesChange() { + this.currentChoseFiles = [] + let files: Array = AppStorage.Get('choseFiles') + files.forEach((item: FileInfo) => { + this.currentChoseFiles.push(item.name) + }) + logInfo(this.TAG, 'current choose file number = ' + this.currentChoseFiles.length) + } + + build() { + Column() { + Row() { + Text($r("app.string.file_name")) + .fontSize(PadSize.SIXTEEN) + .fontWeight(FontWeight.Regular) + .fontColor('#000000') + .margin({ left: PadSize.EIGHT }) + Row() { + if (globalThis.startMode == 'save') { + Text(globalThis.saveFile) + .height(PadSize.THIRTY) + .maxLines(1) + .margin({ left: PadSize.SIXTEEN }) + } else { + Text(this.currentChoseFiles.toString()) + .height(PadSize.THIRTY) + .maxLines(1) + .margin({ left: PadSize.SIXTEEN }) + } + } + .width(PadSize.SIX_HUNDRED_AND_NINE) + .height(PadSize.THIRTY_TWO) + .border({ width: PadSize.ONE, radius: PadSize.SIXTEEN }) + .margin({ left: PadSize.SIXTEEN, right: PadSize.TWENTY_FOUR }) + .opacity(0.2) + } + .width(PadSize.SEVEN_HUNDRED_AND_FOURTEEN) + .height(PadSize.SIXTY_FOUR) + .margin({ left: PadSize.TWENTY_ONE, right: PadSize.NINE }) + + Row() { + Button() { + Text($r('app.string.btn_cancel')) + .fontSize(PadSize.SIXTEEN) + .fontWeight(FontWeight.Medium) + .fontColor('#007DFF') + } + .width(PadSize.ONE_HUNDRED_AND_SEVENTY_EIGHT) + .height(PadSize.FORTY) + .backgroundColor('#0C182431') + .border({ radius: PadSize.TWENTY }) + .margin({ left: PadSize.THREE_HUNDRED_AND_FORTY }) + .onClick(() => { + terminateSelfWithResult(TerminateReason.NO_ACTION, '') + AppStorage.Set('choseFiles', []) + }) + + if (globalThis.startMode == 'save') { + Button() { + Text($r('app.string.btn_save')) + .fontSize(PadSize.SIXTEEN) + .fontWeight(FontWeight.Medium) + .fontColor(this.mMenuLevel != MenuLevel.MENU_FIRST_LEVEL_BY_TYPE ? '#007DFF' : "#99CBFF") + } + .width(PadSize.ONE_HUNDRED_AND_SEVENTY_EIGHT) + .height(PadSize.FORTY) + .backgroundColor(this.mMenuLevel != MenuLevel.MENU_FIRST_LEVEL_BY_TYPE ? '#0C182431' : '#EFF2F3') + .enabled(this.mMenuLevel != MenuLevel.MENU_FIRST_LEVEL_BY_TYPE) + .border({ radius: PadSize.TWENTY }) + .margin({ left: PadSize.TWENTY_FOUR, right: PadSize.TWENTY_FOUR }) + .stateEffect(this.mMenuLevel == MenuLevel.MENU_FIRST_LEVEL_BY_TYPE ? false : true) + .onClick(() => { + logInfo(this.TAG, `path: ${this.mCurrentPath}`) + this.mWorker.postMessage({ + request_data: 'createFile', + device_name: 'local', + MediaType: this.mType, + path: this.mCurrentPath, + save_name: globalThis.saveFile + }) + }) + } else { + Button() { + Text($r('app.string.btn_upload')) + .fontSize(PadSize.SIXTEEN) + .fontWeight(FontWeight.Medium) + .fontColor(this.currentChoseFiles.length != 0 ? '#007DFF' : "#99CBFF") + } + .width(PadSize.ONE_HUNDRED_AND_SEVENTY_EIGHT) + .height(PadSize.FORTY) + .backgroundColor(this.currentChoseFiles.length != 0 ? '#0C182431' : '#EFF2F3') + .enabled(this.currentChoseFiles.length != 0) + .border({ radius: PadSize.TWENTY }) + .margin({ left: PadSize.TWENTY_FOUR, right: PadSize.TWENTY_FOUR }) + .stateEffect(this.currentChoseFiles.length != 0) + .onClick(() => { + let result: string = '' + this.choseFiles.forEach((item: FileInfo) => { + result += item.path + ';' + }) + terminateSelfWithResult(TerminateReason.SUCCESS, result) + AppStorage.Set('choseFiles', []) + }) + } + } + } + .width(PadSize.MAIN_DIALOG_WIDTH) + .height(PadSize.BOTTOM_HEIGHT) + .margin({ bottom: PadSize.FOUR }) + .backgroundColor('#FFF8F9F9') + } +} \ No newline at end of file diff --git a/product/pad/src/main/ets/workers/DataWorker.js b/product/pad/src/main/ets/workers/DataWorker.js index ce03a18..ffed90a 100644 --- a/product/pad/src/main/ets/workers/DataWorker.js +++ b/product/pad/src/main/ets/workers/DataWorker.js @@ -13,16 +13,16 @@ * limitations under the License. */ -import { LogInfo, LogDebug } from '../../../../../../common/LogUtils' -import worker from '@ohos.worker' import filemanager from '@ohos.filemanager' +import worker from '@ohos.worker' +import { logInfo, logDebug, logError } from '../../../../../../common/src/main/ets/components/utils/logutils' var TAG = 'DataWorker' const parentPort = worker.parentPort parentPort.onmessage = function (e) { - LogInfo(TAG, 'DataWorker onMessage') + logInfo(TAG, 'DataWorker onMessage') let data = e.data - LogInfo(TAG, 'DataWorker onMessage ' + data.request_data) + logInfo(TAG, 'DataWorker onMessage ' + data.request_data) if (data.request_data == 'getRoot') { getRootData(data) } else if (data.request_data == 'listFile') { @@ -33,11 +33,11 @@ parentPort.onmessage = function (e) { } parentPort.onmessageerror = function () { - LogInfo(TAG, 'onmessageerror') + logInfo(TAG, 'onmessageerror') } parentPort.onerror = function (data) { - LogInfo(TAG, 'onerror') + logInfo(TAG, 'onerror') } function getRootData(data) { @@ -46,52 +46,46 @@ function getRootData(data) { handleData(file, data) }) .catch((error) => { - LogDebug(TAG, 'getRoot error' + error) + logError(TAG, 'getRoot error' + error) }); } function getListFileData(data) { if (data.offset == undefined || data.count == undefined) { - LogDebug(TAG, 'path = ' + data.path + " type = " + data.media_type) - filemanager.listFile(data.path, data.media_type) - .then(file => { - handleData(file, data) - }) - .catch((error) => { - LogDebug(TAG, 'getListFileData error' + error) - handleData([], data) - }) + logDebug(TAG, 'path = ' + data.path + " type = " + data.MediaType) + filemanager.listFile(data.path, data.MediaType).then(file => { + handleData(file, data) + }).catch((error) => { + logError(TAG, 'getListFileData error' + error) + handleData([], data) + }) } else { - LogDebug(TAG, 'path = ' + data.path + " type = " + data.media_type + " offset = " + data.offset) - filemanager.listFile(data.path, data.media_type, { + logDebug(TAG, 'path = ' + data.path + " type = " + data.MediaType + " offset = " + data.offset) + filemanager.listFile(data.path, data.MediaType, { 'offset': data.offset, 'count': data.count + }).then(file => { + handleData(file, data) + }).catch((error) => { + logError(TAG, 'getListFileData offset error' + error) + handleData([], data) }) - .then(file => { - handleData(file, data) - }) - .catch((error) => { - LogDebug(TAG, 'getListFileData offset error' + error) - handleData([], data) - }) } } function createFile(data) { - LogDebug(TAG, 'path = ' + data.path + ' files = ' + data.save_name) - filemanager.createFile(data.path, data.save_name) - .then((uri) => { - handleData(uri, data) - }) - .catch((error) => { - LogDebug(TAG, 'createFile error' + error) - }) + logDebug(TAG, 'path = ' + data.path + ' files = ' + data.save_name) + filemanager.createFile(data.path, data.save_name).then((uri) => { + handleData(uri, data) + }).catch((error) => { + logError(TAG, 'createFile error' + error) + }) } function handleData(file, data) { - LogInfo(TAG, 'handleData') + logInfo(TAG, 'handleData') var info = JSON.stringify(file) - LogInfo(TAG, 'info = ' + info.length) + logInfo(TAG, 'info = ' + info.length) var buf = new ArrayBuffer(info.length * 2) var bufView = new Uint16Array(buf) for (var index = 0; index < info.length; index++) { diff --git a/product/pad/src/main/resources/base/element/string.json b/product/pad/src/main/resources/base/element/string.json index 936ae05..f502650 100644 --- a/product/pad/src/main/resources/base/element/string.json +++ b/product/pad/src/main/resources/base/element/string.json @@ -23,66 +23,6 @@ { "name": "btn_save", "value": "save" - }, - { - "name": "file_unknown", - "value": "Unknown file" - }, - { - "name": "save_file_has_same_file", - "value": "Duplicate name file already exists" - }, - { - "name": "save_file_no_media_permission", - "value": "Saving to media library is not currently supported" - }, - { - "name": "save_file_unknown_reason", - "value": "Unknown error" - }, - { - "name": "file_zip", - "value": "Compressed (zipped) file" - }, - { - "name": "file_xml", - "value": "XML document" - }, - { - "name": "file_xls", - "value": "Microsoft Excel worksheet" - }, - { - "name": "file_txt", - "value": "Txt document" - }, - { - "name": "file_rar", - "value": "Rar compressed file" - }, - { - "name": "file_pdf", - "value": "Adobe Acrobat Document" - }, - { - "name": "file_html", - "value": "HTML Document" - }, - { - "name": "file_pptx", - "value": "Microsoft PowerPoint Presentation" - }, - { - "name": "file_docx", - "value": "Microsoft Word Document" - }, - { - "name": "file_type", - "value": "file type" - }, - { - "name": "file_name", - "value": "file name : " } ] } \ No newline at end of file diff --git a/product/pad/src/main/resources/base/media/ic_file_doc.png b/product/pad/src/main/resources/base/media/ic_file_doc.png deleted file mode 100644 index 32b7b88..0000000 Binary files a/product/pad/src/main/resources/base/media/ic_file_doc.png and /dev/null differ diff --git a/product/pad/src/main/resources/base/media/ic_file_fold.png b/product/pad/src/main/resources/base/media/ic_file_fold.png deleted file mode 100644 index 45375fd..0000000 Binary files a/product/pad/src/main/resources/base/media/ic_file_fold.png and /dev/null differ diff --git a/product/pad/src/main/resources/base/media/ic_file_html.png b/product/pad/src/main/resources/base/media/ic_file_html.png deleted file mode 100644 index 4df41b0..0000000 Binary files a/product/pad/src/main/resources/base/media/ic_file_html.png and /dev/null differ diff --git a/product/pad/src/main/resources/base/media/ic_file_manager.png b/product/pad/src/main/resources/base/media/ic_file_manager.png deleted file mode 100644 index 45375fd..0000000 Binary files a/product/pad/src/main/resources/base/media/ic_file_manager.png and /dev/null differ diff --git a/product/pad/src/main/resources/base/media/ic_file_pdf.png b/product/pad/src/main/resources/base/media/ic_file_pdf.png deleted file mode 100644 index 025ec1c..0000000 Binary files a/product/pad/src/main/resources/base/media/ic_file_pdf.png and /dev/null differ diff --git a/product/pad/src/main/resources/base/media/ic_file_pptx.png b/product/pad/src/main/resources/base/media/ic_file_pptx.png deleted file mode 100644 index 7669173..0000000 Binary files a/product/pad/src/main/resources/base/media/ic_file_pptx.png and /dev/null differ diff --git a/product/pad/src/main/resources/base/media/ic_file_rar.png b/product/pad/src/main/resources/base/media/ic_file_rar.png deleted file mode 100644 index 49d3865..0000000 Binary files a/product/pad/src/main/resources/base/media/ic_file_rar.png and /dev/null differ diff --git a/product/pad/src/main/resources/base/media/ic_file_txt.png b/product/pad/src/main/resources/base/media/ic_file_txt.png deleted file mode 100644 index 8bf40d0..0000000 Binary files a/product/pad/src/main/resources/base/media/ic_file_txt.png and /dev/null differ diff --git a/product/pad/src/main/resources/base/media/ic_file_unknown.png b/product/pad/src/main/resources/base/media/ic_file_unknown.png deleted file mode 100644 index 4f04e41..0000000 Binary files a/product/pad/src/main/resources/base/media/ic_file_unknown.png and /dev/null differ diff --git a/product/pad/src/main/resources/base/media/ic_file_xls.png b/product/pad/src/main/resources/base/media/ic_file_xls.png deleted file mode 100644 index 684c387..0000000 Binary files a/product/pad/src/main/resources/base/media/ic_file_xls.png and /dev/null differ diff --git a/product/pad/src/main/resources/base/media/ic_file_xml.png b/product/pad/src/main/resources/base/media/ic_file_xml.png deleted file mode 100644 index f557e06..0000000 Binary files a/product/pad/src/main/resources/base/media/ic_file_xml.png and /dev/null differ diff --git a/product/pad/src/main/resources/base/media/ic_file_zip.png b/product/pad/src/main/resources/base/media/ic_file_zip.png deleted file mode 100644 index 5764cc6..0000000 Binary files a/product/pad/src/main/resources/base/media/ic_file_zip.png and /dev/null differ diff --git a/product/pad/src/main/resources/zh_CN/element/string.json b/product/pad/src/main/resources/zh_CN/element/string.json index 504e3a1..651dbe2 100644 --- a/product/pad/src/main/resources/zh_CN/element/string.json +++ b/product/pad/src/main/resources/zh_CN/element/string.json @@ -23,66 +23,6 @@ { "name": "btn_save", "value": "保存" - }, - { - "name": "file_unknown", - "value": "未知文件" - }, - { - "name": "save_file_has_same_file", - "value": "已有重名文件" - }, - { - "name": "save_file_no_media_permission", - "value": "当前不支持保存到媒体库" - }, - { - "name": "save_file_unknown_reason", - "value": "未知错误" - }, - { - "name": "file_zip", - "value": "压缩(zipped)文件" - }, - { - "name": "file_xml", - "value": "XML文档" - }, - { - "name": "file_xls", - "value": "Microsoft Excel工作表" - }, - { - "name": "file_txt", - "value": "TXT文档" - }, - { - "name": "file_rar", - "value": "RAR压缩文件" - }, - { - "name": "file_pdf", - "value": "Adobe Acrobat Document" - }, - { - "name": "file_html", - "value": "HTML网页文件" - }, - { - "name": "file_pptx", - "value": "Microsoft PowerPoint演示文稿" - }, - { - "name": "file_docx", - "value": "Microsoft Word文档" - }, - { - "name": "file_type", - "value": "文件类型" - }, - { - "name": "file_name", - "value": "文件名 : " } ] } \ No newline at end of file diff --git a/product/phone/package-lock.json b/product/phone/package-lock.json index abd853c..c1ec7ac 100644 --- a/product/phone/package-lock.json +++ b/product/phone/package-lock.json @@ -1,5 +1,11 @@ { "name": "phone", "version": "1.0.0", - "lockfileVersion": 1 + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "@ohos/common": { + "version": "file:../../common" + } + } } diff --git a/product/phone/package.json b/product/phone/package.json index e9f46ef..7d55201 100644 --- a/product/phone/package.json +++ b/product/phone/package.json @@ -1,14 +1,16 @@ { - "license": "ISC", - "devDependencies": {}, - "name": "phone", - "ohos": { - "org": "huawei", - "directoryLevel": "module", - "buildTool": "hvigor" - }, - "description": "example description", - "repository": {}, - "version": "1.0.0", - "dependencies": {} + "license": "ISC", + "devDependencies": {}, + "name": "phone", + "ohos": { + "org": "huawei", + "directoryLevel": "module", + "buildTool": "hvigor" + }, + "description": "example description", + "repository": {}, + "version": "1.0.0", + "dependencies": { + "@ohos/common": "file:../../common" + } } diff --git a/product/phone/src/main/ets/Application/AbilityStage.ts b/product/phone/src/main/ets/Application/AbilityStage.ts index 32dfe93..d637557 100644 --- a/product/phone/src/main/ets/Application/AbilityStage.ts +++ b/product/phone/src/main/ets/Application/AbilityStage.ts @@ -1,7 +1,25 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import AbilityStage from "@ohos.application.AbilityStage" +import { logInfo } from '../../../../../../common/src/main/ets/components/Utils/LogUtils' + +const TAG = "MyAbilityStage" export default class MyAbilityStage extends AbilityStage { onCreate() { - console.log("[Demo] MyAbilityStage onCreate") + logInfo(TAG, "onCreate") } } \ No newline at end of file diff --git a/product/phone/src/main/ets/MainAbility/MainAbility.ts b/product/phone/src/main/ets/MainAbility/MainAbility.ts index c0bf40e..31e9a4e 100644 --- a/product/phone/src/main/ets/MainAbility/MainAbility.ts +++ b/product/phone/src/main/ets/MainAbility/MainAbility.ts @@ -1,7 +1,7 @@ import Ability from '@ohos.application.Ability' import display from '@ohos.display' import { Callback } from 'basic' -import { LogInfo, LogDebug } from '../module/LogUtils' +import { logInfo, logError, logWarn } from '../../../../../../common/src/main/ets/components/Utils/LogUtils' let displayWidth: number = 0 let displayHeight: number = 0 @@ -10,46 +10,41 @@ const TAG = "MainAbility" export default class MainAbility extends Ability { onCreate(want, launchParam) { - console.log("filePicker_MainAbility: onCreate") + logInfo(TAG, "onCreate") globalThis.abilityWant = want; globalThis.startMode = want.parameters.startMode globalThis.saveFile = want.parameters.saveFile globalThis.debugMode = want.parameters.debugMode - console.log('filePicker_MainAbility: startMode = ' + globalThis.startMode) - console.log('filePicker_MainAbility: file_name = ' + globalThis.saveFile) - console.log('filePicker_MainAbility: debugMode = ' + globalThis.debugMode) - + logInfo(TAG, `parameters ${JSON.stringify(want.parameters)}`) } onDestroy() { - console.log("[Demo] MainAbility onDestroy") + logInfo(TAG, "onDestroy") } onWindowStageCreate(windowStage) { // Main window is created, set main page for this ability - LogInfo(TAG, "[Demo] MainAbility onWindowStageCreate") + logInfo(TAG, "onWindowStageCreate") globalThis.context = this.context this.requestPermissions(() => this.displayWindow(windowStage)) - - } onWindowStageDestroy() { // Main window is destroyed, release UI related resources - console.log("[Demo] MainAbility onWindowStageDestroy") + logInfo(TAG, "onWindowStageDestroy") } onForeground() { // Ability has brought to foreground - console.log("[Demo] MainAbility onForeground") + logInfo(TAG, "onForeground") } onBackground() { // Ability has back to background - console.log("[Demo] MainAbility onBackground") + logInfo(TAG, "onBackground") } private requestPermissions(callback: Callback) { @@ -59,10 +54,10 @@ export default class MainAbility extends Ability { "ohos.permission.WRITE_MEDIA" ] globalThis.context.requestPermissionsFromUser(permissionList).then(function (data) { - LogInfo(TAG, 'filePicker_MainAbility: request permission data result = ' + data.authResults) + logInfo(TAG, 'request permission data result = ' + data.authResults) callback() }, (error) => { - LogInfo(TAG, 'filePicker_MainAbility: fail to request permission error code = ' + error.code) + logError(TAG, 'fail to request permission error code = ' + error.code) }) } @@ -76,10 +71,10 @@ export default class MainAbility extends Ability { globalThis.mainDialogWidth = dis.width globalThis.mainDialogHeight = (((displayHeight) - 240) * 0.7) - LogInfo(TAG, "cjl displayWidth = " + displayWidth + " displayHeight = " + displayHeight) + logInfo(TAG, "displayWidth = " + displayWidth + " displayHeight = " + displayHeight) windowStage.getMainWindow().then(win => { - LogInfo(TAG, "cjl windowStage.getMainWindow()") + logInfo(TAG, "windowStage.getMainWindow()") win.resetSize(displayWidth - 30, displayHeight - 168) @@ -87,25 +82,25 @@ export default class MainAbility extends Ability { win.setBackgroundColor("#00FFFFFF", (err, data) => { if (err.code) { - LogInfo(TAG, "Fail to set the background color" + JSON.stringify(err)) + logWarn(TAG, "Fail to set the background color" + JSON.stringify(err)) } else { - LogInfo(TAG, "Success to set the background color" + JSON.stringify(data)) + logInfo(TAG, "Success to set the background color" + JSON.stringify(data)) } }) win.disableWindowDecor((err, data) => { if (err.code) { - LogInfo(TAG, 'Failed to set the disableWindowDecor. Data: ' + JSON.stringify(data)) + logWarn(TAG, 'Failed to set the disableWindowDecor. Data: ' + JSON.stringify(data)) } else { - LogInfo(TAG, 'Succeeded in setting the disableWindowDecor. Data: ' + JSON.stringify(data)) + logInfo(TAG, "Success to disable Window Decor" + JSON.stringify(data)) } }) win.setWindowMode(102, (err, data) => { if (err.code) { - LogInfo(TAG, 'Failed to set the setWindowMode. Data: ' + JSON.stringify(data)) + logWarn(TAG, 'Failed to set the setWindowMode. Data: ' + JSON.stringify(data)) } else { - LogInfo(TAG, 'Succeeded in setting the setWindowMode. Data: ' + JSON.stringify(data)) + logInfo(TAG, 'Succeeded in setting the setWindowMode. Data: ' + JSON.stringify(data)) } }) diff --git a/product/phone/src/main/ets/module/AbilityUtils.ets b/product/phone/src/main/ets/module/AbilityUtils.ets deleted file mode 100644 index 837ef84..0000000 --- a/product/phone/src/main/ets/module/AbilityUtils.ets +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import display from '@ohos.display' -import featureAbility from '@ohos.ability.featureAbility' -import { LogInfo } from '../module/LogUtils.ets' -import { DisplayInfo } from './DisplayInfo.ets' - -var TAG: string = 'AbilityUtils' - -export function terminateSelfWithResult(resultCode: number, result: string): void { - LogInfo(TAG, 'terminateSelfWithResult') - let startMode: string = AppStorage.Get('startMode') - var abilityResult = { - resultCode: resultCode, - want: { - parameters: { - 'startMode': startMode, - 'result': result - } - } - } - globalThis.context.terminateSelfWithResult(abilityResult, (error) => { - if (error.code) { - LogInfo(TAG, 'Operation failed. Cause: ' + JSON.stringify(error)) - return - } - LogInfo(TAG, 'Operation succeeded') - }) -} - -export function initData(): void { - LogInfo(TAG, 'initData') - initWindowScale() - - getWantFromHap() -} - -function initWindowScale(): void { - display.getDefaultDisplay().then(dis => { - LogInfo(TAG, 'width = ' + dis.width + ';height= ' + dis.height) - let displayInfo: DisplayInfo = new DisplayInfo() - - if (dis.width > dis.height) { // 横屏 - displayInfo.width = dis.width - displayInfo.height = dis.height * 0.6 // 需要减去信号栏和导航栏的高度 - displayInfo.mainDialogHeight = displayInfo.height - vp2px(64 + 76) - displayInfo.mainDialogWidth = displayInfo.width - - } else { // 竖屏 - displayInfo.width = dis.width - displayInfo.height = dis.height * 0.65 // 需要减去信号栏和导航栏的高度 - displayInfo.mainDialogHeight = displayInfo.height - vp2px(64 + 76) - //displayInfo.mainDialogHeight = displayInfo.height - (64 + 76) * 2 - displayInfo.mainDialogWidth = displayInfo.width - } - - LogInfo(TAG, 'mainDialogWidth = ' + displayInfo.mainDialogWidth) - LogInfo(TAG, 'mainDialogHeight = ' + displayInfo.mainDialogHeight) - AppStorage.SetOrCreate('displayInfo', displayInfo) - }) -} - -function getWantFromHap(): void { - featureAbility.getWant() - .then((Want) => { - var mode: string = Want.parameters['startMode'] - if (mode == undefined) { - AppStorage.SetOrCreate('startMode', 'choose') - } else { - AppStorage.SetOrCreate('startMode', mode) - } - let save_name: string = Want.parameters['file_name'] - AppStorage.Set('saveName', save_name) - LogInfo(TAG, 'saveName = ' + save_name) - }).catch((error) => { - LogInfo(TAG, 'fail Data: ' + JSON.stringify(error)) - }) -} \ No newline at end of file diff --git a/product/phone/src/main/ets/module/Constants.ets b/product/phone/src/main/ets/module/Constants.ets deleted file mode 100644 index 6913acd..0000000 --- a/product/phone/src/main/ets/module/Constants.ets +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export enum menuLevel { - MENU_FIRST_LEVEL_BY_TYPE = 1, - MENU_SECOND_LEVEL_BY_FOLD = 2, - MENU_THIRD_LEVEL_HAS_PIC = 3, - MENU_THIRD_LEVEL_HAS_DETAIL = 4, -} - -export enum media_type { - MEDIA_TYPE_FILE = 1, - MEDIA_TYPE_IMAGE = 3, - MEDIA_TYPE_VIDEO = 4, - MEDIA_TYPE_AUDIO = 5, - MEDIA_TYPE_ALBUM = 8 -} - -export enum GridItemSize { - GRID_ITEM_HEIGHT = 126, - //GRID_ITEM_WIDTH = 112, - GRID_ITEM_WIDTH = 96, - GRID_ITEM_COLUMNS_GAP = 8, - GRID_ITEM_ROWS_GAP = 8, -} - -export enum terminate_reason { - SUCCESS = 0, - NO_ACTION = -1, -} \ No newline at end of file diff --git a/product/phone/src/main/ets/module/DialogUtils.ets b/product/phone/src/main/ets/module/DialogUtils.ets deleted file mode 100644 index be3355e..0000000 --- a/product/phone/src/main/ets/module/DialogUtils.ets +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { FileInfo } from './FileInfo.ets' - -@CustomDialog -export struct WarningDialog { - @Link code: number - controller: CustomDialogController - cancel: () => void - confirm: () => void - - build() { - Column() { - Text('Warning Title').fontSize(20).margin(10) - if (this.code == 1) { - Text($r("app.string.save_file_has_same_file")).fontSize(16).margin(10) - } else if (this.code == 2) { - Text($r("app.string.save_file_no_media_permission")).fontSize(16).margin(10) - } else { - Text($r("app.string.save_file_unknown_reason")).fontSize(16).margin(10) - } - Flex({ justifyContent: FlexAlign.SpaceAround }) { - Button('cancel') - .onClick(() => { - this.controller.close() - this.cancel() - }).backgroundColor(0xffffff).fontColor(Color.Black) - Button('confirm') - .onClick(() => { - this.controller.close() - this.confirm() - }).backgroundColor(0xffffff).fontColor(Color.Red) - }.margin({ bottom: 10 }) - } - } -} - -@CustomDialog -export struct ChooseDialog { - controller: CustomDialogController - - build() { - Column() { - Row() { - Text('选择该文件') - } - Row() { - Button() { - Text('取消') - .height('100%') - .fontSize(24) - .fontColor(Color.Blue) - } - .width(px2vp(200)) - .height(px2vp(50)) - .backgroundColor(Color.White) - .onClick(() => { - this.controller.close() - }) - - Divider() - .vertical(true) - .color(Color.Gray) - .height(40) - .margin({top: 0, right: 10, bottom: 0, left: 10}) - - Button() { - Text('确定') - .height('100%') - .fontSize(24) - .fontColor(Color.Blue) - } - .width(px2vp(200)) - .height(px2vp(50)) - .backgroundColor(Color.White) - .onClick(() => { - let item: FileInfo = AppStorage.Get('selectedFileInfo') - if (item != null) { - let files: Array = AppStorage.Get('choseFiles') - if (files.indexOf(item) == -1) { - files.push(item) - AppStorage.Set('choseFiles', files) - } - } - this.controller.close() - }) - } - .padding(20) - } - .padding({ - top: 25, - right: 0, - bottom: 15, - left: 0 - }) - } -} \ No newline at end of file diff --git a/product/phone/src/main/ets/module/FileInfo.ets b/product/phone/src/main/ets/module/FileInfo.ets deleted file mode 100644 index 28d87de..0000000 --- a/product/phone/src/main/ets/module/FileInfo.ets +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { media_type } from './Constants.ets' - -export class FileInfo { - name: string - path: string - type: number= media_type.MEDIA_TYPE_ALBUM - size: string - dataAdded_time: string - modified_time: string - mediaType: string - thumbnail: Resource - font_color: Color | string | Resource - opacity: number - list_background: string | Resource - - constructor(name: string) { - this.name = name - } -} - -export class TopPathInfo { - name: string - path: string - opacity: number = 1 - - constructor(name: string, path: string) { - this.name = name - this.path = path - } -} \ No newline at end of file diff --git a/product/phone/src/main/ets/module/FileManagerServiceUtils.ets b/product/phone/src/main/ets/module/FileManagerServiceUtils.ets deleted file mode 100644 index 501d2d9..0000000 --- a/product/phone/src/main/ets/module/FileManagerServiceUtils.ets +++ /dev/null @@ -1,341 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { media_type } from './Constants.ets'; -import { FileInfo } from '../module/FileInfo.ets' -import { LogInfo } from '../module/LogUtils.ets' - -var TAG = 'FileManagerServiceUtils' -var isDebug: boolean = true; - -export function getFirstMenu(deviceName: string): Array { - let fileList: Array = []; - if (isDebug) { - let file1: FileInfo = new FileInfo('image_album'); - file1.type = media_type.MEDIA_TYPE_ALBUM; - file1.path = 'dataability:///album'; - file1.size = ''; - file1.dataAdded_time = 'xxx'; - file1.modified_time = 'xxx'; - fileList.push(file1); - - let file2: FileInfo = new FileInfo('video_album'); - file2.type = media_type.MEDIA_TYPE_ALBUM; - file2.path = 'dataability:///album'; - file2.size = ''; - file2.dataAdded_time = 'xxx'; - file2.modified_time = 'xxx'; - fileList.push(file2); - - let file4: FileInfo = new FileInfo('file_folder'); - file4.type = media_type.MEDIA_TYPE_ALBUM; - file4.path = 'dataability:///album'; - file4.size = ''; - file4.dataAdded_time = 'xxx'; - file4.modified_time = 'xxx'; - fileList.push(file4); - - let file3: FileInfo = new FileInfo('audio_album'); - file3.type = media_type.MEDIA_TYPE_ALBUM; - file3.path = 'dataability:///album'; - file3.size = ''; - file3.dataAdded_time = 'xxx'; - file3.modified_time = 'xxx'; - fileList.push(file3); - } else { - // var fileInfo = filemanager.getRoot(deviceName); - } - - fileList.forEach(item => { - if (item.name == 'image_album') { - item.name = "图片"; - item.mediaType = 'image'; - item.thumbnail = $r("app.media.ic_photo") - } else if (item.name == 'video_album') { - item.name = "视频"; - item.mediaType = 'video'; - item.thumbnail = $r("app.media.ic_video") - } else if (item.name == 'audio_album') { - item.name = "音频"; - item.mediaType = 'audio'; - item.thumbnail = $r("app.media.ic_audio") - } else if (item.name == 'file_folder') { - item.name = "文档"; - item.mediaType = 'file'; - item.thumbnail = $r("app.media.ic_document") - } - }); - - return fileList; -} - -export function getListFile(deviceName: string, mediaType: string, path: string): Array { - LogInfo(TAG, "getListFile mediaType = " + mediaType + ';path = ' + path); - let fileList: Array = []; - if (isDebug) { - if (path == 'dataability:///album') { - if (mediaType == 'image') { - let fileInfo1: FileInfo = new FileInfo("微信的图片"); - fileInfo1.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo1.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/01'; - fileInfo1.dataAdded_time = 'xxx'; - fileInfo1.modified_time = 'xxx'; - fileList.push(fileInfo1); - let fileInfo2: FileInfo = new FileInfo("图片1"); - fileInfo2.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo2.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/02'; - fileInfo2.dataAdded_time = 'xxx'; - fileInfo2.modified_time = 'xxx'; - fileList.push(fileInfo2); - let fileInfo3: FileInfo = new FileInfo("图片2"); - fileInfo3.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo3.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/03'; - fileInfo3.dataAdded_time = 'xxx'; - fileInfo3.modified_time = 'xxx'; - fileList.push(fileInfo3); - let fileInfo4: FileInfo = new FileInfo("图片3"); - fileInfo4.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo4.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/04'; - fileInfo4.dataAdded_time = 'xxx'; - fileInfo4.modified_time = 'xxx'; - fileList.push(fileInfo4); - let fileInfo5: FileInfo = new FileInfo("图片4"); - fileInfo5.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo5.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/05'; - fileInfo5.dataAdded_time = 'xxx'; - fileInfo5.modified_time = 'xxx'; - fileList.push(fileInfo5); - let fileInfo6: FileInfo = new FileInfo("图片5"); - fileInfo6.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo6.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/06'; - fileInfo6.dataAdded_time = 'xxx'; - fileInfo6.modified_time = 'xxx'; - fileList.push(fileInfo6); - let fileInfo7: FileInfo = new FileInfo("图片6"); - fileInfo7.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo7.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/07'; - fileInfo7.dataAdded_time = 'xxx'; - fileInfo7.modified_time = 'xxx'; - fileList.push(fileInfo7); - let fileInfo8: FileInfo = new FileInfo("图片7"); - fileInfo8.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo8.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/08'; - fileInfo8.dataAdded_time = 'xxx'; - fileInfo8.modified_time = 'xxx'; - fileList.push(fileInfo8); - let fileInfo9: FileInfo = new FileInfo("图片8"); - fileInfo1.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo1.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/09'; - fileInfo1.dataAdded_time = 'xxx'; - fileInfo1.modified_time = 'xxx'; - fileList.push(fileInfo9); - let fileInfo10: FileInfo = new FileInfo("图片9"); - fileInfo10.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo10.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/10'; - fileInfo10.dataAdded_time = 'xxx'; - fileInfo10.modified_time = 'xxx'; - fileList.push(fileInfo10); - let fileInfo11: FileInfo = new FileInfo("图片10"); - fileInfo11.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo11.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/11'; - fileInfo11.dataAdded_time = 'xxx'; - fileInfo11.modified_time = 'xxx'; - fileList.push(fileInfo11); - } else if (mediaType == 'video') { - let fileInfo1: FileInfo = new FileInfo("视频0"); - fileInfo1.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo1.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/12'; - fileInfo1.dataAdded_time = 'xxx'; - fileInfo1.modified_time = 'xxx'; - fileList.push(fileInfo1); - let fileInfo2: FileInfo = new FileInfo("视频1"); - fileInfo2.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo2.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/13'; - fileInfo2.dataAdded_time = 'xxx'; - fileInfo2.modified_time = 'xxx'; - fileList.push(fileInfo2); - let fileInfo3: FileInfo = new FileInfo("视频2"); - fileInfo3.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo3.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/14'; - fileInfo3.dataAdded_time = 'xxx'; - fileInfo3.modified_time = 'xxx'; - fileList.push(fileInfo3); - let fileInfo4: FileInfo = new FileInfo("视频3"); - fileInfo4.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo4.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/15'; - fileInfo4.dataAdded_time = 'xxx'; - fileInfo4.modified_time = 'xxx'; - fileList.push(fileInfo4); - let fileInfo5: FileInfo = new FileInfo("视频4"); - fileInfo5.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo5.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/16'; - fileInfo5.dataAdded_time = 'xxx'; - fileInfo5.modified_time = 'xxx'; - fileList.push(fileInfo5); - } else if (mediaType == 'audio') { - let fileInfo1: FileInfo = new FileInfo("音频0"); - fileInfo1.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo1.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/17'; - fileInfo1.dataAdded_time = 'xxx'; - fileInfo1.modified_time = 'xxx'; - fileList.push(fileInfo1); - let fileInfo2: FileInfo = new FileInfo("音频1"); - fileInfo2.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo2.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/18'; - fileInfo2.dataAdded_time = 'xxx'; - fileInfo2.modified_time = 'xxx'; - fileList.push(fileInfo2); - let fileInfo3: FileInfo = new FileInfo("音频2"); - fileInfo3.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo3.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/19'; - fileInfo3.dataAdded_time = 'xxx'; - fileInfo3.modified_time = 'xxx'; - fileList.push(fileInfo3); - let fileInfo4: FileInfo = new FileInfo("音频3"); - fileInfo4.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo4.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/20'; - fileInfo4.dataAdded_time = 'xxx'; - fileInfo4.modified_time = 'xxx'; - fileList.push(fileInfo4); - let fileInfo5: FileInfo = new FileInfo("音频4"); - fileInfo5.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo5.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/21'; - fileInfo5.dataAdded_time = 'xxx'; - fileInfo5.modified_time = 'xxx'; - fileList.push(fileInfo5); - } else if (mediaType == 'file') { - let fileInfo1: FileInfo = new FileInfo("文件夹0"); - fileInfo1.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo1.mediaType = mediaType; - fileInfo1.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/22'; - fileInfo1.dataAdded_time = 'xxx'; - fileInfo1.modified_time = 'xxx'; - fileList.push(fileInfo1); - let fileInfo2: FileInfo = new FileInfo("文件夹1"); - fileInfo2.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo2.mediaType = mediaType; - fileInfo2.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/23'; - fileInfo2.dataAdded_time = 'xxx'; - fileInfo2.modified_time = 'xxx'; - fileList.push(fileInfo2); - let fileInfo3: FileInfo = new FileInfo("文件夹2"); - fileInfo3.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo3.mediaType = mediaType; - fileInfo3.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/24'; - fileInfo3.dataAdded_time = 'xxx'; - fileInfo3.modified_time = 'xxx'; - fileList.push(fileInfo3); - let fileInfo4: FileInfo = new FileInfo("文件夹3"); - fileInfo4.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo4.mediaType = mediaType; - fileInfo4.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/25'; - fileInfo4.dataAdded_time = 'xxx'; - fileInfo4.modified_time = 'xxx'; - fileList.push(fileInfo4); - let fileInfo5: FileInfo = new FileInfo("文件夹4"); - fileInfo5.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo5.mediaType = mediaType; - fileInfo5.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/26'; - fileInfo5.dataAdded_time = 'xxx'; - fileInfo5.modified_time = 'xxx'; - fileList.push(fileInfo5); - let fileInfo6: FileInfo = new FileInfo("文本文档.txt"); - fileInfo6.type = media_type.MEDIA_TYPE_FILE; - fileInfo6.mediaType = mediaType; - fileInfo6.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/27'; - fileInfo6.dataAdded_time = 'xxx'; - fileInfo6.modified_time = 'xxx'; - fileInfo6.size = '1,024 KB' - fileList.push(fileInfo6); - let fileInfo7: FileInfo = new FileInfo("验收文稿.ppt"); - fileInfo7.type = media_type.MEDIA_TYPE_FILE; - fileInfo7.mediaType = mediaType; - fileInfo7.path = 'dataability:///com.ohos.medialibrary.MediaLibraryDataAbility/file/28'; - fileInfo7.dataAdded_time = 'xxx'; - fileInfo7.modified_time = 'xxx'; - fileInfo7.size = '4,562,000 KB' - fileList.push(fileInfo7); - } - } else { - if (mediaType == 'image') { - for (var index = 0; index < 10; index++) { - let file: FileInfo = new FileInfo("" + index + ".png"); - file.type = media_type.MEDIA_TYPE_IMAGE; - file.path = path + index; - file.dataAdded_time = 'xxx'; - file.modified_time = 'xxx'; - fileList.push(file); - } - } else if (mediaType == 'video') { - for (var index = 0; index < 15; index++) { - let file: FileInfo = new FileInfo("" + index + ".wmv"); - file.type = media_type.MEDIA_TYPE_VIDEO; - file.path = path + index; - file.dataAdded_time = 'xxx'; - file.modified_time = 'xxx'; - fileList.push(file); - } - } else if (mediaType == 'audio') { - for (var index = 0; index < 18; index++) { - let file: FileInfo = new FileInfo("" + index + ".mp3"); - file.type = media_type.MEDIA_TYPE_AUDIO; - file.path = path + index; - file.dataAdded_time = 'xxx'; - file.modified_time = 'xxx'; - fileList.push(file); - } - } else if (mediaType == 'file') { - let fileInfo4: FileInfo = new FileInfo("文件夹3"); - fileInfo4.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo4.path = path + '5'; - fileInfo4.dataAdded_time = 'xxx'; - fileInfo4.modified_time = 'xxx'; - fileList.push(fileInfo4); - let fileInfo5: FileInfo = new FileInfo("文件夹4"); - fileInfo5.type = media_type.MEDIA_TYPE_ALBUM; - fileInfo5.path = path + '6'; - fileInfo5.dataAdded_time = 'xxx'; - fileInfo5.modified_time = 'xxx'; - fileList.push(fileInfo5); - let fileInfo6: FileInfo = new FileInfo("文本文档.txt"); - fileInfo6.type = media_type.MEDIA_TYPE_FILE; - fileInfo6.path = path + '7'; - fileInfo6.size = '1,000 KB' - fileInfo6.dataAdded_time = 'xxx'; - fileInfo6.modified_time = 'xxx'; - fileList.push(fileInfo6); - let fileInfo7: FileInfo = new FileInfo("验收文稿.ppt"); - fileInfo7.type = media_type.MEDIA_TYPE_FILE; - fileInfo7.path = path + '8'; - fileInfo7.size = '520,000 KB' - fileInfo7.dataAdded_time = 'xxx'; - fileInfo7.modified_time = 'xxx'; - fileList.push(fileInfo7); - } - } - } else { - // fileList = filemanager.listfile(deviceName, mediaType, path); - } - LogInfo(TAG, "get file list is " + fileList.length) - return fileList; -} - -//保存某个文件,返回是否保存成功,或有错误提示,还需要增加三方应用包名 -export function saveFile(deviceName: string, name: string, path: string): boolean { - LogInfo(TAG, 'saveFile'); - - return true; - -} diff --git a/product/phone/src/main/ets/module/LogUtils.ets b/product/phone/src/main/ets/module/LogUtils.ets deleted file mode 100644 index 8e6bb82..0000000 --- a/product/phone/src/main/ets/module/LogUtils.ets +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export function LogInfo(TAG: string, message: string | number): void { - console.info('filePicker_' + TAG + ': ' + message) -} - -export function LogDebug(TAG: string, message: string | number): void { - console.debug('filePicker_' + TAG + ': ' + message) -} diff --git a/product/phone/src/main/ets/module/Utils.ets b/product/phone/src/main/ets/module/Utils.ets deleted file mode 100644 index ca959af..0000000 --- a/product/phone/src/main/ets/module/Utils.ets +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { TopPathInfo } from '../module/FileInfo.ets' -import { LogInfo } from '../module/LogUtils.ets' - -var TAG: string = 'Utils' - -export function getRootPath(): Array { - var root_path: Array = [] - root_path.push(new TopPathInfo('文件类型', '')) - return root_path -} - -var strTypeArr = [ - ['image', '图片'], - ['video', '视频'], - ['audio', '音频'], - ['file', '文档'], -] - -export function changeTypeToString(type: string): string { - LogInfo(TAG, 'changeTypeToString type = ' + type) - for (var i = 0; i < strTypeArr.length; i++) { - if (strTypeArr[i][0] == type) { - return strTypeArr[i][1] - } - } - return '' -} - -export function changeStringToType(type: string): string { - LogInfo(TAG, 'changeStringToType type = ' + type) - for (var i = 0; i < strTypeArr.length; i++) { - if (strTypeArr[i][1] == type) { - return strTypeArr[i][0] - } - } - return '' -} - -export function getItemNumberInGrid(itemWidth: number, itemGap: number, parentWidth: number): string { - LogInfo(TAG, 'getItemNumberInGrid') - let columnTemples: string = '' - let remainderWidth: number = parentWidth - itemWidth - columnTemples += '1fr' - while (itemWidth + itemGap < remainderWidth) { - remainderWidth = remainderWidth - (itemWidth + itemGap) - columnTemples += ' 1fr' - } - LogInfo(TAG, 'columnTemples = ' + columnTemples) - return columnTemples -} - -var fileSuffixAndType = [ - ['.doc', $r("app.media.ic_file_doc"), $r("app.string.file_docx")], - ['.html', $r("app.media.ic_file_html"), $r("app.string.file_html")], - ['.pdf', $r("app.media.ic_file_pdf"), $r("app.string.file_pdf")], - ['.pptx', $r("app.media.ic_file_pptx"), $r("app.string.file_pptx")], - ['.ppt', $r("app.media.ic_file_pptx"), $r("app.string.file_pptx")], - ['.rar', $r("app.media.ic_file_rar"), $r("app.string.file_rar")], - ['.txt', $r("app.media.ic_file_txt"), $r("app.string.file_txt")], - ['.xls', $r("app.media.ic_file_xls"), $r("app.string.file_xls")], - ['.xml', $r("app.media.ic_file_xml"), $r("app.string.file_xml")], - ['.zip', $r("app.media.ic_file_zip"), $r("app.string.file_zip")], -] - -export function getShowIconBySuffix(suffix: string): string | Resource { - LogInfo(TAG, 'getShowIconBySuffix suffix = ' + suffix) - for (var i = 0; i < fileSuffixAndType.length; i++) { - if (isTwoStringEqual(fileSuffixAndType[i][0].toString(),suffix)) { - return fileSuffixAndType[i][1] - } - } - return $r("app.media.ic_file_unknown") -} - -export function getShowTextBySuffix(suffix: string): string | Resource { - LogInfo(TAG, 'getShowTextBySuffix suffix = ' + suffix) - for (var i = 0; i < fileSuffixAndType.length; i++) { - if (fileSuffixAndType[i][0] == suffix) { - return fileSuffixAndType[i][2] - } - } - return $r("app.string.file_unknown") -} - -export function getWarningDialogMessage(code: number): string | Resource { - switch (code) { - case 1: - return $r("app.string.save_file_has_same_file") - case 2: - return $r("app.string.save_file_no_media_permission") - default: - return $r("app.string.save_file_unknown_reason") - } -} - -export function isTwoStringEqual(src: string, tar: string) { - if (src.indexOf(tar) == 0 && tar.indexOf(src) == 0) { - return true; - } - return false; -} - -export function updateTopPathInfo(currentPathInfo: Array, name: string, path: string) { - currentPathInfo.forEach((item: TopPathInfo) => { - item.opacity = 0.4 - }) - - currentPathInfo.push(new TopPathInfo(name, path)) - AppStorage.Set('topPathInfo', currentPathInfo) - return currentPathInfo -} \ No newline at end of file diff --git a/product/phone/src/main/ets/pages/FirstLevelByType.ets b/product/phone/src/main/ets/pages/FirstLevelByType.ets index d5c8630..93eb002 100644 --- a/product/phone/src/main/ets/pages/FirstLevelByType.ets +++ b/product/phone/src/main/ets/pages/FirstLevelByType.ets @@ -13,78 +13,77 @@ * limitations under the License. */ -import { FileInfo } from '../module/FileInfo' -import { LogInfo } from '../module/LogUtils' -import { menuLevel } from '../module/Constants' +import { FileInfo } from '../../../../../../common/src/main/ets/components/Data/FileInfo' +import { MenuLevel } from '../../../../../../common/src/main/ets/components/Data/Constants' @Component export struct FirstLevelByType { - private TAG: string = 'FirstLevelByType' - private mWorker - private mFileList: FileInfo[] - @Link mType: string - @Link mMenuLevel: number - @Link mCurrentPath: string + private TAG: string = 'FirstLevelByType' + private mWorker + private mFileList: FileInfo[] + @Link mType: string + @Link mMenuLevel: number + @Link mCurrentPath: string - build() { - Column() { - ForEach(this.mFileList, (item: FileInfo, index: number) => { + build() { Column() { - RowView({ - item: item, - mMenuLevel: $mMenuLevel, - mType: $mType, - mCurrentPath: $mCurrentPath - }) + ForEach(this.mFileList, (item: FileInfo, index: number) => { + Column() { + RowView({ + item: item, + mMenuLevel: $mMenuLevel, + mType: $mType, + mCurrentPath: $mCurrentPath + }) - Divider() - .color('#000000') - .opacity(0.1) - .visibility(this.mFileList.length == index + 1 ? Visibility.Hidden : Visibility.Visible) - .margin({ left: 40 }) + Divider() + .color('#000000') + .opacity(0.1) + .visibility(this.mFileList.length == index + 1 ? Visibility.Hidden : Visibility.Visible) + .margin({ left: 40 }) + } + .width('100%') + .height(56) + }, item => item.name.toString()) } + .padding({ top: 4, bottom: 4, right: 12, left: 12 }) + .alignItems(HorizontalAlign.Start) // 导致圆角消失 + .border({ radius: 24 }) + .opacity(0.9) + .backgroundColor('#FFFFFF') .width('100%') - .height(56) - }, item => item.name.toString()) } - .padding({ top: 4, bottom: 4, right: 12, left: 12 }) - .alignItems(HorizontalAlign.Start) // 导致圆角消失 - .border({ radius: 24 }) - .opacity(0.9) - .backgroundColor('#FFFFFF') - .width('100%') - } } @Component struct RowView { - private item: FileInfo = new FileInfo('') - @Link mMenuLevel: number - @Link mType: string - @Link mCurrentPath: string + private item: FileInfo = new FileInfo('') + @Link mMenuLevel: number + @Link mType: string + @Link mCurrentPath: string - build() { - Row() { - Image($r("app.media.ic_type_smallfile")) - .width(24) - .height(24) - Text(this.item.name) - .fontSize(16) - .fontColor('#182431') - .fontWeight(FontWeight.Medium) - .margin({ left: 16 }) - Blank() - Image($r("app.media.ic_right")) - .width(12) - .height(24) + build() { + Row() { + Image($r("app.media.ic_type_smallfile")) + .width(24) + .height(24) + Text(this.item.name) + .fontSize(16) + .fontColor('#182431') + .fontWeight(FontWeight.Medium) + .margin({ left: 16 }) + Blank() + Image($r("app.media.ic_right")) + .width(12) + .height(24) + } + .height(56) + .width('100%') // TODO + .backgroundColor(this.item.list_background) + .onClick(() => { + this.mType = this.item.mediaType + this.mCurrentPath = this.item.path + this.mMenuLevel = MenuLevel.MENU_SECOND_LEVEL_BY_FOLD + }) } - .height(56) - .width('100%') // TODO - .backgroundColor(this.item.list_background) - .onClick(() => { - this.mType = this.item.mediaType - this.mCurrentPath = this.item.path - this.mMenuLevel = menuLevel.MENU_SECOND_LEVEL_BY_FOLD - }) - } } \ No newline at end of file diff --git a/product/phone/src/main/ets/pages/SecondLevelByFold.ets b/product/phone/src/main/ets/pages/SecondLevelByFold.ets index f715437..1ff195b 100644 --- a/product/phone/src/main/ets/pages/SecondLevelByFold.ets +++ b/product/phone/src/main/ets/pages/SecondLevelByFold.ets @@ -13,125 +13,125 @@ * limitations under the License. */ -import { FileInfo } from '../module/FileInfo' -import { changeTypeToString, updateTopPathInfo } from '../module/Utils' -import { LogInfo, LogDebug } from '../module/LogUtils' -import { menuLevel } from '../module/Constants' -import { getListFile } from '../module/FileManagerServiceUtils' +import { MenuLevel } from '../../../../../../common/src/main/ets/components/Data/Constants' +import { FileInfo } from '../../../../../../common/src/main/ets/components/Data/FileInfo' +import { getListFile } from '../../../../../../common/src/main/ets/components/Utils/FileManagerServiceUtils' +import { logDebug, logInfo } from '../../../../../../common/src/main/ets/components/Utils/LogUtils' +import { changeTypeToString, updateTopPathInfo } from '../../../../../../common/src/main/ets/components/utils/Utils' let TAG: string = 'SecondLevelByFold' @Component export struct SecondLevelByFold { - private mWorker - @Link mFileList: FileInfo[] - @Link @Watch('fileTypeChange') mType: string - @Link mMenuLevel: number - @Link mCurrentPath: string + private mWorker + @Link mFileList: FileInfo[] + @Link @Watch('fileTypeChange') mType: string + @Link mMenuLevel: number + @Link mCurrentPath: string - aboutToAppear(): void{ - LogInfo(TAG, 'aboutToAppear') - if (globalThis.debugMode) { - this.mFileList = getListFile('local', this.mType, this.mCurrentPath) - LogDebug(TAG, 'mFileList length = ' + this.mFileList.length) - } else { - this.mWorker.postMessage({ - request_data: 'listFile', - device_name: 'local', - menu_level: this.mMenuLevel, - media_type: this.mType, - path: this.mCurrentPath - }) - } - - updateTopPathInfo([], '文件类型', '') - updateTopPathInfo(AppStorage.Get('topPathInfo'), changeTypeToString(this.mType), this.mCurrentPath) - } - - fileTypeChange() { - LogInfo(TAG, 'fileTypeChange ' + this.mType) - if (globalThis.debugMode) { - this.mFileList = getListFile('local', this.mType, this.mCurrentPath) - } else { - this.mWorker.postMessage({ - request_data: 'listFile', - device_name: 'local', - menu_level: this.mMenuLevel, - media_type: this.mType, - path: this.mCurrentPath - }) - } - } - - build() { - Column() { - ForEach(this.mFileList, (item: FileInfo, index: number) => { - Column() { - SecondRowView({ - item: item, - mMenuLevel: $mMenuLevel, - mCurrentPath: $mCurrentPath, - isType: $mType - }) - - Divider() - .color('#000000') - .opacity(0.05) - .visibility(this.mFileList.length == index + 1 ? Visibility.Hidden : Visibility.Visible) - .margin({ left: 40 }) + aboutToAppear(): void{ + logInfo(TAG, 'aboutToAppear') + if (globalThis.debugMode) { + this.mFileList = getListFile('local', this.mType, this.mCurrentPath) + logDebug(TAG, 'mFileList length = ' + this.mFileList.length) + } else { + this.mWorker.postMessage({ + request_data: 'listFile', + device_name: 'local', + menu_level: this.mMenuLevel, + MediaType: this.mType, + path: this.mCurrentPath + }) } - .width('100%') - .height(56) - }, item => item.name.toString()) + + updateTopPathInfo([], '文件类型', '') + updateTopPathInfo(AppStorage.Get('topPathInfo'), changeTypeToString(this.mType), this.mCurrentPath) + } + + fileTypeChange() { + logInfo(TAG, 'fileTypeChange ' + this.mType) + if (globalThis.debugMode) { + this.mFileList = getListFile('local', this.mType, this.mCurrentPath) + } else { + this.mWorker.postMessage({ + request_data: 'listFile', + device_name: 'local', + menu_level: this.mMenuLevel, + MediaType: this.mType, + path: this.mCurrentPath + }) + } + } + + build() { + Column() { + ForEach(this.mFileList, (item: FileInfo, index: number) => { + Column() { + SecondRowView({ + item: item, + mMenuLevel: $mMenuLevel, + mCurrentPath: $mCurrentPath, + isType: $mType + }) + + Divider() + .color('#000000') + .opacity(0.05) + .visibility(this.mFileList.length == index + 1 ? Visibility.Hidden : Visibility.Visible) + .margin({ left: 40 }) + } + .width('100%') + .height(56) + }, item => item.name.toString()) + } + .padding({ top: 4, bottom: 4, left: 12, right: 12 }) + .width('100%') + .alignItems(HorizontalAlign.Start) + .border({ radius: 24 }) + .opacity(0.9) + .backgroundColor(Color.White) } - .padding({ top: 4, bottom: 4, left: 12, right: 12 }) - .width('100%') - .alignItems(HorizontalAlign.Start) - .border({ radius: 24 }) - .opacity(0.9) - .backgroundColor(Color.White) - } } @Component struct SecondRowView { - private item: FileInfo = new FileInfo('') - @Link mMenuLevel: number - @Link mCurrentPath: string - @Link isType: string + private item: FileInfo = new FileInfo('') + @Link mMenuLevel: number + @Link mCurrentPath: string + @Link isType: string - build() { - Row() { - Image($r("app.media.ic_type_smallfile")) - .width(24) - .height(24) - Text(this.item.name) - .fontSize(16) - .fontColor('#182431') - .fontWeight(FontWeight.Medium) - .margin({ left: 17 }) - Blank() - Image($r("app.media.ic_right")) - .width(12) - .height(24) - } - .height(56) - .width('100%') // TODO - .backgroundColor(this.item.list_background) - .onClick(() => { - LogInfo(TAG, 'onClick this.mCurrentPath = ' + this.mCurrentPath) - this.mCurrentPath = this.item.path - updateTopPathInfo(AppStorage.Get('topPathInfo'), this.item.name, this.mCurrentPath) - - if (this.item.path.includes('dataability:///album') == false) { - if (this.isType != 'file') { - LogInfo(TAG, 'MENU_THIRD_LEVEL_HAS_PIC - onClick') - this.mMenuLevel = menuLevel.MENU_THIRD_LEVEL_HAS_PIC - } else { - this.mMenuLevel = menuLevel.MENU_THIRD_LEVEL_HAS_DETAIL - LogInfo(TAG, 'MENU_THIRD_LEVEL_HAS_DETAIL - onClick') + build() { + Row() { + Image($r("app.media.ic_type_smallfile")) + .width(24) + .height(24) + Text(this.item.name) + .fontSize(16) + .fontColor('#182431') + .fontWeight(FontWeight.Medium) + .margin({ left: 17 }) + Blank() + Image($r("app.media.ic_right")) + .width(12) + .height(24) } - } - }) - } + .height(56) + .width('100%') // TODO + .backgroundColor(this.item.list_background) + .onClick(() => { + logInfo(TAG, 'onClick this.mCurrentPath = ' + this.mCurrentPath) + this.mCurrentPath = this.item.path + updateTopPathInfo(AppStorage.Get('topPathInfo'), this.item.name, this.mCurrentPath) + + if (this.item.path.includes('dataability:///album') == false) { + if (this.isType != 'file') { + logInfo(TAG, 'MENU_THIRD_LEVEL_HAS_PIC - onClick') + this.mMenuLevel = MenuLevel.MENU_THIRD_LEVEL_HAS_PIC + } else { + this.mMenuLevel = MenuLevel.MENU_THIRD_LEVEL_HAS_DETAIL + logInfo(TAG, 'MENU_THIRD_LEVEL_HAS_DETAIL - onClick') + } + } + }) + } } \ No newline at end of file diff --git a/product/phone/src/main/ets/pages/ThirdLevelHasDetail.ets b/product/phone/src/main/ets/pages/ThirdLevelHasDetail.ets index e363448..61484b4 100644 --- a/product/phone/src/main/ets/pages/ThirdLevelHasDetail.ets +++ b/product/phone/src/main/ets/pages/ThirdLevelHasDetail.ets @@ -13,209 +13,210 @@ * limitations under the License. */ -import { FileInfo } from '../module/FileInfo' -import { LogInfo } from '../module/LogUtils' -import { getShowIconBySuffix, updateTopPathInfo } from '../module/Utils' -import { media_type } from '../module/Constants' -import { ChooseDialog } from '../module/DialogUtils' -import { getListFile } from '../module/FileManagerServiceUtils' +import { MediaType } from '../../../../../../common/src/main/ets/components/Data/Constants' +import { FileInfo } from '../../../../../../common/src/main/ets/components/Data/FileInfo' +import { logInfo } from '../../../../../../common/src/main/ets/components/Utils/LogUtils' +import { getListFile } from '../../../../../../common/src/main/ets/components/Utils/FileManagerServiceUtils' +import { getShowIconBySuffix, updateTopPathInfo } from '../../../../../../common/src/main/ets/components/utils/utils' +import { ChooseDialog } from '../../../../../../common/src/main/ets/components/View/ChooseDialog' let TAG: string = 'ThirdLevelHasDetail' @Component export struct ThirdLevelHasDetail { - private mCurrentMode: string - private mWorker - @Link mFileInfo: Array - @Link @Watch('refreshFiles') mCurrentPath: string - @Link mMenuLevel: number - @Link mType: string + private mCurrentMode: string + private mWorker + @Link mFileInfo: Array + @Link @Watch('refreshFiles') mCurrentPath: string + @Link mMenuLevel: number + @Link mType: string - private aboutToAppear(): void{ - LogInfo(TAG, 'aboutToAppear') - if (globalThis.debugMode) { - this.mFileInfo = getListFile('local', this.mType, this.mCurrentPath) - } else { - this.mWorker.postMessage({ - request_data: 'listFile', - device_name: 'local', - menu_level: this.mMenuLevel, - media_type: this.mType, - path: this.mCurrentPath - }) - } - } - - private aboutToDisappear() { - LogInfo(TAG, 'aboutToDisappear') - AppStorage.Set('choseFiles', []) - } - - refreshFiles() { - LogInfo(TAG, 'refreshFiles') - AppStorage.Set('choseFiles', []) - - this.mWorker.postMessage({ - request_data: 'listFile', - device_name: 'local', - menu_level: this.mMenuLevel, - media_type: this.mType, - path: this.mCurrentPath - }) - } - - build() { - Column() { - Flex({ - direction: FlexDirection.Row, - wrap: FlexWrap.Wrap, - justifyContent: FlexAlign.Start, - alignItems: ItemAlign.Start - }) { - ForEach(this.mFileInfo, (item: FileInfo, index: number) => { - Column() { - DetailRowView({ - item: item, - mMenuLevel: $mMenuLevel, - mCurrentPath: $mCurrentPath + private aboutToAppear(): void{ + logInfo(TAG, 'aboutToAppear') + if (globalThis.debugMode) { + this.mFileInfo = getListFile('local', this.mType, this.mCurrentPath) + } else { + this.mWorker.postMessage({ + request_data: 'listFile', + device_name: 'local', + menu_level: this.mMenuLevel, + MediaType: this.mType, + path: this.mCurrentPath }) - - Divider() - .color('#000000') - .opacity(0.05) - .visibility(this.mFileInfo.length == index + 1 ? Visibility.Hidden : Visibility.Visible) - .margin({ left: 64, right: 12 }) - } - }, (item: FileInfo) => item.name) - } + } + } + + private aboutToDisappear() { + logInfo(TAG, 'aboutToDisappear') + AppStorage.Set('choseFiles', []) + } + + refreshFiles() { + logInfo(TAG, 'refreshFiles') + AppStorage.Set('choseFiles', []) + if (!globalThis.debugMode) { + this.mWorker.postMessage({ + request_data: 'listFile', + device_name: 'local', + menu_level: this.mMenuLevel, + MediaType: this.mType, + path: this.mCurrentPath + }) + } + } + + build() { + Column() { + Flex({ + direction: FlexDirection.Row, + wrap: FlexWrap.Wrap, + justifyContent: FlexAlign.Start, + alignItems: ItemAlign.Start + }) { + ForEach(this.mFileInfo, (item: FileInfo, index: number) => { + Column() { + DetailRowView({ + item: item, + mMenuLevel: $mMenuLevel, + mCurrentPath: $mCurrentPath + }) + + Divider() + .color('#000000') + .opacity(0.05) + .visibility(this.mFileInfo.length == index + 1 ? Visibility.Hidden : Visibility.Visible) + .margin({ left: 64, right: 12 }) + } + }, (item: FileInfo) => item.name) + } + } + .padding({ bottom: 4 }) + .alignItems(HorizontalAlign.Start) + .border({ radius: 24 }) + .opacity(0.9) + .backgroundColor(Color.White) } - .padding({ bottom: 4 }) - .alignItems(HorizontalAlign.Start) - .border({ radius: 24 }) - .opacity(0.9) - .backgroundColor(Color.White) - } } @Component struct DetailRowView { - private dialogController: CustomDialogController = new CustomDialogController({ - builder: ChooseDialog(), - cancel: () => { - }, - autoCancel: true - }) - @State item: FileInfo = new FileInfo('') - @Link mCurrentPath: string - @Link mMenuLevel: number - @StorageLink('choseFiles') tmpChoseFiles: Array = [] - - build() { - Row() { - if (this.item.type == media_type.MEDIA_TYPE_ALBUM) { - Row() { - Image($r("app.media.ic_type_bigfile")) - .width(40) - .height(40) - .margin({ left: 10 }) - Text(this.item.name) - .fontSize(16) - .fontColor('#182431') - .fontWeight(FontWeight.Medium) - .margin({ left: 16 }) - .maxLines(1) - .textOverflow({ overflow: TextOverflow.Ellipsis }) - Blank() - Image($r("app.media.ic_right")) - .width(12) - .height(24) - .margin({ right: 12 }) - } - .margin({ right: 12 }) - .height(64) - .width('100%') - .backgroundColor(this.item.list_background) - } else { - Row() { - Image(getShowIconBySuffix(this.item.name.substring(this.item.name.lastIndexOf('.')))) - .width(40) - .height(40) - .margin({ left: 8 }) - Column() { - Text(this.item.name) - .height(22) - .fontSize(16) - .fontColor(this.item.font_color) - .fontWeight(FontWeight.Medium) - .maxLines(1) - .textOverflow({ overflow: TextOverflow.Ellipsis }) - .margin({ top: 10 }) - .height(22) - .width(248) - Row() { - Text('' + this.item.modified_time) - .fontSize(14) - .fontColor(this.item.font_color) - .fontWeight(FontWeight.Regular) - .maxLines(1) - .textOverflow({ overflow: TextOverflow.Ellipsis }) - Text('-') - .fontSize(14) - .fontColor(this.item.font_color) - .margin({ left: '8vp' }) - Text('' + this.item.size) - .fontSize(14) - .fontColor(this.item.font_color) - .fontWeight(FontWeight.Regular) - .margin({ left: '8vp' }) - .maxLines(1) - .textOverflow({ overflow: TextOverflow.Ellipsis }) - } - .width(248) - .height(19) - .margin({ top: 2 }) - .opacity(0.6) - } - .height(64) - .alignItems(HorizontalAlign.Start) - .margin({ left: 16 }) - } - .width('100%') - .height(64) // TODO - - } - } - .margin({ top: 4, left: 4, right: 4 }) - .border({ radius: 20 }) - .backgroundColor(this.item.list_background) - .onClick(() => { - if (this.item.type == media_type.MEDIA_TYPE_ALBUM) { - LogInfo(TAG, 'fold onClick') - this.mCurrentPath = this.item.path - updateTopPathInfo(AppStorage.Get('topPathInfo'), this.item.name, this.item.path) - } else { - var index = this.tmpChoseFiles.indexOf(this.item) - if (index == -1) { - this.item.font_color = Color.Black - this.item.opacity = 0.1 - this.item.list_background = 'rgba(46,136,255,0.1)' - this.tmpChoseFiles.push(this.item) - } else { - this.item.font_color = Color.Black - this.item.opacity = 1 - this.item.list_background = '' - this.tmpChoseFiles.splice(index, 1) - } - } + private dialogController: CustomDialogController = new CustomDialogController({ + builder: ChooseDialog(), + cancel: () => { + }, + autoCancel: true }) - .gesture( - LongPressGesture({ repeat: false }) - .onAction((event: GestureEvent) => { - if (this.item.type != media_type.MEDIA_TYPE_ALBUM) { - AppStorage.SetOrCreate('selectedFileInfo', this.item) - this.dialogController.open() + @State item: FileInfo = new FileInfo('') + @Link mCurrentPath: string + @Link mMenuLevel: number + @StorageLink('choseFiles') tmpChoseFiles: Array = [] + + build() { + Row() { + if (this.item.type == MediaType.MEDIA_TYPE_ALBUM) { + Row() { + Image($r("app.media.ic_type_bigfile")) + .width(40) + .height(40) + .margin({ left: 10 }) + Text(this.item.name) + .fontSize(16) + .fontColor('#182431') + .fontWeight(FontWeight.Medium) + .margin({ left: 16 }) + .maxLines(1) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + Blank() + Image($r("app.media.ic_right")) + .width(12) + .height(24) + .margin({ right: 12 }) + } + .margin({ right: 12 }) + .height(64) + .width('100%') + .backgroundColor(this.item.list_background) + } else { + Row() { + Image(getShowIconBySuffix(this.item.name.substring(this.item.name.lastIndexOf('.')))) + .width(40) + .height(40) + .margin({ left: 8 }) + Column() { + Text(this.item.name) + .height(22) + .fontSize(16) + .fontColor(this.item.font_color) + .fontWeight(FontWeight.Medium) + .maxLines(1) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + .margin({ top: 10 }) + .height(22) + .width(248) + Row() { + Text('' + this.item.modified_time) + .fontSize(14) + .fontColor(this.item.font_color) + .fontWeight(FontWeight.Regular) + .maxLines(1) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + Text('-') + .fontSize(14) + .fontColor(this.item.font_color) + .margin({ left: '8vp' }) + Text('' + this.item.size) + .fontSize(14) + .fontColor(this.item.font_color) + .fontWeight(FontWeight.Regular) + .margin({ left: '8vp' }) + .maxLines(1) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + } + .width(248) + .height(19) + .margin({ top: 2 }) + .opacity(0.6) + } + .height(64) + .alignItems(HorizontalAlign.Start) + .margin({ left: 16 }) + } + .width('100%') + .height(64) // TODO + + } } - }) - ) - } + .margin({ top: 4, left: 4, right: 4 }) + .border({ radius: 20 }) + .backgroundColor(this.item.list_background) + .onClick(() => { + if (this.item.type == MediaType.MEDIA_TYPE_ALBUM) { + logInfo(TAG, 'fold onClick') + this.mCurrentPath = this.item.path + updateTopPathInfo(AppStorage.Get('topPathInfo'), this.item.name, this.item.path) + } else { + var index = this.tmpChoseFiles.indexOf(this.item) + if (index == -1) { + this.item.font_color = Color.Black + this.item.opacity = 0.1 + this.item.list_background = 'rgba(46,136,255,0.1)' + this.tmpChoseFiles.push(this.item) + } else { + this.item.font_color = Color.Black + this.item.opacity = 1 + this.item.list_background = '' + this.tmpChoseFiles.splice(index, 1) + } + } + }) + .gesture( + LongPressGesture({ repeat: false }) + .onAction((event: GestureEvent) => { + if (this.item.type != MediaType.MEDIA_TYPE_ALBUM) { + AppStorage.SetOrCreate('selectedFileInfo', this.item) + this.dialogController.open() + } + }) + ) + } } \ No newline at end of file diff --git a/product/phone/src/main/ets/pages/ThirdLevelHasPic.ets b/product/phone/src/main/ets/pages/ThirdLevelHasPic.ets index 1b61a3e..89b720c 100644 --- a/product/phone/src/main/ets/pages/ThirdLevelHasPic.ets +++ b/product/phone/src/main/ets/pages/ThirdLevelHasPic.ets @@ -13,145 +13,146 @@ * limitations under the License. */ -import { FileInfo } from '../module/FileInfo' -import { LogInfo, LogDebug } from '../module/LogUtils' -import { getListFile } from '../module/FileManagerServiceUtils' -import { ChooseDialog } from '../module/DialogUtils' +import { FileInfo } from '../../../../../../common/src/main/ets/components/Data/FileInfo' +import { getListFile } from '../../../../../../common/src/main/ets/components/Utils/FileManagerServiceUtils' +import { logDebug, logInfo } from '../../../../../../common/src/main/ets/components/Utils/LogUtils' +import { ChooseDialog } from '../../../../../../common/src/main/ets/components/View/ChooseDialog' let TAG: string = 'ThirdLevelHasPic' @Component export struct ThirdLevelHasPic { - private mColumnTemplate: string - private mCurrentMode: string - private mCurrentIndex: number - private mWorker - @Link mFileList: Array - @Link mMenuLevel: number - @Link mType: string - @Link mCurrentPath: string - @StorageLink('choseFiles') tmpFiles: Array = [] + private mColumnTemplate: string + private mCurrentMode: string + private mCurrentIndex: number + private mWorker + @Link mFileList: Array + @Link mMenuLevel: number + @Link mType: string + @Link mCurrentPath: string + @StorageLink('choseFiles') tmpFiles: Array = [] - aboutToAppear() { - if (globalThis.debugMode) { - this.mFileList = getListFile('local', this.mType, this.mCurrentPath) - LogDebug(TAG, 'mFileList length = ' + this.mFileList.length) - } else { - this.mWorker.postMessage({ - request_data: 'listFile', - device_name: 'local', - menu_level: this.mMenuLevel, - media_type: this.mType, - path: this.mCurrentPath, - offset: 0, - count: 100 - }) - } - } - - private aboutToDisappear() { - LogInfo(TAG, 'aboutToDisappear') - AppStorage.Set('choseFiles', []) - } - - build() { - if (globalThis.startMode == 'choose') { - Column() { - Flex({ - direction: FlexDirection.Row, - wrap: FlexWrap.Wrap, - justifyContent: FlexAlign.Start, - alignItems: ItemAlign.Start - }) { - ForEach(this.mFileList, (item: FileInfo) => { - GridItemView({ gridItem: item }) - }, item => item.name) + aboutToAppear() { + logInfo(TAG, 'aboutToAppear send message to worker') + if (globalThis.debugMode) { + this.mFileList = getListFile('local', this.mType, this.mCurrentPath) + logDebug(TAG, 'mFileList length = ' + this.mFileList.length) + } else { + this.mWorker.postMessage({ + request_data: 'listFile', + device_name: 'local', + menu_level: this.mMenuLevel, + MediaType: this.mType, + path: this.mCurrentPath, + offset: 0, + count: 100 + }) } - .margin({ top: 8 }) - } - .alignItems(HorizontalAlign.Start) - .border({ radius: 24 }) - .opacity(0.9) - .backgroundColor(Color.White) } - } + private aboutToDisappear() { + logInfo(TAG, 'aboutToDisappear') + AppStorage.Set('choseFiles', []) + } + + build() { + if (globalThis.startMode == 'choose') { + Column() { + Flex({ + direction: FlexDirection.Row, + wrap: FlexWrap.Wrap, + justifyContent: FlexAlign.Start, + alignItems: ItemAlign.Start + }) { + ForEach(this.mFileList, (item: FileInfo) => { + GridItemView({ gridItem: item }) + }, item => item.name) + } + .margin({ top: 8 }) + } + .alignItems(HorizontalAlign.Start) + .border({ radius: 24 }) + .opacity(0.9) + .backgroundColor(Color.White) + } + + } } @Component struct GridItemView { - private dialogController: CustomDialogController = new CustomDialogController({ - builder: ChooseDialog(), - cancel: () => { - }, - autoCancel: true - }) - @State gridItem: FileInfo = new FileInfo('') - - build() { - Flex({ - direction: FlexDirection.Column, - alignItems: ItemAlign.Center, - justifyContent: FlexAlign.Center - }) { - Image(`${this.gridItem.path}/thumbnail/160/160`) - .borderRadius(12) - .objectFit(ImageFit.Contain) - .width(80) - .height(80) - .margin({ - left: 8, - right: 8, - top: 4 - }) - Row() { - Text(this.gridItem.name) - .width(82) - .fontSize(12) - .fontColor(this.gridItem.list_background == 'rgba(46,136,255,0.1)' ? Color.White : Color.Black) - .fontWeight(FontWeight.Regular) - .opacity(0.9) - .textAlign(TextAlign.Center) - .maxLines(2) - .textOverflow({ overflow: TextOverflow.Ellipsis }) - .margin({ top: 2 }) - .padding({ right: 4, left: 4 }) - } - .borderRadius(12) - .backgroundColor(this.gridItem.list_background == 'rgba(46,136,255,0.1)' ? 0x2E8BFF : '') - .alignItems(VerticalAlign.Top) - .width(82) - .height(36) - .margin({ top: 4 }) - } - .padding({ bottom: 8 }) - .width(96) - .height(126) - .margin({ bottom: 12, left: 12 }) - .border({ radius: 20 }) - .backgroundColor(this.gridItem.list_background) - .gesture( - LongPressGesture({ repeat: false }) - .onAction((event: GestureEvent) => { - AppStorage.SetOrCreate('selectedFileInfo', this.gridItem) - this.dialogController.open() - }) - ) - .onClick(() => { - let choseFiles: Array = AppStorage.Get('choseFiles') - let index: number = choseFiles.indexOf(this.gridItem) - if (index == -1) { - this.gridItem.opacity = 0.1 - this.gridItem.font_color = '#FFFFFF' - this.gridItem.list_background = 'rgba(46,136,255,0.1)' - choseFiles.push(this.gridItem) - } else { - choseFiles.splice(index) - this.gridItem.opacity = 1 - this.gridItem.font_color = '#000000' - this.gridItem.list_background = '' - } + private dialogController: CustomDialogController = new CustomDialogController({ + builder: ChooseDialog(), + cancel: () => { + }, + autoCancel: true }) + @State gridItem: FileInfo = new FileInfo('') - } + build() { + Flex({ + direction: FlexDirection.Column, + alignItems: ItemAlign.Center, + justifyContent: FlexAlign.Center + }) { + Image(`${this.gridItem.path}/thumbnail/160/160`) + .borderRadius(12) + .objectFit(ImageFit.Contain) + .width(80) + .height(80) + .margin({ + left: 8, + right: 8, + top: 4 + }) + Row() { + Text(this.gridItem.name) + .width(82) + .fontSize(12) + .fontColor(this.gridItem.list_background == 'rgba(46,136,255,0.1)' ? Color.White : Color.Black) + .fontWeight(FontWeight.Regular) + .opacity(0.9) + .textAlign(TextAlign.Center) + .maxLines(2) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + .margin({ top: 2 }) + .padding({ right: 4, left: 4 }) + } + .borderRadius(12) + .backgroundColor(this.gridItem.list_background == 'rgba(46,136,255,0.1)' ? 0x2E8BFF : '') + .alignItems(VerticalAlign.Top) + .width(82) + .height(36) + .margin({ top: 4 }) + } + .padding({ bottom: 8 }) + .width(96) + .height(126) + .margin({ bottom: 12, left: 12 }) + .border({ radius: 20 }) + .backgroundColor(this.gridItem.list_background) + .gesture( + LongPressGesture({ repeat: false }) + .onAction((event: GestureEvent) => { + AppStorage.SetOrCreate('selectedFileInfo', this.gridItem) + this.dialogController.open() + }) + ) + .onClick(() => { + let choseFiles: Array = AppStorage.Get('choseFiles') + let index: number = choseFiles.indexOf(this.gridItem) + if (index == -1) { + this.gridItem.opacity = 0.1 + this.gridItem.font_color = '#FFFFFF' + this.gridItem.list_background = 'rgba(46,136,255,0.1)' + choseFiles.push(this.gridItem) + } else { + choseFiles.splice(index) + this.gridItem.opacity = 1 + this.gridItem.font_color = '#000000' + this.gridItem.list_background = '' + } + }) + + } } \ No newline at end of file diff --git a/product/phone/src/main/ets/pages/index.ets b/product/phone/src/main/ets/pages/index.ets index d9327bc..6b301a0 100644 --- a/product/phone/src/main/ets/pages/index.ets +++ b/product/phone/src/main/ets/pages/index.ets @@ -18,429 +18,432 @@ import { FirstLevelByType } from './FirstLevelByType' import { SecondLevelByFold } from './SecondLevelByFold' import { ThirdLevelHasDetail } from '../pages/ThirdLevelHasDetail' import { ThirdLevelHasPic } from '../pages/ThirdLevelHasPic' -import { FileInfo, TopPathInfo } from '../module/FileInfo' -import { menuLevel, terminate_reason, media_type } from '../module/Constants' -import { LogInfo, LogDebug } from '../module/LogUtils' -import { changeStringToType, updateTopPathInfo } from '../module/Utils' -import { terminateSelfWithResult } from '../module/AbilityUtils' -import { WarningDialog } from '../module/DialogUtils' -import { getFirstMenu } from '../module/FileManagerServiceUtils' +import { MenuLevel, TerminateReason, MediaType } from '../../../../../../common/src/main/ets/components/Data/Constants' +import { FileInfo } from '../../../../../../common/src/main/ets/components/Data/FileInfo' +import { TopPathInfo } from '../../../../../../common/src/main/ets/components/Data/TopPathInfo' +import { terminateSelfWithResult } from '../../../../../../common/src/main/ets/components/utils/AbilityUtils' +import { getFirstMenu } from '../../../../../../common/src/main/ets/components/Utils/FileManagerServiceUtils' +import { logInfo, logDebug, logError } from '../../../../../../common/src/main/ets/components/Utils/LogUtils' +import { changeStringToType, updateTopPathInfo } from '../../../../../../common/src/main/ets/components/utils/Utils' +import { WarningDialog } from '../../../../../../common/src/main/ets/components/View/WarningDialog' @Entry @Component struct allIndex { - build() { - Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.End, justifyContent: FlexAlign.SpaceBetween }) { - Stack({ alignContent: Alignment.Bottom }) { - Column() { + private TAG: string= 'Main' + + build() { + Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.End, justifyContent: FlexAlign.SpaceBetween }) { + Stack({ alignContent: Alignment.Bottom }) { + Column() { + } + .onClick(() => { + globalThis.context.terminateSelf((err, data) => { + logInfo(this.TAG, 'terminateSelf success') + }) + }) + .width('100%') + .height('100%') + + Index() + } + .width('100%') + .height('100%') } - .onClick(() => { - globalThis.context.terminateSelf((err, data) => { - console.log('terminateSelf success') - }) - }) + .backgroundColor('rgba(0,0,0,0.1)') + .position({ x: 0, y: 0 }) .width('100%') .height('100%') - - Index() - } - .width('100%') - .height('100%') } - .backgroundColor('rgba(0,0,0,0.1)') - .position({ x: 0, y: 0 }) - .width('100%') - .height('100%') - } } @Component struct Index { - private TAG: string= 'Main' - private mWorker - private customDialogController: CustomDialogController = new CustomDialogController({ - builder: WarningDialog({ code: $code }) - }) - @State mFirstMenuData: FileInfo[] = [] - @State mSecondMenuData: FileInfo[] = [] - @State mThirdMenuPicData: FileInfo[]= [] - @State mThirdMenuDetailData: FileInfo[]= [] - @State mType: string = '' - @State mMenuLevel: number = menuLevel.MENU_FIRST_LEVEL_BY_TYPE - @State mCurrentPath: string= '' - @State code: number = 2; - @StorageLink('startMode') mCurrentMode: string = 'choose' - @StorageLink('topPathInfo') topPathInfo: Array = updateTopPathInfo([], '文件类型', '') - scroller: Scroller = new Scroller() + private TAG: string= 'Main' + private mWorker + private customDialogController: CustomDialogController = new CustomDialogController({ + builder: WarningDialog({ code: $code }) + }) + @State mFirstMenuData: FileInfo[] = [] + @State mSecondMenuData: FileInfo[] = [] + @State mThirdMenuPicData: FileInfo[]= [] + @State mThirdMenuDetailData: FileInfo[]= [] + @State mType: string = '' + @State mMenuLevel: number = MenuLevel.MENU_FIRST_LEVEL_BY_TYPE + @State mCurrentPath: string= '' + @State code: number = 2; + @StorageLink('startMode') mCurrentMode: string = 'choose' + @StorageLink('topPathInfo') topPathInfo: Array = updateTopPathInfo([], '文件类型', '') + scroller: Scroller = new Scroller() - aboutToAppear() { - LogInfo(this.TAG, 'aboutToAppear') - if (globalThis.debugMode) { - this.mFirstMenuData = getFirstMenu('') - LogDebug(this.TAG, 'mFirstMenuData length = ' + this.mFirstMenuData.length) - } else { - this.initWork() - LogInfo(this.TAG, 'send message to worker') - this.mWorker.postMessage({ - request_data: 'getRoot', - device_name: 'local', - menu_level: this.mMenuLevel, - media_type: this.mType, - path: this.mCurrentPath - }) - } - } - - private initWork() { - if (this.mWorker == undefined) { - LogInfo(this.TAG, 'initWorker') - this.mWorker = new worker.Worker('phone/ets/workers/DataWorker.js', { type: 'classic', name: 'filePicker' }) - this.mWorker.onerror = this.onError.bind(this) - this.mWorker.onmessageerror = this.onMessageError.bind(this) - this.mWorker.onexit = this.onExit.bind(this) - this.mWorker.onmessage = this.onMessage.bind(this) - } - } - - private onError(e): void{ - LogInfo(this.TAG, 'onError = ' + JSON.stringify(e)) - } - - private onMessageError(e): void{ - LogInfo(this.TAG, 'onMessageError = ' + JSON.stringify(e)) - } - - private onExit(): void{ - LogInfo(this.TAG, 'onExit') - this.mWorker = undefined - } - - private onMessage(result) { - LogInfo(this.TAG, 'main thread onMessage') - var params = result.data.params - var file = JSON.parse(String.fromCharCode.apply(null, new Uint16Array(result.data.data))) - if (params.request_data == 'createFile') { - if (file.code == undefined) { - terminateSelfWithResult(terminate_reason.SUCCESS, file) - } else { - if (params.path == 'dataability:///album') { - this.code = 2; - this.customDialogController.open() + aboutToAppear() { + logInfo(this.TAG, 'aboutToAppear') + if (globalThis.debugMode) { + this.mFirstMenuData = getFirstMenu('') + logDebug(this.TAG, 'mFirstMenuData length = ' + this.mFirstMenuData.length) } else { - this.code = file.code - this.customDialogController.open() + this.initWork() + logInfo(this.TAG, 'send message to worker') + this.mWorker.postMessage({ + request_data: 'getRoot', + device_name: 'local', + menu_level: this.mMenuLevel, + MediaType: this.mType, + path: this.mCurrentPath + }) } - } - return } - if (Array.isArray(file)) { - let listData: Array = [] - for (var index = 0;index < file.length; index++) { - var info = file[index] - let item = new FileInfo(info.name) - item.path = info.path - item.type = info.type - item.size = info.size - item.dataAdded_time = info.added_time - item.modified_time = info.modified_time - if (params.menu_level == menuLevel.MENU_FIRST_LEVEL_BY_TYPE) { - if (item.name == 'image_album') { - item.name = '图片' - item.mediaType = 'image' - item.thumbnail = $r("app.media.ic_type_image") - } else if (item.name == 'video_album') { - item.name = '视频' - item.mediaType = 'video' - item.thumbnail = $r("app.media.ic_type_video") - } else if (item.name == 'audio_album') { - item.name = '音乐' - item.mediaType = 'audio' - item.thumbnail = $r("app.media.ic_type_audio") - } else if (item.name == 'file_folder') { - item.name = '文档' - item.mediaType = 'file' - item.thumbnail = $r("app.media.ic_type_file") - } - } - if (params.menu_level == menuLevel.MENU_THIRD_LEVEL_HAS_DETAIL) { - if (this.mCurrentMode == 'save' && item.type != media_type.MEDIA_TYPE_ALBUM) { - break - } + private initWork() { + if (this.mWorker == undefined) { + logInfo(this.TAG, 'initWorker') + this.mWorker = new worker.Worker('phone/ets/workers/DataWorker.js', { type: 'classic', name: 'filePicker' }) + this.mWorker.onerror = this.onError.bind(this) + this.mWorker.onmessageerror = this.onMessageError.bind(this) + this.mWorker.onexit = this.onExit.bind(this) + this.mWorker.onmessage = this.onMessage.bind(this) } - listData.push(item) - } - if (params.menu_level == menuLevel.MENU_FIRST_LEVEL_BY_TYPE && params.request_data == 'getRoot') { - LogDebug(this.TAG, 'mFirstMenuData length = ' + listData.length) - this.mFirstMenuData = listData - } else if (params.menu_level == menuLevel.MENU_SECOND_LEVEL_BY_FOLD) { - LogDebug(this.TAG, 'mSecondMenuData length = ' + listData.length) - this.mSecondMenuData = listData - } else if (params.menu_level == menuLevel.MENU_THIRD_LEVEL_HAS_PIC) { - LogDebug(this.TAG, 'mThirdMenuPicData length = ' + listData.length) - this.mThirdMenuPicData = listData - } else if (params.menu_level == menuLevel.MENU_THIRD_LEVEL_HAS_DETAIL) { - LogDebug(this.TAG, 'mThirdMenuDetailData length = ' + listData.length) - if (listData.length > 0) { - this.mThirdMenuDetailData = listData - } else { - this.mThirdMenuDetailData = [] - } - } } - } - build() { - Column() { - TopBarArea() + private onError(e): void{ + logError(this.TAG, 'onError = ' + JSON.stringify(e)) + } - Column() { - Column() { - Row() { - List() { - ForEach(this.topPathInfo, (item: TopPathInfo) => { - ListItem() { - Row() { - if (item.name != '文件类型') { - Image($r("app.media.ic_public_right")) - .width(12) - .height(24) - .margin({ - left: 4, - right: 4 - }) - } + private onMessageError(e): void{ + logError(this.TAG, 'onMessageError = ' + JSON.stringify(e)) + } - Text(item.name) - .height(24) - .fontColor('#000000') - .fontSize(16) - .fontWeight(FontWeight.Medium) - .opacity(item.opacity) - .onClick(() => { - LogInfo(this.TAG, item.name + ' onClick') - if (item.name == '文件类型') { - updateTopPathInfo([], '文件类型', '') - this.mMenuLevel = menuLevel.MENU_FIRST_LEVEL_BY_TYPE - this.mType = '' - } else if (this.mMenuLevel == menuLevel.MENU_THIRD_LEVEL_HAS_DETAIL) { - this.mCurrentPath = item.path - LogInfo(this.TAG, 'item.path' + item.path) - let topPathInfo: Array = AppStorage.Get('topPathInfo') - let index: number = topPathInfo.indexOf(item) - if (index != -1) { - var deleteNum = topPathInfo.length - index + 1 - topPathInfo.splice(index + 1, deleteNum) - topPathInfo[topPathInfo.length - 1].opacity = 1 - AppStorage.Set('topPathInfo', topPathInfo) - } - } else if (this.mMenuLevel == menuLevel.MENU_THIRD_LEVEL_HAS_PIC) { - this.mMenuLevel = menuLevel.MENU_SECOND_LEVEL_BY_FOLD - this.mType = changeStringToType(item.name) - LogInfo(this.TAG, 'item.path 2 ' + item.path) - this.mCurrentPath = item.path - } - }) - } + private onExit(): void{ + logInfo(this.TAG, 'onExit') + this.mWorker = undefined + } + + private onMessage(result) { + logInfo(this.TAG, 'main thread onMessage') + var params = result.data.params + var file = JSON.parse(String.fromCharCode.apply(null, new Uint16Array(result.data.data))) + if (params.request_data == 'createFile') { + if (file.code == undefined) { + terminateSelfWithResult(TerminateReason.SUCCESS, file) + } else { + if (params.path == 'dataability:///album') { + this.code = 2; + this.customDialogController.open() + } else { + this.code = file.code + this.customDialogController.open() } - }, item => item.name.toString()) } - .padding({ right: 24 }) - .listDirection(Axis.Horizontal) - } - .alignItems(VerticalAlign.Center) - .width('100%') - .height(48) - .margin({ left: 12, top: 4 }) - .padding({ top: 13, bottom: 13 }) + return + } + if (Array.isArray(file)) { + let listData: Array = [] + for (var index = 0;index < file.length; index++) { + var info = file[index] + let item = new FileInfo(info.name) + item.path = info.path + item.type = info.type + item.size = info.size + item.dataAdded_time = info.added_time + item.modified_time = info.modified_time + if (params.menu_level == MenuLevel.MENU_FIRST_LEVEL_BY_TYPE) { + if (item.name == 'image_album') { + item.name = '图片' + item.mediaType = 'image' + item.thumbnail = $r("app.media.ic_type_image") + } else if (item.name == 'video_album') { + item.name = '视频' + item.mediaType = 'video' + item.thumbnail = $r("app.media.ic_type_video") + } else if (item.name == 'audio_album') { + item.name = '音乐' + item.mediaType = 'audio' + item.thumbnail = $r("app.media.ic_type_audio") + } else if (item.name == 'file_folder') { + item.name = '文档' + item.mediaType = 'file' + item.thumbnail = $r("app.media.ic_type_file") + } + } + + if (params.menu_level == MenuLevel.MENU_THIRD_LEVEL_HAS_DETAIL) { + if (this.mCurrentMode == 'save' && item.type != MediaType.MEDIA_TYPE_ALBUM) { + break + } + } + listData.push(item) + } + if (params.menu_level == MenuLevel.MENU_FIRST_LEVEL_BY_TYPE && params.request_data == 'getRoot') { + logDebug(this.TAG, 'mFirstMenuData length = ' + listData.length) + this.mFirstMenuData = listData + } else if (params.menu_level == MenuLevel.MENU_SECOND_LEVEL_BY_FOLD) { + logDebug(this.TAG, 'mSecondMenuData length = ' + listData.length) + this.mSecondMenuData = listData + } else if (params.menu_level == MenuLevel.MENU_THIRD_LEVEL_HAS_PIC) { + logDebug(this.TAG, 'mThirdMenuPicData length = ' + listData.length) + this.mThirdMenuPicData = listData + } else if (params.menu_level == MenuLevel.MENU_THIRD_LEVEL_HAS_DETAIL) { + logDebug(this.TAG, 'mThirdMenuDetailData length = ' + listData.length) + if (listData.length > 0) { + this.mThirdMenuDetailData = listData + } else { + this.mThirdMenuDetailData = [] + } + } + } + } + + build() { + Column() { + TopBarArea() - Scroll(this.scroller) { Column() { - if (this.mMenuLevel == menuLevel.MENU_FIRST_LEVEL_BY_TYPE) { - FirstLevelByType({ - mFileList: this.mFirstMenuData, - mType: $mType, - mMenuLevel: $mMenuLevel, - mCurrentPath: $mCurrentPath, - mWorker: this.mWorker, - }) - } else if (this.mMenuLevel == menuLevel.MENU_SECOND_LEVEL_BY_FOLD) { - SecondLevelByFold({ - mType: $mType, - mMenuLevel: $mMenuLevel, - mCurrentPath: $mCurrentPath, - mWorker: this.mWorker, - mFileList: $mSecondMenuData - }) - } else if (this.mMenuLevel == menuLevel.MENU_THIRD_LEVEL_HAS_PIC) { - ThirdLevelHasPic({ - mType: $mType, - mMenuLevel: $mMenuLevel, - mCurrentPath: $mCurrentPath, - mWorker: this.mWorker, - mFileList: $mThirdMenuPicData - }) - } else if (this.mMenuLevel == menuLevel.MENU_THIRD_LEVEL_HAS_DETAIL) { - ThirdLevelHasDetail({ - mType: $mType, - mMenuLevel: $mMenuLevel, - mCurrentPath: $mCurrentPath, - mWorker: this.mWorker, - mFileInfo: $mThirdMenuDetailData - }) - } - Row() { - }.width('100%').height(53) + Column() { + Row() { + List() { + ForEach(this.topPathInfo, (item: TopPathInfo) => { + ListItem() { + Row() { + if (item.name != '文件类型') { + Image($r("app.media.ic_public_right")) + .width(12) + .height(24) + .margin({ + left: 4, + right: 4 + }) + } + + Text(item.name) + .height(24) + .fontColor('#000000') + .fontSize(16) + .fontWeight(FontWeight.Medium) + .opacity(item.opacity) + .onClick(() => { + logInfo(this.TAG, item.name + ' onClick') + if (item.name == '文件类型') { + updateTopPathInfo([], '文件类型', '') + this.mMenuLevel = MenuLevel.MENU_FIRST_LEVEL_BY_TYPE + this.mType = '' + } else if (this.mMenuLevel == MenuLevel.MENU_THIRD_LEVEL_HAS_DETAIL) { + this.mCurrentPath = item.path + logInfo(this.TAG, 'item.path' + item.path) + let topPathInfo: Array = AppStorage.Get('topPathInfo') + let index: number = topPathInfo.indexOf(item) + if (index != -1) { + var deleteNum = topPathInfo.length - index + 1 + topPathInfo.splice(index + 1, deleteNum) + topPathInfo[topPathInfo.length - 1].opacity = 1 + AppStorage.Set('topPathInfo', topPathInfo) + } + } else if (this.mMenuLevel == MenuLevel.MENU_THIRD_LEVEL_HAS_PIC) { + this.mMenuLevel = MenuLevel.MENU_SECOND_LEVEL_BY_FOLD + this.mType = changeStringToType(item.name) + logInfo(this.TAG, 'item.path 2 ' + item.path) + this.mCurrentPath = item.path + } + }) + } + } + }, item => item.name.toString()) + } + .padding({ right: 24 }) + .listDirection(Axis.Horizontal) + } + .alignItems(VerticalAlign.Center) + .width('100%') + .height(48) + .margin({ left: 12, top: 4 }) + .padding({ top: 13, bottom: 13 }) + + Scroll(this.scroller) { + Column() { + if (this.mMenuLevel == MenuLevel.MENU_FIRST_LEVEL_BY_TYPE) { + FirstLevelByType({ + mFileList: this.mFirstMenuData, + mType: $mType, + mMenuLevel: $mMenuLevel, + mCurrentPath: $mCurrentPath, + mWorker: this.mWorker, + }) + } else if (this.mMenuLevel == MenuLevel.MENU_SECOND_LEVEL_BY_FOLD) { + SecondLevelByFold({ + mType: $mType, + mMenuLevel: $mMenuLevel, + mCurrentPath: $mCurrentPath, + mWorker: this.mWorker, + mFileList: $mSecondMenuData + }) + } else if (this.mMenuLevel == MenuLevel.MENU_THIRD_LEVEL_HAS_PIC) { + ThirdLevelHasPic({ + mType: $mType, + mMenuLevel: $mMenuLevel, + mCurrentPath: $mCurrentPath, + mWorker: this.mWorker, + mFileList: $mThirdMenuPicData + }) + } else if (this.mMenuLevel == MenuLevel.MENU_THIRD_LEVEL_HAS_DETAIL) { + ThirdLevelHasDetail({ + mType: $mType, + mMenuLevel: $mMenuLevel, + mCurrentPath: $mCurrentPath, + mWorker: this.mWorker, + mFileInfo: $mThirdMenuDetailData + }) + } + Row() { + }.width('100%').height(53) + } + .alignItems(HorizontalAlign.Start) + } + .scrollBar(BarState.Off) + .scrollable(ScrollDirection.Vertical) + } + .alignItems(HorizontalAlign.Start) } .alignItems(HorizontalAlign.Start) - } - .scrollBar(BarState.Off) - .scrollable(ScrollDirection.Vertical) - } - .alignItems(HorizontalAlign.Start) - } - .alignItems(HorizontalAlign.Start) - .height(px2vp(globalThis.mainDialogHeight) - 140) + .height(px2vp(globalThis.mainDialogHeight) - 140) - BottomBar({ - mCurrentPath: $mCurrentPath, - mMenuLevel: $mMenuLevel, - mType: $mType, - mWorker: this.mWorker - }) + BottomBar({ + mCurrentPath: $mCurrentPath, + mMenuLevel: $mMenuLevel, + mType: $mType, + mWorker: this.mWorker + }) + } + .padding({ left: 12, right: 12 }) + .width('100%') + .height(px2vp(globalThis.mainDialogHeight)) + .border({ radius: 24 }) + .backgroundColor('#F1F3F5') } - .padding({ left: 12, right: 12 }) - .width('100%') - .height(px2vp(globalThis.mainDialogHeight)) - .border({ radius: 24 }) - .backgroundColor('#F1F3F5') - } } @Component struct TopBarArea { - build() { - Row() { - Text('文件类型') - .width(98) - .height(33) - .fontSize(24) - .fontColor('#182431') - .fontWeight(FontWeight.Medium) - .margin({ left: 12 }) + build() { + Row() { + Text('文件类型') + .width(98) + .height(33) + .fontSize(24) + .fontColor('#182431') + .fontWeight(FontWeight.Medium) + .margin({ left: 12 }) + } + .height(64) + .width('100%') + .border({ radius: 24 }) + .padding({ top: 8 }) } - .height(64) - .width('100%') - .border({ radius: 24 }) - .padding({ top: 8 }) - } } @Component struct BottomBar { - private TAG: string = 'BottomBar' - private mWorker - @State currentChoseFiles: Array = [] - @Link mType: string - @Link mMenuLevel: number - @Link mCurrentPath: string - @StorageLink('choseFiles') @Watch('choseFileChange') choseFiles: Array = [] + private TAG: string = 'BottomBar' + private mWorker + @State currentChoseFiles: Array = [] + @Link mType: string + @Link mMenuLevel: number + @Link mCurrentPath: string + @StorageLink('choseFiles') @Watch('choseFileChange') choseFiles: Array = [] - aboutToAppear() { - LogInfo(this.TAG, 'current choose file number = ' + this.currentChoseFiles.length) - } - - private choseFileChange() { - this.currentChoseFiles = [] - let files: Array = AppStorage.Get('choseFiles') - files.forEach((item: FileInfo) => { - this.currentChoseFiles.push(item.name) - }) - LogInfo(this.TAG, 'current choose file number = ' + this.currentChoseFiles.length) - } - - build() { - Row() { - Button() { - Text('取消') - .width(110) - .height(22) - .fontSize(16) - .fontWeight(FontWeight.Medium) - .fontColor('#007DFF') - .textAlign(TextAlign.Center) - } - .width(150) - .height(40) - .margin({ left: 12, top: 12, bottom: 24 }) - .backgroundColor('#E5E8EA') - .onClick((event: ClickEvent) => { - terminateSelfWithResult(terminate_reason.NO_ACTION, '') - AppStorage.Set('choseFiles', []) - }) - - if (globalThis.startMode == 'save') { - Button() { - Text($r("app.string.btn_upload")) - .width(110) - .height(22) - .fontSize(16) - .fontWeight(FontWeight.Medium) - .fontColor('#007DFF') - .textAlign(TextAlign.Center) - .opacity(this.choseFiles.length != 0 ? 1 : 0.4) - } - .backgroundColor(this.choseFiles.length != 0 ? '#E5E8EA' : '#ECEEF0') - .margin({ - left: 12, - top: 12, - bottom: 24 - }) - .height(40) - .width(150) - .stateEffect(this.mMenuLevel == menuLevel.MENU_FIRST_LEVEL_BY_TYPE ? false : true) - .onClick((event: ClickEvent) => { - this.mWorker.postMessage({ - request_data: 'createFile', - device_name: 'local', - menu_level: this.mMenuLevel, - media_type: this.mType, - path: this.mCurrentPath, - save_name: globalThis.saveFile, - }) - }) - } else { - Button() { - Text($r("app.string.btn_upload")) - .width(110) - .height(22) - .fontSize(16) - .fontWeight(FontWeight.Medium) - .fontColor('#007DFF') - .textAlign(TextAlign.Center) - .opacity(this.choseFiles.length != 0 ? 1 : 0.4) - } - .backgroundColor(this.choseFiles.length != 0 ? '#E5E8EA' : '#ECEEF0') - .stateEffect(this.choseFiles.length != 0) - .margin({ - left: 12, - top: 12, - bottom: 24 - }) - .height(40) - .width(150) - .onClick(() => { - let result: string = '' - this.choseFiles.forEach((item: FileInfo) => { - result += item.path + ';' - }) - terminateSelfWithResult(terminate_reason.SUCCESS, result) - AppStorage.Set('choseFiles', []) - }) - } + aboutToAppear() { + logInfo(this.TAG, 'current choose file number = ' + this.currentChoseFiles.length) + } + + private choseFileChange() { + this.currentChoseFiles = [] + let files: Array = AppStorage.Get('choseFiles') + files.forEach((item: FileInfo) => { + this.currentChoseFiles.push(item.name) + }) + logInfo(this.TAG, 'current choose file number = ' + this.currentChoseFiles.length) + } + + build() { + Row() { + Button() { + Text('取消') + .width(110) + .height(22) + .fontSize(16) + .fontWeight(FontWeight.Medium) + .fontColor('#007DFF') + .textAlign(TextAlign.Center) + } + .width(150) + .height(40) + .margin({ left: 12, top: 12, bottom: 24 }) + .backgroundColor('#E5E8EA') + .onClick((event: ClickEvent) => { + terminateSelfWithResult(TerminateReason.NO_ACTION, '') + AppStorage.Set('choseFiles', []) + }) + + if (globalThis.startMode == 'save') { + Button() { + Text($r("app.string.btn_upload")) + .width(110) + .height(22) + .fontSize(16) + .fontWeight(FontWeight.Medium) + .fontColor('#007DFF') + .textAlign(TextAlign.Center) + .opacity(this.choseFiles.length != 0 ? 1 : 0.4) + } + .backgroundColor(this.choseFiles.length != 0 ? '#E5E8EA' : '#ECEEF0') + .margin({ + left: 12, + top: 12, + bottom: 24 + }) + .height(40) + .width(150) + .stateEffect(this.mMenuLevel == MenuLevel.MENU_FIRST_LEVEL_BY_TYPE ? false : true) + .onClick((event: ClickEvent) => { + this.mWorker.postMessage({ + request_data: 'createFile', + device_name: 'local', + menu_level: this.mMenuLevel, + MediaType: this.mType, + path: this.mCurrentPath, + save_name: globalThis.saveFile, + }) + }) + } else { + Button() { + Text($r("app.string.btn_upload")) + .width(110) + .height(22) + .fontSize(16) + .fontWeight(FontWeight.Medium) + .fontColor('#007DFF') + .textAlign(TextAlign.Center) + .opacity(this.choseFiles.length != 0 ? 1 : 0.4) + } + .backgroundColor(this.choseFiles.length != 0 ? '#E5E8EA' : '#ECEEF0') + .stateEffect(this.choseFiles.length != 0) + .margin({ + left: 12, + top: 12, + bottom: 24 + }) + .height(40) + .width(150) + .onClick(() => { + let result: string = '' + this.choseFiles.forEach((item: FileInfo) => { + result += item.path + ';' + }) + terminateSelfWithResult(TerminateReason.SUCCESS, result) + AppStorage.Set('choseFiles', []) + }) + } + } + .height(76) + .width('100%') + .backgroundColor('#F1F3F5') } - .height(76) - .width('100%') - .backgroundColor('#F1F3F5') - } } \ No newline at end of file diff --git a/product/phone/src/main/ets/workers/DataWorker.js b/product/phone/src/main/ets/workers/DataWorker.js index 0089ebd..1bcec9a 100644 --- a/product/phone/src/main/ets/workers/DataWorker.js +++ b/product/phone/src/main/ets/workers/DataWorker.js @@ -13,14 +13,14 @@ * limitations under the License. */ -import { LogInfo, LogDebug } from '../module/LogUtils.ets' -import worker from '@ohos.worker' import filemanager from '@ohos.filemanager' +import worker from '@ohos.worker' +import { logInfo, logDebug, logError } from '../../../../../../common/src/main/ets/components/utils/logutils' var TAG = 'DataWorker' const parentPort = worker.parentPort parentPort.onmessage = function (e) { - LogInfo(TAG, 'onMessage') + logInfo(TAG, 'onMessage') let data = e.data if (data.request_data == 'getRoot') { getRootData(data) @@ -32,74 +32,55 @@ parentPort.onmessage = function (e) { } parentPort.onmessageerror = function () { - LogInfo(TAG, 'onmessageerror') + logInfo(TAG, 'onmessageerror') } parentPort.onerror = function (data) { - LogInfo(TAG, 'onerror') + logInfo(TAG, 'onerror') } function getRootData(data) { -// let options = { -// "dev": { -// "name": "external_storage" -// } -// } - filemanager.getRoot() - .then(file => { - handleData(file, data) - }) - .catch((error) => { - LogDebug(TAG, 'getRoot 2 error' + error) - }); + filemanager.getRoot().then(file => { + handleData(file, data) + }).catch((error) => { + logError(TAG, 'getRoot 2 error' + error) + }); } function getListFileData(data) { - LogDebug(TAG, 'getListFileData 1') + logDebug(TAG, 'getListFileData 1') if (data.offset == undefined || data.count == undefined) { - LogDebug(TAG, 'path = ' + data.path + " type = " + data.media_type) - -// let options = { -// "dev": { -// "name": "external_storage" -// } -// } - filemanager.listFile(data.path, data.media_type) - .then(file => { - handleData(file, data) - }) - .catch((error) => { - LogDebug(TAG, 'getListFileData 2 error' + error) - }) + logDebug(TAG, 'path = ' + data.path + " type = " + data.MediaType) + filemanager.listFile(data.path, data.MediaType).then(file => { + handleData(file, data) + }).catch((error) => { + logError(TAG, 'getListFileData 2 error' + error) + }) } else { - filemanager.listFile(data.path, data.media_type, { + filemanager.listFile(data.path, data.MediaType, { 'offset': data.offset, 'count': data.count + }).then(file => { + handleData(file, data) + }).catch((error) => { + logError(TAG, 'getListFileData 3 error' + error) }) - .then(file => { - handleData(file, data) - }) - .catch((error) => { - LogDebug(TAG, 'getListFileData 3 error' + error) - }) } } function createFile(data) { - filemanager.createFile(data.path, data.save_name) - .then((uri) => { - handleData(uri, data) - }) - .catch((err) => { - handleData(err, data) - }) + filemanager.createFile(data.path, data.save_name).then((uri) => { + handleData(uri, data) + }).catch((err) => { + handleData(err, data) + }) } function handleData(file, data) { - LogInfo(TAG, 'handleData') + logInfo(TAG, 'handleData') var info = JSON.stringify(file) - LogInfo(TAG, 'info = ' + info.length) + logInfo(TAG, 'info = ' + info.length) var buf = new ArrayBuffer(info.length * 2) var bufView = new Uint16Array(buf) for (var index = 0; index < info.length; index++) { diff --git a/product/phone/src/main/resources/base/element/string.json b/product/phone/src/main/resources/base/element/string.json index 494b441..99e363b 100644 --- a/product/phone/src/main/resources/base/element/string.json +++ b/product/phone/src/main/resources/base/element/string.json @@ -23,58 +23,6 @@ { "name": "btn_save", "value": "save" - }, - { - "name": "file_unknown", - "value": "Unknown file" - }, - { - "name": "save_file_has_same_file", - "value": "Duplicate name file already exists" - }, - { - "name": "save_file_no_media_permission", - "value": "Saving to media library is not currently supported" - }, - { - "name": "save_file_unknown_reason", - "value": "Unknown error" - }, - { - "name": "file_zip", - "value": "Compressed (zipped) file" - }, - { - "name": "file_xml", - "value": "XML document" - }, - { - "name": "file_xls", - "value": "Microsoft Excel worksheet" - }, - { - "name": "file_txt", - "value": "Txt document" - }, - { - "name": "file_rar", - "value": "Rar compressed file" - }, - { - "name": "file_pdf", - "value": "Adobe Acrobat Document" - }, - { - "name": "file_html", - "value": "HTML Document" - }, - { - "name": "file_pptx", - "value": "Microsoft PowerPoint Presentation" - }, - { - "name": "file_docx", - "value": "Microsoft Word Document" } ] } \ No newline at end of file diff --git a/product/phone/src/main/resources/base/media/ic_file_doc.png b/product/phone/src/main/resources/base/media/ic_file_doc.png deleted file mode 100644 index 32b7b88..0000000 Binary files a/product/phone/src/main/resources/base/media/ic_file_doc.png and /dev/null differ diff --git a/product/phone/src/main/resources/base/media/ic_file_fold.png b/product/phone/src/main/resources/base/media/ic_file_fold.png deleted file mode 100644 index 45375fd..0000000 Binary files a/product/phone/src/main/resources/base/media/ic_file_fold.png and /dev/null differ diff --git a/product/phone/src/main/resources/base/media/ic_file_html.png b/product/phone/src/main/resources/base/media/ic_file_html.png deleted file mode 100644 index 4df41b0..0000000 Binary files a/product/phone/src/main/resources/base/media/ic_file_html.png and /dev/null differ diff --git a/product/phone/src/main/resources/base/media/ic_file_manager.png b/product/phone/src/main/resources/base/media/ic_file_manager.png deleted file mode 100644 index 45375fd..0000000 Binary files a/product/phone/src/main/resources/base/media/ic_file_manager.png and /dev/null differ diff --git a/product/phone/src/main/resources/base/media/ic_file_pdf.png b/product/phone/src/main/resources/base/media/ic_file_pdf.png deleted file mode 100644 index 025ec1c..0000000 Binary files a/product/phone/src/main/resources/base/media/ic_file_pdf.png and /dev/null differ diff --git a/product/phone/src/main/resources/base/media/ic_file_pptx.png b/product/phone/src/main/resources/base/media/ic_file_pptx.png deleted file mode 100644 index 7669173..0000000 Binary files a/product/phone/src/main/resources/base/media/ic_file_pptx.png and /dev/null differ diff --git a/product/phone/src/main/resources/base/media/ic_file_rar.png b/product/phone/src/main/resources/base/media/ic_file_rar.png deleted file mode 100644 index 49d3865..0000000 Binary files a/product/phone/src/main/resources/base/media/ic_file_rar.png and /dev/null differ diff --git a/product/phone/src/main/resources/base/media/ic_file_txt.png b/product/phone/src/main/resources/base/media/ic_file_txt.png deleted file mode 100644 index 8bf40d0..0000000 Binary files a/product/phone/src/main/resources/base/media/ic_file_txt.png and /dev/null differ diff --git a/product/phone/src/main/resources/base/media/ic_file_unknown.png b/product/phone/src/main/resources/base/media/ic_file_unknown.png deleted file mode 100644 index 4f04e41..0000000 Binary files a/product/phone/src/main/resources/base/media/ic_file_unknown.png and /dev/null differ diff --git a/product/phone/src/main/resources/base/media/ic_file_xls.png b/product/phone/src/main/resources/base/media/ic_file_xls.png deleted file mode 100644 index 684c387..0000000 Binary files a/product/phone/src/main/resources/base/media/ic_file_xls.png and /dev/null differ diff --git a/product/phone/src/main/resources/base/media/ic_file_xml.png b/product/phone/src/main/resources/base/media/ic_file_xml.png deleted file mode 100644 index f557e06..0000000 Binary files a/product/phone/src/main/resources/base/media/ic_file_xml.png and /dev/null differ diff --git a/product/phone/src/main/resources/base/media/ic_file_zip.png b/product/phone/src/main/resources/base/media/ic_file_zip.png deleted file mode 100644 index 5764cc6..0000000 Binary files a/product/phone/src/main/resources/base/media/ic_file_zip.png and /dev/null differ diff --git a/product/phone/src/main/resources/zh_CN/element/string.json b/product/phone/src/main/resources/zh_CN/element/string.json index b11b8cf..5f4994e 100644 --- a/product/phone/src/main/resources/zh_CN/element/string.json +++ b/product/phone/src/main/resources/zh_CN/element/string.json @@ -23,58 +23,6 @@ { "name": "btn_save", "value": "保存" - }, - { - "name": "file_unknown", - "value": "未知文件" - }, - { - "name": "save_file_has_same_file", - "value": "已有重名文件" - }, - { - "name": "save_file_no_media_permission", - "value": "当前不支持保存到媒体库" - }, - { - "name": "save_file_unknown_reason", - "value": "未知错误" - }, - { - "name": "file_zip", - "value": "压缩(zipped)文件" - }, - { - "name": "file_xml", - "value": "XML文档" - }, - { - "name": "file_xls", - "value": "Microsoft Excel工作表" - }, - { - "name": "file_txt", - "value": "TXT文档" - }, - { - "name": "file_rar", - "value": "RAR压缩文件" - }, - { - "name": "file_pdf", - "value": "Adobe Acrobat Document" - }, - { - "name": "file_html", - "value": "HTML网页文件" - }, - { - "name": "file_pptx", - "value": "Microsoft PowerPoint演示文稿" - }, - { - "name": "file_docx", - "value": "Microsoft Word文档" } ] } \ No newline at end of file