• 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 */
15
16import {
17  Log,
18  Trace,
19  StyleConstants,
20  CommonConstants,
21  CloseAppManager } from '@ohos/common';
22import GridSwiper from '../common/components/GridSwiper';
23import { PageDesktopDragHandler } from '../common/PageDesktopDragHandler';
24import { PageDesktopViewModel } from '../viewmodel/PageDesktopViewModel';
25import { PageDesktopCloseAppHandler } from '../common/PageDesktopCloseAppHandler';
26
27let mPageDesktopViewModel: PageDesktopViewModel = null;
28const TAG = "PageDesktopLayout";
29
30@Component
31export struct PageDesktopLayout {
32  @StorageLink('workSpaceWidth') @Watch('updateDeskTopParams') workSpaceWidth: number = 0;
33  @StorageLink('workSpaceHeight') @Watch('updateDeskTopParams') workSpaceHeight: number = 0;
34  @State @Watch('updateDeskTopParams') mMargin: number = 0;
35  @State mTop: number = 0;
36  @State @Watch('changeGridConfig') gridConfig: string = '';
37  @StorageLink('menuId') menuId: number = 0;
38  private mPageDesktopDragHandler: PageDesktopDragHandler = null;
39  private isPad: boolean = false;
40  private deviceType: string = CommonConstants.DEFAULT_DEVICE_TYPE;
41  dialogController: CustomDialogController = new CustomDialogController({
42    builder: settingDialog({ cancel: this.onCancel, confirm: this.confirm, onAccept: this.onAccept }),
43    cancel: this.onCancel,
44    autoCancel: true,
45    alignment: DialogAlignment.Bottom,
46    customStyle: true
47  })
48
49  onCancel() {
50  }
51
52  onAccept() {
53    mPageDesktopViewModel.addOrDeleteBlankPage();
54  }
55
56  confirm() {
57    Trace.start(Trace.CORE_METHOD_START_SETTINGS);
58    mPageDesktopViewModel.intoSetting();
59  }
60
61  aboutToAppear(): void  {
62    this.deviceType = AppStorage.get('deviceType');
63    this.mPageDesktopDragHandler = PageDesktopDragHandler.getInstance();
64    mPageDesktopViewModel = PageDesktopViewModel.getInstance();
65    this.gridConfig = mPageDesktopViewModel.getGridConfig().layout;
66    this.updateStyle();
67    if (this.deviceType != CommonConstants.PAD_DEVICE_TYPE) {
68      mPageDesktopViewModel.registerAppListChangeCallback();
69    }
70    CloseAppManager.getInstance().registerCloseAppHandler(new PageDesktopCloseAppHandler());
71  }
72
73  aboutToDisappear(): void {
74    delete this.dialogController;
75    this.dialogController = null;
76  }
77
78  private updateStyle() {
79    mPageDesktopViewModel.setDevice(this.deviceType);
80    this.isPad = mPageDesktopViewModel.getDevice();
81    Log.showDebug(TAG, `updateStyle isPad: ${this.isPad}`);
82  }
83
84  private updateDeskTopParams() {
85    this.mMargin = PageDesktopViewModel.getInstance().getPageDesktopStyleConfig().mMargin;
86    this.mTop = PageDesktopViewModel.getInstance().getPageDesktopStyleConfig().mDesktopMarginTop;
87    Log.showDebug(TAG, `updateDeskTopParams mMargin: ${this.mMargin}, this.mTop: ${this.mTop}`);
88    if (this.mPageDesktopDragHandler != null) {
89      this.mPageDesktopDragHandler.setDragEffectArea({
90        left: this.mMargin,
91        top: this.mTop,
92        right: this.workSpaceWidth - this.mMargin,
93        bottom: PageDesktopViewModel.getInstance().getPageDesktopStyleConfig().mGridHeight + this.mTop
94      });
95    }
96  }
97
98  private changeGridConfig(): void {
99    Log.showDebug(TAG, `changeGridConfig GridConfig: ${this.gridConfig}`);
100    this.updateDeskTopParams();
101  }
102
103  private buildLog(): boolean {
104    Log.showDebug(TAG, 'build start');
105    return true;
106  }
107
108  build() {
109    GridSwiper({
110      gridConfig: this.gridConfig,
111      mPageDesktopViewModel: mPageDesktopViewModel,
112      dialogController: this.deviceType == CommonConstants.PAD_DEVICE_TYPE ? null : this.dialogController
113    }).id(`${TAG}`)
114      .width(StyleConstants.PERCENTAGE_100)
115      .height(StyleConstants.PERCENTAGE_100)
116  }
117}
118
119@CustomDialog
120struct settingDialog {
121  @StorageLink('NavigationBarStatusValue') navigationBarStatusValue: boolean = false;
122  controller: CustomDialogController
123  cancel: () => void
124  confirm: () => void
125  onAccept: () => void
126
127  aboutToAppear(): void {}
128
129  aboutToDisappear(): void {
130    this.cancel = null;
131    this.confirm = null;
132    this.controller = null;
133  }
134
135  build() {
136    Stack() {
137      Column() {
138
139      }
140      .blur(40)
141      .width('100%')
142      .height(120)
143      .border({
144        radius: StyleConstants.DEFAULT_24
145      })
146
147      Column() {
148        Row() {
149          Text($r('app.string.into_settings'))
150            .fontSize(StyleConstants.DEFAULT_BADGE_FONT_SIZE)
151            .fontColor(StyleConstants.TEXT_COLOR_PRIMARY)
152        }.margin({ top: StyleConstants.DEFAULT_24, bottom: StyleConstants.DEFAULT_16 })
153
154        Flex({ alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceEvenly }) {
155          Button() {
156            Text($r('app.string.cancel'))
157              .fontSize(StyleConstants.DEFAULT_BADGE_FONT_SIZE)
158              .fontColor(StyleConstants.BUTTON_FONT_COLOR)
159          }
160          .backgroundColor(StyleConstants.DEFAULT_BG_COLOR)
161          .height(StyleConstants.DEFAULT_BUTTON_HEIGHT)
162          .width(StyleConstants.DEFAULT_BUTTON_WIDTH)
163          .onClick(() => {
164            this.cancel()
165            this.controller.close();
166          })
167
168          Divider()
169            .width(5)
170            .vertical(true)
171            .color(StyleConstants.DEFAULT_DIVIDER_COLOR)
172            .height(StyleConstants.DEFAULT_DIVIDER_HEIGHT)
173
174          Button() {
175            Text(mPageDesktopViewModel.isBlankPage() ? $r('app.string.delete_blank_page') : $r('app.string.add_blank_page'))
176              .fontSize(StyleConstants.DEFAULT_BADGE_FONT_SIZE)
177              .fontColor(StyleConstants.BUTTON_FONT_COLOR)
178          }
179          .backgroundColor(StyleConstants.DEFAULT_BG_COLOR)
180          .height(StyleConstants.DEFAULT_BUTTON_HEIGHT)
181          .width(StyleConstants.DEFAULT_BUTTON_WIDTH)
182          .onClick(() => {
183            this.controller.close();
184            this.onAccept()
185          })
186
187          Divider()
188            .width(5)
189            .vertical(true)
190            .color(StyleConstants.DEFAULT_DIVIDER_COLOR)
191            .height(StyleConstants.DEFAULT_DIVIDER_HEIGHT)
192
193          Button() {
194            Text($r('app.string.launcher_edit'))
195              .fontSize(StyleConstants.DEFAULT_BADGE_FONT_SIZE)
196              .fontColor(StyleConstants.BUTTON_FONT_COLOR)
197          }
198          .backgroundColor(StyleConstants.DEFAULT_BG_COLOR)
199          .height(StyleConstants.DEFAULT_BUTTON_HEIGHT)
200          .width(StyleConstants.DEFAULT_BUTTON_WIDTH)
201          .onClick(() => {
202            this.confirm()
203            this.controller.close();
204
205          })
206        }
207      }
208      .backgroundColor(Color.White)
209      .opacity(0.85)
210      .width('100%')
211      .padding({
212        bottom: StyleConstants.DEFAULT_24
213      })
214      .border({
215        radius: StyleConstants.DEFAULT_24
216      })
217    }
218    .margin({ right: StyleConstants.DEFAULT_12, left: StyleConstants.DEFAULT_12,
219      bottom: this.navigationBarStatusValue ? StyleConstants.DEFAULT_12 : StyleConstants.DEFAULT_40 })
220  }
221}