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