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