From 12380cb9683e214e38981d9bb78c2da4f215c00c Mon Sep 17 00:00:00 2001 From: yiqiang Date: Fri, 29 Jul 2022 10:56:57 +0800 Subject: [PATCH 1/2] hap only use one module name Signed-off-by: yiqiang --- .../src/main/ets/MainAbility/MainAbility.ts | 12 +++ .../tablet/src/main/ets/pages/MyNoteHome.ets | 44 +++++++--- .../src/main/ets/pages/NoteContentHome.ets | 17 +++- .../src/main/ets/pages/NoteHomePortrait.ets | 81 +++++++++++++++++++ 4 files changed, 143 insertions(+), 11 deletions(-) create mode 100644 product/tablet/src/main/ets/pages/NoteHomePortrait.ets diff --git a/product/tablet/src/main/ets/MainAbility/MainAbility.ts b/product/tablet/src/main/ets/MainAbility/MainAbility.ts index c60c19e..ef8eedf 100644 --- a/product/tablet/src/main/ets/MainAbility/MainAbility.ts +++ b/product/tablet/src/main/ets/MainAbility/MainAbility.ts @@ -14,6 +14,7 @@ */ import Ability from '@ohos.application.Ability' +import deviceInfo from '@ohos.deviceInfo'; import AbilityConstant from '@ohos.application.AbilityConstant' import fileio from '@ohos.fileio' import inputMethod from '@ohos.inputmethod'; @@ -23,6 +24,11 @@ export default class MainAbility extends Ability { onCreate(want, launchParam) { console.info(this.Tag + " onCreate, launchReason is " + launchParam.launchReason) + console.info(this.Tag + " onCreate, deviceType" + deviceInfo.deviceType) + if (deviceInfo.deviceType === 'phone' || deviceInfo.deviceType === 'default') { + AppStorage.SetOrCreate('Expand', false) + AppStorage.SetOrCreate('Choose', true) + } if (launchParam.launchReason == AbilityConstant.LaunchReason.CONTINUATION) { // 设置迁移标记 AppStorage.SetOrCreate('IsContinue', true) @@ -37,6 +43,9 @@ export default class MainAbility extends Ability { if (continueChoose) { console.info(this.Tag + " continue from phone") AppStorage.SetOrCreate('ContinueFromPhone', true) + } else { + AppStorage.SetOrCreate('ContinueFromTablet', true) + console.info(this.Tag + " continue from tablet") } this.context.restoreWindowStage(null) } @@ -85,6 +94,9 @@ export default class MainAbility extends Ability { // 保存本端的迁移数据 wantParam["ContinueNote"] = continueNote wantParam["ContinueSection"] = continueSection + if (deviceInfo.deviceType === 'phone' || deviceInfo.deviceType === 'default') { + wantParam["ContinueChoose"] = true + } // save img to DisFileDir console.info(this.Tag + " onContinue, save img to DisFileDir") diff --git a/product/tablet/src/main/ets/pages/MyNoteHome.ets b/product/tablet/src/main/ets/pages/MyNoteHome.ets index fdaeaf8..022de26 100644 --- a/product/tablet/src/main/ets/pages/MyNoteHome.ets +++ b/product/tablet/src/main/ets/pages/MyNoteHome.ets @@ -14,19 +14,20 @@ */ import fileio from '@ohos.fileio' -import bundle from '@ohos.bundle' -import abilityAccessCtrl from '@ohos.abilityAccessCtrl' +import deviceInfo from '@ohos.deviceInfo'; import {NoteHomeComp} from './NoteHome' +import {NoteHomePortraitComp} from './NoteHomePortrait' import {LogUtil} from '@ohos/utils/src/main/ets/default/baseUtil/LogUtil' import RdbStoreUtil from '@ohos/utils/src/main/ets/default/baseUtil/RdbStoreUtil' import NoteData from '@ohos/utils/src/main/ets/default/model/databaseModel/NoteData' import inputMethod from '@ohos.inputmethod'; +import router from '@system.router'; @Entry @Component export struct MyNoteHomeComp { @StorageLink('DBQueryFinished') dBQueryFinished: number = 0 - @Provide('PortraitModel') portraitModel: boolean = false + @Provide('PortraitModel') portraitModel: boolean = (deviceInfo.deviceType === 'phone' || deviceInfo.deviceType === 'default') @Provide('RefreshFlag') refreshFlag: number = 0 private controllerShow: WebController = new WebController() private context = getContext(this) @@ -35,7 +36,12 @@ export struct MyNoteHomeComp { build() { Row() { if (this.dBQueryFinished == 1) { - NoteHomeComp({ controllerShow: this.controllerShow }) + if (deviceInfo.deviceType === 'phone' || deviceInfo.deviceType === 'default') { + NoteHomePortraitComp() + } else { + NoteHomeComp({ controllerShow: this.controllerShow }) + } + } } .width('100%') @@ -54,6 +60,13 @@ export struct MyNoteHomeComp { "ohos.permission.READ_MEDIA", "ohos.permission.DISTRIBUTED_DATASYNC" ] + if (deviceInfo.deviceType === 'phone' || deviceInfo.deviceType === 'default') { + permissionList = [ + "ohos.permission.READ_MEDIA", + "ohos.permission.MEDIA_LOCATION", + "ohos.permission.DISTRIBUTED_DATASYNC" + ] + } LogUtil.info(this.TAG, 'permissions need to require from user') let context: any = getContext(this); context.requestPermissionsFromUser(permissionList).then((data) => { @@ -85,12 +98,25 @@ export struct MyNoteHomeComp { onPageShow(): void{ LogUtil.info(this.TAG, "onPageShow") - let currentNote = AppStorage.Get('NewNote') - let needRefesh = AppStorage.Get('needRefresh') - if (currentNote != null && needRefesh == true) { - this.controllerShow.runJavaScript({ script: "RICH_EDITOR.setHtml('" + currentNote.content_text + "')" }) - AppStorage.SetOrCreate('needRefresh',false) + if (deviceInfo.deviceType === 'phone' || deviceInfo.deviceType === 'default') { + // continue from tablet + let continueFromTablet = AppStorage.Get('ContinueFromTablet') + LogUtil.info(this.TAG, "onPageShow, continueFromTablet : " + continueFromTablet) + let noteContentHomeExist = AppStorage.Get('NoteContentHomeExist') + LogUtil.info(this.TAG, "onPageShow, noteContentHomeExist : " + noteContentHomeExist) + if (continueFromTablet && !noteContentHomeExist) { + router.push({ uri: 'pages/NoteContentHome' }) + AppStorage.SetOrCreate('ContinueFromTablet', false) + } + } else { + let currentNote = AppStorage.Get('NewNote') + let needRefresh = AppStorage.Get('needRefresh') + if (currentNote != null && needRefresh == true) { + this.controllerShow.runJavaScript({ script: "RICH_EDITOR.setHtml('" + currentNote.content_text + "')" }) + AppStorage.SetOrCreate('needRefresh',false) + } } + this.refreshFlag = (this.refreshFlag == 0 ? 1 : 0) } diff --git a/product/tablet/src/main/ets/pages/NoteContentHome.ets b/product/tablet/src/main/ets/pages/NoteContentHome.ets index 861a478..0e74967 100644 --- a/product/tablet/src/main/ets/pages/NoteContentHome.ets +++ b/product/tablet/src/main/ets/pages/NoteContentHome.ets @@ -13,6 +13,8 @@ * limitations under the License. */ +import deviceInfo from '@ohos.deviceInfo'; +import {NoteContentCompPortrait} from '@ohos/component/src/main/ets/components/NoteContentCompPortrait' import {NoteContent} from '@ohos/component/src/main/ets/components/NoteContent' import {LogUtil} from '@ohos/utils/src/main/ets/default/baseUtil/LogUtil' import RdbStoreUtil from '@ohos/utils/src/main/ets/default/baseUtil/RdbStoreUtil' @@ -21,6 +23,7 @@ import inputMethod from '@ohos.inputmethod' @Entry @Component struct NoteContentHome { + @Provide('RefreshFlag') refreshFlag: number = 0 private controllerShow: WebController = new WebController() @StorageLink('DBQueryFinished') dBQueryFinished: number = 0 TAG = "NoteContentHome_Tablet" @@ -29,7 +32,12 @@ struct NoteContentHome { // Note content display area Flex({ direction: FlexDirection.Column, wrap: FlexWrap.Wrap, justifyContent: FlexAlign.Start }) { if (this.dBQueryFinished == 1) { - NoteContent({ controllerShow: this.controllerShow }) + if (deviceInfo.deviceType === 'phone' || deviceInfo.deviceType === 'default') { + NoteContentCompPortrait({ controllerShow: this.controllerShow }) + } else { + NoteContent({ controllerShow: this.controllerShow }) + } + } } .backgroundColor($r("app.color.notecontent_color_ffffff")) @@ -41,7 +49,9 @@ struct NoteContentHome { LogUtil.info(this.TAG, "onBackPress") this.controllerShow.runJavaScript({ script: "RICH_EDITOR.setInputEnabled(false)" }) this.controllerShow.runJavaScript({ script: "getHtmlContent()" }) - inputMethod.getInputMethodController().stopInput() + if (deviceInfo.deviceType !== 'phone' && deviceInfo.deviceType !== 'default') { + inputMethod.getInputMethodController().stopInput() + } } aboutToAppear(): void{ @@ -51,6 +61,9 @@ struct NoteContentHome { if (isContinue) { RdbStoreUtil.initAppStorage(globalThis.noteContext) } + if (deviceInfo.deviceType === 'phone' || deviceInfo.deviceType === 'default') { + AppStorage.SetOrCreate('NoteContentHomeExist', true) + } } } \ No newline at end of file diff --git a/product/tablet/src/main/ets/pages/NoteHomePortrait.ets b/product/tablet/src/main/ets/pages/NoteHomePortrait.ets new file mode 100644 index 0000000..ec185df --- /dev/null +++ b/product/tablet/src/main/ets/pages/NoteHomePortrait.ets @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { FolderListComp, FolderListBackGround } from '@ohos/component/src/main/ets/components/FolderListComp' +import { NoteListComp } from '@ohos/component/src/main/ets/components/NoteListComp' +import { NoteContentCompPortrait } from '@ohos/component/src/main/ets/components/NoteContentCompPortrait' +import StyleConstants from '@ohos/utils/src/main/ets/default/constants/StyleConstants' +import { LogUtil } from '@ohos/utils/src/main/ets/default/baseUtil/LogUtil' +import { circleColorArray } from '@ohos/utils/src/main/ets/default/model/NoteBaseData' +import FolderData from '@ohos/utils/src/main/ets/default/model/databaseModel/FolderData' +import NoteData from '@ohos/utils/src/main/ets/default/model/databaseModel/NoteData' +import { SysDefFolderUuid } from '@ohos/utils/src/main/ets/default/model/databaseModel/EnumData' +import LayoutUtil from '@ohos/utils/src/main/ets/default/baseUtil/LayoutUtil' +import NoteUtil from '@ohos/utils/src/main/ets/default/baseUtil/NoteUtil' + +@Entry +@Component +export struct NoteHomePortraitComp { + // 当前文件夹、笔记、分栏 + @Provide('SelectedFolderData') selectedFolderData: FolderData = AppStorage.Get('Folder') + @Provide('SelectedNoteData') selectedNoteData: NoteData = AppStorage.Get('Note') + @Provide('SectionStatus') sectionStatus: number = 1; // 表示分栏状态, 3表示三分栏, 2表示二分栏,1表示一分栏 + @Provide('LastSectionStatus') lastSectionStatus: number = 1; // 记录分栏上一次的状态 + @Provide('SelectedColor') selectedColor: string = circleColorArray[0]; + @Provide('Longpress') longpress: boolean = false // 第二栏长按状态 + + // 分栏状态 + @Provide('ExpandStatus') expandStatus: boolean = AppStorage.Get('Expand') // 笔记本折叠展开状态 + @Provide('ChooseNote') chooseNote: boolean = AppStorage.Get('Choose') // 是否选择笔记进行打开 + + @Provide('Search') search: boolean = false // 是否处于搜索状态 + @Provide('SearchResultList') searchResultList: NoteData[] = [] // 搜索得到的笔记列表 + @Provide('InputKeyword') inputKeyword: string = '' // 搜索的字串 + @Provide('SelectedAll') selectedAll: boolean = false; + @Provide('EditModel') editModel: boolean = false + TAG = "NoteHomePortraitComp_Phone" + + build() { + Stack({ alignContent: Alignment.Start }) { + + // Note list display area + Flex({ direction: FlexDirection.Column, wrap: FlexWrap.Wrap, justifyContent: FlexAlign.Start }) { + NoteListComp() + } + .width(StyleConstants.PERCENTAGE_100) + .height(StyleConstants.PERCENTAGE_100) + .enabled(this.expandStatus ? false : true) + .backgroundColor($r("app.color.notelist_bgcolor_f1f3f5")) + + //Folder list display area + Stack() { + FolderListBackGround() + FolderListComp() + } + .width(200) + .height(StyleConstants.PERCENTAGE_100) + .visibility(this.expandStatus == false ? Visibility.None : Visibility.Visible) + } + .width(StyleConstants.PERCENTAGE_100).height(StyleConstants.PERCENTAGE_100) + } + + aboutToAppear(): void{ + LogUtil.info(this.TAG, "aboutToAppear") + } + + aboutToDisappear(): void{ + LogUtil.info(this.TAG, "aboutToDisappear") + } +} \ No newline at end of file -- Gitee From 6dbbffdddb460ed427a76ba61ab616a2b927c669 Mon Sep 17 00:00:00 2001 From: yiqiang Date: Mon, 1 Aug 2022 10:35:56 +0800 Subject: [PATCH 2/2] moudle name change Signed-off-by: yiqiang --- product/tablet/src/main/resources/base/profile/main_pages.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/product/tablet/src/main/resources/base/profile/main_pages.json b/product/tablet/src/main/resources/base/profile/main_pages.json index 78dd7be..96441ae 100644 --- a/product/tablet/src/main/resources/base/profile/main_pages.json +++ b/product/tablet/src/main/resources/base/profile/main_pages.json @@ -2,6 +2,7 @@ "src": [ "pages/MyNoteHome", "pages/NoteContentHome", - "pages/NoteHome" + "pages/NoteHome", + "pages/NoteHomePortrait" ] } \ No newline at end of file -- Gitee