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 {Log, Trace, styleManager as CommonStyleManager, AbilityManager} from '@ohos/common'
17import {LockStyleMode} from '../../../../../../features/screenlock/src/main/ets/com/ohos/model/screenlockStyle'
18import ViewModel from '../vm/indexViewModel'
19import SlideScreenLock from './slidescreenlock'
20import CustomScreenLock from './customscreenlock'
21import JournalScreenLock from './journalscreenlock'
22import Constants from '../common/constants'
23import StyleManager from '../common/StyleManager'
24import Router from '@system.router';
25
26const TAG = 'ScreenLock-Entry';
27
28@Entry
29@Component
30struct Index {
31  @State mViewModel: ViewModel = new ViewModel()
32  @State pageStatus: number = Constants.STATUS_ABOUT_TO_APPEAR
33  @State mHeightPx: number = 0
34
35  aboutToAppear() {
36    Log.showInfo(TAG, `aboutToAppear`)
37    try {
38      CommonStyleManager.setAbilityPageName(TAG)
39      let configInfo = AbilityManager.getAbilityData(AbilityManager.ABILITY_NAME_STATUS_BAR, 'rect')
40      Log.showDebug(TAG, `configMaxWidth${JSON.stringify(configInfo.height)}`)
41      this.mHeightPx = configInfo.height
42      StyleManager.setStyle()
43      this.pageStatus = Constants.STATUS_ABOUT_TO_APPEAR
44    } catch (error) {
45      Log.showDebug(TAG, `set status error:` + JSON.stringify(error));
46    }
47    this.mViewModel.ViewModelInit()
48  }
49
50  aboutToDisappear() {
51    Log.showInfo(TAG, `aboutToDisAppear`)
52    this.pageStatus = Constants.STATUS_ABOUT_TO_DISAPPEAR
53    this.mViewModel.ViewModelDestroy()
54  }
55
56  onPageShow() {
57    Trace.end(Trace.CORE_METHOD_SLEEP_TO_LOCK_SCREEN);
58    Trace.end(Trace.CORE_METHOD_SHOW_LOCK_SCREEN);
59    Log.showInfo(TAG, `onPageShow`)
60    this.pageStatus = Constants.STATUS_ON_PAGE_SHOW
61    this.mViewModel.onPageShow();
62  }
63
64  onPageHide() {
65    Log.showInfo(TAG, `onPageHide`)
66    this.pageStatus = Constants.STATUS_ON_PAGE_HIDE
67  }
68
69  onBackPress(): boolean {
70    let length = parseInt(Router.getLength())
71    Log.showInfo(TAG, `onBackPress length: ${length}`)
72    if (length > 1) {
73      Router.back()
74      return false
75    }
76    return true
77  }
78
79  build() {
80    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
81      if (this.mViewModel.mode == LockStyleMode.SlideScreenLock) {
82        // Slide of lock screen
83        SlideScreenLock({ pageStatus: this.pageStatus, mHeightPx: this.mHeightPx })
84      } else if (this.mViewModel.mode == LockStyleMode.JournalScreenLock) {
85        JournalScreenLock()
86      } else if (this.mViewModel.mode == LockStyleMode.CustomScreenLock) {
87        CustomScreenLock()
88      }
89    }
90  }
91}
92
93