diff --git a/common/index.ts b/common/index.ts index d3fd21bb6cc2da77071033e8a62b05cb0a790a6d..4bd8acd7093353ad19d419ef66193fc3c1d1ba3a 100644 --- a/common/index.ts +++ b/common/index.ts @@ -65,7 +65,7 @@ export { } from './src/main/ets/default/manager' export { - DragArea, DragItemPosition + DragArea, DragItemPosition, GridLayoutInfo, FolderData } from './src/main/ets/default/interface' export { diff --git a/common/src/main/ets/default/base/BaseViewModel.ts b/common/src/main/ets/default/base/BaseViewModel.ts index d84bd9e4e8a167013f9b68687e75fb0ff0c68d53..802dfbe809930479f1f798030041e359025e6f57 100644 --- a/common/src/main/ets/default/base/BaseViewModel.ts +++ b/common/src/main/ets/default/base/BaseViewModel.ts @@ -19,6 +19,7 @@ import { AppModel } from '../model/AppModel'; import { ResourceManager } from '../manager/ResourceManager'; import { CommonConstants } from '../constants/CommonConstants'; import { launcherAbilityManager } from '../manager/LauncherAbilityManager'; +import { AsyncCallback } from '@ohos.base'; const TAG = 'BaseViewModel'; @@ -27,7 +28,7 @@ const KEY_NAME = 'name'; /** * Base class for view models. */ - export class BaseViewModel { +export class BaseViewModel { protected mAppModel: AppModel; protected mResourceManager: ResourceManager; private readonly listener; @@ -66,6 +67,10 @@ const KEY_NAME = 'name'; this.jumpTo(CommonConstants.SETTING_ABILITY, CommonConstants.LAUNCHER_BUNDLE, CommonConstants.SETTING_MODULE); } + private uninstallAppCallback = (resultCode: number): void => { + this.informUninstallResult(resultCode); + } + /** * Uninstall target app by bundle name. * @@ -76,14 +81,10 @@ const KEY_NAME = 'name'; if (!isUninstallable) { this.informUninstallResult(CommonConstants.UNINSTALL_FORBID); } else { - void launcherAbilityManager.uninstallLauncherAbility(uninstallBundleName, this.uninstallAppCallback.bind(this)); + void launcherAbilityManager.uninstallLauncherAbility(uninstallBundleName, this.uninstallAppCallback); } } - private uninstallAppCallback(resultData: {code: number}): void { - this.informUninstallResult(resultData.code); - } - registerAppListChangeCallback(): void { this.mAppModel.registerStateChangeListener(this.listener); } @@ -101,7 +102,7 @@ const KEY_NAME = 'name'; } informUninstallResult(resultCode: number): void { - Log.showDebug(TAG, `Launcher AppListView getUninstallApp uninstallationResult: ${resultCode}`); + Log.showDebug(TAG, `Launcher AppListView getUninstallApp uninstallationResult: ${resultCode}`); if (resultCode === CommonConstants.UNINSTALL_FORBID) { Prompt.showToast({ message: $r("app.string.disable_uninstall") diff --git a/common/src/main/ets/default/bean/AppItemInfo.ts b/common/src/main/ets/default/bean/AppItemInfo.ts index e4131db5e3b8c73a5fd1d0a1ddbb932a38cb7180..647a06a1aff8ef1590e3f54ca093055205caa5d9 100644 --- a/common/src/main/ets/default/bean/AppItemInfo.ts +++ b/common/src/main/ets/default/bean/AppItemInfo.ts @@ -62,9 +62,9 @@ export class AppItemInfo { */ badgeNumber: number | undefined; - checked?: boolean | undefined; + checked: boolean | undefined; - installTime?: string | undefined; + installTime: string | undefined; moduleName: string | undefined; diff --git a/common/src/main/ets/default/bean/GridLayoutItemInfo.ts b/common/src/main/ets/default/bean/GridLayoutItemInfo.ts index e08f9ddce35ae2ebc23c1df471e4344295122987..8c5d9542f6f03442e85e40db6a04b66fd400d6a0 100644 --- a/common/src/main/ets/default/bean/GridLayoutItemInfo.ts +++ b/common/src/main/ets/default/bean/GridLayoutItemInfo.ts @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { AppItemInfo } from './AppItemInfo'; import GridLayoutItemBuilder from './GridLayoutItemBuilder'; @@ -96,7 +97,7 @@ export default class GridLayoutItemInfo { /** * GridLayoutItemInfo: bigFolder apps info */ - layoutInfo: any | undefined; + layoutInfo: AppItemInfo[][] | undefined; /** * GridLayoutItemInfo: extend1 diff --git a/common/src/main/ets/default/bean/LauncherDragItemInfo.ts b/common/src/main/ets/default/bean/LauncherDragItemInfo.ts index df42a5e9ba269e46c7b89391d96013bb5107d134..b5c757390bb847a2a7eec07257bd9b7f47b1ebd6 100644 --- a/common/src/main/ets/default/bean/LauncherDragItemInfo.ts +++ b/common/src/main/ets/default/bean/LauncherDragItemInfo.ts @@ -56,4 +56,5 @@ export class LauncherDragItemInfo { layoutInfo?: AppItemInfo[][]; itemType?: number; editable?: boolean; + enterEditing?: boolean; } \ No newline at end of file diff --git a/common/src/main/ets/default/interface/FolderData.ts b/common/src/main/ets/default/interface/FolderData.ts new file mode 100644 index 0000000000000000000000000000000000000000..26cb16967e0cf6eb4d93247ea91776ab5e6cf431 --- /dev/null +++ b/common/src/main/ets/default/interface/FolderData.ts @@ -0,0 +1,24 @@ +/** + * Copyright (c) 2023 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 { AppItemInfo } from '../bean'; + +export class FolderData { + layoutInfo: AppItemInfo[][]; + enterEditing: boolean; + folderName: string; + folderId: string; + badgeNumber?: number; +} \ No newline at end of file diff --git a/common/src/main/ets/default/interface/GridLayoutInfo.ts b/common/src/main/ets/default/interface/GridLayoutInfo.ts new file mode 100644 index 0000000000000000000000000000000000000000..b3f60d423b7f4645cc64cdb176b090712d90d70b --- /dev/null +++ b/common/src/main/ets/default/interface/GridLayoutInfo.ts @@ -0,0 +1,25 @@ +/** + * 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 { LauncherDragItemInfo } from '../bean/LauncherDragItemInfo'; + +export interface GridLayoutInfo { + layoutDescription: { + pageCount: number; + row: number; + column: number; + } | undefined; + layoutInfo: LauncherDragItemInfo[]; +} \ No newline at end of file diff --git a/common/src/main/ets/default/interface/index.ts b/common/src/main/ets/default/interface/index.ts index 0850fbfb67703d7afae07be49e3e60c371091a8a..f3656463a654cdff7c8837b1de93f5212c6d1603 100644 --- a/common/src/main/ets/default/interface/index.ts +++ b/common/src/main/ets/default/interface/index.ts @@ -13,6 +13,10 @@ * limitations under the License. */ -export { DragArea } from './DragArea' +export { DragArea } from './DragArea'; -export { DragItemPosition } from './DragItemPosition' \ No newline at end of file +export { DragItemPosition } from './DragItemPosition'; + +export { GridLayoutInfo } from './GridLayoutInfo'; + +export { FolderData } from './FolderData'; \ No newline at end of file diff --git a/common/src/main/ets/default/layoutconfig/PageDesktopLayoutConfig.ts b/common/src/main/ets/default/layoutconfig/PageDesktopLayoutConfig.ts index 671bf63e3e65d7ebe9645f637e846f7063958345..6bd2f9875fdeda3d4611e53038c7e36a358c9ef1 100644 --- a/common/src/main/ets/default/layoutconfig/PageDesktopLayoutConfig.ts +++ b/common/src/main/ets/default/layoutconfig/PageDesktopLayoutConfig.ts @@ -17,6 +17,7 @@ import { Log } from '../utils/Log'; import { ILayoutConfig } from './ILayoutConfig'; import { CommonConstants } from '../constants/CommonConstants'; import FileUtils from '../utils/FileUtils'; +import { GridLayoutInfo } from '../interface'; const TAG = 'PageDesktopLayoutConfig'; @@ -35,7 +36,7 @@ export class PageDesktopLayoutConfig extends ILayoutConfig { private static readonly DEFAULT_COLUMN_COUNT = 4; - private static readonly DEFAULT_LAYOUT_INFO: any = { + private static readonly DEFAULT_LAYOUT_INFO: GridLayoutInfo = { layoutDescription: { pageCount: PageDesktopLayoutConfig.DEFAULT_PAGE_COUNT, row: PageDesktopLayoutConfig.DEFAULT_ROW_COUNT, @@ -44,7 +45,7 @@ export class PageDesktopLayoutConfig extends ILayoutConfig { layoutInfo: [] }; - private mGridLayoutInfo: any = PageDesktopLayoutConfig.DEFAULT_LAYOUT_INFO; + private mGridLayoutInfo: GridLayoutInfo = PageDesktopLayoutConfig.DEFAULT_LAYOUT_INFO; locked: boolean = false; @@ -88,7 +89,7 @@ export class PageDesktopLayoutConfig extends ILayoutConfig { * * @params gridLayoutInfo */ - updateGridLayoutInfo(gridLayoutInfo: any): void { + updateGridLayoutInfo(gridLayoutInfo: GridLayoutInfo): void { const temp = gridLayoutInfo; FileUtils.writeStringToFile(JSON.stringify(temp), this.getConfigFileAbsPath()); this.mGridLayoutInfo = gridLayoutInfo; @@ -116,7 +117,7 @@ export class PageDesktopLayoutConfig extends ILayoutConfig { * * @return Workspace layout data */ - getGridLayoutInfo(): any { + getGridLayoutInfo(): GridLayoutInfo { return this.mGridLayoutInfo; } diff --git a/common/src/main/ets/default/manager/CommonEventManager.ts b/common/src/main/ets/default/manager/CommonEventManager.ts index d8c1b939f748184878f0725dca1ce763a5368b85..e3bb6f17b3e7ee5607a7b6b0e9a62be934914c3c 100644 --- a/common/src/main/ets/default/manager/CommonEventManager.ts +++ b/common/src/main/ets/default/manager/CommonEventManager.ts @@ -13,10 +13,8 @@ * limitations under the License. */ -import CommonEvent from '@ohos.commonEvent'; import { AsyncCallback } from '@ohos.base'; -import { CommonEventData } from 'commonEvent/commonEventData'; -import { CommonEventSubscriber } from 'commonEvent/commonEventSubscriber'; +import commonEventMgr from '@ohos.commonEventManager'; const TAG = 'CommonEventManager'; @@ -27,8 +25,8 @@ class CommonEventManager { RECENT_FULL_SCREEN = 'CREATE_RECENT_WINDOW_EVENT'; RECENT_SPLIT_SCREEN = 'common.event.SPLIT_SCREEN'; - private callbackList: AsyncCallback[] = []; - private subscriberList: CommonEventSubscriber[] = []; + private callbackList: AsyncCallback[] = []; + private subscriberList: commonEventMgr.CommonEventSubscriber[] = []; /** * get CommonEventManager instance @@ -48,11 +46,12 @@ class CommonEventManager { /** * Register common event listener. */ - public registerCommonEvent(subscriber: CommonEventSubscriber, eventCallback: AsyncCallback): void { - if (this.subscriberList.indexOf(subscriber) != -1) { + public registerCommonEvent(subscriber: commonEventMgr.CommonEventSubscriber, + eventCallback: AsyncCallback): void { + if (this.subscriberList.indexOf(subscriber) !== -1) { return; } - CommonEvent.subscribe(subscriber, eventCallback); + commonEventMgr.subscribe(subscriber, eventCallback); this.subscriberList.push(subscriber); this.callbackList.push(eventCallback); } @@ -60,14 +59,15 @@ class CommonEventManager { /** * Unregister common event listener. */ - public unregisterCommonEvent(subscriber: CommonEventSubscriber, eventCallback: AsyncCallback): void { + public unregisterCommonEvent(subscriber: commonEventMgr.CommonEventSubscriber, + eventCallback: AsyncCallback): void { const subscriberIndex: number = this.subscriberList.indexOf(subscriber); const callbackIndex: number = this.callbackList.indexOf(eventCallback); - if (subscriberIndex != -1) { - CommonEvent.unsubscribe(subscriber); + if (subscriberIndex !== -1) { + commonEventMgr.unsubscribe(subscriber); this.subscriberList.splice(subscriberIndex, 1); } - callbackIndex != -1 && this.callbackList.splice(callbackIndex, 1); + callbackIndex !== -1 && this.callbackList.splice(callbackIndex, 1); } } diff --git a/common/src/main/ets/default/manager/InputMethodManager.ts b/common/src/main/ets/default/manager/InputMethodManager.ts index 7432175add65849cac6c0190be864e56df939844..76713bcfb1c13376498a794286260e2ea92e1e8a 100644 --- a/common/src/main/ets/default/manager/InputMethodManager.ts +++ b/common/src/main/ets/default/manager/InputMethodManager.ts @@ -28,6 +28,6 @@ export class InputMethodManager { } stopInput(): void { - inputMethod.getInputMethodController()?.stopInput(); + inputMethod.getController()?.stopInputSession(); } } \ No newline at end of file diff --git a/common/src/main/ets/default/manager/LauncherAbilityManager.ts b/common/src/main/ets/default/manager/LauncherAbilityManager.ts index 7f32c184f40e1e10441ceccaae1d27d1e060593c..772d55ab2522d520dc8939731aaab920c48d06b2 100644 --- a/common/src/main/ets/default/manager/LauncherAbilityManager.ts +++ b/common/src/main/ets/default/manager/LauncherAbilityManager.ts @@ -13,43 +13,48 @@ * limitations under the License. */ -import bundleMgr from '@ohos.bundle'; +import installer from '@ohos.bundle.installer'; +import bundleMonitor from '@ohos.bundle.bundleMonitor'; import osAccount from '@ohos.account.osAccount'; import hiSysEvent from '@ohos.hiSysEvent'; -import launcherBundleMgr from '@ohos.bundle.innerBundleManager'; -import { LauncherAbilityInfo } from 'bundle/launcherAbilityInfo'; +import launcherBundleManager from '@ohos.bundle.launcherBundleManager'; import { Log } from '../utils/Log'; -import { Trace } from '../utils/Trace'; import { CheckEmptyUtils } from '../utils/CheckEmptyUtils'; import { AppItemInfo } from '../bean/AppItemInfo'; import { CommonConstants } from '../constants/CommonConstants'; import { ResourceManager } from './ResourceManager'; import { EventConstants } from '../constants/EventConstants'; import { BadgeManager } from '../manager/BadgeManager'; +import { BusinessError } from '@ohos.base'; const TAG = 'LauncherAbilityManager'; +interface BundleStatusCallback { + add: (bundleName: string, userId: number) => void; + remove: (bundleName: string, userId: number) => void; + update: (bundleName: string, userId: number) => void; +} + /** * Wrapper class for innerBundleManager and formManager interfaces. */ class LauncherAbilityManager { private static readonly CURRENT_USER_ID = -2; - private static readonly BUNDLE_STATUS_CHANGE_KEY = 'BundleStatusChange'; private readonly mAppMap = new Map(); private mUserId: number = 100; - private readonly mBundleStatusCallback: any = { + private readonly mBundleStatusCallback: BundleStatusCallback = { add: (bundleName, userId) => { - Log.showDebug(TAG, `mBundleStatusCallback add bundleName: ${bundleName}, userId: ${userId}, mUserId ${this.mUserId}`); - this.mUserId == userId && this.notifyLauncherAbilityChange(EventConstants.EVENT_PACKAGE_ADDED, bundleName, userId); + Log.showDebug(TAG, `PACKAGE_ADDED bundleName: ${bundleName}, userId: ${userId}, mUserId ${this.mUserId}`); + this.mUserId === userId && this.notifyLauncherAbilityChange(EventConstants.EVENT_PACKAGE_ADDED, bundleName, userId); }, remove: (bundleName, userId) => { - Log.showDebug(TAG, `mBundleStatusCallback remove bundleName: ${bundleName}, userId: ${userId}, mUserId ${this.mUserId}`); - this.mUserId == userId && this.notifyLauncherAbilityChange(EventConstants.EVENT_PACKAGE_REMOVED, bundleName, userId); + Log.showDebug(TAG, `PACKAGE_REMOVED bundleName: ${bundleName}, userId: ${userId}, mUserId ${this.mUserId}`); + this.mUserId === userId && this.notifyLauncherAbilityChange(EventConstants.EVENT_PACKAGE_REMOVED, bundleName, userId); }, update: (bundleName, userId) => { - Log.showDebug(TAG, `mBundleStatusCallback update bundleName: ${bundleName}, userId: ${userId}, mUserId ${this.mUserId}`); - this.mUserId == userId && this.notifyLauncherAbilityChange(EventConstants.EVENT_PACKAGE_CHANGED, bundleName, userId); + Log.showDebug(TAG, `PACKAGE_CHANGED bundleName: ${bundleName}, userId: ${userId}, mUserId ${this.mUserId}`); + this.mUserId === userId && this.notifyLauncherAbilityChange(EventConstants.EVENT_PACKAGE_CHANGED, bundleName, userId); } }; @@ -87,11 +92,25 @@ class LauncherAbilityManager { registerLauncherAbilityChangeListener(listener: any): void { if (listener != null) { if (this.mLauncherAbilityChangeListeners.length == 0) { - launcherBundleMgr.on(LauncherAbilityManager.BUNDLE_STATUS_CHANGE_KEY, this.mBundleStatusCallback).then(data => { - Log.showDebug(TAG, `registerCallback success: ${JSON.stringify(data)}`); - }).catch(err => { - Log.showError(TAG, `registerCallback fail: ${JSON.stringify(err)}`); - }); + try { + bundleMonitor.on('add', (bundleChangeInfo) => { + Log.showInfo(TAG, `add bundleName: ${bundleChangeInfo.bundleName} userId: ${bundleChangeInfo.userId}`); + this.mBundleStatusCallback.add(bundleChangeInfo.bundleName, bundleChangeInfo.userId); + }); + bundleMonitor.on('update', (bundleChangeInfo) => { + Log.showInfo(TAG, `update bundleName: ${bundleChangeInfo.bundleName} userId: ${bundleChangeInfo.userId}`); + this.mBundleStatusCallback.update(bundleChangeInfo.bundleName, bundleChangeInfo.userId); + }); + bundleMonitor.on('remove', (bundleChangeInfo) => { + Log.showInfo(TAG, `remove bundleName: ${bundleChangeInfo.bundleName} userId: ${bundleChangeInfo.userId}`); + this.mBundleStatusCallback.remove(bundleChangeInfo.bundleName, bundleChangeInfo.userId); + }); + Log.showInfo(TAG, `registerCallback success`); + } catch (errData) { + let message = (errData as BusinessError).message; + let errCode = (errData as BusinessError).code; + Log.showError(TAG, `registerCallback fail errCode:${errCode}, message:${message}`); + } } const index = this.mLauncherAbilityChangeListeners.indexOf(listener); if (index == CommonConstants.INVALID_VALUE) { @@ -112,11 +131,16 @@ class LauncherAbilityManager { this.mLauncherAbilityChangeListeners.splice(index, 1); } if (this.mLauncherAbilityChangeListeners.length == 0) { - launcherBundleMgr.off(LauncherAbilityManager.BUNDLE_STATUS_CHANGE_KEY).then(data => { - Log.showDebug(TAG, 'unregisterCallback success'); - }).catch(err => { - Log.showError(TAG, `unregisterCallback fail: ${JSON.stringify(err)}`); - }); + try { + bundleMonitor.off('add'); + bundleMonitor.off('update'); + bundleMonitor.off('remove'); + Log.showInfo(TAG, 'unregisterCallback success'); + } catch (errData) { + let message = (errData as BusinessError).message; + let errCode = (errData as BusinessError).code; + Log.showError(TAG, `unregisterCallback fail errCode:${errCode}, message:${message}`); + } } } } @@ -132,7 +156,7 @@ class LauncherAbilityManager { */ async getLauncherAbilityList(): Promise { let abilityList = null; - await launcherBundleMgr.getAllLauncherAbilityInfos(LauncherAbilityManager.CURRENT_USER_ID) + await launcherBundleManager.getAllLauncherAbilityInfo(LauncherAbilityManager.CURRENT_USER_ID) .then((res) => { abilityList = res; }) @@ -158,8 +182,8 @@ class LauncherAbilityManager { * @return List of entry capabilities information of the target application */ async getLauncherAbilityInfo(bundleName: string): Promise { - let abilityInfos: LauncherAbilityInfo[]; - await launcherBundleMgr.getLauncherAbilityInfos(bundleName, this.mUserId) + let abilityInfos: launcherBundleManager.LauncherAbilityInfo[]; + await launcherBundleManager.getLauncherAbilityInfo(bundleName, this.mUserId) .then((res) => { abilityInfos = res; }) @@ -193,15 +217,15 @@ class LauncherAbilityManager { return appItemInfo; } // get from system - let abilityInfos = new Array(); - await launcherBundleMgr.getLauncherAbilityInfos(bundleName, LauncherAbilityManager.CURRENT_USER_ID) + let abilityInfos = new Array(); + await launcherBundleManager.getLauncherAbilityInfo(bundleName, LauncherAbilityManager.CURRENT_USER_ID) .then((res)=>{ if (res && res.length) { abilityInfos = res; } }) .catch((err)=>{ - Log.showError(TAG, `getAppInfoByBundleName launcherBundleMgr getLauncherAbilityInfos error: ${JSON.stringify(err)}`); + Log.showError(TAG, `getAppInfoByBundleName getLauncherAbilityInfo error: ${JSON.stringify(err)}`); }); if (!abilityInfos || abilityInfos.length === 0) { Log.showDebug(TAG, `${bundleName} has no launcher ability`); @@ -247,17 +271,28 @@ class LauncherAbilityManager { * @params bundleName application bundleName * @params callback to get result */ - async uninstallLauncherAbility(bundleName: string, callback): Promise { + async uninstallLauncherAbility(bundleName: string, callback: (resultCode: number) => void): Promise { Log.showInfo(TAG, `uninstallLauncherAbility bundleName: ${bundleName}`); - const bundlerInstaller = await bundleMgr.getBundleInstaller(); - bundlerInstaller.uninstall(bundleName, { - userId: this.mUserId, - installFlag: 0, - isKeepData: false - }, (result) => { - Log.showDebug(TAG, `uninstallLauncherAbility result => ${JSON.stringify(result)}`); - callback(result); - }); + try { + const bundlerInstaller = await installer.getBundleInstaller(); + bundlerInstaller.uninstall(bundleName, { + userId: this.mUserId, + installFlag: 0, + isKeepData: false + }, (err: BusinessError) => { + if (err) { + callback(CommonConstants.INVALID_VALUE); + Log.showError(TAG, `uninstallLauncherAbility failed: ${JSON.stringify(err)}`); + } else { + callback(CommonConstants.UNINSTALL_SUCCESS); + Log.showDebug(TAG, `uninstallLauncherAbility successfully: ${JSON.stringify(err)}`); + } + }); + } catch (err) { + let errCode = (err as BusinessError).code; + let errMsg = (err as BusinessError).message; + Log.showError(TAG, `uninstallLauncherAbility errCode: ${errCode}, errMsg: ${errMsg}`); + } } /** @@ -321,9 +356,9 @@ class LauncherAbilityManager { }); } - async getShortcutInfo(paramBundleName, callback) { + async getShortcutInfo(paramBundleName: string, callback) { Log.showDebug(TAG, `getShortcutInfo bundleName: ${paramBundleName}`); - await launcherBundleMgr.getShortcutInfos(paramBundleName) + await launcherBundleManager.getShortcutInfo(paramBundleName) .then(shortcutInfo => { callback(paramBundleName, shortcutInfo); }) @@ -337,7 +372,7 @@ class LauncherAbilityManager { * @params paramBundleName application bundle name * @params paramAbilityName application abilit uri */ - startLauncherAbilityByUri(paramBundleName, abilityUri) { + startLauncherAbilityByUri(paramBundleName: string, abilityUri) { Log.showInfo(TAG, `startLauncherAbilityByUri bundleName:${paramBundleName} abilityUri:${abilityUri}`); const result = globalThis.desktopContext.startAbility({ bundleName: paramBundleName, diff --git a/common/src/main/ets/default/manager/NavigationBarCommonEventManager.ts b/common/src/main/ets/default/manager/NavigationBarCommonEventManager.ts index 7c59c2b8c27ee5f44ac6df57a0eb09f9e208df2e..8079089a5814e6cb5cce87efccd262cc4a0b8cb6 100644 --- a/common/src/main/ets/default/manager/NavigationBarCommonEventManager.ts +++ b/common/src/main/ets/default/manager/NavigationBarCommonEventManager.ts @@ -13,11 +13,8 @@ * limitations under the License. */ -import CommonEvent from '@ohos.commonEvent'; import { AsyncCallback, BusinessError} from '@ohos.base'; -import { CommonEventData } from 'commonEvent/commonEventData'; -import { CommonEventSubscriber } from 'commonEvent/commonEventSubscriber'; -import { CommonEventSubscribeInfo } from 'commonEvent/commonEventSubscribeInfo'; +import commonEventMgr from '@ohos.commonEventManager'; import { EventConstants } from '../constants/EventConstants'; import { localEventManager } from './LocalEventManager'; import commonEventManager from './CommonEventManager'; @@ -29,71 +26,74 @@ const TAG = 'NavigationBarCommonEventManager'; * Wrapper class for NavigationBarCommonEvent interfaces. */ class NavigationBarCommonEventManager { - private static NAVIGATION_BAR_HIDE = 'systemui.event.NAVIGATIONBAR_HIDE'; - private static subscriber: CommonEventSubscriber; - private static eventCallback: AsyncCallback; + private static NAVIGATION_BAR_HIDE = 'systemui.event.NAVIGATIONBAR_HIDE'; + private static subscriber: commonEventMgr.CommonEventSubscriber; + private static eventCallback: AsyncCallback; - /** - * get NavigationBarCommonEvent instance - * - * @return NavigationBarCommonEvent singleton - */ - static getInstance(): NavigationBarCommonEventManager { - if (globalThis.NavigationBarCommonEvent == null) { - globalThis.NavigationBarCommonEvent = new NavigationBarCommonEventManager(); - this.eventCallback = this.navigationBarEventCallback.bind(this); - this.initSubscriber(); - } - return globalThis.NavigationBarCommonEvent; + /** + * get NavigationBarCommonEvent instance + * + * @return NavigationBarCommonEvent singleton + */ + static getInstance(): NavigationBarCommonEventManager { + if (globalThis.NavigationBarCommonEvent == null) { + globalThis.NavigationBarCommonEvent = new NavigationBarCommonEventManager(); + this.eventCallback = this.navigationBarEventCallback.bind(this); + this.initSubscriber(); } + return globalThis.NavigationBarCommonEvent; + } - private static initSubscriber() { - if (NavigationBarCommonEventManager.subscriber != null) { - return; - } - const subscribeInfo: CommonEventSubscribeInfo = { - events: [NavigationBarCommonEventManager.NAVIGATION_BAR_HIDE] - }; - CommonEvent.createSubscriber(subscribeInfo).then((commonEventSubscriber: CommonEventSubscriber) => { - Log.showDebug(TAG, "init SPLIT_SCREEN subscriber success"); - NavigationBarCommonEventManager.subscriber = commonEventSubscriber; - }, (err) => { - Log.showError(TAG, `Failed to createSubscriber ${err}`) - }) + private static initSubscriber() { + if (NavigationBarCommonEventManager.subscriber != null) { + return; } + const subscribeInfo: commonEventMgr.CommonEventSubscribeInfo = { + events: [NavigationBarCommonEventManager.NAVIGATION_BAR_HIDE] + }; + commonEventMgr.createSubscriber(subscribeInfo).then( + (commonEventSubscriber: commonEventMgr.CommonEventSubscriber) => { + Log.showDebug(TAG, "init SPLIT_SCREEN subscriber success"); + NavigationBarCommonEventManager.subscriber = commonEventSubscriber; + }, (err) => { + Log.showError(TAG, `Failed to createSubscriber ${err}`); + }) + } - /** - * Register navigationBar event listener. - */ - public registerNavigationBarEvent() { - commonEventManager.registerCommonEvent(NavigationBarCommonEventManager.subscriber, NavigationBarCommonEventManager.eventCallback); - } + /** + * Register navigationBar event listener. + */ + public registerNavigationBarEvent() { + commonEventManager.registerCommonEvent(NavigationBarCommonEventManager.subscriber, + NavigationBarCommonEventManager.eventCallback); + } - /** - * Unregister navigationBar event listener. - */ - public unregisterNavigationBarEvent() { - commonEventManager.unregisterCommonEvent(NavigationBarCommonEventManager.subscriber, NavigationBarCommonEventManager.eventCallback); - } + /** + * Unregister navigationBar event listener. + */ + public unregisterNavigationBarEvent() { + commonEventManager.unregisterCommonEvent(NavigationBarCommonEventManager.subscriber, + NavigationBarCommonEventManager.eventCallback); + } - /** - * navigationBar event handler. - */ - private static async navigationBarEventCallback(error: BusinessError, data: CommonEventData) { - Log.showDebug(TAG,`navigationBarEventCallback receive data: ${JSON.stringify(data)}.`); - if (error.code != 0) { - Log.showError(TAG, `navigationBarEventCallback error: ${JSON.stringify(error)}`); - return; - } - switch (data.event) { - case NavigationBarCommonEventManager.NAVIGATION_BAR_HIDE: - setTimeout(() => { - localEventManager.sendLocalEventSticky(EventConstants.EVENT_NAVIGATOR_BAR_STATUS_CHANGE, '0'); - }, 30) - default: - break; - } + /** + * navigationBar event handler. + */ + private static async navigationBarEventCallback(error: BusinessError, data: commonEventMgr.CommonEventData) { + Log.showDebug(TAG,`navigationBarEventCallback receive data: ${JSON.stringify(data)}.`); + if (data.code !== 0) { + Log.showError(TAG, `navigationBarEventCallback error: ${JSON.stringify(error)}`); + return; + } + switch (data.event) { + case NavigationBarCommonEventManager.NAVIGATION_BAR_HIDE: + setTimeout(() => { + localEventManager.sendLocalEventSticky(EventConstants.EVENT_NAVIGATOR_BAR_STATUS_CHANGE, '0'); + }, 30) + default: + break; } + } } export const navigationBarCommonEventManager = NavigationBarCommonEventManager.getInstance(); \ No newline at end of file diff --git a/common/src/main/ets/default/manager/RdbStoreManager.ts b/common/src/main/ets/default/manager/RdbStoreManager.ts index b5d5f857fc5893da6cc4954678ee8114cd70338d..036975865eedb99210bc20e2da93d710c0e83516 100644 --- a/common/src/main/ets/default/manager/RdbStoreManager.ts +++ b/common/src/main/ets/default/manager/RdbStoreManager.ts @@ -13,7 +13,9 @@ * limitations under the License. */ -import dataRdb from '@ohos.data.rdb'; +import relationalStore from '@ohos.data.relationalStore'; +import { BusinessError } from '@ohos.base'; +import deviceInfo from '@ohos.deviceInfo'; import hiSysEvent from '@ohos.hiSysEvent'; import { Log } from '../utils/Log'; import { CheckEmptyUtils } from '../utils/CheckEmptyUtils'; @@ -27,6 +29,8 @@ import GridLayoutItemInfo from '../bean/GridLayoutItemInfo'; import GridLayoutItemBuilder from '../bean/GridLayoutItemBuilder'; import GridLayoutInfoColumns from '../bean/GridLayoutInfoColumns'; import DesktopApplicationColumns from '../bean/DesktopApplicationColumns'; +import { GridLayoutInfo } from '../interface'; +import { LauncherDragItemInfo } from '../bean'; const TAG = 'RdbStoreManager'; @@ -34,7 +38,7 @@ const TAG = 'RdbStoreManager'; * Wrapper class for rdb interfaces. */ export class RdbStoreManager { - private mRdbStore; + private mRdbStore: relationalStore.RdbStore; private constructor() { } @@ -52,20 +56,23 @@ export class RdbStoreManager { async initRdbConfig(): Promise { Log.showInfo(TAG, 'initRdbConfig start'); - await dataRdb.getRdbStore(globalThis.desktopContext, { - name: RdbStoreConfig.DB_NAME - }, RdbStoreConfig.DB_VERSION) - .then((rdbStore) => { - this.mRdbStore = rdbStore; - }) - .catch((error) => { - Log.showError(TAG, `initRdbConfig Failed to obtain the rdbStore. Cause: ${error.message}`); - }); + try { + const STORE_CONFIG: relationalStore.StoreConfig = { + name: RdbStoreConfig.DB_NAME, + securityLevel: relationalStore.SecurityLevel.S3 + }; + + this.mRdbStore = await relationalStore.getRdbStore(globalThis.desktopContext, STORE_CONFIG); + } catch (error) { + let err = error as BusinessError; + Log.showError(TAG, `initRdbConfig Failed. code: ${err.code}, message: ${err.message}`); + } } async createTable(): Promise { Log.showDebug(TAG, 'create table start'); try { + await this.mRdbStore.executeSql(RdbStoreConfig.Settings.CREATE_TABLE); await this.mRdbStore.executeSql(RdbStoreConfig.Badge.CREATE_TABLE); await this.mRdbStore.executeSql(RdbStoreConfig.Form.CREATE_TABLE); await this.mRdbStore.executeSql(RdbStoreConfig.SmartDock.CREATE_TABLE); @@ -75,24 +82,24 @@ export class RdbStoreManager { // set default settings data await this.updateSettings(); } catch (error) { - Log.showError(TAG, `create table error: ${error}`); + Log.showError(TAG, `createTable error: ${JSON.stringify(error)}`); } Log.showDebug(TAG, 'create table end'); } async getAllBadge(): Promise { Log.showDebug(TAG, 'getAllBadge start'); - const predicates = new dataRdb.RdbPredicates(RdbStoreConfig.Badge.TABLE_NAME); + const predicates = new relationalStore.RdbPredicates(RdbStoreConfig.Badge.TABLE_NAME); const resultList: BadgeItemInfo[] = []; try { - let resultSet = await this.mRdbStore.query(predicates, []); + let resultSet = await this.mRdbStore.query(predicates); let isLast = resultSet.goToFirstRow(); while (isLast) { const itemInfo: BadgeItemInfo = new BadgeItemInfo(); - itemInfo.id = resultSet.getLong(resultSet.getColumnIndex('id')); + itemInfo.id = resultSet.getString(resultSet.getColumnIndex('id')); itemInfo.bundleName = resultSet.getString(resultSet.getColumnIndex('bundle_name')); itemInfo.badgeNumber = resultSet.getLong(resultSet.getColumnIndex('badge_number')); - itemInfo.display = resultSet.getLong(resultSet.getColumnIndex('display')); + itemInfo.display = this.numberToBoolean(resultSet.getLong(resultSet.getColumnIndex('display'))); itemInfo.userId = resultSet.getLong(resultSet.getColumnIndex('user_id')); resultList.push(itemInfo); isLast = resultSet.goToNextRow(); @@ -112,16 +119,16 @@ export class RdbStoreManager { return resultList; } try { - const predicates = new dataRdb.RdbPredicates(RdbStoreConfig.Badge.TABLE_NAME); + const predicates = new relationalStore.RdbPredicates(RdbStoreConfig.Badge.TABLE_NAME); predicates.equalTo('bundle_name', bundleName); - let resultSet = await this.mRdbStore.query(predicates, []); + let resultSet = await this.mRdbStore.query(predicates); let isLast = resultSet.goToFirstRow(); while (isLast) { const itemInfo: BadgeItemInfo = new BadgeItemInfo(); - itemInfo.id = resultSet.getLong(resultSet.getColumnIndex('id')); + itemInfo.id = resultSet.getString(resultSet.getColumnIndex('id')); itemInfo.bundleName = resultSet.getString(resultSet.getColumnIndex('bundle_name')); itemInfo.badgeNumber = resultSet.getLong(resultSet.getColumnIndex('badge_number')); - itemInfo.display = resultSet.getLong(resultSet.getColumnIndex('display')); + itemInfo.display = this.numberToBoolean(resultSet.getLong(resultSet.getColumnIndex('display'))); itemInfo.userId = resultSet.getLong(resultSet.getColumnIndex('user_id')); resultList.push(itemInfo); isLast = resultSet.goToNextRow(); @@ -141,7 +148,7 @@ export class RdbStoreManager { return result; } try { - const predicates = new dataRdb.RdbPredicates(RdbStoreConfig.Badge.TABLE_NAME); + const predicates = new relationalStore.RdbPredicates(RdbStoreConfig.Badge.TABLE_NAME); predicates.equalTo('bundle_name', bundleName); const updateBucket = { 'badge_number': badgeNum @@ -172,7 +179,7 @@ export class RdbStoreManager { return result; } try { - const predicates = new dataRdb.RdbPredicates(RdbStoreConfig.Badge.TABLE_NAME); + const predicates = new relationalStore.RdbPredicates(RdbStoreConfig.Badge.TABLE_NAME); predicates.equalTo('bundle_name', bundleName); const changeRows = await this.mRdbStore.delete(predicates); if (changeRows == 1) { @@ -192,13 +199,13 @@ export class RdbStoreManager { */ async getAllFormInfos(cardId = CommonConstants.INVALID_VALUE): Promise { Log.showDebug(TAG, 'getAllFormInfos start'); - const predicates = new dataRdb.RdbPredicates(RdbStoreConfig.Form.TABLE_NAME); + const predicates = new relationalStore.RdbPredicates(RdbStoreConfig.Form.TABLE_NAME); if (cardId != CommonConstants.INVALID_VALUE) { predicates.equalTo('card_id', cardId); } const resultList: CardItemInfo[] = []; try { - let resultSet = await this.mRdbStore.query(predicates, []); + let resultSet = await this.mRdbStore.query(predicates); let isLast = resultSet.goToFirstRow(); while (isLast) { const itemInfo: CardItemInfo = new CardItemInfo(); @@ -237,7 +244,7 @@ export class RdbStoreManager { Log.showDebug(TAG, 'updateFormInfoById start'); let result = false; try { - const predicates = new dataRdb.RdbPredicates(RdbStoreConfig.Form.TABLE_NAME); + const predicates = new relationalStore.RdbPredicates(RdbStoreConfig.Form.TABLE_NAME); predicates.equalTo('card_id', cardItemInfo.cardId); const updateBucket = { 'card_name': cardItemInfo.cardName, @@ -275,7 +282,7 @@ export class RdbStoreManager { Log.showDebug(TAG, 'deleteFormInfoById start'); let result = false; try { - const predicates = new dataRdb.RdbPredicates(RdbStoreConfig.Form.TABLE_NAME); + const predicates = new relationalStore.RdbPredicates(RdbStoreConfig.Form.TABLE_NAME); predicates.equalTo('card_id', cardId); const changeRows = await this.mRdbStore.delete(predicates); if (changeRows == 1) { @@ -291,7 +298,7 @@ export class RdbStoreManager { Log.showDebug(TAG, 'deleteFormInfoByBundle start'); let result = false; try { - const predicates = new dataRdb.RdbPredicates(RdbStoreConfig.Form.TABLE_NAME); + const predicates = new relationalStore.RdbPredicates(RdbStoreConfig.Form.TABLE_NAME); predicates.equalTo('bundle_name', bundleName); const changeRows = await this.mRdbStore.delete(predicates); if (changeRows == 1) { @@ -315,7 +322,7 @@ export class RdbStoreManager { let result = false; try { // get deviceType - let deviceType = AppStorage.get('deviceType'); + let deviceType = deviceInfo.deviceType; // init default settings config if (CheckEmptyUtils.isEmpty(key) || CheckEmptyUtils.isEmpty(value)) { @@ -329,10 +336,12 @@ export class RdbStoreManager { }; // insert sql let ret = await this.mRdbStore.insert(RdbStoreConfig.Settings.TABLE_NAME, firstDbData); + Log.showDebug(TAG, `updateSettings insert successful. ${ret}`); } else { // update settings by key and value let sql = `UPDATE ${RdbStoreConfig.Settings.TABLE_NAME} SET ${key} = '${value}' WHERE id = 1`; - await this.mRdbStore.executeSql(sql) + await this.mRdbStore.executeSql(sql); + Log.showDebug(TAG, `updateSettings update successful.`); } } catch (e) { Log.showError(TAG, 'updateSettings error:' + JSON.stringify(e)); @@ -348,22 +357,23 @@ export class RdbStoreManager { await this.deleteTable(RdbStoreConfig.SmartDock.TABLE_NAME); // insert into smartdock - for (let i in dockInfoList) { - let smartdockDbItem = { - 'item_type': dockInfoList[i].itemType, - 'editable': this.booleanToNumber(dockInfoList[i].editable), - 'bundle_name': dockInfoList[i].bundleName, - 'ability_name': dockInfoList[i].abilityName, - 'module_name': dockInfoList[i].moduleName, - 'app_icon_id': dockInfoList[i].appIconId, - 'app_label_id': dockInfoList[i].appLabelId, - 'app_name': dockInfoList[i].appName, - 'is_system_app': this.booleanToNumber(dockInfoList[i].isSystemApp), - 'is_uninstallAble': this.booleanToNumber(dockInfoList[i].isUninstallAble), - 'key_name': dockInfoList[i].keyName, - 'install_time': dockInfoList[i].installTime + for (const element of dockInfoList) { + let smartDockDbItem = { + 'item_type': element.itemType, + 'editable': this.booleanToNumber(element.editable), + 'bundle_name': element.bundleName, + 'ability_name': element.abilityName, + 'module_name': element.moduleName, + 'app_icon_id': element.appIconId, + 'app_label_id': element.appLabelId, + 'app_name': element.appName, + 'is_system_app': this.booleanToNumber(element.isSystemApp), + 'is_uninstallAble': this.booleanToNumber(element.isUninstallAble), + 'key_name': element.keyName, + 'install_time': element.installTime } - let ret = await this.mRdbStore.insert(RdbStoreConfig.SmartDock.TABLE_NAME, smartdockDbItem); + let ret = await this.mRdbStore.insert(RdbStoreConfig.SmartDock.TABLE_NAME, smartDockDbItem); + Log.showDebug(TAG, `insertIntoSmartdock insert successful. ${ret}-${element.keyName}`); } } catch (e) { Log.showError(TAG, 'insertIntoSmartdock error:' + JSON.stringify(e)); @@ -381,10 +391,11 @@ export class RdbStoreManager { async deleteTable(tableName: string): Promise { Log.showDebug(TAG, 'deleteTable start'); try { - let detelSql = `DELETE FROM ${tableName};` - let detelSequenceSql = `UPDATE sqlite_sequence SET seq=0 WHERE name = '${tableName}';` - await this.mRdbStore.executeSql(detelSql, function () {}) - await this.mRdbStore.executeSql(detelSequenceSql, function () {}) + let detelSql = `DELETE FROM ${tableName};`; + let detelSequenceSql = `UPDATE sqlite_sequence SET seq=0 WHERE name = '${tableName}';`; + await this.mRdbStore.executeSql(detelSql); + await this.mRdbStore.executeSql(detelSequenceSql); + Log.showDebug(TAG, 'deleteTable successful.'); } catch (e) { Log.showError(TAG, `deleteTable err: ${JSON.stringify(e)}`); } @@ -402,6 +413,7 @@ export class RdbStoreManager { let dropSql = `DROP TABLE IF EXISTS ${tableName}`; await this.mRdbStore.executeSql(dropSql); await this.mRdbStore.executeSql(RdbStoreConfig.GridLayoutInfo.CREATE_TABLE); + Log.showDebug(TAG, 'dropTable successful.'); } catch (e) { Log.showError(TAG, `dropTable err: ${JSON.stringify(e)}`); } @@ -410,8 +422,8 @@ export class RdbStoreManager { async querySmartDock(): Promise { const resultList: DockItemInfo[] = []; try { - const predicates = new dataRdb.RdbPredicates(RdbStoreConfig.SmartDock.TABLE_NAME); - let resultSet = await this.mRdbStore.query(predicates, []); + const predicates = new relationalStore.RdbPredicates(RdbStoreConfig.SmartDock.TABLE_NAME); + let resultSet = await this.mRdbStore.query(predicates); let isLast = resultSet.goToFirstRow(); while (isLast) { const itemInfo: DockItemInfo = new DockItemInfo(); @@ -430,7 +442,7 @@ export class RdbStoreManager { resultList.push(itemInfo); isLast = resultSet.goToNextRow(); } - resultSet.close() + resultSet.close(); resultSet = null; } catch (e) { Log.showError(TAG, 'querySmartDock error:' + JSON.stringify(e)); @@ -503,8 +515,8 @@ export class RdbStoreManager { async queryDesktopApplication(): Promise { const resultList: AppItemInfo[] = []; try { - const predicates = new dataRdb.RdbPredicates(RdbStoreConfig.DesktopApplicationInfo.TABLE_NAME); - let resultSet = await this.mRdbStore.query(predicates, []); + const predicates = new relationalStore.RdbPredicates(RdbStoreConfig.DesktopApplicationInfo.TABLE_NAME); + let resultSet = await this.mRdbStore.query(predicates); let isLast = resultSet.goToFirstRow(); while (isLast) { let appItemInfo: AppItemInfo = new AppItemInfo(); @@ -530,9 +542,9 @@ export class RdbStoreManager { return resultList; } - async insertGridLayoutInfo(gridlayoutinfo: any): Promise { + async insertGridLayoutInfo(gridLayoutInfo: GridLayoutInfo): Promise { Log.showDebug(TAG, 'insertGridLayoutInfo start'); - if (CheckEmptyUtils.isEmpty(gridlayoutinfo) || CheckEmptyUtils.isEmptyArr(gridlayoutinfo.layoutInfo)) { + if (CheckEmptyUtils.isEmpty(gridLayoutInfo) || CheckEmptyUtils.isEmptyArr(gridLayoutInfo.layoutInfo)) { Log.showError(TAG, 'insertGridLayoutInfo gridlayoutinfo is empty'); return; } @@ -541,9 +553,8 @@ export class RdbStoreManager { // delete gridlayoutinfo table await this.dropTable(RdbStoreConfig.GridLayoutInfo.TABLE_NAME); // insert into gridlayoutinfo - let layoutinfo: any[] = gridlayoutinfo.layoutInfo; - for (let i in layoutinfo) { - let element = layoutinfo[i]; + let layoutInfo: Array = gridLayoutInfo.layoutInfo; + for (const element of layoutInfo) { let item = {}; if (element.typeId === CommonConstants.TYPE_APP) { item = { @@ -558,10 +569,8 @@ export class RdbStoreManager { 'row': element.row, 'container': -100, 'badge_number': element.badgeNumber - } - - let ret = await this.mRdbStore.insert(RdbStoreConfig.GridLayoutInfo.TABLE_NAME, item); - + }; + await this.mRdbStore.insert(RdbStoreConfig.GridLayoutInfo.TABLE_NAME, item); } else if (element.typeId === CommonConstants.TYPE_CARD) { item = { 'bundle_name':element.bundleName, @@ -576,7 +585,7 @@ export class RdbStoreManager { 'row': element.row, 'container': -100, 'badge_number': element.badgeNumber - } + }; await this.mRdbStore.insert(RdbStoreConfig.GridLayoutInfo.TABLE_NAME, item); } else { item = { @@ -592,10 +601,11 @@ export class RdbStoreManager { 'row': element.row, 'container': -100, 'badge_number': element.badgeNumber - } + }; Log.showDebug(TAG, `element prev: ${JSON.stringify(element)}`); let ret: number = await this.mRdbStore.insert(RdbStoreConfig.GridLayoutInfo.TABLE_NAME, item); - if (ret > 0) { + Log.showDebug(TAG, `element ret: ${JSON.stringify(ret)}`); + if (ret !== -1) { await this.insertLayoutInfo(element.layoutInfo, ret); } } @@ -606,7 +616,7 @@ export class RdbStoreManager { } } - private async insertLayoutInfo(layoutInfo: [[]], container: number): Promise { + private async insertLayoutInfo(layoutInfo: AppItemInfo[][], container: number): Promise { Log.showDebug(TAG, 'insertLayoutInfo start'); let result: boolean = true; if (CheckEmptyUtils.isEmptyArr(layoutInfo)) { @@ -614,10 +624,8 @@ export class RdbStoreManager { result = false; return result; } - for (var i in layoutInfo) { - let curItem = layoutInfo[i]; - for (let j in curItem) { - let bigFolderApp: any = curItem[j]; + for (const curItem of layoutInfo) { + for (const bigFolderApp of curItem) { let item = { 'container': container, 'app_name': bigFolderApp.appName, @@ -636,8 +644,9 @@ export class RdbStoreManager { 'column': bigFolderApp.column, 'row': bigFolderApp.row, 'badge_number': bigFolderApp.badgeNumber - } + }; let ret: number = await this.mRdbStore.insert(RdbStoreConfig.GridLayoutInfo.TABLE_NAME, item); + Log.showDebug(TAG, `insertLayoutInfo ret ${container}-${ret}`); if (ret === -1) { result = false; } @@ -649,9 +658,9 @@ export class RdbStoreManager { async queryGridLayoutInfo(): Promise { const resultList: GridLayoutItemInfo[] = []; try { - const predicates = new dataRdb.RdbPredicates(RdbStoreConfig.GridLayoutInfo.TABLE_NAME); + const predicates = new relationalStore.RdbPredicates(RdbStoreConfig.GridLayoutInfo.TABLE_NAME); predicates.equalTo(GridLayoutInfoColumns.CONTAINER, -100); - let resultSet = await this.mRdbStore.query(predicates, []); + let resultSet = await this.mRdbStore.query(predicates); let isLast = resultSet.goToFirstRow(); while (isLast) { let typeId: number = resultSet.getLong(resultSet.getColumnIndex(GridLayoutInfoColumns.TYPE_ID)); @@ -664,7 +673,7 @@ export class RdbStoreManager { resultList.push(builder.buildGridLayoutItem()); isLast = resultSet.goToNextRow(); } - resultSet.close() + resultSet.close(); resultSet = null; } catch (e) { Log.showError(TAG, 'queryGridLayoutInfo error:' + JSON.stringify(e)); @@ -675,7 +684,7 @@ export class RdbStoreManager { private async queryLayoutInfo(container: number): Promise { const resultList: AppItemInfo[] = []; try { - let layoutPredicates = new dataRdb.RdbPredicates(RdbStoreConfig.GridLayoutInfo.TABLE_NAME); + let layoutPredicates = new relationalStore.RdbPredicates(RdbStoreConfig.GridLayoutInfo.TABLE_NAME); layoutPredicates.equalTo("container", container); let columns = [GridLayoutInfoColumns.APP_NAME, GridLayoutInfoColumns.IS_SYSTEM_APP, @@ -687,11 +696,14 @@ export class RdbStoreManager { GridLayoutInfoColumns.MODULE_NAME, GridLayoutInfoColumns.KEY_NAME, GridLayoutInfoColumns.CONTAINER, + GridLayoutInfoColumns.INSTALL_TIME, GridLayoutInfoColumns.TYPE_ID, GridLayoutInfoColumns.AREA, GridLayoutInfoColumns.PAGE, GridLayoutInfoColumns.COLUMN, GridLayoutInfoColumns.ROW]; + + // columns - The columns to query. If the value is null, the query applies to all columns. let resultSet = await this.mRdbStore.query(layoutPredicates, columns); let isLast = resultSet.goToFirstRow(); while (isLast) { @@ -699,7 +711,7 @@ export class RdbStoreManager { resultList.push(itemInfo); isLast = resultSet.goToNextRow(); } - resultSet.close() + resultSet.close(); resultSet = null; } catch (e) { Log.showError(TAG, 'queryLayoutInfo error:' + JSON.stringify(e)); diff --git a/common/src/main/ets/default/manager/SettingsDataManager.ts b/common/src/main/ets/default/manager/SettingsDataManager.ts index 2d1c91dea316648b7af2f2661fc65439d2a681fa..1c0339b78df0d660e362b8f94c2773262d9a090e 100644 --- a/common/src/main/ets/default/manager/SettingsDataManager.ts +++ b/common/src/main/ets/default/manager/SettingsDataManager.ts @@ -15,9 +15,10 @@ */ import { Log } from '../utils/Log'; -import { DataAbilityHelper } from 'ability/dataAbilityHelper'; import settings from '@ohos.settings'; import dataShare from '@ohos.data.dataShare'; +import common from '@ohos.app.ability.common'; +import { Context } from '@ohos.abilityAccessCtrl'; const TAG = 'SettingsDataManager' /** @@ -25,7 +26,7 @@ const TAG = 'SettingsDataManager' */ class SettingsDataManager { private readonly uriShare: string = 'datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true&key='; - private dataShareHelper; + private dataShareHelper: dataShare.DataShareHelper | null = null; private constructor() { } @@ -54,9 +55,13 @@ class SettingsDataManager { /** * Update settingData by settingDataKey. */ - setValue(helper: any, settingDataKey: string, value: string): void { + setValue(helper: dataShare.DataShareHelper | null, settingDataKey: string, value: string): void { Log.showInfo(TAG, "setValue:" + value) - settings.setValueSync(globalThis.desktopContext, settingDataKey, value); + if (typeof globalThis.desktopContext === 'undefined') { + settings.setValueSync(globalThis.settingsContext as Context, settingDataKey, value); + } else { + settings.setValueSync(globalThis.desktopContext as Context, settingDataKey, value); + } } /** @@ -64,8 +69,13 @@ class SettingsDataManager { * * @return settingsDataValue by settingDataKey. */ - getValue(helper: any, settingDataKey: string, defaultValue: string): string { - let value: string = settings.getValueSync(globalThis.desktopContext, settingDataKey, defaultValue); + getValue(helper: dataShare.DataShareHelper | null, settingDataKey: string, defaultValue: string): string { + let value: string = '1'; + if (typeof globalThis.desktopContext === 'undefined') { + value = settings.getValueSync(globalThis.settingsContext as Context, settingDataKey, defaultValue); + } else { + value = settings.getValueSync(globalThis.desktopContext as Context, settingDataKey, defaultValue); + } Log.showInfo(TAG, "getValue:" + value); return value; } @@ -84,8 +94,7 @@ class SettingsDataManager { * * @return settingDataHelper by settingDataUri. */ - getHelper(context: any, uri: string): any{ - // @ts-ignore api8 d.ts + getHelper(context: common.Context, uri: string): dataShare.DataShareHelper | null { return this.dataShareHelper; } } diff --git a/common/src/main/ets/default/manager/WindowManager.ts b/common/src/main/ets/default/manager/WindowManager.ts index feeb442c13cb21f3652547acd000852e1717672e..6a0e1cf9f288728e91a95710d1f4d74ec06458b8 100644 --- a/common/src/main/ets/default/manager/WindowManager.ts +++ b/common/src/main/ets/default/manager/WindowManager.ts @@ -15,14 +15,10 @@ import Window from '@ohos.window'; import display from '@ohos.display'; -import CommonEvent from '@ohos.commonEvent'; -import featureAbility from '@ohos.ability.featureAbility'; -import ServiceExtensionContext from 'application/ServiceExtensionContext'; -import { AsyncCallback, BusinessError} from '@ohos.base'; -import { CommonEventData } from 'commonEvent/commonEventData'; -import { CommonEventSubscriber } from 'commonEvent/commonEventSubscriber'; -import { CommonEventSubscribeInfo } from 'commonEvent/commonEventSubscribeInfo'; - +import commonEventMgr from '@ohos.commonEventManager'; +import common from '@ohos.app.ability.common'; +import { AsyncCallback, BusinessError } from '@ohos.base'; +import AbilityConstant from '@ohos.app.ability.AbilityConstant'; import commonEventManager from './CommonEventManager' import { Log } from '../utils/Log'; import { StyleConstants } from '../constants/StyleConstants'; @@ -33,11 +29,11 @@ const TAG = 'WindowManager'; * Wrapper class for window interfaces. */ class WindowManager { - private mDisplayData = null; + private mDisplayData: display.Display | null = null; - private static subscriber: CommonEventSubscriber; + private static subscriber: commonEventMgr.CommonEventSubscriber; - private static eventCallback: AsyncCallback; + private static eventCallback: AsyncCallback; RECENT_WINDOW_NAME = 'RecentView'; @@ -76,11 +72,11 @@ class WindowManager { * * @return windowWidth */ - async getWindowWidth() { + getWindowWidth(): number { if (this.mDisplayData == null) { - this.mDisplayData = await this.getWindowDisplayData(); + this.mDisplayData = this.getWindowDisplayData(); } - return px2vp(this.mDisplayData.width); + return this.mDisplayData?.width as number; } /** @@ -88,27 +84,26 @@ class WindowManager { * * @return windowHeight */ - async getWindowHeight() { + getWindowHeight(): number { if (this.mDisplayData == null) { - this.mDisplayData = await this.getWindowDisplayData(); + this.mDisplayData = this.getWindowDisplayData(); } - return px2vp(this.mDisplayData.height); + return this.mDisplayData?.height as number; } - private async getWindowDisplayData() { - let displayData = null; - await display.getDefaultDisplay() - .then((res)=>{ - displayData = res; - }).catch((err)=>{ - Log.showError(TAG, 'getWindowDisplayData error:' + err); - }); + private getWindowDisplayData(): display.Display | null { + let displayData: display.Display | null = null; + try { + displayData = display.getDefaultDisplaySync(); + } catch(err) { + Log.showError(TAG, `display.getDefaultDisplaySync error: ${JSON.stringify(err)}`); + } return displayData; } isSplitWindowMode(mode): boolean { - if ((mode == featureAbility.AbilityWindowConfiguration.WINDOW_MODE_SPLIT_PRIMARY) || - (mode == featureAbility.AbilityWindowConfiguration.WINDOW_MODE_SPLIT_SECONDARY)) { + if ((mode === AbilityConstant.WindowMode.WINDOW_MODE_SPLIT_PRIMARY) || + (mode === AbilityConstant.WindowMode.WINDOW_MODE_SPLIT_SECONDARY)) { return true; } return false; @@ -121,8 +116,8 @@ class WindowManager { * @param height window height */ async setWindowSize(width: number, height: number): Promise { - const abilityWindow = await Window.getTopWindow(); - void abilityWindow.resetSize(width, height); + const abilityWindow = await Window.getLastWindow(globalThis.desktopContext as common.BaseContext); + void abilityWindow.resize(width, height); } /** @@ -132,8 +127,8 @@ class WindowManager { * @param y coordinate y */ async setWindowPosition(x: number, y: number): Promise { - const abilityWindow = await Window.getTopWindow(); - void abilityWindow.moveTo(x, y); + const abilityWindow = await Window.getLastWindow(globalThis.desktopContext as common.BaseContext); + void abilityWindow.moveWindowTo(x, y); } /** @@ -172,7 +167,7 @@ class WindowManager { }) } - createWindow(context: ServiceExtensionContext, name: string, windowType: number, loadContent: string, + createWindow(context: common.ServiceExtensionContext, name: string, windowType: number, loadContent: string, isShow: boolean, callback?: Function) { Window.create(context, name, windowType).then((win) => { void win.setPreferredOrientation(Window.Orientation.AUTO_ROTATION_RESTRICTED); @@ -203,7 +198,7 @@ class WindowManager { }); } - createWindowIfAbsent(context: ServiceExtensionContext, name: string, windowType: number, loadContent: string): void { + createWindowIfAbsent(context: common.ServiceExtensionContext, name: string, windowType: number, loadContent: string): void { Log.showDebug(TAG, `create, name ${name}`); Window.find(name).then(win => { void win.show().then(() => { @@ -258,11 +253,16 @@ class WindowManager { } minimizeAllApps(): void { - display.getDefaultDisplay().then(dis => { + try { + let dis: display.Display = display.getDefaultDisplaySync(); Window.minimizeAll(dis.id).then(() => { Log.showDebug(TAG, 'Launcher minimizeAll'); }); - }); + } catch (err) { + let errCode = (err as BusinessError).code; + let errMsg = (err as BusinessError).message; + Log.showError(TAG, `minimizeAllApps errCode: ${errCode}, errMsg: ${errMsg}`); + } this.destroyWindow(this.FORM_MANAGER_WINDOW_NAME); this.destroyWindow(this.FORM_SERVICE_WINDOW_NAME); } @@ -297,7 +297,7 @@ class WindowManager { windowManager.recentMode = mode; win.setWindowMode(mode).then(); } : (win) => { - windowManager.recentMode = featureAbility.AbilityWindowConfiguration.WINDOW_MODE_FULLSCREEN; + windowManager.recentMode = AbilityConstant.WindowMode.WINDOW_MODE_FULLSCREEN; win.setFullScreen(true).then(() => { Log.showDebug(TAG, `${this.RECENT_WINDOW_NAME} setFullScreen`); }); @@ -346,10 +346,10 @@ class WindowManager { if (WindowManager.subscriber != null) { return; } - const subscribeInfo: CommonEventSubscribeInfo = { + const subscribeInfo: commonEventMgr.CommonEventSubscribeInfo = { events: [commonEventManager.RECENT_FULL_SCREEN, commonEventManager.RECENT_SPLIT_SCREEN] }; - CommonEvent.createSubscriber(subscribeInfo).then((commonEventSubscriber: CommonEventSubscriber) => { + commonEventMgr.createSubscriber(subscribeInfo).then((commonEventSubscriber: commonEventMgr.CommonEventSubscriber) => { Log.showDebug(TAG, "init SPLIT_SCREEN subscriber success"); WindowManager.subscriber = commonEventSubscriber; }, (err) => { @@ -374,9 +374,9 @@ class WindowManager { /** * Window event handler. */ - private static async winEventCallback(error: BusinessError, data: CommonEventData) { + private static async winEventCallback(error: BusinessError, data: commonEventMgr.CommonEventData) { Log.showDebug(TAG,`Launcher WindowManager winEventCallback receive data: ${JSON.stringify(data)}.`); - if (error.code != 0) { + if (data.code !== 0) { Log.showError(TAG, `get winEventCallback error: ${JSON.stringify(error)}`); return; } @@ -389,15 +389,15 @@ class WindowManager { case commonEventManager.RECENT_SPLIT_SCREEN: // split window mode const windowModeMap = { - 'Primary': featureAbility.AbilityWindowConfiguration.WINDOW_MODE_SPLIT_PRIMARY, - 'Secondary': featureAbility.AbilityWindowConfiguration.WINDOW_MODE_SPLIT_SECONDARY + 'Primary': AbilityConstant.WindowMode.WINDOW_MODE_SPLIT_PRIMARY, + 'Secondary': AbilityConstant.WindowMode.WINDOW_MODE_SPLIT_SECONDARY }; - if (data.parameters.windowMode != 'Primary' && data.parameters.windowMode != 'Secondary') { + if (data.parameters.windowMode !== 'Primary' && data.parameters.windowMode !== 'Secondary') { break; } windowManager.createRecentWindow(windowModeMap[data.parameters.windowMode]); globalThis.splitMissionId = data.parameters.missionId; - await WindowManager.subscriber.setCode(0) + await WindowManager.subscriber.setCode(0); await WindowManager.subscriber.finishCommonEvent(); break; default: diff --git a/common/src/main/ets/default/model/FormModel.ts b/common/src/main/ets/default/model/FormModel.ts index 270c8f0f44da96ce8f3b0fb90d8e0d9cf61342e1..81e31c3ef02208f7ce30ecd5f8cd678f2eaa0040 100644 --- a/common/src/main/ets/default/model/FormModel.ts +++ b/common/src/main/ets/default/model/FormModel.ts @@ -22,6 +22,7 @@ import { FormManager } from '../manager/FormManager'; import { RdbStoreManager } from '../manager/RdbStoreManager'; import { FormListInfoCacheManager } from '../cache/FormListInfoCacheManager'; import {PageDesktopModel} from './PageDesktopModel'; +import { GridLayoutInfo } from '../interface'; const TAG = 'FormModel'; @@ -254,7 +255,8 @@ export class FormModel { */ async deleteForm(cardId) { Log.showDebug(TAG, 'deleteForm start'); - let gridLayoutInfo = { + let gridLayoutInfo: GridLayoutInfo = { + layoutDescription: undefined, layoutInfo: [] }; gridLayoutInfo = SettingsModel.getInstance().getLayoutInfo(); diff --git a/common/src/main/ets/default/model/SettingsModel.ts b/common/src/main/ets/default/model/SettingsModel.ts index 2179be33bb76e25caec0335d4097a19561e4f943..3c321e4bee90dc93fb8af77bfdea4ade02efff55 100644 --- a/common/src/main/ets/default/model/SettingsModel.ts +++ b/common/src/main/ets/default/model/SettingsModel.ts @@ -12,7 +12,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { DataAbilityHelper } from 'ability/dataAbilityHelper'; import { Log } from '../utils/Log'; import FileUtils from '../utils/FileUtils'; @@ -26,6 +25,8 @@ import { PageDesktopLayoutConfig } from '../layoutconfig/PageDesktopLayoutConfig import { PageDesktopAppModeConfig } from '../layoutconfig/PageDesktopAppModeConfig'; import { SettingsModelObserver } from './SettingsModelObserver'; import GridLayoutConfigs from '../configs/GridLayoutConfigs'; +import dataShare from '@ohos.data.dataShare'; +import { GridLayoutInfo } from '../interface'; const TAG = 'SettingsModel'; @@ -41,12 +42,12 @@ export class SettingsModel { private readonly mPageDesktopAppModeConfig: PageDesktopAppModeConfig; private mGridConfig = 1; private mGridLayoutTable = GridLayoutConfigs.GridLayoutTable; - private readonly uri: string = null; - private helper: any = null; + private readonly uri: string = ''; + private helper: dataShare.DataShareHelper | null = null; private readonly mObserverList: SettingsModelObserver[] = []; private constructor() { - this.mPageDesktopModeConfig = layoutConfigManager.getModeConfig(PageDesktopModeConfig.DESKTOP_MODE_CONFIG); + this.mPageDesktopModeConfig = PageDesktopModeConfig.getInstance(); const deviceType = this.mPageDesktopModeConfig.getDeviceType(); if (deviceType == CommonConstants.DEFAULT_DEVICE_TYPE) { this.mGridLayoutTable = GridLayoutConfigs.GridLayoutTable; @@ -228,7 +229,7 @@ export class SettingsModel { * * @return {object} layout information. */ - getLayoutInfo(): any { + getLayoutInfo(): GridLayoutInfo { this.updateMenuId(); return this.mPageDesktopLayoutConfig.getGridLayoutInfo(); } @@ -236,7 +237,7 @@ export class SettingsModel { /** * Set layout information of grid view. */ - setLayoutInfo(layoutInfo): void { + setLayoutInfo(layoutInfo: GridLayoutInfo): void { this.mPageDesktopLayoutConfig.updateGridLayoutInfo(layoutInfo); } @@ -287,7 +288,9 @@ export class SettingsModel { */ registerListenForDataChanges(callback): void { this.helper = settingsDataManager.getHelper(globalThis.desktopContext, this.uri); - this.helper.on('dataChange', this.uri, callback); + if (this.helper !== null) { + this.helper.on('dataChange', this.uri, callback); + } } private updateMenuId(): void { diff --git a/common/src/main/ets/default/uicomponents/AppIcon.ets b/common/src/main/ets/default/uicomponents/AppIcon.ets index 2d1e00e4de5fb71ad9eb86d659c5562295d36ded..bc436df968cb14361ea749f9b5aadd01f98123dd 100644 --- a/common/src/main/ets/default/uicomponents/AppIcon.ets +++ b/common/src/main/ets/default/uicomponents/AppIcon.ets @@ -17,17 +17,19 @@ import { Log } from '../utils/Log'; import { BadgeManager } from '../manager/BadgeManager'; import { StyleConstants } from '../constants/StyleConstants'; import { ResourceManager } from '../manager/ResourceManager'; +import { LauncherDragItemInfo } from '../bean/LauncherDragItemInfo'; const TAG = 'AppIcon'; @Component export struct AppIcon { + @StorageLink('dragItemInfo') @Watch('updateAppIcon') mDragItemInfo: LauncherDragItemInfo = new LauncherDragItemInfo(); iconSize: number = 0; iconId: number = 0; bundleName: string = ''; moduleName: string = ''; @State icon: string = ''; - badgeNumber: number = 0; + @State badgeNumber: number = 0; @State iconScale: number = 1; useCache: boolean = true; badgeFontSize: number = StyleConstants.DEFAULT_BADGE_FONT_SIZE; @@ -35,6 +37,13 @@ export struct AppIcon { private mBadgeManager = BadgeManager.getInstance(); private mDefaultAppIcon: ResourceStr = ''; + updateAppIcon() { + // 拖动图标到无效区域,松手后图标缩放恢复原有尺寸 + if (!this.mDragItemInfo.isDragging) { + this.iconScale = 1; + } + } + aboutToAppear(): void { this.mResourceManager = ResourceManager.getInstance(); this.mBadgeManager = BadgeManager.getInstance(); @@ -90,9 +99,9 @@ export struct AppIcon { } }) .onMouse((event: MouseEvent) => { - if (event.button == MouseButton.Left && event.action == MouseAction.Press) { + if (event.button === MouseButton.Left && event.action === MouseAction.Press) { this.iconScale = 0.9; - } else if (event.button == MouseButton.Left && event.action == MouseAction.Release) { + } else if (event.button === MouseButton.Left && event.action === MouseAction.Release) { this.iconScale = 1; } }) diff --git a/common/src/main/ets/default/uicomponents/FolderComponent.ets b/common/src/main/ets/default/uicomponents/FolderComponent.ets index 8f82fc2d32ba7c82decc91d6e51d001c2ca30118..7a9edb18f00a7d59816550da4475561ce760b5bc 100644 --- a/common/src/main/ets/default/uicomponents/FolderComponent.ets +++ b/common/src/main/ets/default/uicomponents/FolderComponent.ets @@ -26,6 +26,7 @@ import { LauncherDragItemInfo } from '../bean/LauncherDragItemInfo'; import { AppItemInfo } from '../bean/AppItemInfo'; import { FolderItemInfo } from '../bean/FolderItemInfo'; import { MenuInfo } from '../bean'; +import { FolderData } from '../interface/FolderData'; const TAG = 'FolderComponent'; @@ -75,8 +76,8 @@ export struct FolderComponent { private mShowAppList: AppItemInfo[] = []; private mSuperposeAppList: SuperposeApp[] = []; onAppIconClick: Function = (event: ClickEvent, item: AppItemInfo) => {}; - onOpenFolderClick: Function = (event: ClickEvent, folderItem: FolderItemInfo) => {}; - onFolderTouch: Function = (event: ClickEvent, folderItem: FolderItemInfo) => {}; + onOpenFolderClick: Function = (event: ClickEvent, folderItem: FolderData) => {}; + onFolderTouch: Function = (event: ClickEvent, folderItem: FolderData) => {}; onGetPosition: Function = (callback: (x: number, y: number) => void) => {}; buildMenu: (item: LauncherDragItemInfo) => MenuInfo[] = (item: LauncherDragItemInfo) => []; folderNameLines: number = PresetStyleConstants.DEFAULT_APP_NAME_LINES; diff --git a/common/src/main/ets/default/utils/GridLayoutUtil.ts b/common/src/main/ets/default/utils/GridLayoutUtil.ts index e21a2d626434c5e7bf793c7febc6e44ebe514fb0..06e02e396098b53af9caed631043e089f3fff055 100644 --- a/common/src/main/ets/default/utils/GridLayoutUtil.ts +++ b/common/src/main/ets/default/utils/GridLayoutUtil.ts @@ -12,6 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + +import { GridLayoutInfo } from '../interface'; import BitSet from './BitSet'; export default class GridLayoutUtil { @@ -23,7 +25,8 @@ export default class GridLayoutUtil { * * @return new GridLayoutInfo */ - static updateGridLayoutInfo(gridLayoutInfo: any, newLayoutRows: number, newLayoutColumns: number): any { + static updateGridLayoutInfo(gridLayoutInfo: GridLayoutInfo, newLayoutRows: number, + newLayoutColumns: number): GridLayoutInfo { gridLayoutInfo.layoutDescription.pageCount = GridLayoutUtil.updateLayoutInfo( gridLayoutInfo.layoutInfo, newLayoutRows, newLayoutColumns); gridLayoutInfo.layoutDescription.row = newLayoutRows; diff --git a/feature/appcenter/src/main/ets/default/viewmodel/AppListViewModel.ts b/feature/appcenter/src/main/ets/default/viewmodel/AppListViewModel.ts index 44cf0fb6eb64ea7e58beeea8c42877964df33b6a..b1cf3ad2ed5057536dc345401e7b1534aa04c008 100644 --- a/feature/appcenter/src/main/ets/default/viewmodel/AppListViewModel.ts +++ b/feature/appcenter/src/main/ets/default/viewmodel/AppListViewModel.ts @@ -23,6 +23,11 @@ import AppCenterGridStyleConfig from '../common/AppCenterGridStyleConfig'; const TAG = 'AppListViewModel'; +interface AnimationInfo { + appScaleX: number; + appScaleY: number; +} + const KEY_NAME = "name"; export class AppListViewModel extends BaseViewModel { @@ -62,7 +67,7 @@ export class AppListViewModel extends BaseViewModel { onFinish: () => { } }, () => { - let animationInfo:any = { + let animationInfo: AnimationInfo = { appScaleX: 0.97, appScaleY: 0.97 } diff --git a/feature/bigfolder/src/main/ets/default/common/constants/BigFolderStyleConstants.ts b/feature/bigfolder/src/main/ets/default/common/constants/BigFolderStyleConstants.ts index 8bc3c369740591b0314afb4dbcd4bbf4c14a089e..7d2c86b72cf53f65cda71421cb170b911c1e2cfd 100644 --- a/feature/bigfolder/src/main/ets/default/common/constants/BigFolderStyleConstants.ts +++ b/feature/bigfolder/src/main/ets/default/common/constants/BigFolderStyleConstants.ts @@ -16,7 +16,7 @@ export class BigFolderStyleConstants { // image resources - static readonly DEFAULT_ICON: any = $r('app.media.icon'); + static readonly DEFAULT_ICON = $r('app.media.icon'); static readonly DEFAULT_BACKGROUND_IMAGE = '$media:ic_wallpaper_folder'; static readonly DEFAULT_ADD_FOLDER_APP_IMAGE = '/common/pics/ic_public_add.svg'; static readonly DEFAULT_CANCEL_APP_IMAGE = '/common/pics/ic_public_cancel.svg'; diff --git a/feature/bigfolder/src/main/ets/default/common/uicomponents/FolderAppListDialog.ets b/feature/bigfolder/src/main/ets/default/common/uicomponents/FolderAppListDialog.ets index 201daf92eb23f2b73577a9696af8b77c9008e41b..8fd67379fe83139482f60ce610f500429ff36a56 100644 --- a/feature/bigfolder/src/main/ets/default/common/uicomponents/FolderAppListDialog.ets +++ b/feature/bigfolder/src/main/ets/default/common/uicomponents/FolderAppListDialog.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -import { AppItemInfo, Log } from '@ohos/common'; +import { AppItemInfo, FolderData, Log } from '@ohos/common'; import { AppIcon } from '@ohos/common/component'; import { AppName } from '@ohos/common/component'; import { CommonConstants } from '@ohos/common'; @@ -49,7 +49,7 @@ export default struct FolderAppListDialog { controller?: CustomDialogController; cancel = () => {}; confirm = (isDestory: boolean) => {}; - folderItem: FolderItemType = { layoutInfo: [], folderName: '', folderId: '' }; + folderItem: FolderData = { layoutInfo: [], folderName: '', folderId: '', enterEditing: false }; addToString: string = ''; aboutToAppear(): void { diff --git a/feature/bigfolder/src/main/ets/default/view/FolderOpenComponent.ets b/feature/bigfolder/src/main/ets/default/view/FolderOpenComponent.ets index 7cddbc481a4a9e43949ba09825345e828c6f8cea..78461cfa11a3591108c0d136e8b24ba9809fd5e5 100644 --- a/feature/bigfolder/src/main/ets/default/view/FolderOpenComponent.ets +++ b/feature/bigfolder/src/main/ets/default/view/FolderOpenComponent.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -import { Log , CheckEmptyUtils, AppItemInfo, FolderItemInfo, CardItemInfo } from '@ohos/common'; +import { Log , CheckEmptyUtils, AppItemInfo, FolderItemInfo, CardItemInfo, FolderData } from '@ohos/common'; import { Trace } from '@ohos/common'; import { EventConstants } from '@ohos/common'; import { StyleConstants } from '@ohos/common'; @@ -47,13 +47,6 @@ interface FolderOpenLayoutTable { checked: boolean; } -interface FolderInfo { - layoutInfo: AppItemInfo[][]; - enterEditing: boolean; - folderName: string; - folderId: string; -} - const FOLDER_CLOSE_DELAY = 500; let mBigFolderViewModel: BigFolderViewModel; let mBigFolderStyleConfig: BigFolderStyleConfig; @@ -82,7 +75,7 @@ export struct FolderOpenComponent { @StorageLink('openFolderStatus') @Watch('updateFolderData') openFolderStatus: number = BigFolderConstants.OPEN_FOLDER_STATUS_CLOSE; @State overLayAlpha: number = 0.3; @State isRenaming: boolean = false; - @StorageLink('openFolderData') mFolderInfo: FolderInfo = { layoutInfo: [], enterEditing: false, folderName: '', folderId: '' }; + @StorageLink('openFolderData') mFolderInfo: FolderData = { layoutInfo: [], enterEditing: false, folderName: '', folderId: '' }; @State newFolderName: string = ''; aboutToAppear(): void { @@ -306,15 +299,19 @@ struct FolderSwiperPage { @StorageLink('isDraging') isDraging: boolean = false; @Link isRenaming: boolean; @Prop newFolderName: string; - private mFolderInfo: FolderInfo = { layoutInfo: [], enterEditing: false, folderName: '', folderId: '' }; + private mFolderInfo: FolderData = { layoutInfo: [], enterEditing: false, folderName: '', folderId: '' }; private mAppInfo: AppItemInfo[] = []; private ColumnsTemplate: string = ''; private RowsTemplate: string = ''; private mGridGap = BigFolderStyleConfig.getInstance().mOpenFolderGridGap; @State mBigFolderViewModel: BigFolderViewModel = mBigFolderViewModel; + @State appNameAdd: string = ''; - aboutToAppear(): void { + aboutToAppear(): void { mFolderModel = BigFolderModel.getInstance(); + ResourceManager.getInstance().getStringByResource($r('app.string.add')).then((resName) => { + this.appNameAdd = resName; + }); this.updateConfig(); } @@ -378,15 +375,17 @@ struct FolderSwiperPage { .height(BigFolderStyleConstants.DEFAULT_ADD_APP_ICON_SIZE) }.margin({ top: mGridIconTopPadding }) - AppName({ - nameHeight: mAppNameHeight, - nameSize: mAppNameSize, - nameFontColor: BigFolderStyleConstants.DEFAULT_FONT_COLOR, - appName: item.appName, - useCache: false, - nameLines: mNameLines, - marginTop: mIconNameMargin - }) + if (this.appNameAdd) { + AppName({ + nameHeight: mAppNameHeight, + nameSize: mAppNameSize, + nameFontColor: BigFolderStyleConstants.DEFAULT_FONT_COLOR, + appName: this.appNameAdd, + useCache: false, + nameLines: mNameLines, + marginTop: mIconNameMargin + }) + } } .width(BigFolderStyleConstants.PERCENTAGE_100) .height(BigFolderStyleConstants.PERCENTAGE_100) @@ -456,7 +455,7 @@ struct FolderAppItem { private RowsTemplate: string = ''; private isSwappingPage = false; private willCloseFolder: boolean = false; - private mFolderInfo: FolderItemInfo = new FolderItemInfo(); + private mFolderInfo: FolderData = { layoutInfo: [], enterEditing: false, folderName: '', folderId: '' }; private mouseClick: number = 0; private dialogName: string = ""; private clearForm: Function = () => {}; diff --git a/feature/bigfolder/src/main/ets/default/viewmodel/BigFolderViewModel.ts b/feature/bigfolder/src/main/ets/default/viewmodel/BigFolderViewModel.ts index faed4de78f68e30b43816791908fc9609fd1d264..91bd226e1c9b3e719cafc7823519a556162161af 100644 --- a/feature/bigfolder/src/main/ets/default/viewmodel/BigFolderViewModel.ts +++ b/feature/bigfolder/src/main/ets/default/viewmodel/BigFolderViewModel.ts @@ -26,12 +26,17 @@ import { localEventManager, layoutConfigManager, FolderLayoutConfig, - AppItemInfo + AppItemInfo, + GridLayoutInfo, + FolderData, + LauncherDragItemInfo } from '@ohos/common'; import { BigFolderModel } from '../model/BigFolderModel'; import { BigFolderStyleConfig } from '../common/BigFolderStyleConfig'; import { BigFolderConstants } from '../common/constants/BigFolderConstants'; import { BigFolderStyleConstants } from '../common/constants/BigFolderStyleConstants'; +import GridLayoutItemInfo from '@ohos/common/src/main/ets/default/bean/GridLayoutItemInfo'; +import GridLayoutItemBuilder from '@ohos/common/src/main/ets/default/bean/GridLayoutItemBuilder'; const TAG = 'BigFolderViewModel'; const HEXADECIMAL_VALUE = 36; @@ -50,9 +55,7 @@ export class BigFolderViewModel extends BaseViewModel { Log.showDebug(TAG, `onReceiveEvent receive event: ${event}, params: ${JSON.stringify(params)}`); const openStatus = AppStorage.get('openFolderStatus'); if (event === EventConstants.EVENT_BADGE_UPDATE && (openStatus == BigFolderConstants.OPEN_FOLDER_STATUS_OPEN || openStatus == BigFolderConstants.OPEN_FOLDER_STATUS_STATIC)) { - const openFolderData: { - layoutInfo: [[]] - } = AppStorage.get('openFolderData'); + const openFolderData: FolderData = AppStorage.get('openFolderData'); this.updateBadge(openFolderData, params); } else if (event === EventConstants.EVENT_FOLDER_PACKAGE_REMOVED) { this.deleteAppFromFolderByUninstall(params); @@ -63,12 +66,12 @@ export class BigFolderViewModel extends BaseViewModel { }; // badge will be designed lastly - private updateBadge(openFolderData, params): void { + private updateBadge(openFolderData: FolderData, params: AppItemInfo): void { for (let i = 0; i < openFolderData.layoutInfo.length; i++) { - const appInfo: any = openFolderData.layoutInfo[i].find(item => { - return item.bundleName == params.bundleName; + const appInfo: AppItemInfo = openFolderData.layoutInfo[i].find(item => { + return item.bundleName === params.bundleName; }); - if (appInfo != undefined && appInfo.bundleName.length > 0) { + if (appInfo !== undefined && appInfo.bundleName.length > 0) { const index = openFolderData.layoutInfo[i].indexOf(appInfo); appInfo.badgeNumber = params.badgeNumber; openFolderData.layoutInfo[i][index] = appInfo; @@ -116,12 +119,12 @@ export class BigFolderViewModel extends BaseViewModel { /** * add new folder * - * @param {any} appLayoutInfo (two app for create new folder). + * @param {AppItemInfo[]} appLayoutInfo (two app for create new folder). */ - async addNewFolder(appLayoutInfo) { + async addNewFolder(appLayoutInfo: AppItemInfo[]) { const gridLayoutInfo = this.mSettingsModel.getLayoutInfo(); const settingAppInfoList = this.mSettingsModel.getAppListInfo(); - const folderAppInfo = []; + const folderAppInfo: AppItemInfo[] = []; for (let j = 0; j < appLayoutInfo.length; j++) { Log.showDebug(TAG, `addNewFolder appLayoutInfo: ${JSON.stringify(appLayoutInfo[j])}`) for (let i = 0; i < settingAppInfoList.length; i++) { @@ -142,7 +145,7 @@ export class BigFolderViewModel extends BaseViewModel { // Delete {the app list} from desktop app list for (let i = 0; i < appLayoutInfo.length; i++) { - const index = gridLayoutInfo.layoutInfo.indexOf(appLayoutInfo[i]); + const index = gridLayoutInfo.layoutInfo.indexOf(appLayoutInfo[i] as LauncherDragItemInfo); if (index != CommonConstants.INVALID_VALUE) { gridLayoutInfo.layoutInfo.splice(index, 1); } @@ -163,7 +166,7 @@ export class BigFolderViewModel extends BaseViewModel { } // Push folder into the layoutInfo,include {the app list} - gridLayoutInfo.layoutInfo.push(folderInfo); + gridLayoutInfo.layoutInfo.push(folderInfo as LauncherDragItemInfo); this.deleteAppLayoutItems(gridLayoutInfo, appLayoutInfo); if (needNewPage) { this.mPageDesktopModel.setPageIndex(this.mPageDesktopModel.getPageIndex() + 1); @@ -228,10 +231,10 @@ export class BigFolderViewModel extends BaseViewModel { /** * Delete app from folder by dragging * - * @param {any} folderAppList. + * @param {AppItemInfo[]} folderAppList. * @param {number} index. */ - deleteAppByDraging(folderAppList, index): boolean { + deleteAppByDraging(folderAppList: AppItemInfo[], index: number): boolean { const gridLayoutInfo = this.mSettingsModel.getLayoutInfo(); if (folderAppList.length == 0 || folderAppList.length <= index) { return false; @@ -250,10 +253,7 @@ export class BigFolderViewModel extends BaseViewModel { folderAppList.pop(); } const folderLayoutInfo = this.filterFolderPage(folderAppList); - const openFolderData: { - folderId: string, - layoutInfo: any - } = AppStorage.get('openFolderData'); + const openFolderData: FolderData = AppStorage.get('openFolderData'); const removeAppInfos = [dragAppInfo]; const folderIndex = gridLayoutInfo.layoutInfo.findIndex(item => { return item.typeId === CommonConstants.TYPE_FOLDER && item.folderId === openFolderData.folderId; @@ -272,7 +272,7 @@ export class BigFolderViewModel extends BaseViewModel { for (let i = 0; i < removeAppInfos.length; i++) { this.mPageDesktopModel.updatePageDesktopLayoutInfo(gridLayoutInfo, removeAppInfos[i]); const gridLayout = this.createAppLayoutInfo(removeAppInfos[i]); - gridLayoutInfo.layoutInfo.push(gridLayout); + gridLayoutInfo.layoutInfo.push(gridLayout as LauncherDragItemInfo); appListInfo.push(removeAppInfos[i]); } this.mSettingsModel.setAppListInfo(appListInfo); @@ -285,18 +285,17 @@ export class BigFolderViewModel extends BaseViewModel { * * @param appInfo */ - private createAppLayoutInfo(appInfo): any { - const appLayout = { - bundleName: appInfo.bundleName, - abilityName: appInfo.abilityName, - moduleName: appInfo.moduleName, - keyName: appInfo.keyName, - typeId: appInfo.typeId, - area: appInfo.area, - page: appInfo.page, - column: appInfo.column, - row: appInfo.row - }; + private createAppLayoutInfo(appInfo: AppItemInfo): AppItemInfo { + const appLayout: AppItemInfo = new AppItemInfo(); + appLayout.bundleName = appInfo.bundleName; + appLayout.abilityName = appInfo.abilityName; + appLayout.moduleName = appInfo.moduleName; + appLayout.keyName = appInfo.keyName; + appLayout.typeId = appInfo.typeId; + appLayout.area = appInfo.area; + appLayout.page = appInfo.page; + appLayout.column = appInfo.column; + appLayout.row = appInfo.row; return appLayout; } @@ -320,13 +319,10 @@ export class BigFolderViewModel extends BaseViewModel { /** * Delete app from open folder * - * @param {any} appInfo. + * @param {AppItemInfo} appInfo. */ - deleteAppFromOpenFolder(appInfo): any { - let openFolderData: { - folderId: string, - layoutInfo: any - } = AppStorage.get('openFolderData'); + deleteAppFromOpenFolder(appInfo: AppItemInfo): FolderData { + let openFolderData: FolderData = AppStorage.get('openFolderData'); const folderLayoutInfo = this.getFolderLayoutInfo(openFolderData, appInfo); // Delete app from the folder @@ -349,11 +345,11 @@ export class BigFolderViewModel extends BaseViewModel { column: gridLayoutInfo.layoutInfo[folderIndex].column, row: gridLayoutInfo.layoutInfo[folderIndex].row }; - gridLayoutInfo.layoutInfo.push(appLayout); + gridLayoutInfo.layoutInfo.push(appLayout as LauncherDragItemInfo); appListInfo.push(folderLayoutInfo[0][0]); gridLayoutInfo.layoutInfo.splice(folderIndex, 1); openFolderData = { - folderId: '', layoutInfo: [] + folderId: '',folderName: '', enterEditing: false, layoutInfo: [] }; } else { this.updateBadgeNumber(gridLayoutInfo.layoutInfo[folderIndex], appInfo); @@ -367,13 +363,13 @@ export class BigFolderViewModel extends BaseViewModel { /** * update folder app list info * - * @param {any} appInfos. - * @param {any} folderItem. + * @param {AppItemInfo[]} appInfos. + * @param {FolderData} folderItem. */ - async updateFolderAppList(appInfos, folderItem) { + async updateFolderAppList(appInfos: AppItemInfo[], folderItem: FolderData): Promise { Log.showDebug(TAG, 'updateFolderAppList start'); - let removeFolderApp = []; - let gridLayoutInfoTemp: any; + let removeFolderApp: AppItemInfo[] = []; + let gridLayoutInfoTemp: GridLayoutInfo; let gridLayoutInfo = { layoutInfo: [] }; @@ -393,7 +389,7 @@ export class BigFolderViewModel extends BaseViewModel { localEventManager.sendLocalEventSticky(EventConstants.EVENT_REQUEST_PAGEDESK_ITEM_ADD, removeFolderApp[i]); this.mPageDesktopModel.updatePageDesktopLayoutInfo(gridLayoutInfoTemp, removeFolderApp[i]); const gridLayout = this.createAppLayoutInfo(removeFolderApp[i]); - gridLayoutInfoTemp.layoutInfo.push(gridLayout); + gridLayoutInfoTemp.layoutInfo.push(gridLayout as LauncherDragItemInfo); } this.mSettingsModel.setLayoutInfo(gridLayoutInfoTemp); } else { @@ -455,7 +451,7 @@ export class BigFolderViewModel extends BaseViewModel { * @param appInfos * @param folderAppList */ - getAppRemainInOtherFolder(appInfos, folderAppList): any[] { + getAppRemainInOtherFolder(appInfos: AppItemInfo[], folderAppList: AppItemInfo[]): AppItemInfo[] { const appInfosRemaining = []; for (let m = 0; m < folderAppList.length; m++) { const appIndex = appInfos.findIndex(item => { @@ -475,7 +471,7 @@ export class BigFolderViewModel extends BaseViewModel { * @param folderItem * @param gridLayoutInfo */ - private updateFolderBadgeNumber(appInfos, folderItem, gridLayoutInfo, gridLayoutInfoTemp): void { + private updateFolderBadgeNumber(appInfos: AppItemInfo[], folderItem: FolderData, gridLayoutInfo, gridLayoutInfoTemp): void { for (let i = 0; i < gridLayoutInfo.layoutInfo.length; i++) { if (gridLayoutInfo.layoutInfo[i].typeId === CommonConstants.TYPE_FOLDER && gridLayoutInfo.layoutInfo[i].folderId === folderItem.folderId) { @@ -661,14 +657,14 @@ export class BigFolderViewModel extends BaseViewModel { * @param {number} folderId * */ - async getFolderAddAppList(folderId) { + async getFolderAddAppList(folderId: string): Promise { Log.showDebug(TAG, 'getFolderAddAppList start'); if (CheckEmptyUtils.checkStrIsEmpty(folderId)) { Log.showDebug(TAG, 'getFolderAddAppList folderId is Empty'); return; } - let allAppList = []; - let appInfos: any; + let allAppList: AppItemInfo[] = []; + let appInfos: AppItemInfo[] = []; let gridLayoutInfo = { layoutInfo: [] }; @@ -708,7 +704,7 @@ export class BigFolderViewModel extends BaseViewModel { } } if (!this.getIsPad()) { - let bottomAppList: any = AppStorage.get('residentList'); + let bottomAppList: AppItemInfo[] = AppStorage.get('residentList') as AppItemInfo[]; if (!CheckEmptyUtils.isEmptyArr(bottomAppList)) { for (let i = 0; i < bottomAppList.length; i++) { allAppList = allAppList.filter((item) => { @@ -727,9 +723,9 @@ export class BigFolderViewModel extends BaseViewModel { /** * open folder * - * @param {any} folderInfo. + * @param {FolderData} folderInfo. */ - addAddIcon(folderItem: any): any { + addAddIcon(folderItem: FolderData): FolderData { Log.showDebug(TAG, 'addAddIcon start'); if (folderItem.layoutInfo.length == 0) { @@ -743,13 +739,9 @@ export class BigFolderViewModel extends BaseViewModel { const openFolderConfig = this.mBigFolderModel.getFolderOpenLayout(); const column = openFolderConfig.column; const row = openFolderConfig.row; - const addInfo = { - typeId: CommonConstants.TYPE_ADD, - appName: $r('app.string.add'), - bundleName: '', - appIconId: BigFolderStyleConstants.DEFAULT_ADD_FOLDER_APP_IMAGE, - appLabelId: 0 - }; + const addInfo: AppItemInfo = new AppItemInfo(); + addInfo.typeId = CommonConstants.TYPE_ADD; + addInfo.appName = ''; if (folderItem.layoutInfo[folderItem.layoutInfo.length - 1].length === column * row) { folderItem.layoutInfo.push([addInfo]); } else { @@ -763,9 +755,9 @@ export class BigFolderViewModel extends BaseViewModel { /** * open folder * - * @param {any} folderInfo. + * @param {FolderData} folderInfo. */ - delAddIcon(folderItem: any): any { + delAddIcon(folderItem: FolderData): FolderData { Log.showDebug(TAG, 'delAddIcon start'); if (folderItem.layoutInfo.length == 0) { @@ -789,9 +781,10 @@ export class BigFolderViewModel extends BaseViewModel { /** * open folder * - * @param {any} folderInfo. + * @param {boolean} isRename. + * @param {FolderData} folderItem. */ - async openFolder(isRename: boolean, folderItem: any) { + async openFolder(isRename: boolean, folderItem: FolderData) { Log.showDebug(TAG, 'openFolder start'); folderItem.enterEditing = isRename; @@ -818,7 +811,7 @@ export class BigFolderViewModel extends BaseViewModel { * * @param folderItem */ - async refreshFolder(folderItem: any) { + async refreshFolder(folderItem: FolderData) { Log.showDebug(TAG, 'refreshFolder start'); folderItem.enterEditing = false; this.updateOpenFolderStatus(folderItem); @@ -837,10 +830,11 @@ export class BigFolderViewModel extends BaseViewModel { /** * modify folder name * - * @param {any} folderModel. + * @param {FolderData} folderModel. */ - modifyFolderName(folderModel): void { - let gridLayoutInfo = { + modifyFolderName(folderModel: FolderData): void { + let gridLayoutInfo: GridLayoutInfo = { + layoutDescription: undefined, layoutInfo: [] }; gridLayoutInfo = this.mSettingsModel.getLayoutInfo(); @@ -859,7 +853,7 @@ export class BigFolderViewModel extends BaseViewModel { * * @param appInfos */ - filterFolderPage(appInfos): any[] { + filterFolderPage(appInfos: AppItemInfo[]): AppItemInfo[][] { const folderLayoutInfo = []; const appListInfo = JSON.parse(JSON.stringify(appInfos)); const openFolderConfig = this.mBigFolderModel.getFolderOpenLayout(); @@ -885,10 +879,10 @@ export class BigFolderViewModel extends BaseViewModel { /** * make the folder layoutInfo into list * - * @param folderInfo + * @param {FolderData} folderInfo */ - private layoutInfoToList(folderInfo): any[] { - let appInfo = []; + private layoutInfoToList(folderInfo: FolderData): AppItemInfo[] { + let appInfo: AppItemInfo[] = []; for (let i = 0; i < folderInfo.layoutInfo.length; i++) { for (let j = 0; j < folderInfo.layoutInfo[i].length; j++) { if (folderInfo.layoutInfo[i][j].typeId != CommonConstants.TYPE_ADD) { @@ -902,7 +896,7 @@ export class BigFolderViewModel extends BaseViewModel { /** * create folder info * - * @return {any} folderInfo. + * @return {LauncherDragItemInfo} folderInfo. */ private async createNewFolderInfo() { const folderConfig = this.mBigFolderModel.getFolderLayout(); @@ -916,7 +910,7 @@ export class BigFolderViewModel extends BaseViewModel { area: folderConfig.area, badgeNumber: 0 }; - return folderInfo; + return folderInfo as LauncherDragItemInfo; } /** @@ -1020,7 +1014,7 @@ export class BigFolderViewModel extends BaseViewModel { const layoutInfo = gridLayoutInfo.layoutInfo; for (let i = 0; i < layoutInfo.length; i++) { if (layoutInfo[i].typeId == CommonConstants.TYPE_FOLDER) { - let folderAppList = this.layoutInfoToList(layoutInfo[i]); + let folderAppList = this.layoutInfoToList(layoutInfo[i] as FolderData); folderAppList = folderAppList.filter(item => item.bundleName != bundleName); this.updateFolderInfo(folderAppList, gridLayoutInfo, i); } @@ -1066,13 +1060,10 @@ export class BigFolderViewModel extends BaseViewModel { /** * remove app from folder * - * @param {any} appInfo. + * @param {AppItemInfo} appInfo. */ - removeAppOutOfFolder(appInfo): void { - let openFolderData: { - folderId: string, - layoutInfo: any - } = AppStorage.get('openFolderData'); + removeAppOutOfFolder(appInfo: AppItemInfo): void { + let openFolderData: FolderData = AppStorage.get('openFolderData'); const folderAppList = this.getAppListInFolder(openFolderData); this.deleteAppFromFolderAppList(appInfo, folderAppList); @@ -1089,7 +1080,7 @@ export class BigFolderViewModel extends BaseViewModel { removeAppInfos.push(folderLayoutInfo[0][0]); gridLayoutInfo.layoutInfo.splice(folderIndex, 1); openFolderData = { - folderId: '', layoutInfo: [] + folderId: '',enterEditing: false, folderName: '', layoutInfo: [] }; } else { this.updateBadgeNumber(gridLayoutInfo.layoutInfo[folderIndex], appInfo); @@ -1108,7 +1099,7 @@ export class BigFolderViewModel extends BaseViewModel { } } const gridLayout = this.createAppLayoutInfo(removeAppInfos[i]); - gridLayoutInfo.layoutInfo.push(gridLayout); + gridLayoutInfo.layoutInfo.push(gridLayout as LauncherDragItemInfo); const appIndex = appListInfo.findIndex(item => { return item.keyName === removeAppInfos[i].keyName; }) @@ -1127,7 +1118,7 @@ export class BigFolderViewModel extends BaseViewModel { * * @param openFolderData */ - private updateOpenFolderStatus(openFolderData): void { + private updateOpenFolderStatus(openFolderData: FolderData): void { AppStorage.setOrCreate('openFolderData', openFolderData); if (openFolderData.folderId == '') { AppStorage.setOrCreate('openFolderStatus', BigFolderConstants.OPEN_FOLDER_STATUS_CLOSE); @@ -1156,12 +1147,12 @@ export class BigFolderViewModel extends BaseViewModel { * * @param openFolderData */ - private getAppListInFolder(openFolderData): any[] { + private getAppListInFolder(openFolderData: FolderData): AppItemInfo[] { let folderAppList = []; for (let i = 0; i < openFolderData.layoutInfo.length; i++) { folderAppList = folderAppList.concat(openFolderData.layoutInfo[i]); } - if (folderAppList.length > 0 && folderAppList[folderAppList.length - 1].typeId == CommonConstants.TYPE_ADD) { + if (folderAppList.length > 0 && folderAppList[folderAppList.length - 1].typeId === CommonConstants.TYPE_ADD) { folderAppList.pop(); } return folderAppList; @@ -1173,7 +1164,7 @@ export class BigFolderViewModel extends BaseViewModel { * @param openFolderData * @param appInfo */ - private getFolderLayoutInfo(openFolderData, appInfo): any { + private getFolderLayoutInfo(openFolderData: FolderData, appInfo: AppItemInfo): AppItemInfo[][] { let folderAppList = this.getAppListInFolder(openFolderData); const index = folderAppList.findIndex(item => { return item.keyName === appInfo.keyName; diff --git a/feature/bigfolder/src/main/resources/base/element/string.json b/feature/bigfolder/src/main/resources/base/element/string.json index b5817eceba83105b20b23325cba0434be2c890f3..6add37c3792721ccef188674e79ee5ef5de38705 100644 --- a/feature/bigfolder/src/main/resources/base/element/string.json +++ b/feature/bigfolder/src/main/resources/base/element/string.json @@ -19,6 +19,10 @@ { "name": "confirm_dialog", "value": "确认" + }, + { + "name": "add", + "value": "添加" } ] } \ No newline at end of file diff --git a/feature/form/src/main/ets/default/view/FormServiceComponent.ets b/feature/form/src/main/ets/default/view/FormServiceComponent.ets index 7fa7fc074a9a02bcfca4218a65a6ebb121331579..918252ff665d0d32248b1a0390afa34aaee7880a 100644 --- a/feature/form/src/main/ets/default/view/FormServiceComponent.ets +++ b/feature/form/src/main/ets/default/view/FormServiceComponent.ets @@ -328,6 +328,7 @@ export struct FormServiceComponent { } }, (item: AppItemInfo) => JSON.stringify(item)) } + .scrollBar(BarState.Off) .divider({ strokeWidth: ThisStyleConstants.SERVICE_FORM_APP_ITEM_GROUP_DIVIDER_WIDTH, color: ThisStyleConstants.FORM_SERVICE_APP_LIST_DIVIDER_COLOR, diff --git a/feature/form/src/main/ets/default/viewmodel/FormViewModel.ts b/feature/form/src/main/ets/default/viewmodel/FormViewModel.ts index 8de43499498c9ce1dbd337cfa1148bfd4491a709..0d883b48278f8a2952f7d65d04c970169e8ef626 100644 --- a/feature/form/src/main/ets/default/viewmodel/FormViewModel.ts +++ b/feature/form/src/main/ets/default/viewmodel/FormViewModel.ts @@ -19,7 +19,10 @@ import { PageDesktopModel, CommonConstants, layoutConfigManager, - FormListInfoCacheManager + FormListInfoCacheManager, + CardItemInfo, + LauncherDragItemInfo, + GridLayoutInfo } from '@ohos/common'; import { FormStyleConfig } from '../common/FormStyleConfig'; import FeatureConstants from '../common/constants/FeatureConstants'; @@ -36,7 +39,7 @@ export class FormViewModel { private readonly mPageDesktopModel: PageDesktopModel; private readonly mFormStyleConfig: FormStyleConfig; private readonly mFormListInfoCacheManager: FormListInfoCacheManager; - private mAllFormsInfo; + private mAllFormsInfo?: CardItemInfo[]; private constructor() { Log.showInfo(TAG, 'constructor start'); @@ -74,15 +77,15 @@ export class FormViewModel { * * @param {any} appInfo */ - async isSupportForm(appInfo) { + async isSupportForm(appInfo: LauncherDragItemInfo) { const formInfoList = await this.mFormModel.getAllFormsInfo(); - const formInfo: any = formInfoList.find(item => { + const formInfo: CardItemInfo = formInfoList.find(item => { if (item.bundleName === appInfo.bundleName) { return true; } }); let isSupportForm = false; - if (formInfo.length > 0) { + if (formInfo) { isSupportForm = true; } return isSupportForm; @@ -104,7 +107,8 @@ export class FormViewModel { */ async deleteForm(cardId) { Log.showDebug(TAG, 'deleteForm start'); - let gridLayoutInfo = { + let gridLayoutInfo: GridLayoutInfo = { + layoutDescription: undefined, layoutInfo: [] }; gridLayoutInfo = this.mSettingsModel.getLayoutInfo(); diff --git a/feature/gesturenavigation/src/main/ets/default/common/GestureNavigationExecutors.ts b/feature/gesturenavigation/src/main/ets/default/common/GestureNavigationExecutors.ts index ffdbd647085b60c098180665244289f2d8414acc..42a6508588231d7f827d93e080e3c2ca39350241 100644 --- a/feature/gesturenavigation/src/main/ets/default/common/GestureNavigationExecutors.ts +++ b/feature/gesturenavigation/src/main/ets/default/common/GestureNavigationExecutors.ts @@ -199,7 +199,7 @@ export default class GestureNavigationExecutors { private recentEventCall() { Log.showInfo(TAG, 'recentEventCall recentEvent start'); - globalThis.createWindowWithName(windowManager.RECENT_WINDOW_NAME, windowManager.RECENT_RANK); + windowManager.createWindowWithName(windowManager.RECENT_WINDOW_NAME, windowManager.RECENT_RANK); } private isRecentsViewShowOfDistanceLimit(eventY: number) { diff --git a/feature/gesturenavigation/src/main/ets/default/common/GestureNavigationManager.ts b/feature/gesturenavigation/src/main/ets/default/common/GestureNavigationManager.ts index af0146d135f517579e9425a074ab33352acfd8ef..2f42caf6cc74cb2033e938136787f564454e2295 100644 --- a/feature/gesturenavigation/src/main/ets/default/common/GestureNavigationManager.ts +++ b/feature/gesturenavigation/src/main/ets/default/common/GestureNavigationManager.ts @@ -18,15 +18,19 @@ import inputMonitor from '@ohos.multimodalInput.inputMonitor'; import { Log, CommonConstants, - settingsDataManager + settingsDataManager, + localEventManager, + EventConstants } from '@ohos/common'; +import dataShare from '@ohos.data.dataShare'; import GestureNavigationExecutors from './GestureNavigationExecutors'; +import display from '@ohos.display'; const TAG = 'GestureNavigationManage'; export class GestureNavigationManager { private readonly uri: string | null = null; - private helper: any = null; + private helper: dataShare.DataShareHelper; private readonly sGestureNavigationExecutors: GestureNavigationExecutors = GestureNavigationExecutors.getInstance(); private touchEventCallback: inputMonitor.TouchEventReceiver | null = null; @@ -53,7 +57,7 @@ export class GestureNavigationManager { this.helper.on('dataChange', this.uri, callback); } - initWindowSize(display: any) { + initWindowSize(display: display.Display) { if (globalThis.sGestureNavigationExecutors) { globalThis.sGestureNavigationExecutors.setScreenWidth(display.width); globalThis.sGestureNavigationExecutors.setScreenHeight(display.height); @@ -66,12 +70,16 @@ export class GestureNavigationManager { private getGestureNavigationStatus() { Log.showDebug(TAG, 'getGestureNavigationStatus enter'); let gestureNavigationStatus = null; - try{ + try { gestureNavigationStatus = this.getValue(); Log.showDebug(TAG, `getGestureNavigationStatus gestureNavigationStatus: ${gestureNavigationStatus}`); this.handleEventSwitches(gestureNavigationStatus); + + // 初始化时保持弹窗的距离底部的位置和(打开/关闭)三键时的位置一致 + AppStorage.setOrCreate('NavigationBarStatusValue', gestureNavigationStatus === '0' ? true : false); + this.registerListenForDataChanges(this.dataChangesCallback.bind(this)); - }catch (error) { + } catch (error) { Log.showError(TAG, `getGestureNavigationStatus error: ${JSON.stringify(error)}`); } } @@ -80,7 +88,8 @@ export class GestureNavigationManager { Log.showInfo(TAG, "dataChangesCallback data:" + data); const getRetValue = this.getValue(); this.handleEventSwitches(getRetValue); - AppStorage.setOrCreate('NavigationBarStatusValue', getRetValue == '0' ? true : false); + AppStorage.setOrCreate('NavigationBarStatusValue', getRetValue === '0' ? true : false); + localEventManager.sendLocalEventSticky(EventConstants.EVENT_NAVIGATOR_BAR_STATUS_CHANGE, getRetValue); } private turnOnTouchEventCallback() { diff --git a/feature/pagedesktop/src/main/ets/default/common/PageDesktopDragHandler.ts b/feature/pagedesktop/src/main/ets/default/common/PageDesktopDragHandler.ts index df6eea002bcca61cc44f41ef5906363dc12340d6..5f13848ed3cfe3d2bd4412a887f6d961509373fc 100644 --- a/feature/pagedesktop/src/main/ets/default/common/PageDesktopDragHandler.ts +++ b/feature/pagedesktop/src/main/ets/default/common/PageDesktopDragHandler.ts @@ -291,7 +291,8 @@ export class PageDesktopDragHandler extends BaseDragHandler { "column": this.getColumn(endIndex), "row": this.getRow(endIndex), "x": 0, - "installTime": dragItemInfo.installTime + "installTime": dragItemInfo.installTime, + "badgeNumber": dragItemInfo.badgeNumber }) this.mSettingsModel.setAppListInfo(appInfoList); } @@ -326,9 +327,10 @@ export class PageDesktopDragHandler extends BaseDragHandler { "area": dragItemInfo.area, "page": dragItemInfo.page, "column": this.getColumn(endIndex), - "row": this.getRow(endIndex) + "row": this.getRow(endIndex), + "badgeNumber": dragItemInfo.badgeNumber }; - layoutInfo.push(appInfoTemp); + layoutInfo.push(appInfoTemp as LauncherDragItemInfo); localEventManager.sendLocalEventSticky(EventConstants.EVENT_REQUEST_RESIDENT_DOCK_ITEM_DELETE, dragItemInfo); } else { this.checkAndMove(this.mStartPosition, this.mEndPosition, layoutInfo, dragItemInfo); diff --git a/feature/pagedesktop/src/main/ets/default/common/components/FolderItem.ets b/feature/pagedesktop/src/main/ets/default/common/components/FolderItem.ets index 639de60a39ad917256f3460a793a651df0817736..5dfbb57f23d1b46f237450292f2d4bc362eaad86 100644 --- a/feature/pagedesktop/src/main/ets/default/common/components/FolderItem.ets +++ b/feature/pagedesktop/src/main/ets/default/common/components/FolderItem.ets @@ -25,7 +25,8 @@ import { PresetStyleConstants, AppItemInfo, FolderItemInfo, - MenuInfo + MenuInfo, + FolderData } from '@ohos/common'; import { BigFolderViewModel, @@ -118,11 +119,11 @@ export default struct FolderItem { private renameClick = () => { Log.showInfo(TAG, 'click menu folder rename'); AppStorage.setOrCreate('overlayMode', CommonConstants.OVERLAY_TYPE_HIDE); - this.mBigFolderViewModel?.openFolder(true, this.folderItem); + this.mBigFolderViewModel?.openFolder(true, this.folderItem as FolderData); } private getOpenFolder(): string { - let openFolderData: FolderItemType = AppStorage.get('openFolderData') as FolderItemType; + let openFolderData: FolderData = AppStorage.get('openFolderData') as FolderData; return openFolderData.folderId; } @@ -167,12 +168,12 @@ export default struct FolderItem { this.setStartAppInfo(appItem); this.mPageDesktopViewModel?.openApplication(appItem.abilityName, appItem.bundleName, appItem.moduleName); }, - onOpenFolderClick: (event: ClickEvent, folderItem: FolderItemInfo) => { + onOpenFolderClick: (event: ClickEvent, folderItem: FolderData) => { Log.showInfo(TAG, "onOpenFolderClick"); Trace.start(Trace.CORE_METHOD_OPEN_FOLDER); this.mBigFolderViewModel?.openFolder(false, folderItem); }, - onFolderTouch: (event: TouchEvent, folderItem: FolderItemInfo) => { + onFolderTouch: (event: TouchEvent, folderItem: FolderData) => { if (event.type === CommonConstants.TOUCH_TYPE_UP && this.pageDesktopDragItemInfo.isDragging) { let mIsDragEffectArea = PageDesktopDragHandler.getInstance().isDragEffectArea(event.touches[0].windowX, event.touches[0].windowY); Log.showInfo(TAG, `onTouch mIsDragEffectArea: ${mIsDragEffectArea}`); @@ -215,7 +216,7 @@ export default struct FolderItem { TapGesture({ count: 2 }) .onAction((event: GestureEvent) => { Log.showInfo(TAG, 'TapGesture double click'); - this.mBigFolderViewModel?.openFolder(false, this.folderItem); + this.mBigFolderViewModel?.openFolder(false, this.folderItem as FolderData); }) ) ) diff --git a/feature/pagedesktop/src/main/ets/default/common/components/GridSwiper.ets b/feature/pagedesktop/src/main/ets/default/common/components/GridSwiper.ets index 0845d60267d9440c51cabbd5915eb24fecd06c1e..864c58fda4849aed98b1a1e53b15ef489f0a3de2 100644 --- a/feature/pagedesktop/src/main/ets/default/common/components/GridSwiper.ets +++ b/feature/pagedesktop/src/main/ets/default/common/components/GridSwiper.ets @@ -140,7 +140,7 @@ export default struct GridSwiper { .gesture( LongPressGesture({ repeat: false }) .onAction((event: GestureEvent) => { - this.dialogController?.open() + this.dialogController?.open(); }) ) .bindContextMenu(this.MenuBuilder, ResponseType.RightClick) diff --git a/feature/pagedesktop/src/main/ets/default/common/components/SwiperPage.ets b/feature/pagedesktop/src/main/ets/default/common/components/SwiperPage.ets index 3531c093074395004aeffb709ae84327d870d1fa..be4882061c799244246dd457499b3d379538a26e 100644 --- a/feature/pagedesktop/src/main/ets/default/common/components/SwiperPage.ets +++ b/feature/pagedesktop/src/main/ets/default/common/components/SwiperPage.ets @@ -20,7 +20,8 @@ import { PresetStyleConstants, localEventManager, EventConstants, - CardItemInfo + CardItemInfo, + FolderData } from '@ohos/common'; import AppItem from './AppItem'; import FormItem from './FormItem'; @@ -71,6 +72,19 @@ export default struct SwiperPage { private updateAppListInfo(): void { this.mAppListInfo = this.appListInfo.appGridInfo[this.swiperPage]; + this.updateOpenFolderData(); + } + + /** + * 监听桌面元素变化时,更新打开的大文件的数据。 + * eg:应用角标更新时,大文件内的应用角标同步更新。 + */ + updateOpenFolderData() { + const openFolderData = AppStorage.get('openFolderData') as FolderData; + if (openFolderData?.folderId && this.mAppListInfo.length) { + let temp = this.mAppListInfo.find((item: LauncherDragItemInfo) => item?.folderId === openFolderData.folderId); + AppStorage.setOrCreate('openFolderData', temp as FolderData); + } } aboutToAppear(): void { @@ -220,13 +234,10 @@ export default struct SwiperPage { left: this.mMargin }) .onMouse((event: MouseEvent) => { - if (event.button == MouseButton.Right) { + if (event.button === MouseButton.Right || event.button === MouseButton.Left) { AppStorage.setOrCreate('selectDesktopAppItem', ''); } }) - .onClick((event: ClickEvent) => { - AppStorage.setOrCreate('selectDesktopAppItem', '') - }) .onDragEnter((event: DragEvent, extraParams: string) => { Log.showInfo(TAG, `onDragEnter extraParams: ${extraParams}, event: [${event.getWindowX()}, ${event.getWindowY()}]`); }) diff --git a/feature/pagedesktop/src/main/ets/default/layout/PageDesktopLayout.ets b/feature/pagedesktop/src/main/ets/default/layout/PageDesktopLayout.ets index 33b9c31df2d9d6c47801c230527d45d06d07ea36..58dcab551c26b9b981f22adb660a93eda3cf9d0c 100644 --- a/feature/pagedesktop/src/main/ets/default/layout/PageDesktopLayout.ets +++ b/feature/pagedesktop/src/main/ets/default/layout/PageDesktopLayout.ets @@ -118,7 +118,7 @@ export struct PageDesktopLayout { @CustomDialog struct settingDialog { @StorageLink('NavigationBarStatusValue') navigationBarStatusValue: boolean = false; - controller?: CustomDialogController + controller?: CustomDialogController; cancel = () => {}; confirm = () => {}; onAccept = () => {}; diff --git a/feature/pagedesktop/src/main/ets/default/viewmodel/PageDesktopViewModel.ts b/feature/pagedesktop/src/main/ets/default/viewmodel/PageDesktopViewModel.ts index a8296fe00aff755fc4ab36c41427dc7c08b7982d..c9e3262e4bdaecc01e195e3743d2406fb1d9c5fe 100644 --- a/feature/pagedesktop/src/main/ets/default/viewmodel/PageDesktopViewModel.ts +++ b/feature/pagedesktop/src/main/ets/default/viewmodel/PageDesktopViewModel.ts @@ -33,7 +33,9 @@ import { PageDesktopModel, MenuInfo, CardItemInfo, - localEventManager + localEventManager, + GridLayoutInfo, + LauncherDragItemInfo } from '@ohos/common'; import { BigFolderModel } from '@ohos/bigfolder'; import { FormDetailLayoutConfig } from '@ohos/form'; @@ -67,7 +69,7 @@ export class PageDesktopViewModel extends BaseViewModel { private desktopSwiperController: SwiperController; async showFormManager(params) { - globalThis.createWindowWithName(windowManager.FORM_MANAGER_WINDOW_NAME, windowManager.RECENT_RANK); + windowManager.createWindowWithName(windowManager.FORM_MANAGER_WINDOW_NAME, windowManager.RECENT_RANK); } setSwiperController(swiperController: SwiperController): void { @@ -783,8 +785,8 @@ export class PageDesktopViewModel extends BaseViewModel { const layoutNum = this.mBundleInfoList.length; const maxPerPage = column * row; const pageNum = Math.ceil(layoutNum / maxPerPage); - const newLayoutInfo = { - layoutDescription: {}, + const newLayoutInfo: GridLayoutInfo = { + layoutDescription: undefined, layoutInfo: [] }; newLayoutInfo.layoutDescription = { @@ -804,8 +806,8 @@ export class PageDesktopViewModel extends BaseViewModel { const layoutNum = info.layoutInfo.length; const maxPerPage = column * row; const pageNum = Math.ceil(layoutNum / maxPerPage); - const newLayoutInfo = { - layoutDescription: {}, + const newLayoutInfo: GridLayoutInfo = { + layoutDescription: undefined, layoutInfo: [] }; newLayoutInfo.layoutDescription = { @@ -1045,7 +1047,7 @@ export class PageDesktopViewModel extends BaseViewModel { let menuInfoList = new Array(); const shortcutInfo: any = this.mAppModel.getShortcutInfo(appInfo.bundleName); if (shortcutInfo) { - let menu = null; + let menu: MenuInfo | null = null; shortcutInfo.forEach((value) => { menu = new MenuInfo(); menu.menuType = CommonConstants.MENU_TYPE_DYNAMIC; @@ -1110,7 +1112,7 @@ export class PageDesktopViewModel extends BaseViewModel { formCenterMenu.onMenuClick = (): void => { Log.showInfo(TAG, 'Launcher click menu into form center view.'); if (!this.isPad) { - globalThis.createWindowWithName(windowManager.FORM_SERVICE_WINDOW_NAME, windowManager.RECENT_RANK); + windowManager.createWindowWithName(windowManager.FORM_SERVICE_WINDOW_NAME, windowManager.RECENT_RANK); } }; menuInfoList.push(formCenterMenu); @@ -1204,7 +1206,7 @@ export class PageDesktopViewModel extends BaseViewModel { formCenterMenu.onMenuClick = (): void => { Log.showInfo(TAG, 'Launcher click menu into form center view.'); if (!this.isPad) { - globalThis.createWindowWithName(windowManager.FORM_SERVICE_WINDOW_NAME, windowManager.RECENT_RANK); + windowManager.createWindowWithName(windowManager.FORM_SERVICE_WINDOW_NAME, windowManager.RECENT_RANK); } }; menuInfoList.push(formCenterMenu); @@ -1345,7 +1347,7 @@ export class PageDesktopViewModel extends BaseViewModel { } // Push card into the layoutInfo - gridLayoutInfo.layoutInfo.push(cardItemLayoutInfo); + gridLayoutInfo.layoutInfo.push(cardItemLayoutInfo as LauncherDragItemInfo); this.mSettingsModel.setLayoutInfo(gridLayoutInfo); if (needNewPage) { this.mPageDesktopModel.setPageIndex(curPageIndex + 1); diff --git a/feature/recents/src/main/ets/default/view/RecentMissionsSingleLayout.ets b/feature/recents/src/main/ets/default/view/RecentMissionsSingleLayout.ets index dfad85baa1ab7a78555b1e8bfc8e9a8c380e6153..30eedf103ec15eb2d442c9145b637ed9f5aefcf7 100644 --- a/feature/recents/src/main/ets/default/view/RecentMissionsSingleLayout.ets +++ b/feature/recents/src/main/ets/default/view/RecentMissionsSingleLayout.ets @@ -55,7 +55,6 @@ export struct RecentMissionsSingleLayout { } }, (item: RecentMissionInfo) => JSON.stringify(item)) } - .cachedCount(3) .scrollBar(BarState.Off) .listDirection(Axis.Horizontal) .height(RecentsStyleConstants.SINGLE_LIST_MISSION_HEIGHT) diff --git a/feature/settings/src/main/ets/common/presenter/SettingsPresenter.ts b/feature/settings/src/main/ets/common/presenter/SettingsPresenter.ts index eb32aa0102b060c82077d8a87037cef5f972eab8..5306b2944c382482b4b3115390eaf9763a49e63c 100644 --- a/feature/settings/src/main/ets/common/presenter/SettingsPresenter.ts +++ b/feature/settings/src/main/ets/common/presenter/SettingsPresenter.ts @@ -205,21 +205,17 @@ export default class SettingsPresenter { sendLocalEvent(value: string) { Log.showDebug(TAG, `setValue value: ${value}`); - if (value != '1' && value != '0') { + if (value !== '1' && value !== '0') { Log.showDebug(TAG, 'setValue error'); return; } - if (value == '0') { - this.mSettingsModel.setValue(value); - } else { - localEventManager.sendLocalEventSticky(EventConstants.EVENT_NAVIGATOR_BAR_STATUS_CHANGE, value); - } + this.mSettingsModel.setValue(value); } initNavigationBarStatusValue() { try { const initValue = this.mSettingsModel.getValue(); - const navigationBarStatusValue = initValue == '0' ? true : false; + const navigationBarStatusValue = initValue === '0' ? true : false; Log.showDebug(TAG, `initNavigationBarStatusValue initValue:${initValue}, navigationBarStatusValue:${navigationBarStatusValue}`); AppStorage.setOrCreate('NavigationBarStatusValue', navigationBarStatusValue); } catch (e) { diff --git a/feature/settings/src/main/ets/pages/Settings.ets b/feature/settings/src/main/ets/pages/Settings.ets index 3706116846420998f3e56653bd7b6ea48b7f847c..d328b565ca43fb19d0c08079635925b65dc5c446 100644 --- a/feature/settings/src/main/ets/pages/Settings.ets +++ b/feature/settings/src/main/ets/pages/Settings.ets @@ -28,15 +28,16 @@ const TAG = 'Settings'; @Entry @Component struct Index { - private mSettingsStage = new SettingsStage(); + private mSettingsStage: SettingsStage = new SettingsStage(); private mDevice = SettingsStyleConstants.DEFAULT_DEVICE_TYPE_PHONE; + @State mSettingsPresenter: SettingsPresenter | null = null; onPageShow(): void { } aboutToAppear(): void { this.getDeviceType(); this.mSettingsStage.onCreate(); - mSettingsPresenter = SettingsPresenter.getInstance(); + this.mSettingsPresenter = SettingsPresenter.getInstance(); } aboutToDisappear(): void { @@ -45,13 +46,13 @@ struct Index { async getDeviceType() { try { - let sysWidth = await windowManager.getWindowWidth(); - let sysHeigh = await windowManager.getWindowHeight(); - if (sysWidth > sysHeigh) { + let sysWidth = px2vp(windowManager.getWindowWidth()); + let sysHeight = px2vp(windowManager.getWindowHeight()); + if (sysWidth > sysHeight) { this.mDevice = SettingsStyleConstants.DEFAULT_DEVICE_TYPE_PAD; } } catch (e) { - Log.showError(TAG, 'getWindowWidth or getWindowHeight error:' + e); + Log.showError(TAG, `getWindowWidth or getWindowHeight error: ${JSON.stringify(e)}`); } } @@ -109,7 +110,7 @@ struct top_bar { .width(SettingsStyleConstants.DEFAULT_VP_24) .height(SettingsStyleConstants.DEFAULT_VP_24) .onClick(() => { - mSettingsPresenter.backToTheDesktop(); + SettingsPresenter.getInstance().backToTheDesktop(); }) Text($r('app.string.into_settings')) @@ -128,14 +129,10 @@ struct SettingPage { @State SettingList: SettingItemInfo[] = []; aboutToAppear(): void { - this.SettingList = mSettingsPresenter.getSettingList(); + this.SettingList = SettingsPresenter.getInstance().getSettingList(); Log.showInfo(TAG, `aboutToAppear SettingList length: ${this.SettingList.length}`); } - onPageShow(): void { - this.SettingList = mSettingsPresenter.getSettingList(); - } - build() { Column() { ForEach(this.SettingList, (item: SettingItemInfo) => { @@ -177,9 +174,9 @@ struct SettingItem { } aboutToAppear(): void { - mSettingsPresenter.initNavigationBarStatusValue(); + SettingsPresenter.getInstance().initNavigationBarStatusValue(); if (this.settingType == 1) { - mSettingsPresenter.registerValueCallback(this.ida, this.callback); + SettingsPresenter.getInstance().registerValueCallback(this.ida, this.callback); } } @@ -232,7 +229,7 @@ struct SettingItem { .height(40) .onChange((isOn: boolean) => { Log.showDebug(TAG, `SettingItemToggle onChange for GestureNavigation Enable: ${isOn}`); - mSettingsPresenter.sendLocalEvent(isOn ? '0' : '1'); + SettingsPresenter.getInstance().sendLocalEvent(isOn ? '0' : '1'); }) } } @@ -278,8 +275,8 @@ struct SettingsDialog { }.width(SettingsStyleConstants.PERCENTAGE_100) .height(SettingsStyleConstants.DEFAULT_VP_80) .onClick(() => { - mSettingsPresenter.changeSettingValue(this.ida, item.name); - mSettingsPresenter.setSettingsValue(this.ida, item.value); + SettingsPresenter.getInstance().changeSettingValue(this.ida, item.name); + SettingsPresenter.getInstance().setSettingsValue(this.ida, item.value); if (this.controller) { this.controller.close(); } diff --git a/feature/smartdock/src/main/ets/default/layout/RecentLayout.ets b/feature/smartdock/src/main/ets/default/layout/RecentLayout.ets index e7aa2d7157bdcf485937992baf28d78e6ab09173..513df6bc13e19e0b9ffc6afdb13cef7e0aaa5a49 100644 --- a/feature/smartdock/src/main/ets/default/layout/RecentLayout.ets +++ b/feature/smartdock/src/main/ets/default/layout/RecentLayout.ets @@ -188,6 +188,8 @@ export default struct RecentLayout { }) }, (item: DockItemInfo) => JSON.stringify(item)) } + .enableScrollInteraction(false) + .scrollBar(BarState.Off) .padding(this.dockPadding) .width(this.getListWidth()) .height(this.mSmartDockStyleConfig?.mDockHeight as number) diff --git a/feature/smartdock/src/main/ets/default/layout/ResidentLayout.ets b/feature/smartdock/src/main/ets/default/layout/ResidentLayout.ets index b3ecf48c30773c55c34a324ebe3965b1b584d5fb..237bb5247698c57a57093cffa1c9ecb6518a2e91 100644 --- a/feature/smartdock/src/main/ets/default/layout/ResidentLayout.ets +++ b/feature/smartdock/src/main/ets/default/layout/ResidentLayout.ets @@ -94,12 +94,13 @@ export default struct ResidentLayout { } }, (item: DockItemInfo) => JSON.stringify(item)) } + .enableScrollInteraction(false) + .scrollBar(BarState.Off) .height('100%') .animation({ curve: Curve.Friction }) .listDirection(Axis[this.mSmartDockStyleConfig.mListDirection]) - .editMode(false) } .backgroundColor(this.mSmartDockStyleConfig.mBackgroundColor) .borderRadius(this.mSmartDockStyleConfig.mDockRadius) diff --git a/feature/smartdock/src/main/ets/default/layout/SmartDock.ets b/feature/smartdock/src/main/ets/default/layout/SmartDock.ets index 8bc8ecfd6b5eddfb30c156e61954c9b359a0f70e..34a8ea907c20f781a500df1a01dc9cca2bb7179e 100644 --- a/feature/smartdock/src/main/ets/default/layout/SmartDock.ets +++ b/feature/smartdock/src/main/ets/default/layout/SmartDock.ets @@ -39,7 +39,7 @@ interface DockRecentPopup { @Component export struct SmartDock { popup: DockRecentPopup = { show: false, showItem: '', popup: null }; - showAppCenter: Function = () => {}; + showAppCenter: () => void = () => {}; @StorageLink('showDock') showDock: boolean = false; @StorageLink('recentList') recentList: Array = []; @StorageLink('missionInfoList') missionInfoList: Array = []; @@ -97,7 +97,7 @@ export struct SmartDock { this.mSmartDockViewModel?.deleteDockItem({ bundleName: undefined, keyName: this.mSelectedItem?.keyName - }, this.mSelectedDockType); + } as DockItemInfo, this.mSelectedDockType); } else { this.mSmartDockViewModel?.uninstallApp(this.mSelectedItem?.bundleName, this.mSelectedItem?.isUninstallAble); } @@ -105,8 +105,8 @@ export struct SmartDock { } showDialog = () => { - this.mSelectedItem = this.mSmartDockViewModel?.getSelectedItem(); - this.mSelectedDockType = this.mSmartDockViewModel?.getSelectedDockType(); + this.mSelectedItem = this.mSmartDockViewModel?.getSelectedItem() as DockItemInfo|null; + this.mSelectedDockType = this.mSmartDockViewModel?.getSelectedDockType() as number; this.mDialogController?.open(); } @@ -186,6 +186,8 @@ export struct SmartDock { }) } } + .enableScrollInteraction(false) + .scrollBar(BarState.Off) .hitTestBehavior(this.desktopEventResponse ? HitTestMode.Default : HitTestMode.Block) .alignListItem(ListItemAlign.Center) .height(SmartDockConstants.PERCENTAGE_100) diff --git a/feature/smartdock/src/main/ets/default/model/SmartDockModel.ts b/feature/smartdock/src/main/ets/default/model/SmartDockModel.ts index 68bfc6c74b47edf8df661b82e49bfa801e3339e1..ba3a645f3e14de2e2cc527c94edf240bf5a5eb1d 100644 --- a/feature/smartdock/src/main/ets/default/model/SmartDockModel.ts +++ b/feature/smartdock/src/main/ets/default/model/SmartDockModel.ts @@ -36,6 +36,7 @@ import { SmartDockStyleConfig } from '../config/SmartDockStyleConfig'; import { SmartDockLayoutConfig } from '../config/SmartDockLayoutConfig'; import SmartDockConstants from '../common/constants/SmartDockConstants'; import { RecentMissionInfo } from '@ohos/common'; +import launcherBundleManager from '@ohos.bundle.launcherBundleManager'; const TAG = 'SmartDockModel'; const KEY_NAME = 'name'; @@ -115,6 +116,7 @@ export default class SmartDockModel { dockItemInfo.isSystemApp = typeof (appData) === 'undefined' ? dockItemInfo.isSystemApp : appData.isSystemApp; dockItemInfo.isUninstallAble = typeof (appData) === 'undefined' ? dockItemInfo.isUninstallAble : appData.isUninstallAble; dockItemInfo.installTime = typeof (appData) === 'undefined' ? dockItemInfo.installTime : appData.installTime; + dockItemInfo.badgeNumber = typeof (appData) === 'undefined' ? dockItemInfo.badgeNumber : appData.badgeNumber; residentList.push(dockItemInfo); } else if (dockDataList[i].itemType == CommonConstants.TYPE_CARD) { } else { @@ -129,6 +131,8 @@ export default class SmartDockModel { dockItemInfo.appLabelId = typeof (dockDataList[i].appLabelId) != 'undefined' ? dockDataList[i].appLabelId : dockDataList[i].labelId.id; dockItemInfo.isSystemApp = typeof (dockDataList[i].isSystemApp) === 'undefined' ? true : dockDataList[i].isSystemApp; dockItemInfo.isUninstallAble = typeof (dockDataList[i].isUninstallAble) === 'undefined' ? true : dockDataList[i].isUninstallAble; + dockItemInfo.badgeNumber = typeof (dockDataList[i].badgeNumber) === 'undefined' ? + CommonConstants.BADGE_DISPLAY_HIDE : dockDataList[i].badgeNumber; const loadAppName = await this.mResourceManager .getAppNameSync(dockItemInfo.appLabelId, dockItemInfo.bundleName, dockItemInfo.moduleName, ''); dockItemInfo.appName = loadAppName; @@ -197,7 +201,7 @@ export default class SmartDockModel { * @param dockItem * @param dockType */ - deleteDockItem(dockItem: {bundleName: string | undefined, keyName: string | undefined}, dockType: number): boolean { + deleteDockItem(dockItem: DockItemInfo, dockType: number): boolean { if (SmartDockConstants.RESIDENT_DOCK_TYPE === dockType) { return this.deleteResistDockItem(dockItem); } @@ -221,7 +225,7 @@ export default class SmartDockModel { if (this.checkDockNum(dockItemCount)) { return false; } - const flag = this.idDuplicate(this.mResidentList, appInfo); + const flag = this.idDuplicate(this.mResidentList, appInfo as AppItemInfo); if (flag) { const dockItemInfo = new DockItemInfo(); dockItemInfo.itemType = CommonConstants.TYPE_APP; @@ -236,6 +240,7 @@ export default class SmartDockModel { dockItemInfo.appLabelId = appInfo.appLabelId; dockItemInfo.isSystemApp = appInfo.isSystemApp; dockItemInfo.isUninstallAble = appInfo.isUninstallAble; + dockItemInfo.badgeNumber = appInfo.badgeNumber; if (dockItemCount == 0 || index == undefined || index >= dockItemCount || index < 0) { this.mResidentList.push(dockItemInfo); } else { @@ -521,7 +526,7 @@ export default class SmartDockModel { * get ShortcutInfo by bundleName * @param bundleName */ - getShortcutInfo(bundleName: string): any { + getShortcutInfo(bundleName: string): launcherBundleManager.ShortcutInfo[] | undefined { return this.mAppModel.getShortcutInfo(bundleName); } @@ -647,6 +652,7 @@ export default class SmartDockModel { dockItemInfo.installTime = appInfo.installTime; dockItemInfo.isSystemApp = appInfo.isSystemApp; dockItemInfo.isUninstallAble = appInfo.isUninstallAble; + dockItemInfo.badgeNumber = appInfo.badgeNumber; resistDockItem[i] = dockItemInfo; AppStorage.setOrCreate('residentList', resistDockItem); } diff --git a/feature/smartdock/src/main/ets/default/viewmodel/SmartDockViewModel.ts b/feature/smartdock/src/main/ets/default/viewmodel/SmartDockViewModel.ts index 7e4d6c6c83ec23c799dc6c338aaa8f687651ce0f..bd3b33d44421a90cc85a070a143d530b3c58316e 100644 --- a/feature/smartdock/src/main/ets/default/viewmodel/SmartDockViewModel.ts +++ b/feature/smartdock/src/main/ets/default/viewmodel/SmartDockViewModel.ts @@ -13,7 +13,7 @@ * limitations under the License. */ -import { Log } from '@ohos/common'; +import { LauncherDragItemInfo, Log, RecentBundleMissionInfo, ResourceManager } from '@ohos/common'; import { Trace } from '@ohos/common'; import { CheckEmptyUtils } from '@ohos/common'; import { MenuInfo } from '@ohos/common'; @@ -34,6 +34,10 @@ import { SmartDockLayoutConfig } from '../config/SmartDockLayoutConfig'; const TAG = 'SmartDockViewModel'; +class StartAppItemInfo extends LauncherDragItemInfo { + icon?: ResourceStr; +} + /** * SmartDock Viewmodel */ @@ -43,7 +47,7 @@ export default class SmartDockViewModel extends BaseViewModel { private readonly mSmartDockDragHandler: SmartDockDragHandler; private readonly mSmartDockStartAppHandler: SmartDockStartAppHandler; private readonly mSmartDockModel: SmartDockModel; - private mSelectedItem: DockItemInfo; + private mSelectedItem: DockItemInfo | null = null; private mSelectedDockType = 0; private mDevice = CommonConstants.DEFAULT_DEVICE_TYPE; @@ -76,7 +80,7 @@ export default class SmartDockViewModel extends BaseViewModel { * @param item * @param callback */ - residentOnClick(event, item, callback?) { + residentOnClick(event: ClickEvent | null, item: DockItemInfo, callback?: () => void) { // AppCenter entry AppStorage.setOrCreate('startAppTypeFromPageDesktop', CommonConstants.OVERLAY_TYPE_APP_RESIDENTIAL); if (item.abilityName == CommonConstants.APPCENTER_ABILITY && callback != null) { @@ -84,13 +88,13 @@ export default class SmartDockViewModel extends BaseViewModel { return; } if (item.abilityName == CommonConstants.RECENT_ABILITY) { - globalThis.createWindowWithName(windowManager.RECENT_WINDOW_NAME, windowManager.RECENT_RANK); + windowManager.createWindowWithName(windowManager.RECENT_WINDOW_NAME, windowManager.RECENT_RANK); Trace.start(Trace.CORE_METHOD_START_RECENTS); return; } // app entry Trace.start(Trace.CORE_METHOD_START_APP_ANIMATION); - this.setStartAppInfo(item); + this.setStartAppInfo(item as StartAppItemInfo); launcherAbilityManager.startLauncherAbility(item.abilityName, item.bundleName, item.moduleName); } @@ -99,9 +103,9 @@ export default class SmartDockViewModel extends BaseViewModel { * @param event * @param item */ - public recentOnClick(event, item, callback?) { + public recentOnClick(event: ClickEvent | null, item: DockItemInfo, callback?: () => void) { AppStorage.setOrCreate('startAppTypeFromPageDesktop', CommonConstants.OVERLAY_TYPE_APP_RECENT); - let missionInfoList = []; + let missionInfoList: RecentBundleMissionInfo[] = []; missionInfoList = AppStorage.get('missionInfoList'); Log.showDebug(TAG, `recentOnClick missionInfoList.length: ${missionInfoList.length}`); if (!CheckEmptyUtils.isEmptyArr(missionInfoList)) { @@ -117,7 +121,7 @@ export default class SmartDockViewModel extends BaseViewModel { amsMissionManager.moveMissionToFront(missionId).then(() => {}, () => {}); // set start app info Trace.start(Trace.CORE_METHOD_START_APP_ANIMATION); - this.setStartAppInfo(item); + this.setStartAppInfo(item as StartAppItemInfo); } break; } @@ -136,14 +140,16 @@ export default class SmartDockViewModel extends BaseViewModel { * update drag effective area when dockList changed */ async updateDockParams() { - const screenWidth: number = AppStorage.get('screenWidth'); - const screenHeight: number = AppStorage.get('screenHeight'); - const sysUIBottomHeight: number = AppStorage.get('sysUIBottomHeight'); - const dockHeight: number = AppStorage.get('dockHeight'); + const screenWidth: number = AppStorage.get('screenWidth') as number; + const screenHeight: number = AppStorage.get('screenHeight') as number; + const sysUIBottomHeight: number = AppStorage.get('sysUIBottomHeight') as number; + const dockHeight: number = AppStorage.get('dockHeight') as number; let mResidentWidth: number = this.getListWidth(AppStorage.get('residentList')); - if (AppStorage.get("deviceType") === CommonConstants.DEFAULT_DEVICE_TYPE) { + if ((AppStorage.get('deviceType') as string) === CommonConstants.DEFAULT_DEVICE_TYPE) { const maxDockNum = this.getStyleConfig().mMaxDockNum; - mResidentWidth = this.mSmartDockStyleConfig.mDockPadding * 2 + maxDockNum * (this.mSmartDockStyleConfig.mListItemWidth) + (maxDockNum - 1) * (this.mSmartDockStyleConfig.mListItemGap); + mResidentWidth = this.mSmartDockStyleConfig.mDockPadding * 2 + + maxDockNum * (this.mSmartDockStyleConfig.mListItemWidth) + + (maxDockNum - 1) * (this.mSmartDockStyleConfig.mListItemGap); } AppStorage.setOrCreate('residentWidth', mResidentWidth); AppStorage.setOrCreate("dockPadding", this.getDockPadding(mResidentWidth)); @@ -152,7 +158,7 @@ export default class SmartDockViewModel extends BaseViewModel { if (typeof (this.mSmartDockDragHandler) != 'undefined') { let left = mResidentWidth === 0 ? 0 : (screenWidth - mResidentWidth - (mRecentWidth === 0 ? 0 : (this.mSmartDockStyleConfig.mDockGap + mRecentWidth))) / 2; let right = mResidentWidth === 0 ? screenWidth : (screenWidth - mResidentWidth - (mRecentWidth === 0 ? 0 : (this.mSmartDockStyleConfig.mDockGap + mRecentWidth))) / 2 + mResidentWidth; - if (AppStorage.get('deviceType') == CommonConstants.DEFAULT_DEVICE_TYPE) { + if ((AppStorage.get('deviceType') as string) == CommonConstants.DEFAULT_DEVICE_TYPE) { left = (screenWidth - mResidentWidth) / 2; right = screenWidth - left; } @@ -181,11 +187,11 @@ export default class SmartDockViewModel extends BaseViewModel { * @param dockType * @param callback */ - buildMenuInfoList(appInfo, dockType, showAppcenter, callback?) { + buildMenuInfoList(appInfo: DockItemInfo, dockType: number, showAppcenter: () => void, callback?: () => void) { const menuInfoList = new Array(); const shortcutInfo = this.mSmartDockModel.getShortcutInfo(appInfo.bundleName); if (shortcutInfo) { - let menu = null; + let menu: MenuInfo | null = null; shortcutInfo.forEach((value) => { menu = new MenuInfo(); menu.menuType = CommonConstants.MENU_TYPE_DYNAMIC; @@ -197,7 +203,8 @@ export default class SmartDockViewModel extends BaseViewModel { menu.moduleName = value.moduleName; menu.onMenuClick = () => { Trace.start(Trace.CORE_METHOD_START_APP_ANIMATION); - launcherAbilityManager.startLauncherAbility(value.wants[0].targetClass, value.wants[0].targetBundle, value.wants[0].targetModule); + launcherAbilityManager.startLauncherAbility(value.wants[0].targetAbility, + value.wants[0].targetBundle, value.wants[0].targetModule); }; value.bundleName == appInfo.bundleName && value.moduleName == appInfo.moduleName && menuInfoList.push(menu); }); @@ -213,7 +220,7 @@ export default class SmartDockViewModel extends BaseViewModel { menuInfoList.push(open); if (appInfo.itemType != CommonConstants.TYPE_FUNCTION) { - this.mDevice = AppStorage.get('deviceType'); + this.mDevice = AppStorage.get('deviceType') as string; if (this.mDevice === CommonConstants.PAD_DEVICE_TYPE && dockType === SmartDockConstants.RESIDENT_DOCK_TYPE) { const addToWorkSpaceMenu = new MenuInfo(); addToWorkSpaceMenu.menuType = CommonConstants.MENU_TYPE_FIXED; @@ -250,16 +257,16 @@ export default class SmartDockViewModel extends BaseViewModel { return menuInfoList; } - deleteDockItem(dockItem: {bundleName: string | undefined, keyName: string | undefined}, dockType: number) { + deleteDockItem(dockItem: DockItemInfo, dockType: number) { this.mSmartDockModel.deleteDockItem(dockItem, dockType); } - getSelectedItem(): any { + getSelectedItem(): DockItemInfo | null { Log.showDebug(TAG, `getSelectedItem: ${JSON.stringify(this.mSelectedItem)}`); return this.mSelectedItem; } - getSelectedDockType(): any { + getSelectedDockType(): number { Log.showDebug(TAG, `getSelectedDockType: ${JSON.stringify(this.mSelectedDockType)}`); return this.mSelectedDockType; } @@ -268,7 +275,7 @@ export default class SmartDockViewModel extends BaseViewModel { * calcaulate dock list width after list change * @param itemList */ - private getListWidth(itemList: []): number { + private getListWidth(itemList: RecentBundleMissionInfo[]): number { let width = 0; if (typeof itemList === 'undefined' || itemList == null || itemList.length === 0) { return width; @@ -300,12 +307,12 @@ export default class SmartDockViewModel extends BaseViewModel { /** * set start app info */ - private setStartAppInfo(item) { + private setStartAppInfo(item: StartAppItemInfo) { if (CheckEmptyUtils.isEmpty(item)) { Log.showError(TAG, `setStartAppInfo with item`) return; } - item.icon = globalThis.ResourceManager.getCachedAppIcon(item.appIconId, item.bundleName, item.moduleName) + item.icon = ResourceManager.getInstance().getCachedAppIcon(item.appIconId, item.bundleName, item.moduleName) AppStorage.setOrCreate('startAppItemInfo', item); this.mSmartDockStartAppHandler.setAppIconSize(this.mSmartDockStyleConfig.mIconSize); this.mSmartDockStartAppHandler.setAppIconInfo(); diff --git a/product/pad/src/main/ets/MainAbility/MainAbility.ts b/product/pad/src/main/ets/MainAbility/MainAbility.ts index 351e8b821305a95bbd8994734d1e13c250c0b102..7c18983d62eb7424d659f27c562521813bda1bb2 100644 --- a/product/pad/src/main/ets/MainAbility/MainAbility.ts +++ b/product/pad/src/main/ets/MainAbility/MainAbility.ts @@ -110,7 +110,7 @@ export default class MainAbility extends ServiceExtension { isFinalKeyDown: true }, () => { Log.showInfo(TAG, 'RECENT inputConsumer recentEvent start'); - globalThis.createWindowWithName(windowManager.RECENT_WINDOW_NAME, windowManager.RECENT_RANK); + windowManager.createWindowWithName(windowManager.RECENT_WINDOW_NAME, windowManager.RECENT_RANK); }); } diff --git a/product/pad/src/main/ets/pages/EntryView.ets b/product/pad/src/main/ets/pages/EntryView.ets index efac2707795393b8a60647e7b477d4bfe0a843a5..76ce788ab31a674b25588e0f2790e5e10426103a 100644 --- a/product/pad/src/main/ets/pages/EntryView.ets +++ b/product/pad/src/main/ets/pages/EntryView.ets @@ -33,6 +33,7 @@ import { FormStyleConfig } from '@ohos/form'; import AppCenterGridStyleConfig from '@ohos/appcenter/src/main/ets/default/common/AppCenterGridStyleConfig'; import PadPageDesktopGridStyleConfig from '../common/PadPageDesktopGridStyleConfig'; import { SmartDockStyleConfig } from '@ohos/smartdock'; +import display from '@ohos.display'; const RAW_IMAGE_CACHE_SIZE = 20000000; const TAG = 'EntryView'; @@ -57,16 +58,34 @@ struct EntryView { @State mAppScaleY: number = 1.0; @State mAppAlpha: number = 1.0; @StorageLink('IsSetImageRawDataCacheSize') IsSetImageRawDataCacheSize?: boolean = undefined; + async onPortrait(mediaQueryResult: mediaquery.MediaQueryResult) { + if (mediaQueryResult.matches) { + Log.showInfo(TAG, 'screen change to landscape'); + AppStorage.setOrCreate('isPortrait', false); + } else { + Log.showInfo(TAG, 'screen change to portrait'); + AppStorage.setOrCreate('isPortrait', true); + } + let dis: display.Display | null = null; + try { + dis = display.getDefaultDisplaySync(); + Log.showInfo(TAG, `change to display: ${JSON.stringify(dis)}`); + AppStorage.setOrCreate('screenWidth', px2vp(dis.width)); + AppStorage.setOrCreate('screenHeight', px2vp(dis.height)); + Log.showDebug(TAG, `screenWidth and screenHeight: ${AppStorage.get('screenWidth')},${AppStorage.get('screenHeight')}`); + } catch (err) { + Log.showError(TAG, `display.getDefaultDisplaySync err: ${JSON.stringify(err)}`) + } + } aboutToAppear(): void { Log.showInfo(TAG, 'aboutToAppear'); this.mStage.onCreate(); - + this.navigationBarStatus = SettingsModel.getInstance().getValue(); this.getWindowSize(); this.updateScreenSize(); - this.mOrientationListener.on('change', windowManager.onPortrait); + this.mOrientationListener.on('change', this.onPortrait); this.registerPageDesktopNavigatorStatusChangeEvent(this.mLocalEventListener); - this.navigationBarStatus = SettingsModel.getInstance().getValue(); } registerPageDesktopNavigatorStatusChangeEvent(listener: LocalEventListener): void { @@ -139,10 +158,10 @@ struct EntryView { } } - private async getWindowSize(): Promise { + private getWindowSize(): void { try { - this.screenWidth = await windowManager.getWindowWidth(); - this.screenHeight = await windowManager.getWindowHeight(); + this.screenWidth = px2vp(windowManager.getWindowWidth()); + this.screenHeight = px2vp(windowManager.getWindowHeight()); AppStorage.setOrCreate('screenWidth', this.screenWidth); AppStorage.setOrCreate('screenHeight', this.screenHeight); } catch (error) { @@ -161,7 +180,7 @@ struct EntryView { } aboutToDisappear(): void { - this.mOrientationListener.off('change', windowManager.onPortrait); + this.mOrientationListener.off('change', this.onPortrait); this.mStage.onDestroy(); } diff --git a/product/phone/src/main/ets/MainAbility/MainAbility.ts b/product/phone/src/main/ets/MainAbility/MainAbility.ts index b7fa99cad08bc64f35da23ad84ecde0ad68c3993..77d5fc833102d4a1169c8ce4c239189c5cdc5e29 100644 --- a/product/phone/src/main/ets/MainAbility/MainAbility.ts +++ b/product/phone/src/main/ets/MainAbility/MainAbility.ts @@ -110,7 +110,7 @@ export default class MainAbility extends ServiceExtension { isFinalKeyDown: true }, () => { Log.showInfo(TAG, 'RECENT inputConsumer recentEvent start'); - globalThis.createWindowWithName(windowManager.RECENT_WINDOW_NAME, windowManager.RECENT_RANK); + windowManager.createWindowWithName(windowManager.RECENT_WINDOW_NAME, windowManager.RECENT_RANK); }); } diff --git a/product/phone/src/main/ets/pages/EntryView.ets b/product/phone/src/main/ets/pages/EntryView.ets index 3508e586b98b2726c95c4c21969f1af3c26e724a..f264d0e274b8d4a9d1caa416563e22de5dea313d 100644 --- a/product/phone/src/main/ets/pages/EntryView.ets +++ b/product/phone/src/main/ets/pages/EntryView.ets @@ -59,11 +59,12 @@ struct EntryView { aboutToAppear(): void { Log.showInfo(TAG, 'aboutToAppear'); this.mStage.onCreate(); + this.navigationBarStatus = SettingsModel.getInstance().getValue(); this.getWindowSize(); this.updateScreenSize(); this.registerPageDesktopNavigatorStatusChangeEvent(this.mLocalEventListener); - this.navigationBarStatus = SettingsModel.getInstance().getValue(); + } registerPageDesktopNavigatorStatusChangeEvent(listener: LocalEventListener): void { @@ -105,10 +106,10 @@ struct EntryView { } } - private async getWindowSize(): Promise { + private getWindowSize(): void { try { - this.screenWidth = await windowManager.getWindowWidth(); - this.screenHeight = await windowManager.getWindowHeight(); + this.screenWidth = px2vp(windowManager.getWindowWidth()); + this.screenHeight = px2vp(windowManager.getWindowHeight()); AppStorage.setOrCreate('screenWidth', this.screenWidth); AppStorage.setOrCreate('screenHeight', this.screenHeight); } catch (error) {