!60 删除性能优化

Merge pull request !60 from 朱铖丰/master
This commit is contained in:
openharmony_ci 2022-08-11 02:26:01 +00:00 committed by Gitee
commit 91a97f800e
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
23 changed files with 457 additions and 113 deletions

View File

@ -32,7 +32,7 @@ const appLogger: Logger = new Logger('app');
let isFromCard = false;
let isFromCamera = false;
let appBroadCast = BroadCastManager.getInstance().getBroadCast();
const pagePath: string = 'product/phone/view/index';
const pagePath: string = 'product/pad/view/index';
export default class MainAbility extends Ability {
private static readonly RETRY_MAX_TIMES = 100;

View File

@ -24,6 +24,7 @@ import { BrowserDataInterface } from '../../interface/BrowserDataInterface'
export class BucketSelectionEntry {
private groupId = -1;
private clickedSet: Set<string> = new Set();
private clickIndexSet: Set<number> = new Set();
private totalCount = 0;
private inverseSelection = false;
private groupSelect = false;
@ -56,6 +57,10 @@ export class BucketSelectionEntry {
return this.clickedSet;
}
public getClickIndexSet() {
return this.clickIndexSet;
}
public getSelectedCount() {
if (this.inverseSelection) {
return this.totalCount - this.clickedSet.size;
@ -67,12 +72,14 @@ export class BucketSelectionEntry {
this.inverseSelection = true;
this.groupSelect = true;
this.clickedSet.clear();
this.clickIndexSet.clear();
}
public unselectAll() {
this.inverseSelection = false;
this.groupSelect = false;
this.clickedSet.clear();
this.clickIndexSet.clear();
}
public isItemSelected(targetId) {
@ -130,6 +137,7 @@ export class SelectManager {
logger: Logger = new Logger('SelectManager');
mIsSelectedMode = false;
clickedSet: Set<string> = new Set();
clickedIndexSet: Set<number> = new Set();
totalCount = 0;
inverseSelection = false;
inSingleMode = false;
@ -189,9 +197,12 @@ export class SelectManager {
}
if (isSelected == (!this.inverseSelection)) {
this.clickedSet.add(targetId);
this.clickedIndexSet.add(targetIndex)
this.logger.info(`add targetID ${targetId}`);
this.logger.info(`add targetIndex ${targetIndex}`);
} else {
this.clickedSet.delete(targetId);
this.clickedIndexSet.delete(targetIndex)
}
if (this.isAllSelected) {
this.isAllSelected = false;
@ -209,6 +220,7 @@ export class SelectManager {
if (reverseSelection) {
this.inverseSelection = true;
this.clickedSet.clear();
this.clickedIndexSet.clear();
this.isAllSelected = true;
} else {
this.isAllSelected = true;
@ -221,6 +233,7 @@ export class SelectManager {
this.inverseSelection = false;
this.isAllSelected = false;
this.clickedSet.clear();
this.clickedIndexSet.clear();
this.mCallbacks['allSelect'] && this.mCallbacks['allSelect'](false);
this.mCallbacks['updateCount'] && this.mCallbacks['updateCount'](this.getSelectedCount());
}
@ -242,6 +255,7 @@ export class SelectManager {
this.inverseSelection = false;
this.isAllSelected = false;
this.clickedSet.clear();
this.clickedIndexSet.clear();
this.mCallbacks[`allSelect`] && this.mCallbacks[`allSelect`](false);
}
}
@ -294,6 +308,21 @@ export class SelectManager {
})
}
public getSelectedIndexes(): number[] {
let selectIndexes: number[] = new Array();
if (this.inverseSelection) {
for (let i = 0; i < this.totalCount; i++) {
if (!this.clickedIndexSet.has(i)) {
selectIndexes.push(i);
}
}
} else {
selectIndexes = Array.from(this.clickedIndexSet);
}
this.logger.info(`getSelectedIndexes ${selectIndexes}`);
return selectIndexes;
}
public handleSelection(mediaItems: MediaItem[], callback: AsyncCallback<string[]>) {
let result = [];
mediaItems.forEach((mediaItem) => {
@ -402,22 +431,25 @@ export class TimelineSelectManager extends SelectManager {
this.mCallbacks['updateCount'] && this.mCallbacks['updateCount'](this.getSelectedCount());
}
private toggleClickSet(entry: BucketSelectionEntry, targetId: string, isSelected: boolean) {
private toggleClickSet(entry: BucketSelectionEntry, targetId: string, targetIndex: number, isSelected: boolean) {
this.logger.info(`toggleClickSet: ${targetId} + ${isSelected}`);
if (isSelected == (!this.inverseSelection)) {
this.toggleEntryItem(entry, targetId, true);
this.toggleEntryItem(entry, targetId, targetIndex, true);
} else {
this.toggleEntryItem(entry, targetId, false);
this.toggleEntryItem(entry, targetId, targetIndex, false);
}
}
private toggleEntryItem(entry: BucketSelectionEntry, targetId: string, isSelected: boolean) {
private toggleEntryItem(entry: BucketSelectionEntry, targetId: string, targetIndex: number, isSelected: boolean) {
this.logger.info(`toggleEntryItem ${targetId} ${isSelected}`);
let clickSet = entry.getClickSet();
let clickIndexSet = entry.getClickIndexSet();
if (isSelected != entry.getInverseSelection()) {
clickSet.add(targetId);
clickIndexSet.add(targetIndex);
} else {
clickSet.delete(targetId);
clickIndexSet.delete(targetIndex);
}
}
@ -425,7 +457,7 @@ export class TimelineSelectManager extends SelectManager {
this.logger.info(`toggleTimeline ${targetIndex} id: ${targetId} ${isSelected}`);
let itemCoordinate = this.getCoordinateFromPosition(targetIndex);
let entry = this.getGroupEntry(itemCoordinate);
this.toggleClickSet(entry, targetId, isSelected);
this.toggleClickSet(entry, targetId, targetIndex, isSelected);
let entrySelectedCount = entry.getSelectedCount();
this.logger.info(`check all selected ${entrySelectedCount} ${entry.getTotalCount()}`);
@ -705,6 +737,64 @@ export class TimelineSelectManager extends SelectManager {
}
}
public getSelectedIndexes(): number[] {
this.logger.info('getSelectedIndexes');
let indexes: number[] = new Array()
let start: number = 0
if (this.inverseSelection) {
for (let i = 0; i < this.mGroupData.length; i++) {
let entry = this.mSelectionEntryArray[i];
if (entry) {
let entryClickIndexSet = entry.getClickIndexSet()
if (entry.getInverseSelection()) {
entryClickIndexSet.forEach((item) => {
indexes.push(item)
})
} else {
for (let j = start + i + 1; j <= start + i + this.mGroupData[i].count; j++) {
if (!entryClickIndexSet.has(j)) {
indexes.push(j)
}
}
}
} else {
for (let j = start + i; j <= start + i + this.mGroupData[i].count; j++) {
indexes.push(j)
}
}
start += this.mGroupData[i].count;
}
} else {
for (let i = 0; i < this.mGroupData.length; i++) {
let entry = this.mSelectionEntryArray[i];
if (entry) {
let entryClickIndexSet = entry.getClickIndexSet();
if (entry.getInverseSelection()) {
if (entryClickIndexSet.size == 0) {
this.logger.info('group is all select');
for (let j = start + i; j <= start + i + this.mGroupData[i].count; j++) {
indexes.push(j)
}
} else {
for (let j = start + i + 1; j <= start + i + this.mGroupData[i].count; j++) {
if (!entryClickIndexSet.has(j)) {
indexes.push(j)
}
}
}
} else {
entryClickIndexSet.forEach((item) => {
indexes.push(item)
})
}
}
start += this.mGroupData[i].count;
}
}
this.logger.info(`getSelectedIndexes end ${indexes}`);
return indexes
}
private checkIsGetSelectionFinish(doneCount: number, result: string[], callback: AsyncCallback<string[]>): void {
if (this.mGroupData.length == doneCount) {
this.logger.info(`getSelection result ${result.length}`);

View File

@ -77,6 +77,9 @@ export class Constants {
// photo show state
static readonly PHOTO_SHOW_STATE = 'single_photo_show_state';
// photo can rotate
static readonly PHOTO_CAN_ROTATE = 'single_photo_can_rotate';
// set swiper can swipe
static readonly SET_DISABLE_SWIPE = 'set_disable_swipe';

View File

@ -213,8 +213,8 @@ export class MediaDataSource extends AbsDataSource {
*/
updateSize(requestTime: number, count: number): void {
this.logger.info(`updateSize, old size: ${this.size}, new size: ${count}`)
this.isCountChanged = count != this.size;
this.isCountReduced = count < this.size;
this.isCountChanged = count != this.mediaCount;
this.isCountReduced = count < this.mediaCount;
this.mediaCount = count;
this.size = this.mediaCount;
this.dataIndexes = [];
@ -430,6 +430,60 @@ export class MediaDataSource extends AbsDataSource {
{ id: this.albumId, start: requestStart, count: requestCount, deviceId: this.deviceId });
}
deleteData(indexes: number[]): void {
this.logger.info(`deleteData ${indexes}`);
let sortIndexes = indexes.sort(function (a, b) {
return a - b
});
let dataDeleteIndexes = this.getDataIndexes(indexes);
this.deleteDataUpdateSize(sortIndexes);
this.deleteDataUpdateData(dataDeleteIndexes);
this.broadCast.emit(BroadCastConstants.ON_DATA_RELOADED, [sortIndexes]);
}
getDataIndexes(indexes: number[]) {
return indexes;
}
deleteDataUpdateSize(indexes: number[]) {
this.logger.info(`deleteDataUpdateSize`);
let count = 0;
for (let index of indexes) {
let newIndex = index - count;
for (let i = newIndex + 1; i < this.dataIndexes.length; i++) {
this.dataIndexes[i] = this.dataIndexes[i] - 1;
this.layoutIndexes[i] = this.layoutIndexes[i] - 1;
}
count++;
this.dataIndexes.splice(newIndex, 1);
this.layoutIndexes.splice(newIndex, 1);
}
this.size = this.size - indexes.length;
}
deleteDataUpdateData(indexes: number[]) {
this.logger.info(`deleteDataUpdateData ${indexes}`);
let countBeforeActiveStart = 0;
for (let index of indexes) {
if (index < this.activeStart) {
countBeforeActiveStart++;
} else if (index < this.activeEnd) {
this.items[index - this.activeStart] = undefined;
} else {
break;
}
}
let newData = this.items.filter((item) => {
return (item != undefined)
})
newData = newData.slice(countBeforeActiveStart);
while (newData.length != Constants.DEFAULT_SLIDING_WIN_SIZE) {
newData.push(undefined);
}
this.items = newData;
}
private getWindowActiveStart(dataIndex: number, windowCenter: number): number{
let isForward = (dataIndex > windowCenter);
let halfWinSize = Math.round(this.windowSize / 2);

View File

@ -36,6 +36,7 @@ export class MediaItem {
displayName: string;
filePath: string;
path: string;
canRotate: boolean;
constructor(data) {
if (data == null) {
@ -62,6 +63,7 @@ export class MediaItem {
this.imgHeight = this.height;
this.displayName = data.displayName;
this.path = data.relativePath;
this.canRotate = false;
}
setThumbnail(thumbnail: string) {
@ -71,4 +73,27 @@ export class MediaItem {
setFavorite(isFavorite: boolean) {
this.isFavor = isFavorite;
}
setOrientation(orientation: string) {
if (orientation.length == 0) {
this.canRotate = false;
return
}
this.canRotate = true;
switch (orientation) {
case "Left-bottom":
this.orientation = 270
break
case "Bottom-right":
this.orientation = 180
break
case "Right-top":
this.orientation = 90
break;
case "Top-left":
this.orientation = 0
break
default:
}
}
}

View File

@ -13,6 +13,7 @@
* limitations under the License.
*/
import image from '@ohos.multimedia.image'
import { AlbumDefine } from '../AlbumDefine'
import { BrowserDataImpl } from '../BrowserDataImpl'
import { Logger } from '../../../utils/Logger'
@ -37,7 +38,6 @@ export class PhotoDataImpl extends BrowserDataImpl {
}
// Querying MediaLibrary data
let mediaItemList: MediaItem[] = [];
this.getItems(param.id, param.start, param.count, param.deviceId).then((dataList) => {
this.logger.info(`getMediaItem coming`);
if (dataList != null) {
@ -53,30 +53,52 @@ export class PhotoDataImpl extends BrowserDataImpl {
TraceControllerUtils.startTraceWithTaskId('getFavorInfo', dataList.length);
Promise.all(this.handlePromise(promiseStatus)).then((favor: any) => {
TraceControllerUtils.finishTraceWithTaskId('getFavorInfo', dataList.length);
for (let i = 0; i < promiseStatus.length; i++) {
try {
let item = dataList[i];
let mediaItem: MediaItem = new MediaItem(item);
if (favor[i].status = 'success') {
mediaItem.setFavorite(favor[i].res);
} else {
this.logger.error(`getFavorite error: ${favor[i].err}`);
}
mediaItem.setThumbnail(this.getThumbnailSafe(item.uri));
mediaItemList.push(mediaItem);
}
catch (err) {
this.logger.error(`getItems error: ${err}`);
}
}
this.logger.info(`getMediaItem item size: ${mediaItemList.length}`);
callback.callback(mediaItemList);
this.getMediaItemList(dataList, promiseStatus, favor, callback)
})
}
});
}
private async getMediaItemList(dataList, promiseStatus: Array<Promise<boolean>>, favor: any, callback: AsyncCallback<MediaItem[]>) {
let mediaItemList: MediaItem[] = [];
for (let i = 0; i < promiseStatus.length; i++) {
try {
let item = dataList[i];
let mediaItem: MediaItem = new MediaItem(item);
await this.checkRotate(mediaItem, item)
if (favor[i].status = 'success') {
mediaItem.setFavorite(favor[i].res);
} else {
this.logger.error(`getFavorite error: ${favor[i].err}`);
}
mediaItem.setThumbnail(this.getThumbnailSafe(item.uri));
mediaItemList.push(mediaItem);
}
catch (err) {
this.logger.error(`getItems error: ${err}`);
}
}
this.logger.info(`getMediaItem item size: ${mediaItemList.length}`);
callback.callback(mediaItemList);
}
private async checkRotate(mediaItem: MediaItem, fileAsset): Promise<void> {
this.logger.info(`checkRotate`);
let fd = await MediaLibraryAccess.getInstance().openAsset('RW', fileAsset);
this.logger.debug(`get fd ${fd}`);
let imageSourceApi: image.ImageSource = image.createImageSource(fd);
this.logger.debug(`get imageSourceApi ${mediaItem.displayName}`);
try {
let orientation = await imageSourceApi.getImageProperty("Orientation")
this.logger.debug(`get imageSourceApi ${mediaItem.displayName} success ${orientation}`);
mediaItem.setOrientation(orientation)
} catch (err) {
this.logger.debug(`get imageSourceApi ${mediaItem.displayName} fail`);
mediaItem.setOrientation("")
}
}
handlePromise(promiseList) {
return promiseList.map(promise => promise.then((res) => ({ status: 'success', res }),
(err) => ({ status: 'failed', err })))

View File

@ -26,6 +26,7 @@ import { AlbumDefine } from '../AlbumDefine'
import { BroadCastManager } from '../../common/BroadCastManager';
import { ImageUtil } from '../../../utils/ImageUtil';
import { ScreenManager } from '../../common/ScreenManager';
import { MediaLibraryAccess } from '../../../access/MediaLibraryAccess';
// DataSource
export class PhotoDataSource implements IDataSource, LoadingListener {
@ -92,28 +93,18 @@ export class PhotoDataSource implements IDataSource, LoadingListener {
this.logger.info(`getData index ${index}`);
this.albumDataSource.updateSlidingWindow(index);
let mediaItem: MediaItem = this.albumDataSource.getRawData(index);
if (mediaItem.mediaType == MediaLibraryAccess.MEDIA_TYPE_IMAGE) {
// Thumbnail max size is 1080, so photos should use uri instead
return { data: mediaItem, pos: index, thumbnail: mediaItem.uri };
}
if (mediaItem.height == 0 || mediaItem.width == 0) {
this.getDataById(mediaItem.id).then((result) => {
mediaItem = new MediaItem(result);
if (mediaItem.height == 0 || mediaItem.width == 0) {
return;
}
let index = this.albumDataSource.getIndexByMediaItem(mediaItem);
if (index != -1) {
this.albumDataSource.onDataChanged(index);
}
this.onDataChanged(index);
})
this.logger.warn(`height ${mediaItem.height} width: ${mediaItem.width}`)
}
let orientation = mediaItem.orientation || 0;
let imgWidth = orientation == 0 || orientation == PhotoConstants.ROTATE_TWICE ? mediaItem.width : mediaItem.height;
let imgHeight = orientation == 0 || orientation == PhotoConstants.ROTATE_TWICE ? mediaItem.height : mediaItem.width;
let scale = this.generateSampleSize(imgWidth, imgHeight, index);
mediaItem.imgWidth = Math.ceil(mediaItem.width / scale);
mediaItem.imgHeight = Math.ceil(mediaItem.height / scale);
imgWidth = Math.ceil(imgWidth / scale);
imgHeight = Math.ceil(imgHeight / scale);
return {
data: mediaItem,
pos: index,
@ -222,8 +213,8 @@ export class PhotoDataSource implements IDataSource, LoadingListener {
};
private generateSampleSize(imageWidth: number, imageHeight: number, index: number): number {
let width = ScreenManager.getInstance().getWinWidth();
let height = ScreenManager.getInstance().getWinHeight();
let width = vp2px(ScreenManager.getInstance().getWinWidth());
let height = vp2px(ScreenManager.getInstance().getWinHeight());
width = width == 0 ? ScreenManager.DEFAULT_WIDTH : width;
height = height == 0 ? ScreenManager.DEFAULT_HEIGHT : height;
let maxNumOfPixels

View File

@ -12,6 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import Matrix4 from '@ohos.matrix4'
import router from '@system.router'
import { MediaItem } from '../../common/model/browser/photo/MediaItem'
@ -52,6 +53,7 @@ export struct PhotoItem {
onTransitionChange() {
this.logger.info(`onTransitionChange , ${this.updateTransition} ${this.position}`);
this.photoCanRotateCheck();
if (this.updateTransition == this.position) {
this.transitionId = this.transitionTag + this.item.uri;
this.broadCast.emit(PhotoConstants.PHOTO_SHOW_STATE, [!this.showError]);
@ -74,7 +76,7 @@ export struct PhotoItem {
}
aboutToAppear(): void {
this.logger.info(`photoItem aboutToAppear ${this.item.uri}`);
this.logger.info(`photoItem aboutToAppear ${this.thumbnail}`);
this.eventPipeline = new EventPipeline(this.broadCast, this.item);
this.matrix = Matrix4.identity().copy();
this.firstLoad = true;
@ -99,8 +101,17 @@ export struct PhotoItem {
this.logger.info(`photoItem aboutToAppear ${this.item.uri} end`);
}
private photoCanRotateCheck() {
if (this.updateTransition != this.position) {
this.logger.info(`photoCanRotateCheck not current photo`);
return
}
this.logger.debug(`photoCanRotateCheck this.item.canRotate ${this.item.canRotate}`);
this.broadCast.emit(PhotoConstants.PHOTO_CAN_ROTATE, [this.item.canRotate]);
}
aboutToDisappear(): void {
this.logger.info(`aboutToDisappear ${this.item.uri}`);
this.logger.info(`aboutToDisappear ${this.thumbnail}`);
// clean up event registration
this.broadCast.off(PhotoConstants.TOUCH_EVENT + this.item.uri, null);
this.broadCast.off(PhotoConstants.DIRECTION_CHANGE + this.item.uri, null);

View File

@ -31,7 +31,7 @@ export struct TabBar {
@Consume isSelectedMode: boolean;
@Consume isAlbumSetSelectedMode: boolean;
private currentIndex: number;
private isSidebar: boolean = false;
@StorageLink('isSidebar') isSidebar: boolean = ScreenManager.getInstance().isSidebar();
private tabs: TabItem[] = [];
private controller: TabsController;
private logger: Logger = new Logger('TabBar');

View File

@ -82,7 +82,7 @@ export struct FindSameNameDialog {
Column() {
Text($r('app.string.target_has_same_name', this.getTitle(this.sourceDetails.displayName)))
.fontSize($r('sys.float.ohos_id_text_size_sub_title2'))
.fontWeight(FontWeight.Bold)
.fontWeight(FontWeight.Medium)
.fontColor($r('sys.color.ohos_id_color_text_primary'))
.maxLines(3)
}
@ -92,8 +92,8 @@ export struct FindSameNameDialog {
Row() {
Column() {
Text($r('app.string.source_file_location'))
.fontSize($r('sys.float.ohos_id_text_size_sub_title3'))
.fontWeight(FontWeight.Bold)
.fontSize($r('sys.float.ohos_id_text_size_sub_title2'))
.fontWeight(FontWeight.Medium)
.fontColor($r('sys.color.ohos_id_color_text_primary'))
}
}.margin({
@ -114,7 +114,7 @@ export struct FindSameNameDialog {
Text($r('app.string.file_time_location', this.dataTime))
.fontSize($r('sys.float.ohos_id_text_size_body2'))
.fontWeight(FontWeight.Regular)
.fontColor($r('sys.color.ohos_id_color_text_primary'))
.fontColor($r('sys.color.ohos_id_color_text_secondary'))
}
}.margin({
bottom: $r('app.float.same_name_date_title_dialog_bottom') })
@ -123,7 +123,7 @@ export struct FindSameNameDialog {
Column() {
Text($r('app.string.target_file_location'))
.fontSize($r('sys.float.ohos_id_text_size_sub_title2'))
.fontWeight(FontWeight.Bold)
.fontWeight(FontWeight.Medium)
.fontColor($r('sys.color.ohos_id_color_text_primary'))
}
}.margin({
@ -144,7 +144,7 @@ export struct FindSameNameDialog {
Text($r('app.string.file_time_location', this.targetDataTime))
.fontSize($r('sys.float.ohos_id_text_size_body2'))
.fontWeight(FontWeight.Regular)
.fontColor($r('sys.color.ohos_id_color_text_primary'))
.fontColor($r('sys.color.ohos_id_color_text_secondary'))
}
}.margin({
bottom: $r('app.float.same_name_date_title_dialog_bottom') })

View File

@ -143,7 +143,7 @@ export struct AlbumGridItemNewStyle {
.height($r('app.float.recycle_album_cover_icon_size'))
.fillColor($r('app.color.empty_or_recycle_album_icon'))
}
.height(this.icHeight)
.height(this.gridHeight)
.width('100%')
}
.height(this.gridHeight)

View File

@ -13,12 +13,14 @@
* limitations under the License.
*/
import image from '@ohos.multimedia.image'
import { Logger } from '../../../common/utils/Logger';
import { Constants } from '../../../common/model/browser/photo/Constants'
import { MenuOperation } from '../../../common/view/browserOperation/MenuOperation'
import { MenuContext } from '../../../common/view/browserOperation/MenuContext'
import { BrowserOperationFactory } from '../../../common/interface/BrowserOperationFactory'
import { BrowserDataFactory } from '../../../common/interface/BrowserDataFactory'
import { MediaLibraryAccess } from '../../../common/access/MediaLibraryAccess';
export class RotateMenuOperation implements MenuOperation {
private menuContext: MenuContext;
@ -50,8 +52,39 @@ export class RotateMenuOperation implements MenuOperation {
let dataImpl = BrowserDataFactory.getFeature(BrowserDataFactory.TYPE_PHOTO);
let fileAsset = await dataImpl.getDataById(id);
operationImpl.setOrientation(fileAsset, orientation);
await operationImpl.commitChanges(fileAsset);
if (!fileAsset) {
this.logger.error('get file asset failed.');
return;
}
this.logger.debug(`get fileAsset ${JSON.stringify(fileAsset)}`);
let fd = await MediaLibraryAccess.getInstance().openAsset('RW', fileAsset);
this.logger.debug(`get fd ${fd}`);
let imageSourceApi: image.ImageSource = image.createImageSource(fd);
this.logger.debug(`get imageSourceApi`);
try {
await imageSourceApi.modifyImageProperty("Orientation", this.getPropertyValidOrientation(orientation))
this.logger.debug(`modifyImageProperty ${fileAsset.displayName} finish`);
} catch (error) {
this.logger.error(`modifyImageProperty ${fileAsset.displayName} fail`)
}
await MediaLibraryAccess.getInstance().closeAsset(fd, fileAsset)
this.menuContext.broadCast.emit(Constants.ROTATE, [orientation]);
}
private getPropertyValidOrientation(orientation: number): string {
this.logger.info(`getPropertyValidOrientation ${orientation}`)
switch (orientation) {
case 0:
return "1";
case 270:
return "8";
case 180:
return "3";
case 90:
return "6";
default:
return ""
}
}
}

View File

@ -63,8 +63,8 @@ import resourceManager from '@ohos.resourceManager';
struct PhotoBrowser {
@State opacity: number = 1;
@Provide backgroundColor: Resource = $r('app.color.default_background_color');
@Provide(dateTitle) photoDate: string = '';
@Provide(timeLocationTitle) timeAndLocation: string = '';
@Provide('dateTitle') photoDate: string = '';
@Provide('timeLocationTitle') timeAndLocation: string = '';
@Provide menuList: Array<Action> = new Array<Action>();
private toolMenuList: Array<Action> = new Array<Action>();
@Provide topMenuList: Array<Action> = new Array<Action>();
@ -74,7 +74,8 @@ struct PhotoBrowser {
@Provide isPullingDown: boolean = false;
@Provide pageFrom: number = Constants.ENTRY_FROM.NORMAL;
@Provide canSwipe: boolean = false;
@State @Watch('updateMoreMenu') currentShow: boolean = true;
@State @Watch('currentShowChange') currentShow: boolean = true;
@State @Watch('canRotateChange') canRotate: boolean = false;
@StorageLink('isHorizontal') isHorizontal: boolean = ScreenManager.getInstance().isHorizontal();
@StorageLink('TimelinePageIndex') TimelinePageIndex: number = Constants.INVALID;
@StorageLink('PhotoGridPageIndex') PhotoGridPageIndex: number = Constants.INVALID;
@ -344,7 +345,6 @@ struct PhotoBrowser {
}
this.toolMenuList = [];
this.moreMenuList = [];
let list: Array<Action> = new Array<Action>();
switch (this.pageFrom) {
@ -372,24 +372,23 @@ struct PhotoBrowser {
} else {
this.toolMenuList = list;
}
if (currentPhoto.mediaType == MediaLibraryAccess.MEDIA_TYPE_IMAGE) {
this.moreMenuList.push(Action.MOVE, Action.COPY, Action.RENAME);
if (this.currentShow) {
this.moreMenuList.push(Action.ROTATE);
}
} else {
this.moreMenuList.push(Action.MOVE, Action.COPY, Action.RENAME);
}
this.updateMoreMenu()
}
updateMoreMenu() {
this.moreMenuList = [];
private currentShowChange() {
this.updateMoreMenu()
}
private canRotateChange() {
this.updateMoreMenu()
}
private updateMoreMenu() {
let currentPhoto = this.getCurrentPhoto();
this.moreMenuList = [];
if (currentPhoto.mediaType == MediaLibraryAccess.MEDIA_TYPE_IMAGE) {
this.moreMenuList.push(Action.MOVE, Action.COPY, Action.RENAME);
if (this.currentShow) {
if (this.currentShow && this.canRotate) {
this.moreMenuList.push(Action.ROTATE);
}
} else {
@ -650,6 +649,11 @@ struct PhotoBrowser {
this.currentShow = state;
});
this.broadCast.on(PhotoConstants.PHOTO_CAN_ROTATE, (state: boolean) => {
this.logger.debug(`current photo can rotate ${state}`);
this.canRotate = state;
});
this.broadCast.on(PhotoConstants.SET_DISABLE_SWIPE, (value: boolean) => {
this.logger.info(`set swiper swipe ${value}`);
this.canSwipe = value;
@ -897,7 +901,7 @@ struct PhotoBrowser {
onMenuClicked: this.onMenuClicked,
})
ToolBar({
isShowBar: $isShowBar,
isShowBar: this.isShowBar,
toolMenuList: this.toolMenuList,
onMenuClicked: this.onMenuClicked,
isFromPhotoBrowser: true

View File

@ -43,7 +43,7 @@ export struct PhotoBrowserActionBar {
build() {
Column() {
ActionBar({
isShowBar: $isShowBar,
isShowBar: this.isShowBar,
actionBarProp: this.createActionBar(),
onMenuClicked: this.onMenuClicked,
isVideoPage: this.isVideoPage

View File

@ -59,6 +59,7 @@ struct SettingDialog {
.fontSize($r('sys.float.ohos_id_text_size_headline7'))
.fontFamily($r('app.string.id_text_font_family_regular'))
.fontColor($r('sys.color.ohos_id_color_text_primary'))
.fontWeight(FontWeight.Medium)
}.alignItems(VerticalAlign.Center)
.height($r('app.float.dialog_title_height'))
@ -78,6 +79,7 @@ struct SettingDialog {
}) {
Radio({ group: 'timeGroup', value: item.value })
.checked(item.checked)
.offset({ x: $r('app.float.form_card_radius_offset') })
.onChange((checked: boolean) => {
item.checked = checked;
if (checked) {
@ -406,8 +408,10 @@ struct FormEditorPage {
.fillColor($r('app.color.white'))
.width($r('app.float.FA_back_size'))
.height($r('app.float.FA_back_size'))
.margin({ left: $r('app.float.FA_back_margin_left'), top: $r('app.float.FA_back_margin_top') })
.margin({ left: $r('app.float.FA_back_margin_left') })
}
.height($r('app.float.title_default'))
.alignItems(VerticalAlign.Center)
.width('100%')
.onClick(() => {
this.terminate();
@ -443,6 +447,7 @@ struct FormEditorPage {
Image($r('app.media.ic_gallery_form_arrow'))
.width($r('app.float.form_list_card_more_arrow_w'))
.height($r('app.float.form_list_card_more_arrow_h'))
.fillColor($r('sys.color.ohos_id_color_fourth'))
}
}
.width('100%')
@ -476,6 +481,7 @@ struct FormEditorPage {
Image($r('app.media.ic_gallery_form_arrow'))
.width($r('app.float.form_list_card_more_arrow_w'))
.height($r('app.float.form_list_card_more_arrow_h'))
.fillColor($r('sys.color.ohos_id_color_fourth'))
}
}
.width('100%')
@ -530,11 +536,12 @@ struct FormEditorPage {
: (Constants.NUMBER_2 == this.time / Constants.DEFAULT_TIME) ? $r('app.string.fa_play_interval_time_60')
: $r('app.string.fa_play_interval_time_30'))
.fontSize($r('sys.float.ohos_id_text_size_body2'))
.fontColor(Color.Gray)
.fontColor($r('sys.color.ohos_id_color_text_secondary'))
.margin({ right: $r('app.float.form_list_card_more_gap') })
Image($r('app.media.ic_gallery_form_arrow'))
.width($r('app.float.form_list_card_more_arrow_w'))
.height($r('app.float.form_list_card_more_arrow_h'))
.fillColor($r('sys.color.ohos_id_color_fourth'))
}
}
.width('100%')

View File

@ -1,4 +1,3 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
@ -80,6 +79,7 @@ export struct PhotoGridPage {
isActive = false;
isDistributedAlbum = false;
deleteMode: boolean = false;
deleteReady = true;
routerStart = false;
private dataObserver: CommonObserverCallback = new CommonObserverCallback(this);
private appBroadCast: BroadCast = BroadCastManager.getInstance().getBroadCast();
@ -315,14 +315,22 @@ export struct PhotoGridPage {
onMoveEnd(err, count, total): void {
this.logger.info(`onMoveEnd count: ${count}, total: ${total}`);
this.isDataFreeze = false;
let deleteIndexes = this.mSelectManager.getSelectedIndexes();
if (deleteIndexes.length >= Constants.DEFAULT_SLIDING_WIN_SIZE) {
this.deleteReady = false;
}
this.dataSource.unfreeze();
if (count == deleteIndexes && this.albumInfo.id != AlbumDefine.ALBUM_ID_ALL && this.deleteReady) {
this.dataSource.deleteData(deleteIndexes);
}
this.onModeChange();
MediaObserver.getInstance().registerObserver(this.dataObserver);
this.dataSource.switchRefreshOn();
this.dataSource.onChange(Constants.MEDIA_TYPE_IMAGE);
this.dataSource.unfreeze();
if (err) {
UiUtil.showToast($r('app.string.move_failed_single'));
}
this.deleteReady = true;
}
onDeleteStart(): void {
@ -333,13 +341,21 @@ export struct PhotoGridPage {
this.dataSource.freeze();
}
onDeleteEnd(): void {
onDeleteEnd(err): void {
this.logger.info(`onDeleteEnd`);
this.isDataFreeze = false;
let deleteIndexes = this.mSelectManager.getSelectedIndexes();
if (deleteIndexes.length >= Constants.DEFAULT_SLIDING_WIN_SIZE) {
this.deleteReady = false;
}
this.dataSource.unfreeze();
if (!err && this.deleteReady) {
this.dataSource.deleteData(deleteIndexes);
}
this.onModeChange();
MediaObserver.getInstance().registerObserver(this.dataObserver);
this.dataSource.onChange(Constants.MEDIA_TYPE_IMAGE);
this.dataSource.unfreeze();
this.deleteReady = true;
}
freezeAdapter(fn): Function {
@ -481,7 +497,7 @@ export struct PhotoGridPage {
this.broadCast.on(BroadCastConstants.SELECT,
(position: number, key: string, value: boolean, callback: Function) => {
if (self.mSelectManager.toggle(key, value)) {
if (self.mSelectManager.toggle(key, value, position)) {
self.logger.info('enter event process')
if (!self.isSelectedMode) {
self.isSelectedMode = true;
@ -554,7 +570,9 @@ export struct PhotoGridPage {
this.mSelectManager.registerCallback('allSelect', this.freezeAdapter((newState: boolean) => {
self.logger.info(`allSelect ${newState}`);
self.isAllSelected = newState;
self.dataSource.forceUpdate();
if (!self.deleteMode && this.isSelectedMode) {
self.dataSource.forceUpdate();
}
}));
this.mSelectManager.registerCallback('updateCount', this.freezeAdapter((newState: number) => {
self.logger.info(`updateSelectedCount ${newState}`);
@ -569,16 +587,28 @@ export struct PhotoGridPage {
self.mSelectManager.setTotalCount(newState);
})
this.broadCast.on(BroadCastConstants.ON_DATA_RELOADED, () => {
this.broadCast.on(BroadCastConstants.ON_DATA_RELOADED, (sortIndexes: number[]) => {
this.logger.info('ON_DATA_RELOADED');
if (this.deleteMode) {
if (this.deleteMode && sortIndexes) {
animateTo({ duration: Constants.DELETE_ANIMATE_DURATION }, () => {
this.dataSource.onDataReloaded();
let indexes = sortIndexes.reverse()
indexes.forEach((index) => {
this.dataSource.onDataDeleted(index);
})
})
this.deleteMode = false;
} else {
} else if (sortIndexes) {
let indexes = sortIndexes.reverse()
indexes.forEach((index) => {
this.dataSource.onDataDeleted(index);
})
}
else {
if (this.isSelectedMode) {
this.deleteReady = false; // change index when selected mode
}
this.dataSource.onDataReloaded();
}
this.deleteMode = false;
});
ScreenManager.getInstance().on(ScreenManager.ON_WIN_SIZE_CHANGED, () => {
@ -655,7 +685,8 @@ export struct PhotoGridPage {
item: item.mediaItem,
isSelected: this.isSelectedMode ?
this.mSelectManager.isItemSelected(item.mediaItem.uri) : false,
pageName: Constants.PHOTO_TRANSITION_ALBUM
pageName: Constants.PHOTO_TRANSITION_ALBUM,
position: item.viewIndex
})
}
.columnStart(item.viewIndex % this.gridRowCount)

View File

@ -81,6 +81,11 @@ export struct ThirdSelectAlbumSetPage {
}
}
this.logger.info(`isFromFa: ${this.isFromFa} isFromFaPhoto ${this.isFromFaPhoto}`);
if (this.isFromFa) {
this.albums.setBlackList([AlbumDefine.ALBUM_ID_VIDEO, AlbumDefine.ALBUM_ID_RECYCLE]);
} else {
this.albums.setBlackList([AlbumDefine.ALBUM_ID_RECYCLE]);
}
this.leftAction = this.isFromFa ? Action.BACK : Action.CANCEL
this.title = (this.isFromFa && !this.isFromFaPhoto) ? ActionBarProp.SINGLE_SELECT_ALBUM_TITLE : ActionBarProp.SINGLE_UNSELECT_TITLE
this.albums.setBlackList([AlbumDefine.ALBUM_ID_VIDEO, AlbumDefine.ALBUM_ID_RECYCLE])

View File

@ -127,11 +127,59 @@ export class TimelineDataSource extends MediaDataSource {
this.logger.info(`updateGroupSize, old size: ${previousSize} , old mediaCount: ${previousMediaCount},\
new size: ${this.size}, new mediaCount: ${this.mediaCount}`);
this.isCountChanged = previousSize != this.size;
this.isCountReduced = previousSize > this.size;
this.isCountChanged = previousMediaCount != this.mediaCount;
this.isCountReduced = previousMediaCount > this.mediaCount;
this.updateCountPostProcess();
}
deleteDataUpdateSize(indexes: number[]) {
this.logger.info(`deleteDataUpdateSize ${indexes}`);
let count = 0;
let isGroup = true
for (let index of indexes) {
let newIndex = index - count;
if (this.dataIndexes[newIndex] == TITLE_DATA_INDEX) {
for (let i = newIndex + 1; i < this.dataIndexes.length; i++) {
this.layoutIndexes[i] = this.layoutIndexes[i] - 1;
this.groupIndexes[i] = this.groupIndexes[i] - 1;
}
} else {
for (let i = newIndex + 1; i < this.dataIndexes.length; i++) {
if (this.dataIndexes[i] == TITLE_DATA_INDEX) {
isGroup = false;
} else {
this.dataIndexes[i] = this.dataIndexes[i] - 1;
if (isGroup) {
this.groupViewIndexes[i] = this.groupViewIndexes[i] - 1;
}
}
this.layoutIndexes[i] = this.layoutIndexes[i] - 1;
}
isGroup = true
this.layoutIndexes.splice(newIndex, 1);
}
this.dataIndexes.splice(newIndex, 1);
this.groupIndexes.splice(newIndex, 1);
this.groupViewIndexes.splice(newIndex, 1);
count++;
}
this.size = this.size - indexes.length;
}
getDataIndexes(indexes: number[]) {
let newDataIndexes = []
for (let index of indexes) {
if (this.dataIndexes[index] != TITLE_DATA_INDEX) {
newDataIndexes.push(this.dataIndexes[index]);
}
}
return newDataIndexes
}
emitCountUpdateCallbacks(): void {
this.pendingEmitCallbacks.execute(() => {
super.emitCountUpdateCallbacks();

View File

@ -67,7 +67,6 @@ export struct TimelinePage {
@StorageLink('isSplitMode') isSplitMode: boolean = ScreenManager.getInstance().isSplitMode();
@StorageLink('leftBlank') leftBlank: [number, number, number, number]
= [0, ScreenManager.getInstance().getStatusBarHeight(), 0, ScreenManager.getInstance().getNaviBarHeight()];
dataSource: TimelineDataSource;
logger: Logger = new Logger('TimelinePage');
mSelectManager: TimelineSelectManager = new TimelineSelectManager();
scroller: Scroller = new Scroller();
@ -76,6 +75,7 @@ export struct TimelinePage {
dataObserver: CommonObserverCallback = new CommonObserverCallback(this);
isDataFreeze = false; // Is the page data frozen
deleteMode = false; // Is delete mode
deleteReady = true; // use local delete mode
isActive = false; // Is the page active
@State initLoadFinish: boolean = false; // Is first patch load finished
routerStart = false; // Is move or copy router page
@ -83,13 +83,13 @@ export struct TimelinePage {
@State groupSelectMode: boolean[] = [];
@Provide yearData: TimelineData[] = [];
@Provide dateText: string = '';
private dataSource: TimelineDataSource = TimelineDataSourceManager.getInstance().getDataSource();
private barModel = new TimelinePageBarModel()
aboutToAppear(): void {
TraceControllerUtils.startTrace('TimelinePageAboutToAppear');
this.logger.info('aboutToAppear');
let self = this;
this.dataSource = TimelineDataSourceManager.getInstance().getDataSource();
let params = router.getParams();
if (params != null && params.pageFrom && params.pageFrom == Constants.ENTRY_FROM.CAMERA) {
this.dataSource.initData();
@ -187,16 +187,22 @@ export struct TimelinePage {
});
});
this.broadCast.on(BroadCastConstants.ON_DATA_RELOADED, () => {
this.broadCast.on(BroadCastConstants.ON_DATA_RELOADED, (sortIndexes) => {
this.logger.info('ON_DATA_RELOADED');
if (this.deleteMode) {
if (this.deleteMode && sortIndexes) {
animateTo({ duration: Constants.DELETE_ANIMATE_DURATION }, () => {
this.dataSource.onDataReloaded();
let indexes = sortIndexes.reverse()
indexes.forEach((index) => {
this.dataSource.onDataDeleted(index);
})
})
this.deleteMode = false;
} else {
if (this.isSelectedMode) {
this.deleteReady = false; // change index when selected mode
}
this.dataSource.onDataReloaded();
}
this.deleteMode = false;
});
this.broadCast.on(BroadCastConstants.INIT_DATE_TEXT, () => {
@ -207,7 +213,9 @@ export struct TimelinePage {
this.mSelectManager.registerCallback('allSelect', this.freezeAdapter((newState: boolean) => {
self.logger.info(`allSelect ${newState}`);
self.isAllSelected = newState;
self.dataSource.forceUpdate();
if (this.deleteMode) {
self.dataSource.forceUpdate();
}
}));
this.mSelectManager.registerCallback('updateGroupCount', this.freezeAdapter(() => {
@ -477,15 +485,23 @@ export struct TimelinePage {
this.dataSource.freeze();
}
onDeleteEnd(): void {
onDeleteEnd(err): void {
this.logger.info(`onDeleteEnd`);
this.isDataFreeze = false;
let deleteIndexes = this.mSelectManager.getSelectedIndexes();
if (deleteIndexes.length >= Constants.DEFAULT_SLIDING_WIN_SIZE) {
this.deleteReady = false;
}
this.dataSource.unfreeze();
if (!err && this.deleteReady) {
this.dataSource.deleteData(deleteIndexes);
}
TraceControllerUtils.startTrace('onModeChange');
this.onModeChange();
TraceControllerUtils.finishTrace('onModeChange');
MediaObserver.getInstance().registerObserver(this.dataObserver);
this.dataSource.onChange(Constants.MEDIA_TYPE_IMAGE);
this.dataSource.unfreeze();
this.deleteReady = true;
}
onCopyStart(): void {

View File

@ -156,6 +156,10 @@
"name": "details_dialog_button_margin_left",
"value": "4vp"
},
{
"name": "form_card_radius_offset",
"value": "12vp"
},
{
"name": "disable_button_opacity",
"value": "0.4"
@ -762,7 +766,7 @@
},
{
"name": "process_bar_margin_left",
"value": "4vp"
"value": "16vp"
},
{
"name": "delete_process_bar_margin_right",

View File

@ -374,7 +374,7 @@
},
{
"name": "save_to_local",
"value": "Save to local"
"value": "Save"
},
{
"name": "mirror_text",
@ -510,7 +510,7 @@
},
{
"name": "rename_failed",
"value": "Unable to rename.Please try again"
"value": "Unable to rename.Please try again."
},
{
"name": "download_progress_message",
@ -546,15 +546,15 @@
},
{
"name": "copy_failed_single",
"value": "Unable to copy.Please try again"
"value": "Unable to copy.Please try again."
},
{
"name": "move_failed_single",
"value": "Unable to move.Please try again"
"value": "Unable to move.Please try again."
},
{
"name": "download_failed_multi",
"value": "Only able to save %d of the items"
"value": "Only able to save %d of the items."
},
{
"name": "local",
@ -714,7 +714,7 @@
},
{
"name": "file_time_location",
"value": "Date modified%s"
"value": "Date modified: %s"
},
{
"name": "do_same_action",
@ -770,7 +770,7 @@
},
{
"name": "edit_save_picture_text",
"value": "Saving photo..."
"value": "Saving picture..."
},
{
"name": "fa_select_time",

View File

@ -70,11 +70,11 @@
"value":[
{
"quantity":"one",
"value":"所选文件将被永久删除,无法恢复。是否删除?"
"value":"所选设备上的文件将被永久删除,无法恢复。确定删除?"
},
{
"quantity":"other",
"value":"所选文件将被永久删除,无法恢复。是否删除?"
"value":"所选设备上的文件将被永久删除,无法恢复。确定删除?"
}
]
}

View File

@ -370,7 +370,7 @@
},
{
"name": "save_to_local",
"value": "保存至本机"
"value": "保存"
},
{
"name": "mirror_text",
@ -714,7 +714,7 @@
},
{
"name": "file_time_location",
"value": "修改时间%s"
"value": "修改时间: %s"
},
{
"name": "do_same_action",