16e80583aSopenharmony_ci/**
26e80583aSopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
36e80583aSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
46e80583aSopenharmony_ci * you may not use this file except in compliance with the License.
56e80583aSopenharmony_ci * You may obtain a copy of the License at
66e80583aSopenharmony_ci *
76e80583aSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
86e80583aSopenharmony_ci *
96e80583aSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
106e80583aSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
116e80583aSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
126e80583aSopenharmony_ci * See the License for the specific language governing permissions and
136e80583aSopenharmony_ci * limitations under the License.
146e80583aSopenharmony_ci */
156e80583aSopenharmony_ci
166e80583aSopenharmony_ciimport { StyleConstants } from '../constants/StyleConstants';
176e80583aSopenharmony_ciimport { amsMissionManager } from '../manager/AmsMissionManager'
186e80583aSopenharmony_ci
196e80583aSopenharmony_ciinterface DataList {
206e80583aSopenharmony_ci  name: string;
216e80583aSopenharmony_ci  image: ResourceStr | PixelMap;
226e80583aSopenharmony_ci  missionId: number;
236e80583aSopenharmony_ci  boxSize: number;
246e80583aSopenharmony_ci  bundleName: string;
256e80583aSopenharmony_ci  left?: number;
266e80583aSopenharmony_ci  right?: number;
276e80583aSopenharmony_ci}
286e80583aSopenharmony_ci
296e80583aSopenharmony_ci@Component
306e80583aSopenharmony_ciexport struct ScrollerComponent {
316e80583aSopenharmony_ci  @StorageLink('snapshotList') dataList: DataList[] = [];
326e80583aSopenharmony_ci  @StorageLink('snapShotWidth') listWidth: number = 0;
336e80583aSopenharmony_ci  scroller: Scroller = new Scroller();
346e80583aSopenharmony_ci  private screenWidth = 800;
356e80583aSopenharmony_ci  popupHide: Function = () => {};
366e80583aSopenharmony_ci  updateData: Function = (isUpdate: boolean, bundleName: string, callback: () => void) => {};
376e80583aSopenharmony_ci
386e80583aSopenharmony_ci  aboutToDisappear(): void {
396e80583aSopenharmony_ci  }
406e80583aSopenharmony_ci
416e80583aSopenharmony_ci  build() {
426e80583aSopenharmony_ci    Row() {
436e80583aSopenharmony_ci      Column() {
446e80583aSopenharmony_ci        Button({ type: ButtonType.Circle, stateEffect: true }) {
456e80583aSopenharmony_ci          Image($r('app.media.ic_public_arrow_left'))
466e80583aSopenharmony_ci            .width(20)
476e80583aSopenharmony_ci            .height(20)
486e80583aSopenharmony_ci            .objectFit(ImageFit.Contain)
496e80583aSopenharmony_ci        }
506e80583aSopenharmony_ci        .width(24)
516e80583aSopenharmony_ci        .height(24)
526e80583aSopenharmony_ci        .backgroundColor('#00000005')
536e80583aSopenharmony_ci        .onClick((event: ClickEvent) => {
546e80583aSopenharmony_ci          this.scroller.scrollPage({ next: false })
556e80583aSopenharmony_ci        })
566e80583aSopenharmony_ci      }
576e80583aSopenharmony_ci      .alignItems(HorizontalAlign.Center)
586e80583aSopenharmony_ci      .justifyContent(FlexAlign.Center)
596e80583aSopenharmony_ci      .width(StyleConstants.DEFAULT_56)
606e80583aSopenharmony_ci      .height(StyleConstants.DEFAULT_SMART_DOCK_MISSION_HEIGHT)
616e80583aSopenharmony_ci      .visibility(this.listWidth > this.screenWidth ? Visibility.Visible : Visibility.None)
626e80583aSopenharmony_ci
636e80583aSopenharmony_ci      Scroll(this.scroller) {
646e80583aSopenharmony_ci        Row({ space: StyleConstants.DEFAULT_14 }) {
656e80583aSopenharmony_ci          ForEach(this.dataList, (item: DataList) => {
666e80583aSopenharmony_ci            Column() {
676e80583aSopenharmony_ci              Row() {
686e80583aSopenharmony_ci                Text(item.name.toString())
696e80583aSopenharmony_ci                  .height(StyleConstants.DEFAULT_24)
706e80583aSopenharmony_ci                  .textOverflow({ overflow: TextOverflow.Ellipsis })
716e80583aSopenharmony_ci                  .fontSize(StyleConstants.DEFAULT_14)
726e80583aSopenharmony_ci                  .textAlign(TextAlign.Start)
736e80583aSopenharmony_ci                  .maxLines(StyleConstants.DEFAULT_1)
746e80583aSopenharmony_ci                  .width(item.boxSize - StyleConstants.DEFAULT_30)
756e80583aSopenharmony_ci                  .hoverEffect(HoverEffect.None)
766e80583aSopenharmony_ci                  .fontWeight(FontWeight.Medium)
776e80583aSopenharmony_ci
786e80583aSopenharmony_ci                Image($r('app.media.ic_public_cancel'))
796e80583aSopenharmony_ci                  .width(StyleConstants.DEFAULT_16)
806e80583aSopenharmony_ci                  .height(StyleConstants.DEFAULT_16)
816e80583aSopenharmony_ci                  .objectFit(ImageFit.Contain)
826e80583aSopenharmony_ci                  .margin({ right: StyleConstants.DEFAULT_4 })
836e80583aSopenharmony_ci                  .onClick((event: ClickEvent) => {
846e80583aSopenharmony_ci                    if (this.dataList.length <= 1) {
856e80583aSopenharmony_ci                      this.updateData(false, '', () => amsMissionManager.clearMission(item.missionId));
866e80583aSopenharmony_ci                      return
876e80583aSopenharmony_ci                    }
886e80583aSopenharmony_ci                    this.updateData(true, item.bundleName, () => amsMissionManager.clearMission(item.missionId));
896e80583aSopenharmony_ci                  })
906e80583aSopenharmony_ci              }
916e80583aSopenharmony_ci              .alignItems(VerticalAlign.Center)
926e80583aSopenharmony_ci              .justifyContent(FlexAlign.SpaceBetween)
936e80583aSopenharmony_ci              .width(item.boxSize)
946e80583aSopenharmony_ci
956e80583aSopenharmony_ci              Image(item.image)
966e80583aSopenharmony_ci                .height(StyleConstants.DEFAULT_SMART_DOCK_MISSION_IMAGE_HEIGHT)
976e80583aSopenharmony_ci                .objectFit(ImageFit.Contain)
986e80583aSopenharmony_ci                .borderRadius(StyleConstants.DEFAULT_8)
996e80583aSopenharmony_ci                .hoverEffect(HoverEffect.None)
1006e80583aSopenharmony_ci            }
1016e80583aSopenharmony_ci            .onClick((event: ClickEvent) => {
1026e80583aSopenharmony_ci              this.popupHide();
1036e80583aSopenharmony_ci              amsMissionManager.moveMissionToFront(item.missionId);
1046e80583aSopenharmony_ci            })
1056e80583aSopenharmony_ci            .width(item.boxSize)
1066e80583aSopenharmony_ci            .borderRadius(StyleConstants.DEFAULT_5)
1076e80583aSopenharmony_ci            .justifyContent(FlexAlign.Center)
1086e80583aSopenharmony_ci          }, (item: DataList) => JSON.stringify(item))
1096e80583aSopenharmony_ci        }
1106e80583aSopenharmony_ci        .alignItems(VerticalAlign.Center)
1116e80583aSopenharmony_ci        .margin({
1126e80583aSopenharmony_ci          left: this.listWidth > this.screenWidth ? StyleConstants.DEFAULT_0 : StyleConstants.DEFAULT_14,
1136e80583aSopenharmony_ci          right: this.listWidth > this.screenWidth ? StyleConstants.DEFAULT_0 : StyleConstants.DEFAULT_14
1146e80583aSopenharmony_ci        })
1156e80583aSopenharmony_ci      }
1166e80583aSopenharmony_ci      .constraintSize({
1176e80583aSopenharmony_ci        maxWidth: this.screenWidth,
1186e80583aSopenharmony_ci        maxHeight: StyleConstants.DEFAULT_SMART_DOCK_MISSION_HEIGHT
1196e80583aSopenharmony_ci      })
1206e80583aSopenharmony_ci      .scrollable(ScrollDirection.Horizontal)
1216e80583aSopenharmony_ci      .scrollBar(BarState.Off)
1226e80583aSopenharmony_ci      .height(StyleConstants.DEFAULT_SMART_DOCK_MISSION_HEIGHT)
1236e80583aSopenharmony_ci
1246e80583aSopenharmony_ci      Column() {
1256e80583aSopenharmony_ci        Button({ type: ButtonType.Circle, stateEffect: true }) {
1266e80583aSopenharmony_ci          Image($r('app.media.ic_public_arrow_right'))
1276e80583aSopenharmony_ci            .width(20)
1286e80583aSopenharmony_ci            .height(20)
1296e80583aSopenharmony_ci            .objectFit(ImageFit.Contain)
1306e80583aSopenharmony_ci        }
1316e80583aSopenharmony_ci        .width(24)
1326e80583aSopenharmony_ci        .height(24)
1336e80583aSopenharmony_ci        .backgroundColor('#00000005')
1346e80583aSopenharmony_ci        .onClick((event: ClickEvent) => {
1356e80583aSopenharmony_ci          this.scroller.scrollPage({ next: true })
1366e80583aSopenharmony_ci        })
1376e80583aSopenharmony_ci      }
1386e80583aSopenharmony_ci      .alignItems(HorizontalAlign.Center)
1396e80583aSopenharmony_ci      .justifyContent(FlexAlign.Center)
1406e80583aSopenharmony_ci      .width(StyleConstants.DEFAULT_56)
1416e80583aSopenharmony_ci      .height(StyleConstants.DEFAULT_SMART_DOCK_MISSION_HEIGHT)
1426e80583aSopenharmony_ci      .visibility(this.listWidth > this.screenWidth ? Visibility.Visible : Visibility.None)
1436e80583aSopenharmony_ci    }
1446e80583aSopenharmony_ci    .alignItems(VerticalAlign.Center)
1456e80583aSopenharmony_ci    .justifyContent(FlexAlign.SpaceBetween)
1466e80583aSopenharmony_ci    .constraintSize({
1476e80583aSopenharmony_ci      maxWidth: this.screenWidth + 2 * StyleConstants.DEFAULT_56,
1486e80583aSopenharmony_ci      maxHeight: StyleConstants.DEFAULT_SMART_DOCK_MISSION_HEIGHT
1496e80583aSopenharmony_ci    })
1506e80583aSopenharmony_ci    .height(StyleConstants.DEFAULT_SMART_DOCK_MISSION_HEIGHT)
1516e80583aSopenharmony_ci    .visibility(this.dataList.length < 1 ? Visibility.None : Visibility.Visible)
1526e80583aSopenharmony_ci  }
1536e80583aSopenharmony_ci}