• 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 fileio from '@ohos.fileio'
17import deviceInfo from '@ohos.deviceInfo';
18import { NoteHomeComp } from './NoteHome'
19import { NoteHomePortraitComp } from './NoteHomePortrait'
20import { LogUtil } from '@ohos/utils/src/main/ets/default/baseUtil/LogUtil'
21import RdbStoreUtil from '@ohos/utils/src/main/ets/default/baseUtil/RdbStoreUtil'
22import NoteData from '@ohos/utils/src/main/ets/default/model/databaseModel/NoteData'
23import inputMethod from '@ohos.inputMethod';
24import router from '@system.router';
25import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
26
27@Entry
28@Component
29export struct MyNoteHomeComp {
30  @StorageLink('DBQueryFinished') dBQueryFinished: number = 0
31  @Provide('PortraitModel') portraitModel: boolean = true
32  @Provide('RefreshFlag') refreshFlag: number = 0
33  private controllerShow: WebController = new WebController()
34  private context = getContext(this)
35  TAG = "MyNoteHomeComp_Tablet"
36  @StorageLink('breakPoint') @Watch('onBreakPointChange') breakPoints: string = 'lg'
37
38  onBreakPointChange() {
39    if (this.breakPoints == 'sm' || this.breakPoints == 'md') {
40      this.portraitModel = true
41    } else {
42      this.portraitModel = false
43    }
44  }
45
46  build() {
47    Row() {
48      if (this.dBQueryFinished == 1) {
49        if (this.breakPoints == 'sm') {
50          NoteHomePortraitComp()
51        } else {
52          NoteHomeComp({ controllerShow: this.controllerShow })
53        }
54
55      }
56    }
57    .width('100%')
58    .height('100%')
59  }
60
61  aboutToAppear(): void {
62    LogUtil.info(this.TAG, "aboutToAppear")
63    this.breakPoints = AppStorage.Get('breakPoint')
64    if (this.breakPoints == 'sm' || this.breakPoints == 'md') {
65      this.portraitModel = true
66    } else {
67      this.portraitModel = false
68    }
69    if (this.context == undefined || this.context == null) {
70      LogUtil.warn(this.TAG, "context is error")
71      return
72    }
73
74    let context: any = getContext(this);
75    let dbExist = false;
76    let dbPath = context.databaseDir + "/db/note.db"
77    try {
78      fileio.accessSync(dbPath)
79      LogUtil.info(this.TAG, "db has created")
80      RdbStoreUtil.initAppStorage(this.context)
81      dbExist = true
82    } catch (err) {
83      LogUtil.info(this.TAG, "db has not created, find to rdb folder")
84    }
85    if (!dbExist) {
86      dbPath = context.databaseDir + "/rdb/note.db"
87      try {
88        fileio.accessSync(dbPath)
89        LogUtil.info(this.TAG, "db has created")
90        RdbStoreUtil.initAppStorage(this.context)
91      } catch (err) {
92        LogUtil.info(this.TAG, "db has not created, start to create db")
93        RdbStoreUtil.createRdbStore(this.context)
94      }
95    }
96  }
97
98  aboutToDisappear(): void {
99    LogUtil.info(this.TAG, "aboutToDisappear")
100  }
101
102  onPageShow(): void {
103    LogUtil.info(this.TAG, "onPageShow")
104    // continue from tablet
105    let continueFromTablet = AppStorage.Get<boolean>('ContinueFromTablet')
106    LogUtil.info(this.TAG, "onPageShow, continueFromTablet : " + continueFromTablet)
107    let noteContentHomeExist = AppStorage.Get<boolean>('NoteContentHomeExist')
108    LogUtil.info(this.TAG, "onPageShow, noteContentHomeExist : " + noteContentHomeExist)
109    if (continueFromTablet && !noteContentHomeExist) {
110      router.push({ uri: 'pages/NoteContentHome' })
111      AppStorage.SetOrCreate<boolean>('ContinueFromTablet', false)
112    }
113    this.refreshFlag = (this.refreshFlag == 0 ? 1 : 0)
114  }
115
116  onBackPress() {
117    LogUtil.info(this.TAG, "onBackPress")
118    // 退出键盘
119    // @ts-ignore
120    inputMethod.getController().stopInputSession();
121  }
122}