Search in sources :

Example 21 with Thing

use of com.winsonchiu.reader.data.reddit.Thing in project Reader by TheKeeperOfPie.

the class ControllerComments method setLinkWithComments.

public void setLinkWithComments(Link link) {
    link.setBackgroundColor(this.link.getBackgroundColor());
    this.link = link;
    Listing listing = new Listing();
    // For some reason Reddit doesn't report the link author, so we'll do it manually
    for (Thing thing : link.getComments().getChildren()) {
        Comment comment = (Comment) thing;
        comment.setLinkAuthor(link.getAuthor());
    }
    // TODO: Make this logic cleaner
    if (link.getComments() != null) {
        listing.setChildren(new ArrayList<>(link.getComments().getChildren()));
    } else {
        listing.setChildren(new ArrayList<>());
    }
    listingComments = listing;
    if (sharedPreferences.getBoolean(AppSettings.PREF_COLLAPSE_COMMENT_THREADS, false)) {
        for (int index = listingComments.getChildren().size() - 1; index >= 0; index--) {
            if (((Comment) listingComments.getChildren().get(index)).getLevel() == 0) {
                collapseComment(index, false);
            }
        }
    }
    eventHolder.call(new RxAdapterEvent<>(getData()));
}
Also used : Comment(com.winsonchiu.reader.data.reddit.Comment) Listing(com.winsonchiu.reader.data.reddit.Listing) Thing(com.winsonchiu.reader.data.reddit.Thing)

Aggregations

Thing (com.winsonchiu.reader.data.reddit.Thing)21 Replyable (com.winsonchiu.reader.data.reddit.Replyable)8 Comment (com.winsonchiu.reader.data.reddit.Comment)7 Link (com.winsonchiu.reader.data.reddit.Link)7 Listing (com.winsonchiu.reader.data.reddit.Listing)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 Subreddit (com.winsonchiu.reader.data.reddit.Subreddit)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)3 Comparator (java.util.Comparator)3 AccountManager (android.accounts.AccountManager)2 Context (android.content.Context)2 SharedPreferences (android.content.SharedPreferences)2 PreferenceManager (android.preference.PreferenceManager)2 Nullable (android.support.annotation.Nullable)2 TextUtils (android.text.TextUtils)2 Log (android.util.Log)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 BehaviorRelay (com.jakewharton.rxrelay.BehaviorRelay)2 AppSettings (com.winsonchiu.reader.AppSettings)2