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;
}
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;
}
Aggregations