Example usage for com.google.gwt.ajaxfeed.client.impl EntryWrapper getPublishedDate

List of usage examples for com.google.gwt.ajaxfeed.client.impl EntryWrapper getPublishedDate

Introduction

In this page you can find the example usage for com.google.gwt.ajaxfeed.client.impl EntryWrapper getPublishedDate.

Prototype

public String getPublishedDate();

Source Link

Usage

From source file:com.google.gwt.sample.feedreader.client.FeedPanel.java

License:Apache License

/**
 * Load a single feed./*from ww  w .j a v  a  2s .co  m*/
 */
public void loadFeed() {
    loadStarted = true;
    loadFinished = false;

    getLabel().setBusy(true);

    JavaScriptObject feedJso = feedApi.construct(feed.getUrl());
    feedApi.setNumEntries(feedJso, 20);
    feedApi.load(feedJso, new FeedCallback() {
        public void onLoad(JavaScriptObject feedResult) {
            // Fix up any missing fields
            resultApi.bind(feedResult);

            ErrorWrapper errorResponse = resultApi.getError(feedResult);
            if (errorResponse != null) {
                getLabel().setText(feed.getTitle() + " (Error)");
                setText("Unable to load feed (" + errorResponse.getMessage() + ")");
                return;
            }

            JavaScriptObject jsonFeed = resultApi.getFeed(feedResult);
            entries = jsonFeedApi.getEntries(jsonFeed);

            String title = jsonFeedApi.getTitle(jsonFeed);
            feed.setTitle(title);
            getLabel().setText(title);

            getLabel().setBusy(false);

            final Date lastViewed = new Date(feed.getLastArticle());

            // Count the number of new entries while the next feed downloads
            DeferredCommand.addCommand(new IncrementalCommand() {
                final Iterator i = entries.iterator();
                int newEntries = 0;

                public boolean execute() {
                    EntryWrapper entry = (EntryWrapper) i.next();

                    try {
                        if ((new Date(entry.getPublishedDate())).after(lastViewed)) {
                            newEntries++;
                        }
                    } catch (IllegalArgumentException e) {
                        // Ignore date formats that we can't parse.
                    }

                    if (i.hasNext()) {
                        return true;

                    } else {
                        // Show the number of new entries
                        if (newEntries > 0) {
                            getLabel().addStyleName("unseen");
                            getLabel().setText("(" + newEntries + ") " + feed.getTitle());
                        } else {
                            getLabel().setText(feed.getTitle());
                        }

                        getLabel().setBusy(false);

                        return false;
                    }
                }
            });

            loadStarted = false;
            loadFinished = true;
            drawn = false;
            redraw();
        }
    });
}