Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Revert "Bug 1065519 - Ambient indicator based on list of notifications"
Browse files Browse the repository at this point in the history
This reverts commit b7b59f0.
  • Loading branch information
rvandermeulen committed Sep 30, 2014
1 parent 718427f commit a00d102
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 62 deletions.
4 changes: 2 additions & 2 deletions apps/system/js/app_install_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ var AppInstallManager = {
}

appInfo.installNotification = newNode;
NotificationScreen.addUnreadNotification(manifestURL);
NotificationScreen.incExternalNotifications();
},

getNotificationProgressNode: function ai_getNotificationProgressNode(app) {
Expand Down Expand Up @@ -576,7 +576,7 @@ var AppInstallManager = {

node.parentNode.removeChild(node);
delete appInfo.installNotification;
NotificationScreen.removeUnreadNotification(manifestURL);
NotificationScreen.decExternalNotifications();
},

requestWifiLock: function ai_requestWifiLock(app) {
Expand Down
40 changes: 26 additions & 14 deletions apps/system/js/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ var NotificationScreen = {
// will hold the count of external contributors to the notification
// screen
this.externalNotificationsCount = 0;
this.unreadNotifications = [];
this.unreadNotifications = 0;

window.addEventListener('utilitytrayshow', this);
// Since UI expect there is a slight delay for the opened notification.
Expand Down Expand Up @@ -401,9 +401,10 @@ var NotificationScreen = {
this.container.querySelector('.priority-notifications') :
this.container.querySelector('.other-notifications');


// We need to animate the ambient indicator when the toast
// timesout, so we skip updating it here, by passing a skip bool
this.addUnreadNotification(detail.id, true);
this.addUnreadNotification(true);

var notificationNode = document.createElement('div');
notificationNode.classList.add('notification');
Expand Down Expand Up @@ -650,34 +651,32 @@ var NotificationScreen = {
notification.style.transform = '';
},

addUnreadNotification: function ns_addUnreadNotification(id, skipUpdate) {
addUnreadNotification: function ns_addUnreadNotification(skipUpdate) {
if (UtilityTray.shown) {
return;
}
this.unreadNotifications.push(id);

this.unreadNotifications++;
if (!skipUpdate) {
this.updateNotificationIndicator();
}
},

removeUnreadNotification: function ns_removeUnreadNotification(id) {
var notifIndex = this.unreadNotifications.indexOf(id);
if (notifIndex > -1) {
this.unreadNotifications.splice(notifIndex, 1);
}
removeUnreadNotification: function ns_removeUnreadNotification() {
this.unreadNotifications--;
var isNegative = this.unreadNotifications < 0;
this.unreadNotifications = isNegative ? 0 : this.unreadNotifications;
this.updateNotificationIndicator();
},

hideNotificationIndicator: function ns_hideNotificationIndicator() {
if (this.unreadNotifications.length > 0) {
this.unreadNotifications = [];
}
this.unreadNotifications = 0;
this.updateNotificationIndicator();
},

updateNotificationIndicator: function ns_updateNotificationIndicator() {
if (this.unreadNotifications.length) {
var indicatorSize = getIndicatorSize(this.unreadNotifications.length);
if (this.unreadNotifications) {
var indicatorSize = getIndicatorSize(this.unreadNotifications);
this.ambientIndicator.className = 'unread ' + indicatorSize;
this.ambientIndicator.setAttribute('aria-label', navigator.mozL10n.get(
'statusbarNotifications-unread', {n: this.unreadNotifications}));
Expand Down Expand Up @@ -770,6 +769,19 @@ var NotificationScreen = {
// check if lockscreen notifications visual
// hints (masks & arrow) need to show
window.lockScreenNotifications.adjustContainerVisualHints();
},

incExternalNotifications: function ns_incExternalNotifications() {
this.externalNotificationsCount++;
this.addUnreadNotification();
},

decExternalNotifications: function ns_decExternalNotifications() {
this.externalNotificationsCount--;
if (this.externalNotificationsCount < 0) {
this.externalNotificationsCount = 0;
}
this.removeUnreadNotification();
}

};
Expand Down
6 changes: 2 additions & 4 deletions apps/system/js/storage_watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

var DeviceStorageWatcher = {

LOW_DISK_NOTIF_ID: 'low-disk-space',

init: function dsw_init() {
this._lowDeviceStorage = false;

Expand Down Expand Up @@ -50,15 +48,15 @@ var DeviceStorageWatcher = {
this._lowDeviceStorage = false;
if (this._container.classList.contains('displayed')) {
this._container.classList.remove('displayed');
NotificationScreen.removeUnreadNotification(this.LOW_DISK_NOTIF_ID);
NotificationScreen.decExternalNotifications();
}
},

displayNotification: function dsw_displayNotification() {
this._lowDeviceStorage = true;
if (!this._container.classList.contains('displayed')) {
this._container.classList.add('displayed');
NotificationScreen.addUnreadNotification(this.LOW_DISK_NOTIF_ID);
NotificationScreen.incExternalNotifications();
}
},

Expand Down
5 changes: 2 additions & 3 deletions apps/system/js/update_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ var UpdateManager = {
_dataConnectionWarningEnabled: true,
_startedDownloadUsingDataConnection: false,
_settings: null,
UPDATE_NOTIF_ID: 'update-notification',
NOTIFICATION_BUFFERING_TIMEOUT: 30 * 1000,
TOASTER_TIMEOUT: 1200,
UPDATE_2G_SETT: 'update.2g.enabled',
Expand Down Expand Up @@ -559,14 +558,14 @@ var UpdateManager = {
hideNotificationIfDisplayed: function() {
if (this.container.classList.contains('displayed')) {
this.container.classList.remove('displayed');
NotificationScreen.removeUnreadNotification(this.UPDATE_NOTIF_ID);
NotificationScreen.decExternalNotifications();
}
},

displayNotificationIfHidden: function() {
if (!this.container.classList.contains('displayed')) {
this.container.classList.add('displayed');
NotificationScreen.addUnreadNotification(this.UPDATE_NOTIF_ID);
NotificationScreen.incExternalNotifications();
}
},

Expand Down
24 changes: 12 additions & 12 deletions apps/system/test/unit/app_install_manager_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ suite('system/AppInstallManager >', function() {
});

test('should not remove a notification', function() {
var method = 'removeUnreadNotification';
var method = 'decExternalNotifications';
assert.isUndefined(MockNotificationScreen.wasMethodCalled[method]);
});

Expand All @@ -699,7 +699,7 @@ suite('system/AppInstallManager >', function() {
});

test('should not remove a notification', function() {
var method = 'removeUnreadNotification';
var method = 'decExternalNotifications';
assert.isUndefined(MockNotificationScreen.wasMethodCalled[method]);
});

Expand Down Expand Up @@ -816,7 +816,7 @@ suite('system/AppInstallManager >', function() {
});

test('should add a notification', function() {
var method = 'addUnreadNotification';
var method = 'incExternalNotifications';
assert.equal(fakeNotif.childElementCount, 1);
assert.ok(MockNotificationScreen.wasMethodCalled[method]);
});
Expand Down Expand Up @@ -844,7 +844,7 @@ suite('system/AppInstallManager >', function() {
});

test('should remove the notif', function() {
var method = 'removeUnreadNotification';
var method = 'decExternalNotifications';
assert.equal(fakeNotif.childElementCount, 0);
assert.ok(MockNotificationScreen.wasMethodCalled[method]);
});
Expand Down Expand Up @@ -904,7 +904,7 @@ suite('system/AppInstallManager >', function() {
});

test('should remove the notif', function() {
var method = 'removeUnreadNotification';
var method = 'decExternalNotifications';
assert.equal(fakeNotif.childElementCount, 0);
assert.ok(MockNotificationScreen.wasMethodCalled[method]);
});
Expand Down Expand Up @@ -961,7 +961,7 @@ suite('system/AppInstallManager >', function() {
});

test('should add a notification', function() {
var method = 'addUnreadNotification';
var method = 'incExternalNotifications';
assert.equal(fakeNotif.childElementCount, 1);
assert.ok(MockNotificationScreen.wasMethodCalled[method]);
});
Expand Down Expand Up @@ -1027,7 +1027,7 @@ suite('system/AppInstallManager >', function() {
});

test('should add a notification', function() {
var method = 'addUnreadNotification';
var method = 'incExternalNotifications';
assert.equal(fakeNotif.childElementCount, 1);
assert.ok(MockNotificationScreen.wasMethodCalled[method]);
});
Expand Down Expand Up @@ -1063,7 +1063,7 @@ suite('system/AppInstallManager >', function() {
});

test('should remove the notif', function() {
var method = 'removeUnreadNotification';
var method = 'decExternalNotifications';
assert.equal(fakeNotif.childElementCount, 0);
assert.ok(MockNotificationScreen.wasMethodCalled[method]);
});
Expand Down Expand Up @@ -1122,7 +1122,7 @@ suite('system/AppInstallManager >', function() {
});

test('should remove the notif', function() {
var method = 'removeUnreadNotification';
var method = 'decExternalNotifications';
assert.equal(fakeNotif.childElementCount, 0);
assert.ok(MockNotificationScreen.wasMethodCalled[method]);
});
Expand Down Expand Up @@ -1188,7 +1188,7 @@ suite('system/AppInstallManager >', function() {
});

test('should add a notification', function() {
var method = 'addUnreadNotification';
var method = 'incExternalNotifications';
assert.equal(fakeNotif.childElementCount, 1);
assert.ok(MockNotificationScreen.wasMethodCalled[method]);
});
Expand Down Expand Up @@ -1284,15 +1284,15 @@ suite('system/AppInstallManager >', function() {
test('should add a notification for the pending app', function() {
mockApp.mTriggerDownloadProgress(50);

var method = 'addUnreadNotification';
var method = 'incExternalNotifications';
assert.equal(fakeNotif.childElementCount, 1);
assert.ok(MockNotificationScreen.wasMethodCalled[method]);
});

test('should not add a notification for the installed app', function() {
installedMockApp.mTriggerDownloadProgress(50);

var method = 'addUnreadNotification';
var method = 'incExternalNotifications';
assert.equal(fakeNotif.childElementCount, 0);
assert.isUndefined(MockNotificationScreen.wasMethodCalled[method]);
});
Expand Down
4 changes: 2 additions & 2 deletions apps/system/test/unit/mock_notification_screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ var MockNotificationScreen = {
wasMethodCalled: {},

mockMethods: [
'addUnreadNotification',
'removeUnreadNotification',
'incExternalNotifications',
'decExternalNotifications',
'updateNotificationIndicator',
'addNotification',
'removeNotification'
Expand Down
23 changes: 4 additions & 19 deletions apps/system/test/unit/notifications_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ suite('system/NotificationScreen >', function() {

function incrementNotications(number) {
for (var i = 0; i <= number - 1; i++) {
NotificationScreen.addUnreadNotification(i);
NotificationScreen.incExternalNotifications();
}
}

Expand Down Expand Up @@ -251,13 +251,13 @@ suite('system/NotificationScreen >', function() {

test('should clear unread notifications after open tray', function() {
incrementNotications(2);
assert.equal(NotificationScreen.unreadNotifications.length, 2);
assert.equal(NotificationScreen.unreadNotifications, 2);
assert.equal(NotificationScreen.ambientIndicator.getAttribute(
'aria-label'), localizeAmbientIndicatorLabel(2));
var event = new CustomEvent('utilitytrayshow');
window.dispatchEvent(event);
assert.equal(document.body.getElementsByClassName('unread').length, 0);
assert.equal(NotificationScreen.unreadNotifications.length, 0);
assert.equal(NotificationScreen.unreadNotifications, 0);
assert.isNull(NotificationScreen.ambientIndicator.getAttribute(
'aria-label'));
});
Expand Down Expand Up @@ -305,21 +305,6 @@ suite('system/NotificationScreen >', function() {
'aria-label'));
UtilityTray.shown = false;
});

test('should not clear the ambient after decrement unread', function() {
var imgpath = 'http://example.com/test.png';
var detail = {
id: 'my-id',
icon: imgpath,
title: 'title',
detail: 'detail'
};
NotificationScreen.addNotification(detail);
assert.equal(NotificationScreen.unreadNotifications.length, 1);
NotificationScreen.removeUnreadNotification('other-id');
assert.equal(NotificationScreen.unreadNotifications.length, 1);
});

});

suite('addUnreadNotification', function() {
Expand All @@ -337,7 +322,7 @@ suite('system/NotificationScreen >', function() {
});

test('shouldnt update the notif indicator when skipping', function() {
NotificationScreen.addUnreadNotification('other-id', true);
NotificationScreen.addUnreadNotification(true);
assert.isFalse(NotificationScreen.updateNotificationIndicator.called);
});
});
Expand Down
12 changes: 6 additions & 6 deletions apps/system/test/unit/update_manager_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ suite('system/UpdateManager', function() {
var css = UpdateManager.container.classList;
assert.isTrue(css.contains('displayed'));
assert.equal(
MockNotificationScreen.wasMethodCalled['addUnreadNotification'],
MockNotificationScreen.wasMethodCalled['incExternalNotifications'],
1);
});

Expand All @@ -614,7 +614,7 @@ suite('system/UpdateManager', function() {
assert.isTrue(css.contains('displayed'));
assert.equal(
MockNotificationScreen
.wasMethodCalled['addUnreadNotification'],
.wasMethodCalled['incExternalNotifications'],
1);
});
});
Expand All @@ -634,7 +634,7 @@ suite('system/UpdateManager', function() {
assert.isTrue(css.contains('displayed'));
assert.equal(
MockNotificationScreen
.wasMethodCalled['addUnreadNotification'],
.wasMethodCalled['incExternalNotifications'],
1);
});
});
Expand All @@ -653,7 +653,7 @@ suite('system/UpdateManager', function() {
assert.isTrue(css.contains('displayed'));
assert.equal(
MockNotificationScreen
.wasMethodCalled['addUnreadNotification'],
.wasMethodCalled['incExternalNotifications'],
1);
});

Expand Down Expand Up @@ -732,7 +732,7 @@ suite('system/UpdateManager', function() {

test('should add a new statusbar notification', function() {
this.sinon.clock.tick(TINY_TIMEOUT);
var method1 = 'addUnreadNotification';
var method1 = 'incExternalNotifications';
assert.ok(MockNotificationScreen.wasMethodCalled[method1]);
});
});
Expand All @@ -750,7 +750,7 @@ suite('system/UpdateManager', function() {
});

test('should decrease the external notifications count', function() {
var method1 = 'removeUnreadNotification';
var method1 = 'decExternalNotifications';
assert.ok(MockNotificationScreen.wasMethodCalled[method1]);
});
});
Expand Down

0 comments on commit a00d102

Please sign in to comment.