1/*
2 * Copyright (c) 2021-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 Notification from '@ohos.notification';
17import { AsyncCallback } from '@ohos.base';
18import { NotificationSubscriber } from 'notification/notificationSubscriber';
19import { NotificationRequest } from 'notification/notificationRequest';
20import Log from '../Log';
21
22const TAG = 'NotificationManager';
23
24
25export default class NotificationManager {
26  static readonly TYPE_BASIC: number = Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT;
27  static readonly TYPE_LONG: number = Notification.ContentType.NOTIFICATION_CONTENT_LONG_TEXT;
28  static readonly TYPE_MULTI: number = Notification.ContentType.NOTIFICATION_CONTENT_MULTILINE;
29
30  static subscribeNotification(tag: string, subscriber: NotificationSubscriber, asyncCallback: AsyncCallback<void>): void {
31    Log.showDebug(TAG, `subscribeNotification from: ${tag}`);
32    Notification.subscribe(subscriber, asyncCallback);
33  }
34
35  static unsubscribeNotification(tag: string, subscriber: NotificationSubscriber): void {
36    Log.showDebug(TAG, `subscribeNotification from: ${tag}`);
37    Notification.unsubscribe(subscriber).then(() => {
38    }).catch(err => {
39    });
40  }
41
42  static removeAll(tag: string, callback: AsyncCallback<void>): void {
43    Log.showDebug(TAG, `removeAll from: ${tag}`);
44    Notification.removeAll(callback);
45  }
46
47  static remove(tag: string, hashCode: string, callback: AsyncCallback<void>): void {
48    Log.showDebug(TAG, `remove from: ${tag}`);
49    Notification.remove(hashCode, callback);
50  }
51
52  static getAllActiveNotifications(tag: string, callback: AsyncCallback<NotificationRequest[]>): void {
53    Log.showDebug(TAG, `getAllActiveNotifications from: ${tag}`);
54    Notification.getAllActiveNotifications(callback);
55  }
56}