• 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 deviceInfo from '@ohos.deviceInfo';
17import { NoteContentCompPortrait } from '@ohos/component/src/main/ets/components/NoteContentCompPortrait'
18import { NoteContent } from '@ohos/component/src/main/ets/components/NoteContent'
19import { LogUtil } from '@ohos/utils/src/main/ets/default/baseUtil/LogUtil'
20import RdbStoreUtil from '@ohos/utils/src/main/ets/default/baseUtil/RdbStoreUtil'
21import inputMethod from '@ohos.inputMethod'
22import webview from '@ohos.web.webview';
23import common from '@ohos.app.ability.common';
24
25@Entry
26@Component
27struct NoteContentHome {
28  @Provide('RefreshFlag') refreshFlag: number = 0
29  private controllerShow: WebviewController = new webview.WebviewController()
30  @StorageLink('DBQueryFinished') dBQueryFinished: number = 0
31  @StorageLink('breakPoint') breakPoints: string = 'lg'
32  TAG = "NoteContentHome_Tablet"
33
34  build() {
35    // Note content display area
36    Flex({ direction: FlexDirection.Column, wrap: FlexWrap.Wrap, justifyContent: FlexAlign.Start }) {
37      if (this.dBQueryFinished == 1) {
38        if (this.breakPoints == 'sm') {
39          NoteContentCompPortrait({ controllerShow: this.controllerShow })
40        } else {
41          NoteContent({ controllerShow: this.controllerShow })
42        }
43
44      }
45    }
46    .backgroundColor($r("app.color.notecontent_color_ffffff"))
47    .width('100%')
48    .height('100%')
49  }
50
51  onBackPress(): void {
52    try {
53      LogUtil.info(this.TAG, "onBackPress")
54      this.controllerShow.runJavaScript("RICH_EDITOR.setInputEnabled(false)")
55      this.controllerShow.runJavaScript("getHtmlContent()")
56      if (deviceInfo.deviceType !== 'phone' && deviceInfo.deviceType !== 'default') {
57        inputMethod.getController().stopInputSession();
58      }
59    } catch (error) {
60      LogUtil.info(this.TAG, 'onBackPress error')
61    }
62  }
63
64  aboutToAppear(): void {
65    let noteContext = AppStorage.Get<common.UIAbilityContext>('noteContext')!;
66    this.breakPoints = AppStorage.Get('breakPoint')!;
67    LogUtil.info(this.TAG, "aboutToAppear")
68    let isContinue = AppStorage.Get<boolean>('IsContinue')
69    LogUtil.info(this.TAG, "aboutToAppear, isContinue : " + isContinue)
70    if (isContinue) {
71      RdbStoreUtil.initAppStorage(noteContext);
72    }
73    if (deviceInfo.deviceType === 'phone' || deviceInfo.deviceType === 'default') {
74      AppStorage.SetOrCreate<boolean>('NoteContentHomeExist', true)
75    }
76  }
77}