• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022 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 '../../../utils/Log';
17import { PhotoDataSource } from './PhotoDataSource';
18import { MediaItem } from './MediaItem';
19import { Constants as PhotoConstants } from './Constants';
20import { UserFileManagerAccess } from '../../../access/UserFileManagerAccess';
21import { ScreenManager } from '../../common/ScreenManager';
22
23const MEDIA_ABILITY = 'dataability';
24const URL_TAG = '-UriDataSource';
25const TAG: string = 'common_UriDataSource';
26
27class InnerMediaItem extends MediaItem {
28  isHttp: boolean;
29
30  constructor(uri: string) {
31    //后期需要修改这个接口
32    super(undefined);
33    this.uri = uri;
34    this.width = 0;
35    this.height = 0;
36    this.isHttp = !uri.startsWith(MEDIA_ABILITY);
37  }
38}
39
40export class UriDataSource extends PhotoDataSource {
41  private mItems: InnerMediaItem[] = [];
42
43  constructor(uriArr: string[]) {
44    super()
45    this.mItems = uriArr.map((uri) => {
46      let item = new InnerMediaItem(uri);
47      if (uri.startsWith(MEDIA_ABILITY)) {
48        item.setThumbnail(this.photoDataImpl.getThumbnail(item.uri, item.path, {
49          height: item.height,
50          width: item.width
51        }));
52      } else {
53        item.setThumbnail(item.uri);
54      }
55      return item;
56    })
57    Log.debug(TAG, `create items: ${JSON.stringify(this.mItems)}`);
58  }
59
60  initData() {
61  }
62
63  totalCount(): number {
64    return this.mItems.length;
65  }
66
67  getData(index: number): {
68    data: MediaItem,
69    pos: number,
70    thumbnail: string
71  } {
72    return {
73      data: this.mItems[index],
74      pos: index,
75      thumbnail: this.mItems[index].thumbnail
76    };
77  }
78
79  getRawData(index: number): any {
80    return {
81      data: index < this.mItems.length ? this.mItems[index] : new MediaItem(null),
82      pos: index
83    };
84  }
85
86  registerDataChangeListener(listener: DataChangeListener): void {
87    Log.info(TAG, 'registerDataChangeListener');
88  }
89
90  unregisterDataChangeListener(listener: DataChangeListener): void {
91    Log.info(TAG, 'unregisterDataChangeListener');
92  }
93}