Skip to content

Commit

Permalink
Merge pull request #728 from csmith/master
Browse files Browse the repository at this point in the history
Add interface for UnreadStatusManager.
  • Loading branch information
csmith committed Dec 30, 2016
2 parents 35e370f + f5be0bf commit 8bf6dbe
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 3 deletions.
56 changes: 56 additions & 0 deletions api/src/main/java/com/dmdirc/ui/messages/UnreadStatusManager.java
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2006-2015 DMDirc Developers
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package com.dmdirc.ui.messages;

import com.dmdirc.util.colours.Colour;

import java.util.Optional;

/**
* Keeps track of the number of unread messages in a window, and the most important notification colour for those
* messages.
*/
public interface UnreadStatusManager {

/**
* Gets the total number of unread lines in the window.
*
* @return The number of unread lines
*/
int getUnreadLines();

/**
* Gets the most significant notification colour for the window, if any. More important events will override the
* colour of less important events (for example, the colour for a highlight event may replace the colour for
* an unread message event).
*
* @return The notification colour for the window. If empty, there is no active notification.
*/
Optional<Colour> getNotificationColour();

/**
* Clears the unread status of the window, marking everything as read.
*/
void clearStatus();

}
3 changes: 2 additions & 1 deletion src/main/java/com/dmdirc/FrameContainer.java
Expand Up @@ -39,6 +39,7 @@
import com.dmdirc.ui.messages.BackBufferFactory;
import com.dmdirc.ui.messages.BackBufferImpl;
import com.dmdirc.ui.messages.UnreadStatusManager;
import com.dmdirc.ui.messages.UnreadStatusManagerImpl;

import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -99,7 +100,7 @@ public FrameContainer(
this.backBufferFactory = backBufferFactory;

this.eventBus = eventBus;
this.unreadStatusManager = new UnreadStatusManager(this);
this.unreadStatusManager = new UnreadStatusManagerImpl(this);
this.eventBus.subscribe(unreadStatusManager);
configManager.getBinder().bind(unreadStatusManager, UnreadStatusManager.class);

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/dmdirc/interfaces/WindowModel.java
Expand Up @@ -134,5 +134,11 @@ public interface WindowModel {
*/
Optional<InputModel> getInputModel();

/**
* Returns the manager tracking this window's unread messages.
*
* @return The unread status manager for this window.
*/
UnreadStatusManager getUnreadStatusManager();

}
Expand Up @@ -41,7 +41,7 @@
/**
* Tracks unread messages and other notifications.
*/
public class UnreadStatusManager {
public class UnreadStatusManagerImpl implements UnreadStatusManager {

private final EventBus eventBus;
private final WindowModel container;
Expand All @@ -54,7 +54,7 @@ public class UnreadStatusManager {
private Optional<Colour> messageColour = Optional.of(Colour.BLUE);
private Optional<Colour> highlightColour = Optional.of(Colour.RED);

public UnreadStatusManager(final WindowModel container) {
public UnreadStatusManagerImpl(final WindowModel container) {
this.container = container;
this.eventBus = container.getEventBus();
this.colourManager = new ColourManager(container.getConfigManager());
Expand Down Expand Up @@ -100,14 +100,17 @@ private boolean includeEvent(final DisplayableEvent event) {
&& !event.getDisplayProperty(DisplayProperty.DO_NOT_DISPLAY).orElse(false);
}

@Override
public int getUnreadLines() {
return unreadLines;
}

@Override
public Optional<Colour> getNotificationColour() {
return notificationColour;
}

@Override
public void clearStatus() {
updateStatus(Optional.empty(), 0);
}
Expand Down

0 comments on commit 8bf6dbe

Please sign in to comment.