|
@ -1,7 +1,6 @@ |
|
|
package gr.thmmy.mthmmy.activities.topic; |
|
|
package gr.thmmy.mthmmy.activities.topic; |
|
|
|
|
|
|
|
|
import android.graphics.Color; |
|
|
import android.graphics.Color; |
|
|
import android.util.Log; |
|
|
|
|
|
|
|
|
|
|
|
import org.jsoup.Jsoup; |
|
|
import org.jsoup.Jsoup; |
|
|
import org.jsoup.nodes.Document; |
|
|
import org.jsoup.nodes.Document; |
|
@ -16,21 +15,9 @@ import java.util.Objects; |
|
|
import gr.thmmy.mthmmy.data.Post; |
|
|
import gr.thmmy.mthmmy.data.Post; |
|
|
|
|
|
|
|
|
class TopicParser { |
|
|
class TopicParser { |
|
|
//Parsing variables
|
|
|
//Languages supported
|
|
|
private static String usersViewingTopic; |
|
|
private static final String LANGUAGE_GREEK = "Greek"; |
|
|
private static String currentPage; |
|
|
private static final String LANGUAGE_ENGLISH = "English"; |
|
|
private static String postRowSelection; |
|
|
|
|
|
private static String userNameSelection; |
|
|
|
|
|
private static String guestSelection; |
|
|
|
|
|
private static int postDateSubstrSelection; |
|
|
|
|
|
private static String postNumberSelection; |
|
|
|
|
|
private static int postNumSubstrSelection; |
|
|
|
|
|
private static String postAttachedDiv; |
|
|
|
|
|
private static String postAttachedSubstr; |
|
|
|
|
|
private static String numberOfPostsSelection; |
|
|
|
|
|
private static String genderSelection; |
|
|
|
|
|
private static String genderAltMale; |
|
|
|
|
|
private static String genderAltFemale; |
|
|
|
|
|
|
|
|
|
|
|
//User colors variables
|
|
|
//User colors variables
|
|
|
private static final int USER_COLOR_BLACK = Color.parseColor("#000000"); |
|
|
private static final int USER_COLOR_BLACK = Color.parseColor("#000000"); |
|
@ -43,37 +30,47 @@ class TopicParser { |
|
|
@SuppressWarnings("unused") |
|
|
@SuppressWarnings("unused") |
|
|
private static final String TAG = "TopicParser"; |
|
|
private static final String TAG = "TopicParser"; |
|
|
|
|
|
|
|
|
static String parseUsersViewingThisTopic(Document doc){ |
|
|
static String parseUsersViewingThisTopic(Document doc, String language) { |
|
|
defineLanguage(doc); |
|
|
if (Objects.equals(language, LANGUAGE_GREEK)) |
|
|
Log.d(TAG, doc.select("td:containsOwn(" + usersViewingTopic + ")").first().text()); |
|
|
return doc.select("td:containsOwn(διαβάζουν αυτό το θέμα)").first().html(); |
|
|
return doc.select("td:containsOwn(" + usersViewingTopic + ")").first().html(); |
|
|
return doc.select("td:containsOwn(are viewing this topic)").first().html(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static int parseCurrentPageIndex(Document doc) { |
|
|
static int parseCurrentPageIndex(Document doc, String language) { |
|
|
defineLanguage(doc); |
|
|
|
|
|
|
|
|
|
|
|
int returnPage = 1; |
|
|
int returnPage = 1; |
|
|
|
|
|
|
|
|
|
|
|
if (Objects.equals(language, LANGUAGE_GREEK)) { |
|
|
//Contains pages
|
|
|
//Contains pages
|
|
|
Elements findCurrentPage = doc.select("td:contains(" + currentPage + ")>b"); |
|
|
Elements findCurrentPage = doc.select("td:contains(Σελίδες:)>b"); |
|
|
|
|
|
|
|
|
for (Element item : findCurrentPage) { |
|
|
for (Element item : findCurrentPage) { |
|
|
if (!item.text().contains("...") //It's not "..."
|
|
|
if (!item.text().contains("...") //It's not "..."
|
|
|
&& !item.text().contains(currentPage)) { //Nor "Pages:"/"Σελίδες:"
|
|
|
&& !item.text().contains("Σελίδες:")) { //Nor "Σελίδες:"
|
|
|
|
|
|
returnPage = Integer.parseInt(item.text()); |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
Elements findCurrentPage = doc.select("td:contains(Pages:)>b"); |
|
|
|
|
|
|
|
|
|
|
|
for (Element item : findCurrentPage) { |
|
|
|
|
|
if (!item.text().contains("...") && !item.text().contains("Pages:")) { |
|
|
returnPage = Integer.parseInt(item.text()); |
|
|
returnPage = Integer.parseInt(item.text()); |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
return returnPage; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static int parseTopicNumberOfPages(Document doc, int thisPage) { |
|
|
return returnPage; |
|
|
defineLanguage(doc); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static int parseTopicNumberOfPages(Document doc, int thisPage, String language) { |
|
|
//Method's variables
|
|
|
//Method's variables
|
|
|
int returnPages = 1; |
|
|
int returnPages = 1; |
|
|
|
|
|
|
|
|
|
|
|
if (Objects.equals(language, LANGUAGE_GREEK)) { |
|
|
//Contains all pages
|
|
|
//Contains all pages
|
|
|
Elements pages = doc.select("td:contains(" + currentPage + ")>a.navPages"); |
|
|
Elements pages = doc.select("td:contains(Σελίδες:)>a.navPages"); |
|
|
|
|
|
|
|
|
if (pages.size() != 0) { |
|
|
if (pages.size() != 0) { |
|
|
returnPages = thisPage; //Initialize the number
|
|
|
returnPages = thisPage; //Initialize the number
|
|
@ -82,18 +79,33 @@ class TopicParser { |
|
|
returnPages = Integer.parseInt(item.text()); |
|
|
returnPages = Integer.parseInt(item.text()); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
return returnPages; |
|
|
} else { |
|
|
|
|
|
//Contains all pages
|
|
|
|
|
|
Elements pages = doc.select("td:contains(Pages:)>a.navPages"); |
|
|
|
|
|
|
|
|
|
|
|
if (pages.size() != 0) { |
|
|
|
|
|
returnPages = thisPage; |
|
|
|
|
|
for (Element item : pages) { |
|
|
|
|
|
if (Integer.parseInt(item.text()) > returnPages) |
|
|
|
|
|
returnPages = Integer.parseInt(item.text()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static ArrayList<Post> parseTopic(Document doc) { |
|
|
return returnPages; |
|
|
defineLanguage(doc); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static ArrayList<Post> parseTopic(Document doc, String language) { |
|
|
//Method's variables
|
|
|
//Method's variables
|
|
|
final int NO_INDEX = -1; |
|
|
final int NO_INDEX = -1; |
|
|
ArrayList<Post> returnList = new ArrayList<>(); |
|
|
ArrayList<Post> returnList = new ArrayList<>(); |
|
|
|
|
|
Elements rows; |
|
|
|
|
|
|
|
|
Elements rows = doc.select("form[id=quickModForm]>table>tbody>tr:matches(" |
|
|
if (Objects.equals(language, LANGUAGE_GREEK)) |
|
|
+ postRowSelection +")"); |
|
|
rows = doc.select("form[id=quickModForm]>table>tbody>tr:matches(στις)"); |
|
|
|
|
|
else { |
|
|
|
|
|
rows = doc.select("form[id=quickModForm]>table>tbody>tr:matches(on)"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
for (Element item : rows) { //For every post
|
|
|
for (Element item : rows) { //For every post
|
|
|
//Variables to pass
|
|
|
//Variables to pass
|
|
@ -114,21 +126,7 @@ class TopicParser { |
|
|
p_userColor = USER_COLOR_YELLOW; |
|
|
p_userColor = USER_COLOR_YELLOW; |
|
|
p_attachedFiles = new ArrayList<>(); |
|
|
p_attachedFiles = new ArrayList<>(); |
|
|
|
|
|
|
|
|
//Find the Username
|
|
|
//Language independent parsing
|
|
|
Element userName = item.select("a[title^=" + userNameSelection + "]").first(); |
|
|
|
|
|
if (userName == null) { //Deleted profile
|
|
|
|
|
|
p_isDeleted = true; |
|
|
|
|
|
p_userName = item |
|
|
|
|
|
.select("td:has(div.smalltext:containsOwn(" |
|
|
|
|
|
+ guestSelection + "))[style^=overflow]") |
|
|
|
|
|
.first().text(); |
|
|
|
|
|
p_userName = p_userName.substring(0, p_userName.indexOf(" " + guestSelection)); |
|
|
|
|
|
p_userColor = USER_COLOR_BLACK; |
|
|
|
|
|
} else { |
|
|
|
|
|
p_userName = userName.html(); |
|
|
|
|
|
p_profileURL = userName.attr("href"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//Find thumbnail url
|
|
|
//Find thumbnail url
|
|
|
Element thumbnailUrl = item.select("img.avatar").first(); |
|
|
Element thumbnailUrl = item.select("img.avatar").first(); |
|
|
p_thumbnailUrl = null; //In case user doesn't have an avatar
|
|
|
p_thumbnailUrl = null; //In case user doesn't have an avatar
|
|
@ -142,7 +140,7 @@ class TopicParser { |
|
|
//Find post's text
|
|
|
//Find post's text
|
|
|
p_post = item.select("div").select(".post").first().outerHtml(); |
|
|
p_post = item.select("div").select(".post").first().outerHtml(); |
|
|
|
|
|
|
|
|
{ |
|
|
{ //Fix embedded videos
|
|
|
Elements noembedTag = item.select("div").select(".post").first().select("noembed"); |
|
|
Elements noembedTag = item.select("div").select(".post").first().select("noembed"); |
|
|
ArrayList<String> embededVideosUrls = new ArrayList<>(); |
|
|
ArrayList<String> embededVideosUrls = new ArrayList<>(); |
|
|
|
|
|
|
|
@ -158,50 +156,125 @@ class TopicParser { |
|
|
break; |
|
|
break; |
|
|
p_post = p_post.replace( |
|
|
p_post = p_post.replace( |
|
|
p_post.substring(p_post.indexOf("<embed"), p_post.indexOf("/noembed>") + 9) |
|
|
p_post.substring(p_post.indexOf("<embed"), p_post.indexOf("/noembed>") + 9) |
|
|
, "<iframe width=\"100%\" height=\"auto\" src=\"" |
|
|
, "<div class=\"embedded-video\">" |
|
|
+ "https://www.youtube.com/embed/" |
|
|
+ "<a href=\"https://www.youtube.com/" |
|
|
+ embededVideosUrls.get(tmp_counter) |
|
|
+ embededVideosUrls.get(tmp_counter) + "\" target=\"_blank\">" |
|
|
+ "\" frameborder=\"0\" allowfullscreen></iframe>" |
|
|
+ "<img src=\"https://img.youtube.com/vi/" |
|
|
); |
|
|
+ embededVideosUrls.get(tmp_counter) + "/default.jpg\" alt=\"\" border=\"0\">" |
|
|
|
|
|
+ "</a>" |
|
|
|
|
|
//+ "<img class=\"embedded-video-play\" src=\"http://www.youtube.com/yt/brand/media/image/YouTube_light_color_icon.png\">"
|
|
|
|
|
|
+ "</div>"); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//Add stuff to make it work in WebView
|
|
|
//Add stuff to make it work in WebView
|
|
|
p_post = ("<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" />" |
|
|
//style.css
|
|
|
+ p_post); //style.css
|
|
|
p_post = ("<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" />" + p_post); |
|
|
|
|
|
|
|
|
|
|
|
//Find post's index
|
|
|
|
|
|
Element postIndex = item.select("a[name^=msg]").first(); |
|
|
|
|
|
if (postIndex == null) |
|
|
|
|
|
p_postIndex = NO_INDEX; |
|
|
|
|
|
else { |
|
|
|
|
|
String tmp = postIndex.attr("name"); |
|
|
|
|
|
p_postIndex = Integer.parseInt(tmp.substring(tmp.indexOf("msg") + 3)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//Language dependent parsing
|
|
|
|
|
|
Element userName; |
|
|
|
|
|
if (Objects.equals(language, LANGUAGE_GREEK)) { |
|
|
|
|
|
//Find username
|
|
|
|
|
|
userName = item.select("a[title^=Εμφάνιση προφίλ του μέλους]").first(); |
|
|
|
|
|
if (userName == null) { //Deleted profile
|
|
|
|
|
|
p_isDeleted = true; |
|
|
|
|
|
p_userName = item |
|
|
|
|
|
.select("td:has(div.smalltext:containsOwn(Επισκέπτης))[style^=overflow]") |
|
|
|
|
|
.first().text(); |
|
|
|
|
|
p_userName = p_userName.substring(0, p_userName.indexOf(" Επισκέπτης")); |
|
|
|
|
|
p_userColor = USER_COLOR_BLACK; |
|
|
|
|
|
} else { |
|
|
|
|
|
p_userName = userName.html(); |
|
|
|
|
|
p_profileURL = userName.attr("href"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
//Find post's submit date
|
|
|
//Find post's submit date
|
|
|
Element postDate = item.select("div.smalltext:matches(" + postRowSelection + ":)").first(); |
|
|
Element postDate = item.select("div.smalltext:matches(στις:)").first(); |
|
|
p_postDate = postDate.text(); |
|
|
p_postDate = postDate.text(); |
|
|
p_postDate = p_postDate.substring(p_postDate.indexOf(postRowSelection + ":") + postDateSubstrSelection |
|
|
p_postDate = p_postDate.substring(p_postDate.indexOf("στις:") + 6 |
|
|
, p_postDate.indexOf(" »")); |
|
|
, p_postDate.indexOf(" »")); |
|
|
|
|
|
|
|
|
//Find post's number
|
|
|
//Find post's number
|
|
|
Element postNum = item.select("div.smalltext:matches(" + postNumberSelection + ")").first(); |
|
|
Element postNum = item.select("div.smalltext:matches(Απάντηση #)").first(); |
|
|
if (postNum == null) { //Topic starter
|
|
|
if (postNum == null) { //Topic starter
|
|
|
p_postNum = 0; |
|
|
p_postNum = 0; |
|
|
} else { |
|
|
} else { |
|
|
String tmp_str = postNum.text().substring(postNumSubstrSelection); |
|
|
String tmp_str = postNum.text().substring(12); |
|
|
p_postNum = Integer.parseInt(tmp_str.substring(0, tmp_str.indexOf(" " + postRowSelection))); |
|
|
p_postNum = Integer.parseInt(tmp_str.substring(0, tmp_str.indexOf(" στις"))); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//Find post's index
|
|
|
|
|
|
Element postIndex = item.select("a[name^=msg]").first(); |
|
|
//Find attached file's urls, names and info, if present
|
|
|
if (postIndex == null) |
|
|
Elements postAttachments = item.select("div:containsOwn(έγινε λήψη):containsOwn(φορές.)"); |
|
|
p_postIndex = NO_INDEX; |
|
|
if (postAttachments != null) { |
|
|
else { |
|
|
Elements attachedFiles = postAttachments.select("a"); |
|
|
String tmp = postIndex.attr("name"); |
|
|
String postAttachmentsText = postAttachments.text(); |
|
|
p_postIndex = Integer.parseInt(tmp.substring(tmp.indexOf("msg") + 3)); |
|
|
|
|
|
|
|
|
for (int i = 0; i < attachedFiles.size(); ++i) { |
|
|
|
|
|
String[] attachedArray = new String[3]; |
|
|
|
|
|
|
|
|
|
|
|
//Get file's url and filename
|
|
|
|
|
|
Element tmpAttachedFileUrlAndName = attachedFiles.get(i); |
|
|
|
|
|
attachedArray[0] = tmpAttachedFileUrlAndName.attr("href"); |
|
|
|
|
|
attachedArray[1] = tmpAttachedFileUrlAndName.text().substring(1); |
|
|
|
|
|
|
|
|
|
|
|
//Get file's info (size and download count)
|
|
|
|
|
|
String postAttachmentsTextSbstr = postAttachmentsText.substring( |
|
|
|
|
|
postAttachmentsText.indexOf(attachedArray[1])); |
|
|
|
|
|
|
|
|
|
|
|
attachedArray[2] = postAttachmentsTextSbstr.substring(attachedArray[1] |
|
|
|
|
|
.length(), postAttachmentsTextSbstr.indexOf("φορές.")) + "φορές.)"; |
|
|
|
|
|
|
|
|
|
|
|
p_attachedFiles.add(attachedArray); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
//Find username
|
|
|
|
|
|
userName = item.select("a[title^=View the profile of]").first(); |
|
|
|
|
|
if (userName == null) { //Deleted profile
|
|
|
|
|
|
p_isDeleted = true; |
|
|
|
|
|
p_userName = item |
|
|
|
|
|
.select("td:has(div.smalltext:containsOwn(Guest))[style^=overflow]") |
|
|
|
|
|
.first().text(); |
|
|
|
|
|
p_userName = p_userName.substring(0, p_userName.indexOf(" Guest")); |
|
|
|
|
|
p_userColor = USER_COLOR_BLACK; |
|
|
|
|
|
} else { |
|
|
|
|
|
p_userName = userName.html(); |
|
|
|
|
|
p_profileURL = userName.attr("href"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//Find post's submit date
|
|
|
|
|
|
Element postDate = item.select("div.smalltext:matches(on:)").first(); |
|
|
|
|
|
p_postDate = postDate.text(); |
|
|
|
|
|
p_postDate = p_postDate.substring(p_postDate.indexOf("on:") + 4 |
|
|
|
|
|
, p_postDate.indexOf(" »")); |
|
|
|
|
|
|
|
|
|
|
|
//Find post's number
|
|
|
|
|
|
Element postNum = item.select("div.smalltext:matches(Reply #)").first(); |
|
|
|
|
|
if (postNum == null) { //Topic starter
|
|
|
|
|
|
p_postNum = 0; |
|
|
|
|
|
} else { |
|
|
|
|
|
String tmp_str = postNum.text().substring(9); |
|
|
|
|
|
p_postNum = Integer.parseInt(tmp_str.substring(0, tmp_str.indexOf(" on"))); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Find attached file's urls, names and info, if present
|
|
|
//Find attached file's urls, names and info, if present
|
|
|
Elements postAttachments = item.select("div:containsOwn(" + postAttachedDiv |
|
|
Elements postAttachments = item.select("div:containsOwn(downloaded):containsOwn(times.)"); |
|
|
+ "):containsOwn(" + postAttachedSubstr + ")"); |
|
|
|
|
|
if (postAttachments != null) { |
|
|
if (postAttachments != null) { |
|
|
Elements attachedFiles = postAttachments.select("a"); |
|
|
Elements attachedFiles = postAttachments.select("a"); |
|
|
String postAttachmentsText = postAttachments.text(); |
|
|
String postAttachmentsText = postAttachments.text(); |
|
|
|
|
|
|
|
|
for(int i = 0; i<attachedFiles.size(); ++i){ |
|
|
for (int i = 0; i < attachedFiles.size(); ++i) { |
|
|
String[] attachedArray = new String[3]; |
|
|
String[] attachedArray = new String[3]; |
|
|
|
|
|
|
|
|
//Get file's url and filename
|
|
|
//Get file's url and filename
|
|
@ -213,13 +286,13 @@ class TopicParser { |
|
|
String postAttachmentsTextSbstr = postAttachmentsText.substring( |
|
|
String postAttachmentsTextSbstr = postAttachmentsText.substring( |
|
|
postAttachmentsText.indexOf(attachedArray[1])); |
|
|
postAttachmentsText.indexOf(attachedArray[1])); |
|
|
|
|
|
|
|
|
attachedArray[2] = postAttachmentsTextSbstr.substring(attachedArray[1].length() |
|
|
attachedArray[2] = postAttachmentsTextSbstr.substring(attachedArray[1] |
|
|
, postAttachmentsTextSbstr.indexOf(postAttachedSubstr)) |
|
|
.length(), postAttachmentsTextSbstr.indexOf("times.")) + "times.)"; |
|
|
+ postAttachedSubstr + ")"; |
|
|
|
|
|
|
|
|
|
|
|
p_attachedFiles.add(attachedArray); |
|
|
p_attachedFiles.add(attachedArray); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (!p_isDeleted) { //Active user
|
|
|
if (!p_isDeleted) { //Active user
|
|
|
//Get extra info
|
|
|
//Get extra info
|
|
@ -229,24 +302,47 @@ class TopicParser { |
|
|
Element info = userName.parent().nextElementSibling(); //Get sibling "div"
|
|
|
Element info = userName.parent().nextElementSibling(); //Get sibling "div"
|
|
|
List<String> infoList = Arrays.asList(info.html().split("<br>")); |
|
|
List<String> infoList = Arrays.asList(info.html().split("<br>")); |
|
|
|
|
|
|
|
|
|
|
|
if (Objects.equals(language, LANGUAGE_GREEK)) { |
|
|
|
|
|
for (String line : infoList) { |
|
|
|
|
|
if (line.contains("Μηνύματα:")) { |
|
|
|
|
|
postsLineIndex = infoList.indexOf(line); |
|
|
|
|
|
//Remove any line breaks and spaces on the start and end
|
|
|
|
|
|
p_numberOfPosts = line.replace("\n", "").replace("\r", "").trim(); |
|
|
|
|
|
} |
|
|
|
|
|
if (line.contains("Φύλο:")) { |
|
|
|
|
|
if (line.contains("alt=\"Άντρας\"")) |
|
|
|
|
|
p_gender = "Φύλο: Άντρας"; |
|
|
|
|
|
else |
|
|
|
|
|
p_gender = "Φύλο: Γυναίκα"; |
|
|
|
|
|
} |
|
|
|
|
|
if (line.contains("alt=\"*\"")) { |
|
|
|
|
|
starsLineIndex = infoList.indexOf(line); |
|
|
|
|
|
Document starsHtml = Jsoup.parse(line); |
|
|
|
|
|
p_numberOfStars = starsHtml.select("img[alt]").size(); |
|
|
|
|
|
p_userColor = colorPicker(starsHtml.select("img[alt]").first() |
|
|
|
|
|
.attr("abs:src")); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
for (String line : infoList) { |
|
|
for (String line : infoList) { |
|
|
if (line.contains(numberOfPostsSelection)) { |
|
|
if (line.contains("Posts:")) { |
|
|
postsLineIndex = infoList.indexOf(line); |
|
|
postsLineIndex = infoList.indexOf(line); |
|
|
//Remove any line breaks and spaces on the start and end
|
|
|
//Remove any line breaks and spaces on the start and end
|
|
|
p_numberOfPosts = line.replace("\n", "") |
|
|
p_numberOfPosts = line.replace("\n", "").replace("\r", "").trim(); |
|
|
.replace("\r", "").trim(); |
|
|
|
|
|
} |
|
|
} |
|
|
if (line.contains(genderSelection)) { |
|
|
if (line.contains("Gender:")) { |
|
|
if (line.contains("alt=\"" + genderAltMale + "\"")) |
|
|
if (line.contains("alt=\"Male\"")) |
|
|
p_gender = genderSelection + " " + genderAltMale; |
|
|
p_gender = "Gender: Male"; |
|
|
else |
|
|
else |
|
|
p_gender = genderSelection + " " + genderAltFemale; |
|
|
p_gender = "Gender: Female"; |
|
|
} |
|
|
} |
|
|
if (line.contains("alt=\"*\"")) { |
|
|
if (line.contains("alt=\"*\"")) { |
|
|
starsLineIndex = infoList.indexOf(line); |
|
|
starsLineIndex = infoList.indexOf(line); |
|
|
Document starsHtml = Jsoup.parse(line); |
|
|
Document starsHtml = Jsoup.parse(line); |
|
|
p_numberOfStars = starsHtml.select("img[alt]").size(); |
|
|
p_numberOfStars = starsHtml.select("img[alt]").size(); |
|
|
p_userColor = colorPicker(starsHtml.select("img[alt]").first().attr("abs:src")); |
|
|
p_userColor = colorPicker(starsHtml.select("img[alt]").first() |
|
|
|
|
|
.attr("abs:src")); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -272,99 +368,44 @@ class TopicParser { |
|
|
&& !thisLine.contains("<a href=")) { |
|
|
&& !thisLine.contains("<a href=")) { |
|
|
p_personalText = thisLine; //Then this line has user's personal text
|
|
|
p_personalText = thisLine; //Then this line has user's personal text
|
|
|
//Remove any line breaks and spaces on the start and end
|
|
|
//Remove any line breaks and spaces on the start and end
|
|
|
p_personalText = p_personalText.replace("\n", "") |
|
|
p_personalText = p_personalText.replace("\n", "").replace("\r", "").trim(); |
|
|
.replace("\r", "").trim(); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
//Add new post in postsList, extended information needed
|
|
|
//Add new post in postsList, extended information needed
|
|
|
returnList.add(new Post(p_thumbnailUrl, p_userName, p_subject, p_post |
|
|
returnList.add(new Post(p_thumbnailUrl, p_userName, p_subject, p_post, p_postIndex |
|
|
, p_postIndex, p_postNum, p_postDate, p_profileURL, p_rank |
|
|
, p_postNum, p_postDate, p_profileURL, p_rank, p_specialRank, p_gender |
|
|
, p_specialRank, p_gender, p_numberOfPosts, p_personalText |
|
|
, p_numberOfPosts, p_personalText, p_numberOfStars, p_userColor |
|
|
, p_numberOfStars, p_userColor, p_attachedFiles)); |
|
|
, p_attachedFiles)); |
|
|
|
|
|
|
|
|
} else { //Deleted user
|
|
|
} else { //Deleted user
|
|
|
//Add new post in postsList, only standard information needed
|
|
|
//Add new post in postsList, only standard information needed
|
|
|
returnList.add(new Post(p_thumbnailUrl, p_userName, p_subject, p_post |
|
|
returnList.add(new Post(p_thumbnailUrl, p_userName, p_subject, p_post, p_postIndex |
|
|
, p_postIndex, p_postNum, p_postDate, p_userColor, p_attachedFiles)); |
|
|
, p_postNum, p_postDate, p_userColor, p_attachedFiles)); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
return returnList; |
|
|
return returnList; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private static void defineLanguage(Document doc){ |
|
|
static String defineLanguage(Document doc) { |
|
|
//English parsing variables
|
|
|
if (doc.select("h3").text().contains("Καλώς ορίσατε")) { |
|
|
final String en_usersViewingTopic = "are viewing this topic"; |
|
|
return LANGUAGE_GREEK; |
|
|
final String en_currentPage = "Pages:"; |
|
|
} else { //Default is english (eg. guest's language)
|
|
|
final String en_postRowSelection = "on"; |
|
|
return LANGUAGE_ENGLISH; |
|
|
final String en_userNameSelection = "View the profile of"; |
|
|
} |
|
|
final String en_guestSelection = "Guest"; |
|
|
} |
|
|
final String en_postAttachedDiv = "downloaded"; |
|
|
|
|
|
final String en_postAttachedSubstr = "times."; |
|
|
private static int colorPicker(String starsUrl) { |
|
|
final String en_postsNumberSelection = "Reply #"; |
|
|
if (starsUrl.contains("/star.gif")) |
|
|
final String en_numberOfPostsSelection = "Posts:"; |
|
|
|
|
|
final String en_genderSelection = "Gender:"; |
|
|
|
|
|
final String en_genderAltMale = "Male"; |
|
|
|
|
|
final String en_genderAltFemale = "Female"; |
|
|
|
|
|
|
|
|
|
|
|
//Greek parsing variables
|
|
|
|
|
|
final String gr_usersViewingTopic = "διαβάζουν αυτό το θέμα"; |
|
|
|
|
|
final String gr_currentPage = "Σελίδες:"; |
|
|
|
|
|
final String gr_postRowSelection = "στις"; |
|
|
|
|
|
final String gr_userNameSelection = "Εμφάνιση προφίλ του μέλους"; |
|
|
|
|
|
final String gr_guestSelection = "Επισκέπτης"; |
|
|
|
|
|
final String gr_postAttachedDiv = "έγινε λήψη"; |
|
|
|
|
|
final String gr_postAttachedSubstr = "φορές."; |
|
|
|
|
|
final String gr_postsNumberSelection = "Απάντηση #"; |
|
|
|
|
|
final String gr_numberOfPostsSelection = "Μηνύματα:"; |
|
|
|
|
|
final String gr_genderSelection = "Φύλο:"; |
|
|
|
|
|
final String gr_genderAltMale = "Άντρας"; |
|
|
|
|
|
final String gr_genderAltFemale = "Γυναίκα"; |
|
|
|
|
|
|
|
|
|
|
|
if(doc.select("h3").text().contains("Καλώς ορίσατε")){ |
|
|
|
|
|
usersViewingTopic = gr_usersViewingTopic; |
|
|
|
|
|
currentPage = gr_currentPage; |
|
|
|
|
|
postRowSelection = gr_postRowSelection; |
|
|
|
|
|
userNameSelection = gr_userNameSelection; |
|
|
|
|
|
guestSelection = gr_guestSelection; |
|
|
|
|
|
postAttachedDiv = gr_postAttachedDiv; |
|
|
|
|
|
postAttachedSubstr = gr_postAttachedSubstr; |
|
|
|
|
|
postDateSubstrSelection = 6; |
|
|
|
|
|
postNumberSelection = gr_postsNumberSelection; |
|
|
|
|
|
postNumSubstrSelection = 12; |
|
|
|
|
|
numberOfPostsSelection = gr_numberOfPostsSelection; |
|
|
|
|
|
genderSelection = gr_genderSelection; |
|
|
|
|
|
genderAltMale = gr_genderAltMale; |
|
|
|
|
|
genderAltFemale = gr_genderAltFemale; |
|
|
|
|
|
} |
|
|
|
|
|
else{ //Default is english (eg. guest's language)
|
|
|
|
|
|
usersViewingTopic = en_usersViewingTopic; |
|
|
|
|
|
currentPage = en_currentPage; |
|
|
|
|
|
postRowSelection = en_postRowSelection; |
|
|
|
|
|
userNameSelection = en_userNameSelection; |
|
|
|
|
|
guestSelection = en_guestSelection; |
|
|
|
|
|
postAttachedDiv = en_postAttachedDiv; |
|
|
|
|
|
postAttachedSubstr = en_postAttachedSubstr; |
|
|
|
|
|
postDateSubstrSelection = 4; |
|
|
|
|
|
postNumberSelection = en_postsNumberSelection; |
|
|
|
|
|
postNumSubstrSelection = 9; |
|
|
|
|
|
numberOfPostsSelection = en_numberOfPostsSelection; |
|
|
|
|
|
genderSelection = en_genderSelection; |
|
|
|
|
|
genderAltMale = en_genderAltMale; |
|
|
|
|
|
genderAltFemale = en_genderAltFemale; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
private static int colorPicker(String starsUrl){ |
|
|
|
|
|
if(starsUrl.contains("/star.gif")) |
|
|
|
|
|
return USER_COLOR_YELLOW; |
|
|
return USER_COLOR_YELLOW; |
|
|
else if(starsUrl.contains("/starmod.gif")) |
|
|
else if (starsUrl.contains("/starmod.gif")) |
|
|
return USER_COLOR_GREEN; |
|
|
return USER_COLOR_GREEN; |
|
|
else if(starsUrl.contains("/stargmod.gif")) |
|
|
else if (starsUrl.contains("/stargmod.gif")) |
|
|
return USER_COLOR_BLUE; |
|
|
return USER_COLOR_BLUE; |
|
|
else if(starsUrl.contains("/staradmin.gif")) |
|
|
else if (starsUrl.contains("/staradmin.gif")) |
|
|
return USER_COLOR_RED; |
|
|
return USER_COLOR_RED; |
|
|
else if(starsUrl.contains("/starweb.gif")) |
|
|
else if (starsUrl.contains("/starweb.gif")) |
|
|
return USER_COLOR_BLACK; |
|
|
return USER_COLOR_BLACK; |
|
|
else if(starsUrl.contains("/oscar.gif")) |
|
|
else if (starsUrl.contains("/oscar.gif")) |
|
|
return USER_COLOR_PINK; |
|
|
return USER_COLOR_PINK; |
|
|
return USER_COLOR_YELLOW; |
|
|
return USER_COLOR_YELLOW; |
|
|
} |
|
|
} |
|
|