1/* 2 * Copyright (c) 2022-2023 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 { Log } from '../../utils/Log'; 17import { DateUtil } from '../../utils/DateUtil'; 18import { UserFileManagerAccess } from '../../access/UserFileManagerAccess'; 19import { ColumnSize, ScreenManager } from '../../model/common/ScreenManager'; 20import { Constants } from '../../model/common/Constants'; 21import { DetailsDialogComponent } from '../DetailsDialogComponent'; 22 23const TAG: string = 'common_DetailsDialog'; 24 25@Observed 26export class MediaDetails { 27 public mediaType: number = 0; 28 public height: number = 0; 29 public width: number = 0; 30 public size: number = 0; 31 public duration: number = 0; 32 public title: string = ''; 33 public dateTaken: number = 0; 34 public uri: string = ''; 35 public displayName: string = ''; 36 public dateModified: number = 0; 37} 38 39@CustomDialog 40export struct DetailsDialog { 41 static readonly INTERNAL_PREFIX_NUM = 3; 42 static readonly EXTERNAL_PREFIX_NUM = 2; 43 @StorageLink('isHorizontal') isHorizontal: boolean = ScreenManager.getInstance().isHorizontal(); 44 @StorageLink('isSidebar') isSidebar: boolean = ScreenManager.getInstance().isSidebar(); 45 @StorageLink('leftBlank') leftBlank: number[] = 46 [0, ScreenManager.getInstance().getStatusBarHeight(), 0, ScreenManager.getInstance().getNaviBarHeight()]; 47 sizeConvert = 1024; 48 controller?: CustomDialogController; 49 dataTime: string = ''; 50 @Consume mediaDetails: MediaDetails; 51 @Consume isDistributedAlbum: boolean; 52 @State refresh: boolean = false; 53 private isPcDevice: boolean = AppStorage.get<string>('deviceType') === Constants.PC_DEVICE_TYPE; 54 onWindowSizeChangeCallBack = (): void => this.updateDialogSize(); 55 56 aboutToAppear() { 57 let localizedDate = DateUtil.getLocalizedDate(this.mediaDetails.dateTaken); 58 let localizedTime = DateUtil.getLocalizedTime(this.mediaDetails.dateTaken); 59 this.dataTime = `${localizedDate} ${localizedTime}`; 60 let self = this; 61 62 ScreenManager.getInstance().on(ScreenManager.ON_WIN_SIZE_CHANGED, this.onWindowSizeChangeCallBack); 63 } 64 65 aboutToDisappear(): void { 66 Log.info(TAG, 'aboutToDisappear'); 67 ScreenManager.getInstance().off(ScreenManager.ON_WIN_SIZE_CHANGED, this.onWindowSizeChangeCallBack); 68 } 69 70 getResolution(height: number, width: number): string { 71 return `${width}x${height}`; 72 } 73 74 getTitle() { 75 Log.info(TAG, 'getTitle'); 76 if (this.mediaDetails.title) { 77 return this.mediaDetails.title; 78 } 79 let index = this.mediaDetails.displayName.lastIndexOf('.'); 80 return this.mediaDetails.displayName.substr(0, index); 81 } 82 83 getSize(size: number): string { 84 Log.info(TAG, `file size is: ${size}`); 85 if (size / (this.sizeConvert * this.sizeConvert) > 1) { 86 return `${(size / (this.sizeConvert * this.sizeConvert)).toFixed(2)}MB`; 87 } else { 88 return `${(size / this.sizeConvert).toFixed(2)}KB`; 89 } 90 } 91 92 updateDialogSize() { 93 this.refresh = !this.refresh; 94 } 95 96 build() { 97 Column() { 98 if (this.refresh && false) { 99 Column() 100 } 101 Row() { 102 Text($r('app.string.details')) 103 .key('DetailsBigTitle') 104 .fontSize($r('sys.float.ohos_id_text_size_dialog_tittle')) 105 .fontWeight(FontWeight.Medium) 106 .fontColor($r('sys.color.ohos_id_color_text_primary')) 107 }.alignItems(VerticalAlign.Center) 108 .height($r('app.float.dialog_title_height')) 109 110 DetailsDialogComponent({ 111 title: $r('app.string.title'), 112 content: this.getTitle(), 113 keyForAutoTest: Constants.KEY_FOR_AUTO_TEST_TITLE 114 }) 115 DetailsDialogComponent({ 116 title: $r('app.string.time'), 117 content: this.dataTime, 118 keyForAutoTest: Constants.KEY_FOR_AUTO_TEST_TIME 119 }) 120 DetailsDialogComponent({ 121 title: $r('app.string.size'), 122 content: `${this.getSize(this.mediaDetails.size)}`, 123 keyForAutoTest: Constants.KEY_FOR_AUTO_TEST_SIZE 124 }) 125 DetailsDialogComponent({ 126 title: $r('app.string.resolution'), 127 content: this.getResolution(this.mediaDetails.height, this.mediaDetails.width), 128 isLast: this.mediaDetails.mediaType != UserFileManagerAccess.MEDIA_TYPE_VIDEO && this.isDistributedAlbum, 129 keyForAutoTest: Constants.KEY_FOR_AUTO_TEST_RESOLUTION 130 }) 131 if (this.mediaDetails.mediaType == UserFileManagerAccess.MEDIA_TYPE_VIDEO) { 132 DetailsDialogComponent({ 133 title: $r('app.string.duration'), 134 content: DateUtil.getFormattedDuration(this.mediaDetails.duration), 135 isLast: this.isDistributedAlbum != null && this.isDistributedAlbum, 136 keyForAutoTest: Constants.KEY_FOR_AUTO_TEST_DURATION 137 }) 138 } 139 140 Stack({ alignContent: Alignment.Top }) { 141 Button() { 142 Text($r('app.string.detail_dialog_confirm')) 143 .fontSize($r('sys.float.ohos_id_text_size_button1')) 144 .fontColor($r('app.color.color_control_highlight')) 145 .width('100%') 146 .textAlign(TextAlign.Center) 147 .fontWeight(FontWeight.Medium) 148 } 149 .key('DetailsDialogConfirm') 150 .backgroundColor(this.isPcDevice ? $r('sys.color.ohos_id_color_button_normal') : $r('app.color.transparent')) 151 .height($r('app.float.details_dialog_button_height')) 152 .onClick(() => { 153 this.controller?.close(); 154 }) 155 .margin({ 156 left: $r('app.float.dialog_single_button_indent_margin'), 157 right: $r('app.float.dialog_single_button_indent_margin') 158 }) 159 }.width('100%') 160 .height($r('app.float.details_dialog_button_area_height')) 161 } 162 .borderRadius($r('sys.float.ohos_id_corner_radius_default_l')) 163 .width(this.isPcDevice ? $r('app.float.pc_dialog_width') : ScreenManager.getInstance() 164 .getColumnsWidth(ColumnSize.COLUMN_FOUR)) 165 .backgroundColor($r('app.color.white')) 166 .margin({ 167 right: $r('app.float.dialog_window_margin'), 168 left: $r('app.float.dialog_window_margin'), 169 bottom: this.isHorizontal || this.isSidebar ? 0 : Constants.DIALOG_BOTTOM_OFFSET + this.leftBlank[3] 170 }) 171 .padding({ left: $r('app.float.dialog_content_margin'), right: $r('app.float.dialog_content_margin') }) 172 .alignItems(HorizontalAlign.Start) 173 .shadow({ 174 radius: $r('app.float.dialog_defult_shadow_m_radio'), 175 color: $r('app.color.dialog_defult_shadow_m_color'), 176 offsetX: $r('app.float.dialog_defult_shadow_m_offsetX'), 177 offsetY: $r('app.float.dialog_defult_shadow_m_offsetY') 178 }) 179 } 180} 181