• 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 | undefined = undefined;
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 = null;
39  private isPad: boolean = false;
40  private deviceType: string = CommonConstants.DEFAULT_DEVICE_TYPE;
41  dialogController: CustomDialogController | null = 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') as string;
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    this.dialogController = null;
75  }
76
77  private updateStyle() {
78    mPageDesktopViewModel?.setDevice(this.deviceType);
79    this.isPad = mPageDesktopViewModel?.getDevice() as boolean;
80    Log.showDebug(TAG, `updateStyle isPad: ${this.isPad}`);
81  }
82
83  private updateDeskTopParams() {
84    this.mMargin = PageDesktopViewModel.getInstance().getPageDesktopStyleConfig()?.mMargin;
85    this.mTop = PageDesktopViewModel.getInstance().getPageDesktopStyleConfig()?.mDesktopMarginTop;
86    Log.showDebug(TAG, `updateDeskTopParams mMargin: ${this.mMargin}, this.mTop: ${this.mTop}`);
87    if (this.mPageDesktopDragHandler != null) {
88      this.mPageDesktopDragHandler.setDragEffectArea({
89        left: this.mMargin,
90        top: this.mTop,
91        right: this.workSpaceWidth - this.mMargin,
92        bottom: PageDesktopViewModel.getInstance().getPageDesktopStyleConfig()?.mGridHeight + this.mTop
93      });
94    }
95  }
96
97  private changeGridConfig(): void {
98    Log.showDebug(TAG, `changeGridConfig GridConfig: ${this.gridConfig}`);
99    this.updateDeskTopParams();
100  }
101
102  private buildLog(): boolean {
103    Log.showDebug(TAG, 'build start');
104    return true;
105  }
106
107  build() {
108    GridSwiper({
109      gridConfig: this.gridConfig,
110      mPageDesktopViewModel: mPageDesktopViewModel,
111      dialogController: this.deviceType == CommonConstants.PAD_DEVICE_TYPE ? null : this.dialogController
112    }).id(`${TAG}`)
113      .width(StyleConstants.PERCENTAGE_100)
114      .height(StyleConstants.PERCENTAGE_100)
115  }
116}
117
118@CustomDialog
119struct settingDialog {
120  @StorageLink('NavigationBarStatusValue') navigationBarStatusValue: boolean = false;
121  controller?: CustomDialogController;
122  cancel = () => {};
123  confirm = () => {};
124  onAccept = () => {};
125
126  aboutToAppear(): void {}
127
128  aboutToDisappear(): void {
129  }
130
131  build() {
132    Stack() {
133      Column() {
134
135      }
136      .blur(40)
137      .width('100%')
138      .height(120)
139      .border({
140        radius: StyleConstants.DEFAULT_24
141      })
142
143      Column() {
144        Row() {
145          Text($r('app.string.into_settings'))
146            .fontSize(StyleConstants.DEFAULT_BADGE_FONT_SIZE)
147            .fontColor(StyleConstants.TEXT_COLOR_PRIMARY)
148        }.margin({ top: StyleConstants.DEFAULT_24, bottom: StyleConstants.DEFAULT_16 })
149
150        Flex({ alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceEvenly }) {
151          Button() {
152            Text($r('app.string.cancel'))
153              .fontSize(StyleConstants.DEFAULT_BADGE_FONT_SIZE)
154              .fontColor(StyleConstants.BUTTON_FONT_COLOR)
155          }
156          .backgroundColor(StyleConstants.DEFAULT_BG_COLOR)
157          .height(StyleConstants.DEFAULT_BUTTON_HEIGHT)
158          .width(StyleConstants.DEFAULT_BUTTON_WIDTH)
159          .onClick(() => {
160            this.cancel()
161            this.controller?.close();
162          })
163
164          Divider()
165            .width(5)
166            .vertical(true)
167            .color(StyleConstants.DEFAULT_DIVIDER_COLOR)
168            .height(StyleConstants.DEFAULT_DIVIDER_HEIGHT)
169
170          Button() {
171            Text(mPageDesktopViewModel?.isBlankPage() ? $r('app.string.delete_blank_page') : $r('app.string.add_blank_page'))
172              .fontSize(StyleConstants.DEFAULT_BADGE_FONT_SIZE)
173              .fontColor(StyleConstants.BUTTON_FONT_COLOR)
174          }
175          .backgroundColor(StyleConstants.DEFAULT_BG_COLOR)
176          .height(StyleConstants.DEFAULT_BUTTON_HEIGHT)
177          .width(StyleConstants.DEFAULT_BUTTON_WIDTH)
178          .onClick(() => {
179            this.controller?.close();
180            this.onAccept()
181          })
182
183          Divider()
184            .width(5)
185            .vertical(true)
186            .color(StyleConstants.DEFAULT_DIVIDER_COLOR)
187            .height(StyleConstants.DEFAULT_DIVIDER_HEIGHT)
188
189          Button() {
190            Text($r('app.string.launcher_edit'))
191              .fontSize(StyleConstants.DEFAULT_BADGE_FONT_SIZE)
192              .fontColor(StyleConstants.BUTTON_FONT_COLOR)
193          }
194          .backgroundColor(StyleConstants.DEFAULT_BG_COLOR)
195          .height(StyleConstants.DEFAULT_BUTTON_HEIGHT)
196          .width(StyleConstants.DEFAULT_BUTTON_WIDTH)
197          .onClick(() => {
198            this.confirm()
199            this.controller?.close();
200
201          })
202        }
203      }
204      .backgroundColor(Color.White)
205      .opacity(0.85)
206      .width('100%')
207      .padding({
208        bottom: StyleConstants.DEFAULT_24
209      })
210      .border({
211        radius: StyleConstants.DEFAULT_24
212      })
213    }
214    .margin({ right: StyleConstants.DEFAULT_12, left: StyleConstants.DEFAULT_12,
215      bottom: this.navigationBarStatusValue ? StyleConstants.DEFAULT_12 : StyleConstants.DEFAULT_40 })
216  }
217}