• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022 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 */
15import MediaLib from '@ohos.multimedia.mediaLibrary';
16import { Log } from '@ohos/base/src/main/ets/utils/Log';
17import { DateUtil } from '@ohos/base/src/main/ets/utils/DateUtil';
18import screenManager from '@ohos/base/src/main/ets/manager/ScreenManager';
19import { Constants } from '../../model/common/Constants';
20
21@Observed
22export class MediaDetails {
23    mediaType: number
24    height: number
25    width: number
26    size: number
27    path: string
28    duration: number
29    title: string
30    dateTaken: number
31    dateAdded: number
32    uri: string
33    displayName: string
34    dateModified: number
35}
36
37@CustomDialog
38export struct DetailsDialog {
39    private TAG: string = 'DetailsDialog'
40    @StorageLink('isHorizontal') isHorizontal: boolean = screenManager.isHorizontal();
41    @StorageLink('isSidebar') isSidebar: boolean = screenManager.isSidebar();
42    @StorageLink('leftBlank') leftBlank: [number, number, number, number] = [0, 0, 0, 0];
43    sizeConvert = 1024;
44    controller: CustomDialogController;
45    dataTime: string;
46    @Consume mediaDetails: MediaDetails;
47    @Consume isDistributedAlbum: boolean;
48
49    aboutToAppear() {
50        let localizedDate = DateUtil.getLocalizedDate(this.mediaDetails.dateAdded);
51        let localizedTime = DateUtil.getLocalizedTime(this.mediaDetails.dateAdded);
52        this.dataTime = `${localizedDate} ${localizedTime}`;
53    }
54
55    getResolution(height: number, width: number): string {
56        return `${width}x${height}`;
57    }
58
59    getTitle() {
60        Log.info(this.TAG, 'getTitle');
61        if (this.mediaDetails.title) {
62            return this.mediaDetails.title;
63        }
64        let index = this.mediaDetails.displayName.lastIndexOf('.');
65        return this.mediaDetails.displayName.substr(0, index);
66    }
67
68    getDisplayPath(): string {
69        let showPath = `${this.mediaDetails.path}${this.mediaDetails.displayName}`;
70        return showPath;
71    }
72
73    getSize(size: number): string {
74        if (size / (this.sizeConvert * this.sizeConvert) > 1) {
75            return `${(size / (this.sizeConvert * this.sizeConvert)).toFixed(2)}MB`;
76        } else {
77            return `${(size / this.sizeConvert).toFixed(2)}KB`;
78        }
79    }
80
81    build() {
82        Column() {
83            Row() {
84                Text($r('app.string.details'))
85                    .fontSize($r('sys.float.ohos_id_text_size_headline7'))
86                    .fontWeight(FontWeight.Medium)
87                    .fontColor($r('sys.color.ohos_id_color_text_primary'))
88            }.alignItems(VerticalAlign.Center)
89            .height($r('app.float.dialog_title_height'))
90
91            Row() {
92                Column() {
93                    Text($r('app.string.title'))
94                        .fontSize($r('sys.float.ohos_id_text_size_body2'))
95                        .fontFamily($r('app.string.id_text_font_family_regular'))
96                        .fontColor($r('sys.color.ohos_id_color_text_primary'))
97                }
98
99                Column() {
100                    Text(this.getTitle())
101                        .fontSize($r('sys.float.ohos_id_text_size_body2'))
102                        .fontFamily($r('app.string.id_text_font_family_regular'))
103                        .fontColor($r('sys.color.ohos_id_color_text_secondary'))
104                        .maxLines(Constants.DETAILS_DIALOG_NAME_MAX_LINE)
105                        .padding({ right: $r('app.float.dialog_content_margin') })
106                }
107            }.alignItems(VerticalAlign.Top)
108            .margin({ bottom: $r('sys.float.ohos_id_text_paragraph_margin_s') })
109
110            Row() {
111                Column() {
112                    Text($r('app.string.time'))
113                        .fontSize($r('sys.float.ohos_id_text_size_body2'))
114                        .fontFamily($r('app.string.id_text_font_family_regular'))
115                        .fontColor($r('sys.color.ohos_id_color_text_primary'))
116                }
117
118                Column() {
119                    Text(this.dataTime)
120                        .fontSize($r('sys.float.ohos_id_text_size_body2'))
121                        .fontFamily($r('app.string.id_text_font_family_regular'))
122                        .fontColor($r('sys.color.ohos_id_color_text_secondary'))
123                        .textOverflow({ overflow: TextOverflow.Ellipsis })
124                }
125            }.margin({
126                bottom: $r('sys.float.ohos_id_text_paragraph_margin_s') })
127
128            Row() {
129                Column() {
130                    Text($r('app.string.size'))
131                        .fontSize($r('sys.float.ohos_id_text_size_body2'))
132                        .fontFamily($r('app.string.id_text_font_family_regular'))
133                        .fontColor($r('sys.color.ohos_id_color_text_primary'))
134                }
135
136                Column() {
137                    Text(`${this.getSize(this.mediaDetails.size)}`)
138                        .fontSize($r('sys.float.ohos_id_text_size_body2'))
139                        .fontFamily($r('app.string.id_text_font_family_regular'))
140                        .fontColor($r('sys.color.ohos_id_color_text_secondary'))
141                        .textOverflow({ overflow: TextOverflow.Ellipsis })
142                }
143            }.margin({
144                bottom: $r('sys.float.ohos_id_text_paragraph_margin_s') })
145
146            Row() {
147                Column() {
148                    Text($r('app.string.resolution'))
149                        .fontSize($r('sys.float.ohos_id_text_size_body2'))
150                        .fontFamily($r('app.string.id_text_font_family_regular'))
151                        .fontColor($r('sys.color.ohos_id_color_text_primary'))
152                }
153
154                Column() {
155                    Text(this.getResolution(this.mediaDetails.height, this.mediaDetails.width))
156                        .fontSize($r('sys.float.ohos_id_text_size_body2'))
157                        .fontFamily($r('app.string.id_text_font_family_regular'))
158                        .fontColor($r('sys.color.ohos_id_color_text_secondary'))
159                        .textOverflow({ overflow: TextOverflow.Ellipsis })
160                }
161            }.margin({
162                bottom: $r('sys.float.ohos_id_text_paragraph_margin_s') })
163
164            if (this.mediaDetails.mediaType == MediaLib.MediaType.VIDEO) {
165                Row() {
166                    Column() {
167                        Text($r('app.string.duration'))
168                            .fontSize($r('sys.float.ohos_id_text_size_body2'))
169                            .fontFamily($r('app.string.id_text_font_family_regular'))
170                            .fontColor($r('sys.color.ohos_id_color_text_primary'))
171                    }
172
173                    Column() {
174                        Text(DateUtil.getFormattedDuration(this.mediaDetails.duration))
175                            .fontSize($r('sys.float.ohos_id_text_size_body2'))
176                            .fontFamily($r('app.string.id_text_font_family_regular'))
177                            .fontColor($r('sys.color.ohos_id_color_text_secondary'))
178                            .textOverflow({ overflow: TextOverflow.Ellipsis })
179                    }
180                }.margin({
181                    bottom: $r('sys.float.ohos_id_text_paragraph_margin_s') })
182            }
183            if (!this.isDistributedAlbum) {
184                Row() {
185                    Column() {
186                        Text($r('app.string.path'))
187                            .fontSize($r('sys.float.ohos_id_text_size_body2'))
188                            .fontFamily($r('app.string.id_text_font_family_regular'))
189                            .fontColor($r('sys.color.ohos_id_color_text_primary'))
190                    }
191
192                    Column() {
193                        Text(this.getDisplayPath())
194                            .fontSize($r('sys.float.ohos_id_text_size_body2'))
195                            .fontFamily($r('app.string.id_text_font_family_regular'))
196                            .fontColor($r('sys.color.ohos_id_color_text_secondary'))
197                            .maxLines(Constants.DETAILS_DIALOG_PATH_MAX_LINE)
198                            .padding({ right: $r('app.float.dialog_content_margin') })
199                    }
200                }.alignItems(VerticalAlign.Top)
201                .margin({
202                    bottom: $r('sys.float.ohos_id_text_paragraph_margin_s') })
203            }
204
205            Stack({ alignContent: Alignment.Top }) {
206                Button() {
207                    Text($r('app.string.detail_dialog_confirm'))
208                        .fontSize($r('sys.float.ohos_id_text_size_button1'))
209                        .fontColor($r('app.color.color_control_highlight'))
210                        .width('100%')
211                        .textAlign(TextAlign.Center)
212                        .fontWeight(FontWeight.Medium)
213                }
214                .backgroundColor($r('app.color.transparent'))
215                .height($r('app.float.details_dialog_button_height'))
216                .onClick(() => {
217                    this.controller.close()
218                })
219            }.width('100%')
220            .height($r('app.float.details_dialog_button_area_height'))
221        }
222        .borderRadius($r('app.float.dialog_border_radius'))
223        .width(screenManager.getColumnsWidth(4))
224        .backgroundColor($r('app.color.white'))
225        .margin({
226            right: $r('app.float.dialog_window_margin'),
227            left: $r('app.float.dialog_window_margin'),
228            bottom: this.isHorizontal || this.isSidebar ? 0 : Constants.DIALOG_BOTTOM_OFFSET + px2vp(this.leftBlank[3])
229        })
230        .padding({ left: $r('app.float.dialog_content_margin'), right: $r('app.float.dialog_content_margin') })
231        .alignItems(HorizontalAlign.Start)
232    }
233}
234