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 16enum ActionID { 17 NONE, 18 OK, 19 OK_DISABLE, 20 CANCEL, 21 BACK, 22 INFO, 23 INFO_INVALID, 24 DELETE, 25 DELETE_RECYCLE, 26 CLEAR_RECYCLE, 27 DELETE_INVALID, 28 RECOVER, 29 RECOVER_INVALID, 30 FAVORITE, 31 NOT_FAVORITE, 32 UN_SELECTED, 33 SELECTED, 34 MULTISELECT, 35 MULTISELECT_INVALID, 36 SELECT_ALL, 37 DESELECT_ALL, 38 SETTING, 39 NAVIGATION, 40 MATERIAL_SELECT, 41 GOTO_PHOTOS, 42 SHARE, 43 SHARE_INVALID, 44 EDIT, 45 EDIT_INVALID, 46 MORE, 47 NEW, 48 RENAME, 49 RENAME_INVALID, 50 ADD_NOTES, 51 ROTATE, 52 MOVE, 53 MOVE_INVALID, 54 ADD, 55 ADD_INVALID, 56 COPY, 57 COPY_INVALID, 58 REMOVE_FROM, 59 REMOVE_FROM_INVALID, 60 NAVIGATION_ALBUMS, 61 DOWNLOAD, 62 DOWNLOAD_INVALID, 63 CLEAR_RECYCLE_INVALID 64} 65 66const COMPONENT_KEY_OK: string = 'OK'; 67const COMPONENT_KEY_OK_DISABLE: string = 'OK'; 68const COMPONENT_KEY_CANCEL: string = 'Cancel'; 69const COMPONENT_KEY_BACK: string = 'Back'; 70const COMPONENT_KEY_INFO: string = 'Info'; 71const COMPONENT_KEY_INFO_INVALID: string = 'Info'; 72const COMPONENT_KEY_DELETE: string = 'Delete'; 73const COMPONENT_KEY_DELETE_RECYCLE: string = 'DeleteRecycle'; 74const COMPONENT_KEY_CLEAR_RECYCLE: string = 'ClearRecycle'; 75const COMPONENT_KEY_DELETE_INVALID: string = 'Delete'; 76const COMPONENT_KEY_RECOVER: string = 'Recover'; 77const COMPONENT_KEY_RECOVER_INVALID: string = 'Recover'; 78const COMPONENT_KEY_FAVORITE: string = 'Favor'; 79const COMPONENT_KEY_NOT_FAVORITE: string = 'Favor'; 80const COMPONENT_KEY_UN_SELECTED: string = 'Selected'; 81const COMPONENT_KEY_SELECTED: string = 'Selected'; 82const COMPONENT_KEY_MULTISELECT: string = 'MultiSelected'; 83const COMPONENT_KEY_MULTISELECT_INVALID: string = 'MultiSelected'; 84const COMPONENT_KEY_SELECT_ALL: string = 'SelectAll'; 85const COMPONENT_KEY_DESELECT_ALL: string = 'SelectAll'; 86const COMPONENT_KEY_NAVIGATION: string = 'Navigation'; 87const COMPONENT_KEY_SETTING: string = 'Setting'; 88const COMPONENT_KEY_MATERIAL_SELECT: string = 'MaterialSelect'; 89const COMPONENT_KEY_GOTO_PHOTOS: string = 'GotoPhotos'; 90const COMPONENT_KEY_SHARE: string = 'Share'; 91const COMPONENT_KEY_SHARE_INVALID: string = 'Share'; 92const COMPONENT_KEY_EDIT: string = 'Edit'; 93const COMPONENT_KEY_EDIT_INVALID: string = 'Edit'; 94const COMPONENT_KEY_MORE: string = 'More'; 95const COMPONENT_KEY_NEW: string = 'New'; 96const COMPONENT_KEY_RENAME: string = 'Rename'; 97const COMPONENT_KEY_RENAME_INVALID: string = 'Rename'; 98const COMPONENT_KEY_ADD_NOTES: string = 'AddNotes'; 99const COMPONENT_KEY_ROTATE: string = 'Rotate'; 100const COMPONENT_KEY_MOVE: string = 'Move'; 101const COMPONENT_KEY_MOVE_INVALID: string = 'Move'; 102const COMPONENT_KEY_COPY: string = 'Copy'; 103const COMPONENT_KEY_COPY_INVALID: string = 'Copy'; 104const COMPONENT_KEY_ADD: string = 'Add'; 105const COMPONENT_KEY_ADD_INVALID: string = 'Add'; 106const COMPONENT_KEY_REMOVE_FROM: string = 'RemoveFrom'; 107const COMPONENT_KEY_REMOVE_FROM_INVALID: string = 'RemoveFrom'; 108const COMPONENT_KEY_NAVIGATION_ALBUMS: string = 'NavigationAlbums'; 109const COMPONENT_KEY_DOWNLOAD: string = 'Download'; 110const COMPONENT_KEY_DOWNLOAD_INVALID: string = 'Download'; 111const COMPONENT_KEY_CLEAR_RECYCLE_INVALID: string = 'ClearRecycle'; 112 113interface ActionOptions { 114 id: number; 115 textRes: Resource; 116 iconRes?: Resource; 117 isAutoTint?: boolean; 118 fillColor?: Resource; 119 actionType?: Resource; 120 componentKey?: string; 121} 122 123export class Action { 124 public static NONE = new Action({ 125 id: ActionID.NONE, 126 iconRes: null, 127 textRes: null 128 }); 129 public static OK = new Action({ 130 id: ActionID.OK, 131 iconRes: $r('app.media.ic_gallery_public_ok'), 132 textRes: $r('app.string.action_ok'), 133 componentKey: COMPONENT_KEY_OK 134 }); 135 public static OK_DISABLE = new Action({ 136 id: ActionID.OK_DISABLE, 137 iconRes: $r('app.media.ic_gallery_public_ok'), 138 textRes: $r('app.string.action_ok'), 139 fillColor: $r('app.color.icon_disabled_color'), 140 componentKey: COMPONENT_KEY_OK_DISABLE 141 }); 142 public static CANCEL = new Action({ 143 id: ActionID.CANCEL, 144 iconRes: $r('app.media.ic_gallery_public_cancel'), 145 textRes: $r('app.string.action_cancel'), 146 fillColor: $r('sys.color.ohos_id_color_primary'), 147 componentKey: COMPONENT_KEY_CANCEL 148 }); 149 public static BACK = new Action({ 150 id: ActionID.BACK, 151 iconRes: $r('app.media.ic_gallery_public_back'), 152 textRes: $r('app.string.action_back'), 153 fillColor: $r('sys.color.ohos_id_color_primary'), 154 componentKey: COMPONENT_KEY_BACK 155 }); 156 public static INFO = new Action({ 157 id: ActionID.INFO, 158 iconRes: $r('app.media.ic_gallery_public_details'), 159 textRes: $r('app.string.action_info'), 160 componentKey: COMPONENT_KEY_INFO 161 }); 162 public static INFO_INVALID = new Action({ 163 id: ActionID.INFO_INVALID, 164 iconRes: $r('app.media.ic_gallery_public_details'), 165 textRes: $r('app.string.action_info'), 166 fillColor: $r('app.color.icon_disabled_color'), 167 componentKey: COMPONENT_KEY_INFO_INVALID 168 }); 169 public static DELETE = new Action({ 170 id: ActionID.DELETE, 171 iconRes: $r('app.media.ic_gallery_public_delete_line'), 172 textRes: $r('app.string.action_delete'), 173 actionType: $r('app.string.action_delete'), 174 componentKey: COMPONENT_KEY_DELETE 175 }); 176 public static DELETE_RECYCLE = new Action({ 177 id: ActionID.DELETE_RECYCLE, 178 iconRes: $r('app.media.ic_gallery_public_delete_line'), 179 textRes: $r('app.string.action_delete'), 180 actionType: $r('app.string.action_delete'), 181 componentKey: COMPONENT_KEY_DELETE_RECYCLE 182 }); 183 public static CLEAR_RECYCLE = new Action({ 184 id: ActionID.CLEAR_RECYCLE, 185 iconRes: $r('app.media.ic_gallery_public_delete_line'), 186 textRes: $r('app.string.action_clear_recycle'), 187 actionType: $r('app.string.action_delete'), 188 componentKey: COMPONENT_KEY_CLEAR_RECYCLE 189 }); 190 public static CLEAR_RECYCLE_INVALID = new Action({ 191 id: ActionID.CLEAR_RECYCLE_INVALID, 192 iconRes: $r('app.media.ic_gallery_public_delete_line'), 193 textRes: $r('app.string.action_clear_recycle'), 194 fillColor: $r('app.color.icon_disabled_color'), 195 actionType: $r('app.string.action_delete'), 196 componentKey: COMPONENT_KEY_CLEAR_RECYCLE_INVALID 197 }); 198 public static DELETE_INVALID = new Action({ 199 id: ActionID.DELETE_INVALID, 200 iconRes: $r('app.media.ic_gallery_public_delete_line'), 201 textRes: $r('app.string.action_delete'), 202 fillColor: $r('app.color.icon_disabled_color'), 203 actionType: $r('app.string.action_delete'), 204 componentKey: COMPONENT_KEY_DELETE_INVALID 205 }); 206 public static RECOVER = new Action({ 207 id: ActionID.RECOVER, 208 iconRes: $r('app.media.ic_gallery_public_undo'), 209 textRes: $r('app.string.action_recover'), 210 actionType: $r('app.string.action_recover'), 211 componentKey: COMPONENT_KEY_RECOVER 212 }); 213 public static RECOVER_INVALID = new Action({ 214 id: ActionID.RECOVER_INVALID, 215 iconRes: $r('app.media.ic_gallery_public_undo'), 216 textRes: $r('app.string.action_recover'), 217 fillColor: $r('app.color.icon_disabled_color'), 218 actionType: $r('app.string.action_recover'), 219 componentKey: COMPONENT_KEY_RECOVER_INVALID 220 }); 221 public static FAVORITE = new Action({ 222 id: ActionID.FAVORITE, 223 iconRes: $r('app.media.ic_gallery_public_Favorite_filled'), 224 textRes: $r('app.string.action_favorite'), 225 fillColor: $r('sys.color.ohos_fa_activated'), 226 actionType: $r('app.string.action_favorite'), 227 componentKey: COMPONENT_KEY_FAVORITE 228 }); 229 public static NOT_FAVORITE = new Action({ 230 id: ActionID.NOT_FAVORITE, 231 iconRes: $r('app.media.ic_gallery_public_favorite_line'), 232 textRes: $r('app.string.action_not_favorite'), 233 actionType: $r('app.string.action_favorite'), 234 componentKey: COMPONENT_KEY_NOT_FAVORITE 235 }); 236 public static UN_SELECTED = new Action({ 237 id: ActionID.UN_SELECTED, 238 iconRes: $r('app.media.ic_checkbox_off'), 239 textRes: $r('app.string.action_unselected'), 240 actionType: $r('app.string.action_selected'), 241 componentKey: COMPONENT_KEY_UN_SELECTED 242 }); 243 public static MULTISELECT = new Action({ 244 id: ActionID.MULTISELECT, 245 iconRes: $r('app.media.ic_gallery_material_select_checkbox'), 246 textRes: $r('app.string.multiselect'), 247 actionType: $r('app.string.action_select_all'), 248 componentKey: COMPONENT_KEY_MULTISELECT 249 }); 250 public static MULTISELECT_INVALID = new Action({ 251 id: ActionID.MULTISELECT_INVALID, 252 iconRes: $r('app.media.ic_gallery_material_select_checkbox'), 253 textRes: $r('app.string.multiselect'), 254 fillColor: $r('app.color.icon_disabled_color'), 255 actionType: $r('app.string.action_select_all'), 256 componentKey: COMPONENT_KEY_MULTISELECT_INVALID 257 }); 258 public static SELECTED = new Action({ 259 id: ActionID.SELECTED, 260 iconRes: $r('app.media.ic_gallery_public_checkbox_filled'), 261 textRes: $r('app.string.action_selected'), 262 isAutoTint: false, 263 actionType: $r('app.string.action_selected'), 264 componentKey: COMPONENT_KEY_SELECTED 265 }); 266 public static SELECT_ALL = new Action({ 267 id: ActionID.SELECT_ALL, 268 iconRes: $r('app.media.ic_gallery_public_select_all'), 269 textRes: $r('app.string.action_select_all'), 270 actionType: $r('app.string.action_select_all'), 271 componentKey: COMPONENT_KEY_SELECT_ALL 272 }); 273 public static DESELECT_ALL = new Action({ 274 id: ActionID.DESELECT_ALL, 275 iconRes: $r('app.media.ic_gallery_public_select_all_action'), 276 textRes: $r('app.string.action_deselect_all'), 277 actionType: $r('app.string.action_select_all'), 278 componentKey: COMPONENT_KEY_DESELECT_ALL 279 }); 280 public static SETTING = new Action({ 281 id: ActionID.SETTING, 282 textRes: $r('app.string.action_setting'), 283 componentKey: COMPONENT_KEY_SETTING 284 }); 285 public static NAVIGATION = new Action({ 286 id: ActionID.NAVIGATION, 287 textRes: $r('app.string.action_navigation'), 288 componentKey: COMPONENT_KEY_NAVIGATION 289 }); 290 public static MATERIAL_SELECT = new Action({ 291 id: ActionID.MATERIAL_SELECT, 292 iconRes: $r('app.media.ic_checkbox_off_black_bg'), 293 textRes: $r('app.string.action_material_select'), 294 isAutoTint: false, 295 actionType: $r('app.string.action_selected'), 296 componentKey: COMPONENT_KEY_MATERIAL_SELECT 297 }); 298 public static GOTO_PHOTOS = new Action({ 299 id: ActionID.GOTO_PHOTOS, 300 iconRes: $r('app.media.ic_goto_photos'), 301 textRes: $r('app.string.action_goto_photos'), 302 componentKey: COMPONENT_KEY_GOTO_PHOTOS 303 }); 304 public static SHARE = new Action({ 305 id: ActionID.SHARE, 306 iconRes: $r('app.media.ic_gallery_public_share'), 307 textRes: $r('app.string.action_share'), 308 actionType: $r('app.string.action_share'), 309 componentKey: COMPONENT_KEY_SHARE 310 }); 311 public static SHARE_INVALID = new Action({ 312 id: ActionID.SHARE_INVALID, 313 iconRes: $r('app.media.ic_gallery_public_share'), 314 fillColor: $r('app.color.icon_disabled_color'), 315 textRes: $r('app.string.action_share'), 316 actionType: $r('app.string.action_share'), 317 componentKey: COMPONENT_KEY_SHARE_INVALID 318 }); 319 public static EDIT = new Action({ 320 id: ActionID.EDIT, 321 iconRes: $r('app.media.ic_gallery_public_edit'), 322 textRes: $r('app.string.action_edit'), 323 componentKey: COMPONENT_KEY_EDIT 324 }); 325 public static EDIT_INVALID = new Action({ 326 id: ActionID.EDIT_INVALID, 327 iconRes: $r('app.media.ic_gallery_public_edit'), 328 textRes: $r('app.string.action_edit'), 329 fillColor: $r('app.color.icon_disabled_color'), 330 componentKey: COMPONENT_KEY_EDIT_INVALID 331 }); 332 public static MORE = new Action({ 333 id: ActionID.MORE, 334 iconRes: $r('app.media.ic_gallery_public_more'), 335 textRes: $r('app.string.more_text'), 336 componentKey: COMPONENT_KEY_MORE 337 }); 338 public static NEW = new Action({ 339 id: ActionID.NEW, 340 iconRes: $r('app.media.ic_gallery_public_new'), 341 textRes: $r('app.string.action_new'), 342 componentKey: COMPONENT_KEY_NEW 343 }); 344 public static RENAME = new Action({ 345 id: ActionID.RENAME, 346 iconRes: $r('app.media.ic_gallery_public_rename'), 347 textRes: $r('app.string.action_rename'), 348 actionType: $r('app.string.action_rename'), 349 componentKey: COMPONENT_KEY_RENAME 350 }); 351 public static RENAME_INVALID = new Action({ 352 id: ActionID.RENAME_INVALID, 353 iconRes: $r('app.media.ic_gallery_public_rename'), 354 textRes: $r('app.string.action_rename'), 355 fillColor: $r('app.color.icon_disabled_color'), 356 actionType: $r('app.string.action_rename'), 357 componentKey: COMPONENT_KEY_RENAME 358 }); 359 public static ROTATE = new Action({ 360 id: ActionID.ROTATE, 361 iconRes: $r('app.media.ic_edit_photo_crop_rotate'), 362 textRes: $r('app.string.rotate_text'), 363 actionType: $r('app.string.rotate_text'), 364 componentKey: COMPONENT_KEY_ROTATE 365 }); 366 public static ADD_NOTES = new Action({ 367 id: ActionID.ADD_NOTES, 368 iconRes: null, 369 textRes: $r('app.string.add_notes'), 370 componentKey: COMPONENT_KEY_ADD_NOTES 371 }); 372 public static MOVE = new Action({ 373 id: ActionID.MOVE, 374 textRes: $r('app.string.move_to_album'), 375 componentKey: COMPONENT_KEY_MOVE 376 }); 377 public static MOVE_INVALID = new Action({ 378 id: ActionID.MOVE_INVALID, 379 textRes: $r('app.string.move_to_album'), 380 fillColor: $r('app.color.icon_disabled_color'), 381 componentKey: COMPONENT_KEY_MOVE_INVALID 382 }); 383 public static ADD = new Action({ 384 id: ActionID.ADD, 385 textRes: $r('app.string.add_to_album'), 386 componentKey: COMPONENT_KEY_ADD 387 }); 388 public static ADD_INVALID = new Action({ 389 id: ActionID.ADD_INVALID, 390 textRes: $r('app.string.add_to_album'), 391 fillColor: $r('app.color.icon_disabled_color'), 392 componentKey: COMPONENT_KEY_ADD_INVALID 393 }); 394 public static COPY = new Action({ 395 id: ActionID.COPY, 396 textRes: $r('app.string.copy_to_album'), 397 componentKey: COMPONENT_KEY_COPY 398 }); 399 public static COPY_INVALID = new Action({ 400 id: ActionID.COPY_INVALID, 401 textRes: $r('app.string.copy_to_album'), 402 fillColor: $r('app.color.icon_disabled_color'), 403 componentKey: COMPONENT_KEY_COPY_INVALID 404 }); 405 public static REMOVE_FROM = new Action({ 406 id: ActionID.REMOVE_FROM, 407 textRes: $r('app.string.remove_from'), 408 componentKey: COMPONENT_KEY_REMOVE_FROM 409 }); 410 public static REMOVE_FROM_INVALID = new Action({ 411 id: ActionID.REMOVE_FROM_INVALID, 412 textRes: $r('app.string.remove_from'), 413 fillColor: $r('app.color.icon_disabled_color'), 414 componentKey: COMPONENT_KEY_REMOVE_FROM_INVALID 415 }); 416 public static NAVIGATION_ALBUMS = new Action({ 417 id: ActionID.NAVIGATION_ALBUMS, 418 iconRes: $r('app.media.ic_navigation_albums_line'), 419 textRes: $r('app.string.rotate_text'), 420 fillColor: $r('sys.color.ohos_id_color_primary'), 421 componentKey: COMPONENT_KEY_NAVIGATION_ALBUMS 422 }); 423 public static DOWNLOAD = new Action({ 424 id: ActionID.DOWNLOAD, 425 iconRes: $r('app.media.download'), 426 textRes: $r('app.string.save_to_local'), 427 componentKey: COMPONENT_KEY_DOWNLOAD 428 }); 429 public static DOWNLOAD_INVALID = new Action({ 430 id: ActionID.DOWNLOAD_INVALID, 431 iconRes: $r('app.media.download'), 432 textRes: $r('app.string.save_to_local'), 433 fillColor: $r('app.color.icon_disabled_color'), 434 componentKey: COMPONENT_KEY_DOWNLOAD_INVALID 435 }); 436 public static ICON_DEFAULT_COLOR: Resource = $r('app.color.icon_default_color'); 437 public static ICON_DEFAULT_COLOR_CONTRARY: Resource = $r('app.color.icon_default_color_contrary'); 438 readonly actionID: number; 439 readonly textRes: Resource; 440 readonly iconRes: Resource = $r('app.media.ic_gallery_public_more'); 441 readonly isAutoTint: boolean = true; 442 readonly fillColor: Resource = $r('app.color.icon_default_color'); 443 readonly actionType: Resource; // It is used to distinguish whether it is the same type of action 444 readonly componentKey: string; 445 446 constructor(options: ActionOptions) { 447 this.actionID = options.id; 448 this.textRes = options.textRes; 449 this.componentKey = options.componentKey; 450 if (options.iconRes != undefined) { 451 this.iconRes = options.iconRes; 452 } 453 if (options.isAutoTint != undefined) { 454 this.isAutoTint = options.isAutoTint; 455 } 456 if (options.fillColor != undefined) { 457 this.fillColor = options.fillColor; 458 } 459 if (options.actionType != undefined) { 460 this.actionType = options.actionType; 461 } 462 } 463 464 public equals(action: Action): boolean { 465 return (action) ? (action.actionID === this.actionID) : false; 466 } 467} 468