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