Search in sources :

Example 1 with ActivitiesListener

use of com.biglybt.activities.ActivitiesListener in project BiglyBT by BiglySoftware.

the class SBC_ActivityTableView method setupSidebarEntry.

public static void setupSidebarEntry(final MultipleDocumentInterface mdi) {
    // Put TitleInfo in another class
    final ViewTitleInfo titleInfoActivityView = new ViewTitleInfo() {

        boolean had_unviewed = false;

        @Override
        public Object getTitleInfoProperty(int propertyID) {
            if (propertyID == TITLE_INDICATOR_TEXT) {
                int num_unread = 0;
                int num_unviewed = 0;
                List<ActivitiesEntry> allEntries = ActivitiesManager.getAllEntries();
                for (ActivitiesEntry entry : allEntries) {
                    if (!entry.isRead()) {
                        num_unread++;
                    }
                    if (!entry.getViewed()) {
                        num_unviewed++;
                    }
                }
                if (num_unread == 0) {
                    num_unviewed = 0;
                }
                boolean has_unviewed = num_unviewed > 0;
                if (has_unviewed != had_unviewed) {
                    if (has_unviewed) {
                        MdiEntry parent = mdi.getEntry(MultipleDocumentInterface.SIDEBAR_HEADER_VUZE);
                        if (parent != null && !parent.isExpanded()) {
                            parent.setExpanded(true);
                        }
                    }
                    had_unviewed = has_unviewed;
                }
                if (num_unviewed > 0) {
                    return (String.valueOf(num_unviewed) + (num_unread == 0 ? "" : (":" + num_unread)));
                } else if (num_unread > 0) {
                    return (String.valueOf(num_unread));
                }
                return null;
            } else if (propertyID == TITLE_IMAGEID) {
                return "image.sidebar.activity";
            } else if (propertyID == TITLE_INDICATOR_COLOR) {
                boolean has_unread = false;
                boolean has_unviewed = false;
                List<ActivitiesEntry> allEntries = ActivitiesManager.getAllEntries();
                for (ActivitiesEntry entry : allEntries) {
                    if (!entry.isRead()) {
                        has_unread = true;
                    }
                    if (!entry.getViewed()) {
                        has_unviewed = true;
                    }
                }
                if (has_unread && has_unviewed) {
                    return (COLOR_UNVIEWED_ENTRIES);
                }
            }
            return null;
        }
    };
    activitiesListener = new ActivitiesListener() {

        @Override
        public void vuzeNewsEntryChanged(ActivitiesEntry entry) {
            refresh();
        }

        @Override
        public void vuzeNewsEntriesRemoved(ActivitiesEntry[] entries) {
            refresh();
        }

        @Override
        public void vuzeNewsEntriesAdded(ActivitiesEntry[] entries) {
            refresh();
        }

        private void refresh() {
            ViewTitleInfoManager.refreshTitleInfo(titleInfoActivityView);
            if (mdi_entry != null) {
                mdi_entry.redraw();
            }
        }
    };
    ActivitiesManager.addListener(activitiesListener);
    MdiEntryCreationListener creationListener = new MdiEntryCreationListener() {

        @Override
        public MdiEntry createMDiEntry(String id) {
            mdi_entry = mdi.createEntryFromSkinRef(MultipleDocumentInterface.SIDEBAR_HEADER_VUZE, MultipleDocumentInterface.SIDEBAR_SECTION_ACTIVITIES, "activity", "{sidebar." + MultipleDocumentInterface.SIDEBAR_SECTION_ACTIVITIES + "}", titleInfoActivityView, null, false, null);
            return (mdi_entry);
        }
    };
    mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_ACTIVITIES, creationListener);
    mdi.registerEntry("activities", creationListener);
    PluginInterface pi = PluginInitializer.getDefaultInterface();
    UIManager uim = pi.getUIManager();
    MenuManager menuManager = uim.getMenuManager();
    final MenuItem menuItem = menuManager.addMenuItem("sidebar." + MultipleDocumentInterface.SIDEBAR_SECTION_ACTIVITIES, "v3.activity.button.readall");
    menuItem.setDisposeWithUIDetach(UIInstance.UIT_SWT);
    menuItem.addListener(new MenuItemListener() {

        @Override
        public void selected(MenuItem menu, Object target) {
            List<ActivitiesEntry> allEntries = ActivitiesManager.getAllEntries();
            for (ActivitiesEntry entry : allEntries) {
                entry.setRead(true);
            }
        }
    });
    mdi.addListener(new MdiListener() {

        @Override
        public void mdiEntrySelected(MdiEntry newEntry, MdiEntry oldEntry) {
        }

        @Override
        public void mdiDisposed(MultipleDocumentInterface mdi) {
            if (activitiesListener != null) {
                ActivitiesManager.removeListener(activitiesListener);
                activitiesListener = null;
            }
            menuItem.remove();
        }
    });
}
Also used : ActivitiesListener(com.biglybt.activities.ActivitiesListener) MdiListener(com.biglybt.ui.mdi.MdiListener) MdiEntryCreationListener(com.biglybt.ui.mdi.MdiEntryCreationListener) PluginInterface(com.biglybt.pif.PluginInterface) UIManager(com.biglybt.pif.ui.UIManager) MenuItem(com.biglybt.pif.ui.menus.MenuItem) MultipleDocumentInterface(com.biglybt.ui.mdi.MultipleDocumentInterface) ActivitiesEntry(com.biglybt.activities.ActivitiesEntry) MdiEntry(com.biglybt.ui.mdi.MdiEntry) MenuManager(com.biglybt.pif.ui.menus.MenuManager) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject) ArrayList(java.util.ArrayList) List(java.util.List) ViewTitleInfo(com.biglybt.ui.common.viewtitleinfo.ViewTitleInfo)

Aggregations

ActivitiesEntry (com.biglybt.activities.ActivitiesEntry)1 ActivitiesListener (com.biglybt.activities.ActivitiesListener)1 PluginInterface (com.biglybt.pif.PluginInterface)1 UIManager (com.biglybt.pif.ui.UIManager)1 MenuItem (com.biglybt.pif.ui.menus.MenuItem)1 MenuItemListener (com.biglybt.pif.ui.menus.MenuItemListener)1 MenuManager (com.biglybt.pif.ui.menus.MenuManager)1 ViewTitleInfo (com.biglybt.ui.common.viewtitleinfo.ViewTitleInfo)1 MdiEntry (com.biglybt.ui.mdi.MdiEntry)1 MdiEntryCreationListener (com.biglybt.ui.mdi.MdiEntryCreationListener)1 MdiListener (com.biglybt.ui.mdi.MdiListener)1 MultipleDocumentInterface (com.biglybt.ui.mdi.MultipleDocumentInterface)1 SWTSkinObject (com.biglybt.ui.swt.skin.SWTSkinObject)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1