• 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                    isFromPickerView: true,
82                    isRecentPhotoCheckResultSet: this.onRecentPhotoCheckResult ? true : false
83                }
84            });
85            SecurityUIExtensionComponent.height('100%');
86            SecurityUIExtensionComponent.width('100%');
87            SecurityUIExtensionComponent.onRemoteReady(() => {
88                console.info('RecentPhotoComponent onRemoteReady');
89            });
90            SecurityUIExtensionComponent.onReceive((a3) => {
91                let b3 = a3;
92                this.handleOnReceive(b3);
93            });
94            SecurityUIExtensionComponent.onError(() => {
95                console.info('RecentPhotoComponent onError');
96            });
97        }, SecurityUIExtensionComponent);
98        Column.pop();
99        Row.pop();
100    }
101    handleOnReceive(p2) {
102        console.info('RecentPhotoComponent OnReceive:' + this.encrypt(JSON.stringify(p2)));
103        let q2 = p2.dataType;
104        if (q2 === 'checkResult') {
105            if (this.onRecentPhotoCheckResult) {
106                this.onRecentPhotoCheckResult(p2.isExist);
107            }
108        }
109        else if (q2 === 'select') {
110            if (this.onRecentPhotoClick) {
111                let r2 = new BaseItemInfo();
112                r2.uri = p2.uri;
113                r2.mimeType = p2.mimeType;
114                r2.width = p2.width;
115                r2.height = p2.height;
116                r2.size = p2.size;
117                r2.duration = p2.duration;
118                this.onRecentPhotoClick(r2);
119            }
120            else {
121                console.warn('RecentPhotoComponent onReceive data type is invalid.');
122            }
123        }
124        else if (q2 === 'checkInfo') {
125            if (this.onRecentPhotoCheckInfo) {
126                let s2 = new RecentPhotoInfo();
127                s2.identifier = p2.identifier;
128                s2.dateTaken = p2.dateTaken;
129                this.onRecentPhotoCheckInfo(p2.isExist, s2);
130            }
131        }
132    }
133    convertMIMETypeToFilterType(n2) {
134        let o2;
135        if (n2 === photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE) {
136            o2 = FILTER_MEDIA_TYPE_IMAGE;
137        }
138        else if (n2 === photoAccessHelper.PhotoViewMIMETypes.VIDEO_TYPE) {
139            o2 = FILTER_MEDIA_TYPE_VIDEO;
140        }
141        else if (n2 === photoAccessHelper.PhotoViewMIMETypes.MOVING_PHOTO_IMAGE_TYPE) {
142            o2 = FILTER_MEDIA_TYPE_IMAGE_MOVING_PHOTO;
143        }
144        else {
145            o2 = FILTER_MEDIA_TYPE_ALL;
146        }
147        console.info('RecentPhotoComponent convertMIMETypeToFilterType : ' + JSON.stringify(o2));
148        return o2;
149    }
150    rerender() {
151        this.updateDirtyElements();
152    }
153    encrypt(data) {
154        if (!data || data?.indexOf('file:///data/storage/') !== -1) {
155          return '';
156        }
157        return data.replace(/(\/\w+)\./g, '/******.');
158    }
159}
160
161export class RecentPhotoOptions {
162}
163
164export class RecentPhotoInfo {
165}
166
167export var PhotoSource;
168(function (m2) {
169    m2[m2.ALL = 0] = 'ALL';
170    m2[m2.CAMERA = 1] = 'CAMERA';
171    m2[m2.SCREENSHOT = 2] = 'SCREENSHOT';
172})(PhotoSource || (PhotoSource = {}));
173
174export default { RecentPhotoComponent, RecentPhotoOptions, PhotoSource, RecentPhotoInfo };
175