• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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 photoAccessHelper from '@ohos.file.photoAccessHelper';
17import { DialogCallback } from '../utils/DialogUtil';
18import { Log } from '../utils/Log';
19import { DateUtil } from '../utils/DateUtil';
20import { FindSameOperation } from '../menus/ProcessMenuOperation';
21import { screenManager } from '../common/ScreenManager';
22import { Constants } from '../constants/Constants';
23
24@Observed
25export class FindSameNameParam {
26  sourceFileAsset: photoAccessHelper.PhotoAsset | null = null;
27  targetFileAsset: photoAccessHelper.PhotoAsset | null = null;
28  replaceFunc: Function | null = null;
29  skipFunc: Function | null = null;
30  cancelFunc: Function | null = null;
31  singlePhoto: boolean = false;
32  doSameFunc: Function | null = null;
33}
34
35@CustomDialog
36export struct FindSameNameDialog {
37  private TAG: string = 'FindSameNameDialog'
38  @StorageLink('isHorizontal') isHorizontal: boolean = screenManager.isHorizontal();
39  @StorageLink('isSidebar') isSidebar: boolean = screenManager.isSidebar();
40  @StorageLink('leftBlank') leftBlank: number[] = [0, 0, 0, 0];
41  @State isDoSameAction: boolean = false;
42  @Consume dialogCallback: DialogCallback;
43  @Consume dialogMessage: Resource;
44  @Consume findSameNameParam: FindSameNameParam;
45  sourceDetails: photoAccessHelper.PhotoAsset | null = null;
46  targetDetails: photoAccessHelper.PhotoAsset | null = null;
47  controller?: CustomDialogController;
48  dataTime: string = '';
49  targetDataTime: string = '';
50  timeConvert = 1000;
51
52  getTitle(name: string): string {
53    Log.info(this.TAG, 'getTitle ' + name);
54    if (name != null) {
55      let index: number = name.lastIndexOf('.');
56      if (index === -1) {
57        return name;
58      }
59      return name.substr(0, index);
60    } else {
61      return '';
62    }
63  }
64
65  aboutToAppear(): void {
66    this.sourceDetails = this.findSameNameParam.sourceFileAsset;
67    this.targetDetails = this.findSameNameParam.targetFileAsset;
68    try{
69      this.dataTime = DateUtil.getDateTimeFormat(this.sourceDetails?.get(photoAccessHelper.PhotoKeys.DATE_MODIFIED.toString()) as number * this.timeConvert);
70      this.targetDataTime = DateUtil.getDateTimeFormat(this.targetDetails?.get(photoAccessHelper.PhotoKeys.DATE_MODIFIED.toString()) as number * this.timeConvert);
71    }catch (err){
72    }
73  }
74
75  build() {
76    Column() {
77      Row() {
78        Text($r('app.string.find_same_name'))
79          .fontSize($r('sys.float.ohos_id_text_size_dialog_tittle'))
80          .fontWeight(FontWeight.Medium)
81          .fontColor($r('sys.color.ohos_id_color_text_primary'))
82      }.alignItems(VerticalAlign.Center)
83      .height($r('app.float.dialog_title_height'))
84
85      Row() {
86        Column() {
87          if(this.sourceDetails !== null && this.sourceDetails !== undefined){
88            Text($r('app.string.target_has_same_name', this.getTitle(this.sourceDetails.displayName)))
89              .fontSize($r('sys.float.ohos_id_text_size_sub_title2'))
90              .fontWeight(FontWeight.Medium)
91              .fontColor($r('sys.color.ohos_id_color_text_primary'))
92              .maxLines(3)
93          }
94        }
95      }.margin({
96        bottom: $r('app.float.same_name_date_title_dialog_bottom') })
97
98      Row() {
99        Column() {
100          Text($r('app.string.source_file_location'))
101            .fontSize($r('sys.float.ohos_id_text_size_sub_title2'))
102            .fontWeight(FontWeight.Medium)
103            .fontColor($r('sys.color.ohos_id_color_text_primary'))
104        }
105      }.margin({
106        bottom: $r('app.float.same_name_date_title2_dialog_bottom') })
107
108      Row() {
109        Column() {
110          //TODO
111          //Text($r('app.string.file_size_location', (this.sourceDetails.size / Constants.BYTE_TO_MB).toFixed(2) + 'MB'))
112          Text($r('app.string.file_size_location', 'unknown MB'))
113            .fontSize($r('sys.float.ohos_id_text_size_sub_title2'))
114            .fontWeight(FontWeight.Regular)
115            .fontColor($r('sys.color.ohos_id_color_text_primary'))
116        }
117      }.margin({
118        bottom: $r('app.float.same_name_date_title3_dialog_bottom') })
119
120      Row() {
121        Column() {
122          Text($r('app.string.file_time_location', this.dataTime))
123            .fontSize($r('sys.float.ohos_id_text_size_body2'))
124            .fontWeight(FontWeight.Regular)
125            .fontColor($r('sys.color.ohos_id_color_text_secondary'))
126        }
127      }.margin({
128        bottom: $r('app.float.same_name_date_title_dialog_bottom') })
129
130      Row() {
131        Column() {
132          Text($r('app.string.target_file_location'))
133            .fontSize($r('sys.float.ohos_id_text_size_sub_title2'))
134            .fontWeight(FontWeight.Medium)
135            .fontColor($r('sys.color.ohos_id_color_text_primary'))
136        }
137      }.margin({
138        bottom: $r('app.float.same_name_date_title2_dialog_bottom') })
139
140      Row() {
141        Column() {
142          //TODO
143          Text($r('app.string.file_size_location', 'xx MB'))
144            .fontSize($r('sys.float.ohos_id_text_size_sub_title2'))
145            .fontWeight(FontWeight.Regular)
146            .fontColor($r('sys.color.ohos_id_color_text_primary'))
147        }
148      }.margin({
149        bottom: $r('app.float.same_name_date_title3_dialog_bottom') })
150
151      Row() {
152        Column() {
153          Text($r('app.string.file_time_location', this.targetDataTime))
154            .fontSize($r('sys.float.ohos_id_text_size_body2'))
155            .fontWeight(FontWeight.Regular)
156            .fontColor($r('sys.color.ohos_id_color_text_secondary'))
157        }
158      }.margin({
159        bottom: $r('app.float.same_name_date_title_dialog_bottom') })
160
161      Row() {
162        Image(this.isDoSameAction ? $r('app.media.ic_gallery_public_checkbox_filled')
163                      : $r('app.media.ic_checkbox_off_black_bg'))
164          .height($r('app.float.icon_size'))
165          .width($r('app.float.icon_size'))
166          .margin({
167            right: $r('app.float.details_dialog_button_margin_right') })
168          .onClick((): void => {
169            this.isDoSameAction = !this.isDoSameAction
170          })
171
172        Text($r('app.string.do_same_action'))
173          .fontSize($r('sys.float.ohos_id_text_size_sub_title2'))
174          .fontFamily($r('app.string.id_text_font_family_regular'))
175          .fontColor($r('sys.color.ohos_id_color_text_primary'))
176      }
177      .visibility(this.findSameNameParam.singlePhoto ? Visibility.None : Visibility.Visible)
178      .margin({
179        bottom: $r('app.float.same_name_date_dialog_bottom') })
180
181      Stack({ alignContent: Alignment.Top }) {
182        Row() {
183          Button() {
184            Text($r('app.string.replace_action'))
185              .fontSize($r('sys.float.ohos_id_text_size_button1'))
186              .fontColor($r('app.color.color_control_highlight'))
187              .width(this.findSameNameParam.singlePhoto ? '50%' : Constants.PERCENT_ONE_THIRD)
188              .textAlign(TextAlign.Center)
189              .fontWeight(FontWeight.Medium)
190          }
191          .margin({
192            left: $r('app.float.details_dialog_button_margin_left'),
193            right: $r('app.float.details_dialog_button_margin_right')
194          })
195          .backgroundColor($r('app.color.transparent'))
196          .height($r('app.float.details_dialog_button_height'))
197          .onClick((): void => {
198            Log.debug(this.TAG, 'replaceCallback');
199            if (this.isDoSameAction && this.findSameNameParam.doSameFunc != null) {
200              this.findSameNameParam.doSameFunc(FindSameOperation.REPLACE);
201            }
202            if(this.findSameNameParam.replaceFunc != null) this.findSameNameParam.replaceFunc();
203            this.controller?.close();
204          })
205
206          Row() {
207            Divider()
208              .vertical(true)
209              .height($r('app.float.dialog_divider_height'))
210              .color($r('app.color.divider_vertical_color'))
211          }
212          .height($r('app.float.details_dialog_button_height'))
213          .alignItems(VerticalAlign.Center)
214
215          if (!this.findSameNameParam.singlePhoto) {
216            Button() {
217              Text($r('app.string.skip_action'))
218                .fontSize($r('sys.float.ohos_id_text_size_button1'))
219                .fontColor($r('app.color.color_control_highlight'))
220                .width(Constants.PERCENT_ONE_THIRD)
221                .textAlign(TextAlign.Center)
222                .fontWeight(FontWeight.Medium)
223            }
224            .margin({
225              left: $r('app.float.details_dialog_button_margin_left'),
226              right: $r('app.float.details_dialog_button_margin_right')
227            })
228            .backgroundColor($r('app.color.transparent'))
229            .height($r('app.float.details_dialog_button_height'))
230            .onClick((): void => {
231              Log.debug(this.TAG, 'skipCallback');
232              if (this.isDoSameAction && this.findSameNameParam.doSameFunc != null) {
233                this.findSameNameParam.doSameFunc(FindSameOperation.SKIP);
234              }
235              if(this.findSameNameParam.skipFunc != null) this.findSameNameParam.skipFunc();
236              this.controller?.close();
237            })
238
239            Row() {
240              Divider()
241                .vertical(true)
242                .height($r('app.float.dialog_divider_height'))
243                .color($r('app.color.divider_vertical_color'))
244            }
245            .height($r('app.float.details_dialog_button_height'))
246            .alignItems(VerticalAlign.Center)
247          }
248
249          Button() {
250            Text($r('app.string.dialog_cancel'))
251              .fontSize($r('sys.float.ohos_id_text_size_button1'))
252              .fontColor($r('app.color.color_control_highlight'))
253              .width(this.findSameNameParam.singlePhoto ? '50%' : Constants.PERCENT_ONE_THIRD)
254              .textAlign(TextAlign.Center)
255              .fontWeight(FontWeight.Medium)
256          }
257          .margin({
258            left: $r('app.float.details_dialog_button_margin_left'),
259            right: $r('app.float.details_dialog_button_margin_right')
260          })
261          .backgroundColor($r('app.color.transparent'))
262          .height($r('app.float.details_dialog_button_height'))
263          .onClick((): void => {
264            Log.debug(this.TAG, 'cancelFunc');
265            if(this.findSameNameParam.cancelFunc != null) this.findSameNameParam.cancelFunc();
266            this.controller?.close();
267          })
268        }
269      }
270      .width('100%')
271      .height($r('app.float.details_dialog_button_area_height'))
272    }
273    .padding({ left: $r('app.float.dialog_content_margin'), right: $r('app.float.dialog_content_margin') })
274    .alignItems(HorizontalAlign.Start)
275    .borderRadius($r('app.float.dialog_border_radius'))
276    .width(screenManager.getColumnsWidth(4))
277    .backgroundColor($r('app.color.white'))
278    .margin({
279      right: $r('app.float.dialog_window_margin'),
280      left: $r('app.float.dialog_window_margin'),
281      bottom: this.isHorizontal || this.isSidebar ? 0 : Constants.DIALOG_BOTTOM_OFFSET + px2vp(this.leftBlank[3])
282    })
283  }
284}
285