• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024 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
16if (!("finalizeConstruction" in ViewPU.prototype)) {
17    Reflect.set(ViewPU.prototype, "finalizeConstruction", () => { });
18}
19
20const photoAccessHelper = requireNapi('file.photoAccessHelper');
21const BaseItemInfo = requireNapi('file.PhotoPickerComponent').BaseItemInfo;
22
23const FILTER_MEDIA_TYPE_ALL = 'FILTER_MEDIA_TYPE_ALL';
24const FILTER_MEDIA_TYPE_IMAGE = 'FILTER_MEDIA_TYPE_IMAGE';
25const FILTER_MEDIA_TYPE_VIDEO = 'FILTER_MEDIA_TYPE_VIDEO';
26const FILTER_MEDIA_TYPE_IMAGE_MOVING_PHOTO = 'FILTER_MEDIA_TYPE_IMAGE_MOVING_PHOTO';
27
28export class RecentPhotoComponent extends ViewPU {
29    constructor(j3, k3, l3, m3 = -1, n3 = undefined, o3) {
30        super(j3, l3, m3, o3);
31        if (typeof n3 === 'function') {
32            this.paramsGenerator_ = n3;
33        }
34        this.recentPhotoOptions = undefined;
35        this.onRecentPhotoCheckResult = undefined;
36        this.onRecentPhotoClick = undefined;
37        this.onRecentPhotoCheckInfo = undefined;
38        this.setInitiallyProvidedValue(k3);
39        this.finalizeConstruction();
40    }
41    setInitiallyProvidedValue(i3) {
42        if (i3.recentPhotoOptions !== undefined) {
43            this.recentPhotoOptions = i3.recentPhotoOptions;
44        }
45        if (i3.onRecentPhotoCheckResult !== undefined) {
46            this.onRecentPhotoCheckResult = i3.onRecentPhotoCheckResult;
47        }
48        if (i3.onRecentPhotoClick !== undefined) {
49            this.onRecentPhotoClick = i3.onRecentPhotoClick;
50        }
51        if (i3.onRecentPhotoCheckInfo !== undefined) {
52            this.onRecentPhotoCheckInfo = i3.onRecentPhotoCheckInfo;
53        }
54    }
55    updateStateVars(h3) {
56    }
57    purgeVariableDependenciesOnElmtId(g3) {
58    }
59    aboutToBeDeleted() {
60        SubscriberManager.Get().delete(this.id__());
61        this.aboutToBeDeletedInternal();
62    }
63    initialRender() {
64        this.observeComponentCreation2((e3, f3) => {
65            Row.create();
66            Row.height('100%');
67        }, Row);
68        this.observeComponentCreation2((c3, d3) => {
69            Column.create();
70            Column.width('100%');
71        }, Column);
72        this.observeComponentCreation2((v2, w2) => {
73            SecurityUIExtensionComponent.create({
74                bundleName: 'com.ohos.photos',
75                abilityName: 'RecentUIExtensionAbility',
76                parameters: {
77                    'ability.want.params.uiExtensionType': 'recentPhoto',
78                    filterMediaType: this.convertMIMETypeToFilterType(this.recentPhotoOptions?.MIMEType),
79                    period: this.recentPhotoOptions?.period,
80                    photoSource: this.recentPhotoOptions?.photoSource,
81                    isAutoRefreshSupported: this.recentPhotoOptions?.isAutoRefreshSupported,
82                    colorMode: this.recentPhotoOptions?.colorMode,
83                    isFromPickerView: true,
84                    isRecentPhotoCheckResultSet: this.onRecentPhotoCheckResult ? true : false
85                }
86            });
87            SecurityUIExtensionComponent.height('100%');
88            SecurityUIExtensionComponent.width('100%');
89            SecurityUIExtensionComponent.onRemoteReady(() => {
90                console.info('RecentPhotoComponent onRemoteReady');
91            });
92            SecurityUIExtensionComponent.onReceive((a3) => {
93                let b3 = a3;
94                this.handleOnReceive(b3);
95            });
96            SecurityUIExtensionComponent.onError(() => {
97                console.info('RecentPhotoComponent onError');
98            });
99        }, SecurityUIExtensionComponent);
100        Column.pop();
101        Row.pop();
102    }
103    handleOnReceive(p2) {
104        console.info('RecentPhotoComponent OnReceive:' + this.encrypt(JSON.stringify(p2)));
105        let q2 = p2.dataType;
106        if (q2 === 'checkResult') {
107            if (this.onRecentPhotoCheckResult) {
108                this.onRecentPhotoCheckResult(p2.isExist);
109            }
110        }
111        else if (q2 === 'select') {
112            if (this.onRecentPhotoClick) {
113                let r2 = new BaseItemInfo();
114                r2.uri = p2.uri;
115                r2.mimeType = p2.mimeType;
116                r2.width = p2.width;
117                r2.height = p2.height;
118                r2.size = p2.size;
119                r2.duration = p2.duration;
120                this.onRecentPhotoClick(r2);
121            }
122            else {
123                console.warn('RecentPhotoComponent onReceive data type is invalid.');
124            }
125        }
126        else if (q2 === 'checkInfo') {
127            if (this.onRecentPhotoCheckInfo) {
128                let s2 = new RecentPhotoInfo();
129                s2.identifier = p2.identifier;
130                s2.dateTaken = p2.dateTaken;
131                this.onRecentPhotoCheckInfo(p2.isExist, s2);
132            }
133        }
134    }
135    convertMIMETypeToFilterType(e) {
136        let o;
137        if (e === photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE) {
138            o = FILTER_MEDIA_TYPE_IMAGE;
139        } else if (e === photoAccessHelper.PhotoViewMIMETypes.VIDEO_TYPE) {
140            o = FILTER_MEDIA_TYPE_VIDEO;
141        } else if (e === photoAccessHelper.PhotoViewMIMETypes.MOVING_PHOTO_IMAGE_TYPE) {
142            o = FILTER_MEDIA_TYPE_IMAGE_MOVING_PHOTO;
143        } else {
144            o = FILTER_MEDIA_TYPE_ALL;
145        }
146        console.info('RecentPhotoComponent convertMIMETypeToFilterType: ' + JSON.stringify(o));
147        return o;
148    }
149    rerender() {
150        this.updateDirtyElements();
151    }
152    encrypt(data) {
153        if (!data || data?.indexOf('file:///data/storage/') !== -1) {
154          return '';
155        }
156        return data.replace(/(\/\w+)\./g, '/******.');
157    }
158}
159
160export class RecentPhotoOptions {
161}
162
163export class RecentPhotoInfo {
164}
165
166export var PhotoSource;
167(function (m2) {
168    m2[m2.ALL = 0] = 'ALL';
169    m2[m2.CAMERA = 1] = 'CAMERA';
170    m2[m2.SCREENSHOT = 2] = 'SCREENSHOT';
171})(PhotoSource || (PhotoSource = {}));
172
173export default { RecentPhotoComponent, RecentPhotoOptions, PhotoSource, RecentPhotoInfo };
174