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 { FolderListComp } from '@ohos/component/src/main/ets/components/FolderListComp'
17import { NoteListComp } from '@ohos/component/src/main/ets/components/NoteListComp'
18import { NoteContentComp } from '@ohos/component/src/main/ets/components/NoteContentComp'
19import StyleConstants from '@ohos/utils/src/main/ets/default/constants/StyleConstants'
20import { LogUtil } from '@ohos/utils/src/main/ets/default/baseUtil/LogUtil'
21import { circleColorArray } from '@ohos/utils/src/main/ets/default/model/NoteBaseData'
22import FolderData from '@ohos/utils/src/main/ets/default/model/databaseModel/FolderData'
23import NoteData from '@ohos/utils/src/main/ets/default/model/databaseModel/NoteData'
24import LayoutUtil from '@ohos/utils/src/main/ets/default/baseUtil/LayoutUtil'
25
26@Entry
27@Component
28export struct NoteHomeComp {
29  // 当前文件夹、笔记、分栏
30  @Provide('SelectedFolderData') selectedFolderData: FolderData = AppStorage.Get('Folder')
31  @Provide('SelectedNoteData') selectedNoteData: NoteData = AppStorage.Get('Note')
32  @Provide('SectionStatus') sectionStatus: number = AppStorage.Get('Section')
33  @Provide('SelectedColor') selectedColor: string = circleColorArray[0]
34  @Provide('LastSectionStatus') lastSectionStatus: number = 3 // 记录分栏上一次的状态
35  @Provide('Longpress') longpress: boolean = false // 第二栏长按状态
36  @Provide('ExpandStatus') expandStatus: boolean = false // 笔记本折叠展开状态
37  @Provide('ChooseNote') chooseNote: boolean = true // 是否选择笔记进行打开
38  @Provide('Search') search: boolean = AppStorage.Get('Search') // 是否处于搜索状态
39  @Provide('SearchResultList') searchResultList: NoteData[] = [] // 搜索得到的笔记列表
40  @Provide('InputKeyword') inputKeyword: string = '' // 搜索的字串
41  @Provide('SelectedAll') selectedAll: boolean = false
42  @Provide('EditModel') editModel: boolean = false //编辑模式:临时方案
43  @Provide('Issave') issave: number = 0
44  @StorageLink('breakPoint') breakPoints: string = 'lg'
45  controllerShow: WebviewController
46  TAG = "NoteHomeComp_Tablet"
47  @Provide('AsideWidth') asideWidth: number = 200
48
49  build() {
50    Flex({ justifyContent: FlexAlign.Start }) {
51      if (this.breakPoints === 'lg') {
52        // Folder list display area
53        Flex({ direction: FlexDirection.Column, wrap: FlexWrap.NoWrap, justifyContent: FlexAlign.Center }) {
54          FolderListComp({ controllerShow: this.controllerShow })
55        }
56        .flexShrink(0)
57        .backgroundColor($r("app.color.folderlist_bgcolor_f1f3f5"))
58        .width(this.asideWidth)
59        .height(StyleConstants.PERCENTAGE_100)
60        .animation({ duration: 200 })
61        .enabled(this.search ? false : true)
62
63        // Note list display area
64        Flex({ direction: FlexDirection.Column, wrap: FlexWrap.Wrap, justifyContent: FlexAlign.Start }) {
65          Divider()
66            .vertical(true)
67            .strokeWidth(1)
68            .color($r("app.color.divider_color_182431"))
69            .height("100%")
70            .opacity(StyleConstants.OPACITY_10)
71          NoteListComp({ controllerShow: this.controllerShow })
72        }
73        .flexShrink(1)
74        .backgroundColor($r("app.color.notelist_bgcolor_f1f3f5"))
75        .layoutWeight(2)
76        .height(StyleConstants.PERCENTAGE_100)
77        .visibility(
78            LayoutUtil.getWidthWeightMessage(this.sectionStatus)
79              .noteListVisibility == 0 ? Visibility.None : Visibility.Visible)
80        // Note content display area
81        Flex({ direction: FlexDirection.Column, wrap: FlexWrap.Wrap, justifyContent: FlexAlign.Start }) {
82          Divider()
83            .vertical(true)
84            .strokeWidth(1)
85            .color($r("app.color.divider_color_182431"))
86            .height("100%")
87            .opacity(StyleConstants.OPACITY_10)
88          NoteContentComp({ controllerShow: this.controllerShow })
89        }
90        .flexShrink(0)
91        .backgroundColor($r("app.color.notecontent_color_ffffff"))
92        .layoutWeight(this.sectionStatus != 1 ? 3 : null)
93        .height(StyleConstants.PERCENTAGE_100)
94        .enabled(this.longpress || this.search && this.inputKeyword.length == 0 ? false : true)
95      } else if (this.breakPoints === 'md') {
96        Stack({ alignContent: Alignment.Start }) {
97          Row() {
98            // Note list display area
99            Flex({ direction: FlexDirection.Column, wrap: FlexWrap.Wrap, justifyContent: FlexAlign.Start }) {
100              Divider()
101                .vertical(true)
102                .strokeWidth(1)
103                .color($r("app.color.divider_color_182431"))
104                .height("100%")
105                .opacity(StyleConstants.OPACITY_10)
106              NoteListComp({ controllerShow: this.controllerShow })
107            }
108            .flexShrink(1)
109            .backgroundColor($r("app.color.notelist_bgcolor_f1f3f5"))
110            .layoutWeight(2)
111            .height(StyleConstants.PERCENTAGE_100)
112            .visibility(
113                LayoutUtil.getWidthWeightMessage(this.sectionStatus)
114                  .noteListVisibility == 0 ? Visibility.None : Visibility.Visible)
115
116            Flex({ direction: FlexDirection.Column, wrap: FlexWrap.Wrap, justifyContent: FlexAlign.Start }) {
117              Divider()
118                .vertical(true)
119                .strokeWidth(1)
120                .color($r("app.color.divider_color_182431"))
121                .height("100%")
122                .opacity(StyleConstants.OPACITY_10)
123              NoteContentComp({ controllerShow: this.controllerShow })
124            }
125            .flexShrink(0)
126            .backgroundColor($r("app.color.notecontent_color_ffffff"))
127            .layoutWeight(this.sectionStatus != 1 ? 3 : null)
128            .height(StyleConstants.PERCENTAGE_100)
129            .enabled(this.longpress || this.search && this.inputKeyword.length == 0 ? false : true)
130          }
131
132          // 蒙层
133          if (this.expandStatus) {
134            Column()
135              .width('100%')
136              .height('100%')
137              .position({ x: 0, y: 0 })
138              .backgroundColor(Color.Black)
139              .opacity(0.2)
140              .transition({ opacity: 0 })
141          }
142          //Folder list display area
143          Column() {
144            FolderListComp()
145          }
146          .width(200)
147          .height(StyleConstants.PERCENTAGE_100)
148          .translate({ x: this.expandStatus ? 0 : '-200', y: 0 })
149        }
150        .width(StyleConstants.PERCENTAGE_100).height(StyleConstants.PERCENTAGE_100)
151      }
152    }
153    .width(StyleConstants.PERCENTAGE_100)
154    .height(StyleConstants.PERCENTAGE_100)
155  }
156
157  aboutToAppear(): void {
158    LogUtil.info(this.TAG, "aboutToAppear")
159    let isContinue = AppStorage.Get<boolean>('IsContinue')
160    LogUtil.info(this.TAG, "aboutToAppear, isContinue : " + isContinue)
161    if (isContinue) {
162      this.sectionStatus = AppStorage.Get('Section')
163    }
164    // continue from phone
165    let continueFromPhone = AppStorage.Get<boolean>('ContinueFromPhone')
166    LogUtil.info(this.TAG, "aboutToAppear, continueFromPhone : " + continueFromPhone)
167    if (continueFromPhone) {
168      this.sectionStatus = 1
169    }
170    // save continue data
171    AppStorage.SetOrCreate<number>('ContinueSection', this.sectionStatus)
172    LogUtil.info(this.TAG, "aboutToAppear, set continue section success")
173  }
174
175  aboutToDisappear(): void {
176    LogUtil.info(this.TAG, "aboutToDisappear")
177  }
178}