From a173c7611dbc2d1e4895d2cf20e9988958e80f3d Mon Sep 17 00:00:00 2001 From: guozejun Date: Tue, 10 May 2022 21:30:09 +0800 Subject: [PATCH 1/2] fix note list layout Signed-off-by: guozejun --- .../src/main/ets/components/NoteListComp.ets | 92 ++++++++++--------- 1 file changed, 49 insertions(+), 43 deletions(-) diff --git a/common/component/src/main/ets/components/NoteListComp.ets b/common/component/src/main/ets/components/NoteListComp.ets index 1626b4e..7b32630 100644 --- a/common/component/src/main/ets/components/NoteListComp.ets +++ b/common/component/src/main/ets/components/NoteListComp.ets @@ -373,59 +373,65 @@ export struct NoteItemListComp { .backgroundColor($r("app.color.notelist_bgcolor_f1f3f5")) .visibility((FolderUtil.getNoteCount(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid) == 0) ? Visibility.None : Visibility.Visible) - Column() { - Flex({ justifyContent: FlexAlign.Center }) { - Text($r("app.string.permanently_delete_tips")) - .fontSize(12) - .fontColor($r("app.color.Recently_delete_prompt_font_color")) - } - .padding({ bottom: this.selectedFolderData.uuid == SysDefFolderUuid.RecentDeletes ? 12 : 0 }) - .backgroundColor($r("app.color.notelist_bgcolor_f1f3f5")) - .width('100%') - .visibility(this.selectedFolderData.uuid == SysDefFolderUuid.RecentDeletes ? Visibility.Visible : Visibility.None) - - Column() { - List({ initialIndex: 0 }) { - ListItem() { - Column({ space: 8 }) { - Image($r('app.media.emptyPage')) - .width(120) - .height(120) - Text($r("app.string.Empty_page")) - .fontSize(12) - .fontColor($r("app.color.Empty_page_font_color")) - } - } - .backgroundColor($r("app.color.notelist_bgcolor_f1f3f5")) - .width('100%') - .height('100%') - .padding({ bottom: 120 }) - .visibility((FolderUtil.getNoteCount(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid) == 0) ? Visibility.Visible : Visibility.None) + Stack() { + Flex({direction: FlexDirection.Column}) { + Flex({ justifyContent: FlexAlign.Center }) { + Text($r("app.string.permanently_delete_tips")) + .fontSize(12) + .fontColor($r("app.color.Recently_delete_prompt_font_color")) + } + .padding({ bottom: this.selectedFolderData.uuid == SysDefFolderUuid.RecentDeletes ? 12 : 0 }) + .backgroundColor($r("app.color.notelist_bgcolor_f1f3f5")) + .width('100%') + .visibility(this.selectedFolderData.uuid == SysDefFolderUuid.RecentDeletes ? Visibility.Visible : Visibility.None) - ForEach(this.inputKeyword.length == 0 ? - NoteUtil.getNoteDataArray(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid) : this.searchResultList, (noteItem) => { + Column() { + List({ initialIndex: 0 }) { ListItem() { - Column() { - NoteItemComp({ - noteItem: noteItem, - spans: SearchModel.splitToHighlightText(noteItem.title, this.inputKeyword), - controllerShow: this.controllerShow - }) + Column({ space: 8 }) { + Image($r('app.media.emptyPage')) + .width(120) + .height(120) + Text($r("app.string.Empty_page")) + .fontSize(12) + .fontColor($r("app.color.Empty_page_font_color")) } - .padding({ left: 24, right: 24, bottom: 12 }) } .backgroundColor($r("app.color.notelist_bgcolor_f1f3f5")) - }, noteItem => noteItem.uuid.toString()) + .width('100%') + .height('100%') + .padding({ bottom: 120 }) + .visibility((FolderUtil.getNoteCount(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid) == 0) ? Visibility.Visible : Visibility.None) + + ForEach(this.inputKeyword.length == 0 ? + NoteUtil.getNoteDataArray(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid) : this.searchResultList, (noteItem) => { + ListItem() { + Column() { + NoteItemComp({ + noteItem: noteItem, + spans: SearchModel.splitToHighlightText(noteItem.title, this.inputKeyword), + controllerShow: this.controllerShow + }) + } + .padding({ left: 24, right: 24, bottom: 12 }) + } + .backgroundColor($r("app.color.notelist_bgcolor_f1f3f5")) + }, noteItem => noteItem.uuid.toString()) + } + .layoutWeight(1) + .backgroundColor($r("app.color.notelist_bgcolor_f1f3f5")) + .listDirection(Axis.Vertical) + .edgeEffect(EdgeEffect.Spring) } .layoutWeight(1) .backgroundColor($r("app.color.notelist_bgcolor_f1f3f5")) - .listDirection(Axis.Vertical) - .edgeEffect(EdgeEffect.Spring) + .height("100%") + .margin({ top: this.search ? 8 : 0 }) } - .backgroundColor($r("app.color.notelist_bgcolor_f1f3f5")) - .flexGrow(1) - .margin({ top: this.search ? 8 : 0 }) + .height("100%") + .width("100%") + // search input mask Column() { } .height("100%") -- Gitee From 864e6a6aaa8da62d1fa50d4dcea016ee6a918e5a Mon Sep 17 00:00:00 2001 From: guozejun Date: Wed, 11 May 2022 21:20:41 +0800 Subject: [PATCH 2/2] fix note cannot start after delete all notes Signed-off-by: guozejun --- .../main/ets/components/NoteContentComp.ets | 320 +++++++++--------- .../main/ets/default/baseUtil/NoteUtil.ets | 4 + .../ets/default/baseUtil/RdbStoreUtil.ets | 10 +- 3 files changed, 172 insertions(+), 162 deletions(-) diff --git a/common/component/src/main/ets/components/NoteContentComp.ets b/common/component/src/main/ets/components/NoteContentComp.ets index 5ebb9da..829506f 100644 --- a/common/component/src/main/ets/components/NoteContentComp.ets +++ b/common/component/src/main/ets/components/NoteContentComp.ets @@ -144,7 +144,7 @@ export struct NoteContentComp { } .margin({ left: 12, right: 24, top: 16 }) .width(StyleConstants.PERCENTAGE_100) - .enabled(this.selectedNoteData.is_deleted == Delete.Yes ? false : true) + .enabled(this.selectedNoteData && this.selectedNoteData.is_deleted == Delete.Yes ? false : true) .onClick(() => { this.issave = 0 LogUtil.info(TAG, "editModel : " + this.editModel + ", sectionStatus : " + this.sectionStatus) @@ -384,183 +384,185 @@ export struct ToolBarComp { AppStorage.SetOrCreate('ContinueSection', this.sectionStatus) LogUtil.info(TAG, "ToolBarComp, set continue section success") }) - .visibility(this.selectedNoteData.is_deleted == Delete.Yes ? Visibility.None : Visibility.Visible) - - if (this.selectedNoteData.is_deleted == Delete.Yes) { - Row({ space: StyleConstants.SPACE_24 }) { - Image($r('app.media.delete')) - .height(24) - .width(24) - .onClick(() => { - this.noteDataDeleteDialogCtl.open() - }) - Image($r('app.media.recover')) - .height(24) - .width(24) - .onClick(() => { - this.selectedNoteData.is_deleted = Delete.No - this.selectedNoteData.deleted_time = 0 - prompt.showToast({ message: "已恢复", duration: 2000 }) - this.refreshFlag = (this.refreshFlag == 0 ? 1 : 0) - this.chooseNote = false - // update note to db - let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable) - predicates_note.equalTo(NoteTableColumn.Uuid, this.selectedNoteData.uuid) - RdbStoreUtil.update(this.selectedNoteData.toNoteObject(), predicates_note, null) + .visibility(!this.selectedNoteData ? Visibility.None : this.selectedNoteData.is_deleted == Delete.Yes ? Visibility.None : Visibility.Visible) - this.selectedNoteData = NoteUtil.getFirstNoteData(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid) - this.controllerShow.runJavaScript({ script: "RICH_EDITOR.setHtml('" + this.selectedNoteData.content_text + "')" }) - // save continue data - let continueNote: string = JSON.stringify(this.selectedNoteData.toNoteObject()) - AppStorage.SetOrCreate('ContinueNote', continueNote) - LogUtil.info(TAG, "recover, set continue note success") - }) - }.width(72) - } else if (this.editModel == true) { - Row({ space: StyleConstants.SPACE_6 }) { - Button({ type: ButtonType.Normal, stateEffect: true }) { - Image($r('app.media.circle_tick1')) + if (this.selectedNoteData) { + if (this.selectedNoteData.is_deleted == Delete.Yes) { + Row({ space: StyleConstants.SPACE_24 }) { + Image($r('app.media.delete')) .height(24) .width(24) .onClick(() => { - // 清单 - this.controllerShow.runJavaScript({ script: "javascript:RICH_EDITOR.setTodo()" }) - // 退出键盘 - inputMethod.getInputMethodController().stopInput(); + this.noteDataDeleteDialogCtl.open() }) - }.width(42) - .height(42) - .borderRadius(8) - .backgroundColor($r('app.color.color_ffffff')) - - Button({ type: ButtonType.Normal, stateEffect: true }) { - Image($r('app.media.styles')) + Image($r('app.media.recover')) .height(24) .width(24) .onClick(() => { - // 退出键盘 - inputMethod.getInputMethodController().stopInput(); - this.editContentDialogCtl.open() + this.selectedNoteData.is_deleted = Delete.No + this.selectedNoteData.deleted_time = 0 + prompt.showToast({ message: "已恢复", duration: 2000 }) + this.refreshFlag = (this.refreshFlag == 0 ? 1 : 0) + this.chooseNote = false + // update note to db + let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable) + predicates_note.equalTo(NoteTableColumn.Uuid, this.selectedNoteData.uuid) + RdbStoreUtil.update(this.selectedNoteData.toNoteObject(), predicates_note, null) + + this.selectedNoteData = NoteUtil.getFirstNoteData(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid) + this.controllerShow.runJavaScript({ script: "RICH_EDITOR.setHtml('" + this.selectedNoteData.content_text + "')" }) + // save continue data + let continueNote: string = JSON.stringify(this.selectedNoteData.toNoteObject()) + AppStorage.SetOrCreate('ContinueNote', continueNote) + LogUtil.info(TAG, "recover, set continue note success") }) - }.width(42) - .height(42) - .borderRadius(8) - .backgroundColor($r('app.color.color_ffffff')) - - Button({ type: ButtonType.Normal, stateEffect: true }) { - Image($r('app.media.picture_white')) - .height(24) - .width(24) - .onClick(async () => { - // 退出键盘 - inputMethod.getInputMethodController().stopInput(); - LogUtil.info(TAG, 'startAbility start') - await globalThis.noteContext.startAbilityForResult({ - parameters: { uri: "singleselect" }, - bundleName: "com.ohos.photos", - abilityName: "com.ohos.photos.MainAbility", + }.width(72) + } else if (this.editModel == true) { + Row({ space: StyleConstants.SPACE_6 }) { + Button({ type: ButtonType.Normal, stateEffect: true }) { + Image($r('app.media.circle_tick1')) + .height(24) + .width(24) + .onClick(() => { + // 清单 + this.controllerShow.runJavaScript({ script: "javascript:RICH_EDITOR.setTodo()" }) + // 退出键盘 + inputMethod.getInputMethodController().stopInput(); }) - .then(v => { - let want = v['want']; - if (want != null && want != undefined) { - let param = want['parameters']; - let imageUri = "" - if (param != null && param != undefined) { - let uri = param['select-item-list']; - imageUri = uri; - } - // 拷贝 - if(imageUri != null && imageUri != "") { - OperationUtils.copy(imageUri).then((uriPath) => { - var path = "file://" + uriPath - LogUtil.info(TAG, 'image uri is:' + path) - this.controllerShow.runJavaScript({script:"javascript:RICH_EDITOR.insertImage('" + path + "')"}) - }) + }.width(42) + .height(42) + .borderRadius(8) + .backgroundColor($r('app.color.color_ffffff')) + + Button({ type: ButtonType.Normal, stateEffect: true }) { + Image($r('app.media.styles')) + .height(24) + .width(24) + .onClick(() => { + // 退出键盘 + inputMethod.getInputMethodController().stopInput(); + this.editContentDialogCtl.open() + }) + }.width(42) + .height(42) + .borderRadius(8) + .backgroundColor($r('app.color.color_ffffff')) + + Button({ type: ButtonType.Normal, stateEffect: true }) { + Image($r('app.media.picture_white')) + .height(24) + .width(24) + .onClick(async () => { + // 退出键盘 + inputMethod.getInputMethodController().stopInput(); + LogUtil.info(TAG, 'startAbility start') + await globalThis.noteContext.startAbilityForResult({ + parameters: { uri: "singleselect" }, + bundleName: "com.ohos.photos", + abilityName: "com.ohos.photos.MainAbility", + }) + .then(v => { + let want = v['want']; + if (want != null && want != undefined) { + let param = want['parameters']; + let imageUri = "" + if (param != null && param != undefined) { + let uri = param['select-item-list']; + imageUri = uri; + } + // 拷贝 + if(imageUri != null && imageUri != "") { + OperationUtils.copy(imageUri).then((uriPath) => { + var path = "file://" + uriPath + LogUtil.info(TAG, 'image uri is:' + path) + this.controllerShow.runJavaScript({script:"javascript:RICH_EDITOR.insertImage('" + path + "')"}) + }) + } } - } - }); - }) - }.width(42) - .height(42) - .borderRadius(8) - .backgroundColor($r('app.color.color_ffffff')) - - - Button({ type: ButtonType.Normal, stateEffect: true }) { - Image($r('app.media.undo')) - .height(24) - .width(24) - .onClick(() => { - // 退出键盘 - inputMethod.getInputMethodController().stopInput(); - this.controllerShow.runJavaScript({ script: "RICH_EDITOR.undo()" }) - }) - }.width(42) - .height(42) - .borderRadius(8) - .backgroundColor($r('app.color.color_ffffff')) - - Button({ type: ButtonType.Normal, stateEffect: true }) { - Image($r('app.media.todo')) + }); + }) + }.width(42) + .height(42) + .borderRadius(8) + .backgroundColor($r('app.color.color_ffffff')) + + + Button({ type: ButtonType.Normal, stateEffect: true }) { + Image($r('app.media.undo')) + .height(24) + .width(24) + .onClick(() => { + // 退出键盘 + inputMethod.getInputMethodController().stopInput(); + this.controllerShow.runJavaScript({ script: "RICH_EDITOR.undo()" }) + }) + }.width(42) + .height(42) + .borderRadius(8) + .backgroundColor($r('app.color.color_ffffff')) + + Button({ type: ButtonType.Normal, stateEffect: true }) { + Image($r('app.media.todo')) + .height(24) + .width(24) + .onClick(() => { + // 退出键盘 + inputMethod.getInputMethodController().stopInput(); + this.controllerShow.runJavaScript({ script: "RICH_EDITOR.redo()" }) + }) + }.width(42) + .height(42) + .borderRadius(8) + .backgroundColor($r('app.color.color_ffffff')) + + + Button({ type: ButtonType.Normal, stateEffect: true }) { + Image($r('app.media.tick_thick')) + .height(24) + .width(24) + .fillColor(this.issave == 0 ? Color.Black : Color.Grey) + .onClick(() => { + // 保存笔记信息到数据库 + this.controllerShow.runJavaScript({ script: "get_html_content()" }) + if (this.selectedNoteData.title == "标题" && this.selectedNoteData.content_text == "") { + LogUtil.info(TAG, "note is empty,save note failed") + } + this.issave = 1 + }) + }.width(42) + .height(42) + .borderRadius(8) + .backgroundColor($r('app.color.color_ffffff')) + }.width(274) + } else { + Row({ space: StyleConstants.SPACE_24 }) { + Image(this.selectedNoteData.is_favorite == Favorite.Yes ? $r('app.media.favorite') : $r('app.media.favorite_cancel')) .height(24) .width(24) .onClick(() => { - // 退出键盘 - inputMethod.getInputMethodController().stopInput(); - this.controllerShow.runJavaScript({ script: "RICH_EDITOR.redo()" }) + this.selectedNoteData.is_favorite = (this.selectedNoteData.is_favorite == Favorite.Yes ? Favorite.No : Favorite.Yes) + this.refreshFlag = (this.refreshFlag == 0 ? 1 : 0) + // update note to db + let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable) + predicates_note.equalTo(NoteTableColumn.Uuid, this.selectedNoteData.uuid) + RdbStoreUtil.update(this.selectedNoteData.toNoteObject(), predicates_note, null) + if (this.selectedFolderData.uuid === SysDefFolderUuid.MyFavorites) { + this.selectedNoteData = NoteUtil.getFirstNoteData(AppStorage.Get('AllNoteArray'), SysDefFolderUuid.MyFavorites) + this.controllerShow.runJavaScript({ script: "RICH_EDITOR.setHtml('" + this.selectedNoteData.content_text + "')" }) + // save continue data + let continueNote: string = JSON.stringify(this.selectedNoteData.toNoteObject()) + AppStorage.SetOrCreate('ContinueNote', continueNote) + LogUtil.info(TAG, "ToolBarComp, set continue note success") + } }) - }.width(42) - .height(42) - .borderRadius(8) - .backgroundColor($r('app.color.color_ffffff')) - - - Button({ type: ButtonType.Normal, stateEffect: true }) { - Image($r('app.media.tick_thick')) + Image($r('app.media.delete')) .height(24) .width(24) - .fillColor(this.issave == 0 ? Color.Black : Color.Grey) .onClick(() => { - // 保存笔记信息到数据库 - this.controllerShow.runJavaScript({ script: "get_html_content()" }) - if (this.selectedNoteData.title == "标题" && this.selectedNoteData.content_text == "") { - LogUtil.info(TAG, "note is empty,save note failed") - } - this.issave = 1 + this.noteDataDeleteDialogCtl.open() }) - }.width(42) - .height(42) - .borderRadius(8) - .backgroundColor($r('app.color.color_ffffff')) - }.width(274) - } else { - Row({ space: StyleConstants.SPACE_24 }) { - Image(this.selectedNoteData.is_favorite == Favorite.Yes ? $r('app.media.favorite') : $r('app.media.favorite_cancel')) - .height(24) - .width(24) - .onClick(() => { - this.selectedNoteData.is_favorite = (this.selectedNoteData.is_favorite == Favorite.Yes ? Favorite.No : Favorite.Yes) - this.refreshFlag = (this.refreshFlag == 0 ? 1 : 0) - // update note to db - let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable) - predicates_note.equalTo(NoteTableColumn.Uuid, this.selectedNoteData.uuid) - RdbStoreUtil.update(this.selectedNoteData.toNoteObject(), predicates_note, null) - if (this.selectedFolderData.uuid === SysDefFolderUuid.MyFavorites) { - this.selectedNoteData = NoteUtil.getFirstNoteData(AppStorage.Get('AllNoteArray'), SysDefFolderUuid.MyFavorites) - this.controllerShow.runJavaScript({ script: "RICH_EDITOR.setHtml('" + this.selectedNoteData.content_text + "')" }) - // save continue data - let continueNote: string = JSON.stringify(this.selectedNoteData.toNoteObject()) - AppStorage.SetOrCreate('ContinueNote', continueNote) - LogUtil.info(TAG, "ToolBarComp, set continue note success") - } - }) - Image($r('app.media.delete')) - .height(24) - .width(24) - .onClick(() => { - this.noteDataDeleteDialogCtl.open() - }) - }.width(72) + }.width(72) + } } } .width(StyleConstants.PERCENTAGE_100) diff --git a/common/utils/src/main/ets/default/baseUtil/NoteUtil.ets b/common/utils/src/main/ets/default/baseUtil/NoteUtil.ets index d2772e0..898922e 100644 --- a/common/utils/src/main/ets/default/baseUtil/NoteUtil.ets +++ b/common/utils/src/main/ets/default/baseUtil/NoteUtil.ets @@ -235,6 +235,10 @@ export class NoteUtil { getFirstNoteData(allNoteDataArray: NoteData[], folderUuid: string): NoteData { let noteDataArray: NoteData[] = this.getNoteDataArray(allNoteDataArray, folderUuid); LogUtil.info(TAG, "get noteDataArray size " + noteDataArray.length.toString()) + if (noteDataArray.length == 0) { + LogUtil.info(TAG, "get noteDataArray empty") + return undefined; + } return noteDataArray == undefined ? null : noteDataArray[0] } diff --git a/common/utils/src/main/ets/default/baseUtil/RdbStoreUtil.ets b/common/utils/src/main/ets/default/baseUtil/RdbStoreUtil.ets index fa17a64..9a68d0d 100644 --- a/common/utils/src/main/ets/default/baseUtil/RdbStoreUtil.ets +++ b/common/utils/src/main/ets/default/baseUtil/RdbStoreUtil.ets @@ -150,7 +150,9 @@ export default { AppStorage.SetOrCreate('Folder', AppStorage.Get('AllFolderArray')[0]) let note = NoteUtil.getFirstNoteData(AppStorage.Get('AllNoteArray'), SysDefFolderUuid.AllNotes) AppStorage.SetOrCreate('Note', note) - AppStorage.SetOrCreate('ContinueNote', JSON.stringify(note.toNoteObject())) + if (note) { + AppStorage.SetOrCreate('ContinueNote', JSON.stringify(note.toNoteObject())) + } AppStorage.SetOrCreate('Section', 3) } AppStorage.SetOrCreate('DBQueryFinished', 1) @@ -275,14 +277,16 @@ export default { AppStorage.SetOrCreate('Folder', AppStorage.Get('AllFolderArray')[0]) let note = NoteUtil.getFirstNoteData(AppStorage.Get('AllNoteArray'), SysDefFolderUuid.AllNotes) AppStorage.SetOrCreate('Note', note) - AppStorage.SetOrCreate('ContinueNote', JSON.stringify(note.toNoteObject())) + if (note) { + AppStorage.SetOrCreate('ContinueNote', JSON.stringify(note.toNoteObject())) + } AppStorage.SetOrCreate('Section', 3) } AppStorage.SetOrCreate('DBQueryFinished', 1) LogUtil.info(TAG, "initAppStorage, set DBQueryFinished 1") }) .catch((err) => { - LogUtil.warn(TAG, "initAppStorage, error : " + err) + LogUtil.error(TAG, "initAppStorage, error : " + err) }) }, -- Gitee