1/* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { MediaType } from '../../../../../../common/src/main/ets/components/Data/Constants' 17import { FileInfo } from '../../../../../../common/src/main/ets/components/Data/FileInfo' 18import { logInfo } from '../../../../../../common/src/main/ets/components/Utils/LogUtils' 19import { getListFile } from '../../../../../../common/src/main/ets/components/Utils/FileManagerServiceUtils' 20import { getShowIconBySuffix, updateTopPathInfo } from '../../../../../../common/src/main/ets/components/Utils/Utils' 21import { ChooseDialog } from '../../../../../../common/src/main/ets/components/View/ChooseDialog' 22import { PadSize } from '../module/Constants' 23 24@Component 25export struct ThirdLevelHasDetail { 26 private TAG: string = 'ThirdLevelHasDetail' 27 private mWorker 28 @Link mFileInfo: Array<FileInfo> 29 @Link @Watch('refreshFiles') mCurrentPath: string 30 @Link mMenuLevel: number 31 @Link mType: string 32 33 aboutToAppear(): void{ 34 logInfo(this.TAG, 'aboutToAppear') 35 if (globalThis.debugMode) { 36 this.mFileInfo = getListFile('local', this.mType, this.mCurrentPath) 37 } else { 38 this.mWorker.postMessage({ 39 request_data: 'listFile', 40 device_name: 'local', 41 menu_level: this.mMenuLevel, 42 MediaType: this.mType, 43 path: this.mCurrentPath, 44 context: globalThis.context, 45 }) 46 } 47 } 48 49 aboutToDisappear() { 50 logInfo(this.TAG, 'aboutToDisappear') 51 AppStorage.Set('choseFiles', []) 52 } 53 54 refreshFiles() { 55 logInfo(this.TAG, 'refreshFiles') 56 AppStorage.Set('choseFiles', []) 57 if (!globalThis.debugMode) { 58 this.mWorker.postMessage({ 59 request_data: 'listFile', 60 device_name: 'local', 61 menu_level: this.mMenuLevel, 62 MediaType: this.mType, 63 path: this.mCurrentPath, 64 context: globalThis.context, 65 }) 66 } 67 } 68 69 build() { 70 Column() { 71 List() { 72 ForEach(this.mFileInfo, (item: FileInfo) => { 73 ListItem() { 74 DetailRowView({ 75 listItem: item, 76 mMenuLevel: $mMenuLevel, 77 mCurrentPath: $mCurrentPath 78 }) 79 } 80 }, (item: FileInfo) => item.name) 81 }.align(Alignment.Top) 82 } 83 .height(PadSize.TWO_HUNDRED_AND_SIXTY) 84 .alignItems(HorizontalAlign.Start) 85 .opacity(0.9) 86 .backgroundColor(Color.White) 87 .border({ radius: PadSize.TWENTY_FOUR }) 88 .margin({ top: PadSize.SIXTEEN }) 89 } 90} 91 92@Component 93struct DetailRowView { 94 private TAG: string = 'DetailRowView' 95 private dialogController: CustomDialogController = new CustomDialogController({ 96 builder: ChooseDialog(), 97 cancel: () => { 98 }, 99 autoCancel: true 100 }) 101 @State listItem: FileInfo = new FileInfo('') 102 @Link mCurrentPath: string 103 @Link mMenuLevel: number 104 @StorageLink('choseFiles') @Watch('choseFilesChange') choseFiles: Array<FileInfo> = [] 105 106 private choseFilesChange() { 107 this.choseFiles.forEach((item: FileInfo) => { 108 logInfo(this.TAG, 'choseFilesChange item.name = ' + item.name + ' gridItem.name = ' + this.listItem.name) 109 logInfo(this.TAG, 'choseFilesChange item.path = ' + item.path + ' gridItem.path = ' + this.listItem.path) 110 if (item.name == this.listItem.name && item.path == this.listItem.path) { 111 this.listItem.listBackground = '#19007DFF' 112 } else { 113 this.listItem.listBackground = '' 114 } 115 116 }) 117 } 118 119 build() { 120 Stack() { 121 Divider() 122 .vertical(false) 123 .color("#0C000000") 124 .margin({ left: PadSize.EIGHTY, top: PadSize.SIXTY_FOUR, right: PadSize.TWENTY_FOUR }) 125 Row() { 126 if (this.listItem.type == MediaType.MEDIA_TYPE_ALBUM) { 127 Image($r("app.media.ic_file_fold")) 128 .width(PadSize.FORTY) 129 .height(PadSize.FORTY) 130 .margin({ left: PadSize.EIGHT }) 131 Text(this.listItem.name) 132 .fontSize(PadSize.SIXTEEN) 133 .fontColor('#182431') 134 .fontWeight(FontWeight.Medium) 135 .margin({ left: PadSize.SIXTEEN }) 136 .maxLines(PadSize.ONE) 137 .textOverflow({ overflow: TextOverflow.Ellipsis }) 138 Blank() 139 Image($r("app.media.ic_right")) 140 .width(PadSize.TWELVE) 141 .height(PadSize.TWENTY_FOUR) 142 } else { 143 Image(getShowIconBySuffix(this.listItem.name.substring(this.listItem.name.lastIndexOf('.')))) 144 .width(PadSize.FORTY) 145 .height(PadSize.FORTY) 146 .margin({ left: PadSize.EIGHT }) 147 Column() { 148 Text(this.listItem.name) 149 .height(PadSize.TWENTY_TWO) 150 .fontSize(PadSize.SIXTEEN) 151 .fontWeight(FontWeight.Medium) 152 .fontColor(this.listItem.fontColor) 153 .maxLines(1) 154 .textOverflow({ overflow: TextOverflow.Ellipsis }) 155 .margin({ top: PadSize.TEN }) 156 Row() { 157 Text('' + this.listItem.modifiedTime) 158 .fontSize(PadSize.FOURTEEN) 159 .fontWeight(FontWeight.Regular) 160 .fontColor(this.listItem.fontColor) 161 .maxLines(PadSize.ONE) 162 .textOverflow({ overflow: TextOverflow.Ellipsis }) 163 Text('-') 164 .fontSize(PadSize.FOURTEEN) 165 .fontColor(this.listItem.fontColor) 166 .margin({ left: PadSize.EIGHT }) 167 Text('' + this.listItem.size) 168 .fontSize(PadSize.FOURTEEN) 169 .fontWeight(FontWeight.Regular) 170 .fontColor(this.listItem.fontColor) 171 .margin({ left: PadSize.EIGHT }) 172 .maxLines(PadSize.ONE) 173 .textOverflow({ overflow: TextOverflow.Ellipsis }) 174 } 175 .opacity(0.6) 176 .height(PadSize.NINETEEN) 177 .margin({ top: PadSize.TWO, bottom: PadSize.ELEVEN }) 178 } 179 .alignItems(HorizontalAlign.Start) 180 .margin({ left: PadSize.SIXTEEN }) 181 } 182 } 183 .width(PadSize.FIVE_HUNDRED_AND_FOUR) // TODO 184 .height(PadSize.SIXTY_FOUR) 185 .margin({ left: PadSize.SIXTEEN, right: PadSize.TWENTY_FOUR, bottom: PadSize.ONE }) 186 .border({ radius: PadSize.TWENTY }) 187 .backgroundColor(this.listItem.listBackground) 188 .onClick(() => { 189 if (this.listItem.type == MediaType.MEDIA_TYPE_ALBUM) { 190 this.mCurrentPath = this.listItem.path 191 updateTopPathInfo(AppStorage.Get('topPathInfo'), this.listItem.name, this.listItem.path) 192 } else { 193 var index = this.choseFiles.indexOf(this.listItem) 194 this.choseFiles.splice(0, this.choseFiles.length) 195 if (index == -1) { 196 this.listItem.listBackground = '#19007DFF' 197 this.choseFiles.push(this.listItem) 198 } else { 199 this.listItem.listBackground = '' 200 } 201 } 202 }) 203 .gesture(LongPressGesture({ repeat: false }) 204 .onAction((event: GestureEvent) => { 205 if (this.listItem.type != MediaType.MEDIA_TYPE_ALBUM) { 206 AppStorage.SetOrCreate<FileInfo>('selectedFileInfo', this.listItem) 207 this.dialogController.open() 208 } 209 }) 210 ) 211 } 212 } 213}