• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import type { AsyncCallback } from '../../common/AsyncCallback';
17import { AlbumDefine } from '../AlbumDefine';
18import { TimelineData } from './TimelineData';
19import { DateUtil } from '../../../utils/DateUtil';
20import { Log } from '../../../utils/Log';
21import { FileAsset, UserFileManagerAccess } from '../../../access/UserFileManagerAccess';
22import { BrowserDataImpl } from '../BrowserDataImpl';
23import userFileManager from '@ohos.filemanagement.userFileManager';
24
25const TAG: string = 'TimelineDataImpl';
26
27export class TimelineDataImpl extends BrowserDataImpl {
28
29  // 分组查询方案
30  getData(callback: AsyncCallback<TimelineData[]>, param: unknown): void {
31    Log.info(TAG, `get groupData`);
32    if (callback == null) {
33      Log.info(TAG, 'loadGroupData with empty args');
34      return;
35    }
36    let groupDataList: TimelineData[] = [];
37    this.getGroups().then((groupData: Array<FileAsset>) => {
38      Log.info(TAG, `get groupData length: ${groupData.length}`);
39      if (groupData != null) {
40        if (groupData.length === 0) {
41          Log.warn(TAG, 'get groups empty');
42        }
43        groupData.forEach((data: FileAsset) => {
44          if (!data) {
45            Log.error(TAG, 'group data is null');
46            return;
47          }
48          let groupCount: number = data.get(UserFileManagerAccess.GROUP_BY_KEY) as number;
49          let dateAdded = data.get(userFileManager.ImageVideoKey.DATE_ADDED.toString()) as number * DateUtil.MILLISECONDS_PER_SECOND;
50          let groupData = new TimelineData(dateAdded, dateAdded, groupCount);
51          Log.info(TAG, `groupData count: ${groupCount}`);
52          groupDataList.push(groupData);
53        })
54      }
55      callback.callback(groupDataList);
56    })
57  }
58
59  getDataCount(callback: AsyncCallback<number>, param): void {
60    this.getItemsCount(param.id).then((count) => {
61      Log.info(TAG, `getMediaItemCount callback: ${count}`);
62      callback.callback(count);
63    });
64  }
65
66  async getGroups(): Promise<Array<FileAsset>> {
67    let fetchOpt = AlbumDefine.getTimelineGroupFetchOpt();
68    return await this.getAllObject(fetchOpt);
69  }
70
71  getDataById(id: unknown, deviceId?: unknown): void {
72  }
73
74  getDataByUri(uri: unknown, deviceId?: string): void {
75
76  }
77
78  getDataByName(name: unknown, albumInfo: unknown): void {
79  }
80
81  getDataIndexByUri(callback: AsyncCallback<number>, param: unknown, uri: string): void {
82  }
83}