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