Search in sources :

Example 6 with AwfulPreferences

use of com.ferg.awfulapp.preferences.AwfulPreferences in project Awful.apk by Awful.

the class AnnouncementsRequest method parseAnnouncement.

@NonNull
private static List<AwfulPost> parseAnnouncement(@NonNull Document aThread) {
    List<AwfulPost> results = new ArrayList<>();
    AwfulPreferences prefs = AwfulPreferences.getInstance();
    // grab all the main announcement sections - these contain *most* of the data we need :/
    Elements mainAnnouncements = aThread.select("#main_full  tr[valign='top']");
    Log.d(TAG, "parseAnnouncement: found" + mainAnnouncements.size() + " announcements");
    for (Element announcementSection : mainAnnouncements) {
        AwfulPost announcement = new AwfulPost();
        Element author = announcementSection.select(".author").first();
        if (author != null) {
            announcement.setUsername(author.text());
        }
        Element regDate = announcementSection.select(".registered").first();
        if (regDate != null) {
            announcement.setRegDate(regDate.text());
        }
        Element avatar = announcementSection.select(".title img").first();
        if (avatar != null) {
            tryConvertToHttps(avatar);
            announcement.setAvatar(avatar.attr("src"));
        }
        // not sure if this ever appears for announcements but whatever, may as well
        Element editedBy = announcementSection.select(".editedby").first();
        if (editedBy != null) {
            announcement.setEdited("<i>" + editedBy.text() + "</i>");
        }
        // announcements have their post date in a whole other section directly after the announcement section
        Element postDateSection = announcementSection.nextElementSibling();
        if (postDateSection != null) {
            Element postDate = postDateSection.select(".postdate").first();
            if (postDate != null) {
                announcement.setDate(postDate.text());
            }
        }
        Element postBody = announcementSection.select(".postbody").first();
        if (postBody != null) {
            // process videos, images and links and store the resulting post HTML
            AwfulPost.convertVideos(postBody, prefs.inlineYoutube);
            for (Element image : postBody.getElementsByTag("img")) {
                AwfulPost.processPostImage(image, false, prefs);
            }
            for (Element link : postBody.getElementsByTag("a")) {
                tryConvertToHttps(link);
            }
            announcement.setContent(postBody.html());
        }
        // I guess this is important...?
        announcement.setEditable(false);
        results.add(announcement);
        Log.i(TAG, Integer.toString(mainAnnouncements.size()) + " posts found, " + results.size() + " posts parsed.");
    }
    return results;
}
Also used : AwfulPost(com.ferg.awfulapp.thread.AwfulPost) Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) Elements(org.jsoup.select.Elements) AwfulPreferences(com.ferg.awfulapp.preferences.AwfulPreferences) NonNull(android.support.annotation.NonNull)

Example 7 with AwfulPreferences

use of com.ferg.awfulapp.preferences.AwfulPreferences in project Awful.apk by Awful.

the class LoginRequest method handleResponse.

@Override
protected Boolean handleResponse(Document doc) throws AwfulError {
    Boolean result = NetworkUtils.saveLoginCookies(getContext());
    if (result) {
        AwfulPreferences prefs = AwfulPreferences.getInstance(getContext());
        prefs.setPreference(Keys.USERNAME, username);
    }
    return result;
}
Also used : AwfulPreferences(com.ferg.awfulapp.preferences.AwfulPreferences)

Aggregations

AwfulPreferences (com.ferg.awfulapp.preferences.AwfulPreferences)7 NonNull (android.support.annotation.NonNull)2 ArrayList (java.util.ArrayList)2 WebSettings (android.webkit.WebSettings)1 NetworkResponse (com.android.volley.NetworkResponse)1 VolleyError (com.android.volley.VolleyError)1 LoginRequest (com.ferg.awfulapp.task.LoginRequest)1 AwfulPost (com.ferg.awfulapp.thread.AwfulPost)1 Element (org.jsoup.nodes.Element)1 Elements (org.jsoup.select.Elements)1