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 */ 15 16import { Action } from '../../../common/view/browserOperation/Action'; 17import { Broadcast } from '@ohos/base/src/main/ets/utils/Broadcast'; 18import { BroadcastConstants } from '@ohos/base/src/main/ets/constants/BroadcastConstants'; 19import { Constants } from '../../../common/model/common/Constants'; 20import { Log } from '@ohos/base/src/main/ets/utils/Log'; 21import { SelectUtil } from '@ohos/base/src/main/ets/utils/SelectUtil'; 22import { MediaConstants } from '@ohos/base/src/main/ets/constants/MediaConstants'; 23import { GroupItemDataSource } from '@ohos/base/src/main/ets/vm/GroupItemDataSource'; 24import { MediaDataItem } from '@ohos/base/src/main/ets/data/MediaDataItem'; 25import MediaLib from '@ohos.multimedia.mediaLibrary'; 26import { DateUtil } from '@ohos/base/src/main/ets/utils/DateUtil'; 27 28const TAG = "ThirdSelectedPanel" 29@Component 30export struct ThirdSelectedPanel { 31 static readonly THUMBNAIL_WIDTH = 256; 32 33 selectedScroller: Scroller = new Scroller(); 34 onMenuClicked: Function; 35 @Consume maxSelectCount: number; 36 @Consume @Watch('onSelectedCountChanged') selectedCount: number; 37 @State selectedMediaDataArray: Array<MediaDataItem> = []; 38 @Consume isOriginalChecked: boolean; 39 @Consume broadCast: Broadcast; 40 private groupDataSource: GroupItemDataSource; 41 42 onSelectedCountChanged() { 43 this.selectedMediaDataArray = this.groupDataSource.getSelectedItems(); 44 this.selectedScroller.scrollEdge(Edge.End); 45 } 46 47 getThumbnailSafe(sourceUri: string, size?) { 48 try{ 49 if (size) { 50 return `${sourceUri}/thumbnail/${size.width}/${size.height}`; 51 } else { 52 return `${sourceUri}/thumbnail/${MediaConstants.DEFAULT_SIZE}/${MediaConstants.DEFAULT_SIZE}`; 53 } 54 } catch (err) { 55 Log.warn(TAG, `get Thumbnail Failed! msg:${err}`); 56 return null; 57 } 58 } 59 60 build() { 61 Column() { 62 Row() { 63 Text($r("app.string.selected_photos_count", this.selectedCount, this.maxSelectCount)) 64 .fontSize($r('sys.float.ohos_id_text_size_sub_title2')) 65 .fontFamily($r('app.string.id_text_font_family_regular')) 66 .fontColor($r('sys.color.ohos_id_color_text_primary')) 67 .fontWeight(FontWeight.Medium) 68 Row() { 69 Radio({ value: "", group: "" }) 70 .checked(this.isOriginalChecked) 71 .onClick(() => { 72 this.isOriginalChecked = !this.isOriginalChecked; 73 }) 74 75 Text($r("app.string.filter_original_text")) 76 .fontSize($r('sys.float.ohos_id_text_size_body1')) 77 .fontFamily($r('app.string.id_text_font_family_regular')) 78 .fontColor($r('sys.color.ohos_id_color_text_hint')) 79 .fontWeight(FontWeight.Regular) 80 .margin({ left: $r('app.float.third_selected_toggle_icon_margin_right') }) 81 } 82 .alignItems(VerticalAlign.Center) 83 .markAnchor({ 84 x: 0, 85 y: $r('app.float.third_selected_panel_original_markAnchor') 86 }) 87 .opacity(this.selectedCount > 0 ? 1 : $r('app.float.disable_button_opacity')) 88 89 Text($r("app.string.complete")) 90 .fontSize($r('sys.float.ohos_id_text_size_body2')) 91 .fontFamily($r('app.string.id_text_font_family_regular')) 92 .fontColor($r('sys.color.ohos_id_color_text_hyperlink')) 93 .fontWeight(FontWeight.Medium) 94 .enabled(this.selectedCount > 0 ? true : false) 95 .opacity(this.selectedCount > 0 ? 1 : $r('app.float.disable_button_opacity')) 96 .onClick(() => { 97 this.onMenuClicked(Action.OK); 98 }) 99 } 100 .width("100%") 101 .height($r('app.float.third_selected_panel_title_height')) 102 .justifyContent(FlexAlign.SpaceBetween) 103 .alignItems(VerticalAlign.Bottom) 104 .padding({ 105 left: $r('sys.float.ohos_id_max_padding_start'), 106 right: $r('sys.float.ohos_id_max_padding_end'), 107 bottom: $r('app.float.third_selected_panel_image_padding_top') 108 }) 109 110 if (this.selectedCount > 0) { 111 Scroll(this.selectedScroller) { 112 Row({ space: 8 }) { 113 ForEach(this.selectedMediaDataArray, (selectedItem: MediaDataItem) => { 114 Stack({ alignContent: Alignment.Start }) { 115 Image(this.getThumbnailSafe(selectedItem.uri)) 116 .height("100%") 117 .aspectRatio(1) 118 .objectFit(ImageFit.Cover) 119 .autoResize(false) 120 .onError(() => { 121 Log.error(TAG, 'item Image error'); 122 }) 123 .onComplete(() => { 124 Log.debug(TAG, `Draw the image! ${this.getThumbnailSafe(selectedItem.uri)}`); 125 }) 126 127 if (selectedItem.mediaType == MediaLib.MediaType.VIDEO) { 128 Column() 129 .position({ x: '0%', y: '50%' }) 130 .height('50%') 131 .width('100%') 132 .linearGradient({ 133 angle: 0, 134 colors: [[$r('app.color.album_cover_gradient_start_color'), 0], [$r('app.color.transparent'), 1.0]] 135 }) 136 Text(DateUtil.getFormattedDuration(selectedItem.duration)) 137 .fontSize($r('sys.float.ohos_id_text_size_caption')) 138 .fontFamily($r('app.string.id_text_font_family_regular')) 139 .fontColor($r('app.color.text_color_above_picture')) 140 .lineHeight($r('app.float.grid_item_text_line_height')) 141 .position({ x: '0%', y: '100%' }) 142 .markAnchor({ 143 x: $r('app.float.grid_item_duration_markAnchor_x'), 144 y: $r('app.float.grid_item_duration_markAnchor_y') 145 }) 146 .margin({ right: $r('app.float.grid_item_duration_margin_right') }) 147 } 148 149 if (selectedItem.favouriteStatus == 1) { 150 Image($r('app.media.ic_favorite_overlay')) 151 .height($r('app.float.icon_size')) 152 .width($r('app.float.icon_size')) 153 .objectFit(ImageFit.Contain) 154 .position({ x: '100%', y: '100%' }) 155 .markAnchor({ 156 x: $r('app.float.grid_item_favor_markAnchor_x'), 157 y: $r('app.float.grid_item_favor_markAnchor_y') 158 }) 159 } 160 161 Image($r('app.media.ic_gallery_public_cancel_bg')) 162 .height($r('app.float.icon_size')) 163 .width($r('app.float.icon_size')) 164 .objectFit(ImageFit.Contain) 165 .position({ x: '100%', y: '0%' }) 166 .markAnchor({ 167 x: $r('app.float.grid_item_favor_markAnchor_x'), 168 y: $r('app.float.grid_item_favor_markAnchor_y') 169 }) 170 .onClick(() => { 171 selectedItem.setSelect(false); 172 this.broadCast.emit(BroadcastConstants.SELECT, [selectedItem.index]); 173 }) 174 } 175 .height("100%") 176 .aspectRatio(1) 177 }, item => JSON.stringify(item)) 178 } 179 .margin({ 180 left: $r('sys.float.ohos_id_max_padding_start'), 181 right: $r('sys.float.ohos_id_max_padding_end'), 182 top: $r('app.float.third_selected_panel_image_padding_top'), 183 bottom: $r('sys.float.ohos_id_default_padding_bottom_fixed') 184 }) 185 } 186 .width("100%") 187 .height($r('app.float.third_selected_panel_image_height')) 188 .scrollable(ScrollDirection.Horizontal) 189 .scrollBar(BarState.Off) 190 } else { 191 Column() { 192 Text($r("app.string.select_items_to_add")) 193 .fontSize($r('sys.float.ohos_id_text_size_body2')) 194 .fontFamily($r('app.string.id_text_font_family_regular')) 195 .fontColor($r('sys.color.ohos_id_color_secondary')) 196 .fontWeight(FontWeight.Regular) 197 } 198 .width("100%") 199 .height($r('app.float.third_selected_panel_image_height')) 200 .justifyContent(FlexAlign.Center) 201 .alignItems(HorizontalAlign.Center) 202 .padding({ 203 left: $r('sys.float.ohos_id_max_padding_start'), 204 right: $r('sys.float.ohos_id_max_padding_end') 205 }) 206 } 207 } 208 .backgroundColor($r("sys.color.ohos_id_color_background")) 209 } 210}