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 = 48
34
35  aboutToAppear() {
36    Log.showInfo(TAG, `aboutToAppear`)
37    this.mViewModel.ViewModelInit()
38    this.pageStatus = Constants.STATUS_ABOUT_TO_APPEAR
39    try {
40      CommonStyleManager.setAbilityPageName(TAG)
41      let configInfo = AbilityManager.getAbilityData(AbilityManager.ABILITY_NAME_STATUS_BAR, 'rect')
42      Log.showDebug(TAG, `configMaxWidth${JSON.stringify(configInfo.height)}`)
43      this.mHeightPx = configInfo.height
44      StyleManager.setStyle()
45      this.pageStatus = Constants.STATUS_ABOUT_TO_APPEAR
46    } catch (error) {
47      Log.showError(TAG, `set status error:` + JSON.stringify(error));
48    }
49  }
50
51  aboutToDisappear() {
52    Log.showInfo(TAG, `aboutToDisAppear`)
53    this.pageStatus = Constants.STATUS_ABOUT_TO_DISAPPEAR
54    this.mViewModel.ViewModelDestroy()
55  }
56
57  onPageShow() {
58    Trace.end(Trace.CORE_METHOD_SLEEP_TO_LOCK_SCREEN);
59    Trace.end(Trace.CORE_METHOD_SHOW_LOCK_SCREEN);
60    Log.showInfo(TAG, `onPageShow`)
61    this.pageStatus = Constants.STATUS_ON_PAGE_SHOW
62    this.mViewModel.onPageShow();
63  }
64
65  onPageHide() {
66    Log.showInfo(TAG, `onPageHide`)
67    this.pageStatus = Constants.STATUS_ON_PAGE_HIDE
68  }
69
70  onBackPress(): boolean {
71    let length = parseInt(Router.getLength())
72    Log.showDebug(TAG, `onBackPress length: ${length}`)
73    if (length > 1) {
74      Router.back()
75      return false
76    }
77    return true
78  }
79
80  build() {
81    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
82      if (this.mViewModel.mode == LockStyleMode.SlideScreenLock) {
83        // Slide of lock screen
84        SlideScreenLock({ pageStatus: this.pageStatus, mHeightPx: this.mHeightPx })
85      } else if (this.mViewModel.mode == LockStyleMode.JournalScreenLock) {
86        JournalScreenLock()
87      } else if (this.mViewModel.mode == LockStyleMode.CustomScreenLock) {
88        CustomScreenLock()
89      }
90    }
91  }
92}
93
94