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' 22 23let TAG: string = 'ThirdLevelHasDetail' 24 25@Component 26export struct ThirdLevelHasDetail { 27 private mCurrentMode: string 28 private mWorker 29 @Link mFileInfo: Array<FileInfo> 30 @Link @Watch('refreshFiles') mCurrentPath: string 31 @Link mMenuLevel: number 32 @Link mType: string 33 34 aboutToAppear(): void{ 35 logInfo(TAG, 'aboutToAppear') 36 if (globalThis.debugMode) { 37 this.mFileInfo = getListFile('local', this.mType, this.mCurrentPath) 38 } else { 39 this.mWorker.postMessage({ 40 request_data: 'listFile', 41 device_name: 'local', 42 menu_level: this.mMenuLevel, 43 MediaType: this.mType, 44 path: this.mCurrentPath, 45 context: globalThis.context, 46 }) 47 } 48 } 49 50 aboutToDisappear() { 51 logInfo(TAG, 'aboutToDisappear') 52 AppStorage.Set('choseFiles', []) 53 } 54 55 refreshFiles() { 56 logInfo(TAG, 'refreshFiles') 57 AppStorage.Set('choseFiles', []) 58 if (!globalThis.debugMode) { 59 this.mWorker.postMessage({ 60 request_data: 'listFile', 61 device_name: 'local', 62 menu_level: this.mMenuLevel, 63 MediaType: this.mType, 64 path: this.mCurrentPath, 65 context: globalThis.context, 66 }) 67 } 68 } 69 70 build() { 71 Column() { 72 Flex({ 73 direction: FlexDirection.Row, 74 wrap: FlexWrap.Wrap, 75 justifyContent: FlexAlign.Start, 76 alignItems: ItemAlign.Start 77 }) { 78 ForEach(this.mFileInfo, (item: FileInfo, index: number) => { 79 Column() { 80 DetailRowView({ 81 listItem: item, 82 mMenuLevel: $mMenuLevel, 83 mCurrentPath: $mCurrentPath 84 }) 85 86 Divider() 87 .color('#000000') 88 .opacity(0.05) 89 .visibility(this.mFileInfo.length == index + 1 ? Visibility.Hidden : Visibility.Visible) 90 .margin({ left: 64 * 1.3, right: 12 * 1.3 }) 91 } 92 }, (item: FileInfo) => item.name) 93 } 94 } 95 .padding({ bottom: 4 * 1.3 }) 96 .alignItems(HorizontalAlign.Start) 97 .border({ radius: 24 }) 98 .opacity(0.9) 99 .backgroundColor(Color.White) 100 } 101} 102 103@Component 104struct DetailRowView { 105 private dialogController: CustomDialogController = new CustomDialogController({ 106 builder: ChooseDialog(), 107 cancel: () => { 108 }, 109 autoCancel: true 110 }) 111 @State listItem: FileInfo = new FileInfo('') 112 @Link mCurrentPath: string 113 @Link mMenuLevel: number 114 @StorageLink('choseFiles') @Watch('choseFilesChange') choseFiles: Array<FileInfo> = [] 115 116 private choseFilesChange() { 117 this.choseFiles.forEach((item: FileInfo) => { 118 logInfo(TAG, 'choseFilesChange item.name = ' + item.name + ' gridItem.name = ' + this.listItem.name) 119 logInfo(TAG, 'choseFilesChange item.path = ' + item.path + ' gridItem.path = ' + this.listItem.path) 120 if (item.name == this.listItem.name && item.path == this.listItem.path) { 121 this.listItem.listBackground = '#19007DFF' 122 } else { 123 this.listItem.listBackground = '' 124 } 125 126 }) 127 } 128 129 build() { 130 Row() { 131 if (this.listItem.type == MediaType.MEDIA_TYPE_ALBUM) { 132 Row() { 133 Image($r("app.media.ic_type_bigfile")) 134 .width(40 * 1.3) 135 .height(40 * 1.3) 136 .margin({ left: 10 * 1.3 }) 137 Text(this.listItem.name) 138 .fontSize(16 * 1.3) 139 .fontColor('#182431') 140 .fontWeight(FontWeight.Medium) 141 .margin({ left: 16 * 1.3 }) 142 .maxLines(1) 143 .textOverflow({ overflow: TextOverflow.Ellipsis }) 144 Blank() 145 Image($r("app.media.ic_right")) 146 .width(12 * 1.3) 147 .height(24 * 1.3) 148 .margin({ right: 12 * 1.3 }) 149 } 150 .margin({ right: 12 * 1.3 }) 151 .height(64 * 1.3) 152 .width('100%') 153 .backgroundColor(this.listItem.listBackground) 154 } else { 155 Row() { 156 Image(getShowIconBySuffix(this.listItem.name.substring(this.listItem.name.lastIndexOf('.')))) 157 .width(40 * 1.3) 158 .height(40 * 1.3) 159 .margin({ left: 8 * 1.3 }) 160 Column() { 161 Text(this.listItem.name) 162 .height(22 * 1.3) 163 .fontSize(16 * 1.3) 164 .fontColor(this.listItem.fontColor) 165 .fontWeight(FontWeight.Medium) 166 .maxLines(1) 167 .textOverflow({ overflow: TextOverflow.Ellipsis }) 168 .margin({ top: 10 * 1.3 }) 169 .height(22 * 1.3) 170 .width(248 * 1.3) 171 Row() { 172 Text('' + this.listItem.modifiedTime) 173 .fontSize(14 * 1.3) 174 .fontColor(this.listItem.fontColor) 175 .fontWeight(FontWeight.Regular) 176 .maxLines(1) 177 .textOverflow({ overflow: TextOverflow.Ellipsis }) 178 Text('-') 179 .fontSize(14 * 1.3) 180 .fontColor(this.listItem.fontColor) 181 .margin({ left: 8 * 1.3 }) 182 Text('' + this.listItem.size) 183 .fontSize(14 * 1.3) 184 .fontColor(this.listItem.fontColor) 185 .fontWeight(FontWeight.Regular) 186 .margin({ left: 8 * 1.3 }) 187 .maxLines(1) 188 .textOverflow({ overflow: TextOverflow.Ellipsis }) 189 } 190 .width(248 * 1.3) 191 .height(19 * 1.3) 192 .margin({ top: 2 * 1.3 }) 193 .opacity(0.6) 194 } 195 .height(64 * 1.3) 196 .alignItems(HorizontalAlign.Start) 197 .margin({ left: 16 * 1.3 }) 198 } 199 .width('100%') 200 .height(64 * 1.3) // TODO 201 202 } 203 } 204 .margin({ top: 4 * 1.3, left: 4 * 1.3, right: 4 * 1.3 }) 205 .border({ radius: 20 }) 206 .backgroundColor(this.listItem.listBackground) 207 .onClick(() => { 208 if (this.listItem.type == MediaType.MEDIA_TYPE_ALBUM) { 209 logInfo(TAG, 'fold onClick') 210 this.mCurrentPath = this.listItem.path 211 updateTopPathInfo(AppStorage.Get('topPathInfo'), this.listItem.name, this.listItem.path) 212 } else { 213 var index = this.choseFiles.indexOf(this.listItem) 214 this.choseFiles.splice(0, this.choseFiles.length) 215 if (index == -1) { 216 this.listItem.fontColor = Color.Black 217 this.listItem.opacity = 0.1 218 this.listItem.listBackground = 'rgba(46,136,255,0.1)' 219 this.choseFiles.push(this.listItem) 220 } else { 221 this.listItem.fontColor = Color.Black 222 this.listItem.opacity = 1 223 this.listItem.listBackground = '' 224 } 225 } 226 }) 227 .gesture( 228 LongPressGesture({ repeat: false }) 229 .onAction((event: GestureEvent) => { 230 if (this.listItem.type != MediaType.MEDIA_TYPE_ALBUM) { 231 AppStorage.SetOrCreate<FileInfo>('selectedFileInfo', this.listItem) 232 this.dialogController.open() 233 } 234 }) 235 ) 236 } 237}