• 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 DateUtil from '@ohos/utils/src/main/ets/default/baseUtil/DateUtil'
17import FolderData from '@ohos/utils/src/main/ets/default/model/databaseModel/FolderData'
18import NoteData from '@ohos/utils/src/main/ets/default/model/databaseModel/NoteData'
19import {
20  TableName,
21  NoteTableColumn,
22  SysDefFolderUuid,
23  Favorite,
24  Delete,
25  Top,
26  NoteType
27} from '@ohos/utils/src/main/ets/default/model/databaseModel/EnumData'
28import { NoteDataMoveDialog, DeleteDialog } from './CusDialogComp'
29import RdbStoreUtil from '@ohos/utils/src/main/ets/default/baseUtil/RdbStoreUtil'
30import prompt from '@system.prompt'
31import NoteUtil from '@ohos/utils/src/main/ets/default/baseUtil/NoteUtil'
32import FolderUtil from '@ohos/utils/src/main/ets/default/baseUtil/FolderUtil'
33import StyleConstants from '@ohos/utils/src/main/ets/default/constants/StyleConstants'
34import SearchModel from '@ohos/utils/src/main/ets/default/model/searchModel/SearchModel'
35import { LogUtil } from '@ohos/utils/src/main/ets/default/baseUtil/LogUtil'
36import router from '@system.router';
37import rs from '@ohos.resourceManager'
38import inputMethod from '@ohos.inputMethod';
39
40const TAG = "NoteListComp"
41
42async function routePage() {
43  let options = {
44    uri: 'pages/NoteContentHome'
45  }
46  try {
47    await router.push(options)
48  } catch (err) {
49    LogUtil.info(TAG, "fail callback")
50  }
51}
52
53// Note list component
54@Component
55export struct NoteListComp {
56  @StorageLink('AllFolderArray') AllFolderArray: FolderData[] = AppStorage.Link('AllFolderArray')
57  @Consume('SelectedFolderData') selectedFolderData: FolderData
58  @Consume('Search') search: boolean
59  controllerShow: WebController
60  @Consume('AsideWidth') asideWidth: number
61
62  build() {
63    Flex({ direction: FlexDirection.Column }) {
64      Flex({ direction: FlexDirection.Column }) {
65        NoteOverViewComp({ controllerShow: this.controllerShow })
66        Column() {
67        }
68        .height(this.search ? 15 : 0)
69
70        NoteItemListComp({ controllerShow: this.controllerShow })
71      }
72      .width('100%')
73      .flexShrink(1)
74
75      Column() {
76        OperateNoteCompForPortrait()
77      }
78      .flexShrink(0)
79    }
80    .height('100%')
81    .width('100%')
82  }
83
84  aboutToAppear(): void {
85    AppStorage.SetOrCreate('isUpdate', false)
86    LogUtil.info(TAG, "aboutToAppear")
87  }
88
89  aboutToDisappear(): void {
90    LogUtil.info(TAG, "aboutToDisappear")
91  }
92}
93
94@Component
95struct NoteOverViewComp {
96  @StorageLink('AllNoteArray') AllNoteArray: NoteData[] = AppStorage.Link('AllNoteArray')
97  @StorageLink('breakPoint') breakPoints: string = AppStorage.Get('breakPoint')
98  @StorageLink('CheckedNoteArray') CheckedNoteArray: NoteData[] = []
99  @Consume('SelectedFolderData') selectedFolderData: FolderData
100  @Consume('RefreshFlag') refreshFlag: number
101  @Consume('SectionStatus') sectionStatus: number
102  @Consume("Longpress") longpress: boolean
103  @Consume('ExpandStatus') expandStatus: boolean
104  @Consume('Search') search: boolean
105  @Consume('PortraitModel') portraitModel: boolean
106  controllerShow: WebController
107  @State noteNumber: number = undefined
108  @StorageLink('isUpdate') isUpdate: boolean = false
109  @Consume('AsideWidth') asideWidth: number
110
111  build() {
112    Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) {
113      Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center }) {
114        Column() {
115          Image($r("app.media.suojin_back"))
116            .height(24)
117            .width(24)
118            .responseRegion({
119              x: -15.0,
120              y: -15.0,
121              width: 54,
122              height: 54
123            })
124            .margin({ right: 24 }) // 两分栏时缩进图片与右边有个24的间距
125            .visibility(this.breakPoints == 'lg' && this.sectionStatus == 3 ? Visibility.None : Visibility.Visible)
126            .onClick(() => {
127              if (this.breakPoints == 'sm' || this.breakPoints == 'md') {
128                animateTo({ duration: 200 }, () => {
129                  this.expandStatus = !this.expandStatus
130                })
131              } else {
132                this.asideWidth = 200
133                this.sectionStatus = (this.sectionStatus == 3 ? 2 : 3)
134                // save continue data
135                AppStorage.SetOrCreate<number>('ContinueSection', this.sectionStatus)
136                LogUtil.info(TAG, "NoteOverViewComp, set continue section success")
137              }
138            })
139        }.alignItems(HorizontalAlign.Center)
140
141        Flex({
142          direction: FlexDirection.Column,
143          wrap: FlexWrap.Wrap,
144          justifyContent: FlexAlign.Center,
145          alignItems: ItemAlign.Start
146        }) {
147          Text(FolderUtil.getFolderText(this.selectedFolderData))
148            .id(this.isUpdate + '')
149            .maxLines(1)
150            .fontSize(30)
151            .fontColor($r("app.color.all_notes_font_color"))
152            .fontWeight(FontWeight.Medium)
153            .textOverflow({ overflow: TextOverflow.Ellipsis })
154          Row() {
155            Text(FolderUtil.getNoteCount(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid).toString())
156              .id(this.isUpdate + '')
157              .maxLines(1)
158              .fontSize(14)
159              .fontColor($r("app.color.num_of_notes_font_color"))
160            Text($r("app.string.noteslist"))
161              .fontSize(14)
162              .fontColor($r("app.color.num_of_notes_font_color"))
163              .textOverflow({ overflow: TextOverflow.Ellipsis })
164          }
165          .margin({ top: 5 })
166          .visibility((FolderUtil.getNoteCount(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid) == 0) ? Visibility.None : Visibility.Visible)
167        }.visibility(this.longpress ? Visibility.None : Visibility.Visible)
168
169        Row() {
170          Image($r("app.media.cross"))
171            .height(24)
172            .width(24)
173            .responseRegion({
174              x: -15.0,
175              y: -15.0,
176              width: 54,
177              height: 54
178            })
179            .onClick(() => {
180              this.longpress = false
181              this.refreshFlag = (this.refreshFlag == 0 ? 1 : 0)
182              NoteUtil.unsetAllNotesChecked(this.CheckedNoteArray)
183            })
184          Text(this.CheckedNoteArray.length == 0 ? $r("app.string.none_selected") : $r("app.string.selected", this.CheckedNoteArray.length))
185            .fontSize(20)
186            .fontColor($r("app.color.note_selected_font_color"))
187            .margin({ left: 16 })
188            .textOverflow({ overflow: TextOverflow.Ellipsis })
189            .fontWeight(FontWeight.Medium)
190        }.alignItems(VerticalAlign.Center)
191        .visibility(this.longpress ? Visibility.Visible : Visibility.None)
192      }.padding({ top: 8, bottom: 8 })
193      .height('100%')
194
195      AddNoteComp({ controllerShow: this.controllerShow })
196      OperateNoteComp({ controllerShow: this.controllerShow })
197      Text(this.refreshFlag.toString()).visibility(Visibility.None)
198    }
199    .width('100%')
200    .height(82)
201    .padding({
202      left: this.sectionStatus == 2 ? 24 : 36,
203      right: 24
204    }) // 两分栏时缩进图标与左侧不需要间距
205    .visibility(this.search ? Visibility.None : Visibility.Visible)
206  }
207}
208
209@Component
210export struct NoteItemComp {
211  public noteItem: NoteData
212  public spans: any[]
213  controllerShow: WebController
214  @Consume('SelectedFolderData') selectedFolderData: FolderData
215  @Consume('SelectedNoteData') selectedNoteData: NoteData
216  @StorageLink('AllFolderArray') AllFolderArray: FolderData[] = AppStorage.Link('AllFolderArray')
217  @StorageLink('CheckedNoteArray') CheckedNoteArray: NoteData[] = []
218  @Consume('ChooseNote') chooseNote: boolean
219  @Consume('RefreshFlag') refreshFlag: number
220  @Consume('Search') search: boolean
221  @Consume('selectedAll') selectedAll: boolean
222  @Consume('PortraitModel') portraitModel: boolean
223  @State isChecked: boolean = undefined
224  @Consume('Longpress') @Watch('isLongPress') longpress: boolean
225  @StorageLink('isUpdate') isUpdate: boolean = false
226
227  isLongPress() {
228    if (this.longpress) {
229      this.isChecked = false
230    }
231  }
232
233  updateAndGetChecked() {
234    this.isChecked = NoteUtil.isNoteChecked(this.CheckedNoteArray, this.noteItem)
235    return this.isChecked
236  }
237
238  build() {
239    Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) {
240      Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center }) {
241        Text(JSON.stringify(this.refreshFlag)).visibility(Visibility.None) // 用于强制刷新使用
242        Column({ space: 2 }) {
243          Row({ space: 8 }) {
244            Image($r("app.media.verticalBar"))
245              .id(this.isUpdate + '')
246              .height(16)
247              .width(4)
248              .fillColor(NoteUtil.getVerticalBarBgColor(AppStorage.Get('AllFolderArray'), this.noteItem.folder_uuid))
249            Text(this.noteItem.title)
250              .fontSize(16)
251              .maxLines(1)
252              .textOverflow({ overflow: TextOverflow.Ellipsis })
253          }
254
255          Row({ space: 4 }) {
256            Text(DateUtil.formateDateForNoteTitle(new Date(this.noteItem.modified_time)))
257              .id(this.isUpdate + '')
258              .maxLines(1)
259              .fontSize(14)
260              .fontColor($r("app.color.list_modified_time_font_color"))
261              .fontWeight(FontWeight.Regular)
262              .textOverflow({ overflow: TextOverflow.Ellipsis })
263            Image($r("app.media.favorite"))
264              .height(16)
265              .width(16)
266              .visibility(this.noteItem.is_favorite == Favorite.Yes ? Visibility.Visible : Visibility.None)
267            Image($r("app.media.topped"))
268              .height(16)
269              .width(16)
270              .visibility(this.noteItem.is_top == Top.Yes ? Visibility.Visible : Visibility.None)
271          }
272          .padding({ left: 12 })
273        }.alignItems(HorizontalAlign.Start)
274      }.flexShrink(1)
275
276      Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) {
277        Stack({ alignContent: Alignment.Center }) {
278          Image(this.noteItem.content_img)
279            .id(this.isUpdate + '')
280            .height(47)
281            .width(47)
282            .borderRadius(12)
283            .border({ width: 0.5, color: '#19182431' })
284            .visibility(this.noteItem.content_img ? Visibility.Visible : Visibility.None)
285        }
286
287        Stack({ alignContent: Alignment.Center }) {
288          Image($r("app.media.unChecked"))
289            .height(24)
290            .width(24)
291          Image($r("app.media.checked"))
292            .width(24)
293            .height(24)
294            .visibility(this.updateAndGetChecked() ? Visibility.Visible : Visibility.None)
295            .id(this.isUpdate + '')
296        }.width(24)
297        .height(24)
298        .visibility(this.longpress ? Visibility.Visible : Visibility.None)
299      }
300      .flexShrink(0)
301      .height(48)
302      .width(this.longpress ? 80 : 48)
303    }
304    .width('100%')
305    .height(72)
306    .padding({
307      left: 16,
308      right: 12,
309      top: 4,
310      bottom: 4
311    })
312    .borderRadius(24)
313    .linearGradient({
314      direction: GradientDirection.Right,
315      colors: this.selectedNoteData.uuid == this.noteItem.uuid ? [[0xffcdae, 0.0], [0xFfece2, 1.0]] : [[0xffffff, 0.0], [0xffffff, 1.0]]
316    })
317    .onClick(() => {
318      if (this.search) {
319        this.search = false
320        AppStorage.SetOrCreate<boolean>('Search', this.search)
321        return
322      }
323      if (this.longpress) {
324        if (NoteUtil.isNoteChecked(this.CheckedNoteArray, this.noteItem)) {
325          NoteUtil.unsetNoteChecked(this.CheckedNoteArray, this.noteItem)
326          this.refreshFlag = (this.refreshFlag == 0 ? 1 : 0)
327          this.isChecked = NoteUtil.isNoteChecked(this.CheckedNoteArray, this.noteItem)
328        } else {
329          NoteUtil.setNoteChecked(this.CheckedNoteArray, this.noteItem)
330          this.refreshFlag = (this.refreshFlag == 0 ? 1 : 0)
331          this.isChecked = NoteUtil.isNoteChecked(this.CheckedNoteArray, this.noteItem)
332        }
333        return;
334      } else {
335        this.selectedNoteData = this.noteItem
336        this.chooseNote = true
337        // save continue data
338        let continueNote: string = JSON.stringify(this.selectedNoteData.toNoteObject())
339        AppStorage.SetOrCreate<string>('ContinueNote', continueNote)
340        LogUtil.info(TAG, "NoteItemComp, set continue note success")
341      }
342      if (this.portraitModel == false) {
343        this.controllerShow.runJavaScript({
344          script: "RICH_EDITOR.setHtml('" + this.selectedNoteData.content_text + "')"
345        })
346      }
347      if (this.portraitModel == true) {
348        AppStorage.SetOrCreate<NoteData>('NewNote', this.selectedNoteData)
349        AppStorage.SetOrCreate<FolderData>('NewFolder', this.selectedFolderData)
350        routePage()
351      }
352      this.selectedAll = this.CheckedNoteArray.length ==
353      NoteUtil.getNoteDataArray(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid).length
354      this.refreshFlag = (this.refreshFlag == 0 ? 1 : 0)
355    })
356    .gesture(
357    GestureGroup(GestureMode.Exclusive,
358      // 长按:对笔记列表进行操作
359    LongPressGesture()
360      .onAction(() => {
361        if (this.longpress == false) {
362          this.longpress = true
363          NoteUtil.setNoteChecked(this.CheckedNoteArray, this.noteItem)
364          this.isChecked = NoteUtil.isNoteChecked(this.CheckedNoteArray, this.noteItem)
365        }
366      })
367    )
368    )
369
370  }
371}
372
373@Component
374export struct NoteItemListComp {
375  @StorageLink('AllNoteArray') AllNoteArray: NoteData[] = AppStorage.Link('AllNoteArray')
376  @Consume('SelectedFolderData') selectedFolderData: FolderData
377  @Consume('RefreshFlag') refreshFlag: number
378  @Consume('Longpress') longpress: boolean
379  @Consume('Search') search: boolean
380  @Consume @Watch('doSearch') inputKeyword: string
381  @Consume('SearchResultList') searchResultList: NoteData[]
382  @Consume('SelectedNoteData') selectedNoteData: NoteData
383  @Consume('PortraitModel') portraitModel: boolean
384  @State dateList: NoteData[] = []
385  controllerShow: WebController
386  @StorageLink('isUpdate') @Watch('updateList') isUpdate: boolean = false
387
388  updateList() {
389    if (this.isUpdate) {
390      this.dateList = NoteUtil.getNoteDataArray(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid)
391    }
392    this.isUpdate = false
393    this.doSearch()
394  }
395
396  aboutToAppear() {
397    this.dateList = NoteUtil.getNoteDataArray(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid)
398  }
399
400  doSearch() {
401    if (this.inputKeyword.length == 0) {
402      return
403    }
404    SearchModel.search(NoteUtil.getNoteDataArray(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid), this.inputKeyword)
405      .then((result: NoteData[]) => {
406        LogUtil.info(TAG, "result size " + result.length.toString())
407        this.searchResultList = result
408        if (this.searchResultList.length != 0) {
409          this.selectedNoteData = this.searchResultList[0]
410        } else {
411          this.selectedNoteData = NoteUtil.getFirstNoteData(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid)
412        }
413        if (this.portraitModel == false) {
414          this.controllerShow.runJavaScript({
415            script: "RICH_EDITOR.setHtml('" + this.selectedNoteData.content_text + "')"
416          })
417        }
418        // save continue data
419        let continueNote: string = JSON.stringify(this.selectedNoteData.toNoteObject())
420        AppStorage.SetOrCreate<string>('ContinueNote', continueNote)
421        LogUtil.info(TAG, "doSearch, set continue note success")
422        this.refreshFlag = (this.refreshFlag == 0 ? 1 : 0)
423      })
424  }
425
426  build() {
427    Column() {
428      Text(this.refreshFlag.toString()).visibility(Visibility.None)
429      Flex() {
430        SearchComp()
431      }
432      .id(this.isUpdate + '')
433      .width("100%")
434      .padding({ left: 24, right: 24, bottom: 12 })
435      .visibility((FolderUtil.getNoteCount(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid) == 0) ? Visibility.None : Visibility.Visible)
436
437      Stack() {
438        Flex({ direction: FlexDirection.Column }) {
439          Flex({ justifyContent: FlexAlign.Center }) {
440            Text($r("app.string.permanently_delete_tips"))
441              .fontSize(12)
442              .fontColor($r("app.color.Recently_delete_prompt_font_color"))
443          }
444          .padding({ bottom: this.selectedFolderData.uuid == SysDefFolderUuid.RecentDeletes ? 12 : 0 })
445          .width('100%')
446          .visibility(this.selectedFolderData.uuid == SysDefFolderUuid.RecentDeletes
447                      && FolderUtil.getNoteCount(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid) > 0 ? Visibility.Visible : Visibility.None)
448
449          Column() {
450            List({ initialIndex: 0 }) {
451              ListItem() {
452                Column({ space: 8 }) {
453                  Image($r('app.media.emptyPage'))
454                    .width(120)
455                    .height(120)
456                  Text($r("app.string.Empty_page"))
457                    .fontSize(12)
458                    .fontColor($r("app.color.Empty_page_font_color"))
459                }
460              }
461              .id(this.isUpdate + '')
462              .width('100%')
463              .height('100%')
464              .padding({ bottom: 120 })
465              .visibility((FolderUtil.getNoteCount(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid) == 0) ? Visibility.Visible : Visibility.None)
466
467              ForEach(this.inputKeyword.length == 0 ?
468              this.dateList : this.searchResultList, (noteItem) => {
469                ListItem() {
470                  Column() {
471                    NoteItemComp({
472                      noteItem: noteItem,
473                      spans: SearchModel.splitToHighlightText(noteItem.title, this.inputKeyword),
474                      controllerShow: this.controllerShow
475                    })
476                  }
477                  .padding({ left: 24, right: 24, bottom: 12 })
478                }
479              }, noteItem => JSON.stringify(noteItem))
480            }
481            .id(this.isUpdate + '')
482            .margin((FolderUtil.getNoteCount(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid) == 0) ? {
483                                                                                                                     bottom: 0
484                                                                                                                   } : {
485                                                                                                                         bottom: 56
486                                                                                                                       })
487            .layoutWeight(1)
488            .listDirection(Axis.Vertical)
489            .edgeEffect(EdgeEffect.Spring)
490          }
491          .layoutWeight(1)
492          .height("100%")
493          .margin({ top: this.search ? 8 : 0 })
494        }
495        .height("100%")
496        .width("100%")
497
498        // search input mask
499        Column() {
500        }
501        .height("100%")
502        .width("100%")
503        .backgroundColor("#18181A")
504        .opacity(0.1)
505        .visibility(this.search ? Visibility.Visible : Visibility.Hidden)
506      }
507    }
508    .onClick(() => {
509      this.search = false
510      inputMethod.getController().stopInputSession()
511      AppStorage.SetOrCreate<boolean>('Search', this.search)
512    })
513  }
514}
515
516@Component
517export struct OperateNoteComp {
518  @Consume('Longpress') longpress: boolean
519  @StorageLink('CheckedNoteArray') CheckedNoteArray: NoteData[] = []
520  @StorageLink('AllNoteArray') AllNoteArray: NoteData[] = AppStorage.Link('AllNoteArray')
521  @Consume('SelectedFolderData') selectedFolderData: FolderData
522  @Consume('RefreshFlag') refreshFlag: number
523  @Consume('SelectedNoteData') selectedNoteData: NoteData
524  @Consume('PortraitModel') portraitModel: boolean
525  @Consume('selectedAll') selectedAll: boolean
526  @StorageLink('isUpdate') isUpdate: boolean = false
527  controllerShow: WebController
528  noteDataMoveDialogCtl: CustomDialogController = new CustomDialogController({
529    builder: NoteDataMoveDialog({ onConfirm: this.onMoveConfirm.bind(this) }),
530    alignment: DialogAlignment.Center,
531    autoCancel: false,
532    customStyle: true,
533  })
534
535  onMoveConfirm(folderUuid: string) {
536    this.CheckedNoteArray.forEach((noteItem) => {
537      noteItem.folder_uuid = folderUuid
538      // update note to db
539      let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable)
540      predicates_note.equalTo(NoteTableColumn.Uuid, noteItem.uuid)
541      RdbStoreUtil.update(noteItem.toNoteObject(), predicates_note, null)
542    })
543    this.selectedNoteData = NoteUtil.getFirstNoteData(this.AllNoteArray, this.selectedFolderData.uuid)
544    // save continue data
545    let continueNote: string = JSON.stringify(this.selectedNoteData.toNoteObject())
546    AppStorage.SetOrCreate<string>('ContinueNote', continueNote)
547    LogUtil.info(TAG, "onMoveConfirm, set continue note success")
548    if (this.portraitModel == false) {
549      this.controllerShow.runJavaScript({ script: "RICH_EDITOR.setHtml('" + this.selectedNoteData.content_text + "')" })
550    }
551    this.longpress = false
552    this.refreshFlag = (this.refreshFlag == 0 ? 1 : 0)
553    NoteUtil.unsetAllNotesChecked(this.CheckedNoteArray)
554    NoteUtil.refreshAll()
555  }
556
557  noteDataDeleteDialogCtl: CustomDialogController = new CustomDialogController({
558    builder: DeleteDialog({ onConfirm: this.onDeleteConfirm.bind(this), multiSelect: true }),
559    alignment: DialogAlignment.Center,
560    autoCancel: false,
561    customStyle: true,
562  })
563
564  onDeleteConfirm() {
565    if (this.selectedFolderData.uuid != SysDefFolderUuid.RecentDeletes) {
566      this.CheckedNoteArray.forEach((noteItem: NoteData) => {
567        noteItem.is_deleted = Delete.Yes
568        noteItem.deleted_time = new Date().getTime()
569        // update note to db
570        let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable)
571        predicates_note.equalTo(NoteTableColumn.Uuid, noteItem.uuid)
572        RdbStoreUtil.update(noteItem.toNoteObject(), predicates_note, null)
573      })
574    } else {
575      this.CheckedNoteArray.forEach((noteItem: NoteData) => {
576        NoteUtil.removeNoteData(this.AllNoteArray, noteItem.uuid)
577        // delete note from db
578        let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable)
579        predicates_note.equalTo(NoteTableColumn.Uuid, noteItem.uuid)
580        RdbStoreUtil.delete(predicates_note, null)
581      })
582    }
583    NoteUtil.unsetAllNotesChecked(this.CheckedNoteArray)
584    this.refreshFlag = (this.refreshFlag == 0 ? 1 : 0)
585    this.longpress = false
586    this.selectedNoteData = NoteUtil.getFirstNoteData(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid)
587    if (this.portraitModel == false) {
588      this.controllerShow.runJavaScript({ script: "RICH_EDITOR.setHtml('" + this.selectedNoteData.content_text + "')" })
589    }
590    // save continue data
591    let continueNote: string = JSON.stringify(this.selectedNoteData.toNoteObject())
592    AppStorage.SetOrCreate<string>('ContinueNote', continueNote)
593    LogUtil.info(TAG, "OperateNoteComp, set continue note success")
594    NoteUtil.refreshAll()
595  }
596
597  build() {
598    Row() {
599      Image($r('app.media.set_top'))
600        .width(24)
601        .height(24)
602        .opacity(this.CheckedNoteArray.length == 0 ? 0.4 : 1)
603        .enabled(this.CheckedNoteArray.length == 0 ? false : true)
604        .margin({ right: this.selectedFolderData.uuid == SysDefFolderUuid.RecentDeletes ? 0 : 18 })
605        .visibility(this.selectedFolderData.uuid == SysDefFolderUuid.RecentDeletes ? Visibility.None : Visibility.Visible)
606        .onClick(() => {
607          this.CheckedNoteArray.forEach((noteItem) => {
608            noteItem.is_top = (noteItem.is_top == Top.Yes) ? Top.No : Top.Yes
609            // update note to db
610            let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable)
611            predicates_note.equalTo(NoteTableColumn.Uuid, noteItem.uuid)
612            RdbStoreUtil.update(noteItem.toNoteObject(), predicates_note, null)
613          })
614          this.longpress = false
615          NoteUtil.unsetAllNotesChecked(this.CheckedNoteArray)
616          NoteUtil.refreshAll()
617        })
618      Image($r('app.media.move'))
619        .width(24)
620        .height(24)
621        .opacity(this.CheckedNoteArray.length == 0 ? 0.4 : 1)
622        .enabled(this.CheckedNoteArray.length == 0 ? false : true)
623        .margin({ right: this.selectedFolderData.uuid == SysDefFolderUuid.RecentDeletes ? 0 : 18 })
624        .visibility(this.selectedFolderData.uuid == SysDefFolderUuid.RecentDeletes ? Visibility.None : Visibility.Visible)
625        .onClick(() => {
626          this.noteDataMoveDialogCtl.open()
627        })
628      Image($r('app.media.delete'))
629        .width(24)
630        .height(24)
631        .margin({ right: 18 })
632        .opacity(this.CheckedNoteArray.length == 0 ? 0.4 : 1)
633        .enabled(this.CheckedNoteArray.length == 0 ? false : true)
634        .onClick(() => {
635          this.noteDataDeleteDialogCtl.open()
636        })
637      Image($r('app.media.recover'))
638        .width(24)
639        .height(24)
640        .opacity(this.CheckedNoteArray.length == 0 ? 0.4 : 1)
641        .enabled(this.CheckedNoteArray.length == 0 ? false : true)
642        .margin({ right: this.selectedFolderData.uuid == SysDefFolderUuid.RecentDeletes ? 18 : 0 })
643        .visibility(this.selectedFolderData.uuid == SysDefFolderUuid.RecentDeletes ? Visibility.Visible : Visibility.None)
644        .onClick(() => {
645          this.CheckedNoteArray.forEach((noteItem) => {
646            noteItem.is_deleted = Delete.No
647            noteItem.deleted_time = 0
648            let context: any = getContext(this)
649            let resource = {
650              bundleName: "com.ohos.note",
651              moduleName: "default",
652              id: $r('app.string.restore').id
653            };
654            context.resourceManager.getString(resource, (error, value) => {
655              if (error != null) {
656                console.log("error is " + error);
657              } else {
658                prompt.showToast({ message: value, duration: 2000 });
659              }
660            });
661            // update note to db
662            let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable)
663            predicates_note.equalTo(NoteTableColumn.Uuid, noteItem.uuid)
664            RdbStoreUtil.update(noteItem.toNoteObject(), predicates_note, null)
665          })
666          this.longpress = false
667          NoteUtil.unsetAllNotesChecked(this.CheckedNoteArray)
668          NoteUtil.refreshAll()
669        })
670      Image(this.CheckedNoteArray.length == NoteUtil.getNoteDataArray(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid).length ? $r('app.media.check_all1') : $r('app.media.check_all'))
671        .width(24)
672        .height(24)
673        .id(this.isUpdate + '')
674        .onClick(() => {
675          LogUtil.info(TAG, "select all click")
676          if (this.CheckedNoteArray.length <
677          NoteUtil.getNoteDataArray(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid).length) {
678            NoteUtil.setAllNotesChecked(this.CheckedNoteArray, NoteUtil.getNoteDataArray(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid))
679          } else {
680            NoteUtil.unsetAllNotesChecked(this.CheckedNoteArray)
681          }
682          this.selectedAll = !this.selectedAll
683          this.refreshFlag = (this.refreshFlag == 0 ? 1 : 0)
684          NoteUtil.refreshAll()
685        })
686    }
687    .width(this.selectedFolderData.uuid == SysDefFolderUuid.RecentDeletes ? 168 : 248)
688    .visibility(this.longpress && this.portraitModel == false ? Visibility.Visible : Visibility.None)
689  }
690}
691
692@Component
693export struct AddNoteComp {
694  @StorageLink('AllNoteArray') AllNoteArray: NoteData[] = AppStorage.Link('AllNoteArray')
695  @Consume('Longpress') longpress: boolean
696  @Consume('SelectedFolderData') selectedFolderData: FolderData
697  @Consume('SelectedNoteData') selectedNoteData: NoteData
698  @Consume('SectionStatus') sectionStatus: number
699  @Consume('LastSectionStatus') lastSectionStatus: number
700  @Consume('EditModel') editModel: boolean
701  @Consume('ChooseNote') chooseNote: boolean
702  @Consume('PortraitModel') portraitModel: boolean
703  controllerShow: WebController
704
705  build() {
706    Image($r('app.media.addNote'))
707      .width(24)
708      .height(24)
709      .margin({ right: 12 })
710      .responseRegion({ x: -15.0, y: -15.0, width: 54, height: 54 })
711      .onClick(() => {
712        let noteData
713        if (this.selectedFolderData.uuid == SysDefFolderUuid.AllNotes || this.selectedFolderData.uuid == SysDefFolderUuid.MyFavorites) {
714          noteData = new NoteData(0, "标题", new Date().getTime() + "", SysDefFolderUuid.UnClassified, "", "", NoteType.SysDef, Top.No, Favorite.No, Delete.No, new Date().getTime(), new Date().getTime(), 0, 0)
715        } else {
716          noteData = new NoteData(0, "标题", new Date().getTime() + "", this.selectedFolderData.uuid, "", "", NoteType.SysDef, Top.No, Favorite.No, Delete.No, new Date().getTime(), new Date().getTime(), 0, 0)
717        }
718
719        this.AllNoteArray.push(noteData)
720        RdbStoreUtil.insert(TableName.NoteTable, noteData.toNoteObject(), null)
721        LogUtil.info(TAG, 'insert new note is:' + noteData.uuid)
722
723        this.selectedNoteData = noteData
724        AppStorage.SetOrCreate<NoteData>('NewNote', noteData)
725        if (this.portraitModel == false) {
726          this.controllerShow.runJavaScript({
727            script: "RICH_EDITOR.setHtml('" + this.selectedNoteData.content_text + "')"
728          })
729        }
730        if (this.portraitModel == true) {
731          this.editModel = true
732        }
733        this.chooseNote = true
734        // save continue data
735        let continueNote: string = JSON.stringify(this.selectedNoteData.toNoteObject())
736        AppStorage.SetOrCreate<FolderData>('NewFolder', this.selectedFolderData)
737        AppStorage.SetOrCreate<string>('ContinueNote', continueNote)
738        LogUtil.info(TAG, "addNote, set continue note success")
739        routePage()
740        AppStorage.SetOrCreate('isUpdate', true)
741      })
742      .visibility(this.longpress || this.selectedFolderData.uuid == SysDefFolderUuid.RecentDeletes ? Visibility.None : Visibility.Visible)
743  }
744}
745
746@Component
747export struct SearchComp {
748  @Consume('Search') search: boolean
749  @Consume('InputKeyword') inputKeyword: string
750  @Consume('Longpress') longpress: boolean
751  @State text: string = ''
752  @StorageLink('isFocusOnSearch') isFocusOnSearch: boolean = true
753
754  build() {
755    Row() {
756      Image($r('app.media.back'))
757        .width(24)
758        .height(24)
759        .responseRegion({ x: -15.0, y: -15.0, width: 54, height: 54 })
760        .margin({ right: this.search ? 16 : 0 })
761        .visibility(this.search ? Visibility.Visible : Visibility.None)
762        .onClick(() => {
763          focusControl.requestFocus('searchFocus')
764          this.search = false
765          // 退出键盘
766          // @ts-ignore
767          inputMethod.getController().stopInputSession();
768          AppStorage.SetOrCreate<boolean>('Search', this.search)
769        })
770
771      Flex({ justifyContent: FlexAlign.Start }) {
772        Image($r('app.media.search')).width(20).height(20)
773          .focusable(true)
774          .key('searchFocus')
775          .defaultFocus(true)
776        TextInput({ placeholder: $r('app.string.searchNote'), text: this.text })
777          .backgroundColor(this.longpress ? $r("app.color.search_longpress_bgcolor_f7f8f9") : $r("app.color.color_ffffff"))
778          .caretColor($r("app.color.search_note_caret_color"))
779          .enabled(this.longpress ? false : true)
780          .padding({ left: 6, top: 1 })
781          .padding({ left: 6 })
782          .onEditChange((isEditing: boolean) => {
783            //            this.search = isEditing
784          })
785          .onChange((value: string) => {
786            if (!this.longpress) {
787              LogUtil.info(TAG, "Search value: " + value)
788              this.text = value
789              this.inputKeyword = value
790            }
791          })
792          .onClick(() => {
793            if (this.longpress) {
794              this.search = false
795              AppStorage.SetOrCreate<boolean>('Search', this.search)
796            } else {
797              this.search = true
798              AppStorage.SetOrCreate<boolean>('Search', this.search)
799            }
800          })
801            // whether the focus is on the search input before coutinue
802          .onFocus(() => {
803            this.isFocusOnSearch = true
804          })
805          .onBlur(() => {
806            this.isFocusOnSearch = false
807          })
808            // key for request focus after coutinue
809          .key('searchInput')
810          .restoreId(3)
811      }
812      .backgroundColor(this.longpress ? $r("app.color.search_longpress_bgcolor_f7f8f9") : $r("app.color.color_ffffff"))
813      .height(40)
814      .opacity(this.longpress ? 0.4 : 1)
815      .padding({ left: 6, right: 12, top: 9, bottom: 9 })
816      .borderRadius(20)
817      .border({ width: 1.5, color: $r("app.color.divider_color_e4e4e4") })
818      .margin({ right: this.search ? 40 : 0 })
819    }
820  }
821}
822
823@Component
824export struct OperateNoteCompForPortrait {
825  @Consume('Longpress') longpress: boolean
826  @StorageLink('CheckedNoteArray') CheckedNoteArray: NoteData[] = []
827  @StorageLink('AllNoteArray') AllNoteArray: NoteData[] = AppStorage.Link('AllNoteArray')
828  @Consume('SelectedFolderData') selectedFolderData: FolderData
829  @Consume('RefreshFlag') @Watch('opacityChange') refreshFlag: number
830  @Consume('SelectedNoteData') selectedNoteData: NoteData
831  @Consume('PortraitModel') portraitModel: boolean
832  @State greyOpacity: boolean = false
833  @StorageLink('isUpdate') isUpdate: boolean = false
834  noteDataMoveDialogCtlBottom: CustomDialogController = new CustomDialogController({
835    builder: NoteDataMoveDialog({ onConfirm: this.onMoveConfirm.bind(this) }),
836    alignment: DialogAlignment.Bottom,
837    autoCancel: false,
838    customStyle: true,
839  })
840
841  opacityChange() {
842    if (this.CheckedNoteArray.length == 0 && this.longpress == true) {
843      this.greyOpacity = true
844      LogUtil.info(TAG, "none checked array")
845    } else {
846      this.greyOpacity = false
847      LogUtil.info(TAG, this.CheckedNoteArray.length.toString())
848    }
849  }
850
851  onMoveConfirm(folderUuid: string) {
852    this.CheckedNoteArray.forEach((noteItem) => {
853      noteItem.folder_uuid = folderUuid
854      // update note to db
855      let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable)
856      predicates_note.equalTo(NoteTableColumn.Uuid, noteItem.uuid)
857      RdbStoreUtil.update(noteItem.toNoteObject(), predicates_note, null)
858    })
859    this.selectedNoteData = NoteUtil.getFirstNoteData(this.AllNoteArray, this.selectedFolderData.uuid)
860    // save continue data
861    let continueNote: string = JSON.stringify(this.selectedNoteData.toNoteObject())
862    AppStorage.SetOrCreate<string>('ContinueNote', continueNote)
863    LogUtil.info(TAG, "onMoveConfirm, set continue note success")
864    this.longpress = false
865    this.refreshFlag = (this.refreshFlag == 0 ? 1 : 0)
866    NoteUtil.unsetAllNotesChecked(this.CheckedNoteArray)
867    NoteUtil.refreshAll()
868  }
869
870  noteDataDeleteDialogCtlBottom: CustomDialogController = new CustomDialogController({
871    builder: DeleteDialog({ onConfirm: this.onDeleteConfirm.bind(this), multiSelect: true }),
872    alignment: DialogAlignment.Bottom,
873    autoCancel: false,
874    customStyle: true,
875  })
876
877  onDeleteConfirm() {
878    if (this.selectedFolderData.uuid != SysDefFolderUuid.RecentDeletes) {
879      this.CheckedNoteArray.forEach((noteItem: NoteData) => {
880        noteItem.is_deleted = Delete.Yes
881        noteItem.deleted_time = new Date().getTime()
882        // update note to db
883        let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable)
884        predicates_note.equalTo(NoteTableColumn.Uuid, noteItem.uuid)
885        RdbStoreUtil.update(noteItem.toNoteObject(), predicates_note, null)
886      })
887    } else {
888      this.CheckedNoteArray.forEach((noteItem: NoteData) => {
889        NoteUtil.removeNoteData(this.AllNoteArray, noteItem.uuid)
890        // delete note from db
891        let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable)
892        predicates_note.equalTo(NoteTableColumn.Uuid, noteItem.uuid)
893        RdbStoreUtil.delete(predicates_note, null)
894      })
895    }
896    NoteUtil.unsetAllNotesChecked(this.CheckedNoteArray)
897    this.longpress = false
898    this.refreshFlag = (this.refreshFlag == 0 ? 1 : 0)
899    this.selectedNoteData = NoteUtil.getFirstNoteData(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid)
900    // save continue data
901    let continueNote: string = JSON.stringify(this.selectedNoteData.toNoteObject())
902    AppStorage.SetOrCreate<string>('ContinueNote', continueNote)
903    LogUtil.info(TAG, "OperateNoteCompForPortrait, set continue note success")
904    NoteUtil.refreshAll()
905  }
906
907  build() {
908    Row() {
909      if (this.selectedFolderData.uuid != SysDefFolderUuid.RecentDeletes) {
910        Column() {
911          Image($r("app.media.set_top"))
912            .opacity(this.greyOpacity ? 0.4 : 1)
913            .width(24)
914            .height(24)
915            .responseRegion({ x: -15.0, y: -15.0, width: 54, height: 54 })
916            .onClick(() => {
917              this.CheckedNoteArray.forEach((noteItem) => {
918                noteItem.is_top = (noteItem.is_top == Top.Yes) ? Top.No : Top.Yes
919                // update note to db
920                let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable)
921                predicates_note.equalTo(NoteTableColumn.Uuid, noteItem.uuid)
922                RdbStoreUtil.update(noteItem.toNoteObject(), predicates_note, null)
923              })
924              this.longpress = false
925              this.refreshFlag = (this.refreshFlag == 0 ? 1 : 0)
926              NoteUtil.unsetAllNotesChecked(this.CheckedNoteArray)
927              NoteUtil.refreshAll()
928            })
929          Text($r("app.string.set_top"))
930            .opacity(this.greyOpacity ? 0.4 : 1)
931            .fontSize(10)
932            .fontColor($r("app.color.set_top_font_color"))
933            .padding({ top: 5 })
934        }
935        .width("25%")
936        .height("100%")
937        .opacity(this.greyOpacity ? 0.4 : 1)
938        .enabled(this.greyOpacity ? false : true)
939        .alignItems(HorizontalAlign.Center)
940        .justifyContent(FlexAlign.Center)
941      }
942
943      Column() {
944        Image($r('app.media.delete'))
945          .opacity(this.greyOpacity ? 0.4 : 1)
946          .width(24)
947          .height(24)
948          .responseRegion({ x: -15.0, y: -15.0, width: 54, height: 54 })
949          .onClick(() => {
950            this.noteDataDeleteDialogCtlBottom.open()
951            AppStorage.SetOrCreate('isUpdate', true)
952          })
953        Text($r("app.string.delete"))
954          .opacity(this.greyOpacity ? 0.4 : 1)
955          .fontSize(10)
956          .fontColor($r("app.color.delete_font_color"))
957          .padding({ top: 5 })
958      }
959      .width(this.selectedFolderData.uuid == SysDefFolderUuid.RecentDeletes ? 120 : "25%")
960      .height("100%")
961      .opacity(this.greyOpacity ? 0.4 : 1)
962      .enabled(this.greyOpacity ? false : true)
963      .alignItems(HorizontalAlign.Center)
964      .justifyContent(FlexAlign.Center)
965
966      if (this.selectedFolderData.uuid != SysDefFolderUuid.RecentDeletes) {
967        Column() {
968          Image($r('app.media.move'))
969            .opacity(this.greyOpacity ? 0.4 : 1)
970            .width(24)
971            .height(24)
972            .responseRegion({ x: -15.0, y: -15.0, width: 54, height: 54 })
973            .onClick(() => {
974              this.noteDataMoveDialogCtlBottom.open()
975              AppStorage.SetOrCreate('isUpdate', true)
976            })
977          Text($r("app.string.move"))
978            .opacity(this.greyOpacity ? 0.4 : 1)
979            .fontSize(10)
980            .fontColor($r("app.color.move_font_color"))
981            .padding({ top: 5 })
982        }
983        .width("25%")
984        .height("100%")
985        .opacity(this.greyOpacity ? 0.4 : 1)
986        .enabled(this.greyOpacity ? false : true)
987        .alignItems(HorizontalAlign.Center)
988        .justifyContent(FlexAlign.Center)
989      }
990
991
992      if (this.selectedFolderData.uuid == SysDefFolderUuid.RecentDeletes) {
993        Column() {
994          Image($r('app.media.recover'))
995            .width(24)
996            .height(24)
997            .responseRegion({ x: -15.0, y: -15.0, width: 54, height: 54 })
998            .onClick(() => {
999              this.CheckedNoteArray.forEach((noteItem) => {
1000                noteItem.is_deleted = Delete.No
1001                noteItem.deleted_time = 0
1002                let context: any = getContext(this)
1003                let resource = {
1004                  bundleName: "com.ohos.note",
1005                  moduleName: "default",
1006                  id: $r('app.string.restore').id
1007                };
1008                context.resourceManager.getString(resource, (error, value) => {
1009                  if (error != null) {
1010                    console.log("error is " + error);
1011                  } else {
1012                    prompt.showToast({ message: value, duration: 2000 });
1013                  }
1014                });
1015                // update note to db
1016                let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable)
1017                predicates_note.equalTo(NoteTableColumn.Uuid, noteItem.uuid)
1018                RdbStoreUtil.update(noteItem.toNoteObject(), predicates_note, null)
1019              })
1020              this.longpress = false
1021              NoteUtil.unsetAllNotesChecked(this.CheckedNoteArray)
1022              this.refreshFlag = (this.refreshFlag == 0 ? 1 : 0)
1023              AppStorage.SetOrCreate('isUpdate', true)
1024              NoteUtil.refreshAll()
1025            })
1026          Text($r("app.string.recover"))
1027            .fontSize(10)
1028            .fontColor($r("app.color.recover_font_color"))
1029            .padding({ top: 5 })
1030        }
1031        .width(this.selectedFolderData.uuid == SysDefFolderUuid.RecentDeletes ? 120 : "25%")
1032        .height("100%")
1033        .opacity(this.greyOpacity ? 0.4 : 1)
1034        .enabled(this.greyOpacity ? false : true)
1035        .alignItems(HorizontalAlign.Center)
1036        .justifyContent(FlexAlign.Center)
1037      }
1038
1039      Column() {
1040        Image($r('app.media.check_all'))
1041          .width(24)
1042          .height(24)
1043          .responseRegion({ x: -15.0, y: -15.0, width: 54, height: 54 })
1044          .id(this.isUpdate + '')
1045          .onClick(() => {
1046            if (this.CheckedNoteArray.length <
1047            NoteUtil.getNoteDataArray(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid)
1048              .length) {
1049              NoteUtil.setAllNotesChecked(this.CheckedNoteArray, NoteUtil.getNoteDataArray(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid))
1050            } else {
1051              NoteUtil.unsetAllNotesChecked(this.CheckedNoteArray)
1052            }
1053            this.refreshFlag = (this.refreshFlag == 0 ? 1 : 0)
1054            NoteUtil.refreshAll()
1055          })
1056        Text($r("app.string.check_all"))
1057          .fontSize(10)
1058          .fontColor($r("app.color.check_all_font_color"))
1059          .padding({ top: 5 })
1060      }
1061      .width(this.selectedFolderData.uuid == SysDefFolderUuid.RecentDeletes ? 120 : "25%")
1062      .height("100%")
1063      .alignItems(HorizontalAlign.Center)
1064      .justifyContent(FlexAlign.Center)
1065    }
1066    .justifyContent(FlexAlign.Center)
1067    .width("100%")
1068    .height(56)
1069    .visibility(this.longpress && this.portraitModel == true ? Visibility.Visible : Visibility.None)
1070  }
1071}
1072