diff --git a/entry/src/main/ets/components/SelectFolderDialog.ets b/entry/src/main/ets/components/SelectFolderDialog.ets index d9172517a05816562083494a37c3ec7e1a0135f4..870988a48a34b30fc81ec1709e4e7e00847e4b5d 100644 --- a/entry/src/main/ets/components/SelectFolderDialog.ets +++ b/entry/src/main/ets/components/SelectFolderDialog.ets @@ -38,7 +38,7 @@ export struct SelectFolderDialog { @Consume downloadFolder: Array; @State selectedFolder: string = ''; private controller: CustomDialogController = new CustomDialogController({ builder: null }); - private selectFolder: (folder: string) => void = () => { + public selectFolder: (folder: string) => void = () => { }; build() { diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index 44d373cdc9ed33404173a7ca1b6876484eb7840b..c7f946c1a5592e8def20d88a67ff8747561f5629 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -18,7 +18,7 @@ import { window } from '@kit.ArkUI'; import { logger, urlUtils } from '@ohos/uploaddownload'; const TAG: string = 'EntryAbility'; -const URL: string = 'http://192.168.26.131:8080/'; +const URL: string = 'http://xxx.xxx.xxx.xxxx:8080/'; export default class EntryAbility extends UIAbility { onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { diff --git a/entry/src/main/ets/pages/Download.ets b/entry/src/main/ets/pages/Download.ets index ae99cae18e3eaacd3a74a25b8fa5baaaf40ba803..45093aa6d9187eb9b9ac54b0c2a42666f2a7ead9 100644 --- a/entry/src/main/ets/pages/Download.ets +++ b/entry/src/main/ets/pages/Download.ets @@ -100,6 +100,7 @@ struct Download { } .width(LIST_WIDTH) .height(LIST_HEIGHT) + .constraintSize({maxHeight: '80%'}) .scrollBar(BarState.Off) .backgroundColor(Color.White) .borderRadius(LIST_BORDER_RADIUS) @@ -113,7 +114,8 @@ struct Download { endMargin: END_MARGIN }) } - Column().layoutWeight(1) + Blank() + .layoutWeight(1) this.BottomView() } diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index b4247fc8fd8a4a4f07ba6f3b9b3507e2daab45cb..c3219723126d7e43e78de0815257b0c485ca7fc4 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -17,16 +17,23 @@ import { notificationManager } from '@kit.NotificationKit'; import { router } from '@kit.ArkUI'; import { common } from '@kit.AbilityKit'; -@Styles function itemStyle() { +@Styles +function itemStyle() { .width('100%') .height(56) - .padding({ top: 17, bottom: 17, left: 12, right: 12 }) + .padding({ + top: 17, + bottom: 17, + left: 12, + right: 12 + }) .backgroundColor(Color.White) .borderRadius(24) .margin({ top: 12 }) } -@Extend(Text) function textStyle() { +@Extend(Text) +function textStyle() { .fontColor($r('app.color.text_normal')) .fontWeight(400) .fontFamily('HarmonyHeiTi') @@ -61,14 +68,10 @@ struct Index { .margin({ top: 0 }) this.CapabilityView($r('app.media.ic_upload'), $r('app.string.upload'), 'btn_upload', () => { - router.pushUrl({ - url: 'pages/Upload' - }) + router.pushUrl({ url: 'pages/Upload' }); }) this.CapabilityView($r('app.media.ic_download'), $r('app.string.download'), 'btn_download', () => { - router.pushUrl({ - url: 'pages/Download' - }) + router.pushUrl({ url: 'pages/Download' }); }) } .width('100%') diff --git a/features/uploadanddownload/src/main/ets/components/FileBrowse.ets b/features/uploadanddownload/src/main/ets/components/FileBrowse.ets index 77d27cfce4f82618b6a4eac5506c8647a87ca8e1..55c7e0b465c39cda4bd7617b13bbbb06d40f730a 100644 --- a/features/uploadanddownload/src/main/ets/components/FileBrowse.ets +++ b/features/uploadanddownload/src/main/ets/components/FileBrowse.ets @@ -18,22 +18,23 @@ import { fileUtils } from '../utils/FileUtils'; @Preview @Component export struct FileBrowse { + @StorageLink('files') files: Array = []; + @StorageLink('currentFolder') currentFolder: string = ''; + @StorageLink('pathStack') pathStack: NavPathStack = new NavPathStack(); @State folders: Array = ['folder']; - @State files: Array = []; - @State currentFolder: string = ''; aboutToAppear() { - fileUtils.listFolders().then((folders: Array) => { + fileUtils.listFolders() + .then((folders: Array) => { this.folders = folders; }) } build() { - Navigation() { + Navigation(this.pathStack) { List({ space: 12 }) { ForEach(this.folders, (item: string) => { ListItem() { - NavRouter() { Row() { Image($r('app.media.ic_files_folder')) .size({ width: 32, height: 26 }) @@ -47,19 +48,11 @@ export struct FileBrowse { .padding({ left: 16 }) .backgroundColor(Color.White) .borderRadius(24) - - NavDestination() { - this.FilesView() - } - .title(this.CustomTitle(item)) - .backgroundColor($r('app.color.light_gray')) - } - .onStateChange(async (isActivated: boolean) => { - if (isActivated) { + .onClick(async () => { this.currentFolder = item; this.files = await fileUtils.listFiles(item); - } - }) + this.pathStack.pushPathByName('FilesDetailView', null, null); + }) } }, (item: string, index: number) => index + item) } diff --git a/features/uploadanddownload/src/main/ets/components/FilesDetailView.ets b/features/uploadanddownload/src/main/ets/components/FilesDetailView.ets new file mode 100644 index 0000000000000000000000000000000000000000..a610a22cf72ae9c92e21bc52f0223f5ed3e5928a --- /dev/null +++ b/features/uploadanddownload/src/main/ets/components/FilesDetailView.ets @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2025 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 { fileUtils } from '../utils/FileUtils'; + +@Builder +export function FilesDetailViewBuilder() { + FilesDetailView() +} + +@Component +struct FilesDetailView { + @StorageLink('files') files: Array = []; + @StorageLink('currentFolder') currentFolder: string = ''; + pathStack: NavPathStack = new NavPathStack(); + + build() { + NavDestination() { + this.FilesView() + } + .title(this.CustomTitle(this.currentFolder)) + .backgroundColor($r('app.color.light_gray')) + .onReady((context: NavDestinationContext) => { + this.pathStack = context.pathStack + }) + .height('100%') + } + + @Builder + CustomTitle(title: string) { + Row() { + Text(title) + .fontSize(20) + .fontColor($r('app.color.text_normal')) + .fontWeight(700) + .margin({ left: 8 }) + } + .width('100%') + } + + + @Builder + FilesView() { + Column() { + List({ space: 12 }) { + if (this.files.length === 0) { + ListItem() { + Text($r('app.string.folder_empty')) + .fontSize(16) + .width('100%') + .margin({ top: 50 }) + .textAlign(TextAlign.Center) + } + } + ForEach(this.files, (item: string) => { + ListItem() { + Text(decodeURIComponent(item)) + .fontSize(16) + .width('100%') + } + .padding(12) + .height(48) + .backgroundColor(Color.White) + .borderRadius(24) + }, (item: string, index: number) => index + item) + } + .padding({ left: 12, right: 12 }) + .layoutWeight(1) + + Column() { + Button() { + Image($r('app.media.ic_public_delete')) + .objectFit(ImageFit.Cover) + .size({ width: 24, height: 24 }) + } + .type(ButtonType.Circle) + .width(40) + .height(40) + .backgroundColor('#FF0000') + .margin({ left: 5 }) + + Text($r('app.string.clear_folder')) + .fontSize(14) + .fontColor($r('app.color.text_normal')) + .opacity(0.6) + .margin({ top: 8 }) + } + .margin({ bottom: 24, top: 6 }) + .onClick(() => { + fileUtils.clearFolder(this.currentFolder); + this.files = []; + }) + } + .height('100%') + .backgroundColor($r('app.color.light_gray')) + } +} \ No newline at end of file diff --git a/features/uploadanddownload/src/main/ets/utils/FileUtils.ets b/features/uploadanddownload/src/main/ets/utils/FileUtils.ets index 163a6dc8df8a0c3a34c660e128adb50130a5fa90..a717b411b27e1f023e08bfcdda98a5e76c54dd51 100644 --- a/features/uploadanddownload/src/main/ets/utils/FileUtils.ets +++ b/features/uploadanddownload/src/main/ets/utils/FileUtils.ets @@ -32,7 +32,7 @@ class FileUtil { fileIo.mkdirSync(`${context.cacheDir}/${ALBUMS[1]}`); fileIo.mkdirSync(`${context.cacheDir}/${ALBUMS[2]}`); } catch (err) { - logger.info(TAG, `initDownloadDir err =${JSON.stringify(err)}`); + logger.error(TAG, `initDownloadDir err =${JSON.stringify(err)}`); } } @@ -50,7 +50,7 @@ class FileUtil { fileIo.unlinkSync(`${context.cacheDir}/${folderName}/${files[i]}`); } } catch (err) { - logger.info(TAG, `listFiles err =${JSON.stringify(err)}`); + logger.error(TAG, `listFiles err =${JSON.stringify(err)}`); } } @@ -61,7 +61,7 @@ class FileUtil { files = fileIo.listFileSync(`${context.cacheDir}/${folderName}`); logger.info(TAG, `listFiles listFileSync =${JSON.stringify(files)}`); } catch (err) { - logger.info(TAG, `listFiles err =${JSON.stringify(err)}`); + logger.error(TAG, `listFiles err =${JSON.stringify(err)}`); } return files; } diff --git a/features/uploadanddownload/src/main/module.json5 b/features/uploadanddownload/src/main/module.json5 index dd058680687563e01a7d0e3915778b4a96f4fa9a..0cc93b7dfce99464ea541a46df9e7c80d594bf11 100644 --- a/features/uploadanddownload/src/main/module.json5 +++ b/features/uploadanddownload/src/main/module.json5 @@ -19,6 +19,7 @@ "deviceTypes": [ "phone" ], + "routerMap": "$profile:route_map", "requestPermissions": [ { "name": "ohos.permission.INTERNET", diff --git a/features/uploadanddownload/src/main/resources/base/profile/route_map.json b/features/uploadanddownload/src/main/resources/base/profile/route_map.json new file mode 100644 index 0000000000000000000000000000000000000000..2344e2d93ef2dd60411d8687fdef6ec0fffee325 --- /dev/null +++ b/features/uploadanddownload/src/main/resources/base/profile/route_map.json @@ -0,0 +1,12 @@ +{ + "routerMap": [ + { + "name": "FilesDetailView", + "pageSourceFile": "src/main/ets/components/FilesDetailView.ets", + "buildFunction": "FilesDetailViewBuilder", + "data": { + "description" : "this is FilesDetailView" + } + } + ] +} \ No newline at end of file