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 .visibility((FolderUtil.getNoteCount(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid) == 0) ? Visibility.None : Visibility.Visible) 493 }, noteItem => JSON.stringify(noteItem)) 494 } 495 .id(this.isUpdate + '') 496 .margin((FolderUtil.getNoteCount(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid) == 0) ? { 497 bottom: 0 498 } : { 499 bottom: 56 500 }) 501 .layoutWeight(1) 502 .listDirection(Axis.Vertical) 503 .edgeEffect(EdgeEffect.Spring) 504 } 505 .layoutWeight(1) 506 .height("100%") 507 .margin({ top: this.search ? 8 : 0 }) 508 } 509 .height("100%") 510 .width("100%") 511 512 // search input mask 513 Column() { 514 } 515 .height("100%") 516 .width("100%") 517 .backgroundColor("#18181A") 518 .opacity(0.1) 519 .visibility(this.search ? Visibility.Visible : Visibility.Hidden) 520 } 521 } 522 .onClick(() => { 523 this.search = false 524 inputMethod.getController().stopInputSession() 525 AppStorage.SetOrCreate<boolean>('Search', this.search) 526 }) 527 } 528} 529 530@Component 531export struct OperateNoteComp { 532 @Consume('Longpress') longpress: boolean 533 @StorageLink('CheckedNoteArray') CheckedNoteArray: NoteData[] = [] 534 @StorageLink('AllNoteArray') AllNoteArray: NoteData[] = AppStorage.Link('AllNoteArray') 535 @Consume('SelectedFolderData') selectedFolderData: FolderData 536 @Consume('RefreshFlag') refreshFlag: number 537 @Consume('SelectedNoteData') selectedNoteData: NoteData 538 @Consume('PortraitModel') portraitModel: boolean 539 @Consume('selectedAll') selectedAll: boolean 540 @StorageLink('isUpdate') isUpdate: boolean = false 541 controllerShow: WebviewController 542 noteDataMoveDialogCtl: CustomDialogController = new CustomDialogController({ 543 builder: NoteDataMoveDialog({ onConfirm: this.onMoveConfirm.bind(this) }), 544 alignment: DialogAlignment.Center, 545 autoCancel: false, 546 customStyle: true, 547 }) 548 549 onMoveConfirm(folderUuid: string) { 550 this.CheckedNoteArray.forEach((noteItem) => { 551 noteItem.folder_uuid = folderUuid 552 // update note to db 553 let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable) 554 predicates_note.equalTo(NoteTableColumn.Uuid, noteItem.uuid) 555 RdbStoreUtil.update(noteItem.toNoteObject(), predicates_note, null) 556 }) 557 this.selectedNoteData = NoteUtil.getFirstNoteData(this.AllNoteArray, this.selectedFolderData.uuid) 558 // save continue data 559 let continueNote: string = JSON.stringify(this.selectedNoteData?.toNoteObject()) 560 AppStorage.SetOrCreate<string>('ContinueNote', continueNote) 561 LogUtil.info(TAG, "onMoveConfirm, set continue note success") 562 if (this.portraitModel == false) { 563 this.controllerShow.runJavaScript("RICH_EDITOR.setHtml('" + this.selectedNoteData?.content_text + "')") 564 } 565 this.longpress = false 566 this.refreshFlag = (this.refreshFlag == 0 ? 1 : 0) 567 NoteUtil.unsetAllNotesChecked(this.CheckedNoteArray) 568 NoteUtil.refreshAll() 569 } 570 571 noteDataDeleteDialogCtl: CustomDialogController = new CustomDialogController({ 572 builder: DeleteDialog({ onConfirm: this.onDeleteConfirm.bind(this), multiSelect: true }), 573 alignment: DialogAlignment.Center, 574 autoCancel: false, 575 customStyle: true, 576 }) 577 578 onDeleteConfirm() { 579 if (this.selectedFolderData.uuid != SysDefFolderUuid.RecentDeletes) { 580 this.CheckedNoteArray.forEach((noteItem: NoteData) => { 581 noteItem.is_deleted = Delete.Yes 582 noteItem.deleted_time = new Date().getTime() 583 // update note to db 584 let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable) 585 predicates_note.equalTo(NoteTableColumn.Uuid, noteItem.uuid) 586 RdbStoreUtil.update(noteItem.toNoteObject(), predicates_note, null) 587 }) 588 } else { 589 this.CheckedNoteArray.forEach((noteItem: NoteData) => { 590 NoteUtil.removeNoteData(this.AllNoteArray, noteItem.uuid) 591 // delete note from db 592 let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable) 593 predicates_note.equalTo(NoteTableColumn.Uuid, noteItem.uuid) 594 RdbStoreUtil.delete(predicates_note, null) 595 }) 596 } 597 NoteUtil.unsetAllNotesChecked(this.CheckedNoteArray) 598 this.refreshFlag = (this.refreshFlag == 0 ? 1 : 0) 599 this.longpress = false 600 this.selectedNoteData = NoteUtil.getFirstNoteData(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid) 601 if (this.portraitModel == false) { 602 this.controllerShow.runJavaScript("RICH_EDITOR.setHtml('" + this.selectedNoteData?.content_text + "')") 603 } 604 // save continue data 605 let continueNote: string = JSON.stringify(this.selectedNoteData?.toNoteObject()) 606 AppStorage.SetOrCreate<string>('ContinueNote', continueNote) 607 LogUtil.info(TAG, "OperateNoteComp, set continue note success") 608 NoteUtil.refreshAll() 609 } 610 611 build() { 612 Row() { 613 Image($r('app.media.set_top')) 614 .width(24) 615 .height(24) 616 .opacity(this.CheckedNoteArray.length == 0 ? 0.4 : 1) 617 .enabled(this.CheckedNoteArray.length == 0 ? false : true) 618 .margin({ right: this.selectedFolderData.uuid == SysDefFolderUuid.RecentDeletes ? 0 : 18 }) 619 .visibility(this.selectedFolderData.uuid == SysDefFolderUuid.RecentDeletes ? Visibility.None : Visibility.Visible) 620 .onClick(() => { 621 this.CheckedNoteArray.forEach((noteItem) => { 622 noteItem.is_top = (noteItem.is_top == Top.Yes) ? Top.No : Top.Yes 623 // update note to db 624 let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable) 625 predicates_note.equalTo(NoteTableColumn.Uuid, noteItem.uuid) 626 RdbStoreUtil.update(noteItem.toNoteObject(), predicates_note, null) 627 }) 628 this.longpress = false 629 NoteUtil.unsetAllNotesChecked(this.CheckedNoteArray) 630 NoteUtil.refreshAll() 631 }) 632 Image($r('app.media.move')) 633 .width(24) 634 .height(24) 635 .opacity(this.CheckedNoteArray.length == 0 ? 0.4 : 1) 636 .enabled(this.CheckedNoteArray.length == 0 ? false : true) 637 .margin({ right: this.selectedFolderData.uuid == SysDefFolderUuid.RecentDeletes ? 0 : 18 }) 638 .visibility(this.selectedFolderData.uuid == SysDefFolderUuid.RecentDeletes ? Visibility.None : Visibility.Visible) 639 .onClick(() => { 640 this.noteDataMoveDialogCtl.open() 641 }) 642 Image($r('app.media.delete')) 643 .width(24) 644 .height(24) 645 .margin({ right: 18 }) 646 .opacity(this.CheckedNoteArray.length == 0 ? 0.4 : 1) 647 .enabled(this.CheckedNoteArray.length == 0 ? false : true) 648 .onClick(() => { 649 this.noteDataDeleteDialogCtl.open() 650 }) 651 Image($r('app.media.recover')) 652 .width(24) 653 .height(24) 654 .opacity(this.CheckedNoteArray.length == 0 ? 0.4 : 1) 655 .enabled(this.CheckedNoteArray.length == 0 ? false : true) 656 .margin({ right: this.selectedFolderData.uuid == SysDefFolderUuid.RecentDeletes ? 18 : 0 }) 657 .visibility(this.selectedFolderData.uuid == SysDefFolderUuid.RecentDeletes ? Visibility.Visible : Visibility.None) 658 .onClick(() => { 659 this.CheckedNoteArray.forEach((noteItem) => { 660 noteItem.is_deleted = Delete.No 661 noteItem.deleted_time = 0 662 let context: any = getContext(this) 663 let resource = { 664 bundleName: "com.ohos.note", 665 moduleName: "default", 666 id: $r('app.string.restore').id 667 }; 668 context.resourceManager.getString(resource, (error, value) => { 669 if (error != null) { 670 console.log("error is " + error); 671 } else { 672 prompt.showToast({ message: value, duration: 2000 }); 673 } 674 }); 675 // update note to db 676 let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable) 677 predicates_note.equalTo(NoteTableColumn.Uuid, noteItem.uuid) 678 RdbStoreUtil.update(noteItem.toNoteObject(), predicates_note, null) 679 }) 680 this.longpress = false 681 NoteUtil.unsetAllNotesChecked(this.CheckedNoteArray) 682 NoteUtil.refreshAll() 683 }) 684 Image(this.CheckedNoteArray.length == NoteUtil.getNoteDataArray(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid) 685 .length ? $r('app.media.check_all1') : $r('app.media.check_all')) 686 .width(24) 687 .height(24) 688 .id(this.isUpdate + '') 689 .onClick(() => { 690 LogUtil.info(TAG, "select all click") 691 if (this.CheckedNoteArray.length < 692 NoteUtil.getNoteDataArray(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid).length) { 693 NoteUtil.setAllNotesChecked(this.CheckedNoteArray, NoteUtil.getNoteDataArray(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid)) 694 } else { 695 NoteUtil.unsetAllNotesChecked(this.CheckedNoteArray) 696 } 697 this.selectedAll = !this.selectedAll 698 this.refreshFlag = (this.refreshFlag == 0 ? 1 : 0) 699 NoteUtil.refreshAll() 700 }) 701 } 702 .width(this.selectedFolderData.uuid == SysDefFolderUuid.RecentDeletes ? 168 : 248) 703 .visibility(this.longpress && this.portraitModel == false ? Visibility.Visible : Visibility.None) 704 } 705} 706 707@Component 708export struct AddNoteComp { 709 @StorageLink('AllNoteArray') AllNoteArray: NoteData[] = AppStorage.Link('AllNoteArray') 710 @Consume('Longpress') longpress: boolean 711 @Consume('SelectedFolderData') selectedFolderData: FolderData 712 @Consume('SelectedNoteData') selectedNoteData: NoteData 713 @Consume('SectionStatus') sectionStatus: number 714 @Consume('LastSectionStatus') lastSectionStatus: number 715 @Consume('EditModel') editModel: boolean 716 @Consume('ChooseNote') chooseNote: boolean 717 @Consume('PortraitModel') portraitModel: boolean 718 controllerShow: WebviewController 719 720 build() { 721 Image($r('app.media.addNote')) 722 .width(24) 723 .height(24) 724 .margin({ right: 12 }) 725 .responseRegion({ x: -15.0, y: -15.0, width: 54, height: 54 }) 726 .onClick(() => { 727 let noteData 728 if (this.selectedFolderData.uuid == SysDefFolderUuid.AllNotes || this.selectedFolderData.uuid == SysDefFolderUuid.MyFavorites) { 729 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) 730 } else { 731 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) 732 } 733 734 this.AllNoteArray.push(noteData) 735 RdbStoreUtil.insert(TableName.NoteTable, noteData.toNoteObject(), null) 736 LogUtil.info(TAG, 'insert new note is:' + noteData.uuid) 737 738 this.selectedNoteData = noteData 739 AppStorage.SetOrCreate<NoteData>('NewNote', noteData) 740 if (this.portraitModel == false) { 741 this.controllerShow.runJavaScript( 742 "RICH_EDITOR.setHtml('" + this.selectedNoteData?.content_text + "')" 743 ) 744 } 745 if (this.portraitModel == true) { 746 this.editModel = true 747 } 748 this.chooseNote = true 749 // save continue data 750 let continueNote: string = JSON.stringify(this.selectedNoteData?.toNoteObject()) 751 AppStorage.SetOrCreate<FolderData>('NewFolder', this.selectedFolderData) 752 AppStorage.SetOrCreate<string>('ContinueNote', continueNote) 753 LogUtil.info(TAG, "addNote, set continue note success") 754 routePage() 755 AppStorage.SetOrCreate('isUpdate', true) 756 }) 757 .visibility(this.longpress || this.selectedFolderData.uuid == SysDefFolderUuid.RecentDeletes ? Visibility.None : Visibility.Visible) 758 } 759} 760 761@Component 762export struct SearchComp { 763 @Consume('Search') search: boolean 764 @Consume('InputKeyword') inputKeyword: string 765 @Consume('Longpress') longpress: boolean 766 @State text: string = '' 767 @StorageLink('isFocusOnSearch') isFocusOnSearch: boolean = true 768 769 build() { 770 Row() { 771 Image($r('app.media.back')) 772 .width(24) 773 .height(24) 774 .responseRegion({ x: -15.0, y: -15.0, width: 54, height: 54 }) 775 .margin({ right: this.search ? 16 : 0 }) 776 .visibility(this.search ? Visibility.Visible : Visibility.None) 777 .onClick(() => { 778 focusControl.requestFocus('searchFocus') 779 this.search = false 780 // 退出键盘 781 // @ts-ignore 782 inputMethod.getController().stopInputSession(); 783 AppStorage.SetOrCreate<boolean>('Search', this.search) 784 }) 785 786 Flex({ justifyContent: FlexAlign.Start }) { 787 Image($r('app.media.search')) 788 .width(20) 789 .height(20) 790 .focusable(true) 791 .key('searchFocus') 792 .defaultFocus(true) 793 TextInput({ placeholder: $r('app.string.searchNote'), text: this.text }) 794 .backgroundColor(this.longpress ? $r("app.color.search_longpress_bgcolor_f7f8f9") : $r("app.color.color_ffffff")) 795 .caretColor($r("app.color.search_note_caret_color")) 796 .enabled(this.longpress ? false : true) 797 .padding({ left: 6, top: 1 }) 798 .onEditChange((isEditing: boolean) => { 799 // this.search = isEditing 800 }) 801 .onChange((value: string) => { 802 if (!this.longpress) { 803 LogUtil.info(TAG, "Search value: " + value) 804 this.text = value 805 this.inputKeyword = value 806 } 807 }) 808 .onClick(() => { 809 if (this.longpress) { 810 this.search = false 811 AppStorage.SetOrCreate<boolean>('Search', this.search) 812 } else { 813 this.search = true 814 AppStorage.SetOrCreate<boolean>('Search', this.search) 815 } 816 }) 817 // whether the focus is on the search input before coutinue 818 .onFocus(() => { 819 this.isFocusOnSearch = true 820 }) 821 .onBlur(() => { 822 this.isFocusOnSearch = false 823 }) 824 // key for request focus after coutinue 825 .key('searchInput') 826 .restoreId(3) 827 } 828 .backgroundColor(this.longpress ? $r("app.color.search_longpress_bgcolor_f7f8f9") : $r("app.color.color_ffffff")) 829 .height(40) 830 .opacity(this.longpress ? 0.4 : 1) 831 .padding({ left: 6, right: 12, top: 9, bottom: 9 }) 832 .borderRadius(20) 833 .border({ width: 1.5, color: $r("app.color.divider_color_e4e4e4") }) 834 .margin({ right: this.search ? 40 : 0 }) 835 } 836 } 837} 838 839@Component 840export struct OperateNoteCompForPortrait { 841 @Consume('Longpress') longpress: boolean 842 @StorageLink('CheckedNoteArray') CheckedNoteArray: NoteData[] = [] 843 @StorageLink('AllNoteArray') AllNoteArray: NoteData[] = AppStorage.Link('AllNoteArray') 844 @Consume('SelectedFolderData') selectedFolderData: FolderData 845 @Consume('RefreshFlag') @Watch('opacityChange') refreshFlag: number 846 @Consume('SelectedNoteData') selectedNoteData: NoteData 847 @Consume('PortraitModel') portraitModel: boolean 848 @State greyOpacity: boolean = false 849 @StorageLink('isUpdate') isUpdate: boolean = false 850 noteDataMoveDialogCtlBottom: CustomDialogController = new CustomDialogController({ 851 builder: NoteDataMoveDialog({ onConfirm: this.onMoveConfirm.bind(this) }), 852 alignment: DialogAlignment.Bottom, 853 autoCancel: false, 854 customStyle: true, 855 }) 856 857 opacityChange() { 858 if (this.CheckedNoteArray.length == 0 && this.longpress == true) { 859 this.greyOpacity = true 860 LogUtil.info(TAG, "none checked array") 861 } else { 862 this.greyOpacity = false 863 LogUtil.info(TAG, this.CheckedNoteArray.length.toString()) 864 } 865 } 866 867 onMoveConfirm(folderUuid: string) { 868 this.CheckedNoteArray.forEach((noteItem) => { 869 noteItem.folder_uuid = folderUuid 870 // update note to db 871 let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable) 872 predicates_note.equalTo(NoteTableColumn.Uuid, noteItem.uuid) 873 RdbStoreUtil.update(noteItem.toNoteObject(), predicates_note, null) 874 }) 875 this.selectedNoteData = NoteUtil.getFirstNoteData(this.AllNoteArray, this.selectedFolderData.uuid) 876 // save continue data 877 let continueNote: string = JSON.stringify(this.selectedNoteData?.toNoteObject()) 878 AppStorage.SetOrCreate<string>('ContinueNote', continueNote) 879 LogUtil.info(TAG, "onMoveConfirm, set continue note success") 880 this.longpress = false 881 this.refreshFlag = (this.refreshFlag == 0 ? 1 : 0) 882 NoteUtil.unsetAllNotesChecked(this.CheckedNoteArray) 883 NoteUtil.refreshAll() 884 } 885 886 noteDataDeleteDialogCtlBottom: CustomDialogController = new CustomDialogController({ 887 builder: DeleteDialog({ onConfirm: this.onDeleteConfirm.bind(this), multiSelect: true }), 888 alignment: DialogAlignment.Bottom, 889 autoCancel: false, 890 customStyle: true, 891 }) 892 893 onDeleteConfirm() { 894 if (this.selectedFolderData.uuid != SysDefFolderUuid.RecentDeletes) { 895 this.CheckedNoteArray.forEach((noteItem: NoteData) => { 896 noteItem.is_deleted = Delete.Yes 897 noteItem.deleted_time = new Date().getTime() 898 // update note to db 899 let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable) 900 predicates_note.equalTo(NoteTableColumn.Uuid, noteItem.uuid) 901 RdbStoreUtil.update(noteItem.toNoteObject(), predicates_note, null) 902 }) 903 } else { 904 this.CheckedNoteArray.forEach((noteItem: NoteData) => { 905 NoteUtil.removeNoteData(this.AllNoteArray, noteItem.uuid) 906 // delete note from db 907 let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable) 908 predicates_note.equalTo(NoteTableColumn.Uuid, noteItem.uuid) 909 RdbStoreUtil.delete(predicates_note, null) 910 }) 911 } 912 NoteUtil.unsetAllNotesChecked(this.CheckedNoteArray) 913 this.longpress = false 914 this.refreshFlag = (this.refreshFlag == 0 ? 1 : 0) 915 this.selectedNoteData = NoteUtil.getFirstNoteData(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid) 916 // save continue data 917 let continueNote: string = JSON.stringify(this.selectedNoteData?.toNoteObject()) 918 AppStorage.SetOrCreate<string>('ContinueNote', continueNote) 919 LogUtil.info(TAG, "OperateNoteCompForPortrait, set continue note success") 920 NoteUtil.refreshAll() 921 } 922 923 build() { 924 Row() { 925 if (this.selectedFolderData.uuid != SysDefFolderUuid.RecentDeletes) { 926 Column() { 927 Image($r("app.media.set_top")) 928 .opacity(this.greyOpacity ? 0.4 : 1) 929 .width(24) 930 .height(24) 931 .responseRegion({ x: -15.0, y: -15.0, width: 54, height: 54 }) 932 .onClick(() => { 933 this.CheckedNoteArray.forEach((noteItem) => { 934 noteItem.is_top = (noteItem.is_top == Top.Yes) ? Top.No : Top.Yes 935 // update note to db 936 let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable) 937 predicates_note.equalTo(NoteTableColumn.Uuid, noteItem.uuid) 938 RdbStoreUtil.update(noteItem.toNoteObject(), predicates_note, null) 939 }) 940 this.longpress = false 941 this.refreshFlag = (this.refreshFlag == 0 ? 1 : 0) 942 NoteUtil.unsetAllNotesChecked(this.CheckedNoteArray) 943 NoteUtil.refreshAll() 944 }) 945 Text($r("app.string.set_top")) 946 .opacity(this.greyOpacity ? 0.4 : 1) 947 .fontSize(10) 948 .fontColor($r("app.color.set_top_font_color")) 949 .padding({ top: 5 }) 950 } 951 .width("25%") 952 .height("100%") 953 .opacity(this.greyOpacity ? 0.4 : 1) 954 .enabled(this.greyOpacity ? false : true) 955 .alignItems(HorizontalAlign.Center) 956 .justifyContent(FlexAlign.Center) 957 } 958 959 Column() { 960 Image($r('app.media.delete')) 961 .opacity(this.greyOpacity ? 0.4 : 1) 962 .width(24) 963 .height(24) 964 .responseRegion({ x: -15.0, y: -15.0, width: 54, height: 54 }) 965 .onClick(() => { 966 this.noteDataDeleteDialogCtlBottom.open() 967 AppStorage.SetOrCreate('isUpdate', true) 968 }) 969 Text($r("app.string.delete")) 970 .opacity(this.greyOpacity ? 0.4 : 1) 971 .fontSize(10) 972 .fontColor($r("app.color.delete_font_color")) 973 .padding({ top: 5 }) 974 } 975 .width(this.selectedFolderData.uuid == SysDefFolderUuid.RecentDeletes ? 120 : "25%") 976 .height("100%") 977 .opacity(this.greyOpacity ? 0.4 : 1) 978 .enabled(this.greyOpacity ? false : true) 979 .alignItems(HorizontalAlign.Center) 980 .justifyContent(FlexAlign.Center) 981 982 if (this.selectedFolderData.uuid != SysDefFolderUuid.RecentDeletes) { 983 Column() { 984 Image($r('app.media.move')) 985 .opacity(this.greyOpacity ? 0.4 : 1) 986 .width(24) 987 .height(24) 988 .responseRegion({ x: -15.0, y: -15.0, width: 54, height: 54 }) 989 .onClick(() => { 990 this.noteDataMoveDialogCtlBottom.open() 991 AppStorage.SetOrCreate('isUpdate', true) 992 }) 993 Text($r("app.string.move")) 994 .opacity(this.greyOpacity ? 0.4 : 1) 995 .fontSize(10) 996 .fontColor($r("app.color.move_font_color")) 997 .padding({ top: 5 }) 998 } 999 .width("25%") 1000 .height("100%") 1001 .opacity(this.greyOpacity ? 0.4 : 1) 1002 .enabled(this.greyOpacity ? false : true) 1003 .alignItems(HorizontalAlign.Center) 1004 .justifyContent(FlexAlign.Center) 1005 } 1006 1007 1008 if (this.selectedFolderData.uuid == SysDefFolderUuid.RecentDeletes) { 1009 Column() { 1010 Image($r('app.media.recover')) 1011 .width(24) 1012 .height(24) 1013 .responseRegion({ x: -15.0, y: -15.0, width: 54, height: 54 }) 1014 .onClick(() => { 1015 this.CheckedNoteArray.forEach((noteItem) => { 1016 noteItem.is_deleted = Delete.No 1017 noteItem.deleted_time = 0 1018 let context: any = getContext(this) 1019 let resource = { 1020 bundleName: "com.ohos.note", 1021 moduleName: "default", 1022 id: $r('app.string.restore').id 1023 }; 1024 context.resourceManager.getString(resource, (error, value) => { 1025 if (error != null) { 1026 console.log("error is " + error); 1027 } else { 1028 prompt.showToast({ message: value, duration: 2000 }); 1029 } 1030 }); 1031 // update note to db 1032 let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable) 1033 predicates_note.equalTo(NoteTableColumn.Uuid, noteItem.uuid) 1034 RdbStoreUtil.update(noteItem.toNoteObject(), predicates_note, null) 1035 }) 1036 this.longpress = false 1037 NoteUtil.unsetAllNotesChecked(this.CheckedNoteArray) 1038 this.refreshFlag = (this.refreshFlag == 0 ? 1 : 0) 1039 AppStorage.SetOrCreate('isUpdate', true) 1040 NoteUtil.refreshAll() 1041 }) 1042 Text($r("app.string.recover")) 1043 .fontSize(10) 1044 .fontColor($r("app.color.recover_font_color")) 1045 .padding({ top: 5 }) 1046 } 1047 .width(this.selectedFolderData.uuid == SysDefFolderUuid.RecentDeletes ? 120 : "25%") 1048 .height("100%") 1049 .opacity(this.greyOpacity ? 0.4 : 1) 1050 .enabled(this.greyOpacity ? false : true) 1051 .alignItems(HorizontalAlign.Center) 1052 .justifyContent(FlexAlign.Center) 1053 } 1054 1055 Column() { 1056 Image($r('app.media.check_all')) 1057 .width(24) 1058 .height(24) 1059 .responseRegion({ x: -15.0, y: -15.0, width: 54, height: 54 }) 1060 .id(this.isUpdate + '') 1061 .onClick(() => { 1062 if (this.CheckedNoteArray.length < 1063 NoteUtil.getNoteDataArray(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid) 1064 .length) { 1065 NoteUtil.setAllNotesChecked(this.CheckedNoteArray, NoteUtil.getNoteDataArray(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid)) 1066 } else { 1067 NoteUtil.unsetAllNotesChecked(this.CheckedNoteArray) 1068 } 1069 this.refreshFlag = (this.refreshFlag == 0 ? 1 : 0) 1070 NoteUtil.refreshAll() 1071 }) 1072 Text($r("app.string.check_all")) 1073 .fontSize(10) 1074 .fontColor($r("app.color.check_all_font_color")) 1075 .padding({ top: 5 }) 1076 } 1077 .width(this.selectedFolderData.uuid == SysDefFolderUuid.RecentDeletes ? 120 : "25%") 1078 .height("100%") 1079 .alignItems(HorizontalAlign.Center) 1080 .justifyContent(FlexAlign.Center) 1081 } 1082 .justifyContent(FlexAlign.Center) 1083 .width("100%") 1084 .height(56) 1085 .visibility(this.longpress && this.portraitModel == true ? Visibility.Visible : Visibility.None) 1086 } 1087} 1088