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