Signed-off-by: zhangchao <zhangchao338@huawei.com>
This commit is contained in:
zhangchao 2022-08-08 15:55:01 +08:00
parent f826e3c31e
commit b830ee3fd0
4 changed files with 63 additions and 46 deletions

View File

@ -221,15 +221,21 @@ export class PageDesktopDragHandler extends BaseDragHandler {
this.mStartPosition = this.getTouchPosition(x, y);
}
onDragDrop(x: number, y: number) {
onDragDrop(x: number, y: number): boolean {
const dragItemInfo: any = AppStorage.Get('dragItemInfo');
if (CheckEmptyUtils.isEmpty(dragItemInfo)) {
return;
if (JSON.stringify(dragItemInfo) == '{}') {
return false;
}
Log.showInfo(TAG, `onDragEnd dragItemInfo: ${JSON.stringify(dragItemInfo)}`);
const selectAppIndex: number = AppStorage.Get('selectAppIndex');
const dragItemType: number = AppStorage.Get('dragItemType');
const deviceType: string = AppStorage.Get('deviceType')
// dock appInfo has no location information.
if (dragItemType === CommonConstants.DRAG_FROM_DOCK && deviceType == CommonConstants.DEFAULT_DEVICE_TYPE) {
dragItemInfo.typeId = CommonConstants.TYPE_APP;
dragItemInfo.area = [1, 1];
dragItemInfo.page = AppStorage.Get('pageIndex');
}
Log.showDebug(TAG, `onDragEnd dragItemInfo: ${JSON.stringify(dragItemInfo)}`);
const endIndex = this.getItemIndex(x, y);
Log.showInfo(TAG, `onDragDrop selectAppIndex: ${selectAppIndex}`);
const startPosition: DragItemPosition = this.copyPosition(this.mStartPosition);
let endPosition: DragItemPosition = null;
this.mEndPosition = this.getTouchPosition(x, y);
@ -243,25 +249,23 @@ export class PageDesktopDragHandler extends BaseDragHandler {
} else {
if (this.isMoveToSamePosition(dragItemInfo)) {
this.deleteBlankPageAfterDragging(startPosition, endPosition);
return;
return false;
}
const endLayoutInfo = this.getEndLayoutInfo(layoutInfo);
if (endLayoutInfo != undefined) {
// add app to folder
if (endLayoutInfo.typeId === CommonConstants.TYPE_FOLDER) {
this.mBigFolderViewModel.addOneAppToFolder(dragItemInfo, endLayoutInfo.folderId);
if (AppStorage.Get('dragItemType') === CommonConstants.DRAG_FROM_DOCK
&& AppStorage.Get('deviceType') == CommonConstants.DEFAULT_DEVICE_TYPE) {
if (dragItemType === CommonConstants.DRAG_FROM_DOCK && deviceType == CommonConstants.DEFAULT_DEVICE_TYPE) {
localEventManager.sendLocalEventSticky(EventConstants.EVENT_REQUEST_RESIDENT_DOCK_ITEM_DELETE, dragItemInfo);
}
this.deleteBlankPageAfterDragging(startPosition, endPosition);
return;
return true;
} else if (endLayoutInfo.typeId === CommonConstants.TYPE_APP) {
// create a new folder
const layoutInfoList = [endLayoutInfo];
let startLayoutInfo = null;
if (AppStorage.Get('dragItemType') === CommonConstants.DRAG_FROM_DOCK
&& AppStorage.Get('deviceType') == CommonConstants.DEFAULT_DEVICE_TYPE) {
if (dragItemType === CommonConstants.DRAG_FROM_DOCK && deviceType == CommonConstants.DEFAULT_DEVICE_TYPE) {
let appInfoList = this.mSettingsModel.getAppListInfo();
const appIndex = appInfoList.findIndex(item => {
return item.keyName === dragItemInfo.keyName;
@ -296,13 +300,12 @@ export class PageDesktopDragHandler extends BaseDragHandler {
this.mBigFolderViewModel.addNewFolder(layoutInfoList).then(()=> {
this.deleteBlankPageAfterDragging(startPosition, endPosition);
});
return;
return true;
}
}
}
if (AppStorage.Get('dragItemType') === CommonConstants.DRAG_FROM_DOCK
&& AppStorage.Get('deviceType') == CommonConstants.DEFAULT_DEVICE_TYPE) {
if (dragItemType === CommonConstants.DRAG_FROM_DOCK && deviceType == CommonConstants.DEFAULT_DEVICE_TYPE) {
let appInfoTemp = {
"bundleName": dragItemInfo.bundleName,
"typeId": dragItemInfo.typeId,
@ -324,6 +327,7 @@ export class PageDesktopDragHandler extends BaseDragHandler {
this.mSettingsModel.setLayoutInfo(info);
localEventManager.sendLocalEventSticky(EventConstants.EVENT_SMARTDOCK_INIT_FINISHED, null);
this.deleteBlankPageAfterDragging(startPosition, endPosition);
return true;
}

View File

@ -22,7 +22,7 @@ import FolderItem from './FolderItem';
import { PageDesktopGridStyleConfig } from '../PageDesktopGridStyleConfig';
const TAG = "SwiperPage";
const APP_INFO_REFRESH_DELAY = 500;
const APP_INFO_REFRESH_DELAY = 1000;
@Component
export default struct SwiperPage {
@ -63,7 +63,8 @@ export default struct SwiperPage {
}
itemMove(moveX: number, moveY: number){
if (this.isSwappingPage) {
const isSwappingPage: boolean = AppStorage.Get('isSwappingPage');
if (isSwappingPage) {
return;
}
let curPageIndex: number = AppStorage.Get('pageIndex');
@ -85,9 +86,9 @@ export default struct SwiperPage {
* Increase delay when dragging app to other page.
*/
movingIconSwapPageDelay() {
this.isSwappingPage = true;
AppStorage.SetOrCreate('isSwappingPage', true);
setTimeout(() => {
this.isSwappingPage = false;
AppStorage.SetOrCreate('isSwappingPage', false);
}, APP_INFO_REFRESH_DELAY);
}
@ -173,7 +174,8 @@ export default struct SwiperPage {
.onDragMove((event: DragEvent, extraParams: string) => {
Log.showInfo(TAG, `onDragMove event: [${event.getX()}, ${event.getY()}]`);
if (AppStorage.Get('deviceType') == CommonConstants.DEFAULT_DEVICE_TYPE
|| (AppStorage.Get('deviceType') != CommonConstants.DEFAULT_DEVICE_TYPE && AppStorage.Get('dragItemType') !== 1)) {
|| (AppStorage.Get('deviceType') != CommonConstants.DEFAULT_DEVICE_TYPE
&& AppStorage.Get('dragItemType') !== CommonConstants.DRAG_FROM_DOCK)) {
this.itemMove(event.getX(), event.getY());
}
})
@ -182,22 +184,18 @@ export default struct SwiperPage {
})
.onDrop((event: DragEvent, extraParams: string) => {
Log.showInfo(TAG, `onDrop event: [${event.getX()}, ${event.getY()}]`);
let dragItemInfo: any = AppStorage.Get('dragItemInfo');
// Drag within its own component
if (dragItemInfo && AppStorage.Get('dragItemType') === 2) {
globalThis.PageDesktopDragHandler.onDragDrop(event.getX(), event.getY());
}
// Drag from other components
if (dragItemInfo && AppStorage.Get('dragItemType') === 1 && AppStorage.Get('deviceType') == CommonConstants.DEFAULT_DEVICE_TYPE) {
dragItemInfo.typeId = 0;
dragItemInfo.area = [1, 1];
dragItemInfo.page = AppStorage.Get('pageIndex');
AppStorage.SetOrCreate('dragItemInfo', dragItemInfo);
globalThis.PageDesktopDragHandler.onDragDrop(event.getX(), event.getY());
}
AppStorage.SetOrCreate('dragItemInfo', {});
const dragResult = globalThis.PageDesktopDragHandler.onDragDrop(event.getX(), event.getY());
Log.showInfo(TAG, `onDrop dragResult: ${dragResult}`);
AppStorage.SetOrCreate('selectAppIndex', null);
AppStorage.SetOrCreate('isDrag', false);
if (!dragResult) {
AppStorage.SetOrCreate('dragItemInfo', {});
} else {
// Wait for the UI rendering to end.
setTimeout(() => {
AppStorage.SetOrCreate('dragItemInfo', {});
}, 50);
}
})
}
}

View File

@ -19,6 +19,7 @@ import { localEventManager } from '@ohos/common';
import { BaseDragHandler } from '@ohos/common';
import { CommonConstants } from '@ohos/common';
import { layoutConfigManager } from '@ohos/common';
import { CheckEmptyUtils } from '@ohos/common';
import { SmartDockStyleConfig } from '../config/SmartDockStyleConfig';
import SmartDockModel from '../model/SmartDockModel';
import SmartDockConstants from '../common/constants/SmartDockConstants';
@ -145,18 +146,25 @@ export default class SmartDockDragHandler extends BaseDragHandler {
}
}
protected onDragDrop(x: number, y: number) {
const dragItemInfo = AppStorage.Get('dragItemInfo');
const insertIndex = this.getItemIndex(x, y);
if (dragItemInfo && AppStorage.Get('dragItemType') === CommonConstants.DRAG_FROM_DOCK) {
const selectAppIndex = AppStorage.Get('selectAppIndex');
globalThis.SmartDockDragHandler.layoutAdjustment(insertIndex, selectAppIndex);
protected onDragDrop(x: number, y: number): boolean {
const dragItemInfo: any = AppStorage.Get('dragItemInfo');
if (JSON.stringify(dragItemInfo) == '{}') {
return false;
}
if (dragItemInfo && AppStorage.Get('dragItemType') === CommonConstants.DRAG_FROM_DESKTOP
const dragItemType: number = AppStorage.Get('dragItemType');
const insertIndex = this.getItemIndex(x, y);
if (dragItemType === CommonConstants.DRAG_FROM_DOCK) {
const selectAppIndex: number = AppStorage.Get('selectAppIndex');
globalThis.SmartDockDragHandler.layoutAdjustment(insertIndex, selectAppIndex);
return true;
}
if (dragItemType === CommonConstants.DRAG_FROM_DESKTOP
&& AppStorage.Get('deviceType') == CommonConstants.DEFAULT_DEVICE_TYPE) {
Log.showInfo(TAG, `onDrop insertIndex: ${insertIndex}`);
this.addItemToSmartDock(dragItemInfo, insertIndex);
return true;
}
return false;
}
addItemToSmartDock(dragItemInfo: any, insertIndex: number): boolean {

View File

@ -88,20 +88,27 @@ export default struct ResidentLayout {
.listDirection(this.mSmartDockStyleConfig.mListDirection)
.editMode(false)
.onDragEnter((event: DragEvent, extraParams: string) => {
Log.showInfo(TAG, `onDragEnter extraParams: ${extraParams}, event: [${event.getX()}, ${event.getY()}]`);
Log.showDebug(TAG, `onDragEnter extraParams: ${extraParams}, event: [${event.getX()}, ${event.getY()}]`);
})
.onDragMove((event: DragEvent, extraParams: string) => {
Log.showInfo(TAG, `onDragMove event: [${event.getX()}, ${event.getY()}]`);
Log.showDebug(TAG, `onDragMove event: [${event.getX()}, ${event.getY()}]`);
})
.onDragLeave((event: DragEvent, extraParams: string) => {
Log.showInfo(TAG, `onDragLeave event: [${event.getX()}, ${event.getY()}]`);
Log.showDebug(TAG, `onDragLeave event: [${event.getX()}, ${event.getY()}]`);
})
.onDrop((event: DragEvent, extraParams: string) => {
Log.showInfo(TAG, `onDrop event: [${event.getX()}, ${event.getY()}]`);
globalThis.SmartDockDragHandler.onDragDrop(event.getX(), event.getY());
AppStorage.SetOrCreate('dragItemInfo', {});
const dragResult = globalThis.SmartDockDragHandler.onDragDrop(event.getX(), event.getY());
AppStorage.SetOrCreate('selectAppIndex', null);
AppStorage.SetOrCreate('isDrag', false);
if (!dragResult) {
AppStorage.SetOrCreate('dragItemInfo', {});
} else {
// Wait for the UI rendering to end.
setTimeout(() => {
AppStorage.SetOrCreate('dragItemInfo', {});
}, 50);
}
})
}
}