!191 通知管理开关和状态显示异常

Merge pull request !191 from lijinfengde123/master
This commit is contained in:
openharmony_ci 2022-07-16 02:54:52 +00:00 committed by Gitee
commit 8ae07bd200
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
7 changed files with 112 additions and 70 deletions

22
.gitignore vendored
View File

@ -4,12 +4,16 @@ build
node_modules/
local.properties
signature/systemui_provision_verified.json
product/default/volumepanel/node_modules
product/default/notificationmanagement/node_modules
product/default/navigationBar/node_modules
product/pc/controlpanel/node_modules
product/pc/notificationpanel/node_modules
product/pc/statusbar/node_modules
product/phone/dropdownpanel/node_modules
product/phone/statusbar/node_modules
*/.preview/*
/product/default/volumepanel/node_modules
/product/default/notificationmanagement/node_modules
/product/default/navigationBar/node_modules
/product/pc/controlpanel/node_modules
/product/pc/notificationpanel/node_modules
/product/pc/statusbar/node_modules
/product/phone/dropdownpanel/node_modules
/product/phone/statusbar/node_modules
/product/default/volumepanel/.preview/
/product/pc/notificationpanel/.preview/
/product/phone/statusbar/.preview/
/product/default/notificationmanagement/.preview/
/.hvigor/outputs/logs/details/details.json

View File

@ -19,7 +19,6 @@ import { NotificationSlot } from 'notification/notificationSlot';
const TAG = 'NotificationManagenment-NotificationListener';
interface EnableListener {
bundle: string;
onEnableChanged: {(value: boolean): void};
@ -31,7 +30,7 @@ export interface BundleOption {
}
export class NotificationListener {
private readonly listeners= new Set<EnableListener>();
private readonly listeners = new Set<EnableListener>();
subscribeEnableChanged(): void {
Log.showInfo(TAG, 'subscribeEnableChanged');
@ -78,12 +77,15 @@ export class NotificationListener {
Log.showInfo(TAG, 'unRegisterAll finished');
}
async isNotificationEnabled(bundleOption: BundleOption): Promise<boolean> {
async isNotificationEnabled(bundleOption: BundleOption, callback?: (data) => void): Promise<boolean> {
Log.showDebug(TAG, `isNotificationEnabled bundleOption:${JSON.stringify(bundleOption)} `);
return new Promise((resolve, reject) => {
Notification.isNotificationEnabled(bundleOption, (err, data) => {
Log.showInfo(TAG, `isNotificationEnabled callback data:${JSON.stringify(data)} err:${JSON.stringify(err)}`);
if (!!data) {
if (callback) {
callback(data);
}
resolve(data);
} else {
reject(err);
@ -100,6 +102,31 @@ export class NotificationListener {
});
}
async isNotificationSlotEnabled(bundleOption: BundleOption, slotType: Notification.SlotType, callback?: (data) => void): Promise<boolean> {
Log.showDebug(TAG, `isNotificationSlotEnabled bundleOption:${JSON.stringify(bundleOption)} `);
return new Promise((resolve, reject) => {
Notification.isNotificationSlotEnabled(bundleOption, slotType, (err, data) => {
Log.showInfo(TAG, `isNotificationSlotEnabled callback data:${JSON.stringify(data)} err:${JSON.stringify(err)}`);
if (!!data) {
if (callback) {
callback(data);
}
resolve(data);
} else {
reject(err);
}
});
});
}
enableNotificationSlot(bundleOption: BundleOption, slotType: Notification.SlotType, data: boolean): void {
Log.showDebug(TAG, `enableNotificationSlot bundleOption:${JSON.stringify(bundleOption)} data:${JSON.stringify(data)}`);
let enableValue: boolean = data ? true : false;
Notification.enableNotificationSlot(bundleOption, slotType, enableValue, (err, result) => {
Log.showInfo(TAG, `enableNotificationSlot err:${JSON.stringify(err)} result:${JSON.stringify(result)}`);
});
}
notificationSlotSet(bundleOption: BundleOption, data: NotificationSlot): void {
Log.showDebug(TAG, `notificationSlotSet bundleOption:${JSON.stringify(bundleOption)} data:${JSON.stringify(data)}`);
Notification.setSlotByBundle(bundleOption, data, (err, result) => {
@ -131,5 +158,4 @@ export class NotificationListener {
let notificationListener = new NotificationListener();
export default notificationListener ;
export default notificationListener ;

View File

@ -14,7 +14,7 @@
*/
import ConfigData from '../../common/constants';
import Log from '../../../../../../../../../common/src/main/ets/default/Log';
import Notification from '../../model/notificationListener';
import NotificationListener from '../../model/notificationListener';
import Router from '@system.router'
const TAG = 'ManagementComponent-AppItemComponent';
@ -210,7 +210,7 @@ export default struct AppItemComponent {
.height($r('app.float.toggle_comp_height'))
.onChange((flag) => {
Log.showInfo(TAG, `Toggle onChange param: data:${flag} `);
Notification.enableNotification({ bundle: this.appBundleName, uid: this.appUid }, flag);
NotificationListener.enableNotification({ bundle: this.appBundleName, uid: this.appUid }, flag);
})
}
}
@ -225,20 +225,20 @@ export default struct AppItemComponent {
aboutToAppear(): void{
Log.showInfo(TAG, `aboutToAppear`);
if (this.appSwitch === 1) {
Notification.subscribeEnableChanged();
Notification.register({ bundle: this.appBundleName,
NotificationListener.subscribeEnableChanged();
NotificationListener.register({ bundle: this.appBundleName,
onEnableChanged: (stateValue: boolean) => {
Log.showDebug(TAG, `aboutToAppear listener call`);
this.canNotice = stateValue;
} });
Notification.isNotificationEnabled({ bundle: this.appBundleName, uid: this.appUid })
NotificationListener.isNotificationEnabled({ bundle: this.appBundleName, uid: this.appUid })
.then((stateValue) => {
Log.showInfo(TAG, `Notification.isNotificationEnabled data:${JSON.stringify(stateValue)}`);
Log.showInfo(TAG, `NotificationListener.isNotificationEnabled data:${JSON.stringify(stateValue)}`);
this.canNotice = stateValue;
})
.catch((error) => {
Log.showError(TAG, `Notification.isNotificationEnabled error:${JSON.stringify(error)}`);
Log.showError(TAG, `NotificationListener.isNotificationEnabled error:${JSON.stringify(error)}`);
});
}
}
@ -246,7 +246,7 @@ export default struct AppItemComponent {
aboutToDisappear(): void{
Log.showInfo(TAG, `aboutToDisappear`);
if (this.appSwitch === 1) {
Notification.unsubscribeEnableChanged();
NotificationListener.unsubscribeEnableChanged();
}
}

View File

@ -20,11 +20,10 @@ import Router from '@system.router'
const TAG = 'ManagementComponent-SlotLstComponent';
@Component
export default struct SlotLstComponent {
private appInfo: any= null;
@State slotLst: any[] = [];
@Link slotLst: any[];
build() {
Flex({ justifyContent: FlexAlign.SpaceBetween }) {
@ -75,13 +74,6 @@ export default struct SlotLstComponent {
aboutToAppear(): void{
Log.showInfo(TAG, `aboutToAppear Notification.getSlotsByBundle bundle:` + 'bundle:' + this.appInfo.appBundleName + 'uid' + this.appInfo.appUid);
Notification.getSlotsByBundle({ bundle: this.appInfo.appBundleName, uid: this.appInfo.appUid }, (err, data) => {
Log.showInfo(TAG, `aboutToAppear Notification.getSlotsByBundle data:` + JSON.stringify(data));
data.forEach((val, idx, array) => {
Log.showInfo(TAG, `aboutToAppear Notification.getSlotsByBundle data.forEach:` + JSON.stringify(val));
this.slotLst.push(val);
})
})
}
onBackPress() {

View File

@ -74,13 +74,6 @@ export default struct SwitchComponent {
aboutToAppear(): void{
Log.showInfo(TAG, `aboutToAppear`);
if (this.register) {
Log.showInfo(TAG, `aboutToAppear register listener`);
this.register((stateValue: boolean) => {
Log.showInfo(TAG, `aboutToAppear listener call`);
this.initState = stateValue;
});
}
this.initializationAction().then((data) => {
Log.showInfo(TAG, `initializationAction:${data}`);
this.initState = data;

View File

@ -21,7 +21,8 @@ import SwitchComponent from '../../../../../../../features/managementcomponent/s
import SlotLstComponent from '../../../../../../../features/managementcomponent/src/main/ets/com/ohos/view/component/slotlstcomponent';
import ConfigData from '../common/constants';
import Router from '@system.router'
import Notification from '../../../../../../../features/managementcomponent/src/main/ets/com/ohos/model/notificationlistener';
import notificationListener from '../../../../../../../features/managementcomponent/src/main/ets/com/ohos/model/notificationlistener';
import Notification from '@ohos.notification';
const TAG = 'NotificationManagement-SetEnable';
@ -30,9 +31,11 @@ let appInfo;
@Entry
@Component
export default struct SetEnable {
private listeners: any[] = []
@State headName:Resource = $r('app.string.notificationManagement')
@State allowNotice:Resource = $r('app.string.allowNotification')
private listeners: any[] = [];
@State headName:Resource = $r('app.string.notificationManagement');
@State allowNotice:Resource = $r('app.string.allowNotification');
@State slotLst: any[] = [];
@State initState: boolean = false;
build() {
Flex({ justifyContent: FlexAlign.SpaceBetween }) {
Column() {
@ -63,7 +66,7 @@ export default struct SetEnable {
title: $allowNotice,
initializationAction: () => this.switchComponentInit(),
settingAction: (params) => this.switchComponentSet(params),
register: (listener) => Notification.register({bundle:appInfo.appBundleName,onEnableChanged:listener})
register: (listener) => notificationListener.register({bundle:appInfo.appBundleName,onEnableChanged:listener})
})
}
.margin({ top: $r('app.float.page_notice_title_margin_t')})
@ -71,9 +74,10 @@ export default struct SetEnable {
.height($r('app.float.notice_row_height'))
Row() {
SlotLstComponent({ appInfo: appInfo })
SlotLstComponent({ appInfo: appInfo ,slotLst: $slotLst})
}
.align(Alignment.Start)
.visibility(this.initState ? Visibility.Visible : Visibility.Hidden);
}
.width(ConfigData.WH_100_100)
.height(ConfigData.WH_100_100)
@ -97,13 +101,24 @@ export default struct SetEnable {
Log.showInfo(TAG, `aboutToAppear`)
appInfo = Router.getParams();
appInfo.slotSettingUrl = 'pages/slotSetting'
Notification.subscribeEnableChanged();
Log.showInfo(TAG, `aboutToAppear end`)
notificationListener.subscribeEnableChanged();
Log.showInfo(TAG, `aboutToAppear end`);
}
onPageShow (): void{
Log.showInfo(TAG, `onPageShow`);
Notification.getSlotsByBundle({ bundle: appInfo.appBundleName, uid: appInfo.appUid }, (err, data) => {
this.slotLst = [];
data.forEach((val, idx, array) => {
this.slotLst.push(val);
})
})
}
aboutToDisappear(): void{
Log.showInfo(TAG, `aboutToDisappear`)
Notification.unsubscribeEnableChanged();
this.slotLst = [];
notificationListener.unsubscribeEnableChanged();
}
onBackPress() {
@ -112,11 +127,15 @@ export default struct SetEnable {
switchComponentInit() {
Log.showDebug(TAG, `switchComponentInit`)
return Notification.isNotificationEnabled({ bundle: appInfo.appBundleName, uid: appInfo.appUid })
return notificationListener.isNotificationEnabled({ bundle: appInfo.appBundleName, uid: appInfo.appUid }, (data) => {
Log.showDebug(TAG, 'switchComponentInit callback' + data);
this.initState = data;
});
}
switchComponentSet(params) {
Log.showDebug(TAG, `switchComponentSet`)
Notification.enableNotification({ bundle: appInfo.appBundleName, uid: appInfo.appUid }, params);
this.initState = params;
notificationListener.enableNotification({ bundle: appInfo.appBundleName, uid: appInfo.appUid }, params);
}
}
}

View File

@ -13,20 +13,20 @@
* limitations under the License.
*/
import Log from '../../../../../../../common/src/main/ets/default/Log';
import Log from '../../../../../../../common/src/main/ets/default/log';
import HeadComponent from '../../../../../../../features/managementcomponent/src/main/ets/com/ohos/view/component/headcomponent';
import AppItemComponent from '../../../../../../../features/managementcomponent/src/main/ets/com/ohos/view/component/appitemcomponent';
import SwitchComponent from '../../../../../../../features/managementcomponent/src/main/ets/com/ohos/view/component/switchcomponent';
import ConfigData from '../common/constants';
import NotificationConfigData from '../../../../../../../features/managementcomponent/src/main/ets/com/ohos/common/constants';
import Router from '@system.router'
import Notification from '../../../../../../../features/managementcomponent/src/main/ets/com/ohos/model/notificationlistener';
import NotificationListener from '../../../../../../../features/managementcomponent/src/main/ets/com/ohos/model/notificationlistener';
import notification from '@ohos.notification';
const TAG = 'NotificationManagement-SlotSetting';
const DEFAULT_SOUND = 'file://system/etc/Light.ogg';
let params;
let slotParams;
@Entry
@Component
@ -37,6 +37,7 @@ export default struct SlotSetting {
@State allowNotice: Resource = $r('app.string.allowNotification')
@State noticeStyleBanner: Resource = $r('app.string.notificationStyle_banner')
@State noticeSound: Resource = $r('app.string.notificationSound')
@State initState: boolean = false;
build() {
Flex({ justifyContent: FlexAlign.SpaceBetween }) {
@ -73,12 +74,8 @@ export default struct SlotSetting {
Row() {
SwitchComponent({
title: $allowNotice,
initializationAction: () => this.notificationEnableInit(),
settingAction: (params) => this.notificationEnableSet(params),
register: (listener) => Notification.register({
bundle: this.appInfo.appBundleName,
onEnableChanged: listener
})
initializationAction: () => this.notificationSlotEnableInit(),
settingAction: (params) => this.notificationSlotEnableSet(params)
})
}
.margin({ top: $r('app.float.page_notice_title_margin_t') })
@ -102,7 +99,8 @@ export default struct SlotSetting {
right: $r('sys.float.ohos_id_max_padding_end')
})
.margin({ top: $r('app.float.page_notice_part_margin_t')})
.align(Alignment.Start);
.align(Alignment.Start)
.visibility(this.initState ? Visibility.Visible : Visibility.Hidden);
Row() {
SwitchComponent({
@ -117,6 +115,7 @@ export default struct SlotSetting {
})
.margin({ top: $r('app.float.page_notice_title_margin_t')})
.height($r('app.float.notice_row_height'))
.visibility(this.initState ? Visibility.Visible : Visibility.Hidden);
Row() {
SwitchComponent({
@ -131,6 +130,7 @@ export default struct SlotSetting {
})
.margin({ top: $r('app.float.page_notice_row_margin_t') })
.height($r('app.float.notice_row_height'))
.visibility(this.initState ? Visibility.Visible : Visibility.Hidden);
}
.width(ConfigData.WH_100_100)
.height(ConfigData.WH_100_100)
@ -151,24 +151,32 @@ export default struct SlotSetting {
}
aboutToAppear(): void{
Log.showInfo(TAG, `aboutToAppear`)
params = Router.getParams();
this.appInfo = params.appInfo;
this.slotInfo = params.slotInfo
slotParams = Router.getParams();
this.appInfo = slotParams.appInfo;
this.slotInfo = slotParams.slotInfo
Log.showDebug(TAG, `aboutToAppear ${JSON.stringify(this.slotInfo)}`)
}
onBackPress() {
Log.showInfo(TAG, `onBackPress`)
}
notificationEnableInit() {
Log.showDebug(TAG, `notificationEnableInit`)
return Notification.isNotificationEnabled({ bundle: this.appInfo.appBundleName, uid: this.appInfo.appUid })
notificationSlotEnableInit() {
Log.showDebug(TAG, `notificationSlotEnableInit`)
return NotificationListener.isNotificationSlotEnabled({
bundle: this.appInfo.appBundleName,
uid: this.appInfo.appUid
}, this.slotInfo.type,
(data) => {
Log.showInfo(TAG, 'notificationSlotEnableInit callback' + data);
this.initState = data;
});
}
notificationEnableSet(data) {
notificationSlotEnableSet(data) {
Log.showDebug(TAG, `notificationEnableSet data:${JSON.stringify(data)}`)
Notification.enableNotification({ bundle: this.appInfo.appBundleName, uid: this.appInfo.appUid }, data);
this.initState = data;
NotificationListener.enableNotificationSlot({ bundle: this.appInfo.appBundleName, uid: this.appInfo.appUid }, this.slotInfo.type, data);
}
soundEnableInit() {
@ -225,6 +233,6 @@ export default struct SlotSetting {
notificationSlotSet() {
Log.showDebug(TAG, `notificationSlotSet slotInfo:${JSON.stringify(this.slotInfo)}`)
Notification.notificationSlotSet({ bundle: this.appInfo.appBundleName, uid: this.appInfo.appUid }, this.slotInfo);
NotificationListener.notificationSlotSet({ bundle: this.appInfo.appBundleName, uid: this.appInfo.appUid }, this.slotInfo);
}
}