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 { Log } from '@ohos/common/src/main/ets/default/utils/Log';
17import { PhotoDataImpl } from '@ohos/common/src/main/ets/default/model/browser/photo/PhotoDataImpl';
18import type { AsyncCallback, MediaItem } from '@ohos/common';
19import { StringUtil } from '@ohos/common';
20import type { QueryParam } from '@ohos/common/src/main/ets/default/model/browser/BrowserDataImpl';
21import type SmartPickerDataAdapter from './SmartPickerDataAdapter';
22
23const TAG: string = 'SmartPickerDataImpl';
24
25export default class SmartPickerDataImpl extends PhotoDataImpl {
26  private dataAdapter: SmartPickerDataAdapter;
27
28  constructor() {
29    super();
30  }
31
32  setDataAdapter(dataAdapter: SmartPickerDataAdapter): void {
33    this.dataAdapter = dataAdapter;
34  }
35
36  getData(callback: AsyncCallback<MediaItem[]>, param: QueryParam): void {
37    Log.info(TAG, `getData start ${JSON.stringify(param)}`);
38    if (callback === null || callback === undefined) {
39      Log.error(TAG, 'getData, param or callback is null, return!');
40      return;
41    }
42    if (StringUtil.isEmpty(param?.albumUri)) {
43      return;
44    }
45    this.dataAdapter.getData(callback, param);
46  }
47
48  getDataCount(callback: AsyncCallback<number>, param: QueryParam): void {
49    Log.debug(TAG, `getDataCount: ${JSON.stringify(param)}`);
50    this.dataAdapter.getDataCount(param.albumUri, param.filterMediaType).then((count): void => {
51      callback.callback(count);
52    });
53  }
54}
55
56
57