• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 CommonEvent from '@ohos.commonEvent'
17import LauncherGridLayout from '../components/LauncherGridLayout'
18import { DesktopLayoutModel } from '../model/DesktopLayoutModel'
19import { EventConstants, GridLayoutItemInfo, Logger } from '@ohos/base'
20
21const TAG: string = 'WorkSpace'
22
23@Component
24export struct WorkSpace {
25  @StorageLink('isRefresh') @Watch('refreshWorkSpace') isRefresh: boolean = false;
26  @State appPages: Array<Array<GridLayoutItemInfo>> = [[]]
27  private swiperController: SwiperController = new SwiperController()
28  private desktopLayoutModel: DesktopLayoutModel = DesktopLayoutModel.getInstance(getContext(this))
29
30  build() {
31    Column() {
32      Swiper(this.swiperController) {
33        ForEach(this.appPages, item => {
34          LauncherGridLayout({ gridInfos: item })
35        }, item => item.length.toString())
36      }
37      .indicatorStyle({
38        selectedColor: Color.White
39      })
40      .width('100%')
41      .height('95%')
42      .margin({ top: '5%' })
43      .gesture(
44      PanGesture({ fingers: 1, direction: PanDirection.Up, distance: 20 })
45        .onActionStart((event: GestureEvent) => {
46          console.info('Pan start')
47        })
48        .onActionUpdate((event: GestureEvent) => {
49        })
50        .onActionEnd(() => {
51          console.info('Pan end')
52          CommonEvent.publish(EventConstants.EVENT_ENTER_RECENTS, () => {
53            Logger.info(TAG, 'publish EVENT_ENTER_RECENTS')
54          })
55        })
56      )
57    }
58    .width('100%')
59    .height('100%')
60  }
61
62  aboutToAppear() {
63    Logger.info(TAG, 'aboutToAppear')
64    this.getData()
65    setInterval(()=>{
66      this.getData()
67    },3000)
68  }
69
70  refreshWorkSpace() {
71    if (this.isRefresh) {
72      this.appPages = this.desktopLayoutModel.getLayoutInfoCache()
73      AppStorage.SetOrCreate('isRefresh', false)
74    }
75  }
76
77  async getData() {
78    this.appPages = await this.desktopLayoutModel.getLayoutInfo()
79    Logger.info(TAG, `getLauncherAbilityList end,appPages = ${JSON.stringify(this.appPages)}`)
80  }
81}