Search in sources :

Example 1 with SubscriptionPopularityListener

use of com.biglybt.core.subs.SubscriptionPopularityListener in project BiglyBT by BiglySoftware.

the class SubscriptionListWindow method complete.

@Override
public void complete(final byte[] hash, final Subscription[] subscriptions) {
    if (!(subscriptions.length > 0)) {
        failed(hash, null);
    } else {
        if (display != null && !display.isDisposed()) {
            display.asyncExec(new Runnable() {

                @Override
                public void run() {
                    if (mainComposite.isDisposed()) {
                        return;
                    }
                    subscriptionItems = new SubscriptionItemModel[subscriptions.length];
                    for (int i = 0; i < subscriptions.length; i++) {
                        final SubscriptionItemModel subscriptionItem = new SubscriptionItemModel();
                        subscriptionItems[i] = subscriptionItem;
                        subscriptionItem.name = subscriptions[i].getName();
                        subscriptionItem.popularity = -1;
                        subscriptionItem.popularityDisplay = MessageText.getString("subscriptions.listwindow.popularity.reading");
                        subscriptionItem.subscription = subscriptions[i];
                        try {
                            subscriptions[i].getPopularity(new SubscriptionPopularityListener() {

                                @Override
                                public void gotPopularity(long popularity) {
                                    update(subscriptionItem, popularity, popularity + "");
                                }

                                @Override
                                public void failed(SubscriptionException error) {
                                    update(subscriptionItem, -2, MessageText.getString("subscriptions.listwindow.popularity.unknown"));
                                }
                            });
                        } catch (SubscriptionException e) {
                            update(subscriptionItem, -2, MessageText.getString("subscriptions.listwindow.popularity.unknown"));
                        }
                    }
                    animatedImage.stop();
                    mainLayout.topControl = listPanel;
                    mainComposite.layout();
                    sortAndRefresh();
                    subscriptionsList.setSelection(0);
                    action.addListener(SWT.Selection, new Listener() {

                        @Override
                        public void handleEvent(Event arg0) {
                            if (subscriptionsList != null && !subscriptionsList.isDisposed()) {
                                int selectedIndex = subscriptionsList.getSelectionIndex();
                                if (selectedIndex >= 0 && selectedIndex < subscriptionItems.length) {
                                    Subscription subscription = (Subscription) subscriptionItems[selectedIndex].subscription;
                                    if (subscription != null) {
                                        subscription.setSubscribed(true);
                                        subscription.requestAttention();
                                    }
                                }
                            }
                        }
                    });
                }
            });
        }
    }
}
Also used : SubscriptionPopularityListener(com.biglybt.core.subs.SubscriptionPopularityListener) SubscriptionException(com.biglybt.core.subs.SubscriptionException) Listener(org.eclipse.swt.widgets.Listener) SubscriptionLookupListener(com.biglybt.core.subs.SubscriptionLookupListener) SubscriptionPopularityListener(com.biglybt.core.subs.SubscriptionPopularityListener) Event(org.eclipse.swt.widgets.Event) Subscription(com.biglybt.core.subs.Subscription)

Aggregations

Subscription (com.biglybt.core.subs.Subscription)1 SubscriptionException (com.biglybt.core.subs.SubscriptionException)1 SubscriptionLookupListener (com.biglybt.core.subs.SubscriptionLookupListener)1 SubscriptionPopularityListener (com.biglybt.core.subs.SubscriptionPopularityListener)1 Event (org.eclipse.swt.widgets.Event)1 Listener (org.eclipse.swt.widgets.Listener)1