• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * Copyright (c) 2021-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 { Log, RecentMissionInfo } from '@ohos/common';
16import { localEventManager } from '@ohos/common';
17import { EventConstants } from '@ohos/common';
18import { CommonConstants } from '@ohos/common';
19import RecentMissionCard from '../common/uicomponents/RecentMissionCard';
20import { RecentMissionsViewModel } from '../viewmodel/RecentMissionsViewModel';
21import { RecentsStyleConstants } from '../common/constants/RecentsStyleConstants';
22
23const TAG = 'RecentMissionsDoubleLayout';
24
25/**
26 * Double-line display of recent task list (pad adaptation).
27 */
28@Component
29export struct RecentMissionsDoubleLayout {
30  @Link recentMissionsDoubleList: RecentMissionInfo[];
31  @Link isClickSubComponent: boolean;
32  private mRecentMissionsViewModel?: RecentMissionsViewModel;
33
34  aboutToAppear(): void {
35    Log.showInfo(TAG, 'aboutToAppear start');
36    this.mRecentMissionsViewModel = RecentMissionsViewModel.getInstance();
37  }
38
39  aboutToDisappear(): void {
40    Log.showInfo(TAG, 'aboutToDisappear start');
41  }
42
43  itemChance(item: RecentMissionInfo): RecentMissionInfo {
44    item.snapShotTime = '';
45    return item;
46  }
47
48  build() {
49    Column() {
50      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.Center }) {
51        Grid() {
52          ForEach(this.recentMissionsDoubleList, (item: RecentMissionInfo) => {
53              GridItem() {
54                RecentMissionCard({
55                  missionId: item.missionId,
56                  appIconId: item.appIconId,
57                  appLabelId: item.appLabelId,
58                  appName: item.appName,
59                  bundleName: item.bundleName,
60                  moduleName: item.moduleName,
61                  abilityName: item.abilityName,
62                  lockedState: item.lockedState,
63                  isClickSubComponent: $isClickSubComponent,
64                  snapShotTime: item.snapShotTime
65                })
66              }
67              .align(Alignment.Center)
68          },(item: RecentMissionInfo) => JSON.stringify(this.itemChance(item)))
69        }
70        .width(RecentsStyleConstants.DEFAULT_LAYOUT_PERCENTAGE)
71        .rowsTemplate('1fr 1fr')
72        .direction(Direction.Rtl)
73        .columnsGap(RecentsStyleConstants.DOUBLE_LIST_LAYOUT_COLUMNSGAP)
74        .rowsGap(RecentsStyleConstants.DOUBLE_LIST_LAYOUT_ROWSGAP)
75      }
76      .margin({
77        top: RecentsStyleConstants.DOUBLE_LIST_TOP_MARGIN,
78      })
79      .width(RecentsStyleConstants.DEFAULT_LAYOUT_PERCENTAGE)
80      .height(RecentsStyleConstants.DOUBLE_LIST_GRID_HEIGHT_PERCENTAGE)
81
82      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) {
83        Stack() {
84          Column() {
85          }
86          .width(RecentsStyleConstants.RECENT_DELETE_IMAGE_COLUMN_SIZE)
87          .height(RecentsStyleConstants.RECENT_DELETE_IMAGE_COLUMN_SIZE)
88          .opacity(RecentsStyleConstants.DEFAULT_DELETE_IMAGE_OPACITY)
89          .backgroundColor(RecentsStyleConstants.DEFAULT_FONT_COLOR)
90          .borderRadius(RecentsStyleConstants.RECENT_DELETE_IMAGE_RADIUS)
91          .padding(8)
92
93          Image(RecentsStyleConstants.DEFAULT_DELETE_IMAGE_FULL)
94            .width(RecentsStyleConstants.RECENT_DELETE_IMAGE_SIZE)
95            .height(RecentsStyleConstants.RECENT_DELETE_IMAGE_SIZE)
96        }
97        .onClick(() => {
98          this.isClickSubComponent = true;
99          Log.showDebug(TAG, 'onClick click delete button');
100          localEventManager.sendLocalEventSticky(EventConstants.EVENT_ANIMATION_CLOSE_APPLICATION, null);
101          this.mRecentMissionsViewModel?.deleteRecentMission(true, CommonConstants.INVALID_VALUE);
102          this.mRecentMissionsViewModel?.backView();
103          this.mRecentMissionsViewModel?.getRecentMissionsList();
104        })
105      }
106      .width(RecentsStyleConstants.DEFAULT_LAYOUT_PERCENTAGE)
107    }
108    .width(RecentsStyleConstants.DEFAULT_LAYOUT_PERCENTAGE)
109    .height(RecentsStyleConstants.DEFAULT_LAYOUT_PERCENTAGE)
110  }
111}